ipath_kernel.h 44 KB

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