octeon_device.h 24 KB

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