ipath_kernel.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. #ifndef _IPATH_KERNEL_H
  2. #define _IPATH_KERNEL_H
  3. /*
  4. * Copyright (c) 2006, 2007 QLogic Corporation. All rights reserved.
  5. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. /*
  36. * This header file is the base header file for infinipath kernel code
  37. * ipath_user.h serves a similar purpose for user code.
  38. */
  39. #include <linux/interrupt.h>
  40. #include <linux/pci.h>
  41. #include <linux/dma-mapping.h>
  42. #include <linux/mutex.h>
  43. #include <asm/io.h>
  44. #include <rdma/ib_verbs.h>
  45. #include "ipath_common.h"
  46. #include "ipath_debug.h"
  47. #include "ipath_registers.h"
  48. /* only s/w major version of InfiniPath we can handle */
  49. #define IPATH_CHIP_VERS_MAJ 2U
  50. /* don't care about this except printing */
  51. #define IPATH_CHIP_VERS_MIN 0U
  52. /* temporary, maybe always */
  53. extern struct infinipath_stats ipath_stats;
  54. #define IPATH_CHIP_SWVERSION IPATH_CHIP_VERS_MAJ
  55. /*
  56. * First-cut critierion for "device is active" is
  57. * two thousand dwords combined Tx, Rx traffic per
  58. * 5-second interval. SMA packets are 64 dwords,
  59. * and occur "a few per second", presumably each way.
  60. */
  61. #define IPATH_TRAFFIC_ACTIVE_THRESHOLD (2000)
  62. /*
  63. * Struct used to indicate which errors are logged in each of the
  64. * error-counters that are logged to EEPROM. A counter is incremented
  65. * _once_ (saturating at 255) for each event with any bits set in
  66. * the error or hwerror register masks below.
  67. */
  68. #define IPATH_EEP_LOG_CNT (4)
  69. struct ipath_eep_log_mask {
  70. u64 errs_to_log;
  71. u64 hwerrs_to_log;
  72. };
  73. struct ipath_portdata {
  74. void **port_rcvegrbuf;
  75. dma_addr_t *port_rcvegrbuf_phys;
  76. /* rcvhdrq base, needs mmap before useful */
  77. void *port_rcvhdrq;
  78. /* kernel virtual address where hdrqtail is updated */
  79. void *port_rcvhdrtail_kvaddr;
  80. /*
  81. * temp buffer for expected send setup, allocated at open, instead
  82. * of each setup call
  83. */
  84. void *port_tid_pg_list;
  85. /* when waiting for rcv or pioavail */
  86. wait_queue_head_t port_wait;
  87. /*
  88. * rcvegr bufs base, physical, must fit
  89. * in 44 bits so 32 bit programs mmap64 44 bit works)
  90. */
  91. dma_addr_t port_rcvegr_phys;
  92. /* mmap of hdrq, must fit in 44 bits */
  93. dma_addr_t port_rcvhdrq_phys;
  94. dma_addr_t port_rcvhdrqtailaddr_phys;
  95. /*
  96. * number of opens (including slave subports) on this instance
  97. * (ignoring forks, dup, etc. for now)
  98. */
  99. int port_cnt;
  100. /*
  101. * how much space to leave at start of eager TID entries for
  102. * protocol use, on each TID
  103. */
  104. /* instead of calculating it */
  105. unsigned port_port;
  106. /* non-zero if port is being shared. */
  107. u16 port_subport_cnt;
  108. /* non-zero if port is being shared. */
  109. u16 port_subport_id;
  110. /* chip offset of PIO buffers for this port */
  111. u32 port_piobufs;
  112. /* how many alloc_pages() chunks in port_rcvegrbuf_pages */
  113. u32 port_rcvegrbuf_chunks;
  114. /* how many egrbufs per chunk */
  115. u32 port_rcvegrbufs_perchunk;
  116. /* order for port_rcvegrbuf_pages */
  117. size_t port_rcvegrbuf_size;
  118. /* rcvhdrq size (for freeing) */
  119. size_t port_rcvhdrq_size;
  120. /* next expected TID to check when looking for free */
  121. u32 port_tidcursor;
  122. /* next expected TID to check */
  123. unsigned long port_flag;
  124. /* what happened */
  125. unsigned long int_flag;
  126. /* WAIT_RCV that timed out, no interrupt */
  127. u32 port_rcvwait_to;
  128. /* WAIT_PIO that timed out, no interrupt */
  129. u32 port_piowait_to;
  130. /* WAIT_RCV already happened, no wait */
  131. u32 port_rcvnowait;
  132. /* WAIT_PIO already happened, no wait */
  133. u32 port_pionowait;
  134. /* total number of rcvhdrqfull errors */
  135. u32 port_hdrqfull;
  136. /*
  137. * Used to suppress multiple instances of same
  138. * port staying stuck at same point.
  139. */
  140. u32 port_lastrcvhdrqtail;
  141. /* saved total number of rcvhdrqfull errors for poll edge trigger */
  142. u32 port_hdrqfull_poll;
  143. /* total number of polled urgent packets */
  144. u32 port_urgent;
  145. /* saved total number of polled urgent packets for poll edge trigger */
  146. u32 port_urgent_poll;
  147. /* pid of process using this port */
  148. pid_t port_pid;
  149. pid_t port_subpid[INFINIPATH_MAX_SUBPORT];
  150. /* same size as task_struct .comm[] */
  151. char port_comm[16];
  152. /* pkeys set by this use of this port */
  153. u16 port_pkeys[4];
  154. /* so file ops can get at unit */
  155. struct ipath_devdata *port_dd;
  156. /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
  157. void *subport_uregbase;
  158. /* An array of pages for the eager receive buffers * N */
  159. void *subport_rcvegrbuf;
  160. /* An array of pages for the eager header queue entries * N */
  161. void *subport_rcvhdr_base;
  162. /* The version of the library which opened this port */
  163. u32 userversion;
  164. /* Bitmask of active slaves */
  165. u32 active_slaves;
  166. /* Type of packets or conditions we want to poll for */
  167. u16 poll_type;
  168. /* port rcvhdrq head offset */
  169. u32 port_head;
  170. /* receive packet sequence counter */
  171. u32 port_seq_cnt;
  172. };
  173. struct sk_buff;
  174. /*
  175. * control information for layered drivers
  176. */
  177. struct _ipath_layer {
  178. void *l_arg;
  179. };
  180. struct ipath_skbinfo {
  181. struct sk_buff *skb;
  182. dma_addr_t phys;
  183. };
  184. /* max dwords in small buffer packet */
  185. #define IPATH_SMALLBUF_DWORDS (dd->ipath_piosize2k >> 2)
  186. /*
  187. * Possible IB config parameters for ipath_f_get/set_ib_cfg()
  188. */
  189. #define IPATH_IB_CFG_LIDLMC 0 /* Get/set LID (LS16b) and Mask (MS16b) */
  190. #define IPATH_IB_CFG_HRTBT 1 /* Get/set Heartbeat off/enable/auto */
  191. #define IPATH_IB_HRTBT_ON 3 /* Heartbeat enabled, sent every 100msec */
  192. #define IPATH_IB_HRTBT_OFF 0 /* Heartbeat off */
  193. #define IPATH_IB_CFG_LWID_ENB 2 /* Get/set allowed Link-width */
  194. #define IPATH_IB_CFG_LWID 3 /* Get currently active Link-width */
  195. #define IPATH_IB_CFG_SPD_ENB 4 /* Get/set allowed Link speeds */
  196. #define IPATH_IB_CFG_SPD 5 /* Get current Link spd */
  197. #define IPATH_IB_CFG_RXPOL_ENB 6 /* Get/set Auto-RX-polarity enable */
  198. #define IPATH_IB_CFG_LREV_ENB 7 /* Get/set Auto-Lane-reversal enable */
  199. #define IPATH_IB_CFG_LINKLATENCY 8 /* Get Auto-Lane-reversal enable */
  200. struct ipath_devdata {
  201. struct list_head ipath_list;
  202. struct ipath_kregs const *ipath_kregs;
  203. struct ipath_cregs const *ipath_cregs;
  204. /* mem-mapped pointer to base of chip regs */
  205. u64 __iomem *ipath_kregbase;
  206. /* end of mem-mapped chip space; range checking */
  207. u64 __iomem *ipath_kregend;
  208. /* physical address of chip for io_remap, etc. */
  209. unsigned long ipath_physaddr;
  210. /* base of memory alloced for ipath_kregbase, for free */
  211. u64 *ipath_kregalloc;
  212. /* ipath_cfgports pointers */
  213. struct ipath_portdata **ipath_pd;
  214. /* sk_buffs used by port 0 eager receive queue */
  215. struct ipath_skbinfo *ipath_port0_skbinfo;
  216. /* kvirt address of 1st 2k pio buffer */
  217. void __iomem *ipath_pio2kbase;
  218. /* kvirt address of 1st 4k pio buffer */
  219. void __iomem *ipath_pio4kbase;
  220. /*
  221. * points to area where PIOavail registers will be DMA'ed.
  222. * Has to be on a page of it's own, because the page will be
  223. * mapped into user program space. This copy is *ONLY* ever
  224. * written by DMA, not by the driver! Need a copy per device
  225. * when we get to multiple devices
  226. */
  227. volatile __le64 *ipath_pioavailregs_dma;
  228. /* physical address where updates occur */
  229. dma_addr_t ipath_pioavailregs_phys;
  230. struct _ipath_layer ipath_layer;
  231. /* setup intr */
  232. int (*ipath_f_intrsetup)(struct ipath_devdata *);
  233. /* fallback to alternate interrupt type if possible */
  234. int (*ipath_f_intr_fallback)(struct ipath_devdata *);
  235. /* setup on-chip bus config */
  236. int (*ipath_f_bus)(struct ipath_devdata *, struct pci_dev *);
  237. /* hard reset chip */
  238. int (*ipath_f_reset)(struct ipath_devdata *);
  239. int (*ipath_f_get_boardname)(struct ipath_devdata *, char *,
  240. size_t);
  241. void (*ipath_f_init_hwerrors)(struct ipath_devdata *);
  242. void (*ipath_f_handle_hwerrors)(struct ipath_devdata *, char *,
  243. size_t);
  244. void (*ipath_f_quiet_serdes)(struct ipath_devdata *);
  245. int (*ipath_f_bringup_serdes)(struct ipath_devdata *);
  246. int (*ipath_f_early_init)(struct ipath_devdata *);
  247. void (*ipath_f_clear_tids)(struct ipath_devdata *, unsigned);
  248. void (*ipath_f_put_tid)(struct ipath_devdata *, u64 __iomem*,
  249. u32, unsigned long);
  250. void (*ipath_f_tidtemplate)(struct ipath_devdata *);
  251. void (*ipath_f_cleanup)(struct ipath_devdata *);
  252. void (*ipath_f_setextled)(struct ipath_devdata *, u64, u64);
  253. /* fill out chip-specific fields */
  254. int (*ipath_f_get_base_info)(struct ipath_portdata *, void *);
  255. /* free irq */
  256. void (*ipath_f_free_irq)(struct ipath_devdata *);
  257. struct ipath_message_header *(*ipath_f_get_msgheader)
  258. (struct ipath_devdata *, __le32 *);
  259. void (*ipath_f_config_ports)(struct ipath_devdata *, ushort);
  260. int (*ipath_f_get_ib_cfg)(struct ipath_devdata *, int);
  261. int (*ipath_f_set_ib_cfg)(struct ipath_devdata *, int, u32);
  262. void (*ipath_f_config_jint)(struct ipath_devdata *, u16 , u16);
  263. void (*ipath_f_read_counters)(struct ipath_devdata *,
  264. struct infinipath_counters *);
  265. void (*ipath_f_xgxs_reset)(struct ipath_devdata *);
  266. /* per chip actions needed for IB Link up/down changes */
  267. int (*ipath_f_ib_updown)(struct ipath_devdata *, int, u64);
  268. unsigned ipath_lastegr_idx;
  269. struct ipath_ibdev *verbs_dev;
  270. struct timer_list verbs_timer;
  271. /* total dwords sent (summed from counter) */
  272. u64 ipath_sword;
  273. /* total dwords rcvd (summed from counter) */
  274. u64 ipath_rword;
  275. /* total packets sent (summed from counter) */
  276. u64 ipath_spkts;
  277. /* total packets rcvd (summed from counter) */
  278. u64 ipath_rpkts;
  279. /* ipath_statusp initially points to this. */
  280. u64 _ipath_status;
  281. /* GUID for this interface, in network order */
  282. __be64 ipath_guid;
  283. /*
  284. * aggregrate of error bits reported since last cleared, for
  285. * limiting of error reporting
  286. */
  287. ipath_err_t ipath_lasterror;
  288. /*
  289. * aggregrate of error bits reported since last cleared, for
  290. * limiting of hwerror reporting
  291. */
  292. ipath_err_t ipath_lasthwerror;
  293. /* errors masked because they occur too fast */
  294. ipath_err_t ipath_maskederrs;
  295. u64 ipath_lastlinkrecov; /* link recoveries at last ACTIVE */
  296. /* time in jiffies at which to re-enable maskederrs */
  297. unsigned long ipath_unmasktime;
  298. /* count of egrfull errors, combined for all ports */
  299. u64 ipath_last_tidfull;
  300. /* for ipath_qcheck() */
  301. u64 ipath_lastport0rcv_cnt;
  302. /* template for writing TIDs */
  303. u64 ipath_tidtemplate;
  304. /* value to write to free TIDs */
  305. u64 ipath_tidinvalid;
  306. /* IBA6120 rcv interrupt setup */
  307. u64 ipath_rhdrhead_intr_off;
  308. /* size of memory at ipath_kregbase */
  309. u32 ipath_kregsize;
  310. /* number of registers used for pioavail */
  311. u32 ipath_pioavregs;
  312. /* IPATH_POLL, etc. */
  313. u32 ipath_flags;
  314. /* ipath_flags driver is waiting for */
  315. u32 ipath_state_wanted;
  316. /* last buffer for user use, first buf for kernel use is this
  317. * index. */
  318. u32 ipath_lastport_piobuf;
  319. /* is a stats timer active */
  320. u32 ipath_stats_timer_active;
  321. /* number of interrupts for this device -- saturates... */
  322. u32 ipath_int_counter;
  323. /* dwords sent read from counter */
  324. u32 ipath_lastsword;
  325. /* dwords received read from counter */
  326. u32 ipath_lastrword;
  327. /* sent packets read from counter */
  328. u32 ipath_lastspkts;
  329. /* received packets read from counter */
  330. u32 ipath_lastrpkts;
  331. /* pio bufs allocated per port */
  332. u32 ipath_pbufsport;
  333. /*
  334. * number of ports configured as max; zero is set to number chip
  335. * supports, less gives more pio bufs/port, etc.
  336. */
  337. u32 ipath_cfgports;
  338. /* count of port 0 hdrqfull errors */
  339. u32 ipath_p0_hdrqfull;
  340. /* port 0 number of receive eager buffers */
  341. u32 ipath_p0_rcvegrcnt;
  342. /*
  343. * index of last piobuffer we used. Speeds up searching, by
  344. * starting at this point. Doesn't matter if multiple cpu's use and
  345. * update, last updater is only write that matters. Whenever it
  346. * wraps, we update shadow copies. Need a copy per device when we
  347. * get to multiple devices
  348. */
  349. u32 ipath_lastpioindex;
  350. u32 ipath_lastpioindexl;
  351. /* max length of freezemsg */
  352. u32 ipath_freezelen;
  353. /*
  354. * consecutive times we wanted a PIO buffer but were unable to
  355. * get one
  356. */
  357. u32 ipath_consec_nopiobuf;
  358. /*
  359. * hint that we should update ipath_pioavailshadow before
  360. * looking for a PIO buffer
  361. */
  362. u32 ipath_upd_pio_shadow;
  363. /* so we can rewrite it after a chip reset */
  364. u32 ipath_pcibar0;
  365. /* so we can rewrite it after a chip reset */
  366. u32 ipath_pcibar1;
  367. /* interrupt number */
  368. int ipath_irq;
  369. /* HT/PCI Vendor ID (here for NodeInfo) */
  370. u16 ipath_vendorid;
  371. /* HT/PCI Device ID (here for NodeInfo) */
  372. u16 ipath_deviceid;
  373. /* offset in HT config space of slave/primary interface block */
  374. u8 ipath_ht_slave_off;
  375. /* for write combining settings */
  376. unsigned long ipath_wc_cookie;
  377. unsigned long ipath_wc_base;
  378. unsigned long ipath_wc_len;
  379. /* ref count for each pkey */
  380. atomic_t ipath_pkeyrefs[4];
  381. /* shadow copy of struct page *'s for exp tid pages */
  382. struct page **ipath_pageshadow;
  383. /* shadow copy of dma handles for exp tid pages */
  384. dma_addr_t *ipath_physshadow;
  385. u64 __iomem *ipath_egrtidbase;
  386. /* lock to workaround chip bug 9437 and others */
  387. spinlock_t ipath_kernel_tid_lock;
  388. spinlock_t ipath_tid_lock;
  389. spinlock_t ipath_sendctrl_lock;
  390. /*
  391. * IPATH_STATUS_*,
  392. * this address is mapped readonly into user processes so they can
  393. * get status cheaply, whenever they want.
  394. */
  395. u64 *ipath_statusp;
  396. /* freeze msg if hw error put chip in freeze */
  397. char *ipath_freezemsg;
  398. /* pci access data structure */
  399. struct pci_dev *pcidev;
  400. struct cdev *user_cdev;
  401. struct cdev *diag_cdev;
  402. struct class_device *user_class_dev;
  403. struct class_device *diag_class_dev;
  404. /* timer used to prevent stats overflow, error throttling, etc. */
  405. struct timer_list ipath_stats_timer;
  406. void *ipath_dummy_hdrq; /* used after port close */
  407. dma_addr_t ipath_dummy_hdrq_phys;
  408. unsigned long ipath_ureg_align; /* user register alignment */
  409. /* HoL blocking / user app forward-progress state */
  410. unsigned ipath_hol_state;
  411. unsigned ipath_hol_next;
  412. struct timer_list ipath_hol_timer;
  413. /*
  414. * Shadow copies of registers; size indicates read access size.
  415. * Most of them are readonly, but some are write-only register,
  416. * where we manipulate the bits in the shadow copy, and then write
  417. * the shadow copy to infinipath.
  418. *
  419. * We deliberately make most of these 32 bits, since they have
  420. * restricted range. For any that we read, we won't to generate 32
  421. * bit accesses, since Opteron will generate 2 separate 32 bit HT
  422. * transactions for a 64 bit read, and we want to avoid unnecessary
  423. * HT transactions.
  424. */
  425. /* This is the 64 bit group */
  426. /*
  427. * shadow of pioavail, check to be sure it's large enough at
  428. * init time.
  429. */
  430. unsigned long ipath_pioavailshadow[8];
  431. /* bitmap of send buffers available for the kernel to use with PIO. */
  432. unsigned long ipath_pioavailkernel[8];
  433. /* shadow of kr_gpio_out, for rmw ops */
  434. u64 ipath_gpio_out;
  435. /* shadow the gpio mask register */
  436. u64 ipath_gpio_mask;
  437. /* shadow the gpio output enable, etc... */
  438. u64 ipath_extctrl;
  439. /* kr_revision shadow */
  440. u64 ipath_revision;
  441. /*
  442. * shadow of ibcctrl, for interrupt handling of link changes,
  443. * etc.
  444. */
  445. u64 ipath_ibcctrl;
  446. /*
  447. * last ibcstatus, to suppress "duplicate" status change messages,
  448. * mostly from 2 to 3
  449. */
  450. u64 ipath_lastibcstat;
  451. /* hwerrmask shadow */
  452. ipath_err_t ipath_hwerrmask;
  453. ipath_err_t ipath_errormask; /* errormask shadow */
  454. /* interrupt config reg shadow */
  455. u64 ipath_intconfig;
  456. /* kr_sendpiobufbase value */
  457. u64 ipath_piobufbase;
  458. /* these are the "32 bit" regs */
  459. /*
  460. * number of GUIDs in the flash for this interface; may need some
  461. * rethinking for setting on other ifaces
  462. */
  463. u32 ipath_nguid;
  464. /*
  465. * the following two are 32-bit bitmasks, but {test,clear,set}_bit
  466. * all expect bit fields to be "unsigned long"
  467. */
  468. /* shadow kr_rcvctrl */
  469. unsigned long ipath_rcvctrl;
  470. /* shadow kr_sendctrl */
  471. unsigned long ipath_sendctrl;
  472. unsigned long ipath_lastcancel; /* to not count armlaunch after cancel */
  473. /* value we put in kr_rcvhdrcnt */
  474. u32 ipath_rcvhdrcnt;
  475. /* value we put in kr_rcvhdrsize */
  476. u32 ipath_rcvhdrsize;
  477. /* value we put in kr_rcvhdrentsize */
  478. u32 ipath_rcvhdrentsize;
  479. /* offset of last entry in rcvhdrq */
  480. u32 ipath_hdrqlast;
  481. /* kr_portcnt value */
  482. u32 ipath_portcnt;
  483. /* kr_pagealign value */
  484. u32 ipath_palign;
  485. /* number of "2KB" PIO buffers */
  486. u32 ipath_piobcnt2k;
  487. /* size in bytes of "2KB" PIO buffers */
  488. u32 ipath_piosize2k;
  489. /* number of "4KB" PIO buffers */
  490. u32 ipath_piobcnt4k;
  491. /* size in bytes of "4KB" PIO buffers */
  492. u32 ipath_piosize4k;
  493. /* kr_rcvegrbase value */
  494. u32 ipath_rcvegrbase;
  495. /* kr_rcvegrcnt value */
  496. u32 ipath_rcvegrcnt;
  497. /* kr_rcvtidbase value */
  498. u32 ipath_rcvtidbase;
  499. /* kr_rcvtidcnt value */
  500. u32 ipath_rcvtidcnt;
  501. /* kr_sendregbase */
  502. u32 ipath_sregbase;
  503. /* kr_userregbase */
  504. u32 ipath_uregbase;
  505. /* kr_counterregbase */
  506. u32 ipath_cregbase;
  507. /* shadow the control register contents */
  508. u32 ipath_control;
  509. /* PCI revision register (HTC rev on FPGA) */
  510. u32 ipath_pcirev;
  511. /* chip address space used by 4k pio buffers */
  512. u32 ipath_4kalign;
  513. /* The MTU programmed for this unit */
  514. u32 ipath_ibmtu;
  515. /*
  516. * The max size IB packet, included IB headers that we can send.
  517. * Starts same as ipath_piosize, but is affected when ibmtu is
  518. * changed, or by size of eager buffers
  519. */
  520. u32 ipath_ibmaxlen;
  521. /*
  522. * ibmaxlen at init time, limited by chip and by receive buffer
  523. * size. Not changed after init.
  524. */
  525. u32 ipath_init_ibmaxlen;
  526. /* size of each rcvegrbuffer */
  527. u32 ipath_rcvegrbufsize;
  528. /* localbus width (1, 2,4,8,16,32) from config space */
  529. u32 ipath_lbus_width;
  530. /* localbus speed (HT: 200,400,800,1000; PCIe 2500) */
  531. u32 ipath_lbus_speed;
  532. /*
  533. * number of sequential ibcstatus change for polling active/quiet
  534. * (i.e., link not coming up).
  535. */
  536. u32 ipath_ibpollcnt;
  537. /* low and high portions of MSI capability/vector */
  538. u32 ipath_msi_lo;
  539. /* saved after PCIe init for restore after reset */
  540. u32 ipath_msi_hi;
  541. /* MSI data (vector) saved for restore */
  542. u16 ipath_msi_data;
  543. /* MLID programmed for this instance */
  544. u16 ipath_mlid;
  545. /* LID programmed for this instance */
  546. u16 ipath_lid;
  547. /* list of pkeys programmed; 0 if not set */
  548. u16 ipath_pkeys[4];
  549. /*
  550. * ASCII serial number, from flash, large enough for original
  551. * all digit strings, and longer QLogic serial number format
  552. */
  553. u8 ipath_serial[16];
  554. /* human readable board version */
  555. u8 ipath_boardversion[80];
  556. u8 ipath_lbus_info[32]; /* human readable localbus info */
  557. /* chip major rev, from ipath_revision */
  558. u8 ipath_majrev;
  559. /* chip minor rev, from ipath_revision */
  560. u8 ipath_minrev;
  561. /* board rev, from ipath_revision */
  562. u8 ipath_boardrev;
  563. /* saved for restore after reset */
  564. u8 ipath_pci_cacheline;
  565. /* LID mask control */
  566. u8 ipath_lmc;
  567. /* link width supported */
  568. u8 ipath_link_width_supported;
  569. /* link speed supported */
  570. u8 ipath_link_speed_supported;
  571. u8 ipath_link_width_enabled;
  572. u8 ipath_link_speed_enabled;
  573. u8 ipath_link_width_active;
  574. u8 ipath_link_speed_active;
  575. /* Rx Polarity inversion (compensate for ~tx on partner) */
  576. u8 ipath_rx_pol_inv;
  577. u8 ipath_r_portenable_shift;
  578. u8 ipath_r_intravail_shift;
  579. u8 ipath_r_tailupd_shift;
  580. u8 ipath_r_portcfg_shift;
  581. /* unit # of this chip, if present */
  582. int ipath_unit;
  583. /* local link integrity counter */
  584. u32 ipath_lli_counter;
  585. /* local link integrity errors */
  586. u32 ipath_lli_errors;
  587. /*
  588. * Above counts only cases where _successive_ LocalLinkIntegrity
  589. * errors were seen in the receive headers of kern-packets.
  590. * Below are the three (monotonically increasing) counters
  591. * maintained via GPIO interrupts on iba6120-rev2.
  592. */
  593. u32 ipath_rxfc_unsupvl_errs;
  594. u32 ipath_overrun_thresh_errs;
  595. u32 ipath_lli_errs;
  596. /* status check work */
  597. struct delayed_work status_work;
  598. /*
  599. * Not all devices managed by a driver instance are the same
  600. * type, so these fields must be per-device.
  601. */
  602. u64 ipath_i_bitsextant;
  603. ipath_err_t ipath_e_bitsextant;
  604. ipath_err_t ipath_hwe_bitsextant;
  605. /*
  606. * Below should be computable from number of ports,
  607. * since they are never modified.
  608. */
  609. u64 ipath_i_rcvavail_mask;
  610. u64 ipath_i_rcvurg_mask;
  611. u16 ipath_i_rcvurg_shift;
  612. u16 ipath_i_rcvavail_shift;
  613. /*
  614. * Register bits for selecting i2c direction and values, used for
  615. * I2C serial flash.
  616. */
  617. u8 ipath_gpio_sda_num;
  618. u8 ipath_gpio_scl_num;
  619. u8 ipath_i2c_chain_type;
  620. u64 ipath_gpio_sda;
  621. u64 ipath_gpio_scl;
  622. /* lock for doing RMW of shadows/regs for ExtCtrl and GPIO */
  623. spinlock_t ipath_gpio_lock;
  624. /*
  625. * IB link and linktraining states and masks that vary per chip in
  626. * some way. Set at init, to avoid each IB status change interrupt
  627. */
  628. u8 ibcs_ls_shift;
  629. u8 ibcs_lts_mask;
  630. u32 ibcs_mask;
  631. u32 ib_init;
  632. u32 ib_arm;
  633. u32 ib_active;
  634. u16 ipath_rhf_offset; /* offset of RHF within receive header entry */
  635. /*
  636. * shift/mask for linkcmd, linkinitcmd, maxpktlen in ibccontol
  637. * reg. Changes for IBA7220
  638. */
  639. u8 ibcc_lic_mask; /* LinkInitCmd */
  640. u8 ibcc_lc_shift; /* LinkCmd */
  641. u8 ibcc_mpl_shift; /* Maxpktlen */
  642. u8 delay_mult;
  643. /* used to override LED behavior */
  644. u8 ipath_led_override; /* Substituted for normal value, if non-zero */
  645. u16 ipath_led_override_timeoff; /* delta to next timer event */
  646. u8 ipath_led_override_vals[2]; /* Alternates per blink-frame */
  647. u8 ipath_led_override_phase; /* Just counts, LSB picks from vals[] */
  648. atomic_t ipath_led_override_timer_active;
  649. /* Used to flash LEDs in override mode */
  650. struct timer_list ipath_led_override_timer;
  651. /* Support (including locks) for EEPROM logging of errors and time */
  652. /* control access to actual counters, timer */
  653. spinlock_t ipath_eep_st_lock;
  654. /* control high-level access to EEPROM */
  655. struct mutex ipath_eep_lock;
  656. /* Below inc'd by ipath_snap_cntrs(), locked by ipath_eep_st_lock */
  657. uint64_t ipath_traffic_wds;
  658. /* active time is kept in seconds, but logged in hours */
  659. atomic_t ipath_active_time;
  660. /* Below are nominal shadow of EEPROM, new since last EEPROM update */
  661. uint8_t ipath_eep_st_errs[IPATH_EEP_LOG_CNT];
  662. uint8_t ipath_eep_st_new_errs[IPATH_EEP_LOG_CNT];
  663. uint16_t ipath_eep_hrs;
  664. /*
  665. * masks for which bits of errs, hwerrs that cause
  666. * each of the counters to increment.
  667. */
  668. struct ipath_eep_log_mask ipath_eep_st_masks[IPATH_EEP_LOG_CNT];
  669. /* interrupt mitigation reload register info */
  670. u16 ipath_jint_idle_ticks; /* idle clock ticks */
  671. u16 ipath_jint_max_packets; /* max packets across all ports */
  672. };
  673. /* ipath_hol_state values (stopping/starting user proc, send flushing) */
  674. #define IPATH_HOL_UP 0
  675. #define IPATH_HOL_DOWN 1
  676. /* ipath_hol_next toggle values, used when hol_state IPATH_HOL_DOWN */
  677. #define IPATH_HOL_DOWNSTOP 0
  678. #define IPATH_HOL_DOWNCONT 1
  679. /* Private data for file operations */
  680. struct ipath_filedata {
  681. struct ipath_portdata *pd;
  682. unsigned subport;
  683. unsigned tidcursor;
  684. };
  685. extern struct list_head ipath_dev_list;
  686. extern spinlock_t ipath_devs_lock;
  687. extern struct ipath_devdata *ipath_lookup(int unit);
  688. int ipath_init_chip(struct ipath_devdata *, int);
  689. int ipath_enable_wc(struct ipath_devdata *dd);
  690. void ipath_disable_wc(struct ipath_devdata *dd);
  691. int ipath_count_units(int *npresentp, int *nupp, int *maxportsp);
  692. void ipath_shutdown_device(struct ipath_devdata *);
  693. void ipath_clear_freeze(struct ipath_devdata *);
  694. struct file_operations;
  695. int ipath_cdev_init(int minor, char *name, const struct file_operations *fops,
  696. struct cdev **cdevp, struct class_device **class_devp);
  697. void ipath_cdev_cleanup(struct cdev **cdevp,
  698. struct class_device **class_devp);
  699. int ipath_diag_add(struct ipath_devdata *);
  700. void ipath_diag_remove(struct ipath_devdata *);
  701. extern wait_queue_head_t ipath_state_wait;
  702. int ipath_user_add(struct ipath_devdata *dd);
  703. void ipath_user_remove(struct ipath_devdata *dd);
  704. struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
  705. extern int ipath_diag_inuse;
  706. irqreturn_t ipath_intr(int irq, void *devid);
  707. int ipath_decode_err(char *buf, size_t blen, ipath_err_t err);
  708. #if __IPATH_INFO || __IPATH_DBG
  709. extern const char *ipath_ibcstatus_str[];
  710. #endif
  711. /* clean up any per-chip chip-specific stuff */
  712. void ipath_chip_cleanup(struct ipath_devdata *);
  713. /* clean up any chip type-specific stuff */
  714. void ipath_chip_done(void);
  715. /* check to see if we have to force ordering for write combining */
  716. int ipath_unordered_wc(void);
  717. void ipath_disarm_piobufs(struct ipath_devdata *, unsigned first,
  718. unsigned cnt);
  719. void ipath_cancel_sends(struct ipath_devdata *, int);
  720. int ipath_create_rcvhdrq(struct ipath_devdata *, struct ipath_portdata *);
  721. void ipath_free_pddata(struct ipath_devdata *, struct ipath_portdata *);
  722. int ipath_parse_ushort(const char *str, unsigned short *valp);
  723. void ipath_kreceive(struct ipath_portdata *);
  724. int ipath_setrcvhdrsize(struct ipath_devdata *, unsigned);
  725. int ipath_reset_device(int);
  726. void ipath_get_faststats(unsigned long);
  727. int ipath_wait_linkstate(struct ipath_devdata *, u32, int);
  728. int ipath_set_linkstate(struct ipath_devdata *, u8);
  729. int ipath_set_mtu(struct ipath_devdata *, u16);
  730. int ipath_set_lid(struct ipath_devdata *, u32, u8);
  731. int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv);
  732. void ipath_enable_armlaunch(struct ipath_devdata *);
  733. void ipath_disable_armlaunch(struct ipath_devdata *);
  734. void ipath_hol_down(struct ipath_devdata *);
  735. void ipath_hol_up(struct ipath_devdata *);
  736. void ipath_hol_event(unsigned long);
  737. /* for use in system calls, where we want to know device type, etc. */
  738. #define port_fp(fp) ((struct ipath_filedata *)(fp)->private_data)->pd
  739. #define subport_fp(fp) \
  740. ((struct ipath_filedata *)(fp)->private_data)->subport
  741. #define tidcursor_fp(fp) \
  742. ((struct ipath_filedata *)(fp)->private_data)->tidcursor
  743. /*
  744. * values for ipath_flags
  745. */
  746. /* chip can report link latency (IB 1.2) */
  747. #define IPATH_HAS_LINK_LATENCY 0x1
  748. /* The chip is up and initted */
  749. #define IPATH_INITTED 0x2
  750. /* set if any user code has set kr_rcvhdrsize */
  751. #define IPATH_RCVHDRSZ_SET 0x4
  752. /* The chip is present and valid for accesses */
  753. #define IPATH_PRESENT 0x8
  754. /* HT link0 is only 8 bits wide, ignore upper byte crc
  755. * errors, etc. */
  756. #define IPATH_8BIT_IN_HT0 0x10
  757. /* HT link1 is only 8 bits wide, ignore upper byte crc
  758. * errors, etc. */
  759. #define IPATH_8BIT_IN_HT1 0x20
  760. /* The link is down */
  761. #define IPATH_LINKDOWN 0x40
  762. /* The link level is up (0x11) */
  763. #define IPATH_LINKINIT 0x80
  764. /* The link is in the armed (0x21) state */
  765. #define IPATH_LINKARMED 0x100
  766. /* The link is in the active (0x31) state */
  767. #define IPATH_LINKACTIVE 0x200
  768. /* link current state is unknown */
  769. #define IPATH_LINKUNK 0x400
  770. /* Write combining flush needed for PIO */
  771. #define IPATH_PIO_FLUSH_WC 0x1000
  772. /* DMA Receive tail pointer */
  773. #define IPATH_NODMA_RTAIL 0x2000
  774. /* no IB cable, or no device on IB cable */
  775. #define IPATH_NOCABLE 0x4000
  776. /* Supports port zero per packet receive interrupts via
  777. * GPIO */
  778. #define IPATH_GPIO_INTR 0x8000
  779. /* uses the coded 4byte TID, not 8 byte */
  780. #define IPATH_4BYTE_TID 0x10000
  781. /* packet/word counters are 32 bit, else those 4 counters
  782. * are 64bit */
  783. #define IPATH_32BITCOUNTERS 0x20000
  784. /* Interrupt register is 64 bits */
  785. #define IPATH_INTREG_64 0x40000
  786. /* can miss port0 rx interrupts */
  787. #define IPATH_DISABLED 0x80000 /* administratively disabled */
  788. /* Use GPIO interrupts for new counters */
  789. #define IPATH_GPIO_ERRINTRS 0x100000
  790. #define IPATH_SWAP_PIOBUFS 0x200000
  791. /* Suppress heartbeat, even if turning off loopback */
  792. #define IPATH_NO_HRTBT 0x1000000
  793. #define IPATH_HAS_MULT_IB_SPEED 0x8000000
  794. /* Linkdown-disable intentionally, Do not attempt to bring up */
  795. #define IPATH_IB_LINK_DISABLED 0x40000000
  796. #define IPATH_IB_FORCE_NOTIFY 0x80000000 /* force notify on next ib change */
  797. /* Bits in GPIO for the added interrupts */
  798. #define IPATH_GPIO_PORT0_BIT 2
  799. #define IPATH_GPIO_RXUVL_BIT 3
  800. #define IPATH_GPIO_OVRUN_BIT 4
  801. #define IPATH_GPIO_LLI_BIT 5
  802. #define IPATH_GPIO_ERRINTR_MASK 0x38
  803. /* portdata flag bit offsets */
  804. /* waiting for a packet to arrive */
  805. #define IPATH_PORT_WAITING_RCV 2
  806. /* master has not finished initializing */
  807. #define IPATH_PORT_MASTER_UNINIT 4
  808. /* waiting for an urgent packet to arrive */
  809. #define IPATH_PORT_WAITING_URG 5
  810. /* free up any allocated data at closes */
  811. void ipath_free_data(struct ipath_portdata *dd);
  812. u32 __iomem *ipath_getpiobuf(struct ipath_devdata *, u32, u32 *);
  813. void ipath_chg_pioavailkernel(struct ipath_devdata *dd, unsigned start,
  814. unsigned len, int avail);
  815. void ipath_init_iba6120_funcs(struct ipath_devdata *);
  816. void ipath_init_iba6110_funcs(struct ipath_devdata *);
  817. void ipath_get_eeprom_info(struct ipath_devdata *);
  818. int ipath_update_eeprom_log(struct ipath_devdata *dd);
  819. void ipath_inc_eeprom_err(struct ipath_devdata *dd, u32 eidx, u32 incr);
  820. u64 ipath_snap_cntr(struct ipath_devdata *, ipath_creg);
  821. void ipath_force_pio_avail_update(struct ipath_devdata *);
  822. void signal_ib_event(struct ipath_devdata *dd, enum ib_event_type ev);
  823. /*
  824. * Set LED override, only the two LSBs have "public" meaning, but
  825. * any non-zero value substitutes them for the Link and LinkTrain
  826. * LED states.
  827. */
  828. #define IPATH_LED_PHYS 1 /* Physical (linktraining) GREEN LED */
  829. #define IPATH_LED_LOG 2 /* Logical (link) YELLOW LED */
  830. void ipath_set_led_override(struct ipath_devdata *dd, unsigned int val);
  831. /*
  832. * number of words used for protocol header if not set by ipath_userinit();
  833. */
  834. #define IPATH_DFLT_RCVHDRSIZE 9
  835. int ipath_get_user_pages(unsigned long, size_t, struct page **);
  836. void ipath_release_user_pages(struct page **, size_t);
  837. void ipath_release_user_pages_on_close(struct page **, size_t);
  838. int ipath_eeprom_read(struct ipath_devdata *, u8, void *, int);
  839. int ipath_eeprom_write(struct ipath_devdata *, u8, const void *, int);
  840. int ipath_tempsense_read(struct ipath_devdata *, u8 regnum);
  841. int ipath_tempsense_write(struct ipath_devdata *, u8 regnum, u8 data);
  842. /* these are used for the registers that vary with port */
  843. void ipath_write_kreg_port(const struct ipath_devdata *, ipath_kreg,
  844. unsigned, u64);
  845. /*
  846. * We could have a single register get/put routine, that takes a group type,
  847. * but this is somewhat clearer and cleaner. It also gives us some error
  848. * checking. 64 bit register reads should always work, but are inefficient
  849. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  850. * so we use kreg32 wherever possible. User register and counter register
  851. * reads are always 32 bit reads, so only one form of those routines.
  852. */
  853. /*
  854. * At the moment, none of the s-registers are writable, so no
  855. * ipath_write_sreg(), and none of the c-registers are writable, so no
  856. * ipath_write_creg().
  857. */
  858. /**
  859. * ipath_read_ureg32 - read 32-bit virtualized per-port register
  860. * @dd: device
  861. * @regno: register number
  862. * @port: port number
  863. *
  864. * Return the contents of a register that is virtualized to be per port.
  865. * Returns -1 on errors (not distinguishable from valid contents at
  866. * runtime; we may add a separate error variable at some point).
  867. */
  868. static inline u32 ipath_read_ureg32(const struct ipath_devdata *dd,
  869. ipath_ureg regno, int port)
  870. {
  871. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  872. return 0;
  873. return readl(regno + (u64 __iomem *)
  874. (dd->ipath_uregbase +
  875. (char __iomem *)dd->ipath_kregbase +
  876. dd->ipath_ureg_align * port));
  877. }
  878. /**
  879. * ipath_write_ureg - write 32-bit virtualized per-port register
  880. * @dd: device
  881. * @regno: register number
  882. * @value: value
  883. * @port: port
  884. *
  885. * Write the contents of a register that is virtualized to be per port.
  886. */
  887. static inline void ipath_write_ureg(const struct ipath_devdata *dd,
  888. ipath_ureg regno, u64 value, int port)
  889. {
  890. u64 __iomem *ubase = (u64 __iomem *)
  891. (dd->ipath_uregbase + (char __iomem *) dd->ipath_kregbase +
  892. dd->ipath_ureg_align * port);
  893. if (dd->ipath_kregbase)
  894. writeq(value, &ubase[regno]);
  895. }
  896. static inline u32 ipath_read_kreg32(const struct ipath_devdata *dd,
  897. ipath_kreg regno)
  898. {
  899. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  900. return -1;
  901. return readl((u32 __iomem *) & dd->ipath_kregbase[regno]);
  902. }
  903. static inline u64 ipath_read_kreg64(const struct ipath_devdata *dd,
  904. ipath_kreg regno)
  905. {
  906. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  907. return -1;
  908. return readq(&dd->ipath_kregbase[regno]);
  909. }
  910. static inline void ipath_write_kreg(const struct ipath_devdata *dd,
  911. ipath_kreg regno, u64 value)
  912. {
  913. if (dd->ipath_kregbase)
  914. writeq(value, &dd->ipath_kregbase[regno]);
  915. }
  916. static inline u64 ipath_read_creg(const struct ipath_devdata *dd,
  917. ipath_sreg regno)
  918. {
  919. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  920. return 0;
  921. return readq(regno + (u64 __iomem *)
  922. (dd->ipath_cregbase +
  923. (char __iomem *)dd->ipath_kregbase));
  924. }
  925. static inline u32 ipath_read_creg32(const struct ipath_devdata *dd,
  926. ipath_sreg regno)
  927. {
  928. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  929. return 0;
  930. return readl(regno + (u64 __iomem *)
  931. (dd->ipath_cregbase +
  932. (char __iomem *)dd->ipath_kregbase));
  933. }
  934. static inline void ipath_write_creg(const struct ipath_devdata *dd,
  935. ipath_creg regno, u64 value)
  936. {
  937. if (dd->ipath_kregbase)
  938. writeq(value, regno + (u64 __iomem *)
  939. (dd->ipath_cregbase +
  940. (char __iomem *)dd->ipath_kregbase));
  941. }
  942. static inline void ipath_clear_rcvhdrtail(const struct ipath_portdata *pd)
  943. {
  944. *((u64 *) pd->port_rcvhdrtail_kvaddr) = 0ULL;
  945. }
  946. static inline u32 ipath_get_rcvhdrtail(const struct ipath_portdata *pd)
  947. {
  948. return (u32) le64_to_cpu(*((volatile __le64 *)
  949. pd->port_rcvhdrtail_kvaddr));
  950. }
  951. static inline u32 ipath_get_hdrqtail(const struct ipath_portdata *pd)
  952. {
  953. const struct ipath_devdata *dd = pd->port_dd;
  954. u32 hdrqtail;
  955. if (dd->ipath_flags & IPATH_NODMA_RTAIL) {
  956. __le32 *rhf_addr;
  957. u32 seq;
  958. rhf_addr = (__le32 *) pd->port_rcvhdrq +
  959. pd->port_head + dd->ipath_rhf_offset;
  960. seq = ipath_hdrget_seq(rhf_addr);
  961. hdrqtail = pd->port_head;
  962. if (seq == pd->port_seq_cnt)
  963. hdrqtail++;
  964. } else
  965. hdrqtail = ipath_get_rcvhdrtail(pd);
  966. return hdrqtail;
  967. }
  968. static inline u64 ipath_read_ireg(const struct ipath_devdata *dd, ipath_kreg r)
  969. {
  970. return (dd->ipath_flags & IPATH_INTREG_64) ?
  971. ipath_read_kreg64(dd, r) : ipath_read_kreg32(dd, r);
  972. }
  973. /*
  974. * from contents of IBCStatus (or a saved copy), return linkstate
  975. * Report ACTIVE_DEFER as ACTIVE, because we treat them the same
  976. * everywhere, anyway (and should be, for almost all purposes).
  977. */
  978. static inline u32 ipath_ib_linkstate(struct ipath_devdata *dd, u64 ibcs)
  979. {
  980. u32 state = (u32)(ibcs >> dd->ibcs_ls_shift) &
  981. INFINIPATH_IBCS_LINKSTATE_MASK;
  982. if (state == INFINIPATH_IBCS_L_STATE_ACT_DEFER)
  983. state = INFINIPATH_IBCS_L_STATE_ACTIVE;
  984. return state;
  985. }
  986. /* from contents of IBCStatus (or a saved copy), return linktrainingstate */
  987. static inline u32 ipath_ib_linktrstate(struct ipath_devdata *dd, u64 ibcs)
  988. {
  989. return (u32)(ibcs >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
  990. dd->ibcs_lts_mask;
  991. }
  992. /*
  993. * from contents of IBCStatus (or a saved copy), return logical link state
  994. * combination of link state and linktraining state (down, active, init,
  995. * arm, etc.
  996. */
  997. static inline u32 ipath_ib_state(struct ipath_devdata *dd, u64 ibcs)
  998. {
  999. u32 ibs;
  1000. ibs = (u32)(ibcs >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
  1001. dd->ibcs_lts_mask;
  1002. ibs |= (u32)(ibcs &
  1003. (INFINIPATH_IBCS_LINKSTATE_MASK << dd->ibcs_ls_shift));
  1004. return ibs;
  1005. }
  1006. /*
  1007. * sysfs interface.
  1008. */
  1009. struct device_driver;
  1010. extern const char ib_ipath_version[];
  1011. extern struct attribute_group *ipath_driver_attr_groups[];
  1012. int ipath_device_create_group(struct device *, struct ipath_devdata *);
  1013. void ipath_device_remove_group(struct device *, struct ipath_devdata *);
  1014. int ipath_expose_reset(struct device *);
  1015. int ipath_init_ipathfs(void);
  1016. void ipath_exit_ipathfs(void);
  1017. int ipathfs_add_device(struct ipath_devdata *);
  1018. int ipathfs_remove_device(struct ipath_devdata *);
  1019. /*
  1020. * dma_addr wrappers - all 0's invalid for hw
  1021. */
  1022. dma_addr_t ipath_map_page(struct pci_dev *, struct page *, unsigned long,
  1023. size_t, int);
  1024. dma_addr_t ipath_map_single(struct pci_dev *, void *, size_t, int);
  1025. /*
  1026. * Flush write combining store buffers (if present) and perform a write
  1027. * barrier.
  1028. */
  1029. #if defined(CONFIG_X86_64)
  1030. #define ipath_flush_wc() asm volatile("sfence" ::: "memory")
  1031. #else
  1032. #define ipath_flush_wc() wmb()
  1033. #endif
  1034. extern unsigned ipath_debug; /* debugging bit mask */
  1035. extern unsigned ipath_linkrecovery;
  1036. extern unsigned ipath_mtu4096;
  1037. #define IPATH_MAX_PARITY_ATTEMPTS 10000 /* max times to try recovery */
  1038. const char *ipath_get_unit_name(int unit);
  1039. extern struct mutex ipath_mutex;
  1040. #define IPATH_DRV_NAME "ib_ipath"
  1041. #define IPATH_MAJOR 233
  1042. #define IPATH_USER_MINOR_BASE 0
  1043. #define IPATH_DIAGPKT_MINOR 127
  1044. #define IPATH_DIAG_MINOR_BASE 129
  1045. #define IPATH_NMINORS 255
  1046. #define ipath_dev_err(dd,fmt,...) \
  1047. do { \
  1048. const struct ipath_devdata *__dd = (dd); \
  1049. if (__dd->pcidev) \
  1050. dev_err(&__dd->pcidev->dev, "%s: " fmt, \
  1051. ipath_get_unit_name(__dd->ipath_unit), \
  1052. ##__VA_ARGS__); \
  1053. else \
  1054. printk(KERN_ERR IPATH_DRV_NAME ": %s: " fmt, \
  1055. ipath_get_unit_name(__dd->ipath_unit), \
  1056. ##__VA_ARGS__); \
  1057. } while (0)
  1058. #if _IPATH_DEBUGGING
  1059. # define __IPATH_DBG_WHICH(which,fmt,...) \
  1060. do { \
  1061. if (unlikely(ipath_debug & (which))) \
  1062. printk(KERN_DEBUG IPATH_DRV_NAME ": %s: " fmt, \
  1063. __func__,##__VA_ARGS__); \
  1064. } while(0)
  1065. # define ipath_dbg(fmt,...) \
  1066. __IPATH_DBG_WHICH(__IPATH_DBG,fmt,##__VA_ARGS__)
  1067. # define ipath_cdbg(which,fmt,...) \
  1068. __IPATH_DBG_WHICH(__IPATH_##which##DBG,fmt,##__VA_ARGS__)
  1069. #else /* ! _IPATH_DEBUGGING */
  1070. # define ipath_dbg(fmt,...)
  1071. # define ipath_cdbg(which,fmt,...)
  1072. #endif /* _IPATH_DEBUGGING */
  1073. /*
  1074. * this is used for formatting hw error messages...
  1075. */
  1076. struct ipath_hwerror_msgs {
  1077. u64 mask;
  1078. const char *msg;
  1079. };
  1080. #define INFINIPATH_HWE_MSG(a, b) { .mask = INFINIPATH_HWE_##a, .msg = b }
  1081. /* in ipath_intr.c... */
  1082. void ipath_format_hwerrors(u64 hwerrs,
  1083. const struct ipath_hwerror_msgs *hwerrmsgs,
  1084. size_t nhwerrmsgs,
  1085. char *msg, size_t lmsg);
  1086. #endif /* _IPATH_KERNEL_H */