blob: 3b7cc9320deb15eecdf226c0def9962de20e43dd [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 Vatsavayi111fc642016-11-28 16:54:34 -080031#include "cn23xx_vf_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070032
33/** Default configuration
34 * for CN66XX OCTEON Models.
35 */
36static struct octeon_config default_cn66xx_conf = {
37 .card_type = LIO_210SV,
38 .card_name = LIO_210SV_NAME,
39
40 /** IQ attributes */
41 .iq = {
42 .max_iqs = CN6XXX_CFG_IO_QUEUES,
43 .pending_list_size =
44 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
45 .instr_type = OCTEON_64BYTE_INSTR,
46 .db_min = CN6XXX_DB_MIN,
47 .db_timeout = CN6XXX_DB_TIMEOUT,
48 }
49 ,
50
51 /** OQ attributes */
52 .oq = {
53 .max_oqs = CN6XXX_CFG_IO_QUEUES,
54 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
55 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
56 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
57 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
58 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
59 }
60 ,
61
62 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_66XX,
63 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
64 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
65 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
66
67 /* For ethernet interface 0: Port cfg Attributes */
68 .nic_if_cfg[0] = {
69 /* Max Txqs: Half for each of the two ports :max_iq/2 */
70 .max_txqs = MAX_TXQS_PER_INTF,
71
72 /* Actual configured value. Range could be: 1...max_txqs */
73 .num_txqs = DEF_TXQS_PER_INTF,
74
75 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
76 .max_rxqs = MAX_RXQS_PER_INTF,
77
78 /* Actual configured value. Range could be: 1...max_rxqs */
79 .num_rxqs = DEF_RXQS_PER_INTF,
80
81 /* Num of desc for rx rings */
82 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
83
84 /* Num of desc for tx rings */
85 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
86
87 /* SKB size, We need not change buf size even for Jumbo frames.
88 * Octeon can send jumbo frames in 4 consecutive descriptors,
89 */
90 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
91
92 .base_queue = BASE_QUEUE_NOT_REQUESTED,
93
94 .gmx_port_id = 0,
95 },
96
97 .nic_if_cfg[1] = {
98 /* Max Txqs: Half for each of the two ports :max_iq/2 */
99 .max_txqs = MAX_TXQS_PER_INTF,
100
101 /* Actual configured value. Range could be: 1...max_txqs */
102 .num_txqs = DEF_TXQS_PER_INTF,
103
104 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
105 .max_rxqs = MAX_RXQS_PER_INTF,
106
107 /* Actual configured value. Range could be: 1...max_rxqs */
108 .num_rxqs = DEF_RXQS_PER_INTF,
109
110 /* Num of desc for rx rings */
111 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
112
113 /* Num of desc for tx rings */
114 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
115
116 /* SKB size, We need not change buf size even for Jumbo frames.
117 * Octeon can send jumbo frames in 4 consecutive descriptors,
118 */
119 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
120
121 .base_queue = BASE_QUEUE_NOT_REQUESTED,
122
123 .gmx_port_id = 1,
124 },
125
126 /** Miscellaneous attributes */
127 .misc = {
128 /* Host driver link query interval */
129 .oct_link_query_interval = 100,
130
131 /* Octeon link query interval */
132 .host_link_query_interval = 500,
133
134 .enable_sli_oq_bp = 0,
135
136 /* Control queue group */
137 .ctrlq_grp = 1,
138 }
139 ,
140};
141
142/** Default configuration
143 * for CN68XX OCTEON Model.
144 */
145
146static struct octeon_config default_cn68xx_conf = {
147 .card_type = LIO_410NV,
148 .card_name = LIO_410NV_NAME,
149
150 /** IQ attributes */
151 .iq = {
152 .max_iqs = CN6XXX_CFG_IO_QUEUES,
153 .pending_list_size =
154 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
155 .instr_type = OCTEON_64BYTE_INSTR,
156 .db_min = CN6XXX_DB_MIN,
157 .db_timeout = CN6XXX_DB_TIMEOUT,
158 }
159 ,
160
161 /** OQ attributes */
162 .oq = {
163 .max_oqs = CN6XXX_CFG_IO_QUEUES,
164 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
165 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
166 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
167 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
168 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
169 }
170 ,
171
172 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX,
173 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
174 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
175 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
176
177 .nic_if_cfg[0] = {
178 /* Max Txqs: Half for each of the two ports :max_iq/2 */
179 .max_txqs = MAX_TXQS_PER_INTF,
180
181 /* Actual configured value. Range could be: 1...max_txqs */
182 .num_txqs = DEF_TXQS_PER_INTF,
183
184 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
185 .max_rxqs = MAX_RXQS_PER_INTF,
186
187 /* Actual configured value. Range could be: 1...max_rxqs */
188 .num_rxqs = DEF_RXQS_PER_INTF,
189
190 /* Num of desc for rx rings */
191 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
192
193 /* Num of desc for tx rings */
194 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
195
196 /* SKB size, We need not change buf size even for Jumbo frames.
197 * Octeon can send jumbo frames in 4 consecutive descriptors,
198 */
199 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
200
201 .base_queue = BASE_QUEUE_NOT_REQUESTED,
202
203 .gmx_port_id = 0,
204 },
205
206 .nic_if_cfg[1] = {
207 /* Max Txqs: Half for each of the two ports :max_iq/2 */
208 .max_txqs = MAX_TXQS_PER_INTF,
209
210 /* Actual configured value. Range could be: 1...max_txqs */
211 .num_txqs = DEF_TXQS_PER_INTF,
212
213 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
214 .max_rxqs = MAX_RXQS_PER_INTF,
215
216 /* Actual configured value. Range could be: 1...max_rxqs */
217 .num_rxqs = DEF_RXQS_PER_INTF,
218
219 /* Num of desc for rx rings */
220 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
221
222 /* Num of desc for tx rings */
223 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
224
225 /* SKB size, We need not change buf size even for Jumbo frames.
226 * Octeon can send jumbo frames in 4 consecutive descriptors,
227 */
228 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
229
230 .base_queue = BASE_QUEUE_NOT_REQUESTED,
231
232 .gmx_port_id = 1,
233 },
234
235 .nic_if_cfg[2] = {
236 /* Max Txqs: Half for each of the two ports :max_iq/2 */
237 .max_txqs = MAX_TXQS_PER_INTF,
238
239 /* Actual configured value. Range could be: 1...max_txqs */
240 .num_txqs = DEF_TXQS_PER_INTF,
241
242 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
243 .max_rxqs = MAX_RXQS_PER_INTF,
244
245 /* Actual configured value. Range could be: 1...max_rxqs */
246 .num_rxqs = DEF_RXQS_PER_INTF,
247
248 /* Num of desc for rx rings */
249 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
250
251 /* Num of desc for tx rings */
252 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
253
254 /* SKB size, We need not change buf size even for Jumbo frames.
255 * Octeon can send jumbo frames in 4 consecutive descriptors,
256 */
257 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
258
259 .base_queue = BASE_QUEUE_NOT_REQUESTED,
260
261 .gmx_port_id = 2,
262 },
263
264 .nic_if_cfg[3] = {
265 /* Max Txqs: Half for each of the two ports :max_iq/2 */
266 .max_txqs = MAX_TXQS_PER_INTF,
267
268 /* Actual configured value. Range could be: 1...max_txqs */
269 .num_txqs = DEF_TXQS_PER_INTF,
270
271 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
272 .max_rxqs = MAX_RXQS_PER_INTF,
273
274 /* Actual configured value. Range could be: 1...max_rxqs */
275 .num_rxqs = DEF_RXQS_PER_INTF,
276
277 /* Num of desc for rx rings */
278 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
279
280 /* Num of desc for tx rings */
281 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
282
283 /* SKB size, We need not change buf size even for Jumbo frames.
284 * Octeon can send jumbo frames in 4 consecutive descriptors,
285 */
286 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
287
288 .base_queue = BASE_QUEUE_NOT_REQUESTED,
289
290 .gmx_port_id = 3,
291 },
292
293 /** Miscellaneous attributes */
294 .misc = {
295 /* Host driver link query interval */
296 .oct_link_query_interval = 100,
297
298 /* Octeon link query interval */
299 .host_link_query_interval = 500,
300
301 .enable_sli_oq_bp = 0,
302
303 /* Control queue group */
304 .ctrlq_grp = 1,
305 }
306 ,
307};
308
309/** Default configuration
310 * for CN68XX OCTEON Model.
311 */
312static struct octeon_config default_cn68xx_210nv_conf = {
313 .card_type = LIO_210NV,
314 .card_name = LIO_210NV_NAME,
315
316 /** IQ attributes */
317
318 .iq = {
319 .max_iqs = CN6XXX_CFG_IO_QUEUES,
320 .pending_list_size =
321 (CN6XXX_MAX_IQ_DESCRIPTORS * CN6XXX_CFG_IO_QUEUES),
322 .instr_type = OCTEON_64BYTE_INSTR,
323 .db_min = CN6XXX_DB_MIN,
324 .db_timeout = CN6XXX_DB_TIMEOUT,
325 }
326 ,
327
328 /** OQ attributes */
329 .oq = {
330 .max_oqs = CN6XXX_CFG_IO_QUEUES,
331 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
332 .refill_threshold = CN6XXX_OQ_REFIL_THRESHOLD,
333 .oq_intr_pkt = CN6XXX_OQ_INTR_PKT,
334 .oq_intr_time = CN6XXX_OQ_INTR_TIME,
335 .pkts_per_intr = CN6XXX_OQ_PKTSPER_INTR,
336 }
337 ,
338
339 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_68XX_210NV,
340 .num_def_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
341 .num_def_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
342 .def_rx_buf_size = CN6XXX_OQ_BUF_SIZE,
343
344 .nic_if_cfg[0] = {
345 /* Max Txqs: Half for each of the two ports :max_iq/2 */
346 .max_txqs = MAX_TXQS_PER_INTF,
347
348 /* Actual configured value. Range could be: 1...max_txqs */
349 .num_txqs = DEF_TXQS_PER_INTF,
350
351 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
352 .max_rxqs = MAX_RXQS_PER_INTF,
353
354 /* Actual configured value. Range could be: 1...max_rxqs */
355 .num_rxqs = DEF_RXQS_PER_INTF,
356
357 /* Num of desc for rx rings */
358 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
359
360 /* Num of desc for tx rings */
361 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
362
363 /* SKB size, We need not change buf size even for Jumbo frames.
364 * Octeon can send jumbo frames in 4 consecutive descriptors,
365 */
366 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
367
368 .base_queue = BASE_QUEUE_NOT_REQUESTED,
369
370 .gmx_port_id = 0,
371 },
372
373 .nic_if_cfg[1] = {
374 /* Max Txqs: Half for each of the two ports :max_iq/2 */
375 .max_txqs = MAX_TXQS_PER_INTF,
376
377 /* Actual configured value. Range could be: 1...max_txqs */
378 .num_txqs = DEF_TXQS_PER_INTF,
379
380 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
381 .max_rxqs = MAX_RXQS_PER_INTF,
382
383 /* Actual configured value. Range could be: 1...max_rxqs */
384 .num_rxqs = DEF_RXQS_PER_INTF,
385
386 /* Num of desc for rx rings */
387 .num_rx_descs = CN6XXX_MAX_OQ_DESCRIPTORS,
388
389 /* Num of desc for tx rings */
390 .num_tx_descs = CN6XXX_MAX_IQ_DESCRIPTORS,
391
392 /* SKB size, We need not change buf size even for Jumbo frames.
393 * Octeon can send jumbo frames in 4 consecutive descriptors,
394 */
395 .rx_buf_size = CN6XXX_OQ_BUF_SIZE,
396
397 .base_queue = BASE_QUEUE_NOT_REQUESTED,
398
399 .gmx_port_id = 1,
400 },
401
402 /** Miscellaneous attributes */
403 .misc = {
404 /* Host driver link query interval */
405 .oct_link_query_interval = 100,
406
407 /* Octeon link query interval */
408 .host_link_query_interval = 500,
409
410 .enable_sli_oq_bp = 0,
411
412 /* Control queue group */
413 .ctrlq_grp = 1,
414 }
415 ,
416};
417
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700418static struct octeon_config default_cn23xx_conf = {
419 .card_type = LIO_23XX,
420 .card_name = LIO_23XX_NAME,
421 /** IQ attributes */
422 .iq = {
423 .max_iqs = CN23XX_CFG_IO_QUEUES,
424 .pending_list_size = (CN23XX_MAX_IQ_DESCRIPTORS *
425 CN23XX_CFG_IO_QUEUES),
426 .instr_type = OCTEON_64BYTE_INSTR,
427 .db_min = CN23XX_DB_MIN,
428 .db_timeout = CN23XX_DB_TIMEOUT,
429 .iq_intr_pkt = CN23XX_DEF_IQ_INTR_THRESHOLD,
430 },
431
432 /** OQ attributes */
433 .oq = {
434 .max_oqs = CN23XX_CFG_IO_QUEUES,
435 .info_ptr = OCTEON_OQ_INFOPTR_MODE,
436 .pkts_per_intr = CN23XX_OQ_PKTSPER_INTR,
437 .refill_threshold = CN23XX_OQ_REFIL_THRESHOLD,
438 .oq_intr_pkt = CN23XX_OQ_INTR_PKT,
439 .oq_intr_time = CN23XX_OQ_INTR_TIME,
440 },
441
442 .num_nic_ports = DEFAULT_NUM_NIC_PORTS_23XX,
443 .num_def_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
444 .num_def_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
445 .def_rx_buf_size = CN23XX_OQ_BUF_SIZE,
446
447 /* For ethernet interface 0: Port cfg Attributes */
448 .nic_if_cfg[0] = {
449 /* Max Txqs: Half for each of the two ports :max_iq/2 */
450 .max_txqs = MAX_TXQS_PER_INTF,
451
452 /* Actual configured value. Range could be: 1...max_txqs */
453 .num_txqs = DEF_TXQS_PER_INTF,
454
455 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
456 .max_rxqs = MAX_RXQS_PER_INTF,
457
458 /* Actual configured value. Range could be: 1...max_rxqs */
459 .num_rxqs = DEF_RXQS_PER_INTF,
460
461 /* Num of desc for rx rings */
462 .num_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
463
464 /* Num of desc for tx rings */
465 .num_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
466
467 /* SKB size, We need not change buf size even for Jumbo frames.
468 * Octeon can send jumbo frames in 4 consecutive descriptors,
469 */
470 .rx_buf_size = CN23XX_OQ_BUF_SIZE,
471
472 .base_queue = BASE_QUEUE_NOT_REQUESTED,
473
474 .gmx_port_id = 0,
475 },
476
477 .nic_if_cfg[1] = {
478 /* Max Txqs: Half for each of the two ports :max_iq/2 */
479 .max_txqs = MAX_TXQS_PER_INTF,
480
481 /* Actual configured value. Range could be: 1...max_txqs */
482 .num_txqs = DEF_TXQS_PER_INTF,
483
484 /* Max Rxqs: Half for each of the two ports :max_oq/2 */
485 .max_rxqs = MAX_RXQS_PER_INTF,
486
487 /* Actual configured value. Range could be: 1...max_rxqs */
488 .num_rxqs = DEF_RXQS_PER_INTF,
489
490 /* Num of desc for rx rings */
491 .num_rx_descs = CN23XX_MAX_OQ_DESCRIPTORS,
492
493 /* Num of desc for tx rings */
494 .num_tx_descs = CN23XX_MAX_IQ_DESCRIPTORS,
495
496 /* SKB size, We need not change buf size even for Jumbo frames.
497 * Octeon can send jumbo frames in 4 consecutive descriptors,
498 */
499 .rx_buf_size = CN23XX_OQ_BUF_SIZE,
500
501 .base_queue = BASE_QUEUE_NOT_REQUESTED,
502
503 .gmx_port_id = 1,
504 },
505
506 .misc = {
507 /* Host driver link query interval */
508 .oct_link_query_interval = 100,
509
510 /* Octeon link query interval */
511 .host_link_query_interval = 500,
512
513 .enable_sli_oq_bp = 0,
514
515 /* Control queue group */
516 .ctrlq_grp = 1,
517 }
518};
519
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700520static struct octeon_config_ptr {
521 u32 conf_type;
522} oct_conf_info[MAX_OCTEON_DEVICES] = {
523 {
524 OCTEON_CONFIG_TYPE_DEFAULT,
525 }, {
526 OCTEON_CONFIG_TYPE_DEFAULT,
527 }, {
528 OCTEON_CONFIG_TYPE_DEFAULT,
529 }, {
530 OCTEON_CONFIG_TYPE_DEFAULT,
531 },
532};
533
534static char oct_dev_state_str[OCT_DEV_STATES + 1][32] = {
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -0700535 "BEGIN", "PCI-MAP-DONE", "DISPATCH-INIT-DONE",
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700536 "IQ-INIT-DONE", "SCBUFF-POOL-INIT-DONE", "RESPLIST-INIT-DONE",
537 "DROQ-INIT-DONE", "IO-QUEUES-INIT-DONE", "CONSOLE-INIT-DONE",
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -0700538 "HOST-READY", "CORE-READY", "RUNNING", "IN-RESET",
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700539 "INVALID"
540};
541
542static char oct_dev_app_str[CVM_DRV_APP_COUNT + 1][32] = {
543 "BASE", "NIC", "UNKNOWN"};
544
545static struct octeon_device *octeon_device[MAX_OCTEON_DEVICES];
Rick Farringtone1e3ce62017-05-16 11:14:50 -0700546static atomic_t adapter_refcounts[MAX_OCTEON_DEVICES];
547
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700548static u32 octeon_device_count;
Rick Farringtone1e3ce62017-05-16 11:14:50 -0700549/* locks device array (i.e. octeon_device[]) */
Colin Ian King4454e862017-05-18 10:14:01 +0100550static spinlock_t octeon_devices_lock;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700551
552static struct octeon_core_setup core_setup[MAX_OCTEON_DEVICES];
553
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700554static void oct_set_config_info(int oct_id, int conf_type)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700555{
556 if (conf_type < 0 || conf_type > (NUM_OCTEON_CONFS - 1))
557 conf_type = OCTEON_CONFIG_TYPE_DEFAULT;
558 oct_conf_info[oct_id].conf_type = conf_type;
559}
560
561void octeon_init_device_list(int conf_type)
562{
563 int i;
564
565 memset(octeon_device, 0, (sizeof(void *) * MAX_OCTEON_DEVICES));
566 for (i = 0; i < MAX_OCTEON_DEVICES; i++)
567 oct_set_config_info(i, conf_type);
Rick Farringtone1e3ce62017-05-16 11:14:50 -0700568 spin_lock_init(&octeon_devices_lock);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700569}
570
571static void *__retrieve_octeon_config_info(struct octeon_device *oct,
572 u16 card_type)
573{
574 u32 oct_id = oct->octeon_id;
575 void *ret = NULL;
576
577 switch (oct_conf_info[oct_id].conf_type) {
578 case OCTEON_CONFIG_TYPE_DEFAULT:
579 if (oct->chip_id == OCTEON_CN66XX) {
Raghu Vatsavayi69c69da2016-11-28 16:54:35 -0800580 ret = &default_cn66xx_conf;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700581 } else if ((oct->chip_id == OCTEON_CN68XX) &&
582 (card_type == LIO_210NV)) {
Raghu Vatsavayi69c69da2016-11-28 16:54:35 -0800583 ret = &default_cn68xx_210nv_conf;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700584 } else if ((oct->chip_id == OCTEON_CN68XX) &&
585 (card_type == LIO_410NV)) {
Raghu Vatsavayi69c69da2016-11-28 16:54:35 -0800586 ret = &default_cn68xx_conf;
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700587 } else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
Raghu Vatsavayi69c69da2016-11-28 16:54:35 -0800588 ret = &default_cn23xx_conf;
589 } else if (oct->chip_id == OCTEON_CN23XX_VF_VID) {
590 ret = &default_cn23xx_conf;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700591 }
592 break;
593 default:
594 break;
595 }
596 return ret;
597}
598
599static int __verify_octeon_config_info(struct octeon_device *oct, void *conf)
600{
601 switch (oct->chip_id) {
602 case OCTEON_CN66XX:
603 case OCTEON_CN68XX:
604 return lio_validate_cn6xxx_config_info(oct, conf);
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700605 case OCTEON_CN23XX_PF_VID:
Raghu Vatsavayi69c69da2016-11-28 16:54:35 -0800606 case OCTEON_CN23XX_VF_VID:
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700607 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 Vatsavayi763185a2016-11-14 15:54:45 -0800652 if (oct->io_qmask.oq & BIT_ULL(i))
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -0700653 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 Vatsavayi763185a2016-11-14 15:54:45 -0800657 if (oct->io_qmask.iq & BIT_ULL(i))
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -0700658 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 Vatsavayi111fc642016-11-28 16:54:34 -0800684 case OCTEON_CN23XX_VF_VID:
685 configsize = sizeof(struct octeon_cn23xx_vf);
686 break;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700687 default:
688 pr_err("%s: Unknown PCI Device: 0x%x\n",
689 __func__,
690 pci_id);
691 return NULL;
692 }
693
694 if (configsize & 0x7)
695 configsize += (8 - (configsize & 0x7));
696
697 octdevsize = sizeof(struct octeon_device);
698 if (octdevsize & 0x7)
699 octdevsize += (8 - (octdevsize & 0x7));
700
701 if (priv_size & 0x7)
702 priv_size += (8 - (priv_size & 0x7));
703
704 size = octdevsize + priv_size + configsize +
705 (sizeof(struct octeon_dispatch) * DISPATCH_LIST_SIZE);
706
707 buf = vmalloc(size);
708 if (!buf)
709 return NULL;
710
711 memset(buf, 0, size);
712
713 oct = (struct octeon_device *)buf;
714 oct->priv = (void *)(buf + octdevsize);
715 oct->chip = (void *)(buf + octdevsize + priv_size);
716 oct->dispatch.dlist = (struct octeon_dispatch *)
717 (buf + octdevsize + priv_size + configsize);
718
719 return oct;
720}
721
722struct octeon_device *octeon_allocate_device(u32 pci_id,
723 u32 priv_size)
724{
725 u32 oct_idx = 0;
726 struct octeon_device *oct = NULL;
727
Rick Farringtone1e3ce62017-05-16 11:14:50 -0700728 spin_lock(&octeon_devices_lock);
729
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700730 for (oct_idx = 0; oct_idx < MAX_OCTEON_DEVICES; oct_idx++)
731 if (!octeon_device[oct_idx])
732 break;
733
Rick Farringtone1e3ce62017-05-16 11:14:50 -0700734 if (oct_idx < MAX_OCTEON_DEVICES) {
735 oct = octeon_allocate_device_mem(pci_id, priv_size);
736 if (oct) {
737 octeon_device_count++;
738 octeon_device[oct_idx] = oct;
739 }
740 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700741
Rick Farringtone1e3ce62017-05-16 11:14:50 -0700742 spin_unlock(&octeon_devices_lock);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700743 if (!oct)
744 return NULL;
745
746 spin_lock_init(&oct->pci_win_lock);
747 spin_lock_init(&oct->mem_access_lock);
748
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700749 oct->octeon_id = oct_idx;
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700750 snprintf(oct->device_name, sizeof(oct->device_name),
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700751 "LiquidIO%d", (oct->octeon_id));
752
753 return oct;
754}
755
Rick Farringtone1e3ce62017-05-16 11:14:50 -0700756/** Register a device's bus location at initialization time.
757 * @param octeon_dev - pointer to the octeon device structure.
758 * @param bus - PCIe bus #
759 * @param dev - PCIe device #
760 * @param func - PCIe function #
761 * @param is_pf - TRUE for PF, FALSE for VF
762 * @return reference count of device's adapter
763 */
764int octeon_register_device(struct octeon_device *oct,
765 int bus, int dev, int func, int is_pf)
766{
767 int idx, refcount;
768
769 oct->loc.bus = bus;
770 oct->loc.dev = dev;
771 oct->loc.func = func;
772
773 oct->adapter_refcount = &adapter_refcounts[oct->octeon_id];
774 atomic_set(oct->adapter_refcount, 0);
775
776 spin_lock(&octeon_devices_lock);
777 for (idx = (int)oct->octeon_id - 1; idx >= 0; idx--) {
778 if (!octeon_device[idx]) {
779 dev_err(&oct->pci_dev->dev,
780 "%s: Internal driver error, missing dev",
781 __func__);
782 spin_unlock(&octeon_devices_lock);
783 atomic_inc(oct->adapter_refcount);
784 return 1; /* here, refcount is guaranteed to be 1 */
785 }
786 /* if another device is at same bus/dev, use its refcounter */
787 if ((octeon_device[idx]->loc.bus == bus) &&
788 (octeon_device[idx]->loc.dev == dev)) {
789 oct->adapter_refcount =
790 octeon_device[idx]->adapter_refcount;
791 break;
792 }
793 }
794 spin_unlock(&octeon_devices_lock);
795
796 atomic_inc(oct->adapter_refcount);
797 refcount = atomic_read(oct->adapter_refcount);
798
799 dev_dbg(&oct->pci_dev->dev, "%s: %02x:%02x:%d refcount %u", __func__,
800 oct->loc.bus, oct->loc.dev, oct->loc.func, refcount);
801
802 return refcount;
803}
804
805/** Deregister a device at de-initialization time.
806 * @param octeon_dev - pointer to the octeon device structure.
807 * @return reference count of device's adapter
808 */
809int octeon_deregister_device(struct octeon_device *oct)
810{
811 int refcount;
812
813 atomic_dec(oct->adapter_refcount);
814 refcount = atomic_read(oct->adapter_refcount);
815
816 dev_dbg(&oct->pci_dev->dev, "%s: %04d:%02d:%d refcount %u", __func__,
817 oct->loc.bus, oct->loc.dev, oct->loc.func, refcount);
818
819 return refcount;
820}
821
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700822int
823octeon_allocate_ioq_vector(struct octeon_device *oct)
824{
825 int i, num_ioqs = 0;
826 struct octeon_ioq_vector *ioq_vector;
827 int cpu_num;
828 int size;
829
830 if (OCTEON_CN23XX_PF(oct))
831 num_ioqs = oct->sriov_info.num_pf_rings;
Raghu Vatsavayicf39faf2016-11-28 16:54:40 -0800832 else if (OCTEON_CN23XX_VF(oct))
833 num_ioqs = oct->sriov_info.rings_per_vf;
834
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700835 size = sizeof(struct octeon_ioq_vector) * num_ioqs;
836
837 oct->ioq_vector = vmalloc(size);
838 if (!oct->ioq_vector)
839 return 1;
840 memset(oct->ioq_vector, 0, size);
841 for (i = 0; i < num_ioqs; i++) {
842 ioq_vector = &oct->ioq_vector[i];
843 ioq_vector->oct_dev = oct;
844 ioq_vector->iq_index = i;
845 ioq_vector->droq_index = i;
Raghu Vatsavayi5d655562016-11-14 15:54:42 -0800846 ioq_vector->mbox = oct->mbox[i];
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700847
848 cpu_num = i % num_online_cpus();
849 cpumask_set_cpu(cpu_num, &ioq_vector->affinity_mask);
850
851 if (oct->chip_id == OCTEON_CN23XX_PF_VID)
852 ioq_vector->ioq_num = i + oct->sriov_info.pf_srn;
853 else
854 ioq_vector->ioq_num = i;
855 }
856 return 0;
857}
858
859void
860octeon_free_ioq_vector(struct octeon_device *oct)
861{
862 vfree(oct->ioq_vector);
863}
864
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700865/* this function is only for setting up the first queue */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700866int octeon_setup_instr_queues(struct octeon_device *oct)
867{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700868 u32 num_descs = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700869 u32 iq_no = 0;
870 union oct_txpciq txpciq;
VSR Burrub3ca9af2017-03-09 17:03:24 -0800871 int numa_node = dev_to_node(&oct->pci_dev->dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700872
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700873 if (OCTEON_CN6XXX(oct))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700874 num_descs =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800875 CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700876 else if (OCTEON_CN23XX_PF(oct))
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800877 num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_pf));
Raghu Vatsavayi9003baf2016-11-28 16:54:38 -0800878 else if (OCTEON_CN23XX_VF(oct))
879 num_descs = CFG_GET_NUM_DEF_TX_DESCS(CHIP_CONF(oct, cn23xx_vf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700880
881 oct->num_iqs = 0;
882
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700883 oct->instr_queue[0] = vmalloc_node(sizeof(*oct->instr_queue[0]),
884 numa_node);
885 if (!oct->instr_queue[0])
886 oct->instr_queue[0] =
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700887 vmalloc(sizeof(struct octeon_instr_queue));
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700888 if (!oct->instr_queue[0])
889 return 1;
890 memset(oct->instr_queue[0], 0, sizeof(struct octeon_instr_queue));
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700891 oct->instr_queue[0]->q_index = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700892 oct->instr_queue[0]->app_ctx = (void *)(size_t)0;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700893 oct->instr_queue[0]->ifidx = 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700894 txpciq.u64 = 0;
895 txpciq.s.q_no = iq_no;
Raghu Vatsavayi5b823512016-09-01 11:16:07 -0700896 txpciq.s.pkind = oct->pfvf_hsword.pkind;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700897 txpciq.s.use_qpg = 0;
898 txpciq.s.qpg = 0;
899 if (octeon_init_instr_queue(oct, txpciq, num_descs)) {
900 /* prevent memory leak */
901 vfree(oct->instr_queue[0]);
Raghu Vatsavayi515e7522016-11-14 15:54:44 -0800902 oct->instr_queue[0] = NULL;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700903 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700904 }
905
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700906 oct->num_iqs++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700907 return 0;
908}
909
910int octeon_setup_output_queues(struct octeon_device *oct)
911{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700912 u32 num_descs = 0;
913 u32 desc_size = 0;
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700914 u32 oq_no = 0;
VSR Burrub3ca9af2017-03-09 17:03:24 -0800915 int numa_node = dev_to_node(&oct->pci_dev->dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700916
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700917 if (OCTEON_CN6XXX(oct)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700918 num_descs =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800919 CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700920 desc_size =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800921 CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700922 } else if (OCTEON_CN23XX_PF(oct)) {
Raghu Vatsavayi97a25322016-11-14 15:54:47 -0800923 num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_pf));
924 desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_pf));
Raghu Vatsavayi9003baf2016-11-28 16:54:38 -0800925 } else if (OCTEON_CN23XX_VF(oct)) {
926 num_descs = CFG_GET_NUM_DEF_RX_DESCS(CHIP_CONF(oct, cn23xx_vf));
927 desc_size = CFG_GET_DEF_RX_BUF_SIZE(CHIP_CONF(oct, cn23xx_vf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700928 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700929 oct->num_oqs = 0;
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700930 oct->droq[0] = vmalloc_node(sizeof(*oct->droq[0]), numa_node);
931 if (!oct->droq[0])
932 oct->droq[0] = vmalloc(sizeof(*oct->droq[0]));
933 if (!oct->droq[0])
934 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700935
Raghu Vatsavayi515e7522016-11-14 15:54:44 -0800936 if (octeon_init_droq(oct, oq_no, num_descs, desc_size, NULL)) {
937 vfree(oct->droq[oq_no]);
938 oct->droq[oq_no] = NULL;
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700939 return 1;
Raghu Vatsavayi515e7522016-11-14 15:54:44 -0800940 }
Raghu Vatsavayi96ae48b2016-06-14 16:54:46 -0700941 oct->num_oqs++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700942
943 return 0;
944}
945
Raghu Vatsavayic865cdf2016-11-28 16:54:36 -0800946int octeon_set_io_queues_off(struct octeon_device *oct)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700947{
Raghu Vatsavayic865cdf2016-11-28 16:54:36 -0800948 int loop = BUSY_READING_REG_VF_LOOP_COUNT;
949
Raghu Vatsavayi5b823512016-09-01 11:16:07 -0700950 if (OCTEON_CN6XXX(oct)) {
951 octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
952 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
Raghu Vatsavayic865cdf2016-11-28 16:54:36 -0800953 } else if (oct->chip_id == OCTEON_CN23XX_VF_VID) {
954 u32 q_no;
955
956 /* IOQs will already be in reset.
957 * If RST bit is set, wait for quiet bit to be set.
958 * Once quiet bit is set, clear the RST bit.
959 */
960 for (q_no = 0; q_no < oct->sriov_info.rings_per_vf; q_no++) {
961 u64 reg_val = octeon_read_csr64(
962 oct, CN23XX_VF_SLI_IQ_PKT_CONTROL64(q_no));
963
964 while ((reg_val & CN23XX_PKT_INPUT_CTL_RST) &&
965 !(reg_val & CN23XX_PKT_INPUT_CTL_QUIET) &&
966 loop) {
967 reg_val = octeon_read_csr64(
968 oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
969 loop--;
970 }
971 if (!loop) {
972 dev_err(&oct->pci_dev->dev,
973 "clearing the reset reg failed or setting the quiet reg failed for qno: %u\n",
974 q_no);
975 return -1;
976 }
977
978 reg_val = reg_val & ~CN23XX_PKT_INPUT_CTL_RST;
979 octeon_write_csr64(oct,
980 CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
981 reg_val);
982
983 reg_val = octeon_read_csr64(
984 oct, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
985 if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
986 dev_err(&oct->pci_dev->dev,
987 "unable to reset qno %u\n", q_no);
988 return -1;
989 }
990 }
Raghu Vatsavayi5b823512016-09-01 11:16:07 -0700991 }
Raghu Vatsavayic865cdf2016-11-28 16:54:36 -0800992 return 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700993}
994
995void octeon_set_droq_pkt_op(struct octeon_device *oct,
996 u32 q_no,
997 u32 enable)
998{
999 u32 reg_val = 0;
1000
1001 /* Disable the i/p and o/p queues for this Octeon. */
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001002 if (OCTEON_CN6XXX(oct)) {
1003 reg_val = octeon_read_csr(oct, CN6XXX_SLI_PKT_OUT_ENB);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001004
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001005 if (enable)
1006 reg_val = reg_val | (1 << q_no);
1007 else
1008 reg_val = reg_val & (~(1 << q_no));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001009
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001010 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, reg_val);
1011 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001012}
1013
1014int octeon_init_dispatch_list(struct octeon_device *oct)
1015{
1016 u32 i;
1017
1018 oct->dispatch.count = 0;
1019
1020 for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
1021 oct->dispatch.dlist[i].opcode = 0;
1022 INIT_LIST_HEAD(&oct->dispatch.dlist[i].list);
1023 }
1024
1025 for (i = 0; i <= REQTYPE_LAST; i++)
1026 octeon_register_reqtype_free_fn(oct, i, NULL);
1027
1028 spin_lock_init(&oct->dispatch.lock);
1029
1030 return 0;
1031}
1032
1033void octeon_delete_dispatch_list(struct octeon_device *oct)
1034{
1035 u32 i;
1036 struct list_head freelist, *temp, *tmp2;
1037
1038 INIT_LIST_HEAD(&freelist);
1039
1040 spin_lock_bh(&oct->dispatch.lock);
1041
1042 for (i = 0; i < DISPATCH_LIST_SIZE; i++) {
1043 struct list_head *dispatch;
1044
1045 dispatch = &oct->dispatch.dlist[i].list;
1046 while (dispatch->next != dispatch) {
1047 temp = dispatch->next;
1048 list_del(temp);
1049 list_add_tail(temp, &freelist);
1050 }
1051
1052 oct->dispatch.dlist[i].opcode = 0;
1053 }
1054
1055 oct->dispatch.count = 0;
1056
1057 spin_unlock_bh(&oct->dispatch.lock);
1058
1059 list_for_each_safe(temp, tmp2, &freelist) {
1060 list_del(temp);
1061 vfree(temp);
1062 }
1063}
1064
1065octeon_dispatch_fn_t
1066octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
1067 u16 subcode)
1068{
1069 u32 idx;
1070 struct list_head *dispatch;
1071 octeon_dispatch_fn_t fn = NULL;
1072 u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
1073
1074 idx = combined_opcode & OCTEON_OPCODE_MASK;
1075
1076 spin_lock_bh(&octeon_dev->dispatch.lock);
1077
1078 if (octeon_dev->dispatch.count == 0) {
1079 spin_unlock_bh(&octeon_dev->dispatch.lock);
1080 return NULL;
1081 }
1082
1083 if (!(octeon_dev->dispatch.dlist[idx].opcode)) {
1084 spin_unlock_bh(&octeon_dev->dispatch.lock);
1085 return NULL;
1086 }
1087
1088 if (octeon_dev->dispatch.dlist[idx].opcode == combined_opcode) {
1089 fn = octeon_dev->dispatch.dlist[idx].dispatch_fn;
1090 } else {
1091 list_for_each(dispatch,
1092 &octeon_dev->dispatch.dlist[idx].list) {
1093 if (((struct octeon_dispatch *)dispatch)->opcode ==
1094 combined_opcode) {
1095 fn = ((struct octeon_dispatch *)
1096 dispatch)->dispatch_fn;
1097 break;
1098 }
1099 }
1100 }
1101
1102 spin_unlock_bh(&octeon_dev->dispatch.lock);
1103 return fn;
1104}
1105
1106/* octeon_register_dispatch_fn
1107 * Parameters:
1108 * octeon_id - id of the octeon device.
1109 * opcode - opcode for which driver should call the registered function
1110 * subcode - subcode for which driver should call the registered function
1111 * fn - The function to call when a packet with "opcode" arrives in
1112 * octeon output queues.
1113 * fn_arg - The argument to be passed when calling function "fn".
1114 * Description:
1115 * Registers a function and its argument to be called when a packet
1116 * arrives in Octeon output queues with "opcode".
1117 * Returns:
1118 * Success: 0
1119 * Failure: 1
1120 * Locks:
1121 * No locks are held.
1122 */
1123int
1124octeon_register_dispatch_fn(struct octeon_device *oct,
1125 u16 opcode,
1126 u16 subcode,
1127 octeon_dispatch_fn_t fn, void *fn_arg)
1128{
1129 u32 idx;
1130 octeon_dispatch_fn_t pfn;
1131 u16 combined_opcode = OPCODE_SUBCODE(opcode, subcode);
1132
1133 idx = combined_opcode & OCTEON_OPCODE_MASK;
1134
1135 spin_lock_bh(&oct->dispatch.lock);
1136 /* Add dispatch function to first level of lookup table */
1137 if (oct->dispatch.dlist[idx].opcode == 0) {
1138 oct->dispatch.dlist[idx].opcode = combined_opcode;
1139 oct->dispatch.dlist[idx].dispatch_fn = fn;
1140 oct->dispatch.dlist[idx].arg = fn_arg;
1141 oct->dispatch.count++;
1142 spin_unlock_bh(&oct->dispatch.lock);
1143 return 0;
1144 }
1145
1146 spin_unlock_bh(&oct->dispatch.lock);
1147
1148 /* Check if there was a function already registered for this
1149 * opcode/subcode.
1150 */
1151 pfn = octeon_get_dispatch(oct, opcode, subcode);
1152 if (!pfn) {
1153 struct octeon_dispatch *dispatch;
1154
1155 dev_dbg(&oct->pci_dev->dev,
1156 "Adding opcode to dispatch list linked list\n");
1157 dispatch = (struct octeon_dispatch *)
1158 vmalloc(sizeof(struct octeon_dispatch));
1159 if (!dispatch) {
1160 dev_err(&oct->pci_dev->dev,
1161 "No memory to add dispatch function\n");
1162 return 1;
1163 }
1164 dispatch->opcode = combined_opcode;
1165 dispatch->dispatch_fn = fn;
1166 dispatch->arg = fn_arg;
1167
1168 /* Add dispatch function to linked list of fn ptrs
1169 * at the hashed index.
1170 */
1171 spin_lock_bh(&oct->dispatch.lock);
1172 list_add(&dispatch->list, &oct->dispatch.dlist[idx].list);
1173 oct->dispatch.count++;
1174 spin_unlock_bh(&oct->dispatch.lock);
1175
1176 } else {
1177 dev_err(&oct->pci_dev->dev,
1178 "Found previously registered dispatch fn for opcode/subcode: %x/%x\n",
1179 opcode, subcode);
1180 return 1;
1181 }
1182
1183 return 0;
1184}
1185
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001186int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf)
1187{
1188 u32 i;
1189 char app_name[16];
1190 struct octeon_device *oct = (struct octeon_device *)buf;
1191 struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
1192 struct octeon_core_setup *cs = NULL;
1193 u32 num_nic_ports = 0;
1194
1195 if (OCTEON_CN6XXX(oct))
1196 num_nic_ports =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08001197 CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001198 else if (OCTEON_CN23XX_PF(oct))
1199 num_nic_ports =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08001200 CFG_GET_NUM_NIC_PORTS(CHIP_CONF(oct, cn23xx_pf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001201
1202 if (atomic_read(&oct->status) >= OCT_DEV_RUNNING) {
1203 dev_err(&oct->pci_dev->dev, "Received CORE OK when device state is 0x%x\n",
1204 atomic_read(&oct->status));
1205 goto core_drv_init_err;
1206 }
1207
1208 strncpy(app_name,
1209 get_oct_app_string(
1210 (u32)recv_pkt->rh.r_core_drv_init.app_mode),
1211 sizeof(app_name) - 1);
1212 oct->app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07001213 if (recv_pkt->rh.r_core_drv_init.app_mode == CVM_DRV_NIC_APP) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001214 oct->fw_info.max_nic_ports =
1215 (u32)recv_pkt->rh.r_core_drv_init.max_nic_ports;
1216 oct->fw_info.num_gmx_ports =
1217 (u32)recv_pkt->rh.r_core_drv_init.num_gmx_ports;
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07001218 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001219
1220 if (oct->fw_info.max_nic_ports < num_nic_ports) {
1221 dev_err(&oct->pci_dev->dev,
1222 "Config has more ports than firmware allows (%d > %d).\n",
1223 num_nic_ports, oct->fw_info.max_nic_ports);
1224 goto core_drv_init_err;
1225 }
1226 oct->fw_info.app_cap_flags = recv_pkt->rh.r_core_drv_init.app_cap_flags;
1227 oct->fw_info.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001228 oct->pfvf_hsword.app_mode = (u32)recv_pkt->rh.r_core_drv_init.app_mode;
1229
1230 oct->pfvf_hsword.pkind = recv_pkt->rh.r_core_drv_init.pkind;
1231
1232 for (i = 0; i < oct->num_iqs; i++)
1233 oct->instr_queue[i]->txpciq.s.pkind = oct->pfvf_hsword.pkind;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001234
1235 atomic_set(&oct->status, OCT_DEV_CORE_OK);
1236
1237 cs = &core_setup[oct->octeon_id];
1238
1239 if (recv_pkt->buffer_size[0] != sizeof(*cs)) {
1240 dev_dbg(&oct->pci_dev->dev, "Core setup bytes expected %u found %d\n",
1241 (u32)sizeof(*cs),
1242 recv_pkt->buffer_size[0]);
1243 }
1244
1245 memcpy(cs, get_rbd(recv_pkt->buffer_ptr[0]), sizeof(*cs));
1246 strncpy(oct->boardinfo.name, cs->boardname, OCT_BOARD_NAME);
1247 strncpy(oct->boardinfo.serial_number, cs->board_serial_number,
1248 OCT_SERIAL_LEN);
1249
1250 octeon_swap_8B_data((u64 *)cs, (sizeof(*cs) >> 3));
1251
1252 oct->boardinfo.major = cs->board_rev_major;
1253 oct->boardinfo.minor = cs->board_rev_minor;
1254
1255 dev_info(&oct->pci_dev->dev,
1256 "Running %s (%llu Hz)\n",
1257 app_name, CVM_CAST64(cs->corefreq));
1258
1259core_drv_init_err:
1260 for (i = 0; i < recv_pkt->buffer_count; i++)
1261 recv_buffer_free(recv_pkt->buffer_ptr[i]);
1262 octeon_free_recv_info(recv_info);
1263 return 0;
1264}
1265
1266int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no)
1267
1268{
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001269 if (oct && (q_no < MAX_OCTEON_INSTR_QUEUES(oct)) &&
Raghu Vatsavayi763185a2016-11-14 15:54:45 -08001270 (oct->io_qmask.iq & BIT_ULL(q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001271 return oct->instr_queue[q_no]->max_count;
1272
1273 return -1;
1274}
1275
1276int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no)
1277{
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001278 if (oct && (q_no < MAX_OCTEON_OUTPUT_QUEUES(oct)) &&
Raghu Vatsavayi763185a2016-11-14 15:54:45 -08001279 (oct->io_qmask.oq & BIT_ULL(q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001280 return oct->droq[q_no]->max_count;
1281 return -1;
1282}
1283
1284/* Retruns the host firmware handshake OCTEON specific configuration */
1285struct octeon_config *octeon_get_conf(struct octeon_device *oct)
1286{
1287 struct octeon_config *default_oct_conf = NULL;
1288
1289 /* check the OCTEON Device model & return the corresponding octeon
1290 * configuration
1291 */
1292
1293 if (OCTEON_CN6XXX(oct)) {
1294 default_oct_conf =
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08001295 (struct octeon_config *)(CHIP_CONF(oct, cn6xxx));
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001296 } else if (OCTEON_CN23XX_PF(oct)) {
1297 default_oct_conf = (struct octeon_config *)
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08001298 (CHIP_CONF(oct, cn23xx_pf));
Raghu Vatsavayi846b4682016-12-07 08:54:31 -08001299 } else if (OCTEON_CN23XX_VF(oct)) {
1300 default_oct_conf = (struct octeon_config *)
1301 (CHIP_CONF(oct, cn23xx_vf));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001302 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001303 return default_oct_conf;
1304}
1305
1306/* scratch register address is same in all the OCT-II and CN70XX models */
1307#define CNXX_SLI_SCRATCH1 0x3C0
1308
1309/** Get the octeon device pointer.
1310 * @param octeon_id - The id for which the octeon device pointer is required.
1311 * @return Success: Octeon device pointer.
1312 * @return Failure: NULL.
1313 */
1314struct octeon_device *lio_get_device(u32 octeon_id)
1315{
1316 if (octeon_id >= MAX_OCTEON_DEVICES)
1317 return NULL;
1318 else
1319 return octeon_device[octeon_id];
1320}
1321
1322u64 lio_pci_readq(struct octeon_device *oct, u64 addr)
1323{
1324 u64 val64;
1325 unsigned long flags;
1326 u32 val32, addrhi;
1327
1328 spin_lock_irqsave(&oct->pci_win_lock, flags);
1329
1330 /* The windowed read happens when the LSB of the addr is written.
1331 * So write MSB first
1332 */
1333 addrhi = (addr >> 32);
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001334 if ((oct->chip_id == OCTEON_CN66XX) ||
1335 (oct->chip_id == OCTEON_CN68XX) ||
1336 (oct->chip_id == OCTEON_CN23XX_PF_VID))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001337 addrhi |= 0x00060000;
1338 writel(addrhi, oct->reg_list.pci_win_rd_addr_hi);
1339
1340 /* Read back to preserve ordering of writes */
1341 val32 = readl(oct->reg_list.pci_win_rd_addr_hi);
1342
1343 writel(addr & 0xffffffff, oct->reg_list.pci_win_rd_addr_lo);
1344 val32 = readl(oct->reg_list.pci_win_rd_addr_lo);
1345
1346 val64 = readq(oct->reg_list.pci_win_rd_data);
1347
1348 spin_unlock_irqrestore(&oct->pci_win_lock, flags);
1349
1350 return val64;
1351}
1352
1353void lio_pci_writeq(struct octeon_device *oct,
1354 u64 val,
1355 u64 addr)
1356{
1357 u32 val32;
1358 unsigned long flags;
1359
1360 spin_lock_irqsave(&oct->pci_win_lock, flags);
1361
1362 writeq(addr, oct->reg_list.pci_win_wr_addr);
1363
1364 /* The write happens when the LSB is written. So write MSB first. */
1365 writel(val >> 32, oct->reg_list.pci_win_wr_data_hi);
1366 /* Read the MSB to ensure ordering of writes. */
1367 val32 = readl(oct->reg_list.pci_win_wr_data_hi);
1368
1369 writel(val & 0xffffffff, oct->reg_list.pci_win_wr_data_lo);
1370
1371 spin_unlock_irqrestore(&oct->pci_win_lock, flags);
1372}
1373
1374int octeon_mem_access_ok(struct octeon_device *oct)
1375{
1376 u64 access_okay = 0;
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001377 u64 lmc0_reset_ctl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001378
1379 /* Check to make sure a DDR interface is enabled */
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07001380 if (OCTEON_CN23XX_PF(oct)) {
1381 lmc0_reset_ctl = lio_pci_readq(oct, CN23XX_LMC0_RESET_CTL);
1382 access_okay =
1383 (lmc0_reset_ctl & CN23XX_LMC0_RESET_CTL_DDR3RST_MASK);
1384 } else {
1385 lmc0_reset_ctl = lio_pci_readq(oct, CN6XXX_LMC0_RESET_CTL);
1386 access_okay =
1387 (lmc0_reset_ctl & CN6XXX_LMC0_RESET_CTL_DDR3RST_MASK);
1388 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001389
1390 return access_okay ? 0 : 1;
1391}
1392
1393int octeon_wait_for_ddr_init(struct octeon_device *oct, u32 *timeout)
1394{
1395 int ret = 1;
1396 u32 ms;
1397
1398 if (!timeout)
1399 return ret;
1400
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001401 for (ms = 0; (ret != 0) && ((*timeout == 0) || (ms <= *timeout));
1402 ms += HZ / 10) {
1403 ret = octeon_mem_access_ok(oct);
1404
1405 /* wait 100 ms */
1406 if (ret)
1407 schedule_timeout_uninterruptible(HZ / 10);
1408 }
1409
1410 return ret;
1411}
1412
1413/** Get the octeon id assigned to the octeon device passed as argument.
1414 * This function is exported to other modules.
1415 * @param dev - octeon device pointer passed as a void *.
1416 * @return octeon device id
1417 */
1418int lio_get_device_id(void *dev)
1419{
1420 struct octeon_device *octeon_dev = (struct octeon_device *)dev;
1421 u32 i;
1422
1423 for (i = 0; i < MAX_OCTEON_DEVICES; i++)
1424 if (octeon_device[i] == octeon_dev)
1425 return octeon_dev->octeon_id;
1426 return -1;
1427}
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001428
1429void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq)
1430{
Raghu Vatsavayi9ded1a52016-09-01 11:16:10 -07001431 u64 instr_cnt;
Prasad Kannegantia55667e2017-05-25 10:54:29 -07001432 u32 pkts_pend;
Raghu Vatsavayi9ded1a52016-09-01 11:16:10 -07001433 struct octeon_device *oct = NULL;
1434
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001435 /* the whole thing needs to be atomic, ideally */
1436 if (droq) {
Prasad Kannegantia55667e2017-05-25 10:54:29 -07001437 pkts_pend = (u32)atomic_read(&droq->pkts_pending);
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001438 spin_lock_bh(&droq->lock);
Prasad Kannegantia55667e2017-05-25 10:54:29 -07001439 writel(droq->pkt_count - pkts_pend, droq->pkts_sent_reg);
1440 droq->pkt_count = pkts_pend;
Satanand Burlacdb478e2017-01-31 13:04:42 -08001441 /* this write needs to be flushed before we release the lock */
1442 mmiowb();
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001443 spin_unlock_bh(&droq->lock);
Raghu Vatsavayi9ded1a52016-09-01 11:16:10 -07001444 oct = droq->oct_dev;
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001445 }
1446 if (iq) {
1447 spin_lock_bh(&iq->lock);
1448 writel(iq->pkt_in_done, iq->inst_cnt_reg);
1449 iq->pkt_in_done = 0;
Satanand Burlacdb478e2017-01-31 13:04:42 -08001450 /* this write needs to be flushed before we release the lock */
1451 mmiowb();
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001452 spin_unlock_bh(&iq->lock);
Raghu Vatsavayi9ded1a52016-09-01 11:16:10 -07001453 oct = iq->oct_dev;
1454 }
1455 /*write resend. Writing RESEND in SLI_PKTX_CNTS should be enough
1456 *to trigger tx interrupts as well, if they are pending.
1457 */
Raghu Vatsavayi9217c3c2016-12-07 08:54:37 -08001458 if (oct && (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct))) {
Raghu Vatsavayi9ded1a52016-09-01 11:16:10 -07001459 if (droq)
1460 writeq(CN23XX_INTR_RESEND, droq->pkts_sent_reg);
1461 /*we race with firmrware here. read and write the IN_DONE_CNTS*/
1462 else if (iq) {
1463 instr_cnt = readq(iq->inst_cnt_reg);
1464 writeq(((instr_cnt & 0xFFFFFFFF00000000ULL) |
1465 CN23XX_INTR_RESEND),
1466 iq->inst_cnt_reg);
1467 }
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -07001468 }
1469}