card_base.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef __CARD_BASE_H__
  3. #define __CARD_BASE_H__
  4. /**
  5. * IBM Accelerator Family 'GenWQE'
  6. *
  7. * (C) Copyright IBM Corp. 2013
  8. *
  9. * Author: Frank Haverkamp <[email protected]>
  10. * Author: Joerg-Stephan Vogt <[email protected]>
  11. * Author: Michael Jung <[email protected]>
  12. * Author: Michael Ruettger <[email protected]>
  13. */
  14. /*
  15. * Interfaces within the GenWQE module. Defines genwqe_card and
  16. * ddcb_queue as well as ddcb_requ.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/types.h>
  20. #include <linux/cdev.h>
  21. #include <linux/stringify.h>
  22. #include <linux/pci.h>
  23. #include <linux/semaphore.h>
  24. #include <linux/uaccess.h>
  25. #include <linux/io.h>
  26. #include <linux/debugfs.h>
  27. #include <linux/slab.h>
  28. #include <linux/genwqe/genwqe_card.h>
  29. #include "genwqe_driver.h"
  30. #define GENWQE_MSI_IRQS 4 /* Just one supported, no MSIx */
  31. #define GENWQE_MAX_VFS 15 /* maximum 15 VFs are possible */
  32. #define GENWQE_MAX_FUNCS 16 /* 1 PF and 15 VFs */
  33. #define GENWQE_CARD_NO_MAX (16 * GENWQE_MAX_FUNCS)
  34. /* Compile parameters, some of them appear in debugfs for later adjustment */
  35. #define GENWQE_DDCB_MAX 32 /* DDCBs on the work-queue */
  36. #define GENWQE_POLLING_ENABLED 0 /* in case of irqs not working */
  37. #define GENWQE_DDCB_SOFTWARE_TIMEOUT 10 /* timeout per DDCB in seconds */
  38. #define GENWQE_KILL_TIMEOUT 8 /* time until process gets killed */
  39. #define GENWQE_VF_JOBTIMEOUT_MSEC 250 /* 250 msec */
  40. #define GENWQE_PF_JOBTIMEOUT_MSEC 8000 /* 8 sec should be ok */
  41. #define GENWQE_HEALTH_CHECK_INTERVAL 4 /* <= 0: disabled */
  42. /* Sysfs attribute groups used when we create the genwqe device */
  43. extern const struct attribute_group *genwqe_attribute_groups[];
  44. /*
  45. * Config space for Genwqe5 A7:
  46. * 00:[14 10 4b 04]40 00 10 00[00 00 00 12]00 00 00 00
  47. * 10: 0c 00 00 f0 07 3c 00 00 00 00 00 00 00 00 00 00
  48. * 20: 00 00 00 00 00 00 00 00 00 00 00 00[14 10 4b 04]
  49. * 30: 00 00 00 00 50 00 00 00 00 00 00 00 00 00 00 00
  50. */
  51. #define PCI_DEVICE_GENWQE 0x044b /* Genwqe DeviceID */
  52. #define PCI_SUBSYSTEM_ID_GENWQE5 0x035f /* Genwqe A5 Subsystem-ID */
  53. #define PCI_SUBSYSTEM_ID_GENWQE5_NEW 0x044b /* Genwqe A5 Subsystem-ID */
  54. #define PCI_CLASSCODE_GENWQE5 0x1200 /* UNKNOWN */
  55. #define PCI_SUBVENDOR_ID_IBM_SRIOV 0x0000
  56. #define PCI_SUBSYSTEM_ID_GENWQE5_SRIOV 0x0000 /* Genwqe A5 Subsystem-ID */
  57. #define PCI_CLASSCODE_GENWQE5_SRIOV 0x1200 /* UNKNOWN */
  58. #define GENWQE_SLU_ARCH_REQ 2 /* Required SLU architecture level */
  59. /**
  60. * struct genwqe_reg - Genwqe data dump functionality
  61. */
  62. struct genwqe_reg {
  63. u32 addr;
  64. u32 idx;
  65. u64 val;
  66. };
  67. /*
  68. * enum genwqe_dbg_type - Specify chip unit to dump/debug
  69. */
  70. enum genwqe_dbg_type {
  71. GENWQE_DBG_UNIT0 = 0, /* captured before prev errs cleared */
  72. GENWQE_DBG_UNIT1 = 1,
  73. GENWQE_DBG_UNIT2 = 2,
  74. GENWQE_DBG_UNIT3 = 3,
  75. GENWQE_DBG_UNIT4 = 4,
  76. GENWQE_DBG_UNIT5 = 5,
  77. GENWQE_DBG_UNIT6 = 6,
  78. GENWQE_DBG_UNIT7 = 7,
  79. GENWQE_DBG_REGS = 8,
  80. GENWQE_DBG_DMA = 9,
  81. GENWQE_DBG_UNITS = 10, /* max number of possible debug units */
  82. };
  83. /* Software error injection to simulate card failures */
  84. #define GENWQE_INJECT_HARDWARE_FAILURE 0x00000001 /* injects -1 reg reads */
  85. #define GENWQE_INJECT_BUS_RESET_FAILURE 0x00000002 /* pci_bus_reset fail */
  86. #define GENWQE_INJECT_GFIR_FATAL 0x00000004 /* GFIR = 0x0000ffff */
  87. #define GENWQE_INJECT_GFIR_INFO 0x00000008 /* GFIR = 0xffff0000 */
  88. /*
  89. * Genwqe card description and management data.
  90. *
  91. * Error-handling in case of card malfunction
  92. * ------------------------------------------
  93. *
  94. * If the card is detected to be defective the outside environment
  95. * will cause the PCI layer to call deinit (the cleanup function for
  96. * probe). This is the same effect like doing a unbind/bind operation
  97. * on the card.
  98. *
  99. * The genwqe card driver implements a health checking thread which
  100. * verifies the card function. If this detects a problem the cards
  101. * device is being shutdown and restarted again, along with a reset of
  102. * the card and queue.
  103. *
  104. * All functions accessing the card device return either -EIO or -ENODEV
  105. * code to indicate the malfunction to the user. The user has to close
  106. * the file descriptor and open a new one, once the card becomes
  107. * available again.
  108. *
  109. * If the open file descriptor is setup to receive SIGIO, the signal is
  110. * genereated for the application which has to provide a handler to
  111. * react on it. If the application does not close the open
  112. * file descriptor a SIGKILL is send to enforce freeing the cards
  113. * resources.
  114. *
  115. * I did not find a different way to prevent kernel problems due to
  116. * reference counters for the cards character devices getting out of
  117. * sync. The character device deallocation does not block, even if
  118. * there is still an open file descriptor pending. If this pending
  119. * descriptor is closed, the data structures used by the character
  120. * device is reinstantiated, which will lead to the reference counter
  121. * dropping below the allowed values.
  122. *
  123. * Card recovery
  124. * -------------
  125. *
  126. * To test the internal driver recovery the following command can be used:
  127. * sudo sh -c 'echo 0xfffff > /sys/class/genwqe/genwqe0_card/err_inject'
  128. */
  129. /**
  130. * struct dma_mapping_type - Mapping type definition
  131. *
  132. * To avoid memcpying data arround we use user memory directly. To do
  133. * this we need to pin/swap-in the memory and request a DMA address
  134. * for it.
  135. */
  136. enum dma_mapping_type {
  137. GENWQE_MAPPING_RAW = 0, /* contignous memory buffer */
  138. GENWQE_MAPPING_SGL_TEMP, /* sglist dynamically used */
  139. GENWQE_MAPPING_SGL_PINNED, /* sglist used with pinning */
  140. };
  141. /**
  142. * struct dma_mapping - Information about memory mappings done by the driver
  143. */
  144. struct dma_mapping {
  145. enum dma_mapping_type type;
  146. void *u_vaddr; /* user-space vaddr/non-aligned */
  147. void *k_vaddr; /* kernel-space vaddr/non-aligned */
  148. dma_addr_t dma_addr; /* physical DMA address */
  149. struct page **page_list; /* list of pages used by user buff */
  150. dma_addr_t *dma_list; /* list of dma addresses per page */
  151. unsigned int nr_pages; /* number of pages */
  152. unsigned int size; /* size in bytes */
  153. struct list_head card_list; /* list of usr_maps for card */
  154. struct list_head pin_list; /* list of pinned memory for dev */
  155. int write; /* writable map? useful in unmapping */
  156. };
  157. static inline void genwqe_mapping_init(struct dma_mapping *m,
  158. enum dma_mapping_type type)
  159. {
  160. memset(m, 0, sizeof(*m));
  161. m->type = type;
  162. m->write = 1; /* Assume the maps we create are R/W */
  163. }
  164. /**
  165. * struct ddcb_queue - DDCB queue data
  166. * @ddcb_max: Number of DDCBs on the queue
  167. * @ddcb_next: Next free DDCB
  168. * @ddcb_act: Next DDCB supposed to finish
  169. * @ddcb_seq: Sequence number of last DDCB
  170. * @ddcbs_in_flight: Currently enqueued DDCBs
  171. * @ddcbs_completed: Number of already completed DDCBs
  172. * @return_on_busy: Number of -EBUSY returns on full queue
  173. * @wait_on_busy: Number of waits on full queue
  174. * @ddcb_daddr: DMA address of first DDCB in the queue
  175. * @ddcb_vaddr: Kernel virtual address of first DDCB in the queue
  176. * @ddcb_req: Associated requests (one per DDCB)
  177. * @ddcb_waitqs: Associated wait queues (one per DDCB)
  178. * @ddcb_lock: Lock to protect queuing operations
  179. * @ddcb_waitq: Wait on next DDCB finishing
  180. */
  181. struct ddcb_queue {
  182. int ddcb_max; /* amount of DDCBs */
  183. int ddcb_next; /* next available DDCB num */
  184. int ddcb_act; /* DDCB to be processed */
  185. u16 ddcb_seq; /* slc seq num */
  186. unsigned int ddcbs_in_flight; /* number of ddcbs in processing */
  187. unsigned int ddcbs_completed;
  188. unsigned int ddcbs_max_in_flight;
  189. unsigned int return_on_busy; /* how many times -EBUSY? */
  190. unsigned int wait_on_busy;
  191. dma_addr_t ddcb_daddr; /* DMA address */
  192. struct ddcb *ddcb_vaddr; /* kernel virtual addr for DDCBs */
  193. struct ddcb_requ **ddcb_req; /* ddcb processing parameter */
  194. wait_queue_head_t *ddcb_waitqs; /* waitqueue per ddcb */
  195. spinlock_t ddcb_lock; /* exclusive access to queue */
  196. wait_queue_head_t busy_waitq; /* wait for ddcb processing */
  197. /* registers or the respective queue to be used */
  198. u32 IO_QUEUE_CONFIG;
  199. u32 IO_QUEUE_STATUS;
  200. u32 IO_QUEUE_SEGMENT;
  201. u32 IO_QUEUE_INITSQN;
  202. u32 IO_QUEUE_WRAP;
  203. u32 IO_QUEUE_OFFSET;
  204. u32 IO_QUEUE_WTIME;
  205. u32 IO_QUEUE_ERRCNTS;
  206. u32 IO_QUEUE_LRW;
  207. };
  208. /*
  209. * GFIR, SLU_UNITCFG, APP_UNITCFG
  210. * 8 Units with FIR/FEC + 64 * 2ndary FIRS/FEC.
  211. */
  212. #define GENWQE_FFDC_REGS (3 + (8 * (2 + 2 * 64)))
  213. struct genwqe_ffdc {
  214. unsigned int entries;
  215. struct genwqe_reg *regs;
  216. };
  217. /**
  218. * struct genwqe_dev - GenWQE device information
  219. * @card_state: Card operation state, see above
  220. * @ffdc: First Failure Data Capture buffers for each unit
  221. * @card_thread: Working thread to operate the DDCB queue
  222. * @card_waitq: Wait queue used in card_thread
  223. * @queue: DDCB queue
  224. * @health_thread: Card monitoring thread (only for PFs)
  225. * @health_waitq: Wait queue used in health_thread
  226. * @pci_dev: Associated PCI device (function)
  227. * @mmio: Base address of 64-bit register space
  228. * @mmio_len: Length of register area
  229. * @file_lock: Lock to protect access to file_list
  230. * @file_list: List of all processes with open GenWQE file descriptors
  231. *
  232. * This struct contains all information needed to communicate with a
  233. * GenWQE card. It is initialized when a GenWQE device is found and
  234. * destroyed when it goes away. It holds data to maintain the queue as
  235. * well as data needed to feed the user interfaces.
  236. */
  237. struct genwqe_dev {
  238. enum genwqe_card_state card_state;
  239. spinlock_t print_lock;
  240. int card_idx; /* card index 0..CARD_NO_MAX-1 */
  241. u64 flags; /* general flags */
  242. /* FFDC data gathering */
  243. struct genwqe_ffdc ffdc[GENWQE_DBG_UNITS];
  244. /* DDCB workqueue */
  245. struct task_struct *card_thread;
  246. wait_queue_head_t queue_waitq;
  247. struct ddcb_queue queue; /* genwqe DDCB queue */
  248. unsigned int irqs_processed;
  249. /* Card health checking thread */
  250. struct task_struct *health_thread;
  251. wait_queue_head_t health_waitq;
  252. int use_platform_recovery; /* use platform recovery mechanisms */
  253. /* char device */
  254. dev_t devnum_genwqe; /* major/minor num card */
  255. struct class *class_genwqe; /* reference to class object */
  256. struct device *dev; /* for device creation */
  257. struct cdev cdev_genwqe; /* char device for card */
  258. struct dentry *debugfs_root; /* debugfs card root directory */
  259. struct dentry *debugfs_genwqe; /* debugfs driver root directory */
  260. /* pci resources */
  261. struct pci_dev *pci_dev; /* PCI device */
  262. void __iomem *mmio; /* BAR-0 MMIO start */
  263. unsigned long mmio_len;
  264. int num_vfs;
  265. u32 vf_jobtimeout_msec[GENWQE_MAX_VFS];
  266. int is_privileged; /* access to all regs possible */
  267. /* config regs which we need often */
  268. u64 slu_unitcfg;
  269. u64 app_unitcfg;
  270. u64 softreset;
  271. u64 err_inject;
  272. u64 last_gfir;
  273. char app_name[5];
  274. spinlock_t file_lock; /* lock for open files */
  275. struct list_head file_list; /* list of open files */
  276. /* debugfs parameters */
  277. int ddcb_software_timeout; /* wait until DDCB times out */
  278. int skip_recovery; /* circumvention if recovery fails */
  279. int kill_timeout; /* wait after sending SIGKILL */
  280. };
  281. /**
  282. * enum genwqe_requ_state - State of a DDCB execution request
  283. */
  284. enum genwqe_requ_state {
  285. GENWQE_REQU_NEW = 0,
  286. GENWQE_REQU_ENQUEUED = 1,
  287. GENWQE_REQU_TAPPED = 2,
  288. GENWQE_REQU_FINISHED = 3,
  289. GENWQE_REQU_STATE_MAX,
  290. };
  291. /**
  292. * struct genwqe_sgl - Scatter gather list describing user-space memory
  293. * @sgl: scatter gather list needs to be 128 byte aligned
  294. * @sgl_dma_addr: dma address of sgl
  295. * @sgl_size: size of area used for sgl
  296. * @user_addr: user-space address of memory area
  297. * @user_size: size of user-space memory area
  298. * @page: buffer for partial pages if needed
  299. * @page_dma_addr: dma address partial pages
  300. * @write: should we write it back to userspace?
  301. */
  302. struct genwqe_sgl {
  303. dma_addr_t sgl_dma_addr;
  304. struct sg_entry *sgl;
  305. size_t sgl_size; /* size of sgl */
  306. void __user *user_addr; /* user-space base-address */
  307. size_t user_size; /* size of memory area */
  308. int write;
  309. unsigned long nr_pages;
  310. unsigned long fpage_offs;
  311. size_t fpage_size;
  312. size_t lpage_size;
  313. void *fpage;
  314. dma_addr_t fpage_dma_addr;
  315. void *lpage;
  316. dma_addr_t lpage_dma_addr;
  317. };
  318. int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl,
  319. void __user *user_addr, size_t user_size, int write);
  320. int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl,
  321. dma_addr_t *dma_list);
  322. int genwqe_free_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl);
  323. /**
  324. * struct ddcb_requ - Kernel internal representation of the DDCB request
  325. * @cmd: User space representation of the DDCB execution request
  326. */
  327. struct ddcb_requ {
  328. /* kernel specific content */
  329. enum genwqe_requ_state req_state; /* request status */
  330. int num; /* ddcb_no for this request */
  331. struct ddcb_queue *queue; /* associated queue */
  332. struct dma_mapping dma_mappings[DDCB_FIXUPS];
  333. struct genwqe_sgl sgls[DDCB_FIXUPS];
  334. /* kernel/user shared content */
  335. struct genwqe_ddcb_cmd cmd; /* ddcb_no for this request */
  336. struct genwqe_debug_data debug_data;
  337. };
  338. /**
  339. * struct genwqe_file - Information for open GenWQE devices
  340. */
  341. struct genwqe_file {
  342. struct genwqe_dev *cd;
  343. struct genwqe_driver *client;
  344. struct file *filp;
  345. struct fasync_struct *async_queue;
  346. struct pid *opener;
  347. struct list_head list; /* entry in list of open files */
  348. spinlock_t map_lock; /* lock for dma_mappings */
  349. struct list_head map_list; /* list of dma_mappings */
  350. spinlock_t pin_lock; /* lock for pinned memory */
  351. struct list_head pin_list; /* list of pinned memory */
  352. };
  353. int genwqe_setup_service_layer(struct genwqe_dev *cd); /* for PF only */
  354. int genwqe_finish_queue(struct genwqe_dev *cd);
  355. int genwqe_release_service_layer(struct genwqe_dev *cd);
  356. /**
  357. * genwqe_get_slu_id() - Read Service Layer Unit Id
  358. * Return: 0x00: Development code
  359. * 0x01: SLC1 (old)
  360. * 0x02: SLC2 (sept2012)
  361. * 0x03: SLC2 (feb2013, generic driver)
  362. */
  363. static inline int genwqe_get_slu_id(struct genwqe_dev *cd)
  364. {
  365. return (int)((cd->slu_unitcfg >> 32) & 0xff);
  366. }
  367. int genwqe_ddcbs_in_flight(struct genwqe_dev *cd);
  368. u8 genwqe_card_type(struct genwqe_dev *cd);
  369. int genwqe_card_reset(struct genwqe_dev *cd);
  370. int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count);
  371. void genwqe_reset_interrupt_capability(struct genwqe_dev *cd);
  372. int genwqe_device_create(struct genwqe_dev *cd);
  373. int genwqe_device_remove(struct genwqe_dev *cd);
  374. /* debugfs */
  375. void genwqe_init_debugfs(struct genwqe_dev *cd);
  376. void genqwe_exit_debugfs(struct genwqe_dev *cd);
  377. int genwqe_read_softreset(struct genwqe_dev *cd);
  378. /* Hardware Circumventions */
  379. int genwqe_recovery_on_fatal_gfir_required(struct genwqe_dev *cd);
  380. int genwqe_flash_readback_fails(struct genwqe_dev *cd);
  381. /**
  382. * genwqe_write_vreg() - Write register in VF window
  383. * @cd: genwqe device
  384. * @reg: register address
  385. * @val: value to write
  386. * @func: 0: PF, 1: VF0, ..., 15: VF14
  387. */
  388. int genwqe_write_vreg(struct genwqe_dev *cd, u32 reg, u64 val, int func);
  389. /**
  390. * genwqe_read_vreg() - Read register in VF window
  391. * @cd: genwqe device
  392. * @reg: register address
  393. * @func: 0: PF, 1: VF0, ..., 15: VF14
  394. *
  395. * Return: content of the register
  396. */
  397. u64 genwqe_read_vreg(struct genwqe_dev *cd, u32 reg, int func);
  398. /* FFDC Buffer Management */
  399. int genwqe_ffdc_buff_size(struct genwqe_dev *cd, int unit_id);
  400. int genwqe_ffdc_buff_read(struct genwqe_dev *cd, int unit_id,
  401. struct genwqe_reg *regs, unsigned int max_regs);
  402. int genwqe_read_ffdc_regs(struct genwqe_dev *cd, struct genwqe_reg *regs,
  403. unsigned int max_regs, int all);
  404. int genwqe_ffdc_dump_dma(struct genwqe_dev *cd,
  405. struct genwqe_reg *regs, unsigned int max_regs);
  406. int genwqe_init_debug_data(struct genwqe_dev *cd,
  407. struct genwqe_debug_data *d);
  408. void genwqe_init_crc32(void);
  409. int genwqe_read_app_id(struct genwqe_dev *cd, char *app_name, int len);
  410. /* Memory allocation/deallocation; dma address handling */
  411. int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m,
  412. void *uaddr, unsigned long size);
  413. int genwqe_user_vunmap(struct genwqe_dev *cd, struct dma_mapping *m);
  414. static inline bool dma_mapping_used(struct dma_mapping *m)
  415. {
  416. if (!m)
  417. return false;
  418. return m->size != 0;
  419. }
  420. /**
  421. * __genwqe_execute_ddcb() - Execute DDCB request with addr translation
  422. *
  423. * This function will do the address translation changes to the DDCBs
  424. * according to the definitions required by the ATS field. It looks up
  425. * the memory allocation buffer or does vmap/vunmap for the respective
  426. * user-space buffers, inclusive page pinning and scatter gather list
  427. * buildup and teardown.
  428. */
  429. int __genwqe_execute_ddcb(struct genwqe_dev *cd,
  430. struct genwqe_ddcb_cmd *cmd, unsigned int f_flags);
  431. /**
  432. * __genwqe_execute_raw_ddcb() - Execute DDCB request without addr translation
  433. *
  434. * This version will not do address translation or any modification of
  435. * the DDCB data. It is used e.g. for the MoveFlash DDCB which is
  436. * entirely prepared by the driver itself. That means the appropriate
  437. * DMA addresses are already in the DDCB and do not need any
  438. * modification.
  439. */
  440. int __genwqe_execute_raw_ddcb(struct genwqe_dev *cd,
  441. struct genwqe_ddcb_cmd *cmd,
  442. unsigned int f_flags);
  443. int __genwqe_enqueue_ddcb(struct genwqe_dev *cd,
  444. struct ddcb_requ *req,
  445. unsigned int f_flags);
  446. int __genwqe_wait_ddcb(struct genwqe_dev *cd, struct ddcb_requ *req);
  447. int __genwqe_purge_ddcb(struct genwqe_dev *cd, struct ddcb_requ *req);
  448. /* register access */
  449. int __genwqe_writeq(struct genwqe_dev *cd, u64 byte_offs, u64 val);
  450. u64 __genwqe_readq(struct genwqe_dev *cd, u64 byte_offs);
  451. int __genwqe_writel(struct genwqe_dev *cd, u64 byte_offs, u32 val);
  452. u32 __genwqe_readl(struct genwqe_dev *cd, u64 byte_offs);
  453. void *__genwqe_alloc_consistent(struct genwqe_dev *cd, size_t size,
  454. dma_addr_t *dma_handle);
  455. void __genwqe_free_consistent(struct genwqe_dev *cd, size_t size,
  456. void *vaddr, dma_addr_t dma_handle);
  457. /* Base clock frequency in MHz */
  458. int genwqe_base_clock_frequency(struct genwqe_dev *cd);
  459. /* Before FFDC is captured the traps should be stopped. */
  460. void genwqe_stop_traps(struct genwqe_dev *cd);
  461. void genwqe_start_traps(struct genwqe_dev *cd);
  462. /* Hardware circumvention */
  463. bool genwqe_need_err_masking(struct genwqe_dev *cd);
  464. /**
  465. * genwqe_is_privileged() - Determine operation mode for PCI function
  466. *
  467. * On Intel with SRIOV support we see:
  468. * PF: is_physfn = 1 is_virtfn = 0
  469. * VF: is_physfn = 0 is_virtfn = 1
  470. *
  471. * On Systems with no SRIOV support _and_ virtualized systems we get:
  472. * is_physfn = 0 is_virtfn = 0
  473. *
  474. * Other vendors have individual pci device ids to distinguish between
  475. * virtual function drivers and physical function drivers. GenWQE
  476. * unfortunately has just on pci device id for both, VFs and PF.
  477. *
  478. * The following code is used to distinguish if the card is running in
  479. * privileged mode, either as true PF or in a virtualized system with
  480. * full register access e.g. currently on PowerPC.
  481. *
  482. * if (pci_dev->is_virtfn)
  483. * cd->is_privileged = 0;
  484. * else
  485. * cd->is_privileged = (__genwqe_readq(cd, IO_SLU_BITSTREAM)
  486. * != IO_ILLEGAL_VALUE);
  487. */
  488. static inline int genwqe_is_privileged(struct genwqe_dev *cd)
  489. {
  490. return cd->is_privileged;
  491. }
  492. #endif /* __CARD_BASE_H__ */