ipath_kernel.h 43 KB

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