card_base.h 19 KB

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