cvmx-pko.h 19 KB

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