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