Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cvmx-pko.h
Go to the documentation of this file.
1 /***********************license start***************
2  * Author: Cavium Networks
3  *
4  * Contact: [email protected]
5  * This file is part of the OCTEON SDK
6  *
7  * Copyright (c) 2003-2008 Cavium Networks
8  *
9  * This file is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License, Version 2, as
11  * published by the Free Software Foundation.
12  *
13  * This file is distributed in the hope that it will be useful, but
14  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16  * NONINFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this file; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  * or visit http://www.gnu.org/licenses/.
23  *
24  * This file may also be available under a different license from Cavium.
25  * Contact Cavium Networks for more information
26  ***********************license end**************************************/
27 
58 #ifndef __CVMX_PKO_H__
59 #define __CVMX_PKO_H__
60 
61 #include <asm/octeon/cvmx-fpa.h>
62 #include <asm/octeon/cvmx-pow.h>
65 
66 /* Adjust the command buffer size by 1 word so that in the case of using only
67  * two word PKO commands no command words stradle buffers. The useful values
68  * for this are 0 and 1. */
69 #define CVMX_PKO_COMMAND_BUFFER_SIZE_ADJUST (1)
70 
71 #define CVMX_PKO_MAX_OUTPUT_QUEUES_STATIC 256
72 #define CVMX_PKO_MAX_OUTPUT_QUEUES ((OCTEON_IS_MODEL(OCTEON_CN31XX) || \
73  OCTEON_IS_MODEL(OCTEON_CN3010) || OCTEON_IS_MODEL(OCTEON_CN3005) || \
74  OCTEON_IS_MODEL(OCTEON_CN50XX)) ? 32 : \
75  (OCTEON_IS_MODEL(OCTEON_CN58XX) || \
76  OCTEON_IS_MODEL(OCTEON_CN56XX)) ? 256 : 128)
77 #define CVMX_PKO_NUM_OUTPUT_PORTS 40
78 /* use this for queues that are not used */
79 #define CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID 63
80 #define CVMX_PKO_QUEUE_STATIC_PRIORITY 9
81 #define CVMX_PKO_ILLEGAL_QUEUE 0xFFFF
82 #define CVMX_PKO_MAX_QUEUE_DEPTH 0
83 
84 typedef enum {
93 
97 typedef enum {
98  /*
99  * PKO doesn't do any locking. It is the responsibility of the
100  * application to make sure that no other core is accessing
101  * the same queue at the same time
102  */
104  /*
105  * PKO performs an atomic tagswitch to insure exclusive access
106  * to the output queue. This will maintain packet ordering on
107  * output.
108  */
110  /*
111  * PKO uses the common command queue locks to insure exclusive
112  * access to the output queue. This is a memory based
113  * ll/sc. This is the most portable locking mechanism.
114  */
117 
118 typedef struct {
123 
127 typedef union {
129  struct {
130  /* Must CVMX_IO_SEG */
131  uint64_t mem_space:2;
132  /* Must be zero */
134  /* Must be one */
135  uint64_t is_io:1;
136  /* The ID of the device on the non-coherent bus */
137  uint64_t did:8;
138  /* Must be zero */
140  /* Must be zero */
142  /*
143  * The hardware likes to have the output port in
144  * addition to the output queue,
145  */
147  /*
148  * The output queue to send the packet to (0-127 are
149  * legal)
150  */
152  /* Must be zero */
154  } s;
156 
160 typedef union {
162  struct {
163  /*
164  * The size of the reg1 operation - could be 8, 16,
165  * 32, or 64 bits.
166  */
167  uint64_t size1:2;
168  /*
169  * The size of the reg0 operation - could be 8, 16,
170  * 32, or 64 bits.
171  */
172  uint64_t size0:2;
173  /*
174  * If set, subtract 1, if clear, subtract packet
175  * size.
176  */
177  uint64_t subone1:1;
178  /*
179  * The register, subtract will be done if reg1 is
180  * non-zero.
181  */
183  /* If set, subtract 1, if clear, subtract packet size */
184  uint64_t subone0:1;
185  /* The register, subtract will be done if reg0 is non-zero */
187  /*
188  * When set, interpret segment pointer and segment
189  * bytes in little endian order.
190  */
192  /*
193  * When set, packet data not allocated in L2 cache by
194  * PKO.
195  */
196  uint64_t n2:1;
197  /*
198  * If set and rsp is set, word3 contains a pointer to
199  * a work queue entry.
200  */
201  uint64_t wqp:1;
202  /* If set, the hardware will send a response when done */
204  /*
205  * If set, the supplied pkt_ptr is really a pointer to
206  * a list of pkt_ptr's.
207  */
209  /*
210  * If ipoffp1 is non zero, (ipoffp1-1) is the number
211  * of bytes to IP header, and the hardware will
212  * calculate and insert the UDP/TCP checksum.
213  */
214  uint64_t ipoffp1:7;
215  /*
216  * If set, ignore the I bit (force to zero) from all
217  * pointer structures.
218  */
219  uint64_t ignore_i:1;
220  /*
221  * If clear, the hardware will attempt to free the
222  * buffers containing the packet.
223  */
224  uint64_t dontfree:1;
225  /*
226  * The total number of segs in the packet, if gather
227  * set, also gather list length.
228  */
229  uint64_t segs:6;
230  /* Including L2, but no trailing CRC */
232  } s;
234 
235 /* CSR typedefs have been moved to cvmx-csr-*.h */
236 
240 typedef struct {
241  /* ptr to start of buffer, offset kept in FAU reg */
244 
249 extern void cvmx_pko_initialize_global(void);
250 extern int cvmx_pko_initialize_local(void);
251 
256 extern void cvmx_pko_enable(void);
257 
261 extern void cvmx_pko_disable(void);
262 
267 extern void cvmx_pko_shutdown(void);
268 
281  uint64_t base_queue,
283  const uint64_t priority[]);
284 
295 static inline void cvmx_pko_doorbell(uint64_t port, uint64_t queue,
296  uint64_t len)
297 {
299 
300  ptr.u64 = 0;
301  ptr.s.mem_space = CVMX_IO_SEG;
302  ptr.s.did = CVMX_OCT_DID_PKT_SEND;
303  ptr.s.is_io = 1;
304  ptr.s.port = port;
305  ptr.s.queue = queue;
306  /*
307  * Need to make sure output queue data is in DRAM before
308  * doorbell write.
309  */
310  CVMX_SYNCWS;
311  cvmx_write_io(ptr.u64, len);
312 }
313 
347 static inline void cvmx_pko_send_packet_prepare(uint64_t port, uint64_t queue,
348  cvmx_pko_lock_t use_locking)
349 {
350  if (use_locking == CVMX_PKO_LOCK_ATOMIC_TAG) {
351  /*
352  * Must do a full switch here to handle all cases. We
353  * use a fake WQE pointer, as the POW does not access
354  * this memory. The WQE pointer and group are only
355  * used if this work is descheduled, which is not
356  * supported by the
357  * cvmx_pko_send_packet_prepare/cvmx_pko_send_packet_finish
358  * combination. Note that this is a special case in
359  * which these fake values can be used - this is not a
360  * general technique.
361  */
362  uint32_t tag =
365  (CVMX_TAG_SUBGROUP_MASK & queue);
366  cvmx_pow_tag_sw_full((cvmx_wqe_t *) cvmx_phys_to_ptr(0x80), tag,
368  }
369 }
370 
388 static inline cvmx_pko_status_t cvmx_pko_send_packet_finish(
389  uint64_t port,
390  uint64_t queue,
391  cvmx_pko_command_word0_t pko_command,
392  union cvmx_buf_ptr packet,
393  cvmx_pko_lock_t use_locking)
394 {
396  if (use_locking == CVMX_PKO_LOCK_ATOMIC_TAG)
397  cvmx_pow_tag_sw_wait();
398  result = cvmx_cmd_queue_write2(CVMX_CMD_QUEUE_PKO(queue),
399  (use_locking == CVMX_PKO_LOCK_CMD_QUEUE),
400  pko_command.u64, packet.u64);
401  if (likely(result == CVMX_CMD_QUEUE_SUCCESS)) {
402  cvmx_pko_doorbell(port, queue, 2);
403  return CVMX_PKO_SUCCESS;
404  } else if ((result == CVMX_CMD_QUEUE_NO_MEMORY)
405  || (result == CVMX_CMD_QUEUE_FULL)) {
406  return CVMX_PKO_NO_MEMORY;
407  } else {
408  return CVMX_PKO_INVALID_QUEUE;
409  }
410 }
411 
431 static inline cvmx_pko_status_t cvmx_pko_send_packet_finish3(
432  uint64_t port,
433  uint64_t queue,
434  cvmx_pko_command_word0_t pko_command,
435  union cvmx_buf_ptr packet,
436  uint64_t addr,
437  cvmx_pko_lock_t use_locking)
438 {
440  if (use_locking == CVMX_PKO_LOCK_ATOMIC_TAG)
441  cvmx_pow_tag_sw_wait();
442  result = cvmx_cmd_queue_write3(CVMX_CMD_QUEUE_PKO(queue),
443  (use_locking == CVMX_PKO_LOCK_CMD_QUEUE),
444  pko_command.u64, packet.u64, addr);
445  if (likely(result == CVMX_CMD_QUEUE_SUCCESS)) {
446  cvmx_pko_doorbell(port, queue, 3);
447  return CVMX_PKO_SUCCESS;
448  } else if ((result == CVMX_CMD_QUEUE_NO_MEMORY)
449  || (result == CVMX_CMD_QUEUE_FULL)) {
450  return CVMX_PKO_NO_MEMORY;
451  } else {
452  return CVMX_PKO_INVALID_QUEUE;
453  }
454 }
455 
466 static inline int cvmx_pko_get_base_queue_per_core(int port, int core)
467 {
468 #ifndef CVMX_HELPER_PKO_MAX_PORTS_INTERFACE0
469 #define CVMX_HELPER_PKO_MAX_PORTS_INTERFACE0 16
470 #endif
471 #ifndef CVMX_HELPER_PKO_MAX_PORTS_INTERFACE1
472 #define CVMX_HELPER_PKO_MAX_PORTS_INTERFACE1 16
473 #endif
474 
477  else if (port >= 16 && port < 16 + CVMX_PKO_MAX_PORTS_INTERFACE1)
480  16) *
482  else if ((port >= 32) && (port < 36))
487  32) *
489  else if ((port >= 36) && (port < 40))
494  4 * CVMX_PKO_QUEUES_PER_PORT_PCI + (port -
495  36) *
497  else
498  /* Given the limit on the number of ports we can map to
499  * CVMX_MAX_OUTPUT_QUEUES_STATIC queues (currently 256,
500  * divided among all cores), the remaining unmapped ports
501  * are assigned an illegal queue number */
502  return CVMX_PKO_ILLEGAL_QUEUE;
503 }
504 
512 static inline int cvmx_pko_get_base_queue(int port)
513 {
514  return cvmx_pko_get_base_queue_per_core(port, 0);
515 }
516 
523 static inline int cvmx_pko_get_num_queues(int port)
524 {
525  if (port < 16)
527  else if (port < 32)
529  else if (port < 36)
531  else if (port < 40)
533  else
534  return 0;
535 }
536 
544 static inline void cvmx_pko_get_port_status(uint64_t port_num, uint64_t clear,
546 {
547  union cvmx_pko_reg_read_idx pko_reg_read_idx;
548  union cvmx_pko_mem_count0 pko_mem_count0;
549  union cvmx_pko_mem_count1 pko_mem_count1;
550 
551  pko_reg_read_idx.u64 = 0;
552  pko_reg_read_idx.s.index = port_num;
553  cvmx_write_csr(CVMX_PKO_REG_READ_IDX, pko_reg_read_idx.u64);
554 
555  pko_mem_count0.u64 = cvmx_read_csr(CVMX_PKO_MEM_COUNT0);
556  status->packets = pko_mem_count0.s.count;
557  if (clear) {
558  pko_mem_count0.s.count = port_num;
559  cvmx_write_csr(CVMX_PKO_MEM_COUNT0, pko_mem_count0.u64);
560  }
561 
562  pko_mem_count1.u64 = cvmx_read_csr(CVMX_PKO_MEM_COUNT1);
563  status->octets = pko_mem_count1.s.count;
564  if (clear) {
565  pko_mem_count1.s.count = port_num;
566  cvmx_write_csr(CVMX_PKO_MEM_COUNT1, pko_mem_count1.u64);
567  }
568 
570  union cvmx_pko_mem_debug9 debug9;
571  pko_reg_read_idx.s.index = cvmx_pko_get_base_queue(port_num);
572  cvmx_write_csr(CVMX_PKO_REG_READ_IDX, pko_reg_read_idx.u64);
573  debug9.u64 = cvmx_read_csr(CVMX_PKO_MEM_DEBUG9);
574  status->doorbell = debug9.cn38xx.doorbell;
575  } else {
576  union cvmx_pko_mem_debug8 debug8;
577  pko_reg_read_idx.s.index = cvmx_pko_get_base_queue(port_num);
578  cvmx_write_csr(CVMX_PKO_REG_READ_IDX, pko_reg_read_idx.u64);
579  debug8.u64 = cvmx_read_csr(CVMX_PKO_MEM_DEBUG8);
580  status->doorbell = debug8.cn58xx.doorbell;
581  }
582 }
583 
595 extern int cvmx_pko_rate_limit_packets(int port, int packets_s, int burst);
596 
608 extern int cvmx_pko_rate_limit_bits(int port, uint64_t bits_s, int burst);
609 
610 #endif /* __CVMX_PKO_H__ */