1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include <asm/octeon/octeon.h>
33
34#include <asm/octeon/cvmx-config.h>
35#include <asm/octeon/cvmx-pko.h>
36#include <asm/octeon/cvmx-helper.h>
37
38
39
40
41
42static int __cvmx_pko_int(int interface, int index)
43{
44 switch (interface) {
45 case 0:
46 return index;
47 case 1:
48 return 4;
49 case 2:
50 return index + 0x08;
51 case 3:
52 return index + 0x0c;
53 case 4:
54 return index + 0x10;
55 case 5:
56 return 0x1c;
57 case 6:
58 return 0x1d;
59 case 7:
60 return 0x1e;
61 case 8:
62 return 0x1f;
63 default:
64 return -1;
65 }
66}
67
68static void __cvmx_pko_iport_config(int pko_port)
69{
70 int queue;
71 const int num_queues = 1;
72 const int base_queue = pko_port;
73 const int static_priority_end = 1;
74 const int static_priority_base = 1;
75
76 for (queue = 0; queue < num_queues; queue++) {
77 union cvmx_pko_mem_iqueue_ptrs config;
78 cvmx_cmd_queue_result_t cmd_res;
79 uint64_t *buf_ptr;
80
81 config.u64 = 0;
82 config.s.index = queue;
83 config.s.qid = base_queue + queue;
84 config.s.ipid = pko_port;
85 config.s.tail = (queue == (num_queues - 1));
86 config.s.s_tail = (queue == static_priority_end);
87 config.s.static_p = (static_priority_base >= 0);
88 config.s.static_q = (queue <= static_priority_end);
89 config.s.qos_mask = 0xff;
90
91 cmd_res = cvmx_cmd_queue_initialize(
92 CVMX_CMD_QUEUE_PKO(base_queue + queue),
93 CVMX_PKO_MAX_QUEUE_DEPTH,
94 CVMX_FPA_OUTPUT_BUFFER_POOL,
95 (CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE -
96 CVMX_PKO_COMMAND_BUFFER_SIZE_ADJUST * 8));
97
98 WARN(cmd_res,
99 "%s: cmd_res=%d pko_port=%d base_queue=%d num_queues=%d queue=%d\n",
100 __func__, (int)cmd_res, pko_port, base_queue,
101 num_queues, queue);
102
103 buf_ptr = (uint64_t *)cvmx_cmd_queue_buffer(
104 CVMX_CMD_QUEUE_PKO(base_queue + queue));
105 config.s.buf_ptr = cvmx_ptr_to_phys(buf_ptr) >> 7;
106 CVMX_SYNCWS;
107 cvmx_write_csr(CVMX_PKO_MEM_IQUEUE_PTRS, config.u64);
108 }
109}
110
111static void __cvmx_pko_queue_alloc_o68(void)
112{
113 int port;
114
115 for (port = 0; port < 48; port++)
116 __cvmx_pko_iport_config(port);
117}
118
119static void __cvmx_pko_port_map_o68(void)
120{
121 int port;
122 int interface, index;
123 cvmx_helper_interface_mode_t mode;
124 union cvmx_pko_mem_iport_ptrs config;
125
126
127
128
129 config.u64 = 0;
130 config.s.eid = 31;
131 for (port = 0; port < 128; port++) {
132 config.s.ipid = port;
133 cvmx_write_csr(CVMX_PKO_MEM_IPORT_PTRS, config.u64);
134 }
135
136
137
138
139 for (port = 0; port < 48; port++) {
140 interface = cvmx_helper_get_interface_num(port);
141 index = cvmx_helper_get_interface_index_num(port);
142 mode = cvmx_helper_interface_get_mode(interface);
143 if (mode == CVMX_HELPER_INTERFACE_MODE_DISABLED)
144 continue;
145
146 config.s.ipid = port;
147 config.s.qos_mask = 0xff;
148 config.s.crc = 1;
149 config.s.min_pkt = 1;
150 config.s.intr = __cvmx_pko_int(interface, index);
151 config.s.eid = config.s.intr;
152 config.s.pipe = (mode == CVMX_HELPER_INTERFACE_MODE_LOOP) ?
153 index : port;
154 cvmx_write_csr(CVMX_PKO_MEM_IPORT_PTRS, config.u64);
155 }
156}
157
158static void __cvmx_pko_chip_init(void)
159{
160 int i;
161
162 if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
163 __cvmx_pko_port_map_o68();
164 __cvmx_pko_queue_alloc_o68();
165 return;
166 }
167
168
169
170
171 for (i = 0; i < CVMX_PKO_MAX_OUTPUT_QUEUES; i++) {
172 const uint64_t priority = 8;
173
174 cvmx_pko_config_port(CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID, i, 1,
175 &priority);
176 }
177}
178
179
180
181
182
183
184
185void cvmx_pko_initialize_global(void)
186{
187 union cvmx_pko_reg_cmd_buf config;
188
189
190
191
192
193
194 config.u64 = 0;
195 config.s.pool = CVMX_FPA_OUTPUT_BUFFER_POOL;
196 config.s.size = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE / 8 - 1;
197
198 cvmx_write_csr(CVMX_PKO_REG_CMD_BUF, config.u64);
199
200
201
202
203 __cvmx_pko_chip_init();
204
205
206
207
208
209 if (OCTEON_IS_MODEL(OCTEON_CN38XX) || OCTEON_IS_MODEL(OCTEON_CN58XX)
210 || OCTEON_IS_MODEL(OCTEON_CN56XX)
211 || OCTEON_IS_MODEL(OCTEON_CN52XX)) {
212 int num_interfaces = cvmx_helper_get_number_of_interfaces();
213 int last_port =
214 cvmx_helper_get_last_ipd_port(num_interfaces - 1);
215 int max_queues =
216 cvmx_pko_get_base_queue(last_port) +
217 cvmx_pko_get_num_queues(last_port);
218 if (OCTEON_IS_MODEL(OCTEON_CN38XX)) {
219 if (max_queues <= 32)
220 cvmx_write_csr(CVMX_PKO_REG_QUEUE_MODE, 2);
221 else if (max_queues <= 64)
222 cvmx_write_csr(CVMX_PKO_REG_QUEUE_MODE, 1);
223 } else {
224 if (max_queues <= 64)
225 cvmx_write_csr(CVMX_PKO_REG_QUEUE_MODE, 2);
226 else if (max_queues <= 128)
227 cvmx_write_csr(CVMX_PKO_REG_QUEUE_MODE, 1);
228 }
229 }
230}
231
232
233
234
235
236
237
238
239
240int cvmx_pko_initialize_local(void)
241{
242
243 return 0;
244}
245
246
247
248
249
250void cvmx_pko_enable(void)
251{
252 union cvmx_pko_reg_flags flags;
253
254 flags.u64 = cvmx_read_csr(CVMX_PKO_REG_FLAGS);
255 if (flags.s.ena_pko)
256 cvmx_dprintf
257 ("Warning: Enabling PKO when PKO already enabled.\n");
258
259 flags.s.ena_dwb = 1;
260 flags.s.ena_pko = 1;
261
262
263
264
265 flags.s.store_be = 1;
266 cvmx_write_csr(CVMX_PKO_REG_FLAGS, flags.u64);
267}
268
269
270
271
272void cvmx_pko_disable(void)
273{
274 union cvmx_pko_reg_flags pko_reg_flags;
275 pko_reg_flags.u64 = cvmx_read_csr(CVMX_PKO_REG_FLAGS);
276 pko_reg_flags.s.ena_pko = 0;
277 cvmx_write_csr(CVMX_PKO_REG_FLAGS, pko_reg_flags.u64);
278}
279EXPORT_SYMBOL_GPL(cvmx_pko_disable);
280
281
282
283
284static void __cvmx_pko_reset(void)
285{
286 union cvmx_pko_reg_flags pko_reg_flags;
287 pko_reg_flags.u64 = cvmx_read_csr(CVMX_PKO_REG_FLAGS);
288 pko_reg_flags.s.reset = 1;
289 cvmx_write_csr(CVMX_PKO_REG_FLAGS, pko_reg_flags.u64);
290}
291
292
293
294
295void cvmx_pko_shutdown(void)
296{
297 union cvmx_pko_mem_queue_ptrs config;
298 int queue;
299
300 cvmx_pko_disable();
301
302 for (queue = 0; queue < CVMX_PKO_MAX_OUTPUT_QUEUES; queue++) {
303 config.u64 = 0;
304 config.s.tail = 1;
305 config.s.index = 0;
306 config.s.port = CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID;
307 config.s.queue = queue & 0x7f;
308 config.s.qos_mask = 0;
309 config.s.buf_ptr = 0;
310 if (!OCTEON_IS_MODEL(OCTEON_CN3XXX)) {
311 union cvmx_pko_reg_queue_ptrs1 config1;
312 config1.u64 = 0;
313 config1.s.qid7 = queue >> 7;
314 cvmx_write_csr(CVMX_PKO_REG_QUEUE_PTRS1, config1.u64);
315 }
316 cvmx_write_csr(CVMX_PKO_MEM_QUEUE_PTRS, config.u64);
317 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_PKO(queue));
318 }
319 __cvmx_pko_reset();
320}
321EXPORT_SYMBOL_GPL(cvmx_pko_shutdown);
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340cvmx_pko_status_t cvmx_pko_config_port(uint64_t port, uint64_t base_queue,
341 uint64_t num_queues,
342 const uint64_t priority[])
343{
344 cvmx_pko_status_t result_code;
345 uint64_t queue;
346 union cvmx_pko_mem_queue_ptrs config;
347 union cvmx_pko_reg_queue_ptrs1 config1;
348 int static_priority_base = -1;
349 int static_priority_end = -1;
350
351 if (OCTEON_IS_MODEL(OCTEON_CN68XX))
352 return CVMX_PKO_SUCCESS;
353
354 if ((port >= CVMX_PKO_NUM_OUTPUT_PORTS)
355 && (port != CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID)) {
356 cvmx_dprintf("ERROR: cvmx_pko_config_port: Invalid port %llu\n",
357 (unsigned long long)port);
358 return CVMX_PKO_INVALID_PORT;
359 }
360
361 if (base_queue + num_queues > CVMX_PKO_MAX_OUTPUT_QUEUES) {
362 cvmx_dprintf
363 ("ERROR: cvmx_pko_config_port: Invalid queue range %llu\n",
364 (unsigned long long)(base_queue + num_queues));
365 return CVMX_PKO_INVALID_QUEUE;
366 }
367
368 if (port != CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID) {
369
370
371
372
373
374 for (queue = 0; queue < num_queues; queue++) {
375
376 if (static_priority_base == -1
377 && priority[queue] ==
378 CVMX_PKO_QUEUE_STATIC_PRIORITY)
379 static_priority_base = queue;
380
381 if (static_priority_base != -1
382 && static_priority_end == -1
383 && priority[queue] != CVMX_PKO_QUEUE_STATIC_PRIORITY
384 && queue)
385 static_priority_end = queue - 1;
386 else if (static_priority_base != -1
387 && static_priority_end == -1
388 && queue == num_queues - 1)
389
390 static_priority_end = queue;
391
392
393
394
395
396
397 if (static_priority_end != -1
398 && (int)queue > static_priority_end
399 && priority[queue] ==
400 CVMX_PKO_QUEUE_STATIC_PRIORITY) {
401 cvmx_dprintf("ERROR: cvmx_pko_config_port: "
402 "Static priority queues aren't "
403 "contiguous or don't start at "
404 "base queue. q: %d, eq: %d\n",
405 (int)queue, static_priority_end);
406 return CVMX_PKO_INVALID_PRIORITY;
407 }
408 }
409 if (static_priority_base > 0) {
410 cvmx_dprintf("ERROR: cvmx_pko_config_port: Static "
411 "priority queues don't start at base "
412 "queue. sq: %d\n",
413 static_priority_base);
414 return CVMX_PKO_INVALID_PRIORITY;
415 }
416#if 0
417 cvmx_dprintf("Port %d: Static priority queue base: %d, "
418 "end: %d\n", port,
419 static_priority_base, static_priority_end);
420#endif
421 }
422
423
424
425
426
427
428 result_code = CVMX_PKO_SUCCESS;
429
430#ifdef PKO_DEBUG
431 cvmx_dprintf("num queues: %d (%lld,%lld)\n", num_queues,
432 CVMX_PKO_QUEUES_PER_PORT_INTERFACE0,
433 CVMX_PKO_QUEUES_PER_PORT_INTERFACE1);
434#endif
435
436 for (queue = 0; queue < num_queues; queue++) {
437 uint64_t *buf_ptr = NULL;
438
439 config1.u64 = 0;
440 config1.s.idx3 = queue >> 3;
441 config1.s.qid7 = (base_queue + queue) >> 7;
442
443 config.u64 = 0;
444 config.s.tail = queue == (num_queues - 1);
445 config.s.index = queue;
446 config.s.port = port;
447 config.s.queue = base_queue + queue;
448
449 if (!cvmx_octeon_is_pass1()) {
450 config.s.static_p = static_priority_base >= 0;
451 config.s.static_q = (int)queue <= static_priority_end;
452 config.s.s_tail = (int)queue == static_priority_end;
453 }
454
455
456
457
458
459 switch ((int)priority[queue]) {
460 case 0:
461 config.s.qos_mask = 0x00;
462 break;
463 case 1:
464 config.s.qos_mask = 0x01;
465 break;
466 case 2:
467 config.s.qos_mask = 0x11;
468 break;
469 case 3:
470 config.s.qos_mask = 0x49;
471 break;
472 case 4:
473 config.s.qos_mask = 0x55;
474 break;
475 case 5:
476 config.s.qos_mask = 0x57;
477 break;
478 case 6:
479 config.s.qos_mask = 0x77;
480 break;
481 case 7:
482 config.s.qos_mask = 0x7f;
483 break;
484 case 8:
485 config.s.qos_mask = 0xff;
486 break;
487 case CVMX_PKO_QUEUE_STATIC_PRIORITY:
488
489 if (!cvmx_octeon_is_pass1()) {
490 config.s.qos_mask = 0xff;
491 break;
492 }
493 default:
494 cvmx_dprintf("ERROR: cvmx_pko_config_port: Invalid "
495 "priority %llu\n",
496 (unsigned long long)priority[queue]);
497 config.s.qos_mask = 0xff;
498 result_code = CVMX_PKO_INVALID_PRIORITY;
499 break;
500 }
501
502 if (port != CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID) {
503 cvmx_cmd_queue_result_t cmd_res =
504 cvmx_cmd_queue_initialize(CVMX_CMD_QUEUE_PKO
505 (base_queue + queue),
506 CVMX_PKO_MAX_QUEUE_DEPTH,
507 CVMX_FPA_OUTPUT_BUFFER_POOL,
508 CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE
509 -
510 CVMX_PKO_COMMAND_BUFFER_SIZE_ADJUST
511 * 8);
512 if (cmd_res != CVMX_CMD_QUEUE_SUCCESS) {
513 switch (cmd_res) {
514 case CVMX_CMD_QUEUE_NO_MEMORY:
515 cvmx_dprintf("ERROR: "
516 "cvmx_pko_config_port: "
517 "Unable to allocate "
518 "output buffer.\n");
519 return CVMX_PKO_NO_MEMORY;
520 case CVMX_CMD_QUEUE_ALREADY_SETUP:
521 cvmx_dprintf
522 ("ERROR: cvmx_pko_config_port: Port already setup.\n");
523 return CVMX_PKO_PORT_ALREADY_SETUP;
524 case CVMX_CMD_QUEUE_INVALID_PARAM:
525 default:
526 cvmx_dprintf
527 ("ERROR: cvmx_pko_config_port: Command queue initialization failed.\n");
528 return CVMX_PKO_CMD_QUEUE_INIT_ERROR;
529 }
530 }
531
532 buf_ptr =
533 (uint64_t *)
534 cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_PKO
535 (base_queue + queue));
536 config.s.buf_ptr = cvmx_ptr_to_phys(buf_ptr);
537 } else
538 config.s.buf_ptr = 0;
539
540 CVMX_SYNCWS;
541
542 if (!OCTEON_IS_MODEL(OCTEON_CN3XXX))
543 cvmx_write_csr(CVMX_PKO_REG_QUEUE_PTRS1, config1.u64);
544 cvmx_write_csr(CVMX_PKO_MEM_QUEUE_PTRS, config.u64);
545 }
546
547 return result_code;
548}
549
550#ifdef PKO_DEBUG
551
552
553
554void cvmx_pko_show_queue_map()
555{
556 int core, port;
557 int pko_output_ports = 36;
558
559 cvmx_dprintf("port");
560 for (port = 0; port < pko_output_ports; port++)
561 cvmx_dprintf("%3d ", port);
562 cvmx_dprintf("\n");
563
564 for (core = 0; core < CVMX_MAX_CORES; core++) {
565 cvmx_dprintf("\n%2d: ", core);
566 for (port = 0; port < pko_output_ports; port++) {
567 cvmx_dprintf("%3d ",
568 cvmx_pko_get_base_queue_per_core(port,
569 core));
570 }
571 }
572 cvmx_dprintf("\n");
573}
574#endif
575
576
577
578
579
580
581
582
583
584
585
586
587int cvmx_pko_rate_limit_packets(int port, int packets_s, int burst)
588{
589 union cvmx_pko_mem_port_rate0 pko_mem_port_rate0;
590 union cvmx_pko_mem_port_rate1 pko_mem_port_rate1;
591
592 pko_mem_port_rate0.u64 = 0;
593 pko_mem_port_rate0.s.pid = port;
594 pko_mem_port_rate0.s.rate_pkt =
595 cvmx_sysinfo_get()->cpu_clock_hz / packets_s / 16;
596
597 pko_mem_port_rate0.s.rate_word = 0;
598
599 pko_mem_port_rate1.u64 = 0;
600 pko_mem_port_rate1.s.pid = port;
601 pko_mem_port_rate1.s.rate_lim =
602 ((uint64_t) pko_mem_port_rate0.s.rate_pkt * burst) >> 8;
603
604 cvmx_write_csr(CVMX_PKO_MEM_PORT_RATE0, pko_mem_port_rate0.u64);
605 cvmx_write_csr(CVMX_PKO_MEM_PORT_RATE1, pko_mem_port_rate1.u64);
606 return 0;
607}
608
609
610
611
612
613
614
615
616
617
618
619
620int cvmx_pko_rate_limit_bits(int port, uint64_t bits_s, int burst)
621{
622 union cvmx_pko_mem_port_rate0 pko_mem_port_rate0;
623 union cvmx_pko_mem_port_rate1 pko_mem_port_rate1;
624 uint64_t clock_rate = cvmx_sysinfo_get()->cpu_clock_hz;
625 uint64_t tokens_per_bit = clock_rate * 16 / bits_s;
626
627 pko_mem_port_rate0.u64 = 0;
628 pko_mem_port_rate0.s.pid = port;
629
630
631
632
633
634
635 pko_mem_port_rate0.s.rate_pkt = (12 + 8 + 4) * 8 * tokens_per_bit / 256;
636
637 pko_mem_port_rate0.s.rate_word = 64 * tokens_per_bit;
638
639 pko_mem_port_rate1.u64 = 0;
640 pko_mem_port_rate1.s.pid = port;
641 pko_mem_port_rate1.s.rate_lim = tokens_per_bit * burst / 256;
642
643 cvmx_write_csr(CVMX_PKO_MEM_PORT_RATE0, pko_mem_port_rate0.u64);
644 cvmx_write_csr(CVMX_PKO_MEM_PORT_RATE1, pko_mem_port_rate1.u64);
645 return 0;
646}
647