octeon_device.h 23 KB

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