ipath_kernel.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  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. };
  171. struct sk_buff;
  172. /*
  173. * control information for layered drivers
  174. */
  175. struct _ipath_layer {
  176. void *l_arg;
  177. };
  178. struct ipath_skbinfo {
  179. struct sk_buff *skb;
  180. dma_addr_t phys;
  181. };
  182. /*
  183. * Possible IB config parameters for ipath_f_get/set_ib_cfg()
  184. */
  185. #define IPATH_IB_CFG_LIDLMC 0 /* Get/set LID (LS16b) and Mask (MS16b) */
  186. #define IPATH_IB_CFG_HRTBT 1 /* Get/set Heartbeat off/enable/auto */
  187. #define IPATH_IB_HRTBT_ON 3 /* Heartbeat enabled, sent every 100msec */
  188. #define IPATH_IB_HRTBT_OFF 0 /* Heartbeat off */
  189. #define IPATH_IB_CFG_LWID_ENB 2 /* Get/set allowed Link-width */
  190. #define IPATH_IB_CFG_LWID 3 /* Get currently active Link-width */
  191. #define IPATH_IB_CFG_SPD_ENB 4 /* Get/set allowed Link speeds */
  192. #define IPATH_IB_CFG_SPD 5 /* Get current Link spd */
  193. #define IPATH_IB_CFG_RXPOL_ENB 6 /* Get/set Auto-RX-polarity enable */
  194. #define IPATH_IB_CFG_LREV_ENB 7 /* Get/set Auto-Lane-reversal enable */
  195. #define IPATH_IB_CFG_LINKLATENCY 8 /* Get Auto-Lane-reversal enable */
  196. struct ipath_devdata {
  197. struct list_head ipath_list;
  198. struct ipath_kregs const *ipath_kregs;
  199. struct ipath_cregs const *ipath_cregs;
  200. /* mem-mapped pointer to base of chip regs */
  201. u64 __iomem *ipath_kregbase;
  202. /* end of mem-mapped chip space; range checking */
  203. u64 __iomem *ipath_kregend;
  204. /* physical address of chip for io_remap, etc. */
  205. unsigned long ipath_physaddr;
  206. /* base of memory alloced for ipath_kregbase, for free */
  207. u64 *ipath_kregalloc;
  208. /*
  209. * virtual address where port0 rcvhdrqtail updated for this unit.
  210. * only written to by the chip, not the driver.
  211. */
  212. volatile __le64 *ipath_hdrqtailptr;
  213. /* ipath_cfgports pointers */
  214. struct ipath_portdata **ipath_pd;
  215. /* sk_buffs used by port 0 eager receive queue */
  216. struct ipath_skbinfo *ipath_port0_skbinfo;
  217. /* kvirt address of 1st 2k pio buffer */
  218. void __iomem *ipath_pio2kbase;
  219. /* kvirt address of 1st 4k pio buffer */
  220. void __iomem *ipath_pio4kbase;
  221. /*
  222. * points to area where PIOavail registers will be DMA'ed.
  223. * Has to be on a page of it's own, because the page will be
  224. * mapped into user program space. This copy is *ONLY* ever
  225. * written by DMA, not by the driver! Need a copy per device
  226. * when we get to multiple devices
  227. */
  228. volatile __le64 *ipath_pioavailregs_dma;
  229. /* physical address where updates occur */
  230. dma_addr_t ipath_pioavailregs_phys;
  231. struct _ipath_layer ipath_layer;
  232. /* setup intr */
  233. int (*ipath_f_intrsetup)(struct ipath_devdata *);
  234. /* fallback to alternate interrupt type if possible */
  235. int (*ipath_f_intr_fallback)(struct ipath_devdata *);
  236. /* setup on-chip bus config */
  237. int (*ipath_f_bus)(struct ipath_devdata *, struct pci_dev *);
  238. /* hard reset chip */
  239. int (*ipath_f_reset)(struct ipath_devdata *);
  240. int (*ipath_f_get_boardname)(struct ipath_devdata *, char *,
  241. size_t);
  242. void (*ipath_f_init_hwerrors)(struct ipath_devdata *);
  243. void (*ipath_f_handle_hwerrors)(struct ipath_devdata *, char *,
  244. size_t);
  245. void (*ipath_f_quiet_serdes)(struct ipath_devdata *);
  246. int (*ipath_f_bringup_serdes)(struct ipath_devdata *);
  247. int (*ipath_f_early_init)(struct ipath_devdata *);
  248. void (*ipath_f_clear_tids)(struct ipath_devdata *, unsigned);
  249. void (*ipath_f_put_tid)(struct ipath_devdata *, u64 __iomem*,
  250. u32, unsigned long);
  251. void (*ipath_f_tidtemplate)(struct ipath_devdata *);
  252. void (*ipath_f_cleanup)(struct ipath_devdata *);
  253. void (*ipath_f_setextled)(struct ipath_devdata *, u64, u64);
  254. /* fill out chip-specific fields */
  255. int (*ipath_f_get_base_info)(struct ipath_portdata *, void *);
  256. /* free irq */
  257. void (*ipath_f_free_irq)(struct ipath_devdata *);
  258. struct ipath_message_header *(*ipath_f_get_msgheader)
  259. (struct ipath_devdata *, __le32 *);
  260. void (*ipath_f_config_ports)(struct ipath_devdata *, ushort);
  261. int (*ipath_f_get_ib_cfg)(struct ipath_devdata *, int);
  262. int (*ipath_f_set_ib_cfg)(struct ipath_devdata *, int, u32);
  263. void (*ipath_f_config_jint)(struct ipath_devdata *, u16 , u16);
  264. void (*ipath_f_read_counters)(struct ipath_devdata *,
  265. struct infinipath_counters *);
  266. void (*ipath_f_xgxs_reset)(struct ipath_devdata *);
  267. /* per chip actions needed for IB Link up/down changes */
  268. int (*ipath_f_ib_updown)(struct ipath_devdata *, int, u64);
  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. /* time in jiffies at which to re-enable maskederrs */
  296. unsigned long ipath_unmasktime;
  297. /* count of egrfull errors, combined for all ports */
  298. u64 ipath_last_tidfull;
  299. /* for ipath_qcheck() */
  300. u64 ipath_lastport0rcv_cnt;
  301. /* template for writing TIDs */
  302. u64 ipath_tidtemplate;
  303. /* value to write to free TIDs */
  304. u64 ipath_tidinvalid;
  305. /* IBA6120 rcv interrupt setup */
  306. u64 ipath_rhdrhead_intr_off;
  307. /* size of memory at ipath_kregbase */
  308. u32 ipath_kregsize;
  309. /* number of registers used for pioavail */
  310. u32 ipath_pioavregs;
  311. /* IPATH_POLL, etc. */
  312. u32 ipath_flags;
  313. /* ipath_flags driver is waiting for */
  314. u32 ipath_state_wanted;
  315. /* last buffer for user use, first buf for kernel use is this
  316. * index. */
  317. u32 ipath_lastport_piobuf;
  318. /* is a stats timer active */
  319. u32 ipath_stats_timer_active;
  320. /* number of interrupts for this device -- saturates... */
  321. u32 ipath_int_counter;
  322. /* dwords sent read from counter */
  323. u32 ipath_lastsword;
  324. /* dwords received read from counter */
  325. u32 ipath_lastrword;
  326. /* sent packets read from counter */
  327. u32 ipath_lastspkts;
  328. /* received packets read from counter */
  329. u32 ipath_lastrpkts;
  330. /* pio bufs allocated per port */
  331. u32 ipath_pbufsport;
  332. /*
  333. * number of ports configured as max; zero is set to number chip
  334. * supports, less gives more pio bufs/port, etc.
  335. */
  336. u32 ipath_cfgports;
  337. /* count of port 0 hdrqfull errors */
  338. u32 ipath_p0_hdrqfull;
  339. /* port 0 number of receive eager buffers */
  340. u32 ipath_p0_rcvegrcnt;
  341. /*
  342. * index of last piobuffer we used. Speeds up searching, by
  343. * starting at this point. Doesn't matter if multiple cpu's use and
  344. * update, last updater is only write that matters. Whenever it
  345. * wraps, we update shadow copies. Need a copy per device when we
  346. * get to multiple devices
  347. */
  348. u32 ipath_lastpioindex;
  349. /* max length of freezemsg */
  350. u32 ipath_freezelen;
  351. /*
  352. * consecutive times we wanted a PIO buffer but were unable to
  353. * get one
  354. */
  355. u32 ipath_consec_nopiobuf;
  356. /*
  357. * hint that we should update ipath_pioavailshadow before
  358. * looking for a PIO buffer
  359. */
  360. u32 ipath_upd_pio_shadow;
  361. /* so we can rewrite it after a chip reset */
  362. u32 ipath_pcibar0;
  363. /* so we can rewrite it after a chip reset */
  364. u32 ipath_pcibar1;
  365. /* interrupt number */
  366. int ipath_irq;
  367. /* HT/PCI Vendor ID (here for NodeInfo) */
  368. u16 ipath_vendorid;
  369. /* HT/PCI Device ID (here for NodeInfo) */
  370. u16 ipath_deviceid;
  371. /* offset in HT config space of slave/primary interface block */
  372. u8 ipath_ht_slave_off;
  373. /* for write combining settings */
  374. unsigned long ipath_wc_cookie;
  375. unsigned long ipath_wc_base;
  376. unsigned long ipath_wc_len;
  377. /* ref count for each pkey */
  378. atomic_t ipath_pkeyrefs[4];
  379. /* shadow copy of struct page *'s for exp tid pages */
  380. struct page **ipath_pageshadow;
  381. /* shadow copy of dma handles for exp tid pages */
  382. dma_addr_t *ipath_physshadow;
  383. u64 __iomem *ipath_egrtidbase;
  384. /* lock to workaround chip bug 9437 and others */
  385. spinlock_t ipath_kernel_tid_lock;
  386. spinlock_t ipath_tid_lock;
  387. spinlock_t ipath_sendctrl_lock;
  388. /*
  389. * IPATH_STATUS_*,
  390. * this address is mapped readonly into user processes so they can
  391. * get status cheaply, whenever they want.
  392. */
  393. u64 *ipath_statusp;
  394. /* freeze msg if hw error put chip in freeze */
  395. char *ipath_freezemsg;
  396. /* pci access data structure */
  397. struct pci_dev *pcidev;
  398. struct cdev *user_cdev;
  399. struct cdev *diag_cdev;
  400. struct class_device *user_class_dev;
  401. struct class_device *diag_class_dev;
  402. /* timer used to prevent stats overflow, error throttling, etc. */
  403. struct timer_list ipath_stats_timer;
  404. void *ipath_dummy_hdrq; /* used after port close */
  405. dma_addr_t ipath_dummy_hdrq_phys;
  406. unsigned long ipath_ureg_align; /* user register alignment */
  407. /* HoL blocking / user app forward-progress state */
  408. unsigned ipath_hol_state;
  409. unsigned ipath_hol_next;
  410. struct timer_list ipath_hol_timer;
  411. /*
  412. * Shadow copies of registers; size indicates read access size.
  413. * Most of them are readonly, but some are write-only register,
  414. * where we manipulate the bits in the shadow copy, and then write
  415. * the shadow copy to infinipath.
  416. *
  417. * We deliberately make most of these 32 bits, since they have
  418. * restricted range. For any that we read, we won't to generate 32
  419. * bit accesses, since Opteron will generate 2 separate 32 bit HT
  420. * transactions for a 64 bit read, and we want to avoid unnecessary
  421. * HT transactions.
  422. */
  423. /* This is the 64 bit group */
  424. /*
  425. * shadow of pioavail, check to be sure it's large enough at
  426. * init time.
  427. */
  428. unsigned long ipath_pioavailshadow[8];
  429. /* shadow of kr_gpio_out, for rmw ops */
  430. u64 ipath_gpio_out;
  431. /* shadow the gpio mask register */
  432. u64 ipath_gpio_mask;
  433. /* shadow the gpio output enable, etc... */
  434. u64 ipath_extctrl;
  435. /* kr_revision shadow */
  436. u64 ipath_revision;
  437. /*
  438. * shadow of ibcctrl, for interrupt handling of link changes,
  439. * etc.
  440. */
  441. u64 ipath_ibcctrl;
  442. /*
  443. * last ibcstatus, to suppress "duplicate" status change messages,
  444. * mostly from 2 to 3
  445. */
  446. u64 ipath_lastibcstat;
  447. /* hwerrmask shadow */
  448. ipath_err_t ipath_hwerrmask;
  449. ipath_err_t ipath_errormask; /* errormask shadow */
  450. /* interrupt config reg shadow */
  451. u64 ipath_intconfig;
  452. /* kr_sendpiobufbase value */
  453. u64 ipath_piobufbase;
  454. /* these are the "32 bit" regs */
  455. /*
  456. * number of GUIDs in the flash for this interface; may need some
  457. * rethinking for setting on other ifaces
  458. */
  459. u32 ipath_nguid;
  460. /*
  461. * the following two are 32-bit bitmasks, but {test,clear,set}_bit
  462. * all expect bit fields to be "unsigned long"
  463. */
  464. /* shadow kr_rcvctrl */
  465. unsigned long ipath_rcvctrl;
  466. /* shadow kr_sendctrl */
  467. unsigned long ipath_sendctrl;
  468. unsigned long ipath_lastcancel; /* to not count armlaunch after cancel */
  469. /* value we put in kr_rcvhdrcnt */
  470. u32 ipath_rcvhdrcnt;
  471. /* value we put in kr_rcvhdrsize */
  472. u32 ipath_rcvhdrsize;
  473. /* value we put in kr_rcvhdrentsize */
  474. u32 ipath_rcvhdrentsize;
  475. /* offset of last entry in rcvhdrq */
  476. u32 ipath_hdrqlast;
  477. /* kr_portcnt value */
  478. u32 ipath_portcnt;
  479. /* kr_pagealign value */
  480. u32 ipath_palign;
  481. /* number of "2KB" PIO buffers */
  482. u32 ipath_piobcnt2k;
  483. /* size in bytes of "2KB" PIO buffers */
  484. u32 ipath_piosize2k;
  485. /* number of "4KB" PIO buffers */
  486. u32 ipath_piobcnt4k;
  487. /* size in bytes of "4KB" PIO buffers */
  488. u32 ipath_piosize4k;
  489. /* kr_rcvegrbase value */
  490. u32 ipath_rcvegrbase;
  491. /* kr_rcvegrcnt value */
  492. u32 ipath_rcvegrcnt;
  493. /* kr_rcvtidbase value */
  494. u32 ipath_rcvtidbase;
  495. /* kr_rcvtidcnt value */
  496. u32 ipath_rcvtidcnt;
  497. /* kr_sendregbase */
  498. u32 ipath_sregbase;
  499. /* kr_userregbase */
  500. u32 ipath_uregbase;
  501. /* kr_counterregbase */
  502. u32 ipath_cregbase;
  503. /* shadow the control register contents */
  504. u32 ipath_control;
  505. /* PCI revision register (HTC rev on FPGA) */
  506. u32 ipath_pcirev;
  507. /* chip address space used by 4k pio buffers */
  508. u32 ipath_4kalign;
  509. /* The MTU programmed for this unit */
  510. u32 ipath_ibmtu;
  511. /*
  512. * The max size IB packet, included IB headers that we can send.
  513. * Starts same as ipath_piosize, but is affected when ibmtu is
  514. * changed, or by size of eager buffers
  515. */
  516. u32 ipath_ibmaxlen;
  517. /*
  518. * ibmaxlen at init time, limited by chip and by receive buffer
  519. * size. Not changed after init.
  520. */
  521. u32 ipath_init_ibmaxlen;
  522. /* size of each rcvegrbuffer */
  523. u32 ipath_rcvegrbufsize;
  524. /* localbus width (1, 2,4,8,16,32) from config space */
  525. u32 ipath_lbus_width;
  526. /* localbus speed (HT: 200,400,800,1000; PCIe 2500) */
  527. u32 ipath_lbus_speed;
  528. /*
  529. * number of sequential ibcstatus change for polling active/quiet
  530. * (i.e., link not coming up).
  531. */
  532. u32 ipath_ibpollcnt;
  533. /* low and high portions of MSI capability/vector */
  534. u32 ipath_msi_lo;
  535. /* saved after PCIe init for restore after reset */
  536. u32 ipath_msi_hi;
  537. /* MSI data (vector) saved for restore */
  538. u16 ipath_msi_data;
  539. /* MLID programmed for this instance */
  540. u16 ipath_mlid;
  541. /* LID programmed for this instance */
  542. u16 ipath_lid;
  543. /* list of pkeys programmed; 0 if not set */
  544. u16 ipath_pkeys[4];
  545. /*
  546. * ASCII serial number, from flash, large enough for original
  547. * all digit strings, and longer QLogic serial number format
  548. */
  549. u8 ipath_serial[16];
  550. /* human readable board version */
  551. u8 ipath_boardversion[80];
  552. u8 ipath_lbus_info[32]; /* human readable localbus info */
  553. /* chip major rev, from ipath_revision */
  554. u8 ipath_majrev;
  555. /* chip minor rev, from ipath_revision */
  556. u8 ipath_minrev;
  557. /* board rev, from ipath_revision */
  558. u8 ipath_boardrev;
  559. u8 ipath_r_portenable_shift;
  560. u8 ipath_r_intravail_shift;
  561. u8 ipath_r_tailupd_shift;
  562. u8 ipath_r_portcfg_shift;
  563. /* unit # of this chip, if present */
  564. int ipath_unit;
  565. /* saved for restore after reset */
  566. u8 ipath_pci_cacheline;
  567. /* LID mask control */
  568. u8 ipath_lmc;
  569. /* link width supported */
  570. u8 ipath_link_width_supported;
  571. /* link speed supported */
  572. u8 ipath_link_speed_supported;
  573. u8 ipath_link_width_enabled;
  574. u8 ipath_link_speed_enabled;
  575. u8 ipath_link_width_active;
  576. u8 ipath_link_speed_active;
  577. /* Rx Polarity inversion (compensate for ~tx on partner) */
  578. u8 ipath_rx_pol_inv;
  579. /* local link integrity counter */
  580. u32 ipath_lli_counter;
  581. /* local link integrity errors */
  582. u32 ipath_lli_errors;
  583. /*
  584. * Above counts only cases where _successive_ LocalLinkIntegrity
  585. * errors were seen in the receive headers of kern-packets.
  586. * Below are the three (monotonically increasing) counters
  587. * maintained via GPIO interrupts on iba6120-rev2.
  588. */
  589. u32 ipath_rxfc_unsupvl_errs;
  590. u32 ipath_overrun_thresh_errs;
  591. u32 ipath_lli_errs;
  592. /* status check work */
  593. struct delayed_work status_work;
  594. /*
  595. * Not all devices managed by a driver instance are the same
  596. * type, so these fields must be per-device.
  597. */
  598. u64 ipath_i_bitsextant;
  599. ipath_err_t ipath_e_bitsextant;
  600. ipath_err_t ipath_hwe_bitsextant;
  601. /*
  602. * Below should be computable from number of ports,
  603. * since they are never modified.
  604. */
  605. u32 ipath_i_rcvavail_mask;
  606. u32 ipath_i_rcvurg_mask;
  607. u16 ipath_i_rcvurg_shift;
  608. u16 ipath_i_rcvavail_shift;
  609. /*
  610. * Register bits for selecting i2c direction and values, used for
  611. * I2C serial flash.
  612. */
  613. u16 ipath_gpio_sda_num;
  614. u16 ipath_gpio_scl_num;
  615. u64 ipath_gpio_sda;
  616. u64 ipath_gpio_scl;
  617. /* lock for doing RMW of shadows/regs for ExtCtrl and GPIO */
  618. spinlock_t ipath_gpio_lock;
  619. /*
  620. * IB link and linktraining states and masks that vary per chip in
  621. * some way. Set at init, to avoid each IB status change interrupt
  622. */
  623. u8 ibcs_ls_shift;
  624. u8 ibcs_lts_mask;
  625. u32 ibcs_mask;
  626. u32 ib_init;
  627. u32 ib_arm;
  628. u32 ib_active;
  629. u16 ipath_rhf_offset; /* offset of RHF within receive header entry */
  630. /*
  631. * shift/mask for linkcmd, linkinitcmd, maxpktlen in ibccontol
  632. * reg. Changes for IBA7220
  633. */
  634. u8 ibcc_lic_mask; /* LinkInitCmd */
  635. u8 ibcc_lc_shift; /* LinkCmd */
  636. u8 ibcc_mpl_shift; /* Maxpktlen */
  637. u8 delay_mult;
  638. /* used to override LED behavior */
  639. u8 ipath_led_override; /* Substituted for normal value, if non-zero */
  640. u16 ipath_led_override_timeoff; /* delta to next timer event */
  641. u8 ipath_led_override_vals[2]; /* Alternates per blink-frame */
  642. u8 ipath_led_override_phase; /* Just counts, LSB picks from vals[] */
  643. atomic_t ipath_led_override_timer_active;
  644. /* Used to flash LEDs in override mode */
  645. struct timer_list ipath_led_override_timer;
  646. /* Support (including locks) for EEPROM logging of errors and time */
  647. /* control access to actual counters, timer */
  648. spinlock_t ipath_eep_st_lock;
  649. /* control high-level access to EEPROM */
  650. struct mutex ipath_eep_lock;
  651. /* Below inc'd by ipath_snap_cntrs(), locked by ipath_eep_st_lock */
  652. uint64_t ipath_traffic_wds;
  653. /* active time is kept in seconds, but logged in hours */
  654. atomic_t ipath_active_time;
  655. /* Below are nominal shadow of EEPROM, new since last EEPROM update */
  656. uint8_t ipath_eep_st_errs[IPATH_EEP_LOG_CNT];
  657. uint8_t ipath_eep_st_new_errs[IPATH_EEP_LOG_CNT];
  658. uint16_t ipath_eep_hrs;
  659. /*
  660. * masks for which bits of errs, hwerrs that cause
  661. * each of the counters to increment.
  662. */
  663. struct ipath_eep_log_mask ipath_eep_st_masks[IPATH_EEP_LOG_CNT];
  664. /* interrupt mitigation reload register info */
  665. u16 ipath_jint_idle_ticks; /* idle clock ticks */
  666. u16 ipath_jint_max_packets; /* max packets across all ports */
  667. };
  668. /* ipath_hol_state values (stopping/starting user proc, send flushing) */
  669. #define IPATH_HOL_UP 0
  670. #define IPATH_HOL_DOWN 1
  671. /* ipath_hol_next toggle values, used when hol_state IPATH_HOL_DOWN */
  672. #define IPATH_HOL_DOWNSTOP 0
  673. #define IPATH_HOL_DOWNCONT 1
  674. /* Private data for file operations */
  675. struct ipath_filedata {
  676. struct ipath_portdata *pd;
  677. unsigned subport;
  678. unsigned tidcursor;
  679. };
  680. extern struct list_head ipath_dev_list;
  681. extern spinlock_t ipath_devs_lock;
  682. extern struct ipath_devdata *ipath_lookup(int unit);
  683. int ipath_init_chip(struct ipath_devdata *, int);
  684. int ipath_enable_wc(struct ipath_devdata *dd);
  685. void ipath_disable_wc(struct ipath_devdata *dd);
  686. int ipath_count_units(int *npresentp, int *nupp, int *maxportsp);
  687. void ipath_shutdown_device(struct ipath_devdata *);
  688. void ipath_clear_freeze(struct ipath_devdata *);
  689. struct file_operations;
  690. int ipath_cdev_init(int minor, char *name, const struct file_operations *fops,
  691. struct cdev **cdevp, struct class_device **class_devp);
  692. void ipath_cdev_cleanup(struct cdev **cdevp,
  693. struct class_device **class_devp);
  694. int ipath_diag_add(struct ipath_devdata *);
  695. void ipath_diag_remove(struct ipath_devdata *);
  696. extern wait_queue_head_t ipath_state_wait;
  697. int ipath_user_add(struct ipath_devdata *dd);
  698. void ipath_user_remove(struct ipath_devdata *dd);
  699. struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
  700. extern int ipath_diag_inuse;
  701. irqreturn_t ipath_intr(int irq, void *devid);
  702. int ipath_decode_err(char *buf, size_t blen, ipath_err_t err);
  703. #if __IPATH_INFO || __IPATH_DBG
  704. extern const char *ipath_ibcstatus_str[];
  705. #endif
  706. /* clean up any per-chip chip-specific stuff */
  707. void ipath_chip_cleanup(struct ipath_devdata *);
  708. /* clean up any chip type-specific stuff */
  709. void ipath_chip_done(void);
  710. /* check to see if we have to force ordering for write combining */
  711. int ipath_unordered_wc(void);
  712. void ipath_disarm_piobufs(struct ipath_devdata *, unsigned first,
  713. unsigned cnt);
  714. void ipath_cancel_sends(struct ipath_devdata *, int);
  715. int ipath_create_rcvhdrq(struct ipath_devdata *, struct ipath_portdata *);
  716. void ipath_free_pddata(struct ipath_devdata *, struct ipath_portdata *);
  717. int ipath_parse_ushort(const char *str, unsigned short *valp);
  718. void ipath_kreceive(struct ipath_portdata *);
  719. int ipath_setrcvhdrsize(struct ipath_devdata *, unsigned);
  720. int ipath_reset_device(int);
  721. void ipath_get_faststats(unsigned long);
  722. int ipath_wait_linkstate(struct ipath_devdata *, u32, int);
  723. int ipath_set_linkstate(struct ipath_devdata *, u8);
  724. int ipath_set_mtu(struct ipath_devdata *, u16);
  725. int ipath_set_lid(struct ipath_devdata *, u32, u8);
  726. int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv);
  727. void ipath_enable_armlaunch(struct ipath_devdata *);
  728. void ipath_disable_armlaunch(struct ipath_devdata *);
  729. void ipath_hol_down(struct ipath_devdata *);
  730. void ipath_hol_up(struct ipath_devdata *);
  731. void ipath_hol_event(unsigned long);
  732. /* for use in system calls, where we want to know device type, etc. */
  733. #define port_fp(fp) ((struct ipath_filedata *)(fp)->private_data)->pd
  734. #define subport_fp(fp) \
  735. ((struct ipath_filedata *)(fp)->private_data)->subport
  736. #define tidcursor_fp(fp) \
  737. ((struct ipath_filedata *)(fp)->private_data)->tidcursor
  738. /*
  739. * values for ipath_flags
  740. */
  741. /* chip can report link latency (IB 1.2) */
  742. #define IPATH_HAS_LINK_LATENCY 0x1
  743. /* The chip is up and initted */
  744. #define IPATH_INITTED 0x2
  745. /* set if any user code has set kr_rcvhdrsize */
  746. #define IPATH_RCVHDRSZ_SET 0x4
  747. /* The chip is present and valid for accesses */
  748. #define IPATH_PRESENT 0x8
  749. /* HT link0 is only 8 bits wide, ignore upper byte crc
  750. * errors, etc. */
  751. #define IPATH_8BIT_IN_HT0 0x10
  752. /* HT link1 is only 8 bits wide, ignore upper byte crc
  753. * errors, etc. */
  754. #define IPATH_8BIT_IN_HT1 0x20
  755. /* The link is down */
  756. #define IPATH_LINKDOWN 0x40
  757. /* The link level is up (0x11) */
  758. #define IPATH_LINKINIT 0x80
  759. /* The link is in the armed (0x21) state */
  760. #define IPATH_LINKARMED 0x100
  761. /* The link is in the active (0x31) state */
  762. #define IPATH_LINKACTIVE 0x200
  763. /* link current state is unknown */
  764. #define IPATH_LINKUNK 0x400
  765. /* Write combining flush needed for PIO */
  766. #define IPATH_PIO_FLUSH_WC 0x1000
  767. /* no IB cable, or no device on IB cable */
  768. #define IPATH_NOCABLE 0x4000
  769. /* Supports port zero per packet receive interrupts via
  770. * GPIO */
  771. #define IPATH_GPIO_INTR 0x8000
  772. /* uses the coded 4byte TID, not 8 byte */
  773. #define IPATH_4BYTE_TID 0x10000
  774. /* packet/word counters are 32 bit, else those 4 counters
  775. * are 64bit */
  776. #define IPATH_32BITCOUNTERS 0x20000
  777. /* can miss port0 rx interrupts */
  778. /* Interrupt register is 64 bits */
  779. #define IPATH_INTREG_64 0x40000
  780. #define IPATH_DISABLED 0x80000 /* administratively disabled */
  781. /* Use GPIO interrupts for new counters */
  782. #define IPATH_GPIO_ERRINTRS 0x100000
  783. #define IPATH_SWAP_PIOBUFS 0x200000
  784. /* Suppress heartbeat, even if turning off loopback */
  785. #define IPATH_NO_HRTBT 0x1000000
  786. #define IPATH_HAS_MULT_IB_SPEED 0x8000000
  787. #define IPATH_IB_FORCE_NOTIFY 0x80000000 /* force notify on next ib change */
  788. /* Bits in GPIO for the added interrupts */
  789. #define IPATH_GPIO_PORT0_BIT 2
  790. #define IPATH_GPIO_RXUVL_BIT 3
  791. #define IPATH_GPIO_OVRUN_BIT 4
  792. #define IPATH_GPIO_LLI_BIT 5
  793. #define IPATH_GPIO_ERRINTR_MASK 0x38
  794. /* portdata flag bit offsets */
  795. /* waiting for a packet to arrive */
  796. #define IPATH_PORT_WAITING_RCV 2
  797. /* master has not finished initializing */
  798. #define IPATH_PORT_MASTER_UNINIT 4
  799. /* waiting for an urgent packet to arrive */
  800. #define IPATH_PORT_WAITING_URG 5
  801. /* free up any allocated data at closes */
  802. void ipath_free_data(struct ipath_portdata *dd);
  803. u32 __iomem *ipath_getpiobuf(struct ipath_devdata *, u32 *);
  804. void ipath_init_iba6120_funcs(struct ipath_devdata *);
  805. void ipath_init_iba6110_funcs(struct ipath_devdata *);
  806. void ipath_get_eeprom_info(struct ipath_devdata *);
  807. int ipath_update_eeprom_log(struct ipath_devdata *dd);
  808. void ipath_inc_eeprom_err(struct ipath_devdata *dd, u32 eidx, u32 incr);
  809. u64 ipath_snap_cntr(struct ipath_devdata *, ipath_creg);
  810. void signal_ib_event(struct ipath_devdata *dd, enum ib_event_type ev);
  811. /*
  812. * Set LED override, only the two LSBs have "public" meaning, but
  813. * any non-zero value substitutes them for the Link and LinkTrain
  814. * LED states.
  815. */
  816. #define IPATH_LED_PHYS 1 /* Physical (linktraining) GREEN LED */
  817. #define IPATH_LED_LOG 2 /* Logical (link) YELLOW LED */
  818. void ipath_set_led_override(struct ipath_devdata *dd, unsigned int val);
  819. /*
  820. * number of words used for protocol header if not set by ipath_userinit();
  821. */
  822. #define IPATH_DFLT_RCVHDRSIZE 9
  823. int ipath_get_user_pages(unsigned long, size_t, struct page **);
  824. void ipath_release_user_pages(struct page **, size_t);
  825. void ipath_release_user_pages_on_close(struct page **, size_t);
  826. int ipath_eeprom_read(struct ipath_devdata *, u8, void *, int);
  827. int ipath_eeprom_write(struct ipath_devdata *, u8, const void *, int);
  828. /* these are used for the registers that vary with port */
  829. void ipath_write_kreg_port(const struct ipath_devdata *, ipath_kreg,
  830. unsigned, u64);
  831. /*
  832. * We could have a single register get/put routine, that takes a group type,
  833. * but this is somewhat clearer and cleaner. It also gives us some error
  834. * checking. 64 bit register reads should always work, but are inefficient
  835. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  836. * so we use kreg32 wherever possible. User register and counter register
  837. * reads are always 32 bit reads, so only one form of those routines.
  838. */
  839. /*
  840. * At the moment, none of the s-registers are writable, so no
  841. * ipath_write_sreg(), and none of the c-registers are writable, so no
  842. * ipath_write_creg().
  843. */
  844. /**
  845. * ipath_read_ureg32 - read 32-bit virtualized per-port register
  846. * @dd: device
  847. * @regno: register number
  848. * @port: port number
  849. *
  850. * Return the contents of a register that is virtualized to be per port.
  851. * Returns -1 on errors (not distinguishable from valid contents at
  852. * runtime; we may add a separate error variable at some point).
  853. */
  854. static inline u32 ipath_read_ureg32(const struct ipath_devdata *dd,
  855. ipath_ureg regno, int port)
  856. {
  857. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  858. return 0;
  859. return readl(regno + (u64 __iomem *)
  860. (dd->ipath_uregbase +
  861. (char __iomem *)dd->ipath_kregbase +
  862. dd->ipath_ureg_align * port));
  863. }
  864. /**
  865. * ipath_write_ureg - write 32-bit virtualized per-port register
  866. * @dd: device
  867. * @regno: register number
  868. * @value: value
  869. * @port: port
  870. *
  871. * Write the contents of a register that is virtualized to be per port.
  872. */
  873. static inline void ipath_write_ureg(const struct ipath_devdata *dd,
  874. ipath_ureg regno, u64 value, int port)
  875. {
  876. u64 __iomem *ubase = (u64 __iomem *)
  877. (dd->ipath_uregbase + (char __iomem *) dd->ipath_kregbase +
  878. dd->ipath_ureg_align * port);
  879. if (dd->ipath_kregbase)
  880. writeq(value, &ubase[regno]);
  881. }
  882. static inline u32 ipath_read_kreg32(const struct ipath_devdata *dd,
  883. ipath_kreg regno)
  884. {
  885. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  886. return -1;
  887. return readl((u32 __iomem *) & dd->ipath_kregbase[regno]);
  888. }
  889. static inline u64 ipath_read_kreg64(const struct ipath_devdata *dd,
  890. ipath_kreg regno)
  891. {
  892. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  893. return -1;
  894. return readq(&dd->ipath_kregbase[regno]);
  895. }
  896. static inline void ipath_write_kreg(const struct ipath_devdata *dd,
  897. ipath_kreg regno, u64 value)
  898. {
  899. if (dd->ipath_kregbase)
  900. writeq(value, &dd->ipath_kregbase[regno]);
  901. }
  902. static inline u64 ipath_read_creg(const struct ipath_devdata *dd,
  903. ipath_sreg regno)
  904. {
  905. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  906. return 0;
  907. return readq(regno + (u64 __iomem *)
  908. (dd->ipath_cregbase +
  909. (char __iomem *)dd->ipath_kregbase));
  910. }
  911. static inline u32 ipath_read_creg32(const struct ipath_devdata *dd,
  912. ipath_sreg regno)
  913. {
  914. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  915. return 0;
  916. return readl(regno + (u64 __iomem *)
  917. (dd->ipath_cregbase +
  918. (char __iomem *)dd->ipath_kregbase));
  919. }
  920. static inline void ipath_write_creg(const struct ipath_devdata *dd,
  921. ipath_creg regno, u64 value)
  922. {
  923. if (dd->ipath_kregbase)
  924. writeq(value, regno + (u64 __iomem *)
  925. (dd->ipath_cregbase +
  926. (char __iomem *)dd->ipath_kregbase));
  927. }
  928. static inline void ipath_clear_rcvhdrtail(const struct ipath_portdata *pd)
  929. {
  930. *((u64 *) pd->port_rcvhdrtail_kvaddr) = 0ULL;
  931. }
  932. static inline u32 ipath_get_rcvhdrtail(const struct ipath_portdata *pd)
  933. {
  934. return (u32) le64_to_cpu(*((volatile __le64 *)
  935. pd->port_rcvhdrtail_kvaddr));
  936. }
  937. static inline u64 ipath_read_ireg(const struct ipath_devdata *dd, ipath_kreg r)
  938. {
  939. return (dd->ipath_flags & IPATH_INTREG_64) ?
  940. ipath_read_kreg64(dd, r) : ipath_read_kreg32(dd, r);
  941. }
  942. /*
  943. * from contents of IBCStatus (or a saved copy), return linkstate
  944. * Report ACTIVE_DEFER as ACTIVE, because we treat them the same
  945. * everywhere, anyway (and should be, for almost all purposes).
  946. */
  947. static inline u32 ipath_ib_linkstate(struct ipath_devdata *dd, u64 ibcs)
  948. {
  949. u32 state = (u32)(ibcs >> dd->ibcs_ls_shift) &
  950. INFINIPATH_IBCS_LINKSTATE_MASK;
  951. if (state == INFINIPATH_IBCS_L_STATE_ACT_DEFER)
  952. state = INFINIPATH_IBCS_L_STATE_ACTIVE;
  953. return state;
  954. }
  955. /* from contents of IBCStatus (or a saved copy), return linktrainingstate */
  956. static inline u32 ipath_ib_linktrstate(struct ipath_devdata *dd, u64 ibcs)
  957. {
  958. return (u32)(ibcs >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
  959. dd->ibcs_lts_mask;
  960. }
  961. /*
  962. * from contents of IBCStatus (or a saved copy), return logical link state
  963. * combination of link state and linktraining state (down, active, init,
  964. * arm, etc.
  965. */
  966. static inline u32 ipath_ib_state(struct ipath_devdata *dd, u64 ibcs)
  967. {
  968. u32 ibs;
  969. ibs = (u32)(ibcs >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
  970. dd->ibcs_lts_mask;
  971. ibs |= (u32)(ibcs &
  972. (INFINIPATH_IBCS_LINKSTATE_MASK << dd->ibcs_ls_shift));
  973. return ibs;
  974. }
  975. /*
  976. * sysfs interface.
  977. */
  978. struct device_driver;
  979. extern const char ib_ipath_version[];
  980. extern struct attribute_group *ipath_driver_attr_groups[];
  981. int ipath_device_create_group(struct device *, struct ipath_devdata *);
  982. void ipath_device_remove_group(struct device *, struct ipath_devdata *);
  983. int ipath_expose_reset(struct device *);
  984. int ipath_init_ipathfs(void);
  985. void ipath_exit_ipathfs(void);
  986. int ipathfs_add_device(struct ipath_devdata *);
  987. int ipathfs_remove_device(struct ipath_devdata *);
  988. /*
  989. * dma_addr wrappers - all 0's invalid for hw
  990. */
  991. dma_addr_t ipath_map_page(struct pci_dev *, struct page *, unsigned long,
  992. size_t, int);
  993. dma_addr_t ipath_map_single(struct pci_dev *, void *, size_t, int);
  994. /*
  995. * Flush write combining store buffers (if present) and perform a write
  996. * barrier.
  997. */
  998. #if defined(CONFIG_X86_64)
  999. #define ipath_flush_wc() asm volatile("sfence" ::: "memory")
  1000. #else
  1001. #define ipath_flush_wc() wmb()
  1002. #endif
  1003. extern unsigned ipath_debug; /* debugging bit mask */
  1004. extern unsigned ipath_mtu4096;
  1005. #define IPATH_MAX_PARITY_ATTEMPTS 10000 /* max times to try recovery */
  1006. const char *ipath_get_unit_name(int unit);
  1007. extern struct mutex ipath_mutex;
  1008. #define IPATH_DRV_NAME "ib_ipath"
  1009. #define IPATH_MAJOR 233
  1010. #define IPATH_USER_MINOR_BASE 0
  1011. #define IPATH_DIAGPKT_MINOR 127
  1012. #define IPATH_DIAG_MINOR_BASE 129
  1013. #define IPATH_NMINORS 255
  1014. #define ipath_dev_err(dd,fmt,...) \
  1015. do { \
  1016. const struct ipath_devdata *__dd = (dd); \
  1017. if (__dd->pcidev) \
  1018. dev_err(&__dd->pcidev->dev, "%s: " fmt, \
  1019. ipath_get_unit_name(__dd->ipath_unit), \
  1020. ##__VA_ARGS__); \
  1021. else \
  1022. printk(KERN_ERR IPATH_DRV_NAME ": %s: " fmt, \
  1023. ipath_get_unit_name(__dd->ipath_unit), \
  1024. ##__VA_ARGS__); \
  1025. } while (0)
  1026. #if _IPATH_DEBUGGING
  1027. # define __IPATH_DBG_WHICH(which,fmt,...) \
  1028. do { \
  1029. if(unlikely(ipath_debug&(which))) \
  1030. printk(KERN_DEBUG IPATH_DRV_NAME ": %s: " fmt, \
  1031. __func__,##__VA_ARGS__); \
  1032. } while(0)
  1033. # define ipath_dbg(fmt,...) \
  1034. __IPATH_DBG_WHICH(__IPATH_DBG,fmt,##__VA_ARGS__)
  1035. # define ipath_cdbg(which,fmt,...) \
  1036. __IPATH_DBG_WHICH(__IPATH_##which##DBG,fmt,##__VA_ARGS__)
  1037. #else /* ! _IPATH_DEBUGGING */
  1038. # define ipath_dbg(fmt,...)
  1039. # define ipath_cdbg(which,fmt,...)
  1040. #endif /* _IPATH_DEBUGGING */
  1041. /*
  1042. * this is used for formatting hw error messages...
  1043. */
  1044. struct ipath_hwerror_msgs {
  1045. u64 mask;
  1046. const char *msg;
  1047. };
  1048. #define INFINIPATH_HWE_MSG(a, b) { .mask = INFINIPATH_HWE_##a, .msg = b }
  1049. /* in ipath_intr.c... */
  1050. void ipath_format_hwerrors(u64 hwerrs,
  1051. const struct ipath_hwerror_msgs *hwerrmsgs,
  1052. size_t nhwerrmsgs,
  1053. char *msg, size_t lmsg);
  1054. #endif /* _IPATH_KERNEL_H */