]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/mips/cavium/dev/rgmii/octeon_ipd.c
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / mips / cavium / dev / rgmii / octeon_ipd.c
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  * octeon_ipd.c      Input Packet Unit
41  *
42  *------------------------------------------------------------------
43  */
44
45 #include <sys/cdefs.h>
46 __FBSDID("$FreeBSD$");
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50
51 #include <mips/cavium/octeon_pcmap_regs.h>
52 #include "octeon_ipd.h"
53
54 /*
55  * octeon_ipd_enable
56  *
57  * enable ipd
58  */
59 void octeon_ipd_enable (void)
60 {
61     octeon_ipd_ctl_status_t octeon_ipd_reg;
62
63     octeon_ipd_reg.word64 = oct_read64(OCTEON_IPD_CTL_STATUS);
64     octeon_ipd_reg.bits.ipd_en = 1;
65     oct_write64(OCTEON_IPD_CTL_STATUS, octeon_ipd_reg.word64);
66 }
67
68
69 /*
70  * octeon_ipd_disable
71  *
72  * disable ipd
73  */
74 void octeon_ipd_disable (void)
75 {
76     octeon_ipd_ctl_status_t octeon_ipd_reg;
77
78     octeon_ipd_reg.word64 = oct_read64(OCTEON_IPD_CTL_STATUS);
79     octeon_ipd_reg.bits.ipd_en = 0;
80     oct_write64(OCTEON_IPD_CTL_STATUS, octeon_ipd_reg.word64);
81 }
82
83
84 /*
85  * octeon_ipd_config
86  *
87  * Configure IPD
88  *
89  * mbuff_size Packets buffer size in 8 byte words
90  * first_mbuff_skip
91  *                   Number of 8 byte words to skip in the first buffer
92  * not_first_mbuff_skip
93  *                   Number of 8 byte words to skip in each following buffer
94  * first_back Must be same as first_mbuff_skip / Cache_Line_size
95  * second_back
96  *                   Must be same as not_first_mbuff_skip / Cache_Line_Size
97  * wqe_fpa_pool
98  *                   FPA pool to get work entries from
99  * cache_mode
100  * back_pres_enable_flag
101  *                   Enable or disable port back pressure
102  */
103 void octeon_ipd_config (u_int mbuff_size,
104                         u_int first_mbuff_skip,
105                         u_int not_first_mbuff_skip,
106                         u_int first_back,
107                         u_int second_back,
108                         u_int wqe_fpa_pool,
109                         octeon_ipd_mode_t cache_mode,
110                         u_int back_pres_enable_flag)
111 {
112     octeon_ipd_mbuff_first_skip_t first_skip;
113     octeon_ipd_mbuff_not_first_skip_t not_first_skip;
114     octeon_ipd_mbuff_size_t size;
115     octeon_ipd_first_next_ptr_back_t first_back_struct;
116     octeon_ipd_second_next_ptr_back_t second_back_struct;
117     octeon_ipd_wqe_fpa_pool_t wqe_pool;
118     octeon_ipd_ctl_status_t octeon_ipd_ctl_reg;
119
120     first_skip.word64 = 0;
121     first_skip.bits.skip_sz = first_mbuff_skip;
122     oct_write64(OCTEON_IPD_1ST_MBUFF_SKIP, first_skip.word64);
123
124     not_first_skip.word64 = 0;
125     not_first_skip.bits.skip_sz = not_first_mbuff_skip;
126     oct_write64(OCTEON_IPD_NOT_1ST_MBUFF_SKIP, not_first_skip.word64);
127
128     size.word64 = 0;
129     size.bits.mb_size = mbuff_size;
130     oct_write64(OCTEON_IPD_PACKET_MBUFF_SIZE, size.word64);
131
132     first_back_struct.word64 = 0;
133     first_back_struct.bits.back = first_back;
134     oct_write64(OCTEON_IPD_1ST_NEXT_PTR_BACK, first_back_struct.word64);
135
136     second_back_struct.word64 = 0;
137     second_back_struct.bits.back = second_back;
138     oct_write64(OCTEON_IPD_2ND_NEXT_PTR_BACK, second_back_struct.word64);
139
140     wqe_pool.word64 = 0;
141     wqe_pool.bits.wqe_pool = wqe_fpa_pool;
142     oct_write64(OCTEON_IPD_WQE_FPA_QUEUE, wqe_pool.word64);
143
144     octeon_ipd_ctl_reg.word64 = 0;
145     octeon_ipd_ctl_reg.bits.opc_mode = cache_mode;
146     octeon_ipd_ctl_reg.bits.pbp_en = back_pres_enable_flag;
147     oct_write64(OCTEON_IPD_CTL_STATUS, octeon_ipd_ctl_reg.word64);
148 }