ipath_kernel.h 44 KB

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