1*4882a593Smuzhiyun /***********************license start***************
2*4882a593Smuzhiyun * Author: Cavium Networks
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Contact: support@caviumnetworks.com
5*4882a593Smuzhiyun * This file is part of the OCTEON SDK
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Copyright (c) 2003-2008 Cavium Networks
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * This file is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun * it under the terms of the GNU General Public License, Version 2, as
11*4882a593Smuzhiyun * published by the Free Software Foundation.
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * This file is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15*4882a593Smuzhiyun * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16*4882a593Smuzhiyun * NONINFRINGEMENT. See the GNU General Public License for more
17*4882a593Smuzhiyun * details.
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License
20*4882a593Smuzhiyun * along with this file; if not, write to the Free Software
21*4882a593Smuzhiyun * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22*4882a593Smuzhiyun * or visit http://www.gnu.org/licenses/.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * This file may also be available under a different license from Cavium.
25*4882a593Smuzhiyun * Contact Cavium Networks for more information
26*4882a593Smuzhiyun ***********************license end**************************************/
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /**
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * Interface to the hardware Packet Output unit.
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun * Starting with SDK 1.7.0, the PKO output functions now support
33*4882a593Smuzhiyun * two types of locking. CVMX_PKO_LOCK_ATOMIC_TAG continues to
34*4882a593Smuzhiyun * function similarly to previous SDKs by using POW atomic tags
35*4882a593Smuzhiyun * to preserve ordering and exclusivity. As a new option, you
36*4882a593Smuzhiyun * can now pass CVMX_PKO_LOCK_CMD_QUEUE which uses a ll/sc
37*4882a593Smuzhiyun * memory based locking instead. This locking has the advantage
38*4882a593Smuzhiyun * of not affecting the tag state but doesn't preserve packet
39*4882a593Smuzhiyun * ordering. CVMX_PKO_LOCK_CMD_QUEUE is appropriate in most
40*4882a593Smuzhiyun * generic code while CVMX_PKO_LOCK_CMD_QUEUE should be used
41*4882a593Smuzhiyun * with hand tuned fast path code.
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * Some of other SDK differences visible to the command queuing:
44*4882a593Smuzhiyun * - PKO indexes are no longer stored in the FAU. A large
45*4882a593Smuzhiyun * percentage of the FAU register block used to be tied up
46*4882a593Smuzhiyun * maintaining PKO queue pointers. These are now stored in a
47*4882a593Smuzhiyun * global named block.
48*4882a593Smuzhiyun * - The PKO <b>use_locking</b> parameter can now have a global
49*4882a593Smuzhiyun * effect. Since all application use the same named block,
50*4882a593Smuzhiyun * queue locking correctly applies across all operating
51*4882a593Smuzhiyun * systems when using CVMX_PKO_LOCK_CMD_QUEUE.
52*4882a593Smuzhiyun * - PKO 3 word commands are now supported. Use
53*4882a593Smuzhiyun * cvmx_pko_send_packet_finish3().
54*4882a593Smuzhiyun *
55*4882a593Smuzhiyun */
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun #ifndef __CVMX_PKO_H__
58*4882a593Smuzhiyun #define __CVMX_PKO_H__
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun #include <asm/octeon/cvmx-fpa.h>
61*4882a593Smuzhiyun #include <asm/octeon/cvmx-pow.h>
62*4882a593Smuzhiyun #include <asm/octeon/cvmx-cmd-queue.h>
63*4882a593Smuzhiyun #include <asm/octeon/cvmx-pko-defs.h>
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /* Adjust the command buffer size by 1 word so that in the case of using only
66*4882a593Smuzhiyun * two word PKO commands no command words stradle buffers. The useful values
67*4882a593Smuzhiyun * for this are 0 and 1. */
68*4882a593Smuzhiyun #define CVMX_PKO_COMMAND_BUFFER_SIZE_ADJUST (1)
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun #define CVMX_PKO_MAX_OUTPUT_QUEUES_STATIC 256
71*4882a593Smuzhiyun #define CVMX_PKO_MAX_OUTPUT_QUEUES ((OCTEON_IS_MODEL(OCTEON_CN31XX) || \
72*4882a593Smuzhiyun OCTEON_IS_MODEL(OCTEON_CN3010) || OCTEON_IS_MODEL(OCTEON_CN3005) || \
73*4882a593Smuzhiyun OCTEON_IS_MODEL(OCTEON_CN50XX)) ? 32 : \
74*4882a593Smuzhiyun (OCTEON_IS_MODEL(OCTEON_CN58XX) || \
75*4882a593Smuzhiyun OCTEON_IS_MODEL(OCTEON_CN56XX)) ? 256 : 128)
76*4882a593Smuzhiyun #define CVMX_PKO_NUM_OUTPUT_PORTS 40
77*4882a593Smuzhiyun /* use this for queues that are not used */
78*4882a593Smuzhiyun #define CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID 63
79*4882a593Smuzhiyun #define CVMX_PKO_QUEUE_STATIC_PRIORITY 9
80*4882a593Smuzhiyun #define CVMX_PKO_ILLEGAL_QUEUE 0xFFFF
81*4882a593Smuzhiyun #define CVMX_PKO_MAX_QUEUE_DEPTH 0
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun typedef enum {
84*4882a593Smuzhiyun CVMX_PKO_SUCCESS,
85*4882a593Smuzhiyun CVMX_PKO_INVALID_PORT,
86*4882a593Smuzhiyun CVMX_PKO_INVALID_QUEUE,
87*4882a593Smuzhiyun CVMX_PKO_INVALID_PRIORITY,
88*4882a593Smuzhiyun CVMX_PKO_NO_MEMORY,
89*4882a593Smuzhiyun CVMX_PKO_PORT_ALREADY_SETUP,
90*4882a593Smuzhiyun CVMX_PKO_CMD_QUEUE_INIT_ERROR
91*4882a593Smuzhiyun } cvmx_pko_status_t;
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun /**
94*4882a593Smuzhiyun * This enumeration represents the differnet locking modes supported by PKO.
95*4882a593Smuzhiyun */
96*4882a593Smuzhiyun typedef enum {
97*4882a593Smuzhiyun /*
98*4882a593Smuzhiyun * PKO doesn't do any locking. It is the responsibility of the
99*4882a593Smuzhiyun * application to make sure that no other core is accessing
100*4882a593Smuzhiyun * the same queue at the same time
101*4882a593Smuzhiyun */
102*4882a593Smuzhiyun CVMX_PKO_LOCK_NONE = 0,
103*4882a593Smuzhiyun /*
104*4882a593Smuzhiyun * PKO performs an atomic tagswitch to insure exclusive access
105*4882a593Smuzhiyun * to the output queue. This will maintain packet ordering on
106*4882a593Smuzhiyun * output.
107*4882a593Smuzhiyun */
108*4882a593Smuzhiyun CVMX_PKO_LOCK_ATOMIC_TAG = 1,
109*4882a593Smuzhiyun /*
110*4882a593Smuzhiyun * PKO uses the common command queue locks to insure exclusive
111*4882a593Smuzhiyun * access to the output queue. This is a memory based
112*4882a593Smuzhiyun * ll/sc. This is the most portable locking mechanism.
113*4882a593Smuzhiyun */
114*4882a593Smuzhiyun CVMX_PKO_LOCK_CMD_QUEUE = 2,
115*4882a593Smuzhiyun } cvmx_pko_lock_t;
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun typedef struct {
118*4882a593Smuzhiyun uint32_t packets;
119*4882a593Smuzhiyun uint64_t octets;
120*4882a593Smuzhiyun uint64_t doorbell;
121*4882a593Smuzhiyun } cvmx_pko_port_status_t;
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun /**
124*4882a593Smuzhiyun * This structure defines the address to use on a packet enqueue
125*4882a593Smuzhiyun */
126*4882a593Smuzhiyun typedef union {
127*4882a593Smuzhiyun uint64_t u64;
128*4882a593Smuzhiyun struct {
129*4882a593Smuzhiyun #ifdef __BIG_ENDIAN_BITFIELD
130*4882a593Smuzhiyun /* Must CVMX_IO_SEG */
131*4882a593Smuzhiyun uint64_t mem_space:2;
132*4882a593Smuzhiyun /* Must be zero */
133*4882a593Smuzhiyun uint64_t reserved:13;
134*4882a593Smuzhiyun /* Must be one */
135*4882a593Smuzhiyun uint64_t is_io:1;
136*4882a593Smuzhiyun /* The ID of the device on the non-coherent bus */
137*4882a593Smuzhiyun uint64_t did:8;
138*4882a593Smuzhiyun /* Must be zero */
139*4882a593Smuzhiyun uint64_t reserved2:4;
140*4882a593Smuzhiyun /* Must be zero */
141*4882a593Smuzhiyun uint64_t reserved3:18;
142*4882a593Smuzhiyun /*
143*4882a593Smuzhiyun * The hardware likes to have the output port in
144*4882a593Smuzhiyun * addition to the output queue,
145*4882a593Smuzhiyun */
146*4882a593Smuzhiyun uint64_t port:6;
147*4882a593Smuzhiyun /*
148*4882a593Smuzhiyun * The output queue to send the packet to (0-127 are
149*4882a593Smuzhiyun * legal)
150*4882a593Smuzhiyun */
151*4882a593Smuzhiyun uint64_t queue:9;
152*4882a593Smuzhiyun /* Must be zero */
153*4882a593Smuzhiyun uint64_t reserved4:3;
154*4882a593Smuzhiyun #else
155*4882a593Smuzhiyun uint64_t reserved4:3;
156*4882a593Smuzhiyun uint64_t queue:9;
157*4882a593Smuzhiyun uint64_t port:9;
158*4882a593Smuzhiyun uint64_t reserved3:15;
159*4882a593Smuzhiyun uint64_t reserved2:4;
160*4882a593Smuzhiyun uint64_t did:8;
161*4882a593Smuzhiyun uint64_t is_io:1;
162*4882a593Smuzhiyun uint64_t reserved:13;
163*4882a593Smuzhiyun uint64_t mem_space:2;
164*4882a593Smuzhiyun #endif
165*4882a593Smuzhiyun } s;
166*4882a593Smuzhiyun } cvmx_pko_doorbell_address_t;
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun /**
169*4882a593Smuzhiyun * Structure of the first packet output command word.
170*4882a593Smuzhiyun */
171*4882a593Smuzhiyun union cvmx_pko_command_word0 {
172*4882a593Smuzhiyun uint64_t u64;
173*4882a593Smuzhiyun struct {
174*4882a593Smuzhiyun #ifdef __BIG_ENDIAN_BITFIELD
175*4882a593Smuzhiyun /*
176*4882a593Smuzhiyun * The size of the reg1 operation - could be 8, 16,
177*4882a593Smuzhiyun * 32, or 64 bits.
178*4882a593Smuzhiyun */
179*4882a593Smuzhiyun uint64_t size1:2;
180*4882a593Smuzhiyun /*
181*4882a593Smuzhiyun * The size of the reg0 operation - could be 8, 16,
182*4882a593Smuzhiyun * 32, or 64 bits.
183*4882a593Smuzhiyun */
184*4882a593Smuzhiyun uint64_t size0:2;
185*4882a593Smuzhiyun /*
186*4882a593Smuzhiyun * If set, subtract 1, if clear, subtract packet
187*4882a593Smuzhiyun * size.
188*4882a593Smuzhiyun */
189*4882a593Smuzhiyun uint64_t subone1:1;
190*4882a593Smuzhiyun /*
191*4882a593Smuzhiyun * The register, subtract will be done if reg1 is
192*4882a593Smuzhiyun * non-zero.
193*4882a593Smuzhiyun */
194*4882a593Smuzhiyun uint64_t reg1:11;
195*4882a593Smuzhiyun /* If set, subtract 1, if clear, subtract packet size */
196*4882a593Smuzhiyun uint64_t subone0:1;
197*4882a593Smuzhiyun /* The register, subtract will be done if reg0 is non-zero */
198*4882a593Smuzhiyun uint64_t reg0:11;
199*4882a593Smuzhiyun /*
200*4882a593Smuzhiyun * When set, interpret segment pointer and segment
201*4882a593Smuzhiyun * bytes in little endian order.
202*4882a593Smuzhiyun */
203*4882a593Smuzhiyun uint64_t le:1;
204*4882a593Smuzhiyun /*
205*4882a593Smuzhiyun * When set, packet data not allocated in L2 cache by
206*4882a593Smuzhiyun * PKO.
207*4882a593Smuzhiyun */
208*4882a593Smuzhiyun uint64_t n2:1;
209*4882a593Smuzhiyun /*
210*4882a593Smuzhiyun * If set and rsp is set, word3 contains a pointer to
211*4882a593Smuzhiyun * a work queue entry.
212*4882a593Smuzhiyun */
213*4882a593Smuzhiyun uint64_t wqp:1;
214*4882a593Smuzhiyun /* If set, the hardware will send a response when done */
215*4882a593Smuzhiyun uint64_t rsp:1;
216*4882a593Smuzhiyun /*
217*4882a593Smuzhiyun * If set, the supplied pkt_ptr is really a pointer to
218*4882a593Smuzhiyun * a list of pkt_ptr's.
219*4882a593Smuzhiyun */
220*4882a593Smuzhiyun uint64_t gather:1;
221*4882a593Smuzhiyun /*
222*4882a593Smuzhiyun * If ipoffp1 is non zero, (ipoffp1-1) is the number
223*4882a593Smuzhiyun * of bytes to IP header, and the hardware will
224*4882a593Smuzhiyun * calculate and insert the UDP/TCP checksum.
225*4882a593Smuzhiyun */
226*4882a593Smuzhiyun uint64_t ipoffp1:7;
227*4882a593Smuzhiyun /*
228*4882a593Smuzhiyun * If set, ignore the I bit (force to zero) from all
229*4882a593Smuzhiyun * pointer structures.
230*4882a593Smuzhiyun */
231*4882a593Smuzhiyun uint64_t ignore_i:1;
232*4882a593Smuzhiyun /*
233*4882a593Smuzhiyun * If clear, the hardware will attempt to free the
234*4882a593Smuzhiyun * buffers containing the packet.
235*4882a593Smuzhiyun */
236*4882a593Smuzhiyun uint64_t dontfree:1;
237*4882a593Smuzhiyun /*
238*4882a593Smuzhiyun * The total number of segs in the packet, if gather
239*4882a593Smuzhiyun * set, also gather list length.
240*4882a593Smuzhiyun */
241*4882a593Smuzhiyun uint64_t segs:6;
242*4882a593Smuzhiyun /* Including L2, but no trailing CRC */
243*4882a593Smuzhiyun uint64_t total_bytes:16;
244*4882a593Smuzhiyun #else
245*4882a593Smuzhiyun uint64_t total_bytes:16;
246*4882a593Smuzhiyun uint64_t segs:6;
247*4882a593Smuzhiyun uint64_t dontfree:1;
248*4882a593Smuzhiyun uint64_t ignore_i:1;
249*4882a593Smuzhiyun uint64_t ipoffp1:7;
250*4882a593Smuzhiyun uint64_t gather:1;
251*4882a593Smuzhiyun uint64_t rsp:1;
252*4882a593Smuzhiyun uint64_t wqp:1;
253*4882a593Smuzhiyun uint64_t n2:1;
254*4882a593Smuzhiyun uint64_t le:1;
255*4882a593Smuzhiyun uint64_t reg0:11;
256*4882a593Smuzhiyun uint64_t subone0:1;
257*4882a593Smuzhiyun uint64_t reg1:11;
258*4882a593Smuzhiyun uint64_t subone1:1;
259*4882a593Smuzhiyun uint64_t size0:2;
260*4882a593Smuzhiyun uint64_t size1:2;
261*4882a593Smuzhiyun #endif
262*4882a593Smuzhiyun } s;
263*4882a593Smuzhiyun };
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun /* CSR typedefs have been moved to cvmx-csr-*.h */
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun /**
268*4882a593Smuzhiyun * Definition of internal state for Packet output processing
269*4882a593Smuzhiyun */
270*4882a593Smuzhiyun typedef struct {
271*4882a593Smuzhiyun /* ptr to start of buffer, offset kept in FAU reg */
272*4882a593Smuzhiyun uint64_t *start_ptr;
273*4882a593Smuzhiyun } cvmx_pko_state_elem_t;
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun /**
276*4882a593Smuzhiyun * Call before any other calls to initialize the packet
277*4882a593Smuzhiyun * output system.
278*4882a593Smuzhiyun */
279*4882a593Smuzhiyun extern void cvmx_pko_initialize_global(void);
280*4882a593Smuzhiyun extern int cvmx_pko_initialize_local(void);
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun /**
283*4882a593Smuzhiyun * Enables the packet output hardware. It must already be
284*4882a593Smuzhiyun * configured.
285*4882a593Smuzhiyun */
286*4882a593Smuzhiyun extern void cvmx_pko_enable(void);
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun /**
289*4882a593Smuzhiyun * Disables the packet output. Does not affect any configuration.
290*4882a593Smuzhiyun */
291*4882a593Smuzhiyun extern void cvmx_pko_disable(void);
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun /**
294*4882a593Smuzhiyun * Shutdown and free resources required by packet output.
295*4882a593Smuzhiyun */
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun extern void cvmx_pko_shutdown(void);
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun /**
300*4882a593Smuzhiyun * Configure a output port and the associated queues for use.
301*4882a593Smuzhiyun *
302*4882a593Smuzhiyun * @port: Port to configure.
303*4882a593Smuzhiyun * @base_queue: First queue number to associate with this port.
304*4882a593Smuzhiyun * @num_queues: Number of queues t oassociate with this port
305*4882a593Smuzhiyun * @priority: Array of priority levels for each queue. Values are
306*4882a593Smuzhiyun * allowed to be 1-8. A value of 8 get 8 times the traffic
307*4882a593Smuzhiyun * of a value of 1. There must be num_queues elements in the
308*4882a593Smuzhiyun * array.
309*4882a593Smuzhiyun */
310*4882a593Smuzhiyun extern cvmx_pko_status_t cvmx_pko_config_port(uint64_t port,
311*4882a593Smuzhiyun uint64_t base_queue,
312*4882a593Smuzhiyun uint64_t num_queues,
313*4882a593Smuzhiyun const uint64_t priority[]);
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun /**
316*4882a593Smuzhiyun * Ring the packet output doorbell. This tells the packet
317*4882a593Smuzhiyun * output hardware that "len" command words have been added
318*4882a593Smuzhiyun * to its pending list. This command includes the required
319*4882a593Smuzhiyun * CVMX_SYNCWS before the doorbell ring.
320*4882a593Smuzhiyun *
321*4882a593Smuzhiyun * @port: Port the packet is for
322*4882a593Smuzhiyun * @queue: Queue the packet is for
323*4882a593Smuzhiyun * @len: Length of the command in 64 bit words
324*4882a593Smuzhiyun */
cvmx_pko_doorbell(uint64_t port,uint64_t queue,uint64_t len)325*4882a593Smuzhiyun static inline void cvmx_pko_doorbell(uint64_t port, uint64_t queue,
326*4882a593Smuzhiyun uint64_t len)
327*4882a593Smuzhiyun {
328*4882a593Smuzhiyun cvmx_pko_doorbell_address_t ptr;
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun ptr.u64 = 0;
331*4882a593Smuzhiyun ptr.s.mem_space = CVMX_IO_SEG;
332*4882a593Smuzhiyun ptr.s.did = CVMX_OCT_DID_PKT_SEND;
333*4882a593Smuzhiyun ptr.s.is_io = 1;
334*4882a593Smuzhiyun ptr.s.port = port;
335*4882a593Smuzhiyun ptr.s.queue = queue;
336*4882a593Smuzhiyun /*
337*4882a593Smuzhiyun * Need to make sure output queue data is in DRAM before
338*4882a593Smuzhiyun * doorbell write.
339*4882a593Smuzhiyun */
340*4882a593Smuzhiyun CVMX_SYNCWS;
341*4882a593Smuzhiyun cvmx_write_io(ptr.u64, len);
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun /**
345*4882a593Smuzhiyun * Prepare to send a packet. This may initiate a tag switch to
346*4882a593Smuzhiyun * get exclusive access to the output queue structure, and
347*4882a593Smuzhiyun * performs other prep work for the packet send operation.
348*4882a593Smuzhiyun *
349*4882a593Smuzhiyun * cvmx_pko_send_packet_finish() MUST be called after this function is called,
350*4882a593Smuzhiyun * and must be called with the same port/queue/use_locking arguments.
351*4882a593Smuzhiyun *
352*4882a593Smuzhiyun * The use_locking parameter allows the caller to use three
353*4882a593Smuzhiyun * possible locking modes.
354*4882a593Smuzhiyun * - CVMX_PKO_LOCK_NONE
355*4882a593Smuzhiyun * - PKO doesn't do any locking. It is the responsibility
356*4882a593Smuzhiyun * of the application to make sure that no other core
357*4882a593Smuzhiyun * is accessing the same queue at the same time.
358*4882a593Smuzhiyun * - CVMX_PKO_LOCK_ATOMIC_TAG
359*4882a593Smuzhiyun * - PKO performs an atomic tagswitch to insure exclusive
360*4882a593Smuzhiyun * access to the output queue. This will maintain
361*4882a593Smuzhiyun * packet ordering on output.
362*4882a593Smuzhiyun * - CVMX_PKO_LOCK_CMD_QUEUE
363*4882a593Smuzhiyun * - PKO uses the common command queue locks to insure
364*4882a593Smuzhiyun * exclusive access to the output queue. This is a
365*4882a593Smuzhiyun * memory based ll/sc. This is the most portable
366*4882a593Smuzhiyun * locking mechanism.
367*4882a593Smuzhiyun *
368*4882a593Smuzhiyun * NOTE: If atomic locking is used, the POW entry CANNOT be
369*4882a593Smuzhiyun * descheduled, as it does not contain a valid WQE pointer.
370*4882a593Smuzhiyun *
371*4882a593Smuzhiyun * @port: Port to send it on
372*4882a593Smuzhiyun * @queue: Queue to use
373*4882a593Smuzhiyun * @use_locking: CVMX_PKO_LOCK_NONE, CVMX_PKO_LOCK_ATOMIC_TAG, or
374*4882a593Smuzhiyun * CVMX_PKO_LOCK_CMD_QUEUE
375*4882a593Smuzhiyun */
376*4882a593Smuzhiyun
cvmx_pko_send_packet_prepare(uint64_t port,uint64_t queue,cvmx_pko_lock_t use_locking)377*4882a593Smuzhiyun static inline void cvmx_pko_send_packet_prepare(uint64_t port, uint64_t queue,
378*4882a593Smuzhiyun cvmx_pko_lock_t use_locking)
379*4882a593Smuzhiyun {
380*4882a593Smuzhiyun if (use_locking == CVMX_PKO_LOCK_ATOMIC_TAG) {
381*4882a593Smuzhiyun /*
382*4882a593Smuzhiyun * Must do a full switch here to handle all cases. We
383*4882a593Smuzhiyun * use a fake WQE pointer, as the POW does not access
384*4882a593Smuzhiyun * this memory. The WQE pointer and group are only
385*4882a593Smuzhiyun * used if this work is descheduled, which is not
386*4882a593Smuzhiyun * supported by the
387*4882a593Smuzhiyun * cvmx_pko_send_packet_prepare/cvmx_pko_send_packet_finish
388*4882a593Smuzhiyun * combination. Note that this is a special case in
389*4882a593Smuzhiyun * which these fake values can be used - this is not a
390*4882a593Smuzhiyun * general technique.
391*4882a593Smuzhiyun */
392*4882a593Smuzhiyun uint32_t tag =
393*4882a593Smuzhiyun CVMX_TAG_SW_BITS_INTERNAL << CVMX_TAG_SW_SHIFT |
394*4882a593Smuzhiyun CVMX_TAG_SUBGROUP_PKO << CVMX_TAG_SUBGROUP_SHIFT |
395*4882a593Smuzhiyun (CVMX_TAG_SUBGROUP_MASK & queue);
396*4882a593Smuzhiyun cvmx_pow_tag_sw_full((struct cvmx_wqe *) cvmx_phys_to_ptr(0x80), tag,
397*4882a593Smuzhiyun CVMX_POW_TAG_TYPE_ATOMIC, 0);
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun }
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun /**
402*4882a593Smuzhiyun * Complete packet output. cvmx_pko_send_packet_prepare() must be
403*4882a593Smuzhiyun * called exactly once before this, and the same parameters must be
404*4882a593Smuzhiyun * passed to both cvmx_pko_send_packet_prepare() and
405*4882a593Smuzhiyun * cvmx_pko_send_packet_finish().
406*4882a593Smuzhiyun *
407*4882a593Smuzhiyun * @port: Port to send it on
408*4882a593Smuzhiyun * @queue: Queue to use
409*4882a593Smuzhiyun * @pko_command:
410*4882a593Smuzhiyun * PKO HW command word
411*4882a593Smuzhiyun * @packet: Packet to send
412*4882a593Smuzhiyun * @use_locking: CVMX_PKO_LOCK_NONE, CVMX_PKO_LOCK_ATOMIC_TAG, or
413*4882a593Smuzhiyun * CVMX_PKO_LOCK_CMD_QUEUE
414*4882a593Smuzhiyun *
415*4882a593Smuzhiyun * Returns: CVMX_PKO_SUCCESS on success, or error code on
416*4882a593Smuzhiyun * failure of output
417*4882a593Smuzhiyun */
cvmx_pko_send_packet_finish(uint64_t port,uint64_t queue,union cvmx_pko_command_word0 pko_command,union cvmx_buf_ptr packet,cvmx_pko_lock_t use_locking)418*4882a593Smuzhiyun static inline cvmx_pko_status_t cvmx_pko_send_packet_finish(
419*4882a593Smuzhiyun uint64_t port,
420*4882a593Smuzhiyun uint64_t queue,
421*4882a593Smuzhiyun union cvmx_pko_command_word0 pko_command,
422*4882a593Smuzhiyun union cvmx_buf_ptr packet,
423*4882a593Smuzhiyun cvmx_pko_lock_t use_locking)
424*4882a593Smuzhiyun {
425*4882a593Smuzhiyun cvmx_cmd_queue_result_t result;
426*4882a593Smuzhiyun if (use_locking == CVMX_PKO_LOCK_ATOMIC_TAG)
427*4882a593Smuzhiyun cvmx_pow_tag_sw_wait();
428*4882a593Smuzhiyun result = cvmx_cmd_queue_write2(CVMX_CMD_QUEUE_PKO(queue),
429*4882a593Smuzhiyun (use_locking == CVMX_PKO_LOCK_CMD_QUEUE),
430*4882a593Smuzhiyun pko_command.u64, packet.u64);
431*4882a593Smuzhiyun if (likely(result == CVMX_CMD_QUEUE_SUCCESS)) {
432*4882a593Smuzhiyun cvmx_pko_doorbell(port, queue, 2);
433*4882a593Smuzhiyun return CVMX_PKO_SUCCESS;
434*4882a593Smuzhiyun } else if ((result == CVMX_CMD_QUEUE_NO_MEMORY)
435*4882a593Smuzhiyun || (result == CVMX_CMD_QUEUE_FULL)) {
436*4882a593Smuzhiyun return CVMX_PKO_NO_MEMORY;
437*4882a593Smuzhiyun } else {
438*4882a593Smuzhiyun return CVMX_PKO_INVALID_QUEUE;
439*4882a593Smuzhiyun }
440*4882a593Smuzhiyun }
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun /**
443*4882a593Smuzhiyun * Complete packet output. cvmx_pko_send_packet_prepare() must be
444*4882a593Smuzhiyun * called exactly once before this, and the same parameters must be
445*4882a593Smuzhiyun * passed to both cvmx_pko_send_packet_prepare() and
446*4882a593Smuzhiyun * cvmx_pko_send_packet_finish().
447*4882a593Smuzhiyun *
448*4882a593Smuzhiyun * @port: Port to send it on
449*4882a593Smuzhiyun * @queue: Queue to use
450*4882a593Smuzhiyun * @pko_command:
451*4882a593Smuzhiyun * PKO HW command word
452*4882a593Smuzhiyun * @packet: Packet to send
453*4882a593Smuzhiyun * @addr: Plysical address of a work queue entry or physical address
454*4882a593Smuzhiyun * to zero on complete.
455*4882a593Smuzhiyun * @use_locking: CVMX_PKO_LOCK_NONE, CVMX_PKO_LOCK_ATOMIC_TAG, or
456*4882a593Smuzhiyun * CVMX_PKO_LOCK_CMD_QUEUE
457*4882a593Smuzhiyun *
458*4882a593Smuzhiyun * Returns: CVMX_PKO_SUCCESS on success, or error code on
459*4882a593Smuzhiyun * failure of output
460*4882a593Smuzhiyun */
cvmx_pko_send_packet_finish3(uint64_t port,uint64_t queue,union cvmx_pko_command_word0 pko_command,union cvmx_buf_ptr packet,uint64_t addr,cvmx_pko_lock_t use_locking)461*4882a593Smuzhiyun static inline cvmx_pko_status_t cvmx_pko_send_packet_finish3(
462*4882a593Smuzhiyun uint64_t port,
463*4882a593Smuzhiyun uint64_t queue,
464*4882a593Smuzhiyun union cvmx_pko_command_word0 pko_command,
465*4882a593Smuzhiyun union cvmx_buf_ptr packet,
466*4882a593Smuzhiyun uint64_t addr,
467*4882a593Smuzhiyun cvmx_pko_lock_t use_locking)
468*4882a593Smuzhiyun {
469*4882a593Smuzhiyun cvmx_cmd_queue_result_t result;
470*4882a593Smuzhiyun if (use_locking == CVMX_PKO_LOCK_ATOMIC_TAG)
471*4882a593Smuzhiyun cvmx_pow_tag_sw_wait();
472*4882a593Smuzhiyun result = cvmx_cmd_queue_write3(CVMX_CMD_QUEUE_PKO(queue),
473*4882a593Smuzhiyun (use_locking == CVMX_PKO_LOCK_CMD_QUEUE),
474*4882a593Smuzhiyun pko_command.u64, packet.u64, addr);
475*4882a593Smuzhiyun if (likely(result == CVMX_CMD_QUEUE_SUCCESS)) {
476*4882a593Smuzhiyun cvmx_pko_doorbell(port, queue, 3);
477*4882a593Smuzhiyun return CVMX_PKO_SUCCESS;
478*4882a593Smuzhiyun } else if ((result == CVMX_CMD_QUEUE_NO_MEMORY)
479*4882a593Smuzhiyun || (result == CVMX_CMD_QUEUE_FULL)) {
480*4882a593Smuzhiyun return CVMX_PKO_NO_MEMORY;
481*4882a593Smuzhiyun } else {
482*4882a593Smuzhiyun return CVMX_PKO_INVALID_QUEUE;
483*4882a593Smuzhiyun }
484*4882a593Smuzhiyun }
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun /**
487*4882a593Smuzhiyun * Return the pko output queue associated with a port and a specific core.
488*4882a593Smuzhiyun * In normal mode (PKO lockless operation is disabled), the value returned
489*4882a593Smuzhiyun * is the base queue.
490*4882a593Smuzhiyun *
491*4882a593Smuzhiyun * @port: Port number
492*4882a593Smuzhiyun * @core: Core to get queue for
493*4882a593Smuzhiyun *
494*4882a593Smuzhiyun * Returns Core-specific output queue
495*4882a593Smuzhiyun */
cvmx_pko_get_base_queue_per_core(int port,int core)496*4882a593Smuzhiyun static inline int cvmx_pko_get_base_queue_per_core(int port, int core)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun #ifndef CVMX_HELPER_PKO_MAX_PORTS_INTERFACE0
499*4882a593Smuzhiyun #define CVMX_HELPER_PKO_MAX_PORTS_INTERFACE0 16
500*4882a593Smuzhiyun #endif
501*4882a593Smuzhiyun #ifndef CVMX_HELPER_PKO_MAX_PORTS_INTERFACE1
502*4882a593Smuzhiyun #define CVMX_HELPER_PKO_MAX_PORTS_INTERFACE1 16
503*4882a593Smuzhiyun #endif
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun if (port < CVMX_PKO_MAX_PORTS_INTERFACE0)
506*4882a593Smuzhiyun return port * CVMX_PKO_QUEUES_PER_PORT_INTERFACE0 + core;
507*4882a593Smuzhiyun else if (port >= 16 && port < 16 + CVMX_PKO_MAX_PORTS_INTERFACE1)
508*4882a593Smuzhiyun return CVMX_PKO_MAX_PORTS_INTERFACE0 *
509*4882a593Smuzhiyun CVMX_PKO_QUEUES_PER_PORT_INTERFACE0 + (port -
510*4882a593Smuzhiyun 16) *
511*4882a593Smuzhiyun CVMX_PKO_QUEUES_PER_PORT_INTERFACE1 + core;
512*4882a593Smuzhiyun else if ((port >= 32) && (port < 36))
513*4882a593Smuzhiyun return CVMX_PKO_MAX_PORTS_INTERFACE0 *
514*4882a593Smuzhiyun CVMX_PKO_QUEUES_PER_PORT_INTERFACE0 +
515*4882a593Smuzhiyun CVMX_PKO_MAX_PORTS_INTERFACE1 *
516*4882a593Smuzhiyun CVMX_PKO_QUEUES_PER_PORT_INTERFACE1 + (port -
517*4882a593Smuzhiyun 32) *
518*4882a593Smuzhiyun CVMX_PKO_QUEUES_PER_PORT_PCI;
519*4882a593Smuzhiyun else if ((port >= 36) && (port < 40))
520*4882a593Smuzhiyun return CVMX_PKO_MAX_PORTS_INTERFACE0 *
521*4882a593Smuzhiyun CVMX_PKO_QUEUES_PER_PORT_INTERFACE0 +
522*4882a593Smuzhiyun CVMX_PKO_MAX_PORTS_INTERFACE1 *
523*4882a593Smuzhiyun CVMX_PKO_QUEUES_PER_PORT_INTERFACE1 +
524*4882a593Smuzhiyun 4 * CVMX_PKO_QUEUES_PER_PORT_PCI + (port -
525*4882a593Smuzhiyun 36) *
526*4882a593Smuzhiyun CVMX_PKO_QUEUES_PER_PORT_LOOP;
527*4882a593Smuzhiyun else
528*4882a593Smuzhiyun /* Given the limit on the number of ports we can map to
529*4882a593Smuzhiyun * CVMX_MAX_OUTPUT_QUEUES_STATIC queues (currently 256,
530*4882a593Smuzhiyun * divided among all cores), the remaining unmapped ports
531*4882a593Smuzhiyun * are assigned an illegal queue number */
532*4882a593Smuzhiyun return CVMX_PKO_ILLEGAL_QUEUE;
533*4882a593Smuzhiyun }
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun /**
536*4882a593Smuzhiyun * For a given port number, return the base pko output queue
537*4882a593Smuzhiyun * for the port.
538*4882a593Smuzhiyun *
539*4882a593Smuzhiyun * @port: Port number
540*4882a593Smuzhiyun * Returns Base output queue
541*4882a593Smuzhiyun */
cvmx_pko_get_base_queue(int port)542*4882a593Smuzhiyun static inline int cvmx_pko_get_base_queue(int port)
543*4882a593Smuzhiyun {
544*4882a593Smuzhiyun if (OCTEON_IS_MODEL(OCTEON_CN68XX))
545*4882a593Smuzhiyun return port;
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun return cvmx_pko_get_base_queue_per_core(port, 0);
548*4882a593Smuzhiyun }
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun /**
551*4882a593Smuzhiyun * For a given port number, return the number of pko output queues.
552*4882a593Smuzhiyun *
553*4882a593Smuzhiyun * @port: Port number
554*4882a593Smuzhiyun * Returns Number of output queues
555*4882a593Smuzhiyun */
cvmx_pko_get_num_queues(int port)556*4882a593Smuzhiyun static inline int cvmx_pko_get_num_queues(int port)
557*4882a593Smuzhiyun {
558*4882a593Smuzhiyun if (port < 16)
559*4882a593Smuzhiyun return CVMX_PKO_QUEUES_PER_PORT_INTERFACE0;
560*4882a593Smuzhiyun else if (port < 32)
561*4882a593Smuzhiyun return CVMX_PKO_QUEUES_PER_PORT_INTERFACE1;
562*4882a593Smuzhiyun else if (port < 36)
563*4882a593Smuzhiyun return CVMX_PKO_QUEUES_PER_PORT_PCI;
564*4882a593Smuzhiyun else if (port < 40)
565*4882a593Smuzhiyun return CVMX_PKO_QUEUES_PER_PORT_LOOP;
566*4882a593Smuzhiyun else
567*4882a593Smuzhiyun return 0;
568*4882a593Smuzhiyun }
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun /**
571*4882a593Smuzhiyun * Get the status counters for a port.
572*4882a593Smuzhiyun *
573*4882a593Smuzhiyun * @port_num: Port number to get statistics for.
574*4882a593Smuzhiyun * @clear: Set to 1 to clear the counters after they are read
575*4882a593Smuzhiyun * @status: Where to put the results.
576*4882a593Smuzhiyun */
cvmx_pko_get_port_status(uint64_t port_num,uint64_t clear,cvmx_pko_port_status_t * status)577*4882a593Smuzhiyun static inline void cvmx_pko_get_port_status(uint64_t port_num, uint64_t clear,
578*4882a593Smuzhiyun cvmx_pko_port_status_t *status)
579*4882a593Smuzhiyun {
580*4882a593Smuzhiyun union cvmx_pko_reg_read_idx pko_reg_read_idx;
581*4882a593Smuzhiyun union cvmx_pko_mem_count0 pko_mem_count0;
582*4882a593Smuzhiyun union cvmx_pko_mem_count1 pko_mem_count1;
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun pko_reg_read_idx.u64 = 0;
585*4882a593Smuzhiyun pko_reg_read_idx.s.index = port_num;
586*4882a593Smuzhiyun cvmx_write_csr(CVMX_PKO_REG_READ_IDX, pko_reg_read_idx.u64);
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun pko_mem_count0.u64 = cvmx_read_csr(CVMX_PKO_MEM_COUNT0);
589*4882a593Smuzhiyun status->packets = pko_mem_count0.s.count;
590*4882a593Smuzhiyun if (clear) {
591*4882a593Smuzhiyun pko_mem_count0.s.count = port_num;
592*4882a593Smuzhiyun cvmx_write_csr(CVMX_PKO_MEM_COUNT0, pko_mem_count0.u64);
593*4882a593Smuzhiyun }
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun pko_mem_count1.u64 = cvmx_read_csr(CVMX_PKO_MEM_COUNT1);
596*4882a593Smuzhiyun status->octets = pko_mem_count1.s.count;
597*4882a593Smuzhiyun if (clear) {
598*4882a593Smuzhiyun pko_mem_count1.s.count = port_num;
599*4882a593Smuzhiyun cvmx_write_csr(CVMX_PKO_MEM_COUNT1, pko_mem_count1.u64);
600*4882a593Smuzhiyun }
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun if (OCTEON_IS_MODEL(OCTEON_CN3XXX)) {
603*4882a593Smuzhiyun union cvmx_pko_mem_debug9 debug9;
604*4882a593Smuzhiyun pko_reg_read_idx.s.index = cvmx_pko_get_base_queue(port_num);
605*4882a593Smuzhiyun cvmx_write_csr(CVMX_PKO_REG_READ_IDX, pko_reg_read_idx.u64);
606*4882a593Smuzhiyun debug9.u64 = cvmx_read_csr(CVMX_PKO_MEM_DEBUG9);
607*4882a593Smuzhiyun status->doorbell = debug9.cn38xx.doorbell;
608*4882a593Smuzhiyun } else {
609*4882a593Smuzhiyun union cvmx_pko_mem_debug8 debug8;
610*4882a593Smuzhiyun pko_reg_read_idx.s.index = cvmx_pko_get_base_queue(port_num);
611*4882a593Smuzhiyun cvmx_write_csr(CVMX_PKO_REG_READ_IDX, pko_reg_read_idx.u64);
612*4882a593Smuzhiyun debug8.u64 = cvmx_read_csr(CVMX_PKO_MEM_DEBUG8);
613*4882a593Smuzhiyun status->doorbell = debug8.cn50xx.doorbell;
614*4882a593Smuzhiyun }
615*4882a593Smuzhiyun }
616*4882a593Smuzhiyun
617*4882a593Smuzhiyun /**
618*4882a593Smuzhiyun * Rate limit a PKO port to a max packets/sec. This function is only
619*4882a593Smuzhiyun * supported on CN57XX, CN56XX, CN55XX, and CN54XX.
620*4882a593Smuzhiyun *
621*4882a593Smuzhiyun * @port: Port to rate limit
622*4882a593Smuzhiyun * @packets_s: Maximum packet/sec
623*4882a593Smuzhiyun * @burst: Maximum number of packets to burst in a row before rate
624*4882a593Smuzhiyun * limiting cuts in.
625*4882a593Smuzhiyun *
626*4882a593Smuzhiyun * Returns Zero on success, negative on failure
627*4882a593Smuzhiyun */
628*4882a593Smuzhiyun extern int cvmx_pko_rate_limit_packets(int port, int packets_s, int burst);
629*4882a593Smuzhiyun
630*4882a593Smuzhiyun /**
631*4882a593Smuzhiyun * Rate limit a PKO port to a max bits/sec. This function is only
632*4882a593Smuzhiyun * supported on CN57XX, CN56XX, CN55XX, and CN54XX.
633*4882a593Smuzhiyun *
634*4882a593Smuzhiyun * @port: Port to rate limit
635*4882a593Smuzhiyun * @bits_s: PKO rate limit in bits/sec
636*4882a593Smuzhiyun * @burst: Maximum number of bits to burst before rate
637*4882a593Smuzhiyun * limiting cuts in.
638*4882a593Smuzhiyun *
639*4882a593Smuzhiyun * Returns Zero on success, negative on failure
640*4882a593Smuzhiyun */
641*4882a593Smuzhiyun extern int cvmx_pko_rate_limit_bits(int port, uint64_t bits_s, int burst);
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun #endif /* __CVMX_PKO_H__ */
644