blob: 79c8875ffd61567eb9497c1ba01a1d83aa082b60 [file] [log] [blame]
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001/**********************************************************************
Raghu Vatsavayi50579d32016-11-14 15:54:46 -08002 * Author: Cavium, Inc.
3 *
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
6 *
7 * Copyright (c) 2003-2016 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 details.
17 ***********************************************************************/
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070018#include <linux/pci.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070019#include <linux/netdevice.h>
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -070020#include <linux/vmalloc.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070021#include "liquidio_common.h"
22#include "octeon_droq.h"
23#include "octeon_iq.h"
24#include "response_manager.h"
25#include "octeon_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070026#include "octeon_main.h"
27#include "octeon_network.h"
28#include "cn66xx_regs.h"
29#include "cn66xx_device.h"
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -070030#include "cn23xx_pf_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070031
32/** Default configuration
33 * for CN66XX OCTEON Models.
34 */
35static struct octeon_config default_cn66xx_conf = {
36 .card_type = LIO_210SV,
37 .card_name = LIO_210SV_NAME,
38
39 /** IQ attributes */
40 .iq = {
41 .max_iqs = CN6XXX_CFG_IO_QUEUES,
42 .pending_list_size =
43 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
44 .instr_type = OCTEON_64BYTE_INSTR,
45 .db_min = CN6XXX_DB_MIN,
46 .db_timeout = CN6XXX_DB_TIMEOUT,
47 }
48 ,
49
50 /** OQ attributes */
51 .oq = {
52 .max_oqs = CN6XXX_CFG_IO_QUEUES,
53 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
54 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
55 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
56 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
57 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
58 }
59 ,
60
61 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_66XX,
62 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
63 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
64 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
65
66 /* For ethernet interface 0: Port cfg Attributes */
67 .nic_if_cfg[0] = {
68 /* Max Txqs: Half for each of the two ports :max_iq/2 */
69 .max_txqs = MAX_TXQS_PER_INTF,
70
71 /* Actual configured value. Range could be: 1...max_txqs */
72 .num_txqs = DEF_TXQS_PER_INTF,
73
74 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
75 .max_rxqs = MAX_RXQS_PER_INTF,
76
77 /* Actual configured value. Range could be: 1...max_rxqs */
78 .num_rxqs = DEF_RXQS_PER_INTF,
79
80 /* Num of desc for rx rings */
81 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
82
83 /* Num of desc for tx rings */
84 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
85
86 /* SKB size, We need not change buf size even for Jumbo frames.
87 * Octeon can send jumbo frames in 4 consecutive descriptors,
88 */
89 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
90
91 .base_queue = BASE_QUEUE_NOT_REQUESTED,
92
93 .gmx_port_id = 0,
94 },
95
96 .nic_if_cfg[1] = {
97 /* Max Txqs: Half for each of the two ports :max_iq/2 */
98 .max_txqs = MAX_TXQS_PER_INTF,
99
100 /* Actual configured value. Range could be: 1...max_txqs */
101 .num_txqs = DEF_TXQS_PER_INTF,
102
103 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
104 .max_rxqs = MAX_RXQS_PER_INTF,
105
106 /* Actual configured value. Range could be: 1...max_rxqs */
107 .num_rxqs = DEF_RXQS_PER_INTF,
108
109 /* Num of desc for rx rings */
110 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
111
112 /* Num of desc for tx rings */
113 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
114
115 /* SKB size, We need not change buf size even for Jumbo frames.
116 * Octeon can send jumbo frames in 4 consecutive descriptors,
117 */
118 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
119
120 .base_queue = BASE_QUEUE_NOT_REQUESTED,
121
122 .gmx_port_id = 1,
123 },
124
125 /** Miscellaneous attributes */
126 .misc = {
127 /* Host driver link query interval */
128 .oct_link_query_interval = 100,
129
130 /* Octeon link query interval */
131 .host_link_query_interval = 500,
132
133 .enable_sli_oq_bp = 0,
134
135 /* Control queue group */
136 .ctrlq_grp = 1,
137 }
138 ,
139};
140
141/** Default configuration
142 * for CN68XX OCTEON Model.
143 */
144
145static struct octeon_config default_cn68xx_conf = {
146 .card_type = LIO_410NV,
147 .card_name = LIO_410NV_NAME,
148
149 /** IQ attributes */
150 .iq = {
151 .max_iqs = CN6XXX_CFG_IO_QUEUES,
152 .pending_list_size =
153 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
154 .instr_type = OCTEON_64BYTE_INSTR,
155 .db_min = CN6XXX_DB_MIN,
156 .db_timeout = CN6XXX_DB_TIMEOUT,
157 }
158 ,
159
160 /** OQ attributes */
161 .oq = {
162 .max_oqs = CN6XXX_CFG_IO_QUEUES,
163 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
164 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
165 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
166 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
167 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
168 }
169 ,
170
171 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX,
172 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
173 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
174 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
175
176 .nic_if_cfg[0] = {
177 /* Max Txqs: Half for each of the two ports :max_iq/2 */
178 .max_txqs = MAX_TXQS_PER_INTF,
179
180 /* Actual configured value. Range could be: 1...max_txqs */
181 .num_txqs = DEF_TXQS_PER_INTF,
182
183 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
184 .max_rxqs = MAX_RXQS_PER_INTF,
185
186 /* Actual configured value. Range could be: 1...max_rxqs */
187 .num_rxqs = DEF_RXQS_PER_INTF,
188
189 /* Num of desc for rx rings */
190 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
191
192 /* Num of desc for tx rings */
193 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
194
195 /* SKB size, We need not change buf size even for Jumbo frames.
196 * Octeon can send jumbo frames in 4 consecutive descriptors,
197 */
198 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
199
200 .base_queue = BASE_QUEUE_NOT_REQUESTED,
201
202 .gmx_port_id = 0,
203 },
204
205 .nic_if_cfg[1] = {
206 /* Max Txqs: Half for each of the two ports :max_iq/2 */
207 .max_txqs = MAX_TXQS_PER_INTF,
208
209 /* Actual configured value. Range could be: 1...max_txqs */
210 .num_txqs = DEF_TXQS_PER_INTF,
211
212 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
213 .max_rxqs = MAX_RXQS_PER_INTF,
214
215 /* Actual configured value. Range could be: 1...max_rxqs */
216 .num_rxqs = DEF_RXQS_PER_INTF,
217
218 /* Num of desc for rx rings */
219 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
220
221 /* Num of desc for tx rings */
222 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
223
224 /* SKB size, We need not change buf size even for Jumbo frames.
225 * Octeon can send jumbo frames in 4 consecutive descriptors,
226 */
227 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
228
229 .base_queue = BASE_QUEUE_NOT_REQUESTED,
230
231 .gmx_port_id = 1,
232 },
233
234 .nic_if_cfg[2] = {
235 /* Max Txqs: Half for each of the two ports :max_iq/2 */
236 .max_txqs = MAX_TXQS_PER_INTF,
237
238 /* Actual configured value. Range could be: 1...max_txqs */
239 .num_txqs = DEF_TXQS_PER_INTF,
240
241 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
242 .max_rxqs = MAX_RXQS_PER_INTF,
243
244 /* Actual configured value. Range could be: 1...max_rxqs */
245 .num_rxqs = DEF_RXQS_PER_INTF,
246
247 /* Num of desc for rx rings */
248 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
249
250 /* Num of desc for tx rings */
251 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
252
253 /* SKB size, We need not change buf size even for Jumbo frames.
254 * Octeon can send jumbo frames in 4 consecutive descriptors,
255 */
256 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
257
258 .base_queue = BASE_QUEUE_NOT_REQUESTED,
259
260 .gmx_port_id = 2,
261 },
262
263 .nic_if_cfg[3] = {
264 /* Max Txqs: Half for each of the two ports :max_iq/2 */
265 .max_txqs = MAX_TXQS_PER_INTF,
266
267 /* Actual configured value. Range could be: 1...max_txqs */
268 .num_txqs = DEF_TXQS_PER_INTF,
269
270 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
271 .max_rxqs = MAX_RXQS_PER_INTF,
272
273 /* Actual configured value. Range could be: 1...max_rxqs */
274 .num_rxqs = DEF_RXQS_PER_INTF,
275
276 /* Num of desc for rx rings */
277 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
278
279 /* Num of desc for tx rings */
280 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
281
282 /* SKB size, We need not change buf size even for Jumbo frames.
283 * Octeon can send jumbo frames in 4 consecutive descriptors,
284 */
285 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
286
287 .base_queue = BASE_QUEUE_NOT_REQUESTED,
288
289 .gmx_port_id = 3,
290 },
291
292 /** Miscellaneous attributes */
293 .misc = {
294 /* Host driver link query interval */
295 .oct_link_query_interval = 100,
296
297 /* Octeon link query interval */
298 .host_link_query_interval = 500,
299
300 .enable_sli_oq_bp = 0,
301
302 /* Control queue group */
303 .ctrlq_grp = 1,
304 }
305 ,
306};
307
308/** Default configuration
309 * for CN68XX OCTEON Model.
310 */
311static struct octeon_config default_cn68xx_210nv_conf = {
312 .card_type = LIO_210NV,
313 .card_name = LIO_210NV_NAME,
314
315 /** IQ attributes */
316
317 .iq = {
318 .max_iqs = CN6XXX_CFG_IO_QUEUES,
319 .pending_list_size =
320 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
321 .instr_type = OCTEON_64BYTE_INSTR,
322 .db_min = CN6XXX_DB_MIN,
323 .db_timeout = CN6XXX_DB_TIMEOUT,
324 }
325 ,
326
327 /** OQ attributes */
328 .oq = {
329 .max_oqs = CN6XXX_CFG_IO_QUEUES,
330 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
331 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
332 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
333 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
334 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
335 }
336 ,
337
338 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX_210NV,
339 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
340 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
341 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
342
343 .nic_if_cfg[0] = {
344 /* Max Txqs: Half for each of the two ports :max_iq/2 */
345 .max_txqs = MAX_TXQS_PER_INTF,
346
347 /* Actual configured value. Range could be: 1...max_txqs */
348 .num_txqs = DEF_TXQS_PER_INTF,
349
350 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
351 .max_rxqs = MAX_RXQS_PER_INTF,
352
353 /* Actual configured value. Range could be: 1...max_rxqs */
354 .num_rxqs = DEF_RXQS_PER_INTF,
355
356 /* Num of desc for rx rings */
357 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
358
359 /* Num of desc for tx rings */
360 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
361
362 /* SKB size, We need not change buf size even for Jumbo frames.
363 * Octeon can send jumbo frames in 4 consecutive descriptors,
364 */
365 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
366
367 .base_queue = BASE_QUEUE_NOT_REQUESTED,
368
369 .gmx_port_id = 0,
370 },
371
372 .nic_if_cfg[1] = {
373 /* Max Txqs: Half for each of the two ports :max_iq/2 */
374 .max_txqs = MAX_TXQS_PER_INTF,
375
376 /* Actual configured value. Range could be: 1...max_txqs */
377 .num_txqs = DEF_TXQS_PER_INTF,
378
379 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
380 .max_rxqs = MAX_RXQS_PER_INTF,
381
382 /* Actual configured value. Range could be: 1...max_rxqs */
383 .num_rxqs = DEF_RXQS_PER_INTF,
384
385 /* Num of desc for rx rings */
386 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
387
388 /* Num of desc for tx rings */
389 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
390
391 /* SKB size, We need not change buf size even for Jumbo frames.
392 * Octeon can send jumbo frames in 4 consecutive descriptors,
393 */
394 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
395
396 .base_queue = BASE_QUEUE_NOT_REQUESTED,
397
398 .gmx_port_id = 1,
399 },
400
401 /** Miscellaneous attributes */
402 .misc = {
403 /* Host driver link query interval */
404 .oct_link_query_interval = 100,
405
406 /* Octeon link query interval */
407 .host_link_query_interval = 500,
408
409 .enable_sli_oq_bp = 0,
410
411 /* Control queue group */
412 .ctrlq_grp = 1,
413 }
414 ,
415};
416
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700417static struct octeon_config default_cn23xx_conf = {
418 .card_type = LIO_23XX,
419 .card_name = LIO_23XX_NAME,
420 /** IQ attributes */
421 .iq = {
422 .max_iqs = CN23XX_CFG_IO_QUEUES,
423 .pending_list_size = (CN23XX_MAX_IQ_DESCRIPTORS *
424 CN23XX_CFG_IO_QUEUES),
425 .instr_type = OCTEON_64BYTE_INSTR,
426 .db_min = CN23XX_DB_MIN,
427 .db_timeout = CN23XX_DB_TIMEOUT,
428 .iq_intr_pkt = CN23XX_DEF_IQ_INTR_THRESHOLD,
429 },
430
431 /** OQ attributes */
432 .oq = {
433 .max_oqs = CN23XX_CFG_IO_QUEUES,
434 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
435 .pkts_per_intr = CN23XX_OQ_PKTSPER_INTR,
436 .refill_threshold = CN23XX_OQ_REFIL_THRESHOLD,
437 .oq_intr_pkt = CN23XX_OQ_INTR_PKT,
438 .oq_intr_time = CN23XX_OQ_INTR_TIME,
439 },
440
441 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_23XX,
442 .num_def_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
443 .num_def_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
444 .def_rx_buf_size = CN23XX_OQ_BUF_SIZE,
445
446 /* For ethernet interface 0: Port cfg Attributes */
447 .nic_if_cfg[0] = {
448 /* Max Txqs: Half for each of the two ports :max_iq/2 */
449 .max_txqs = MAX_TXQS_PER_INTF,
450
451 /* Actual configured value. Range could be: 1...max_txqs */
452 .num_txqs = DEF_TXQS_PER_INTF,
453
454 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
455 .max_rxqs = MAX_RXQS_PER_INTF,
456
457 /* Actual configured value. Range could be: 1...max_rxqs */
458 .num_rxqs = DEF_RXQS_PER_INTF,
459
460 /* Num of desc for rx rings */
461 .num_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
462
463 /* Num of desc for tx rings */
464 .num_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
465
466 /* SKB size, We need not change buf size even for Jumbo frames.
467 * Octeon can send jumbo frames in 4 consecutive descriptors,
468 */
469 .rx_buf_size = CN23XX_OQ_BUF_SIZE,
470
471 .base_queue = BASE_QUEUE_NOT_REQUESTED,
472
473 .gmx_port_id = 0,
474 },
475
476 .nic_if_cfg[1] = {
477 /* Max Txqs: Half for each of the two ports :max_iq/2 */
478 .max_txqs = MAX_TXQS_PER_INTF,
479
480 /* Actual configured value. Range could be: 1...max_txqs */
481 .num_txqs = DEF_TXQS_PER_INTF,
482
483 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
484 .max_rxqs = MAX_RXQS_PER_INTF,
485
486 /* Actual configured value. Range could be: 1...max_rxqs */
487 .num_rxqs = DEF_RXQS_PER_INTF,
488
489 /* Num of desc for rx rings */
490 .num_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
491
492 /* Num of desc for tx rings */
493 .num_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
494
495 /* SKB size, We need not change buf size even for Jumbo frames.
496 * Octeon can send jumbo frames in 4 consecutive descriptors,
497 */
498 .rx_buf_size = CN23XX_OQ_BUF_SIZE,
499
500 .base_queue = BASE_QUEUE_NOT_REQUESTED,
501
502 .gmx_port_id = 1,
503 },
504
505 .misc = {
506 /* Host driver link query interval */
507 .oct_link_query_interval = 100,
508
509 /* Octeon link query interval */
510 .host_link_query_interval = 500,
511
512 .enable_sli_oq_bp = 0,
513
514 /* Control queue group */
515 .ctrlq_grp = 1,
516 }
517};
518
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700519static struct octeon_config_ptr {
520 u32 conf_type;
521} oct_conf_info[MAX_OCTEON_DEVICES] = {
522 {
523 OCTEON_CONFIG_TYPE_DEFAULT,
524 }, {
525 OCTEON_CONFIG_TYPE_DEFAULT,
526 }, {
527 OCTEON_CONFIG_TYPE_DEFAULT,
528 }, {
529 OCTEON_CONFIG_TYPE_DEFAULT,
530 },
531};
532
533static char oct_dev_state_str[OCT_DEV_STATES + 1][32] = {
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -0700534 "BEGIN", "PCI-MAP-DONE", "DISPATCH-INIT-DONE",
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700535 "IQ-INIT-DONE", "SCBUFF-POOL-INIT-DONE", "RESPLIST-INIT-DONE",
536 "DROQ-INIT-DONE", "IO-QUEUES-INIT-DONE", "CONSOLE-INIT-DONE",
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -0700537 "HOST-READY", "CORE-READY", "RUNNING", "IN-RESET",
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700538 "INVALID"
539};
540
541static char oct_dev_app_str[CVM_DRV_APP_COUNT + 1][32] = {
542 "BASE", "NIC", "UNKNOWN"};
543
544static struct octeon_device *octeon_device[MAX_OCTEON_DEVICES];
545static u32 octeon_device_count;
546
547static struct octeon_core_setup core_setup[MAX_OCTEON_DEVICES];
548
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700549static void oct_set_config_info(int oct_id, int conf_type)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700550{
551 if (conf_type < 0 || conf_type > (NUM_OCTEON_CONFS - 1))
552 conf_type = OCTEON_CONFIG_TYPE_DEFAULT;
553 oct_conf_info[oct_id].conf_type = conf_type;
554}
555
556void octeon_init_device_list(int conf_type)
557{
558 int i;
559
560 memset(octeon_device, 0, (sizeof(void *) * MAX_OCTEON_DEVICES));
561 for (i = 0; i < MAX_OCTEON_DEVICES; i++)
562 oct_set_config_info(i, conf_type);
563}
564
565static void *__retrieve_octeon_config_info(struct octeon_device *oct,
566 u16 card_type)
567{
568 u32 oct_id = oct->octeon_id;
569 void *ret = NULL;
570
571 switch (oct_conf_info[oct_id].conf_type) {
572 case OCTEON_CONFIG_TYPE_DEFAULT:
573 if (oct->chip_id == OCTEON_CN66XX) {
574 ret = (void *)&default_cn66xx_conf;
575 } else if ((oct->chip_id == OCTEON_CN68XX) &&
576 (card_type == LIO_210NV)) {
577 ret = (void *)&default_cn68xx_210nv_conf;
578 } else if ((oct->chip_id == OCTEON_CN68XX) &&
579 (card_type == LIO_410NV)) {
580 ret = (void *)&default_cn68xx_conf;
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700581 } else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
582 ret = (void *)&default_cn23xx_conf;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700583 }
584 break;
585 default:
586 break;
587 }
588 return ret;
589}
590
591static int __verify_octeon_config_info(struct octeon_device *oct, void *conf)
592{
593 switch (oct->chip_id) {
594 case OCTEON_CN66XX:
595 case OCTEON_CN68XX:
596 return lio_validate_cn6xxx_config_info(oct, conf);
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700597 case OCTEON_CN23XX_PF_VID:
598 return 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700599 default:
600 break;
601 }
602
603 return 1;
604}
605
606void *oct_get_config_info(struct octeon_device *oct, u16 card_type)
607{
608 void *conf = NULL;
609
610 conf = __retrieve_octeon_config_info(oct, card_type);
611 if (!conf)
612 return NULL;
613
614 if (__verify_octeon_config_info(oct, conf)) {
615 dev_err(&oct->pci_dev->dev, "Configuration verification failed\n");
616 return NULL;
617 }
618
619 return conf;
620}
621
622char *lio_get_state_string(atomic_t *state_ptr)
623{
624 s32 istate = (s32)atomic_read(state_ptr);
625
626 if (istate > OCT_DEV_STATES || istate < 0)
627 return oct_dev_state_str[OCT_DEV_STATE_INVALID];
628 return oct_dev_state_str[istate];
629}
630
631static char *get_oct_app_string(u32 app_mode)
632{
633 if (app_mode <= CVM_DRV_APP_END)
634 return oct_dev_app_str[app_mode - CVM_DRV_APP_START];
635 return oct_dev_app_str[CVM_DRV_INVALID_APP - CVM_DRV_APP_START];
636}
637
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700638void octeon_free_device_mem(struct octeon_device *oct)
639{
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -0700640 int i;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700641
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700642 for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
Raghu Vatsavayi763185a2016-11-14 15:54:45 -0800643 if (oct->io_qmask.oq & BIT_ULL(i))
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -0700644 vfree(oct->droq[i]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700645 }
646
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700647 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
Raghu Vatsavayi763185a2016-11-14 15:54:45 -0800648 if (oct->io_qmask.iq & BIT_ULL(i))
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -0700649 vfree(oct->instr_queue[i]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700650 }
651
652 i = oct->octeon_id;
653 vfree(oct);
654
655 octeon_device[i] = NULL;
656 octeon_device_count--;
657}
658
659static struct octeon_device *octeon_allocate_device_mem(u32 pci_id,
660 u32 priv_size)
661{
662 struct octeon_device *oct;
663 u8 *buf = NULL;
664 u32 octdevsize = 0, configsize = 0, size;
665
666 switch (pci_id) {
667 case OCTEON_CN68XX:
668 case OCTEON_CN66XX:
669 configsize = sizeof(struct octeon_cn6xxx);
670 break;
671
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700672 case OCTEON_CN23XX_PF_VID:
673 configsize = sizeof(struct octeon_cn23xx_pf);
674 break;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700675 default:
676 pr_err("%s: Unknown PCI Device: 0x%x\n",
677 __func__,
678 pci_id);
679 return NULL;
680 }
681
682 if (configsize & 0x7)
683 configsize += (8 - (configsize & 0x7));
684
685 octdevsize = sizeof(struct octeon_device);
686 if (octdevsize & 0x7)
687 octdevsize += (8 - (octdevsize & 0x7));
688
689 if (priv_size & 0x7)
690 priv_size += (8 - (priv_size & 0x7));
691
692 size = octdevsize + priv_size + configsize +
693 (sizeof(struct octeon_dispatch) * DISPATCH_LIST_SIZE);
694
695 buf = vmalloc(size);
696 if (!buf)
697 return NULL;
698
699 memset(buf, 0, size);
700
701 oct = (struct octeon_device *)buf;
702 oct->priv = (void *)(buf + octdevsize);
703 oct->chip = (void *)(buf + octdevsize + priv_size);
704 oct->dispatch.dlist = (struct octeon_dispatch *)
705 (buf + octdevsize + priv_size + configsize);
706
707 return oct;
708}
709
710struct octeon_device *octeon_allocate_device(u32 pci_id,
711 u32 priv_size)
712{
713 u32 oct_idx = 0;
714 struct octeon_device *oct = NULL;
715
716 for (oct_idx = 0; oct_idx < MAX_OCTEON_DEVICES; oct_idx++)
717 if (!octeon_device[oct_idx])
718 break;
719
720 if (oct_idx == MAX_OCTEON_DEVICES)
721 return NULL;
722
723 oct = octeon_allocate_device_mem(pci_id, priv_size);
724 if (!oct)
725 return NULL;
726
727 spin_lock_init(&oct->pci_win_lock);
728 spin_lock_init(&oct->mem_access_lock);
729
730 octeon_device_count++;
731 octeon_device[oct_idx] = oct;
732
733 oct->octeon_id = oct_idx;
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700734 snprintf(oct->device_name, sizeof(oct->device_name),
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700735 "LiquidIO%d", (oct->octeon_id));
736
737 return oct;
738}
739
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700740int
741octeon_allocate_ioq_vector(struct octeon_device *oct)
742{
743 int i, num_ioqs = 0;
744 struct octeon_ioq_vector *ioq_vector;
745 int cpu_num;
746 int size;
747
748 if (OCTEON_CN23XX_PF(oct))
749 num_ioqs = oct->sriov_info.num_pf_rings;
750 size = sizeof(struct octeon_ioq_vector) * num_ioqs;
751
752 oct->ioq_vector = vmalloc(size);
753 if (!oct->ioq_vector)
754 return 1;
755 memset(oct->ioq_vector, 0, size);
756 for (i = 0; i < num_ioqs; i++) {
757 ioq_vector = &oct->ioq_vector[i];
758 ioq_vector->oct_dev = oct;
759 ioq_vector->iq_index = i;
760 ioq_vector->droq_index = i;
Raghu Vatsavayi5d655562016-11-14 15:54:42 -0800761 ioq_vector->mbox = oct->mbox[i];
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700762
763 cpu_num = i % num_online_cpus();
764 cpumask_set_cpu(cpu_num, &ioq_vector->affinity_mask);
765
766 if (oct->chip_id == OCTEON_CN23XX_PF_VID)
767 ioq_vector->ioq_num = i + oct->sriov_info.pf_srn;
768 else
769 ioq_vector->ioq_num = i;
770 }
771 return 0;
772}
773
774void
775octeon_free_ioq_vector(struct octeon_device *oct)
776{
777 vfree(oct->ioq_vector);
778}
779
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700780/* this function is only for setting up the first queue */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700781int octeon_setup_instr_queues(struct octeon_device *oct)
782{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700783 u32 num_descs = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700784 u32 iq_no = 0;
785 union oct_txpciq txpciq;
786 int numa_node = cpu_to_node(iq_no % num_online_cpus());
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700787
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700788 if (OCTEON_CN6XXX(oct))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700789 num_descs =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800790 CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700791 else if (OCTEON_CN23XX_PF(oct))
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800792 num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_pf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700793
794 oct->num_iqs = 0;
795
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700796 oct->instr_queue[0] = vmalloc_node(sizeof(*oct->instr_queue[0]),
797 numa_node);
798 if (!oct->instr_queue[0])
799 oct->instr_queue[0] =
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700800 vmalloc(sizeof(struct octeon_instr_queue));
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700801 if (!oct->instr_queue[0])
802 return 1;
803 memset(oct->instr_queue[0], 0, sizeof(struct octeon_instr_queue));
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700804 oct->instr_queue[0]->q_index = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700805 oct->instr_queue[0]->app_ctx = (void *)(size_t)0;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700806 oct->instr_queue[0]->ifidx = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700807 txpciq.u64 = 0;
808 txpciq.s.q_no = iq_no;
Raghu Vatsavayi5b823512016-09-01 11:16:07 -0700809 txpciq.s.pkind = oct->pfvf_hsword.pkind;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700810 txpciq.s.use_qpg = 0;
811 txpciq.s.qpg = 0;
812 if (octeon_init_instr_queue(oct, txpciq, num_descs)) {
813 /* prevent memory leak */
814 vfree(oct->instr_queue[0]);
Raghu Vatsavayi515e7522016-11-14 15:54:44 -0800815 oct->instr_queue[0] = NULL;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700816 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700817 }
818
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700819 oct->num_iqs++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700820 return 0;
821}
822
823int octeon_setup_output_queues(struct octeon_device *oct)
824{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700825 u32 num_descs = 0;
826 u32 desc_size = 0;
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700827 u32 oq_no = 0;
828 int numa_node = cpu_to_node(oq_no % num_online_cpus());
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700829
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700830 if (OCTEON_CN6XXX(oct)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700831 num_descs =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800832 CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700833 desc_size =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800834 CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700835 } else if (OCTEON_CN23XX_PF(oct)) {
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800836 num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_pf));
837 desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_pf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700838 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700839 oct->num_oqs = 0;
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700840 oct->droq[0] = vmalloc_node(sizeof(*oct->droq[0]), numa_node);
841 if (!oct->droq[0])
842 oct->droq[0] = vmalloc(sizeof(*oct->droq[0]));
843 if (!oct->droq[0])
844 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700845
Raghu Vatsavayi515e7522016-11-14 15:54:44 -0800846 if (octeon_init_droq(oct, oq_no, num_descs, desc_size, NULL)) {
847 vfree(oct->droq[oq_no]);
848 oct->droq[oq_no] = NULL;
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700849 return 1;
Raghu Vatsavayi515e7522016-11-14 15:54:44 -0800850 }
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700851 oct->num_oqs++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700852
853 return 0;
854}
855
856void octeon_set_io_queues_off(struct octeon_device *oct)
857{
Raghu Vatsavayi5b823512016-09-01 11:16:07 -0700858 if (OCTEON_CN6XXX(oct)) {
859 octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
860 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
861 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700862}
863
864void octeon_set_droq_pkt_op(struct octeon_device *oct,
865 u32 q_no,
866 u32 enable)
867{
868 u32 reg_val = 0;
869
870 /* Disable the i/p and o/p queues for this Octeon. */
Raghu Vatsavayi5b823512016-09-01 11:16:07 -0700871 if (OCTEON_CN6XXX(oct)) {
872 reg_val = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700873
Raghu Vatsavayi5b823512016-09-01 11:16:07 -0700874 if (enable)
875 reg_val = reg_val | (1 << q_no);
876 else
877 reg_val = reg_val & (~(1 << q_no));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700878
Raghu Vatsavayi5b823512016-09-01 11:16:07 -0700879 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, reg_val);
880 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700881}
882
883int octeon_init_dispatch_list(struct octeon_device *oct)
884{
885 u32 i;
886
887 oct->dispatch.count = 0;
888
889 for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
890 oct->dispatch.dlist[i].opcode = 0;
891 INIT_LIST_HEAD(&oct->dispatch.dlist[i].list);
892 }
893
894 for (i = 0; i <= REQTYPE_LAST; i++)
895 octeon_register_reqtype_free_fn(oct, i, NULL);
896
897 spin_lock_init(&oct->dispatch.lock);
898
899 return 0;
900}
901
902void octeon_delete_dispatch_list(struct octeon_device *oct)
903{
904 u32 i;
905 struct list_head freelist, *temp, *tmp2;
906
907 INIT_LIST_HEAD(&freelist);
908
909 spin_lock_bh(&oct->dispatch.lock);
910
911 for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
912 struct list_head *dispatch;
913
914 dispatch = &oct->dispatch.dlist[i].list;
915 while (dispatch->next != dispatch) {
916 temp = dispatch->next;
917 list_del(temp);
918 list_add_tail(temp, &freelist);
919 }
920
921 oct->dispatch.dlist[i].opcode = 0;
922 }
923
924 oct->dispatch.count = 0;
925
926 spin_unlock_bh(&oct->dispatch.lock);
927
928 list_for_each_safe(temp, tmp2, &freelist) {
929 list_del(temp);
930 vfree(temp);
931 }
932}
933
934octeon_dispatch_fn_t
935octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
936 u16 subcode)
937{
938 u32 idx;
939 struct list_head *dispatch;
940 octeon_dispatch_fn_t fn = NULL;
941 u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
942
943 idx = combined_opcode & OCTEON_OPCODE_MASK;
944
945 spin_lock_bh(&octeon_dev->dispatch.lock);
946
947 if (octeon_dev->dispatch.count == 0) {
948 spin_unlock_bh(&octeon_dev->dispatch.lock);
949 return NULL;
950 }
951
952 if (!(octeon_dev->dispatch.dlist[idx].opcode)) {
953 spin_unlock_bh(&octeon_dev->dispatch.lock);
954 return NULL;
955 }
956
957 if (octeon_dev->dispatch.dlist[idx].opcode == combined_opcode) {
958 fn = octeon_dev->dispatch.dlist[idx].dispatch_fn;
959 } else {
960 list_for_each(dispatch,
961 &octeon_dev->dispatch.dlist[idx].list) {
962 if (((struct octeon_dispatch *)dispatch)->opcode ==
963 combined_opcode) {
964 fn = ((struct octeon_dispatch *)
965 dispatch)->dispatch_fn;
966 break;
967 }
968 }
969 }
970
971 spin_unlock_bh(&octeon_dev->dispatch.lock);
972 return fn;
973}
974
975/* octeon_register_dispatch_fn
976 * Parameters:
977 * octeon_id - id of the octeon device.
978 * opcode - opcode for which driver should call the registered function
979 * subcode - subcode for which driver should call the registered function
980 * fn - The function to call when a packet with "opcode" arrives in
981 * octeon output queues.
982 * fn_arg - The argument to be passed when calling function "fn".
983 * Description:
984 * Registers a function and its argument to be called when a packet
985 * arrives in Octeon output queues with "opcode".
986 * Returns:
987 * Success: 0
988 * Failure: 1
989 * Locks:
990 * No locks are held.
991 */
992int
993octeon_register_dispatch_fn(struct octeon_device *oct,
994 u16 opcode,
995 u16 subcode,
996 octeon_dispatch_fn_t fn, void *fn_arg)
997{
998 u32 idx;
999 octeon_dispatch_fn_t pfn;
1000 u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
1001
1002 idx = combined_opcode & OCTEON_OPCODE_MASK;
1003
1004 spin_lock_bh(&oct->dispatch.lock);
1005 /* Add dispatch function to first level of lookup table */
1006 if (oct->dispatch.dlist[idx].opcode == 0) {
1007 oct->dispatch.dlist[idx].opcode = combined_opcode;
1008 oct->dispatch.dlist[idx].dispatch_fn = fn;
1009 oct->dispatch.dlist[idx].arg = fn_arg;
1010 oct->dispatch.count++;
1011 spin_unlock_bh(&oct->dispatch.lock);
1012 return 0;
1013 }
1014
1015 spin_unlock_bh(&oct->dispatch.lock);
1016
1017 /* Check if there was a function already registered for this
1018 * opcode/subcode.
1019 */
1020 pfn = octeon_get_dispatch(oct, opcode, subcode);
1021 if (!pfn) {
1022 struct octeon_dispatch *dispatch;
1023
1024 dev_dbg(&oct->pci_dev->dev,
1025 "Adding opcode to dispatch list linked list\n");
1026 dispatch = (struct octeon_dispatch *)
1027 vmalloc(sizeof(struct octeon_dispatch));
1028 if (!dispatch) {
1029 dev_err(&oct->pci_dev->dev,
1030 "No memory to add dispatch function\n");
1031 return 1;
1032 }
1033 dispatch->opcode = combined_opcode;
1034 dispatch->dispatch_fn = fn;
1035 dispatch->arg = fn_arg;
1036
1037 /* Add dispatch function to linked list of fn ptrs
1038 * at the hashed index.
1039 */
1040 spin_lock_bh(&oct->dispatch.lock);
1041 list_add(&dispatch->list, &oct->dispatch.dlist[idx].list);
1042 oct->dispatch.count++;
1043 spin_unlock_bh(&oct->dispatch.lock);
1044
1045 } else {
1046 dev_err(&oct->pci_dev->dev,
1047 "Found previously registered dispatch fn for opcode/subcode: %x/%x\n",
1048 opcode, subcode);
1049 return 1;
1050 }
1051
1052 return 0;
1053}
1054
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001055int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf)
1056{
1057 u32 i;
1058 char app_name[16];
1059 struct octeon_device *oct = (struct octeon_device *)buf;
1060 struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
1061 struct octeon_core_setup *cs = NULL;
1062 u32 num_nic_ports = 0;
1063
1064 if (OCTEON_CN6XXX(oct))
1065 num_nic_ports =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08001066 CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001067 else if (OCTEON_CN23XX_PF(oct))
1068 num_nic_ports =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08001069 CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn23xx_pf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001070
1071 if (atomic_read(&oct->status) >= OCT_DEV_RUNNING) {
1072 dev_err(&oct->pci_dev->dev, "Received CORE OK when device state is 0x%x\n",
1073 atomic_read(&oct->status));
1074 goto core_drv_init_err;
1075 }
1076
1077 strncpy(app_name,
1078 get_oct_app_string(
1079 (u32)recv_pkt->rh.r_core_drv_init.app_mode),
1080 sizeof(app_name) - 1);
1081 oct->app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07001082 if (recv_pkt->rh.r_core_drv_init.app_mode == CVM_DRV_NIC_APP) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001083 oct->fw_info.max_nic_ports =
1084 (u32)recv_pkt->rh.r_core_drv_init.max_nic_ports;
1085 oct->fw_info.num_gmx_ports =
1086 (u32)recv_pkt->rh.r_core_drv_init.num_gmx_ports;
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07001087 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001088
1089 if (oct->fw_info.max_nic_ports < num_nic_ports) {
1090 dev_err(&oct->pci_dev->dev,
1091 "Config has more ports than firmware allows (%d > %d).\n",
1092 num_nic_ports, oct->fw_info.max_nic_ports);
1093 goto core_drv_init_err;
1094 }
1095 oct->fw_info.app_cap_flags = recv_pkt->rh.r_core_drv_init.app_cap_flags;
1096 oct->fw_info.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001097 oct->pfvf_hsword.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
1098
1099 oct->pfvf_hsword.pkind = recv_pkt->rh.r_core_drv_init.pkind;
1100
1101 for (i = 0; i < oct->num_iqs; i++)
1102 oct->instr_queue[i]->txpciq.s.pkind = oct->pfvf_hsword.pkind;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001103
1104 atomic_set(&oct->status, OCT_DEV_CORE_OK);
1105
1106 cs = &core_setup[oct->octeon_id];
1107
1108 if (recv_pkt->buffer_size[0] != sizeof(*cs)) {
1109 dev_dbg(&oct->pci_dev->dev, "Core setup bytes expected %u found %d\n",
1110 (u32)sizeof(*cs),
1111 recv_pkt->buffer_size[0]);
1112 }
1113
1114 memcpy(cs, get_rbd(recv_pkt->buffer_ptr[0]), sizeof(*cs));
1115 strncpy(oct->boardinfo.name, cs->boardname, OCT_BOARD_NAME);
1116 strncpy(oct->boardinfo.serial_number, cs->board_serial_number,
1117 OCT_SERIAL_LEN);
1118
1119 octeon_swap_8B_data((u64 *)cs, (sizeof(*cs) >> 3));
1120
1121 oct->boardinfo.major = cs->board_rev_major;
1122 oct->boardinfo.minor = cs->board_rev_minor;
1123
1124 dev_info(&oct->pci_dev->dev,
1125 "Running %s (%llu Hz)\n",
1126 app_name, CVM_CAST64(cs->corefreq));
1127
1128core_drv_init_err:
1129 for (i = 0; i < recv_pkt->buffer_count; i++)
1130 recv_buffer_free(recv_pkt->buffer_ptr[i]);
1131 octeon_free_recv_info(recv_info);
1132 return 0;
1133}
1134
1135int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no)
1136
1137{
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001138 if (oct && (q_no < MAX_OCTEON_INSTR_QUEUES(oct)) &&
Raghu Vatsavayi763185a2016-11-14 15:54:45 -08001139 (oct->io_qmask.iq & BIT_ULL(q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001140 return oct->instr_queue[q_no]->max_count;
1141
1142 return -1;
1143}
1144
1145int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no)
1146{
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001147 if (oct && (q_no < MAX_OCTEON_OUTPUT_QUEUES(oct)) &&
Raghu Vatsavayi763185a2016-11-14 15:54:45 -08001148 (oct->io_qmask.oq & BIT_ULL(q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001149 return oct->droq[q_no]->max_count;
1150 return -1;
1151}
1152
1153/* Retruns the host firmware handshake OCTEON specific configuration */
1154struct octeon_config *octeon_get_conf(struct octeon_device *oct)
1155{
1156 struct octeon_config *default_oct_conf = NULL;
1157
1158 /* check the OCTEON Device model & return the corresponding octeon
1159 * configuration
1160 */
1161
1162 if (OCTEON_CN6XXX(oct)) {
1163 default_oct_conf =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08001164 (struct octeon_config *)(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001165 } else if (OCTEON_CN23XX_PF(oct)) {
1166 default_oct_conf = (struct octeon_config *)
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08001167 (CHIP_CONF(oct, cn23xx_pf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001168 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001169 return default_oct_conf;
1170}
1171
1172/* scratch register address is same in all the OCT-II and CN70XX models */
1173#define CNXX_SLI_SCRATCH1 0x3C0
1174
1175/** Get the octeon device pointer.
1176 * @param octeon_id - The id for which the octeon device pointer is required.
1177 * @return Success: Octeon device pointer.
1178 * @return Failure: NULL.
1179 */
1180struct octeon_device *lio_get_device(u32 octeon_id)
1181{
1182 if (octeon_id >= MAX_OCTEON_DEVICES)
1183 return NULL;
1184 else
1185 return octeon_device[octeon_id];
1186}
1187
1188u64 lio_pci_readq(struct octeon_device *oct, u64 addr)
1189{
1190 u64 val64;
1191 unsigned long flags;
1192 u32 val32, addrhi;
1193
1194 spin_lock_irqsave(&oct->pci_win_lock, flags);
1195
1196 /* The windowed read happens when the LSB of the addr is written.
1197 * So write MSB first
1198 */
1199 addrhi = (addr >> 32);
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001200 if ((oct->chip_id == OCTEON_CN66XX) ||
1201 (oct->chip_id == OCTEON_CN68XX) ||
1202 (oct->chip_id == OCTEON_CN23XX_PF_VID))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001203 addrhi |= 0x00060000;
1204 writel(addrhi, oct->reg_list.pci_win_rd_addr_hi);
1205
1206 /* Read back to preserve ordering of writes */
1207 val32 = readl(oct->reg_list.pci_win_rd_addr_hi);
1208
1209 writel(addr & 0xffffffff, oct->reg_list.pci_win_rd_addr_lo);
1210 val32 = readl(oct->reg_list.pci_win_rd_addr_lo);
1211
1212 val64 = readq(oct->reg_list.pci_win_rd_data);
1213
1214 spin_unlock_irqrestore(&oct->pci_win_lock, flags);
1215
1216 return val64;
1217}
1218
1219void lio_pci_writeq(struct octeon_device *oct,
1220 u64 val,
1221 u64 addr)
1222{
1223 u32 val32;
1224 unsigned long flags;
1225
1226 spin_lock_irqsave(&oct->pci_win_lock, flags);
1227
1228 writeq(addr, oct->reg_list.pci_win_wr_addr);
1229
1230 /* The write happens when the LSB is written. So write MSB first. */
1231 writel(val >> 32, oct->reg_list.pci_win_wr_data_hi);
1232 /* Read the MSB to ensure ordering of writes. */
1233 val32 = readl(oct->reg_list.pci_win_wr_data_hi);
1234
1235 writel(val & 0xffffffff, oct->reg_list.pci_win_wr_data_lo);
1236
1237 spin_unlock_irqrestore(&oct->pci_win_lock, flags);
1238}
1239
1240int octeon_mem_access_ok(struct octeon_device *oct)
1241{
1242 u64 access_okay = 0;
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001243 u64 lmc0_reset_ctl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001244
1245 /* Check to make sure a DDR interface is enabled */
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001246 if (OCTEON_CN23XX_PF(oct)) {
1247 lmc0_reset_ctl = lio_pci_readq(oct, CN23XX_LMC0_RESET_CTL);
1248 access_okay =
1249 (lmc0_reset_ctl & CN23XX_LMC0_RESET_CTL_DDR3RST_MASK);
1250 } else {
1251 lmc0_reset_ctl = lio_pci_readq(oct, CN6XXX_LMC0_RESET_CTL);
1252 access_okay =
1253 (lmc0_reset_ctl & CN6XXX_LMC0_RESET_CTL_DDR3RST_MASK);
1254 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001255
1256 return access_okay ? 0 : 1;
1257}
1258
1259int octeon_wait_for_ddr_init(struct octeon_device *oct, u32 *timeout)
1260{
1261 int ret = 1;
1262 u32 ms;
1263
1264 if (!timeout)
1265 return ret;
1266
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001267 for (ms = 0; (ret != 0) && ((*timeout == 0) || (ms <= *timeout));
1268 ms += HZ / 10) {
1269 ret = octeon_mem_access_ok(oct);
1270
1271 /* wait 100 ms */
1272 if (ret)
1273 schedule_timeout_uninterruptible(HZ / 10);
1274 }
1275
1276 return ret;
1277}
1278
1279/** Get the octeon id assigned to the octeon device passed as argument.
1280 * This function is exported to other modules.
1281 * @param dev - octeon device pointer passed as a void *.
1282 * @return octeon device id
1283 */
1284int lio_get_device_id(void *dev)
1285{
1286 struct octeon_device *octeon_dev = (struct octeon_device *)dev;
1287 u32 i;
1288
1289 for (i = 0; i < MAX_OCTEON_DEVICES; i++)
1290 if (octeon_device[i] == octeon_dev)
1291 return octeon_dev->octeon_id;
1292 return -1;
1293}
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001294
1295void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq)
1296{
Raghu Vatsavayi9ded1a52016-09-01 11:16:10 -07001297 u64 instr_cnt;
1298 struct octeon_device *oct = NULL;
1299
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001300 /* the whole thing needs to be atomic, ideally */
1301 if (droq) {
1302 spin_lock_bh(&droq->lock);
1303 writel(droq->pkt_count, droq->pkts_sent_reg);
1304 droq->pkt_count = 0;
1305 spin_unlock_bh(&droq->lock);
Raghu Vatsavayi9ded1a52016-09-01 11:16:10 -07001306 oct = droq->oct_dev;
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001307 }
1308 if (iq) {
1309 spin_lock_bh(&iq->lock);
1310 writel(iq->pkt_in_done, iq->inst_cnt_reg);
1311 iq->pkt_in_done = 0;
1312 spin_unlock_bh(&iq->lock);
Raghu Vatsavayi9ded1a52016-09-01 11:16:10 -07001313 oct = iq->oct_dev;
1314 }
1315 /*write resend. Writing RESEND in SLI_PKTX_CNTS should be enough
1316 *to trigger tx interrupts as well, if they are pending.
1317 */
1318 if (oct && OCTEON_CN23XX_PF(oct)) {
1319 if (droq)
1320 writeq(CN23XX_INTR_RESEND, droq->pkts_sent_reg);
1321 /*we race with firmrware here. read and write the IN_DONE_CNTS*/
1322 else if (iq) {
1323 instr_cnt = readq(iq->inst_cnt_reg);
1324 writeq(((instr_cnt & 0xFFFFFFFF00000000ULL) |
1325 CN23XX_INTR_RESEND),
1326 iq->inst_cnt_reg);
1327 }
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001328 }
1329}