octeon_device.h 24 KB

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