1 /**********************************************************************
2 * 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 ***********************************************************************/
18 /*! \file octeon_device.h
19 * \brief Host Driver: This file defines the octeon device structure.
20 */
21
22 #ifndef _OCTEON_DEVICE_H_
23 #define _OCTEON_DEVICE_H_
24
25 #include <linux/interrupt.h>
26 #include <net/devlink.h>
27
28 /** PCI VendorId Device Id */
29 #define OCTEON_CN68XX_PCIID 0x91177d
30 #define OCTEON_CN66XX_PCIID 0x92177d
31 #define OCTEON_CN23XX_PCIID_PF 0x9702177d
32 /** Driver identifies chips by these Ids, created by clubbing together
33 * DeviceId+RevisionId; Where Revision Id is not used to distinguish
34 * between chips, a value of 0 is used for revision id.
35 */
36 #define OCTEON_CN68XX 0x0091
37 #define OCTEON_CN66XX 0x0092
38 #define OCTEON_CN23XX_PF_VID 0x9702
39 #define OCTEON_CN23XX_VF_VID 0x9712
40
41 /**RevisionId for the chips */
42 #define OCTEON_CN23XX_REV_1_0 0x00
43 #define OCTEON_CN23XX_REV_1_1 0x01
44 #define OCTEON_CN23XX_REV_2_0 0x80
45
46 /**SubsystemId for the chips */
47 #define OCTEON_CN2350_10GB_SUBSYS_ID_1 0X3177d
48 #define OCTEON_CN2350_10GB_SUBSYS_ID_2 0X4177d
49 #define OCTEON_CN2360_10GB_SUBSYS_ID 0X5177d
50 #define OCTEON_CN2350_25GB_SUBSYS_ID 0X7177d
51 #define OCTEON_CN2360_25GB_SUBSYS_ID 0X6177d
52
53 /** Endian-swap modes supported by Octeon. */
54 enum octeon_pci_swap_mode {
55 OCTEON_PCI_PASSTHROUGH = 0,
56 OCTEON_PCI_64BIT_SWAP = 1,
57 OCTEON_PCI_32BIT_BYTE_SWAP = 2,
58 OCTEON_PCI_32BIT_LW_SWAP = 3
59 };
60
61 enum lio_fw_state {
62 FW_IS_PRELOADED = 0,
63 FW_NEEDS_TO_BE_LOADED = 1,
64 FW_IS_BEING_LOADED = 2,
65 FW_HAS_BEEN_LOADED = 3,
66 };
67
68 enum {
69 OCTEON_CONFIG_TYPE_DEFAULT = 0,
70 NUM_OCTEON_CONFS,
71 };
72
73 #define OCTEON_INPUT_INTR (1)
74 #define OCTEON_OUTPUT_INTR (2)
75 #define OCTEON_MBOX_INTR (4)
76 #define OCTEON_ALL_INTR 0xff
77
78 /*--------------- PCI BAR1 index registers -------------*/
79
80 /* BAR1 Mask */
81 #define PCI_BAR1_ENABLE_CA 1
82 #define PCI_BAR1_ENDIAN_MODE OCTEON_PCI_64BIT_SWAP
83 #define PCI_BAR1_ENTRY_VALID 1
84 #define PCI_BAR1_MASK ((PCI_BAR1_ENABLE_CA << 3) \
85 | (PCI_BAR1_ENDIAN_MODE << 1) \
86 | PCI_BAR1_ENTRY_VALID)
87
88 /** Octeon Device state.
89 * Each octeon device goes through each of these states
90 * as it is initialized.
91 */
92 #define OCT_DEV_BEGIN_STATE 0x0
93 #define OCT_DEV_PCI_ENABLE_DONE 0x1
94 #define OCT_DEV_PCI_MAP_DONE 0x2
95 #define OCT_DEV_DISPATCH_INIT_DONE 0x3
96 #define OCT_DEV_INSTR_QUEUE_INIT_DONE 0x4
97 #define OCT_DEV_SC_BUFF_POOL_INIT_DONE 0x5
98 #define OCT_DEV_RESP_LIST_INIT_DONE 0x6
99 #define OCT_DEV_DROQ_INIT_DONE 0x7
100 #define OCT_DEV_MBOX_SETUP_DONE 0x8
101 #define OCT_DEV_MSIX_ALLOC_VECTOR_DONE 0x9
102 #define OCT_DEV_INTR_SET_DONE 0xa
103 #define OCT_DEV_IO_QUEUES_DONE 0xb
104 #define OCT_DEV_CONSOLE_INIT_DONE 0xc
105 #define OCT_DEV_HOST_OK 0xd
106 #define OCT_DEV_CORE_OK 0xe
107 #define OCT_DEV_RUNNING 0xf
108 #define OCT_DEV_IN_RESET 0x10
109 #define OCT_DEV_STATE_INVALID 0x11
110
111 #define OCT_DEV_STATES OCT_DEV_STATE_INVALID
112
113 /** Octeon Device interrupts
114 * These interrupt bits are set in int_status filed of
115 * octeon_device structure
116 */
117 #define OCT_DEV_INTR_DMA0_FORCE 0x01
118 #define OCT_DEV_INTR_DMA1_FORCE 0x02
119 #define OCT_DEV_INTR_PKT_DATA 0x04
120
121 #define LIO_RESET_SECS (3)
122
123 /*---------------------------DISPATCH LIST-------------------------------*/
124
125 /** The dispatch list entry.
126 * The driver keeps a record of functions registered for each
127 * response header opcode in this structure. Since the opcode is
128 * hashed to index into the driver's list, more than one opcode
129 * can hash to the same entry, in which case the list field points
130 * to a linked list with the other entries.
131 */
132 struct octeon_dispatch {
133 /** List head for this entry */
134 struct list_head list;
135
136 /** The opcode for which the dispatch function & arg should be used */
137 u16 opcode;
138
139 /** The function to be called for a packet received by the driver */
140 octeon_dispatch_fn_t dispatch_fn;
141
142 /* The application specified argument to be passed to the above
143 * function along with the received packet
144 */
145 void *arg;
146 };
147
148 /** The dispatch list structure. */
149 struct octeon_dispatch_list {
150 /** access to dispatch list must be atomic */
151 spinlock_t lock;
152
153 /** Count of dispatch functions currently registered */
154 u32 count;
155
156 /** The list of dispatch functions */
157 struct octeon_dispatch *dlist;
158 };
159
160 /*----------------------- THE OCTEON DEVICE ---------------------------*/
161
162 #define OCT_MEM_REGIONS 3
163 /** PCI address space mapping information.
164 * Each of the 3 address spaces given by BAR0, BAR2 and BAR4 of
165 * Octeon gets mapped to different physical address spaces in
166 * the kernel.
167 */
168 struct octeon_mmio {
169 /** PCI address to which the BAR is mapped. */
170 u64 start;
171
172 /** Length of this PCI address space. */
173 u32 len;
174
175 /** Length that has been mapped to phys. address space. */
176 u32 mapped_len;
177
178 /** The physical address to which the PCI address space is mapped. */
179 u8 __iomem *hw_addr;
180
181 /** Flag indicating the mapping was successful. */
182 u32 done;
183 };
184
185 #define MAX_OCTEON_MAPS 32
186
187 struct octeon_io_enable {
188 u64 iq;
189 u64 oq;
190 u64 iq64B;
191 };
192
193 struct octeon_reg_list {
194 u32 __iomem *pci_win_wr_addr_hi;
195 u32 __iomem *pci_win_wr_addr_lo;
196 u64 __iomem *pci_win_wr_addr;
197
198 u32 __iomem *pci_win_rd_addr_hi;
199 u32 __iomem *pci_win_rd_addr_lo;
200 u64 __iomem *pci_win_rd_addr;
201
202 u32 __iomem *pci_win_wr_data_hi;
203 u32 __iomem *pci_win_wr_data_lo;
204 u64 __iomem *pci_win_wr_data;
205
206 u32 __iomem *pci_win_rd_data_hi;
207 u32 __iomem *pci_win_rd_data_lo;
208 u64 __iomem *pci_win_rd_data;
209 };
210
211 #define OCTEON_CONSOLE_MAX_READ_BYTES 512
212 typedef int (*octeon_console_print_fn)(struct octeon_device *oct,
213 u32 num, char *pre, char *suf);
214 struct octeon_console {
215 u32 active;
216 u32 waiting;
217 u64 addr;
218 u32 buffer_size;
219 u64 input_base_addr;
220 u64 output_base_addr;
221 octeon_console_print_fn print;
222 char leftover[OCTEON_CONSOLE_MAX_READ_BYTES];
223 };
224
225 struct octeon_board_info {
226 char name[OCT_BOARD_NAME];
227 char serial_number[OCT_SERIAL_LEN];
228 u64 major;
229 u64 minor;
230 };
231
232 struct octeon_fn_list {
233 void (*setup_iq_regs)(struct octeon_device *, u32);
234 void (*setup_oq_regs)(struct octeon_device *, u32);
235
236 irqreturn_t (*process_interrupt_regs)(void *);
237 u64 (*msix_interrupt_handler)(void *);
238
239 int (*setup_mbox)(struct octeon_device *);
240 int (*free_mbox)(struct octeon_device *);
241
242 int (*soft_reset)(struct octeon_device *);
243 int (*setup_device_regs)(struct octeon_device *);
244 void (*bar1_idx_setup)(struct octeon_device *, u64, u32, int);
245 void (*bar1_idx_write)(struct octeon_device *, u32, u32);
246 u32 (*bar1_idx_read)(struct octeon_device *, u32);
247 u32 (*update_iq_read_idx)(struct octeon_instr_queue *);
248
249 void (*enable_oq_pkt_time_intr)(struct octeon_device *, u32);
250 void (*disable_oq_pkt_time_intr)(struct octeon_device *, u32);
251
252 void (*enable_interrupt)(struct octeon_device *, u8);
253 void (*disable_interrupt)(struct octeon_device *, u8);
254
255 int (*enable_io_queues)(struct octeon_device *);
256 void (*disable_io_queues)(struct octeon_device *);
257 };
258
259 /* Must be multiple of 8, changing breaks ABI */
260 #define CVMX_BOOTMEM_NAME_LEN 128
261
262 /* Structure for named memory blocks
263 * Number of descriptors
264 * available can be changed without affecting compatibility,
265 * but name length changes require a bump in the bootmem
266 * descriptor version
267 * Note: This structure must be naturally 64 bit aligned, as a single
268 * memory image will be used by both 32 and 64 bit programs.
269 */
270 struct cvmx_bootmem_named_block_desc {
271 /** Base address of named block */
272 u64 base_addr;
273
274 /** Size actually allocated for named block */
275 u64 size;
276
277 /** name of named block */
278 char name[CVMX_BOOTMEM_NAME_LEN];
279 };
280
281 struct oct_fw_info {
282 u32 max_nic_ports; /** max nic ports for the device */
283 u32 num_gmx_ports; /** num gmx ports */
284 u64 app_cap_flags; /** firmware cap flags */
285
286 /** The core application is running in this mode.
287 * See octeon-drv-opcodes.h for values.
288 */
289 u32 app_mode;
290 char liquidio_firmware_version[32];
291 /* Fields extracted from legacy string 'liquidio_firmware_version' */
292 struct {
293 u8 maj;
294 u8 min;
295 u8 rev;
296 } ver;
297 };
298
299 #define OCT_FW_VER(maj, min, rev) \
300 (((u32)(maj) << 16) | ((u32)(min) << 8) | ((u32)(rev)))
301
302 /* wrappers around work structs */
303 struct cavium_wk {
304 struct delayed_work work;
305 void *ctxptr;
306 u64 ctxul;
307 };
308
309 struct cavium_wq {
310 struct workqueue_struct *wq;
311 struct cavium_wk wk;
312 };
313
314 struct octdev_props {
315 /* Each interface in the Octeon device has a network
316 * device pointer (used for OS specific calls).
317 */
318 int rx_on;
319 int napi_enabled;
320 int gmxport;
321 struct net_device *netdev;
322 };
323
324 #define LIO_FLAG_MSIX_ENABLED 0x1
325 #define MSIX_PO_INT 0x1
326 #define MSIX_PI_INT 0x2
327 #define MSIX_MBOX_INT 0x4
328
329 struct octeon_pf_vf_hs_word {
330 #ifdef __LITTLE_ENDIAN_BITFIELD
331 /** PKIND value assigned for the DPI interface */
332 u64 pkind : 8;
333
334 /** OCTEON core clock multiplier */
335 u64 core_tics_per_us : 16;
336
337 /** OCTEON coprocessor clock multiplier */
338 u64 coproc_tics_per_us : 16;
339
340 /** app that currently running on OCTEON */
341 u64 app_mode : 8;
342
343 /** RESERVED */
344 u64 reserved : 16;
345
346 #else
347
348 /** RESERVED */
349 u64 reserved : 16;
350
351 /** app that currently running on OCTEON */
352 u64 app_mode : 8;
353
354 /** OCTEON coprocessor clock multiplier */
355 u64 coproc_tics_per_us : 16;
356
357 /** OCTEON core clock multiplier */
358 u64 core_tics_per_us : 16;
359
360 /** PKIND value assigned for the DPI interface */
361 u64 pkind : 8;
362 #endif
363 };
364
365 struct octeon_sriov_info {
366 /* Number of rings assigned to VF */
367 u32 rings_per_vf;
368
369 /** Max Number of VF devices that can be enabled. This variable can
370 * specified during load time or it will be derived after allocating
371 * PF queues. When max_vfs is derived then each VF will get one queue
372 **/
373 u32 max_vfs;
374
375 /** Number of VF devices enabled using sysfs. */
376 u32 num_vfs_alloced;
377
378 /* Actual rings left for PF device */
379 u32 num_pf_rings;
380
381 /* SRN of PF usable IO queues */
382 u32 pf_srn;
383
384 /* total pf rings */
385 u32 trs;
386
387 u32 sriov_enabled;
388
389 struct lio_trusted_vf trusted_vf;
390
391 /*lookup table that maps DPI ring number to VF pci_dev struct pointer*/
392 struct pci_dev *dpiring_to_vfpcidev_lut[MAX_POSSIBLE_VFS];
393
394 u64 vf_macaddr[MAX_POSSIBLE_VFS];
395
396 u16 vf_vlantci[MAX_POSSIBLE_VFS];
397
398 int vf_linkstate[MAX_POSSIBLE_VFS];
399
400 u64 vf_drv_loaded_mask;
401 };
402
403 struct octeon_ioq_vector {
404 struct octeon_device *oct_dev;
405 int iq_index;
406 int droq_index;
407 int vector;
408 struct octeon_mbox *mbox;
409 struct cpumask affinity_mask;
410 u32 ioq_num;
411 };
412
413 struct lio_vf_rep_list {
414 int num_vfs;
415 struct net_device *ndev[CN23XX_MAX_VFS_PER_PF];
416 };
417
418 struct lio_devlink_priv {
419 struct octeon_device *oct;
420 };
421
422 /** The Octeon device.
423 * Each Octeon device has this structure to represent all its
424 * components.
425 */
426 struct octeon_device {
427 /** Lock for PCI window configuration accesses */
428 spinlock_t pci_win_lock;
429
430 /** Lock for memory accesses */
431 spinlock_t mem_access_lock;
432
433 /** PCI device pointer */
434 struct pci_dev *pci_dev;
435
436 /** Chip specific information. */
437 void *chip;
438
439 /** Number of interfaces detected in this octeon device. */
440 u32 ifcount;
441
442 struct octdev_props props[MAX_OCTEON_LINKS];
443
444 /** Octeon Chip type. */
445 u16 chip_id;
446
447 u16 rev_id;
448
449 u32 subsystem_id;
450
451 u16 pf_num;
452
453 u16 vf_num;
454
455 /** This device's id - set by the driver. */
456 u32 octeon_id;
457
458 /** This device's PCIe port used for traffic. */
459 u16 pcie_port;
460
461 u16 flags;
462 #define LIO_FLAG_MSI_ENABLED (u32)(1 << 1)
463
464 /** The state of this device */
465 atomic_t status;
466
467 /** memory mapped io range */
468 struct octeon_mmio mmio[OCT_MEM_REGIONS];
469
470 struct octeon_reg_list reg_list;
471
472 struct octeon_fn_list fn_list;
473
474 struct octeon_board_info boardinfo;
475
476 u32 num_iqs;
477
478 /* The pool containing pre allocated buffers used for soft commands */
479 struct octeon_sc_buffer_pool sc_buf_pool;
480
481 /** The input instruction queues */
482 struct octeon_instr_queue *instr_queue
483 [MAX_POSSIBLE_OCTEON_INSTR_QUEUES];
484
485 /** The doubly-linked list of instruction response */
486 struct octeon_response_list response_list[MAX_RESPONSE_LISTS];
487
488 u32 num_oqs;
489
490 /** The DROQ output queues */
491 struct octeon_droq *droq[MAX_POSSIBLE_OCTEON_OUTPUT_QUEUES];
492
493 struct octeon_io_enable io_qmask;
494
495 /** List of dispatch functions */
496 struct octeon_dispatch_list dispatch;
497
498 u32 int_status;
499
500 u64 droq_intr;
501
502 /** Physical location of the cvmx_bootmem_desc_t in octeon memory */
503 u64 bootmem_desc_addr;
504
505 /** Placeholder memory for named blocks.
506 * Assumes single-threaded access
507 */
508 struct cvmx_bootmem_named_block_desc bootmem_named_block_desc;
509
510 /** Address of consoles descriptor */
511 u64 console_desc_addr;
512
513 /** Number of consoles available. 0 means they are inaccessible */
514 u32 num_consoles;
515
516 /* Console caches */
517 struct octeon_console console[MAX_OCTEON_MAPS];
518
519 /* Console named block info */
520 struct {
521 u64 dram_region_base;
522 int bar1_index;
523 } console_nb_info;
524
525 /* Coprocessor clock rate. */
526 u64 coproc_clock_rate;
527
528 /** The core application is running in this mode. See liquidio_common.h
529 * for values.
530 */
531 u32 app_mode;
532
533 struct oct_fw_info fw_info;
534
535 /** The name given to this device. */
536 char device_name[32];
537
538 /** Application Context */
539 void *app_ctx;
540
541 struct cavium_wq dma_comp_wq;
542
543 /** Lock for dma response list */
544 spinlock_t cmd_resp_wqlock;
545 u32 cmd_resp_state;
546
547 struct cavium_wq check_db_wq[MAX_POSSIBLE_OCTEON_INSTR_QUEUES];
548
549 struct cavium_wk nic_poll_work;
550
551 struct cavium_wk console_poll_work[MAX_OCTEON_MAPS];
552
553 void *priv;
554
555 int num_msix_irqs;
556
557 void *msix_entries;
558
559 /* when requesting IRQs, the names are stored here */
560 void *irq_name_storage;
561
562 struct octeon_sriov_info sriov_info;
563
564 struct octeon_pf_vf_hs_word pfvf_hsword;
565
566 int msix_on;
567
568 /** Mail Box details of each octeon queue. */
569 struct octeon_mbox *mbox[MAX_POSSIBLE_VFS];
570
571 /** IOq information of it's corresponding MSI-X interrupt. */
572 struct octeon_ioq_vector *ioq_vector;
573
574 int rx_pause;
575 int tx_pause;
576
577 struct oct_link_stats link_stats; /*stastics from firmware*/
578
579 /* private flags to control driver-specific features through ethtool */
580 u32 priv_flags;
581
582 void *watchdog_task;
583
584 u32 rx_coalesce_usecs;
585 u32 rx_max_coalesced_frames;
586 u32 tx_max_coalesced_frames;
587
588 bool cores_crashed;
589
590 struct {
591 int bus;
592 int dev;
593 int func;
594 } loc;
595
596 atomic_t *adapter_refcount; /* reference count of adapter */
597
598 atomic_t *adapter_fw_state; /* per-adapter, lio_fw_state */
599
600 bool ptp_enable;
601
602 struct lio_vf_rep_list vf_rep_list;
603 struct devlink *devlink;
604 enum devlink_eswitch_mode eswitch_mode;
605
606 /* for 25G NIC speed change */
607 u8 speed_boot;
608 u8 speed_setting;
609 u8 no_speed_setting;
610 };
611
612 #define OCT_DRV_ONLINE 1
613 #define OCT_DRV_OFFLINE 2
614 #define OCTEON_CN6XXX(oct) ({ \
615 typeof(oct) _oct = (oct); \
616 ((_oct->chip_id == OCTEON_CN66XX) || \
617 (_oct->chip_id == OCTEON_CN68XX)); })
618 #define OCTEON_CN23XX_PF(oct) ((oct)->chip_id == OCTEON_CN23XX_PF_VID)
619 #define OCTEON_CN23XX_VF(oct) ((oct)->chip_id == OCTEON_CN23XX_VF_VID)
620 #define CHIP_CONF(oct, TYPE) \
621 (((struct octeon_ ## TYPE *)((oct)->chip))->conf)
622
623 #define MAX_IO_PENDING_PKT_COUNT 100
624
625 /*------------------ Function Prototypes ----------------------*/
626
627 /** Initialize device list memory */
628 void octeon_init_device_list(int conf_type);
629
630 /** Free memory for Input and Output queue structures for a octeon device */
631 void octeon_free_device_mem(struct octeon_device *oct);
632
633 /* Look up a free entry in the octeon_device table and allocate resources
634 * for the octeon_device structure for an octeon device. Called at init
635 * time.
636 */
637 struct octeon_device *octeon_allocate_device(u32 pci_id,
638 u32 priv_size);
639
640 /** Register a device's bus location at initialization time.
641 * @param octeon_dev - pointer to the octeon device structure.
642 * @param bus - PCIe bus #
643 * @param dev - PCIe device #
644 * @param func - PCIe function #
645 * @param is_pf - TRUE for PF, FALSE for VF
646 * @return reference count of device's adapter
647 */
648 int octeon_register_device(struct octeon_device *oct,
649 int bus, int dev, int func, int is_pf);
650
651 /** Deregister a device at de-initialization time.
652 * @param octeon_dev - pointer to the octeon device structure.
653 * @return reference count of device's adapter
654 */
655 int octeon_deregister_device(struct octeon_device *oct);
656
657 /** Initialize the driver's dispatch list which is a mix of a hash table
658 * and a linked list. This is done at driver load time.
659 * @param octeon_dev - pointer to the octeon device structure.
660 * @return 0 on success, else -ve error value
661 */
662 int octeon_init_dispatch_list(struct octeon_device *octeon_dev);
663
664 /** Delete the driver's dispatch list and all registered entries.
665 * This is done at driver unload time.
666 * @param octeon_dev - pointer to the octeon device structure.
667 */
668 void octeon_delete_dispatch_list(struct octeon_device *octeon_dev);
669
670 /** Initialize the core device fields with the info returned by the FW.
671 * @param recv_info - Receive info structure
672 * @param buf - Receive buffer
673 */
674 int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf);
675
676 /** Gets the dispatch function registered to receive packets with a
677 * given opcode/subcode.
678 * @param octeon_dev - the octeon device pointer.
679 * @param opcode - the opcode for which the dispatch function
680 * is to checked.
681 * @param subcode - the subcode for which the dispatch function
682 * is to checked.
683 *
684 * @return Success: octeon_dispatch_fn_t (dispatch function pointer)
685 * @return Failure: NULL
686 *
687 * Looks up the dispatch list to get the dispatch function for a
688 * given opcode.
689 */
690 octeon_dispatch_fn_t
691 octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
692 u16 subcode);
693
694 /** Get the octeon device pointer.
695 * @param octeon_id - The id for which the octeon device pointer is required.
696 * @return Success: Octeon device pointer.
697 * @return Failure: NULL.
698 */
699 struct octeon_device *lio_get_device(u32 octeon_id);
700
701 /** Get the octeon id assigned to the octeon device passed as argument.
702 * This function is exported to other modules.
703 * @param dev - octeon device pointer passed as a void *.
704 * @return octeon device id
705 */
706 int lio_get_device_id(void *dev);
707
OCTEON_MAJOR_REV(struct octeon_device * oct)708 static inline u16 OCTEON_MAJOR_REV(struct octeon_device *oct)
709 {
710 u16 rev = (oct->rev_id & 0xC) >> 2;
711
712 return (rev == 0) ? 1 : rev;
713 }
714
OCTEON_MINOR_REV(struct octeon_device * oct)715 static inline u16 OCTEON_MINOR_REV(struct octeon_device *oct)
716 {
717 return oct->rev_id & 0x3;
718 }
719
720 /** Read windowed register.
721 * @param oct - pointer to the Octeon device.
722 * @param addr - Address of the register to read.
723 *
724 * This routine is called to read from the indirectly accessed
725 * Octeon registers that are visible through a PCI BAR0 mapped window
726 * register.
727 * @return - 64 bit value read from the register.
728 */
729
730 u64 lio_pci_readq(struct octeon_device *oct, u64 addr);
731
732 /** Write windowed register.
733 * @param oct - pointer to the Octeon device.
734 * @param val - Value to write
735 * @param addr - Address of the register to write
736 *
737 * This routine is called to write to the indirectly accessed
738 * Octeon registers that are visible through a PCI BAR0 mapped window
739 * register.
740 * @return Nothing.
741 */
742 void lio_pci_writeq(struct octeon_device *oct, u64 val, u64 addr);
743
744 /* Routines for reading and writing CSRs */
745 #define octeon_write_csr(oct_dev, reg_off, value) \
746 writel(value, (oct_dev)->mmio[0].hw_addr + (reg_off))
747
748 #define octeon_write_csr64(oct_dev, reg_off, val64) \
749 writeq(val64, (oct_dev)->mmio[0].hw_addr + (reg_off))
750
751 #define octeon_read_csr(oct_dev, reg_off) \
752 readl((oct_dev)->mmio[0].hw_addr + (reg_off))
753
754 #define octeon_read_csr64(oct_dev, reg_off) \
755 readq((oct_dev)->mmio[0].hw_addr + (reg_off))
756
757 /**
758 * Checks if memory access is okay
759 *
760 * @param oct which octeon to send to
761 * @return Zero on success, negative on failure.
762 */
763 int octeon_mem_access_ok(struct octeon_device *oct);
764
765 /**
766 * Waits for DDR initialization.
767 *
768 * @param oct which octeon to send to
769 * @param timeout_in_ms pointer to how long to wait until DDR is initialized
770 * in ms.
771 * If contents are 0, it waits until contents are non-zero
772 * before starting to check.
773 * @return Zero on success, negative on failure.
774 */
775 int octeon_wait_for_ddr_init(struct octeon_device *oct,
776 u32 *timeout_in_ms);
777
778 /**
779 * Wait for u-boot to boot and be waiting for a command.
780 *
781 * @param wait_time_hundredths
782 * Maximum time to wait
783 *
784 * @return Zero on success, negative on failure.
785 */
786 int octeon_wait_for_bootloader(struct octeon_device *oct,
787 u32 wait_time_hundredths);
788
789 /**
790 * Initialize console access
791 *
792 * @param oct which octeon initialize
793 * @return Zero on success, negative on failure.
794 */
795 int octeon_init_consoles(struct octeon_device *oct);
796
797 /**
798 * Adds access to a console to the device.
799 *
800 * @param oct: which octeon to add to
801 * @param console_num: which console
802 * @param dbg_enb: ptr to debug enablement string, one of:
803 * * NULL for no debug output (i.e. disabled)
804 * * empty string enables debug output (via default method)
805 * * specific string to enable debug console output
806 *
807 * @return Zero on success, negative on failure.
808 */
809 int octeon_add_console(struct octeon_device *oct, u32 console_num,
810 char *dbg_enb);
811
812 /** write or read from a console */
813 int octeon_console_write(struct octeon_device *oct, u32 console_num,
814 char *buffer, u32 write_request_size, u32 flags);
815 int octeon_console_write_avail(struct octeon_device *oct, u32 console_num);
816
817 int octeon_console_read_avail(struct octeon_device *oct, u32 console_num);
818
819 /** Removes all attached consoles. */
820 void octeon_remove_consoles(struct octeon_device *oct);
821
822 /**
823 * Send a string to u-boot on console 0 as a command.
824 *
825 * @param oct which octeon to send to
826 * @param cmd_str String to send
827 * @param wait_hundredths Time to wait for u-boot to accept the command.
828 *
829 * @return Zero on success, negative on failure.
830 */
831 int octeon_console_send_cmd(struct octeon_device *oct, char *cmd_str,
832 u32 wait_hundredths);
833
834 /** Parses, validates, and downloads firmware, then boots associated cores.
835 * @param oct which octeon to download firmware to
836 * @param data - The complete firmware file image
837 * @param size - The size of the data
838 *
839 * @return 0 if success.
840 * -EINVAL if file is incompatible or badly formatted.
841 * -ENODEV if no handler was found for the application type or an
842 * invalid octeon id was passed.
843 */
844 int octeon_download_firmware(struct octeon_device *oct, const u8 *data,
845 size_t size);
846
847 char *lio_get_state_string(atomic_t *state_ptr);
848
849 /** Sets up instruction queues for the device
850 * @param oct which octeon to setup
851 *
852 * @return 0 if success. 1 if fails
853 */
854 int octeon_setup_instr_queues(struct octeon_device *oct);
855
856 /** Sets up output queues for the device
857 * @param oct which octeon to setup
858 *
859 * @return 0 if success. 1 if fails
860 */
861 int octeon_setup_output_queues(struct octeon_device *oct);
862
863 int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no);
864
865 int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no);
866
867 /** Turns off the input and output queues for the device
868 * @param oct which octeon to disable
869 */
870 int octeon_set_io_queues_off(struct octeon_device *oct);
871
872 /** Turns on or off the given output queue for the device
873 * @param oct which octeon to change
874 * @param q_no which queue
875 * @param enable 1 to enable, 0 to disable
876 */
877 void octeon_set_droq_pkt_op(struct octeon_device *oct, u32 q_no, u32 enable);
878
879 /** Retrieve the config for the device
880 * @param oct which octeon
881 * @param card_type type of card
882 *
883 * @returns pointer to configuration
884 */
885 void *oct_get_config_info(struct octeon_device *oct, u16 card_type);
886
887 /** Gets the octeon device configuration
888 * @return - pointer to the octeon configuration struture
889 */
890 struct octeon_config *octeon_get_conf(struct octeon_device *oct);
891
892 void octeon_free_ioq_vector(struct octeon_device *oct);
893 int octeon_allocate_ioq_vector(struct octeon_device *oct, u32 num_ioqs);
894 void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq);
895
896 /* LiquidIO driver pivate flags */
897 enum {
898 OCT_PRIV_FLAG_TX_BYTES = 0, /* Tx interrupts by pending byte count */
899 };
900
901 #define OCT_PRIV_FLAG_DEFAULT 0x0
902
lio_get_priv_flag(struct octeon_device * octdev,u32 flag)903 static inline u32 lio_get_priv_flag(struct octeon_device *octdev, u32 flag)
904 {
905 return !!(octdev->priv_flags & (0x1 << flag));
906 }
907
lio_set_priv_flag(struct octeon_device * octdev,u32 flag,u32 val)908 static inline void lio_set_priv_flag(struct octeon_device *octdev,
909 u32 flag, u32 val)
910 {
911 if (val)
912 octdev->priv_flags |= (0x1 << flag);
913 else
914 octdev->priv_flags &= ~(0x1 << flag);
915 }
916 #endif
917