blob: 120b78e8bc01cb54a4eaf08db453dcd44d88d7bc [file] [log] [blame]
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001/**********************************************************************
2* Author: Cavium, Inc.
3*
4* Contact: support@cavium.com
5* Please include "LiquidIO" in the subject.
6*
7* Copyright (c) 2003-2015 Cavium, Inc.
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* This file may also be available under a different license from Cavium.
20* Contact Cavium, Inc. for more information
21**********************************************************************/
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070022#include <linux/pci.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070023#include <linux/netdevice.h>
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -070024#include <linux/vmalloc.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070025#include "liquidio_common.h"
26#include "octeon_droq.h"
27#include "octeon_iq.h"
28#include "response_manager.h"
29#include "octeon_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070030#include "octeon_main.h"
31#include "octeon_network.h"
32#include "cn66xx_regs.h"
33#include "cn66xx_device.h"
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -070034#include "cn23xx_pf_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070035
36/** Default configuration
37 * for CN66XX OCTEON Models.
38 */
39static struct octeon_config default_cn66xx_conf = {
40 .card_type = LIO_210SV,
41 .card_name = LIO_210SV_NAME,
42
43 /** IQ attributes */
44 .iq = {
45 .max_iqs = CN6XXX_CFG_IO_QUEUES,
46 .pending_list_size =
47 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
48 .instr_type = OCTEON_64BYTE_INSTR,
49 .db_min = CN6XXX_DB_MIN,
50 .db_timeout = CN6XXX_DB_TIMEOUT,
51 }
52 ,
53
54 /** OQ attributes */
55 .oq = {
56 .max_oqs = CN6XXX_CFG_IO_QUEUES,
57 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
58 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
59 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
60 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
61 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
62 }
63 ,
64
65 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_66XX,
66 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
67 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
68 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
69
70 /* For ethernet interface 0: Port cfg Attributes */
71 .nic_if_cfg[0] = {
72 /* Max Txqs: Half for each of the two ports :max_iq/2 */
73 .max_txqs = MAX_TXQS_PER_INTF,
74
75 /* Actual configured value. Range could be: 1...max_txqs */
76 .num_txqs = DEF_TXQS_PER_INTF,
77
78 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
79 .max_rxqs = MAX_RXQS_PER_INTF,
80
81 /* Actual configured value. Range could be: 1...max_rxqs */
82 .num_rxqs = DEF_RXQS_PER_INTF,
83
84 /* Num of desc for rx rings */
85 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
86
87 /* Num of desc for tx rings */
88 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
89
90 /* SKB size, We need not change buf size even for Jumbo frames.
91 * Octeon can send jumbo frames in 4 consecutive descriptors,
92 */
93 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
94
95 .base_queue = BASE_QUEUE_NOT_REQUESTED,
96
97 .gmx_port_id = 0,
98 },
99
100 .nic_if_cfg[1] = {
101 /* Max Txqs: Half for each of the two ports :max_iq/2 */
102 .max_txqs = MAX_TXQS_PER_INTF,
103
104 /* Actual configured value. Range could be: 1...max_txqs */
105 .num_txqs = DEF_TXQS_PER_INTF,
106
107 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
108 .max_rxqs = MAX_RXQS_PER_INTF,
109
110 /* Actual configured value. Range could be: 1...max_rxqs */
111 .num_rxqs = DEF_RXQS_PER_INTF,
112
113 /* Num of desc for rx rings */
114 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
115
116 /* Num of desc for tx rings */
117 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
118
119 /* SKB size, We need not change buf size even for Jumbo frames.
120 * Octeon can send jumbo frames in 4 consecutive descriptors,
121 */
122 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
123
124 .base_queue = BASE_QUEUE_NOT_REQUESTED,
125
126 .gmx_port_id = 1,
127 },
128
129 /** Miscellaneous attributes */
130 .misc = {
131 /* Host driver link query interval */
132 .oct_link_query_interval = 100,
133
134 /* Octeon link query interval */
135 .host_link_query_interval = 500,
136
137 .enable_sli_oq_bp = 0,
138
139 /* Control queue group */
140 .ctrlq_grp = 1,
141 }
142 ,
143};
144
145/** Default configuration
146 * for CN68XX OCTEON Model.
147 */
148
149static struct octeon_config default_cn68xx_conf = {
150 .card_type = LIO_410NV,
151 .card_name = LIO_410NV_NAME,
152
153 /** IQ attributes */
154 .iq = {
155 .max_iqs = CN6XXX_CFG_IO_QUEUES,
156 .pending_list_size =
157 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
158 .instr_type = OCTEON_64BYTE_INSTR,
159 .db_min = CN6XXX_DB_MIN,
160 .db_timeout = CN6XXX_DB_TIMEOUT,
161 }
162 ,
163
164 /** OQ attributes */
165 .oq = {
166 .max_oqs = CN6XXX_CFG_IO_QUEUES,
167 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
168 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
169 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
170 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
171 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
172 }
173 ,
174
175 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX,
176 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
177 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
178 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
179
180 .nic_if_cfg[0] = {
181 /* Max Txqs: Half for each of the two ports :max_iq/2 */
182 .max_txqs = MAX_TXQS_PER_INTF,
183
184 /* Actual configured value. Range could be: 1...max_txqs */
185 .num_txqs = DEF_TXQS_PER_INTF,
186
187 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
188 .max_rxqs = MAX_RXQS_PER_INTF,
189
190 /* Actual configured value. Range could be: 1...max_rxqs */
191 .num_rxqs = DEF_RXQS_PER_INTF,
192
193 /* Num of desc for rx rings */
194 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
195
196 /* Num of desc for tx rings */
197 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
198
199 /* SKB size, We need not change buf size even for Jumbo frames.
200 * Octeon can send jumbo frames in 4 consecutive descriptors,
201 */
202 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
203
204 .base_queue = BASE_QUEUE_NOT_REQUESTED,
205
206 .gmx_port_id = 0,
207 },
208
209 .nic_if_cfg[1] = {
210 /* Max Txqs: Half for each of the two ports :max_iq/2 */
211 .max_txqs = MAX_TXQS_PER_INTF,
212
213 /* Actual configured value. Range could be: 1...max_txqs */
214 .num_txqs = DEF_TXQS_PER_INTF,
215
216 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
217 .max_rxqs = MAX_RXQS_PER_INTF,
218
219 /* Actual configured value. Range could be: 1...max_rxqs */
220 .num_rxqs = DEF_RXQS_PER_INTF,
221
222 /* Num of desc for rx rings */
223 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
224
225 /* Num of desc for tx rings */
226 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
227
228 /* SKB size, We need not change buf size even for Jumbo frames.
229 * Octeon can send jumbo frames in 4 consecutive descriptors,
230 */
231 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
232
233 .base_queue = BASE_QUEUE_NOT_REQUESTED,
234
235 .gmx_port_id = 1,
236 },
237
238 .nic_if_cfg[2] = {
239 /* Max Txqs: Half for each of the two ports :max_iq/2 */
240 .max_txqs = MAX_TXQS_PER_INTF,
241
242 /* Actual configured value. Range could be: 1...max_txqs */
243 .num_txqs = DEF_TXQS_PER_INTF,
244
245 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
246 .max_rxqs = MAX_RXQS_PER_INTF,
247
248 /* Actual configured value. Range could be: 1...max_rxqs */
249 .num_rxqs = DEF_RXQS_PER_INTF,
250
251 /* Num of desc for rx rings */
252 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
253
254 /* Num of desc for tx rings */
255 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
256
257 /* SKB size, We need not change buf size even for Jumbo frames.
258 * Octeon can send jumbo frames in 4 consecutive descriptors,
259 */
260 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
261
262 .base_queue = BASE_QUEUE_NOT_REQUESTED,
263
264 .gmx_port_id = 2,
265 },
266
267 .nic_if_cfg[3] = {
268 /* Max Txqs: Half for each of the two ports :max_iq/2 */
269 .max_txqs = MAX_TXQS_PER_INTF,
270
271 /* Actual configured value. Range could be: 1...max_txqs */
272 .num_txqs = DEF_TXQS_PER_INTF,
273
274 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
275 .max_rxqs = MAX_RXQS_PER_INTF,
276
277 /* Actual configured value. Range could be: 1...max_rxqs */
278 .num_rxqs = DEF_RXQS_PER_INTF,
279
280 /* Num of desc for rx rings */
281 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
282
283 /* Num of desc for tx rings */
284 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
285
286 /* SKB size, We need not change buf size even for Jumbo frames.
287 * Octeon can send jumbo frames in 4 consecutive descriptors,
288 */
289 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
290
291 .base_queue = BASE_QUEUE_NOT_REQUESTED,
292
293 .gmx_port_id = 3,
294 },
295
296 /** Miscellaneous attributes */
297 .misc = {
298 /* Host driver link query interval */
299 .oct_link_query_interval = 100,
300
301 /* Octeon link query interval */
302 .host_link_query_interval = 500,
303
304 .enable_sli_oq_bp = 0,
305
306 /* Control queue group */
307 .ctrlq_grp = 1,
308 }
309 ,
310};
311
312/** Default configuration
313 * for CN68XX OCTEON Model.
314 */
315static struct octeon_config default_cn68xx_210nv_conf = {
316 .card_type = LIO_210NV,
317 .card_name = LIO_210NV_NAME,
318
319 /** IQ attributes */
320
321 .iq = {
322 .max_iqs = CN6XXX_CFG_IO_QUEUES,
323 .pending_list_size =
324 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
325 .instr_type = OCTEON_64BYTE_INSTR,
326 .db_min = CN6XXX_DB_MIN,
327 .db_timeout = CN6XXX_DB_TIMEOUT,
328 }
329 ,
330
331 /** OQ attributes */
332 .oq = {
333 .max_oqs = CN6XXX_CFG_IO_QUEUES,
334 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
335 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
336 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
337 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
338 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
339 }
340 ,
341
342 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX_210NV,
343 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
344 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
345 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
346
347 .nic_if_cfg[0] = {
348 /* Max Txqs: Half for each of the two ports :max_iq/2 */
349 .max_txqs = MAX_TXQS_PER_INTF,
350
351 /* Actual configured value. Range could be: 1...max_txqs */
352 .num_txqs = DEF_TXQS_PER_INTF,
353
354 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
355 .max_rxqs = MAX_RXQS_PER_INTF,
356
357 /* Actual configured value. Range could be: 1...max_rxqs */
358 .num_rxqs = DEF_RXQS_PER_INTF,
359
360 /* Num of desc for rx rings */
361 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
362
363 /* Num of desc for tx rings */
364 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
365
366 /* SKB size, We need not change buf size even for Jumbo frames.
367 * Octeon can send jumbo frames in 4 consecutive descriptors,
368 */
369 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
370
371 .base_queue = BASE_QUEUE_NOT_REQUESTED,
372
373 .gmx_port_id = 0,
374 },
375
376 .nic_if_cfg[1] = {
377 /* Max Txqs: Half for each of the two ports :max_iq/2 */
378 .max_txqs = MAX_TXQS_PER_INTF,
379
380 /* Actual configured value. Range could be: 1...max_txqs */
381 .num_txqs = DEF_TXQS_PER_INTF,
382
383 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
384 .max_rxqs = MAX_RXQS_PER_INTF,
385
386 /* Actual configured value. Range could be: 1...max_rxqs */
387 .num_rxqs = DEF_RXQS_PER_INTF,
388
389 /* Num of desc for rx rings */
390 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
391
392 /* Num of desc for tx rings */
393 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
394
395 /* SKB size, We need not change buf size even for Jumbo frames.
396 * Octeon can send jumbo frames in 4 consecutive descriptors,
397 */
398 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
399
400 .base_queue = BASE_QUEUE_NOT_REQUESTED,
401
402 .gmx_port_id = 1,
403 },
404
405 /** Miscellaneous attributes */
406 .misc = {
407 /* Host driver link query interval */
408 .oct_link_query_interval = 100,
409
410 /* Octeon link query interval */
411 .host_link_query_interval = 500,
412
413 .enable_sli_oq_bp = 0,
414
415 /* Control queue group */
416 .ctrlq_grp = 1,
417 }
418 ,
419};
420
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700421static struct octeon_config default_cn23xx_conf = {
422 .card_type = LIO_23XX,
423 .card_name = LIO_23XX_NAME,
424 /** IQ attributes */
425 .iq = {
426 .max_iqs = CN23XX_CFG_IO_QUEUES,
427 .pending_list_size = (CN23XX_MAX_IQ_DESCRIPTORS *
428 CN23XX_CFG_IO_QUEUES),
429 .instr_type = OCTEON_64BYTE_INSTR,
430 .db_min = CN23XX_DB_MIN,
431 .db_timeout = CN23XX_DB_TIMEOUT,
432 .iq_intr_pkt = CN23XX_DEF_IQ_INTR_THRESHOLD,
433 },
434
435 /** OQ attributes */
436 .oq = {
437 .max_oqs = CN23XX_CFG_IO_QUEUES,
438 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
439 .pkts_per_intr = CN23XX_OQ_PKTSPER_INTR,
440 .refill_threshold = CN23XX_OQ_REFIL_THRESHOLD,
441 .oq_intr_pkt = CN23XX_OQ_INTR_PKT,
442 .oq_intr_time = CN23XX_OQ_INTR_TIME,
443 },
444
445 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_23XX,
446 .num_def_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
447 .num_def_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
448 .def_rx_buf_size = CN23XX_OQ_BUF_SIZE,
449
450 /* For ethernet interface 0: Port cfg Attributes */
451 .nic_if_cfg[0] = {
452 /* Max Txqs: Half for each of the two ports :max_iq/2 */
453 .max_txqs = MAX_TXQS_PER_INTF,
454
455 /* Actual configured value. Range could be: 1...max_txqs */
456 .num_txqs = DEF_TXQS_PER_INTF,
457
458 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
459 .max_rxqs = MAX_RXQS_PER_INTF,
460
461 /* Actual configured value. Range could be: 1...max_rxqs */
462 .num_rxqs = DEF_RXQS_PER_INTF,
463
464 /* Num of desc for rx rings */
465 .num_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
466
467 /* Num of desc for tx rings */
468 .num_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
469
470 /* SKB size, We need not change buf size even for Jumbo frames.
471 * Octeon can send jumbo frames in 4 consecutive descriptors,
472 */
473 .rx_buf_size = CN23XX_OQ_BUF_SIZE,
474
475 .base_queue = BASE_QUEUE_NOT_REQUESTED,
476
477 .gmx_port_id = 0,
478 },
479
480 .nic_if_cfg[1] = {
481 /* Max Txqs: Half for each of the two ports :max_iq/2 */
482 .max_txqs = MAX_TXQS_PER_INTF,
483
484 /* Actual configured value. Range could be: 1...max_txqs */
485 .num_txqs = DEF_TXQS_PER_INTF,
486
487 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
488 .max_rxqs = MAX_RXQS_PER_INTF,
489
490 /* Actual configured value. Range could be: 1...max_rxqs */
491 .num_rxqs = DEF_RXQS_PER_INTF,
492
493 /* Num of desc for rx rings */
494 .num_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
495
496 /* Num of desc for tx rings */
497 .num_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
498
499 /* SKB size, We need not change buf size even for Jumbo frames.
500 * Octeon can send jumbo frames in 4 consecutive descriptors,
501 */
502 .rx_buf_size = CN23XX_OQ_BUF_SIZE,
503
504 .base_queue = BASE_QUEUE_NOT_REQUESTED,
505
506 .gmx_port_id = 1,
507 },
508
509 .misc = {
510 /* Host driver link query interval */
511 .oct_link_query_interval = 100,
512
513 /* Octeon link query interval */
514 .host_link_query_interval = 500,
515
516 .enable_sli_oq_bp = 0,
517
518 /* Control queue group */
519 .ctrlq_grp = 1,
520 }
521};
522
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700523enum {
524 OCTEON_CONFIG_TYPE_DEFAULT = 0,
525 NUM_OCTEON_CONFS,
526};
527
528static struct octeon_config_ptr {
529 u32 conf_type;
530} oct_conf_info[MAX_OCTEON_DEVICES] = {
531 {
532 OCTEON_CONFIG_TYPE_DEFAULT,
533 }, {
534 OCTEON_CONFIG_TYPE_DEFAULT,
535 }, {
536 OCTEON_CONFIG_TYPE_DEFAULT,
537 }, {
538 OCTEON_CONFIG_TYPE_DEFAULT,
539 },
540};
541
542static char oct_dev_state_str[OCT_DEV_STATES + 1][32] = {
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -0700543 "BEGIN", "PCI-MAP-DONE", "DISPATCH-INIT-DONE",
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700544 "IQ-INIT-DONE", "SCBUFF-POOL-INIT-DONE", "RESPLIST-INIT-DONE",
545 "DROQ-INIT-DONE", "IO-QUEUES-INIT-DONE", "CONSOLE-INIT-DONE",
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -0700546 "HOST-READY", "CORE-READY", "RUNNING", "IN-RESET",
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700547 "INVALID"
548};
549
550static char oct_dev_app_str[CVM_DRV_APP_COUNT + 1][32] = {
551 "BASE", "NIC", "UNKNOWN"};
552
553static struct octeon_device *octeon_device[MAX_OCTEON_DEVICES];
554static u32 octeon_device_count;
555
556static struct octeon_core_setup core_setup[MAX_OCTEON_DEVICES];
557
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700558static void oct_set_config_info(int oct_id, int conf_type)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700559{
560 if (conf_type < 0 || conf_type > (NUM_OCTEON_CONFS - 1))
561 conf_type = OCTEON_CONFIG_TYPE_DEFAULT;
562 oct_conf_info[oct_id].conf_type = conf_type;
563}
564
565void octeon_init_device_list(int conf_type)
566{
567 int i;
568
569 memset(octeon_device, 0, (sizeof(void *) * MAX_OCTEON_DEVICES));
570 for (i = 0; i < MAX_OCTEON_DEVICES; i++)
571 oct_set_config_info(i, conf_type);
572}
573
574static void *__retrieve_octeon_config_info(struct octeon_device *oct,
575 u16 card_type)
576{
577 u32 oct_id = oct->octeon_id;
578 void *ret = NULL;
579
580 switch (oct_conf_info[oct_id].conf_type) {
581 case OCTEON_CONFIG_TYPE_DEFAULT:
582 if (oct->chip_id == OCTEON_CN66XX) {
583 ret = (void *)&default_cn66xx_conf;
584 } else if ((oct->chip_id == OCTEON_CN68XX) &&
585 (card_type == LIO_210NV)) {
586 ret = (void *)&default_cn68xx_210nv_conf;
587 } else if ((oct->chip_id == OCTEON_CN68XX) &&
588 (card_type == LIO_410NV)) {
589 ret = (void *)&default_cn68xx_conf;
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700590 } else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
591 ret = (void *)&default_cn23xx_conf;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700592 }
593 break;
594 default:
595 break;
596 }
597 return ret;
598}
599
600static int __verify_octeon_config_info(struct octeon_device *oct, void *conf)
601{
602 switch (oct->chip_id) {
603 case OCTEON_CN66XX:
604 case OCTEON_CN68XX:
605 return lio_validate_cn6xxx_config_info(oct, conf);
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700606 case OCTEON_CN23XX_PF_VID:
607 return 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700608 default:
609 break;
610 }
611
612 return 1;
613}
614
615void *oct_get_config_info(struct octeon_device *oct, u16 card_type)
616{
617 void *conf = NULL;
618
619 conf = __retrieve_octeon_config_info(oct, card_type);
620 if (!conf)
621 return NULL;
622
623 if (__verify_octeon_config_info(oct, conf)) {
624 dev_err(&oct->pci_dev->dev, "Configuration verification failed\n");
625 return NULL;
626 }
627
628 return conf;
629}
630
631char *lio_get_state_string(atomic_t *state_ptr)
632{
633 s32 istate = (s32)atomic_read(state_ptr);
634
635 if (istate > OCT_DEV_STATES || istate < 0)
636 return oct_dev_state_str[OCT_DEV_STATE_INVALID];
637 return oct_dev_state_str[istate];
638}
639
640static char *get_oct_app_string(u32 app_mode)
641{
642 if (app_mode <= CVM_DRV_APP_END)
643 return oct_dev_app_str[app_mode - CVM_DRV_APP_START];
644 return oct_dev_app_str[CVM_DRV_INVALID_APP - CVM_DRV_APP_START];
645}
646
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700647void octeon_free_device_mem(struct octeon_device *oct)
648{
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -0700649 int i;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700650
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700651 for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -0700652 if (oct->io_qmask.oq & (1ULL << i))
653 vfree(oct->droq[i]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700654 }
655
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700656 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -0700657 if (oct->io_qmask.iq & (1ULL << i))
658 vfree(oct->instr_queue[i]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700659 }
660
661 i = oct->octeon_id;
662 vfree(oct);
663
664 octeon_device[i] = NULL;
665 octeon_device_count--;
666}
667
668static struct octeon_device *octeon_allocate_device_mem(u32 pci_id,
669 u32 priv_size)
670{
671 struct octeon_device *oct;
672 u8 *buf = NULL;
673 u32 octdevsize = 0, configsize = 0, size;
674
675 switch (pci_id) {
676 case OCTEON_CN68XX:
677 case OCTEON_CN66XX:
678 configsize = sizeof(struct octeon_cn6xxx);
679 break;
680
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700681 case OCTEON_CN23XX_PF_VID:
682 configsize = sizeof(struct octeon_cn23xx_pf);
683 break;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700684 default:
685 pr_err("%s: Unknown PCI Device: 0x%x\n",
686 __func__,
687 pci_id);
688 return NULL;
689 }
690
691 if (configsize & 0x7)
692 configsize += (8 - (configsize & 0x7));
693
694 octdevsize = sizeof(struct octeon_device);
695 if (octdevsize & 0x7)
696 octdevsize += (8 - (octdevsize & 0x7));
697
698 if (priv_size & 0x7)
699 priv_size += (8 - (priv_size & 0x7));
700
701 size = octdevsize + priv_size + configsize +
702 (sizeof(struct octeon_dispatch) * DISPATCH_LIST_SIZE);
703
704 buf = vmalloc(size);
705 if (!buf)
706 return NULL;
707
708 memset(buf, 0, size);
709
710 oct = (struct octeon_device *)buf;
711 oct->priv = (void *)(buf + octdevsize);
712 oct->chip = (void *)(buf + octdevsize + priv_size);
713 oct->dispatch.dlist = (struct octeon_dispatch *)
714 (buf + octdevsize + priv_size + configsize);
715
716 return oct;
717}
718
719struct octeon_device *octeon_allocate_device(u32 pci_id,
720 u32 priv_size)
721{
722 u32 oct_idx = 0;
723 struct octeon_device *oct = NULL;
724
725 for (oct_idx = 0; oct_idx < MAX_OCTEON_DEVICES; oct_idx++)
726 if (!octeon_device[oct_idx])
727 break;
728
729 if (oct_idx == MAX_OCTEON_DEVICES)
730 return NULL;
731
732 oct = octeon_allocate_device_mem(pci_id, priv_size);
733 if (!oct)
734 return NULL;
735
736 spin_lock_init(&oct->pci_win_lock);
737 spin_lock_init(&oct->mem_access_lock);
738
739 octeon_device_count++;
740 octeon_device[oct_idx] = oct;
741
742 oct->octeon_id = oct_idx;
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700743 snprintf(oct->device_name, sizeof(oct->device_name),
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700744 "LiquidIO%d", (oct->octeon_id));
745
746 return oct;
747}
748
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700749/* this function is only for setting up the first queue */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700750int octeon_setup_instr_queues(struct octeon_device *oct)
751{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700752 u32 num_descs = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700753 u32 iq_no = 0;
754 union oct_txpciq txpciq;
755 int numa_node = cpu_to_node(iq_no % num_online_cpus());
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700756
757 /* this causes queue 0 to be default queue */
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700758 if (OCTEON_CN6XXX(oct))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700759 num_descs =
760 CFG_GET_NUM_DEF_TX_DESCS(CHIP_FIELD(oct, cn6xxx, conf));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700761 else if (OCTEON_CN23XX_PF(oct))
762 num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_FIELD(oct, cn23xx_pf,
763 conf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700764
765 oct->num_iqs = 0;
766
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700767 oct->instr_queue[0] = vmalloc_node(sizeof(*oct->instr_queue[0]),
768 numa_node);
769 if (!oct->instr_queue[0])
770 oct->instr_queue[0] =
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700771 vmalloc(sizeof(struct octeon_instr_queue));
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700772 if (!oct->instr_queue[0])
773 return 1;
774 memset(oct->instr_queue[0], 0, sizeof(struct octeon_instr_queue));
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700775 oct->instr_queue[0]->q_index = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700776 oct->instr_queue[0]->app_ctx = (void *)(size_t)0;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700777 oct->instr_queue[0]->ifidx = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700778 txpciq.u64 = 0;
779 txpciq.s.q_no = iq_no;
780 txpciq.s.use_qpg = 0;
781 txpciq.s.qpg = 0;
782 if (octeon_init_instr_queue(oct, txpciq, num_descs)) {
783 /* prevent memory leak */
784 vfree(oct->instr_queue[0]);
785 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700786 }
787
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700788 oct->num_iqs++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700789 return 0;
790}
791
792int octeon_setup_output_queues(struct octeon_device *oct)
793{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700794 u32 num_descs = 0;
795 u32 desc_size = 0;
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700796 u32 oq_no = 0;
797 int numa_node = cpu_to_node(oq_no % num_online_cpus());
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700798
799 /* this causes queue 0 to be default queue */
800 if (OCTEON_CN6XXX(oct)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700801 num_descs =
802 CFG_GET_NUM_DEF_RX_DESCS(CHIP_FIELD(oct, cn6xxx, conf));
803 desc_size =
804 CFG_GET_DEF_RX_BUF_SIZE(CHIP_FIELD(oct, cn6xxx, conf));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700805 } else if (OCTEON_CN23XX_PF(oct)) {
806 num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_FIELD(oct, cn23xx_pf,
807 conf));
808 desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_FIELD(oct, cn23xx_pf,
809 conf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700810 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700811 oct->num_oqs = 0;
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700812 oct->droq[0] = vmalloc_node(sizeof(*oct->droq[0]), numa_node);
813 if (!oct->droq[0])
814 oct->droq[0] = vmalloc(sizeof(*oct->droq[0]));
815 if (!oct->droq[0])
816 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700817
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700818 if (octeon_init_droq(oct, oq_no, num_descs, desc_size, NULL))
819 return 1;
820 oct->num_oqs++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700821
822 return 0;
823}
824
825void octeon_set_io_queues_off(struct octeon_device *oct)
826{
827 /* Disable the i/p and o/p queues for this Octeon. */
828
829 octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
830 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
831}
832
833void octeon_set_droq_pkt_op(struct octeon_device *oct,
834 u32 q_no,
835 u32 enable)
836{
837 u32 reg_val = 0;
838
839 /* Disable the i/p and o/p queues for this Octeon. */
840 reg_val = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB);
841
842 if (enable)
843 reg_val = reg_val | (1 << q_no);
844 else
845 reg_val = reg_val & (~(1 << q_no));
846
847 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, reg_val);
848}
849
850int octeon_init_dispatch_list(struct octeon_device *oct)
851{
852 u32 i;
853
854 oct->dispatch.count = 0;
855
856 for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
857 oct->dispatch.dlist[i].opcode = 0;
858 INIT_LIST_HEAD(&oct->dispatch.dlist[i].list);
859 }
860
861 for (i = 0; i <= REQTYPE_LAST; i++)
862 octeon_register_reqtype_free_fn(oct, i, NULL);
863
864 spin_lock_init(&oct->dispatch.lock);
865
866 return 0;
867}
868
869void octeon_delete_dispatch_list(struct octeon_device *oct)
870{
871 u32 i;
872 struct list_head freelist, *temp, *tmp2;
873
874 INIT_LIST_HEAD(&freelist);
875
876 spin_lock_bh(&oct->dispatch.lock);
877
878 for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
879 struct list_head *dispatch;
880
881 dispatch = &oct->dispatch.dlist[i].list;
882 while (dispatch->next != dispatch) {
883 temp = dispatch->next;
884 list_del(temp);
885 list_add_tail(temp, &freelist);
886 }
887
888 oct->dispatch.dlist[i].opcode = 0;
889 }
890
891 oct->dispatch.count = 0;
892
893 spin_unlock_bh(&oct->dispatch.lock);
894
895 list_for_each_safe(temp, tmp2, &freelist) {
896 list_del(temp);
897 vfree(temp);
898 }
899}
900
901octeon_dispatch_fn_t
902octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
903 u16 subcode)
904{
905 u32 idx;
906 struct list_head *dispatch;
907 octeon_dispatch_fn_t fn = NULL;
908 u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
909
910 idx = combined_opcode & OCTEON_OPCODE_MASK;
911
912 spin_lock_bh(&octeon_dev->dispatch.lock);
913
914 if (octeon_dev->dispatch.count == 0) {
915 spin_unlock_bh(&octeon_dev->dispatch.lock);
916 return NULL;
917 }
918
919 if (!(octeon_dev->dispatch.dlist[idx].opcode)) {
920 spin_unlock_bh(&octeon_dev->dispatch.lock);
921 return NULL;
922 }
923
924 if (octeon_dev->dispatch.dlist[idx].opcode == combined_opcode) {
925 fn = octeon_dev->dispatch.dlist[idx].dispatch_fn;
926 } else {
927 list_for_each(dispatch,
928 &octeon_dev->dispatch.dlist[idx].list) {
929 if (((struct octeon_dispatch *)dispatch)->opcode ==
930 combined_opcode) {
931 fn = ((struct octeon_dispatch *)
932 dispatch)->dispatch_fn;
933 break;
934 }
935 }
936 }
937
938 spin_unlock_bh(&octeon_dev->dispatch.lock);
939 return fn;
940}
941
942/* octeon_register_dispatch_fn
943 * Parameters:
944 * octeon_id - id of the octeon device.
945 * opcode - opcode for which driver should call the registered function
946 * subcode - subcode for which driver should call the registered function
947 * fn - The function to call when a packet with "opcode" arrives in
948 * octeon output queues.
949 * fn_arg - The argument to be passed when calling function "fn".
950 * Description:
951 * Registers a function and its argument to be called when a packet
952 * arrives in Octeon output queues with "opcode".
953 * Returns:
954 * Success: 0
955 * Failure: 1
956 * Locks:
957 * No locks are held.
958 */
959int
960octeon_register_dispatch_fn(struct octeon_device *oct,
961 u16 opcode,
962 u16 subcode,
963 octeon_dispatch_fn_t fn, void *fn_arg)
964{
965 u32 idx;
966 octeon_dispatch_fn_t pfn;
967 u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
968
969 idx = combined_opcode & OCTEON_OPCODE_MASK;
970
971 spin_lock_bh(&oct->dispatch.lock);
972 /* Add dispatch function to first level of lookup table */
973 if (oct->dispatch.dlist[idx].opcode == 0) {
974 oct->dispatch.dlist[idx].opcode = combined_opcode;
975 oct->dispatch.dlist[idx].dispatch_fn = fn;
976 oct->dispatch.dlist[idx].arg = fn_arg;
977 oct->dispatch.count++;
978 spin_unlock_bh(&oct->dispatch.lock);
979 return 0;
980 }
981
982 spin_unlock_bh(&oct->dispatch.lock);
983
984 /* Check if there was a function already registered for this
985 * opcode/subcode.
986 */
987 pfn = octeon_get_dispatch(oct, opcode, subcode);
988 if (!pfn) {
989 struct octeon_dispatch *dispatch;
990
991 dev_dbg(&oct->pci_dev->dev,
992 "Adding opcode to dispatch list linked list\n");
993 dispatch = (struct octeon_dispatch *)
994 vmalloc(sizeof(struct octeon_dispatch));
995 if (!dispatch) {
996 dev_err(&oct->pci_dev->dev,
997 "No memory to add dispatch function\n");
998 return 1;
999 }
1000 dispatch->opcode = combined_opcode;
1001 dispatch->dispatch_fn = fn;
1002 dispatch->arg = fn_arg;
1003
1004 /* Add dispatch function to linked list of fn ptrs
1005 * at the hashed index.
1006 */
1007 spin_lock_bh(&oct->dispatch.lock);
1008 list_add(&dispatch->list, &oct->dispatch.dlist[idx].list);
1009 oct->dispatch.count++;
1010 spin_unlock_bh(&oct->dispatch.lock);
1011
1012 } else {
1013 dev_err(&oct->pci_dev->dev,
1014 "Found previously registered dispatch fn for opcode/subcode: %x/%x\n",
1015 opcode, subcode);
1016 return 1;
1017 }
1018
1019 return 0;
1020}
1021
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001022int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf)
1023{
1024 u32 i;
1025 char app_name[16];
1026 struct octeon_device *oct = (struct octeon_device *)buf;
1027 struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
1028 struct octeon_core_setup *cs = NULL;
1029 u32 num_nic_ports = 0;
1030
1031 if (OCTEON_CN6XXX(oct))
1032 num_nic_ports =
1033 CFG_GET_NUM_NIC_PORTS(CHIP_FIELD(oct, cn6xxx, conf));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001034 else if (OCTEON_CN23XX_PF(oct))
1035 num_nic_ports =
1036 CFG_GET_NUM_NIC_PORTS(CHIP_FIELD(oct, cn23xx_pf, conf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001037
1038 if (atomic_read(&oct->status) >= OCT_DEV_RUNNING) {
1039 dev_err(&oct->pci_dev->dev, "Received CORE OK when device state is 0x%x\n",
1040 atomic_read(&oct->status));
1041 goto core_drv_init_err;
1042 }
1043
1044 strncpy(app_name,
1045 get_oct_app_string(
1046 (u32)recv_pkt->rh.r_core_drv_init.app_mode),
1047 sizeof(app_name) - 1);
1048 oct->app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07001049 if (recv_pkt->rh.r_core_drv_init.app_mode == CVM_DRV_NIC_APP) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001050 oct->fw_info.max_nic_ports =
1051 (u32)recv_pkt->rh.r_core_drv_init.max_nic_ports;
1052 oct->fw_info.num_gmx_ports =
1053 (u32)recv_pkt->rh.r_core_drv_init.num_gmx_ports;
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07001054 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001055
1056 if (oct->fw_info.max_nic_ports < num_nic_ports) {
1057 dev_err(&oct->pci_dev->dev,
1058 "Config has more ports than firmware allows (%d > %d).\n",
1059 num_nic_ports, oct->fw_info.max_nic_ports);
1060 goto core_drv_init_err;
1061 }
1062 oct->fw_info.app_cap_flags = recv_pkt->rh.r_core_drv_init.app_cap_flags;
1063 oct->fw_info.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
1064
1065 atomic_set(&oct->status, OCT_DEV_CORE_OK);
1066
1067 cs = &core_setup[oct->octeon_id];
1068
1069 if (recv_pkt->buffer_size[0] != sizeof(*cs)) {
1070 dev_dbg(&oct->pci_dev->dev, "Core setup bytes expected %u found %d\n",
1071 (u32)sizeof(*cs),
1072 recv_pkt->buffer_size[0]);
1073 }
1074
1075 memcpy(cs, get_rbd(recv_pkt->buffer_ptr[0]), sizeof(*cs));
1076 strncpy(oct->boardinfo.name, cs->boardname, OCT_BOARD_NAME);
1077 strncpy(oct->boardinfo.serial_number, cs->board_serial_number,
1078 OCT_SERIAL_LEN);
1079
1080 octeon_swap_8B_data((u64 *)cs, (sizeof(*cs) >> 3));
1081
1082 oct->boardinfo.major = cs->board_rev_major;
1083 oct->boardinfo.minor = cs->board_rev_minor;
1084
1085 dev_info(&oct->pci_dev->dev,
1086 "Running %s (%llu Hz)\n",
1087 app_name, CVM_CAST64(cs->corefreq));
1088
1089core_drv_init_err:
1090 for (i = 0; i < recv_pkt->buffer_count; i++)
1091 recv_buffer_free(recv_pkt->buffer_ptr[i]);
1092 octeon_free_recv_info(recv_info);
1093 return 0;
1094}
1095
1096int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no)
1097
1098{
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001099 if (oct && (q_no < MAX_OCTEON_INSTR_QUEUES(oct)) &&
1100 (oct->io_qmask.iq & (1ULL << q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001101 return oct->instr_queue[q_no]->max_count;
1102
1103 return -1;
1104}
1105
1106int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no)
1107{
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001108 if (oct && (q_no < MAX_OCTEON_OUTPUT_QUEUES(oct)) &&
1109 (oct->io_qmask.oq & (1ULL << q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001110 return oct->droq[q_no]->max_count;
1111 return -1;
1112}
1113
1114/* Retruns the host firmware handshake OCTEON specific configuration */
1115struct octeon_config *octeon_get_conf(struct octeon_device *oct)
1116{
1117 struct octeon_config *default_oct_conf = NULL;
1118
1119 /* check the OCTEON Device model & return the corresponding octeon
1120 * configuration
1121 */
1122
1123 if (OCTEON_CN6XXX(oct)) {
1124 default_oct_conf =
1125 (struct octeon_config *)(CHIP_FIELD(oct, cn6xxx, conf));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001126 } else if (OCTEON_CN23XX_PF(oct)) {
1127 default_oct_conf = (struct octeon_config *)
1128 (CHIP_FIELD(oct, cn23xx_pf, conf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001129 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001130 return default_oct_conf;
1131}
1132
1133/* scratch register address is same in all the OCT-II and CN70XX models */
1134#define CNXX_SLI_SCRATCH1 0x3C0
1135
1136/** Get the octeon device pointer.
1137 * @param octeon_id - The id for which the octeon device pointer is required.
1138 * @return Success: Octeon device pointer.
1139 * @return Failure: NULL.
1140 */
1141struct octeon_device *lio_get_device(u32 octeon_id)
1142{
1143 if (octeon_id >= MAX_OCTEON_DEVICES)
1144 return NULL;
1145 else
1146 return octeon_device[octeon_id];
1147}
1148
1149u64 lio_pci_readq(struct octeon_device *oct, u64 addr)
1150{
1151 u64 val64;
1152 unsigned long flags;
1153 u32 val32, addrhi;
1154
1155 spin_lock_irqsave(&oct->pci_win_lock, flags);
1156
1157 /* The windowed read happens when the LSB of the addr is written.
1158 * So write MSB first
1159 */
1160 addrhi = (addr >> 32);
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001161 if ((oct->chip_id == OCTEON_CN66XX) ||
1162 (oct->chip_id == OCTEON_CN68XX) ||
1163 (oct->chip_id == OCTEON_CN23XX_PF_VID))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001164 addrhi |= 0x00060000;
1165 writel(addrhi, oct->reg_list.pci_win_rd_addr_hi);
1166
1167 /* Read back to preserve ordering of writes */
1168 val32 = readl(oct->reg_list.pci_win_rd_addr_hi);
1169
1170 writel(addr & 0xffffffff, oct->reg_list.pci_win_rd_addr_lo);
1171 val32 = readl(oct->reg_list.pci_win_rd_addr_lo);
1172
1173 val64 = readq(oct->reg_list.pci_win_rd_data);
1174
1175 spin_unlock_irqrestore(&oct->pci_win_lock, flags);
1176
1177 return val64;
1178}
1179
1180void lio_pci_writeq(struct octeon_device *oct,
1181 u64 val,
1182 u64 addr)
1183{
1184 u32 val32;
1185 unsigned long flags;
1186
1187 spin_lock_irqsave(&oct->pci_win_lock, flags);
1188
1189 writeq(addr, oct->reg_list.pci_win_wr_addr);
1190
1191 /* The write happens when the LSB is written. So write MSB first. */
1192 writel(val >> 32, oct->reg_list.pci_win_wr_data_hi);
1193 /* Read the MSB to ensure ordering of writes. */
1194 val32 = readl(oct->reg_list.pci_win_wr_data_hi);
1195
1196 writel(val & 0xffffffff, oct->reg_list.pci_win_wr_data_lo);
1197
1198 spin_unlock_irqrestore(&oct->pci_win_lock, flags);
1199}
1200
1201int octeon_mem_access_ok(struct octeon_device *oct)
1202{
1203 u64 access_okay = 0;
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001204 u64 lmc0_reset_ctl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001205
1206 /* Check to make sure a DDR interface is enabled */
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001207 if (OCTEON_CN23XX_PF(oct)) {
1208 lmc0_reset_ctl = lio_pci_readq(oct, CN23XX_LMC0_RESET_CTL);
1209 access_okay =
1210 (lmc0_reset_ctl & CN23XX_LMC0_RESET_CTL_DDR3RST_MASK);
1211 } else {
1212 lmc0_reset_ctl = lio_pci_readq(oct, CN6XXX_LMC0_RESET_CTL);
1213 access_okay =
1214 (lmc0_reset_ctl & CN6XXX_LMC0_RESET_CTL_DDR3RST_MASK);
1215 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001216
1217 return access_okay ? 0 : 1;
1218}
1219
1220int octeon_wait_for_ddr_init(struct octeon_device *oct, u32 *timeout)
1221{
1222 int ret = 1;
1223 u32 ms;
1224
1225 if (!timeout)
1226 return ret;
1227
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001228 for (ms = 0; (ret != 0) && ((*timeout == 0) || (ms <= *timeout));
1229 ms += HZ / 10) {
1230 ret = octeon_mem_access_ok(oct);
1231
1232 /* wait 100 ms */
1233 if (ret)
1234 schedule_timeout_uninterruptible(HZ / 10);
1235 }
1236
1237 return ret;
1238}
1239
1240/** Get the octeon id assigned to the octeon device passed as argument.
1241 * This function is exported to other modules.
1242 * @param dev - octeon device pointer passed as a void *.
1243 * @return octeon device id
1244 */
1245int lio_get_device_id(void *dev)
1246{
1247 struct octeon_device *octeon_dev = (struct octeon_device *)dev;
1248 u32 i;
1249
1250 for (i = 0; i < MAX_OCTEON_DEVICES; i++)
1251 if (octeon_device[i] == octeon_dev)
1252 return octeon_dev->octeon_id;
1253 return -1;
1254}
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001255
1256void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq)
1257{
1258 /* the whole thing needs to be atomic, ideally */
1259 if (droq) {
1260 spin_lock_bh(&droq->lock);
1261 writel(droq->pkt_count, droq->pkts_sent_reg);
1262 droq->pkt_count = 0;
1263 spin_unlock_bh(&droq->lock);
1264 }
1265 if (iq) {
1266 spin_lock_bh(&iq->lock);
1267 writel(iq->pkt_in_done, iq->inst_cnt_reg);
1268 iq->pkt_in_done = 0;
1269 spin_unlock_bh(&iq->lock);
1270 }
1271}