ipath_kernel.h 44 KB

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