ipath_kernel.h 44 KB

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