card_base.h 19 KB

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