octeon_device.h 25 KB

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