ipath_kernel.h 38 KB

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