hfi.h 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  1. #ifndef _HFI1_KERNEL_H
  2. #define _HFI1_KERNEL_H
  3. /*
  4. * Copyright(c) 2015-2017 Intel Corporation.
  5. *
  6. * This file is provided under a dual BSD/GPLv2 license. When using or
  7. * redistributing this file, you may do so under either license.
  8. *
  9. * GPL LICENSE SUMMARY
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * BSD LICENSE
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. *
  26. * - Redistributions of source code must retain the above copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * - Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in
  30. * the documentation and/or other materials provided with the
  31. * distribution.
  32. * - Neither the name of Intel Corporation nor the names of its
  33. * contributors may be used to endorse or promote products derived
  34. * from this software without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  37. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  39. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  43. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  44. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  46. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. */
  49. #include <linux/interrupt.h>
  50. #include <linux/pci.h>
  51. #include <linux/dma-mapping.h>
  52. #include <linux/mutex.h>
  53. #include <linux/list.h>
  54. #include <linux/scatterlist.h>
  55. #include <linux/slab.h>
  56. #include <linux/idr.h>
  57. #include <linux/io.h>
  58. #include <linux/fs.h>
  59. #include <linux/completion.h>
  60. #include <linux/kref.h>
  61. #include <linux/sched.h>
  62. #include <linux/cdev.h>
  63. #include <linux/delay.h>
  64. #include <linux/kthread.h>
  65. #include <linux/i2c.h>
  66. #include <linux/i2c-algo-bit.h>
  67. #include <rdma/ib_hdrs.h>
  68. #include <linux/rhashtable.h>
  69. #include <linux/netdevice.h>
  70. #include <rdma/rdma_vt.h>
  71. #include "chip_registers.h"
  72. #include "common.h"
  73. #include "verbs.h"
  74. #include "pio.h"
  75. #include "chip.h"
  76. #include "mad.h"
  77. #include "qsfp.h"
  78. #include "platform.h"
  79. #include "affinity.h"
  80. /* bumped 1 from s/w major version of TrueScale */
  81. #define HFI1_CHIP_VERS_MAJ 3U
  82. /* don't care about this except printing */
  83. #define HFI1_CHIP_VERS_MIN 0U
  84. /* The Organization Unique Identifier (Mfg code), and its position in GUID */
  85. #define HFI1_OUI 0x001175
  86. #define HFI1_OUI_LSB 40
  87. #define DROP_PACKET_OFF 0
  88. #define DROP_PACKET_ON 1
  89. extern unsigned long hfi1_cap_mask;
  90. #define HFI1_CAP_KGET_MASK(mask, cap) ((mask) & HFI1_CAP_##cap)
  91. #define HFI1_CAP_UGET_MASK(mask, cap) \
  92. (((mask) >> HFI1_CAP_USER_SHIFT) & HFI1_CAP_##cap)
  93. #define HFI1_CAP_KGET(cap) (HFI1_CAP_KGET_MASK(hfi1_cap_mask, cap))
  94. #define HFI1_CAP_UGET(cap) (HFI1_CAP_UGET_MASK(hfi1_cap_mask, cap))
  95. #define HFI1_CAP_IS_KSET(cap) (!!HFI1_CAP_KGET(cap))
  96. #define HFI1_CAP_IS_USET(cap) (!!HFI1_CAP_UGET(cap))
  97. #define HFI1_MISC_GET() ((hfi1_cap_mask >> HFI1_CAP_MISC_SHIFT) & \
  98. HFI1_CAP_MISC_MASK)
  99. /* Offline Disabled Reason is 4-bits */
  100. #define HFI1_ODR_MASK(rsn) ((rsn) & OPA_PI_MASK_OFFLINE_REASON)
  101. /*
  102. * Control context is always 0 and handles the error packets.
  103. * It also handles the VL15 and multicast packets.
  104. */
  105. #define HFI1_CTRL_CTXT 0
  106. /*
  107. * Driver context will store software counters for each of the events
  108. * associated with these status registers
  109. */
  110. #define NUM_CCE_ERR_STATUS_COUNTERS 41
  111. #define NUM_RCV_ERR_STATUS_COUNTERS 64
  112. #define NUM_MISC_ERR_STATUS_COUNTERS 13
  113. #define NUM_SEND_PIO_ERR_STATUS_COUNTERS 36
  114. #define NUM_SEND_DMA_ERR_STATUS_COUNTERS 4
  115. #define NUM_SEND_EGRESS_ERR_STATUS_COUNTERS 64
  116. #define NUM_SEND_ERR_STATUS_COUNTERS 3
  117. #define NUM_SEND_CTXT_ERR_STATUS_COUNTERS 5
  118. #define NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS 24
  119. /*
  120. * per driver stats, either not device nor port-specific, or
  121. * summed over all of the devices and ports.
  122. * They are described by name via ipathfs filesystem, so layout
  123. * and number of elements can change without breaking compatibility.
  124. * If members are added or deleted hfi1_statnames[] in debugfs.c must
  125. * change to match.
  126. */
  127. struct hfi1_ib_stats {
  128. __u64 sps_ints; /* number of interrupts handled */
  129. __u64 sps_errints; /* number of error interrupts */
  130. __u64 sps_txerrs; /* tx-related packet errors */
  131. __u64 sps_rcverrs; /* non-crc rcv packet errors */
  132. __u64 sps_hwerrs; /* hardware errors reported (parity, etc.) */
  133. __u64 sps_nopiobufs; /* no pio bufs avail from kernel */
  134. __u64 sps_ctxts; /* number of contexts currently open */
  135. __u64 sps_lenerrs; /* number of kernel packets where RHF != LRH len */
  136. __u64 sps_buffull;
  137. __u64 sps_hdrfull;
  138. };
  139. extern struct hfi1_ib_stats hfi1_stats;
  140. extern const struct pci_error_handlers hfi1_pci_err_handler;
  141. /*
  142. * First-cut criterion for "device is active" is
  143. * two thousand dwords combined Tx, Rx traffic per
  144. * 5-second interval. SMA packets are 64 dwords,
  145. * and occur "a few per second", presumably each way.
  146. */
  147. #define HFI1_TRAFFIC_ACTIVE_THRESHOLD (2000)
  148. /*
  149. * Below contains all data related to a single context (formerly called port).
  150. */
  151. #ifdef CONFIG_DEBUG_FS
  152. struct hfi1_opcode_stats_perctx;
  153. #endif
  154. struct ctxt_eager_bufs {
  155. ssize_t size; /* total size of eager buffers */
  156. u32 count; /* size of buffers array */
  157. u32 numbufs; /* number of buffers allocated */
  158. u32 alloced; /* number of rcvarray entries used */
  159. u32 rcvtid_size; /* size of each eager rcv tid */
  160. u32 threshold; /* head update threshold */
  161. struct eager_buffer {
  162. void *addr;
  163. dma_addr_t dma;
  164. ssize_t len;
  165. } *buffers;
  166. struct {
  167. void *addr;
  168. dma_addr_t dma;
  169. } *rcvtids;
  170. };
  171. struct exp_tid_set {
  172. struct list_head list;
  173. u32 count;
  174. };
  175. struct hfi1_ctxtdata {
  176. /* shadow the ctxt's RcvCtrl register */
  177. u64 rcvctrl;
  178. /* rcvhdrq base, needs mmap before useful */
  179. void *rcvhdrq;
  180. /* kernel virtual address where hdrqtail is updated */
  181. volatile __le64 *rcvhdrtail_kvaddr;
  182. /* when waiting for rcv or pioavail */
  183. wait_queue_head_t wait;
  184. /* rcvhdrq size (for freeing) */
  185. size_t rcvhdrq_size;
  186. /* number of rcvhdrq entries */
  187. u16 rcvhdrq_cnt;
  188. /* size of each of the rcvhdrq entries */
  189. u16 rcvhdrqentsize;
  190. /* mmap of hdrq, must fit in 44 bits */
  191. dma_addr_t rcvhdrq_dma;
  192. dma_addr_t rcvhdrqtailaddr_dma;
  193. struct ctxt_eager_bufs egrbufs;
  194. /* this receive context's assigned PIO ACK send context */
  195. struct send_context *sc;
  196. /* dynamic receive available interrupt timeout */
  197. u32 rcvavail_timeout;
  198. /*
  199. * number of opens (including slave sub-contexts) on this instance
  200. * (ignoring forks, dup, etc. for now)
  201. */
  202. int cnt;
  203. /* Device context index */
  204. unsigned ctxt;
  205. /*
  206. * non-zero if ctxt can be shared, and defines the maximum number of
  207. * sub-contexts for this device context.
  208. */
  209. u16 subctxt_cnt;
  210. /* non-zero if ctxt is being shared. */
  211. u16 subctxt_id;
  212. u8 uuid[16];
  213. /* job key */
  214. u16 jkey;
  215. /* number of RcvArray groups for this context. */
  216. u32 rcv_array_groups;
  217. /* index of first eager TID entry. */
  218. u32 eager_base;
  219. /* number of expected TID entries */
  220. u32 expected_count;
  221. /* index of first expected TID entry. */
  222. u32 expected_base;
  223. struct exp_tid_set tid_group_list;
  224. struct exp_tid_set tid_used_list;
  225. struct exp_tid_set tid_full_list;
  226. /* lock protecting all Expected TID data */
  227. struct mutex exp_lock;
  228. /* number of pio bufs for this ctxt (all procs, if shared) */
  229. u32 piocnt;
  230. /* first pio buffer for this ctxt */
  231. u32 pio_base;
  232. /* chip offset of PIO buffers for this ctxt */
  233. u32 piobufs;
  234. /* per-context configuration flags */
  235. unsigned long flags;
  236. /* per-context event flags for fileops/intr communication */
  237. unsigned long event_flags;
  238. /* WAIT_RCV that timed out, no interrupt */
  239. u32 rcvwait_to;
  240. /* WAIT_PIO that timed out, no interrupt */
  241. u32 piowait_to;
  242. /* WAIT_RCV already happened, no wait */
  243. u32 rcvnowait;
  244. /* WAIT_PIO already happened, no wait */
  245. u32 pionowait;
  246. /* total number of polled urgent packets */
  247. u32 urgent;
  248. /* saved total number of polled urgent packets for poll edge trigger */
  249. u32 urgent_poll;
  250. /* same size as task_struct .comm[], command that opened context */
  251. char comm[TASK_COMM_LEN];
  252. /* so file ops can get at unit */
  253. struct hfi1_devdata *dd;
  254. /* so functions that need physical port can get it easily */
  255. struct hfi1_pportdata *ppd;
  256. /* associated msix interrupt */
  257. u32 msix_intr;
  258. /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
  259. void *subctxt_uregbase;
  260. /* An array of pages for the eager receive buffers * N */
  261. void *subctxt_rcvegrbuf;
  262. /* An array of pages for the eager header queue entries * N */
  263. void *subctxt_rcvhdr_base;
  264. /* Bitmask of in use context(s) */
  265. DECLARE_BITMAP(in_use_ctxts, HFI1_MAX_SHARED_CTXTS);
  266. /* The version of the library which opened this ctxt */
  267. u32 userversion;
  268. /* Type of packets or conditions we want to poll for */
  269. u16 poll_type;
  270. /* receive packet sequence counter */
  271. u8 seq_cnt;
  272. u8 redirect_seq_cnt;
  273. /* ctxt rcvhdrq head offset */
  274. u32 head;
  275. u32 pkt_count;
  276. /* QPs waiting for context processing */
  277. struct list_head qp_wait_list;
  278. /* interrupt handling */
  279. u64 imask; /* clear interrupt mask */
  280. int ireg; /* clear interrupt register */
  281. unsigned numa_id; /* numa node of this context */
  282. /* verbs stats per CTX */
  283. struct hfi1_opcode_stats_perctx *opstats;
  284. /*
  285. * This is the kernel thread that will keep making
  286. * progress on the user sdma requests behind the scenes.
  287. * There is one per context (shared contexts use the master's).
  288. */
  289. struct task_struct *progress;
  290. struct list_head sdma_queues;
  291. /* protect sdma queues */
  292. spinlock_t sdma_qlock;
  293. /* Is ASPM interrupt supported for this context */
  294. bool aspm_intr_supported;
  295. /* ASPM state (enabled/disabled) for this context */
  296. bool aspm_enabled;
  297. /* Timer for re-enabling ASPM if interrupt activity quietens down */
  298. struct timer_list aspm_timer;
  299. /* Lock to serialize between intr, timer intr and user threads */
  300. spinlock_t aspm_lock;
  301. /* Is ASPM processing enabled for this context (in intr context) */
  302. bool aspm_intr_enable;
  303. /* Last interrupt timestamp */
  304. ktime_t aspm_ts_last_intr;
  305. /* Last timestamp at which we scheduled a timer for this context */
  306. ktime_t aspm_ts_timer_sched;
  307. /*
  308. * The interrupt handler for a particular receive context can vary
  309. * throughout it's lifetime. This is not a lock protected data member so
  310. * it must be updated atomically and the prev and new value must always
  311. * be valid. Worst case is we process an extra interrupt and up to 64
  312. * packets with the wrong interrupt handler.
  313. */
  314. int (*do_interrupt)(struct hfi1_ctxtdata *rcd, int threaded);
  315. /* Indicates that this is vnic context */
  316. bool is_vnic;
  317. /* vnic queue index this context is mapped to */
  318. u8 vnic_q_idx;
  319. };
  320. /*
  321. * Represents a single packet at a high level. Put commonly computed things in
  322. * here so we do not have to keep doing them over and over. The rule of thumb is
  323. * if something is used one time to derive some value, store that something in
  324. * here. If it is used multiple times, then store the result of that derivation
  325. * in here.
  326. */
  327. struct hfi1_packet {
  328. void *ebuf;
  329. void *hdr;
  330. struct hfi1_ctxtdata *rcd;
  331. __le32 *rhf_addr;
  332. struct rvt_qp *qp;
  333. struct ib_other_headers *ohdr;
  334. u64 rhf;
  335. u32 maxcnt;
  336. u32 rhqoff;
  337. u16 tlen;
  338. s16 etail;
  339. u8 hlen;
  340. u8 numpkt;
  341. u8 rsize;
  342. u8 updegr;
  343. u8 rcv_flags;
  344. u8 etype;
  345. };
  346. struct rvt_sge_state;
  347. /*
  348. * Get/Set IB link-level config parameters for f_get/set_ib_cfg()
  349. * Mostly for MADs that set or query link parameters, also ipath
  350. * config interfaces
  351. */
  352. #define HFI1_IB_CFG_LIDLMC 0 /* LID (LS16b) and Mask (MS16b) */
  353. #define HFI1_IB_CFG_LWID_DG_ENB 1 /* allowed Link-width downgrade */
  354. #define HFI1_IB_CFG_LWID_ENB 2 /* allowed Link-width */
  355. #define HFI1_IB_CFG_LWID 3 /* currently active Link-width */
  356. #define HFI1_IB_CFG_SPD_ENB 4 /* allowed Link speeds */
  357. #define HFI1_IB_CFG_SPD 5 /* current Link spd */
  358. #define HFI1_IB_CFG_RXPOL_ENB 6 /* Auto-RX-polarity enable */
  359. #define HFI1_IB_CFG_LREV_ENB 7 /* Auto-Lane-reversal enable */
  360. #define HFI1_IB_CFG_LINKLATENCY 8 /* Link Latency (IB1.2 only) */
  361. #define HFI1_IB_CFG_HRTBT 9 /* IB heartbeat off/enable/auto; DDR/QDR only */
  362. #define HFI1_IB_CFG_OP_VLS 10 /* operational VLs */
  363. #define HFI1_IB_CFG_VL_HIGH_CAP 11 /* num of VL high priority weights */
  364. #define HFI1_IB_CFG_VL_LOW_CAP 12 /* num of VL low priority weights */
  365. #define HFI1_IB_CFG_OVERRUN_THRESH 13 /* IB overrun threshold */
  366. #define HFI1_IB_CFG_PHYERR_THRESH 14 /* IB PHY error threshold */
  367. #define HFI1_IB_CFG_LINKDEFAULT 15 /* IB link default (sleep/poll) */
  368. #define HFI1_IB_CFG_PKEYS 16 /* update partition keys */
  369. #define HFI1_IB_CFG_MTU 17 /* update MTU in IBC */
  370. #define HFI1_IB_CFG_VL_HIGH_LIMIT 19
  371. #define HFI1_IB_CFG_PMA_TICKS 20 /* PMA sample tick resolution */
  372. #define HFI1_IB_CFG_PORT 21 /* switch port we are connected to */
  373. /*
  374. * HFI or Host Link States
  375. *
  376. * These describe the states the driver thinks the logical and physical
  377. * states are in. Used as an argument to set_link_state(). Implemented
  378. * as bits for easy multi-state checking. The actual state can only be
  379. * one.
  380. */
  381. #define __HLS_UP_INIT_BP 0
  382. #define __HLS_UP_ARMED_BP 1
  383. #define __HLS_UP_ACTIVE_BP 2
  384. #define __HLS_DN_DOWNDEF_BP 3 /* link down default */
  385. #define __HLS_DN_POLL_BP 4
  386. #define __HLS_DN_DISABLE_BP 5
  387. #define __HLS_DN_OFFLINE_BP 6
  388. #define __HLS_VERIFY_CAP_BP 7
  389. #define __HLS_GOING_UP_BP 8
  390. #define __HLS_GOING_OFFLINE_BP 9
  391. #define __HLS_LINK_COOLDOWN_BP 10
  392. #define HLS_UP_INIT BIT(__HLS_UP_INIT_BP)
  393. #define HLS_UP_ARMED BIT(__HLS_UP_ARMED_BP)
  394. #define HLS_UP_ACTIVE BIT(__HLS_UP_ACTIVE_BP)
  395. #define HLS_DN_DOWNDEF BIT(__HLS_DN_DOWNDEF_BP) /* link down default */
  396. #define HLS_DN_POLL BIT(__HLS_DN_POLL_BP)
  397. #define HLS_DN_DISABLE BIT(__HLS_DN_DISABLE_BP)
  398. #define HLS_DN_OFFLINE BIT(__HLS_DN_OFFLINE_BP)
  399. #define HLS_VERIFY_CAP BIT(__HLS_VERIFY_CAP_BP)
  400. #define HLS_GOING_UP BIT(__HLS_GOING_UP_BP)
  401. #define HLS_GOING_OFFLINE BIT(__HLS_GOING_OFFLINE_BP)
  402. #define HLS_LINK_COOLDOWN BIT(__HLS_LINK_COOLDOWN_BP)
  403. #define HLS_UP (HLS_UP_INIT | HLS_UP_ARMED | HLS_UP_ACTIVE)
  404. #define HLS_DOWN ~(HLS_UP)
  405. /* use this MTU size if none other is given */
  406. #define HFI1_DEFAULT_ACTIVE_MTU 10240
  407. /* use this MTU size as the default maximum */
  408. #define HFI1_DEFAULT_MAX_MTU 10240
  409. /* default partition key */
  410. #define DEFAULT_PKEY 0xffff
  411. /*
  412. * Possible fabric manager config parameters for fm_{get,set}_table()
  413. */
  414. #define FM_TBL_VL_HIGH_ARB 1 /* Get/set VL high prio weights */
  415. #define FM_TBL_VL_LOW_ARB 2 /* Get/set VL low prio weights */
  416. #define FM_TBL_BUFFER_CONTROL 3 /* Get/set Buffer Control */
  417. #define FM_TBL_SC2VLNT 4 /* Get/set SC->VLnt */
  418. #define FM_TBL_VL_PREEMPT_ELEMS 5 /* Get (no set) VL preempt elems */
  419. #define FM_TBL_VL_PREEMPT_MATRIX 6 /* Get (no set) VL preempt matrix */
  420. /*
  421. * Possible "operations" for f_rcvctrl(ppd, op, ctxt)
  422. * these are bits so they can be combined, e.g.
  423. * HFI1_RCVCTRL_INTRAVAIL_ENB | HFI1_RCVCTRL_CTXT_ENB
  424. */
  425. #define HFI1_RCVCTRL_TAILUPD_ENB 0x01
  426. #define HFI1_RCVCTRL_TAILUPD_DIS 0x02
  427. #define HFI1_RCVCTRL_CTXT_ENB 0x04
  428. #define HFI1_RCVCTRL_CTXT_DIS 0x08
  429. #define HFI1_RCVCTRL_INTRAVAIL_ENB 0x10
  430. #define HFI1_RCVCTRL_INTRAVAIL_DIS 0x20
  431. #define HFI1_RCVCTRL_PKEY_ENB 0x40 /* Note, default is enabled */
  432. #define HFI1_RCVCTRL_PKEY_DIS 0x80
  433. #define HFI1_RCVCTRL_TIDFLOW_ENB 0x0400
  434. #define HFI1_RCVCTRL_TIDFLOW_DIS 0x0800
  435. #define HFI1_RCVCTRL_ONE_PKT_EGR_ENB 0x1000
  436. #define HFI1_RCVCTRL_ONE_PKT_EGR_DIS 0x2000
  437. #define HFI1_RCVCTRL_NO_RHQ_DROP_ENB 0x4000
  438. #define HFI1_RCVCTRL_NO_RHQ_DROP_DIS 0x8000
  439. #define HFI1_RCVCTRL_NO_EGR_DROP_ENB 0x10000
  440. #define HFI1_RCVCTRL_NO_EGR_DROP_DIS 0x20000
  441. /* partition enforcement flags */
  442. #define HFI1_PART_ENFORCE_IN 0x1
  443. #define HFI1_PART_ENFORCE_OUT 0x2
  444. /* how often we check for synthetic counter wrap around */
  445. #define SYNTH_CNT_TIME 3
  446. /* Counter flags */
  447. #define CNTR_NORMAL 0x0 /* Normal counters, just read register */
  448. #define CNTR_SYNTH 0x1 /* Synthetic counters, saturate at all 1s */
  449. #define CNTR_DISABLED 0x2 /* Disable this counter */
  450. #define CNTR_32BIT 0x4 /* Simulate 64 bits for this counter */
  451. #define CNTR_VL 0x8 /* Per VL counter */
  452. #define CNTR_SDMA 0x10
  453. #define CNTR_INVALID_VL -1 /* Specifies invalid VL */
  454. #define CNTR_MODE_W 0x0
  455. #define CNTR_MODE_R 0x1
  456. /* VLs Supported/Operational */
  457. #define HFI1_MIN_VLS_SUPPORTED 1
  458. #define HFI1_MAX_VLS_SUPPORTED 8
  459. #define HFI1_GUIDS_PER_PORT 5
  460. #define HFI1_PORT_GUID_INDEX 0
  461. static inline void incr_cntr64(u64 *cntr)
  462. {
  463. if (*cntr < (u64)-1LL)
  464. (*cntr)++;
  465. }
  466. static inline void incr_cntr32(u32 *cntr)
  467. {
  468. if (*cntr < (u32)-1LL)
  469. (*cntr)++;
  470. }
  471. #define MAX_NAME_SIZE 64
  472. struct hfi1_msix_entry {
  473. enum irq_type type;
  474. struct msix_entry msix;
  475. void *arg;
  476. char name[MAX_NAME_SIZE];
  477. cpumask_t mask;
  478. struct irq_affinity_notify notify;
  479. };
  480. /* per-SL CCA information */
  481. struct cca_timer {
  482. struct hrtimer hrtimer;
  483. struct hfi1_pportdata *ppd; /* read-only */
  484. int sl; /* read-only */
  485. u16 ccti; /* read/write - current value of CCTI */
  486. };
  487. struct link_down_reason {
  488. /*
  489. * SMA-facing value. Should be set from .latest when
  490. * HLS_UP_* -> HLS_DN_* transition actually occurs.
  491. */
  492. u8 sma;
  493. u8 latest;
  494. };
  495. enum {
  496. LO_PRIO_TABLE,
  497. HI_PRIO_TABLE,
  498. MAX_PRIO_TABLE
  499. };
  500. struct vl_arb_cache {
  501. /* protect vl arb cache */
  502. spinlock_t lock;
  503. struct ib_vl_weight_elem table[VL_ARB_TABLE_SIZE];
  504. };
  505. /*
  506. * The structure below encapsulates data relevant to a physical IB Port.
  507. * Current chips support only one such port, but the separation
  508. * clarifies things a bit. Note that to conform to IB conventions,
  509. * port-numbers are one-based. The first or only port is port1.
  510. */
  511. struct hfi1_pportdata {
  512. struct hfi1_ibport ibport_data;
  513. struct hfi1_devdata *dd;
  514. struct kobject pport_cc_kobj;
  515. struct kobject sc2vl_kobj;
  516. struct kobject sl2sc_kobj;
  517. struct kobject vl2mtu_kobj;
  518. /* PHY support */
  519. struct qsfp_data qsfp_info;
  520. /* Values for SI tuning of SerDes */
  521. u32 port_type;
  522. u32 tx_preset_eq;
  523. u32 tx_preset_noeq;
  524. u32 rx_preset;
  525. u8 local_atten;
  526. u8 remote_atten;
  527. u8 default_atten;
  528. u8 max_power_class;
  529. /* GUIDs for this interface, in host order, guids[0] is a port guid */
  530. u64 guids[HFI1_GUIDS_PER_PORT];
  531. /* GUID for peer interface, in host order */
  532. u64 neighbor_guid;
  533. /* up or down physical link state */
  534. u32 linkup;
  535. /*
  536. * this address is mapped read-only into user processes so they can
  537. * get status cheaply, whenever they want. One qword of status per port
  538. */
  539. u64 *statusp;
  540. /* SendDMA related entries */
  541. struct workqueue_struct *hfi1_wq;
  542. /* move out of interrupt context */
  543. struct work_struct link_vc_work;
  544. struct work_struct link_up_work;
  545. struct work_struct link_down_work;
  546. struct work_struct sma_message_work;
  547. struct work_struct freeze_work;
  548. struct work_struct link_downgrade_work;
  549. struct work_struct link_bounce_work;
  550. struct delayed_work start_link_work;
  551. /* host link state variables */
  552. struct mutex hls_lock;
  553. u32 host_link_state;
  554. u32 lstate; /* logical link state */
  555. /* these are the "32 bit" regs */
  556. u32 ibmtu; /* The MTU programmed for this unit */
  557. /*
  558. * Current max size IB packet (in bytes) including IB headers, that
  559. * we can send. Changes when ibmtu changes.
  560. */
  561. u32 ibmaxlen;
  562. u32 current_egress_rate; /* units [10^6 bits/sec] */
  563. /* LID programmed for this instance */
  564. u16 lid;
  565. /* list of pkeys programmed; 0 if not set */
  566. u16 pkeys[MAX_PKEY_VALUES];
  567. u16 link_width_supported;
  568. u16 link_width_downgrade_supported;
  569. u16 link_speed_supported;
  570. u16 link_width_enabled;
  571. u16 link_width_downgrade_enabled;
  572. u16 link_speed_enabled;
  573. u16 link_width_active;
  574. u16 link_width_downgrade_tx_active;
  575. u16 link_width_downgrade_rx_active;
  576. u16 link_speed_active;
  577. u8 vls_supported;
  578. u8 vls_operational;
  579. u8 actual_vls_operational;
  580. /* LID mask control */
  581. u8 lmc;
  582. /* Rx Polarity inversion (compensate for ~tx on partner) */
  583. u8 rx_pol_inv;
  584. u8 hw_pidx; /* physical port index */
  585. u8 port; /* IB port number and index into dd->pports - 1 */
  586. /* type of neighbor node */
  587. u8 neighbor_type;
  588. u8 neighbor_normal;
  589. u8 neighbor_fm_security; /* 1 if firmware checking is disabled */
  590. u8 neighbor_port_number;
  591. u8 is_sm_config_started;
  592. u8 offline_disabled_reason;
  593. u8 is_active_optimize_enabled;
  594. u8 driver_link_ready; /* driver ready for active link */
  595. u8 link_enabled; /* link enabled? */
  596. u8 linkinit_reason;
  597. u8 local_tx_rate; /* rate given to 8051 firmware */
  598. u8 last_pstate; /* info only */
  599. u8 qsfp_retry_count;
  600. /* placeholders for IB MAD packet settings */
  601. u8 overrun_threshold;
  602. u8 phy_error_threshold;
  603. /* Used to override LED behavior for things like maintenance beaconing*/
  604. /*
  605. * Alternates per phase of blink
  606. * [0] holds LED off duration, [1] holds LED on duration
  607. */
  608. unsigned long led_override_vals[2];
  609. u8 led_override_phase; /* LSB picks from vals[] */
  610. atomic_t led_override_timer_active;
  611. /* Used to flash LEDs in override mode */
  612. struct timer_list led_override_timer;
  613. u32 sm_trap_qp;
  614. u32 sa_qp;
  615. /*
  616. * cca_timer_lock protects access to the per-SL cca_timer
  617. * structures (specifically the ccti member).
  618. */
  619. spinlock_t cca_timer_lock ____cacheline_aligned_in_smp;
  620. struct cca_timer cca_timer[OPA_MAX_SLS];
  621. /* List of congestion control table entries */
  622. struct ib_cc_table_entry_shadow ccti_entries[CC_TABLE_SHADOW_MAX];
  623. /* congestion entries, each entry corresponding to a SL */
  624. struct opa_congestion_setting_entry_shadow
  625. congestion_entries[OPA_MAX_SLS];
  626. /*
  627. * cc_state_lock protects (write) access to the per-port
  628. * struct cc_state.
  629. */
  630. spinlock_t cc_state_lock ____cacheline_aligned_in_smp;
  631. struct cc_state __rcu *cc_state;
  632. /* Total number of congestion control table entries */
  633. u16 total_cct_entry;
  634. /* Bit map identifying service level */
  635. u32 cc_sl_control_map;
  636. /* CA's max number of 64 entry units in the congestion control table */
  637. u8 cc_max_table_entries;
  638. /*
  639. * begin congestion log related entries
  640. * cc_log_lock protects all congestion log related data
  641. */
  642. spinlock_t cc_log_lock ____cacheline_aligned_in_smp;
  643. u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
  644. u16 threshold_event_counter;
  645. struct opa_hfi1_cong_log_event_internal cc_events[OPA_CONG_LOG_ELEMS];
  646. int cc_log_idx; /* index for logging events */
  647. int cc_mad_idx; /* index for reporting events */
  648. /* end congestion log related entries */
  649. struct vl_arb_cache vl_arb_cache[MAX_PRIO_TABLE];
  650. /* port relative counter buffer */
  651. u64 *cntrs;
  652. /* port relative synthetic counter buffer */
  653. u64 *scntrs;
  654. /* port_xmit_discards are synthesized from different egress errors */
  655. u64 port_xmit_discards;
  656. u64 port_xmit_discards_vl[C_VL_COUNT];
  657. u64 port_xmit_constraint_errors;
  658. u64 port_rcv_constraint_errors;
  659. /* count of 'link_err' interrupts from DC */
  660. u64 link_downed;
  661. /* number of times link retrained successfully */
  662. u64 link_up;
  663. /* number of times a link unknown frame was reported */
  664. u64 unknown_frame_count;
  665. /* port_ltp_crc_mode is returned in 'portinfo' MADs */
  666. u16 port_ltp_crc_mode;
  667. /* port_crc_mode_enabled is the crc we support */
  668. u8 port_crc_mode_enabled;
  669. /* mgmt_allowed is also returned in 'portinfo' MADs */
  670. u8 mgmt_allowed;
  671. u8 part_enforce; /* partition enforcement flags */
  672. struct link_down_reason local_link_down_reason;
  673. struct link_down_reason neigh_link_down_reason;
  674. /* Value to be sent to link peer on LinkDown .*/
  675. u8 remote_link_down_reason;
  676. /* Error events that will cause a port bounce. */
  677. u32 port_error_action;
  678. struct work_struct linkstate_active_work;
  679. /* Does this port need to prescan for FECNs */
  680. bool cc_prescan;
  681. };
  682. typedef int (*rhf_rcv_function_ptr)(struct hfi1_packet *packet);
  683. typedef void (*opcode_handler)(struct hfi1_packet *packet);
  684. /* return values for the RHF receive functions */
  685. #define RHF_RCV_CONTINUE 0 /* keep going */
  686. #define RHF_RCV_DONE 1 /* stop, this packet processed */
  687. #define RHF_RCV_REPROCESS 2 /* stop. retain this packet */
  688. struct rcv_array_data {
  689. u8 group_size;
  690. u16 ngroups;
  691. u16 nctxt_extra;
  692. };
  693. struct per_vl_data {
  694. u16 mtu;
  695. struct send_context *sc;
  696. };
  697. /* 16 to directly index */
  698. #define PER_VL_SEND_CONTEXTS 16
  699. struct err_info_rcvport {
  700. u8 status_and_code;
  701. u64 packet_flit1;
  702. u64 packet_flit2;
  703. };
  704. struct err_info_constraint {
  705. u8 status;
  706. u16 pkey;
  707. u32 slid;
  708. };
  709. struct hfi1_temp {
  710. unsigned int curr; /* current temperature */
  711. unsigned int lo_lim; /* low temperature limit */
  712. unsigned int hi_lim; /* high temperature limit */
  713. unsigned int crit_lim; /* critical temperature limit */
  714. u8 triggers; /* temperature triggers */
  715. };
  716. struct hfi1_i2c_bus {
  717. struct hfi1_devdata *controlling_dd; /* current controlling device */
  718. struct i2c_adapter adapter; /* bus details */
  719. struct i2c_algo_bit_data algo; /* bus algorithm details */
  720. int num; /* bus number, 0 or 1 */
  721. };
  722. /* common data between shared ASIC HFIs */
  723. struct hfi1_asic_data {
  724. struct hfi1_devdata *dds[2]; /* back pointers */
  725. struct mutex asic_resource_mutex;
  726. struct hfi1_i2c_bus *i2c_bus0;
  727. struct hfi1_i2c_bus *i2c_bus1;
  728. };
  729. /* sizes for both the QP and RSM map tables */
  730. #define NUM_MAP_ENTRIES 256
  731. #define NUM_MAP_REGS 32
  732. /*
  733. * Number of VNIC contexts used. Ensure it is less than or equal to
  734. * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
  735. */
  736. #define HFI1_NUM_VNIC_CTXT 8
  737. /* Number of VNIC RSM entries */
  738. #define NUM_VNIC_MAP_ENTRIES 8
  739. /* Virtual NIC information */
  740. struct hfi1_vnic_data {
  741. struct hfi1_ctxtdata *ctxt[HFI1_NUM_VNIC_CTXT];
  742. struct kmem_cache *txreq_cache;
  743. u8 num_vports;
  744. struct idr vesw_idr;
  745. u8 rmt_start;
  746. u8 num_ctxt;
  747. u32 msix_idx;
  748. };
  749. struct hfi1_vnic_vport_info;
  750. /* device data struct now contains only "general per-device" info.
  751. * fields related to a physical IB port are in a hfi1_pportdata struct.
  752. */
  753. struct sdma_engine;
  754. struct sdma_vl_map;
  755. #define BOARD_VERS_MAX 96 /* how long the version string can be */
  756. #define SERIAL_MAX 16 /* length of the serial number */
  757. typedef int (*send_routine)(struct rvt_qp *, struct hfi1_pkt_state *, u64);
  758. struct hfi1_devdata {
  759. struct hfi1_ibdev verbs_dev; /* must be first */
  760. struct list_head list;
  761. /* pointers to related structs for this device */
  762. /* pci access data structure */
  763. struct pci_dev *pcidev;
  764. struct cdev user_cdev;
  765. struct cdev diag_cdev;
  766. struct cdev ui_cdev;
  767. struct device *user_device;
  768. struct device *diag_device;
  769. struct device *ui_device;
  770. /* mem-mapped pointer to base of chip regs */
  771. u8 __iomem *kregbase;
  772. /* end of mem-mapped chip space excluding sendbuf and user regs */
  773. u8 __iomem *kregend;
  774. /* physical address of chip for io_remap, etc. */
  775. resource_size_t physaddr;
  776. /* Per VL data. Enough for all VLs but not all elements are set/used. */
  777. struct per_vl_data vld[PER_VL_SEND_CONTEXTS];
  778. /* send context data */
  779. struct send_context_info *send_contexts;
  780. /* map hardware send contexts to software index */
  781. u8 *hw_to_sw;
  782. /* spinlock for allocating and releasing send context resources */
  783. spinlock_t sc_lock;
  784. /* lock for pio_map */
  785. spinlock_t pio_map_lock;
  786. /* Send Context initialization lock. */
  787. spinlock_t sc_init_lock;
  788. /* lock for sdma_map */
  789. spinlock_t sde_map_lock;
  790. /* array of kernel send contexts */
  791. struct send_context **kernel_send_context;
  792. /* array of vl maps */
  793. struct pio_vl_map __rcu *pio_map;
  794. /* default flags to last descriptor */
  795. u64 default_desc1;
  796. /* fields common to all SDMA engines */
  797. volatile __le64 *sdma_heads_dma; /* DMA'ed by chip */
  798. dma_addr_t sdma_heads_phys;
  799. void *sdma_pad_dma; /* DMA'ed by chip */
  800. dma_addr_t sdma_pad_phys;
  801. /* for deallocation */
  802. size_t sdma_heads_size;
  803. /* number from the chip */
  804. u32 chip_sdma_engines;
  805. /* num used */
  806. u32 num_sdma;
  807. /* array of engines sized by num_sdma */
  808. struct sdma_engine *per_sdma;
  809. /* array of vl maps */
  810. struct sdma_vl_map __rcu *sdma_map;
  811. /* SPC freeze waitqueue and variable */
  812. wait_queue_head_t sdma_unfreeze_wq;
  813. atomic_t sdma_unfreeze_count;
  814. u32 lcb_access_count; /* count of LCB users */
  815. /* common data between shared ASIC HFIs in this OS */
  816. struct hfi1_asic_data *asic_data;
  817. /* mem-mapped pointer to base of PIO buffers */
  818. void __iomem *piobase;
  819. /*
  820. * write-combining mem-mapped pointer to base of RcvArray
  821. * memory.
  822. */
  823. void __iomem *rcvarray_wc;
  824. /*
  825. * credit return base - a per-NUMA range of DMA address that
  826. * the chip will use to update the per-context free counter
  827. */
  828. struct credit_return_base *cr_base;
  829. /* send context numbers and sizes for each type */
  830. struct sc_config_sizes sc_sizes[SC_MAX];
  831. char *boardname; /* human readable board info */
  832. /* reset value */
  833. u64 z_int_counter;
  834. u64 z_rcv_limit;
  835. u64 z_send_schedule;
  836. u64 __percpu *send_schedule;
  837. /* number of receive contexts in use by the driver */
  838. u32 num_rcv_contexts;
  839. /* number of pio send contexts in use by the driver */
  840. u32 num_send_contexts;
  841. /*
  842. * number of ctxts available for PSM open
  843. */
  844. u32 freectxts;
  845. /* total number of available user/PSM contexts */
  846. u32 num_user_contexts;
  847. /* base receive interrupt timeout, in CSR units */
  848. u32 rcv_intr_timeout_csr;
  849. u32 freezelen; /* max length of freezemsg */
  850. u64 __iomem *egrtidbase;
  851. spinlock_t sendctrl_lock; /* protect changes to SendCtrl */
  852. spinlock_t rcvctrl_lock; /* protect changes to RcvCtrl */
  853. /* around rcd and (user ctxts) ctxt_cnt use (intr vs free) */
  854. spinlock_t uctxt_lock; /* rcd and user context changes */
  855. struct mutex dc8051_lock; /* exclusive access to 8051 */
  856. struct workqueue_struct *update_cntr_wq;
  857. struct work_struct update_cntr_work;
  858. /* exclusive access to 8051 memory */
  859. spinlock_t dc8051_memlock;
  860. int dc8051_timed_out; /* remember if the 8051 timed out */
  861. /*
  862. * A page that will hold event notification bitmaps for all
  863. * contexts. This page will be mapped into all processes.
  864. */
  865. unsigned long *events;
  866. /*
  867. * per unit status, see also portdata statusp
  868. * mapped read-only into user processes so they can get unit and
  869. * IB link status cheaply
  870. */
  871. struct hfi1_status *status;
  872. /* revision register shadow */
  873. u64 revision;
  874. /* Base GUID for device (network order) */
  875. u64 base_guid;
  876. /* these are the "32 bit" regs */
  877. /* value we put in kr_rcvhdrsize */
  878. u32 rcvhdrsize;
  879. /* number of receive contexts the chip supports */
  880. u32 chip_rcv_contexts;
  881. /* number of receive array entries */
  882. u32 chip_rcv_array_count;
  883. /* number of PIO send contexts the chip supports */
  884. u32 chip_send_contexts;
  885. /* number of bytes in the PIO memory buffer */
  886. u32 chip_pio_mem_size;
  887. /* number of bytes in the SDMA memory buffer */
  888. u32 chip_sdma_mem_size;
  889. /* size of each rcvegrbuffer */
  890. u32 rcvegrbufsize;
  891. /* log2 of above */
  892. u16 rcvegrbufsize_shift;
  893. /* both sides of the PCIe link are gen3 capable */
  894. u8 link_gen3_capable;
  895. /* default link down value (poll/sleep) */
  896. u8 link_default;
  897. /* localbus width (1, 2,4,8,16,32) from config space */
  898. u32 lbus_width;
  899. /* localbus speed in MHz */
  900. u32 lbus_speed;
  901. int unit; /* unit # of this chip */
  902. int node; /* home node of this chip */
  903. /* save these PCI fields to restore after a reset */
  904. u32 pcibar0;
  905. u32 pcibar1;
  906. u32 pci_rom;
  907. u16 pci_command;
  908. u16 pcie_devctl;
  909. u16 pcie_lnkctl;
  910. u16 pcie_devctl2;
  911. u32 pci_msix0;
  912. u32 pci_lnkctl3;
  913. u32 pci_tph2;
  914. /*
  915. * ASCII serial number, from flash, large enough for original
  916. * all digit strings, and longer serial number format
  917. */
  918. u8 serial[SERIAL_MAX];
  919. /* human readable board version */
  920. u8 boardversion[BOARD_VERS_MAX];
  921. u8 lbus_info[32]; /* human readable localbus info */
  922. /* chip major rev, from CceRevision */
  923. u8 majrev;
  924. /* chip minor rev, from CceRevision */
  925. u8 minrev;
  926. /* hardware ID */
  927. u8 hfi1_id;
  928. /* implementation code */
  929. u8 icode;
  930. /* vAU of this device */
  931. u8 vau;
  932. /* vCU of this device */
  933. u8 vcu;
  934. /* link credits of this device */
  935. u16 link_credits;
  936. /* initial vl15 credits to use */
  937. u16 vl15_init;
  938. /*
  939. * Cached value for vl15buf, read during verify cap interrupt. VL15
  940. * credits are to be kept at 0 and set when handling the link-up
  941. * interrupt. This removes the possibility of receiving VL15 MAD
  942. * packets before this HFI is ready.
  943. */
  944. u16 vl15buf_cached;
  945. /* Misc small ints */
  946. u8 n_krcv_queues;
  947. u8 qos_shift;
  948. u16 irev; /* implementation revision */
  949. u32 dc8051_ver; /* 8051 firmware version */
  950. spinlock_t hfi1_diag_trans_lock; /* protect diag observer ops */
  951. struct platform_config platform_config;
  952. struct platform_config_cache pcfg_cache;
  953. struct diag_client *diag_client;
  954. /* MSI-X information */
  955. struct hfi1_msix_entry *msix_entries;
  956. u32 num_msix_entries;
  957. u32 first_dyn_msix_idx;
  958. /* INTx information */
  959. u32 requested_intx_irq; /* did we request one? */
  960. char intx_name[MAX_NAME_SIZE]; /* INTx name */
  961. /* general interrupt: mask of handled interrupts */
  962. u64 gi_mask[CCE_NUM_INT_CSRS];
  963. struct rcv_array_data rcv_entries;
  964. /* cycle length of PS* counters in HW (in picoseconds) */
  965. u16 psxmitwait_check_rate;
  966. /*
  967. * 64 bit synthetic counters
  968. */
  969. struct timer_list synth_stats_timer;
  970. /*
  971. * device counters
  972. */
  973. char *cntrnames;
  974. size_t cntrnameslen;
  975. size_t ndevcntrs;
  976. u64 *cntrs;
  977. u64 *scntrs;
  978. /*
  979. * remembered values for synthetic counters
  980. */
  981. u64 last_tx;
  982. u64 last_rx;
  983. /*
  984. * per-port counters
  985. */
  986. size_t nportcntrs;
  987. char *portcntrnames;
  988. size_t portcntrnameslen;
  989. struct err_info_rcvport err_info_rcvport;
  990. struct err_info_constraint err_info_rcv_constraint;
  991. struct err_info_constraint err_info_xmit_constraint;
  992. atomic_t drop_packet;
  993. u8 do_drop;
  994. u8 err_info_uncorrectable;
  995. u8 err_info_fmconfig;
  996. /*
  997. * Software counters for the status bits defined by the
  998. * associated error status registers
  999. */
  1000. u64 cce_err_status_cnt[NUM_CCE_ERR_STATUS_COUNTERS];
  1001. u64 rcv_err_status_cnt[NUM_RCV_ERR_STATUS_COUNTERS];
  1002. u64 misc_err_status_cnt[NUM_MISC_ERR_STATUS_COUNTERS];
  1003. u64 send_pio_err_status_cnt[NUM_SEND_PIO_ERR_STATUS_COUNTERS];
  1004. u64 send_dma_err_status_cnt[NUM_SEND_DMA_ERR_STATUS_COUNTERS];
  1005. u64 send_egress_err_status_cnt[NUM_SEND_EGRESS_ERR_STATUS_COUNTERS];
  1006. u64 send_err_status_cnt[NUM_SEND_ERR_STATUS_COUNTERS];
  1007. /* Software counter that spans all contexts */
  1008. u64 sw_ctxt_err_status_cnt[NUM_SEND_CTXT_ERR_STATUS_COUNTERS];
  1009. /* Software counter that spans all DMA engines */
  1010. u64 sw_send_dma_eng_err_status_cnt[
  1011. NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS];
  1012. /* Software counter that aggregates all cce_err_status errors */
  1013. u64 sw_cce_err_status_aggregate;
  1014. /* Software counter that aggregates all bypass packet rcv errors */
  1015. u64 sw_rcv_bypass_packet_errors;
  1016. /* receive interrupt function */
  1017. rhf_rcv_function_ptr normal_rhf_rcv_functions[8];
  1018. /* Save the enabled LCB error bits */
  1019. u64 lcb_err_en;
  1020. /*
  1021. * Capability to have different send engines simply by changing a
  1022. * pointer value.
  1023. */
  1024. send_routine process_pio_send ____cacheline_aligned_in_smp;
  1025. send_routine process_dma_send;
  1026. void (*pio_inline_send)(struct hfi1_devdata *dd, struct pio_buf *pbuf,
  1027. u64 pbc, const void *from, size_t count);
  1028. int (*process_vnic_dma_send)(struct hfi1_devdata *dd, u8 q_idx,
  1029. struct hfi1_vnic_vport_info *vinfo,
  1030. struct sk_buff *skb, u64 pbc, u8 plen);
  1031. /* hfi1_pportdata, points to array of (physical) port-specific
  1032. * data structs, indexed by pidx (0..n-1)
  1033. */
  1034. struct hfi1_pportdata *pport;
  1035. /* receive context data */
  1036. struct hfi1_ctxtdata **rcd;
  1037. u64 __percpu *int_counter;
  1038. /* device (not port) flags, basically device capabilities */
  1039. u16 flags;
  1040. /* Number of physical ports available */
  1041. u8 num_pports;
  1042. /* Lowest context number which can be used by user processes or VNIC */
  1043. u8 first_dyn_alloc_ctxt;
  1044. /* adding a new field here would make it part of this cacheline */
  1045. /* seqlock for sc2vl */
  1046. seqlock_t sc2vl_lock ____cacheline_aligned_in_smp;
  1047. u64 sc2vl[4];
  1048. /* receive interrupt functions */
  1049. rhf_rcv_function_ptr *rhf_rcv_function_map;
  1050. u64 __percpu *rcv_limit;
  1051. u16 rhf_offset; /* offset of RHF within receive header entry */
  1052. /* adding a new field here would make it part of this cacheline */
  1053. /* OUI comes from the HW. Used everywhere as 3 separate bytes. */
  1054. u8 oui1;
  1055. u8 oui2;
  1056. u8 oui3;
  1057. u8 dc_shutdown;
  1058. /* Timer and counter used to detect RcvBufOvflCnt changes */
  1059. struct timer_list rcverr_timer;
  1060. wait_queue_head_t event_queue;
  1061. /* receive context tail dummy address */
  1062. __le64 *rcvhdrtail_dummy_kvaddr;
  1063. dma_addr_t rcvhdrtail_dummy_dma;
  1064. u32 rcv_ovfl_cnt;
  1065. /* Serialize ASPM enable/disable between multiple verbs contexts */
  1066. spinlock_t aspm_lock;
  1067. /* Number of verbs contexts which have disabled ASPM */
  1068. atomic_t aspm_disabled_cnt;
  1069. /* Keeps track of user space clients */
  1070. atomic_t user_refcount;
  1071. /* Used to wait for outstanding user space clients before dev removal */
  1072. struct completion user_comp;
  1073. bool eprom_available; /* true if EPROM is available for this device */
  1074. bool aspm_supported; /* Does HW support ASPM */
  1075. bool aspm_enabled; /* ASPM state: enabled/disabled */
  1076. struct rhashtable *sdma_rht;
  1077. struct kobject kobj;
  1078. /* vnic data */
  1079. struct hfi1_vnic_data vnic;
  1080. };
  1081. static inline bool hfi1_vnic_is_rsm_full(struct hfi1_devdata *dd, int spare)
  1082. {
  1083. return (dd->vnic.rmt_start + spare) > NUM_MAP_ENTRIES;
  1084. }
  1085. /* 8051 firmware version helper */
  1086. #define dc8051_ver(a, b, c) ((a) << 16 | (b) << 8 | (c))
  1087. #define dc8051_ver_maj(a) (((a) & 0xff0000) >> 16)
  1088. #define dc8051_ver_min(a) (((a) & 0x00ff00) >> 8)
  1089. #define dc8051_ver_patch(a) ((a) & 0x0000ff)
  1090. /* f_put_tid types */
  1091. #define PT_EXPECTED 0
  1092. #define PT_EAGER 1
  1093. #define PT_INVALID 2
  1094. struct tid_rb_node;
  1095. struct mmu_rb_node;
  1096. struct mmu_rb_handler;
  1097. /* Private data for file operations */
  1098. struct hfi1_filedata {
  1099. struct hfi1_devdata *dd;
  1100. struct hfi1_ctxtdata *uctxt;
  1101. struct hfi1_user_sdma_comp_q *cq;
  1102. struct hfi1_user_sdma_pkt_q *pq;
  1103. u16 subctxt;
  1104. /* for cpu affinity; -1 if none */
  1105. int rec_cpu_num;
  1106. u32 tid_n_pinned;
  1107. struct mmu_rb_handler *handler;
  1108. struct tid_rb_node **entry_to_rb;
  1109. spinlock_t tid_lock; /* protect tid_[limit,used] counters */
  1110. u32 tid_limit;
  1111. u32 tid_used;
  1112. u32 *invalid_tids;
  1113. u32 invalid_tid_idx;
  1114. /* protect invalid_tids array and invalid_tid_idx */
  1115. spinlock_t invalid_lock;
  1116. struct mm_struct *mm;
  1117. };
  1118. extern struct list_head hfi1_dev_list;
  1119. extern spinlock_t hfi1_devs_lock;
  1120. struct hfi1_devdata *hfi1_lookup(int unit);
  1121. extern u32 hfi1_cpulist_count;
  1122. extern unsigned long *hfi1_cpulist;
  1123. int hfi1_init(struct hfi1_devdata *dd, int reinit);
  1124. int hfi1_count_active_units(void);
  1125. int hfi1_diag_add(struct hfi1_devdata *dd);
  1126. void hfi1_diag_remove(struct hfi1_devdata *dd);
  1127. void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup);
  1128. void handle_user_interrupt(struct hfi1_ctxtdata *rcd);
  1129. int hfi1_create_rcvhdrq(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd);
  1130. int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd);
  1131. int hfi1_create_ctxts(struct hfi1_devdata *dd);
  1132. struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt,
  1133. int numa);
  1134. void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd,
  1135. struct hfi1_devdata *dd, u8 hw_pidx, u8 port);
  1136. void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd);
  1137. int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread);
  1138. int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread);
  1139. int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread);
  1140. void set_all_slowpath(struct hfi1_devdata *dd);
  1141. void hfi1_vnic_synchronize_irq(struct hfi1_devdata *dd);
  1142. void hfi1_set_vnic_msix_info(struct hfi1_ctxtdata *rcd);
  1143. void hfi1_reset_vnic_msix_info(struct hfi1_ctxtdata *rcd);
  1144. extern const struct pci_device_id hfi1_pci_tbl[];
  1145. /* receive packet handler dispositions */
  1146. #define RCV_PKT_OK 0x0 /* keep going */
  1147. #define RCV_PKT_LIMIT 0x1 /* stop, hit limit, start thread */
  1148. #define RCV_PKT_DONE 0x2 /* stop, no more packets detected */
  1149. /* calculate the current RHF address */
  1150. static inline __le32 *get_rhf_addr(struct hfi1_ctxtdata *rcd)
  1151. {
  1152. return (__le32 *)rcd->rcvhdrq + rcd->head + rcd->dd->rhf_offset;
  1153. }
  1154. int hfi1_reset_device(int);
  1155. /* return the driver's idea of the logical OPA port state */
  1156. static inline u32 driver_lstate(struct hfi1_pportdata *ppd)
  1157. {
  1158. /*
  1159. * The driver does some processing from the time the logical
  1160. * link state is at INIT to the time the SM can be notified
  1161. * as such. Return IB_PORT_DOWN until the software state
  1162. * is ready.
  1163. */
  1164. if (ppd->lstate == IB_PORT_INIT && !(ppd->host_link_state & HLS_UP))
  1165. return IB_PORT_DOWN;
  1166. else
  1167. return ppd->lstate;
  1168. }
  1169. void receive_interrupt_work(struct work_struct *work);
  1170. /* extract service channel from header and rhf */
  1171. static inline int hfi1_9B_get_sc5(struct ib_header *hdr, u64 rhf)
  1172. {
  1173. return ib_get_sc(hdr) | ((!!(rhf_dc_info(rhf))) << 4);
  1174. }
  1175. #define HFI1_JKEY_WIDTH 16
  1176. #define HFI1_JKEY_MASK (BIT(16) - 1)
  1177. #define HFI1_ADMIN_JKEY_RANGE 32
  1178. /*
  1179. * J_KEYs are split and allocated in the following groups:
  1180. * 0 - 31 - users with administrator privileges
  1181. * 32 - 63 - kernel protocols using KDETH packets
  1182. * 64 - 65535 - all other users using KDETH packets
  1183. */
  1184. static inline u16 generate_jkey(kuid_t uid)
  1185. {
  1186. u16 jkey = from_kuid(current_user_ns(), uid) & HFI1_JKEY_MASK;
  1187. if (capable(CAP_SYS_ADMIN))
  1188. jkey &= HFI1_ADMIN_JKEY_RANGE - 1;
  1189. else if (jkey < 64)
  1190. jkey |= BIT(HFI1_JKEY_WIDTH - 1);
  1191. return jkey;
  1192. }
  1193. /*
  1194. * active_egress_rate
  1195. *
  1196. * returns the active egress rate in units of [10^6 bits/sec]
  1197. */
  1198. static inline u32 active_egress_rate(struct hfi1_pportdata *ppd)
  1199. {
  1200. u16 link_speed = ppd->link_speed_active;
  1201. u16 link_width = ppd->link_width_active;
  1202. u32 egress_rate;
  1203. if (link_speed == OPA_LINK_SPEED_25G)
  1204. egress_rate = 25000;
  1205. else /* assume OPA_LINK_SPEED_12_5G */
  1206. egress_rate = 12500;
  1207. switch (link_width) {
  1208. case OPA_LINK_WIDTH_4X:
  1209. egress_rate *= 4;
  1210. break;
  1211. case OPA_LINK_WIDTH_3X:
  1212. egress_rate *= 3;
  1213. break;
  1214. case OPA_LINK_WIDTH_2X:
  1215. egress_rate *= 2;
  1216. break;
  1217. default:
  1218. /* assume IB_WIDTH_1X */
  1219. break;
  1220. }
  1221. return egress_rate;
  1222. }
  1223. /*
  1224. * egress_cycles
  1225. *
  1226. * Returns the number of 'fabric clock cycles' to egress a packet
  1227. * of length 'len' bytes, at 'rate' Mbit/s. Since the fabric clock
  1228. * rate is (approximately) 805 MHz, the units of the returned value
  1229. * are (1/805 MHz).
  1230. */
  1231. static inline u32 egress_cycles(u32 len, u32 rate)
  1232. {
  1233. u32 cycles;
  1234. /*
  1235. * cycles is:
  1236. *
  1237. * (length) [bits] / (rate) [bits/sec]
  1238. * ---------------------------------------------------
  1239. * fabric_clock_period == 1 /(805 * 10^6) [cycles/sec]
  1240. */
  1241. cycles = len * 8; /* bits */
  1242. cycles *= 805;
  1243. cycles /= rate;
  1244. return cycles;
  1245. }
  1246. void set_link_ipg(struct hfi1_pportdata *ppd);
  1247. void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
  1248. u32 rqpn, u8 svc_type);
  1249. void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
  1250. u32 pkey, u32 slid, u32 dlid, u8 sc5,
  1251. const struct ib_grh *old_grh);
  1252. #define PKEY_CHECK_INVALID -1
  1253. int egress_pkey_check(struct hfi1_pportdata *ppd, __be16 *lrh, __be32 *bth,
  1254. u8 sc5, int8_t s_pkey_index);
  1255. #define PACKET_EGRESS_TIMEOUT 350
  1256. static inline void pause_for_credit_return(struct hfi1_devdata *dd)
  1257. {
  1258. /* Pause at least 1us, to ensure chip returns all credits */
  1259. u32 usec = cclock_to_ns(dd, PACKET_EGRESS_TIMEOUT) / 1000;
  1260. udelay(usec ? usec : 1);
  1261. }
  1262. /**
  1263. * sc_to_vlt() reverse lookup sc to vl
  1264. * @dd - devdata
  1265. * @sc5 - 5 bit sc
  1266. */
  1267. static inline u8 sc_to_vlt(struct hfi1_devdata *dd, u8 sc5)
  1268. {
  1269. unsigned seq;
  1270. u8 rval;
  1271. if (sc5 >= OPA_MAX_SCS)
  1272. return (u8)(0xff);
  1273. do {
  1274. seq = read_seqbegin(&dd->sc2vl_lock);
  1275. rval = *(((u8 *)dd->sc2vl) + sc5);
  1276. } while (read_seqretry(&dd->sc2vl_lock, seq));
  1277. return rval;
  1278. }
  1279. #define PKEY_MEMBER_MASK 0x8000
  1280. #define PKEY_LOW_15_MASK 0x7fff
  1281. /*
  1282. * ingress_pkey_matches_entry - return 1 if the pkey matches ent (ent
  1283. * being an entry from the ingress partition key table), return 0
  1284. * otherwise. Use the matching criteria for ingress partition keys
  1285. * specified in the OPAv1 spec., section 9.10.14.
  1286. */
  1287. static inline int ingress_pkey_matches_entry(u16 pkey, u16 ent)
  1288. {
  1289. u16 mkey = pkey & PKEY_LOW_15_MASK;
  1290. u16 ment = ent & PKEY_LOW_15_MASK;
  1291. if (mkey == ment) {
  1292. /*
  1293. * If pkey[15] is clear (limited partition member),
  1294. * is bit 15 in the corresponding table element
  1295. * clear (limited member)?
  1296. */
  1297. if (!(pkey & PKEY_MEMBER_MASK))
  1298. return !!(ent & PKEY_MEMBER_MASK);
  1299. return 1;
  1300. }
  1301. return 0;
  1302. }
  1303. /*
  1304. * ingress_pkey_table_search - search the entire pkey table for
  1305. * an entry which matches 'pkey'. return 0 if a match is found,
  1306. * and 1 otherwise.
  1307. */
  1308. static int ingress_pkey_table_search(struct hfi1_pportdata *ppd, u16 pkey)
  1309. {
  1310. int i;
  1311. for (i = 0; i < MAX_PKEY_VALUES; i++) {
  1312. if (ingress_pkey_matches_entry(pkey, ppd->pkeys[i]))
  1313. return 0;
  1314. }
  1315. return 1;
  1316. }
  1317. /*
  1318. * ingress_pkey_table_fail - record a failure of ingress pkey validation,
  1319. * i.e., increment port_rcv_constraint_errors for the port, and record
  1320. * the 'error info' for this failure.
  1321. */
  1322. static void ingress_pkey_table_fail(struct hfi1_pportdata *ppd, u16 pkey,
  1323. u16 slid)
  1324. {
  1325. struct hfi1_devdata *dd = ppd->dd;
  1326. incr_cntr64(&ppd->port_rcv_constraint_errors);
  1327. if (!(dd->err_info_rcv_constraint.status & OPA_EI_STATUS_SMASK)) {
  1328. dd->err_info_rcv_constraint.status |= OPA_EI_STATUS_SMASK;
  1329. dd->err_info_rcv_constraint.slid = slid;
  1330. dd->err_info_rcv_constraint.pkey = pkey;
  1331. }
  1332. }
  1333. /*
  1334. * ingress_pkey_check - Return 0 if the ingress pkey is valid, return 1
  1335. * otherwise. Use the criteria in the OPAv1 spec, section 9.10.14. idx
  1336. * is a hint as to the best place in the partition key table to begin
  1337. * searching. This function should not be called on the data path because
  1338. * of performance reasons. On datapath pkey check is expected to be done
  1339. * by HW and rcv_pkey_check function should be called instead.
  1340. */
  1341. static inline int ingress_pkey_check(struct hfi1_pportdata *ppd, u16 pkey,
  1342. u8 sc5, u8 idx, u16 slid)
  1343. {
  1344. if (!(ppd->part_enforce & HFI1_PART_ENFORCE_IN))
  1345. return 0;
  1346. /* If SC15, pkey[0:14] must be 0x7fff */
  1347. if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
  1348. goto bad;
  1349. /* Is the pkey = 0x0, or 0x8000? */
  1350. if ((pkey & PKEY_LOW_15_MASK) == 0)
  1351. goto bad;
  1352. /* The most likely matching pkey has index 'idx' */
  1353. if (ingress_pkey_matches_entry(pkey, ppd->pkeys[idx]))
  1354. return 0;
  1355. /* no match - try the whole table */
  1356. if (!ingress_pkey_table_search(ppd, pkey))
  1357. return 0;
  1358. bad:
  1359. ingress_pkey_table_fail(ppd, pkey, slid);
  1360. return 1;
  1361. }
  1362. /*
  1363. * rcv_pkey_check - Return 0 if the ingress pkey is valid, return 1
  1364. * otherwise. It only ensures pkey is vlid for QP0. This function
  1365. * should be called on the data path instead of ingress_pkey_check
  1366. * as on data path, pkey check is done by HW (except for QP0).
  1367. */
  1368. static inline int rcv_pkey_check(struct hfi1_pportdata *ppd, u16 pkey,
  1369. u8 sc5, u16 slid)
  1370. {
  1371. if (!(ppd->part_enforce & HFI1_PART_ENFORCE_IN))
  1372. return 0;
  1373. /* If SC15, pkey[0:14] must be 0x7fff */
  1374. if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
  1375. goto bad;
  1376. return 0;
  1377. bad:
  1378. ingress_pkey_table_fail(ppd, pkey, slid);
  1379. return 1;
  1380. }
  1381. /* MTU handling */
  1382. /* MTU enumeration, 256-4k match IB */
  1383. #define OPA_MTU_0 0
  1384. #define OPA_MTU_256 1
  1385. #define OPA_MTU_512 2
  1386. #define OPA_MTU_1024 3
  1387. #define OPA_MTU_2048 4
  1388. #define OPA_MTU_4096 5
  1389. u32 lrh_max_header_bytes(struct hfi1_devdata *dd);
  1390. int mtu_to_enum(u32 mtu, int default_if_bad);
  1391. u16 enum_to_mtu(int mtu);
  1392. static inline int valid_ib_mtu(unsigned int mtu)
  1393. {
  1394. return mtu == 256 || mtu == 512 ||
  1395. mtu == 1024 || mtu == 2048 ||
  1396. mtu == 4096;
  1397. }
  1398. static inline int valid_opa_max_mtu(unsigned int mtu)
  1399. {
  1400. return mtu >= 2048 &&
  1401. (valid_ib_mtu(mtu) || mtu == 8192 || mtu == 10240);
  1402. }
  1403. int set_mtu(struct hfi1_pportdata *ppd);
  1404. int hfi1_set_lid(struct hfi1_pportdata *ppd, u32 lid, u8 lmc);
  1405. void hfi1_disable_after_error(struct hfi1_devdata *dd);
  1406. int hfi1_set_uevent_bits(struct hfi1_pportdata *ppd, const int evtbit);
  1407. int hfi1_rcvbuf_validate(u32 size, u8 type, u16 *encode);
  1408. int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t);
  1409. int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t);
  1410. void set_up_vau(struct hfi1_devdata *dd, u8 vau);
  1411. void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf);
  1412. void reset_link_credits(struct hfi1_devdata *dd);
  1413. void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu);
  1414. int set_buffer_control(struct hfi1_pportdata *ppd, struct buffer_control *bc);
  1415. static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd)
  1416. {
  1417. return ppd->dd;
  1418. }
  1419. static inline struct hfi1_devdata *dd_from_dev(struct hfi1_ibdev *dev)
  1420. {
  1421. return container_of(dev, struct hfi1_devdata, verbs_dev);
  1422. }
  1423. static inline struct hfi1_devdata *dd_from_ibdev(struct ib_device *ibdev)
  1424. {
  1425. return dd_from_dev(to_idev(ibdev));
  1426. }
  1427. static inline struct hfi1_pportdata *ppd_from_ibp(struct hfi1_ibport *ibp)
  1428. {
  1429. return container_of(ibp, struct hfi1_pportdata, ibport_data);
  1430. }
  1431. static inline struct hfi1_ibdev *dev_from_rdi(struct rvt_dev_info *rdi)
  1432. {
  1433. return container_of(rdi, struct hfi1_ibdev, rdi);
  1434. }
  1435. static inline struct hfi1_ibport *to_iport(struct ib_device *ibdev, u8 port)
  1436. {
  1437. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1438. unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
  1439. WARN_ON(pidx >= dd->num_pports);
  1440. return &dd->pport[pidx].ibport_data;
  1441. }
  1442. static inline struct hfi1_ibport *rcd_to_iport(struct hfi1_ctxtdata *rcd)
  1443. {
  1444. return &rcd->ppd->ibport_data;
  1445. }
  1446. void hfi1_process_ecn_slowpath(struct rvt_qp *qp, struct hfi1_packet *pkt,
  1447. bool do_cnp);
  1448. static inline bool process_ecn(struct rvt_qp *qp, struct hfi1_packet *pkt,
  1449. bool do_cnp)
  1450. {
  1451. struct ib_other_headers *ohdr = pkt->ohdr;
  1452. u32 bth1;
  1453. bth1 = be32_to_cpu(ohdr->bth[1]);
  1454. if (unlikely(bth1 & (IB_BECN_SMASK | IB_FECN_SMASK))) {
  1455. hfi1_process_ecn_slowpath(qp, pkt, do_cnp);
  1456. return !!(bth1 & IB_FECN_SMASK);
  1457. }
  1458. return false;
  1459. }
  1460. /*
  1461. * Return the indexed PKEY from the port PKEY table.
  1462. */
  1463. static inline u16 hfi1_get_pkey(struct hfi1_ibport *ibp, unsigned index)
  1464. {
  1465. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  1466. u16 ret;
  1467. if (index >= ARRAY_SIZE(ppd->pkeys))
  1468. ret = 0;
  1469. else
  1470. ret = ppd->pkeys[index];
  1471. return ret;
  1472. }
  1473. /*
  1474. * Return the indexed GUID from the port GUIDs table.
  1475. */
  1476. static inline __be64 get_sguid(struct hfi1_ibport *ibp, unsigned int index)
  1477. {
  1478. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  1479. WARN_ON(index >= HFI1_GUIDS_PER_PORT);
  1480. return cpu_to_be64(ppd->guids[index]);
  1481. }
  1482. /*
  1483. * Called by readers of cc_state only, must call under rcu_read_lock().
  1484. */
  1485. static inline struct cc_state *get_cc_state(struct hfi1_pportdata *ppd)
  1486. {
  1487. return rcu_dereference(ppd->cc_state);
  1488. }
  1489. /*
  1490. * Called by writers of cc_state only, must call under cc_state_lock.
  1491. */
  1492. static inline
  1493. struct cc_state *get_cc_state_protected(struct hfi1_pportdata *ppd)
  1494. {
  1495. return rcu_dereference_protected(ppd->cc_state,
  1496. lockdep_is_held(&ppd->cc_state_lock));
  1497. }
  1498. /*
  1499. * values for dd->flags (_device_ related flags)
  1500. */
  1501. #define HFI1_INITTED 0x1 /* chip and driver up and initted */
  1502. #define HFI1_PRESENT 0x2 /* chip accesses can be done */
  1503. #define HFI1_FROZEN 0x4 /* chip in SPC freeze */
  1504. #define HFI1_HAS_SDMA_TIMEOUT 0x8
  1505. #define HFI1_HAS_SEND_DMA 0x10 /* Supports Send DMA */
  1506. #define HFI1_FORCED_FREEZE 0x80 /* driver forced freeze mode */
  1507. /* IB dword length mask in PBC (lower 11 bits); same for all chips */
  1508. #define HFI1_PBC_LENGTH_MASK ((1 << 11) - 1)
  1509. /* ctxt_flag bit offsets */
  1510. /* base context has not finished initializing */
  1511. #define HFI1_CTXT_BASE_UNINIT 1
  1512. /* base context initaliation failed */
  1513. #define HFI1_CTXT_BASE_FAILED 2
  1514. /* waiting for a packet to arrive */
  1515. #define HFI1_CTXT_WAITING_RCV 3
  1516. /* waiting for an urgent packet to arrive */
  1517. #define HFI1_CTXT_WAITING_URG 4
  1518. /* free up any allocated data at closes */
  1519. struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
  1520. const struct pci_device_id *ent);
  1521. void hfi1_free_devdata(struct hfi1_devdata *dd);
  1522. struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra);
  1523. /* LED beaconing functions */
  1524. void hfi1_start_led_override(struct hfi1_pportdata *ppd, unsigned int timeon,
  1525. unsigned int timeoff);
  1526. void shutdown_led_override(struct hfi1_pportdata *ppd);
  1527. #define HFI1_CREDIT_RETURN_RATE (100)
  1528. /*
  1529. * The number of words for the KDETH protocol field. If this is
  1530. * larger then the actual field used, then part of the payload
  1531. * will be in the header.
  1532. *
  1533. * Optimally, we want this sized so that a typical case will
  1534. * use full cache lines. The typical local KDETH header would
  1535. * be:
  1536. *
  1537. * Bytes Field
  1538. * 8 LRH
  1539. * 12 BHT
  1540. * ?? KDETH
  1541. * 8 RHF
  1542. * ---
  1543. * 28 + KDETH
  1544. *
  1545. * For a 64-byte cache line, KDETH would need to be 36 bytes or 9 DWORDS
  1546. */
  1547. #define DEFAULT_RCVHDRSIZE 9
  1548. /*
  1549. * Maximal header byte count:
  1550. *
  1551. * Bytes Field
  1552. * 8 LRH
  1553. * 40 GRH (optional)
  1554. * 12 BTH
  1555. * ?? KDETH
  1556. * 8 RHF
  1557. * ---
  1558. * 68 + KDETH
  1559. *
  1560. * We also want to maintain a cache line alignment to assist DMA'ing
  1561. * of the header bytes. Round up to a good size.
  1562. */
  1563. #define DEFAULT_RCVHDR_ENTSIZE 32
  1564. bool hfi1_can_pin_pages(struct hfi1_devdata *dd, struct mm_struct *mm,
  1565. u32 nlocked, u32 npages);
  1566. int hfi1_acquire_user_pages(struct mm_struct *mm, unsigned long vaddr,
  1567. size_t npages, bool writable, struct page **pages);
  1568. void hfi1_release_user_pages(struct mm_struct *mm, struct page **p,
  1569. size_t npages, bool dirty);
  1570. static inline void clear_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
  1571. {
  1572. *((u64 *)rcd->rcvhdrtail_kvaddr) = 0ULL;
  1573. }
  1574. static inline u32 get_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
  1575. {
  1576. /*
  1577. * volatile because it's a DMA target from the chip, routine is
  1578. * inlined, and don't want register caching or reordering.
  1579. */
  1580. return (u32)le64_to_cpu(*rcd->rcvhdrtail_kvaddr);
  1581. }
  1582. /*
  1583. * sysfs interface.
  1584. */
  1585. extern const char ib_hfi1_version[];
  1586. int hfi1_device_create(struct hfi1_devdata *dd);
  1587. void hfi1_device_remove(struct hfi1_devdata *dd);
  1588. int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
  1589. struct kobject *kobj);
  1590. int hfi1_verbs_register_sysfs(struct hfi1_devdata *dd);
  1591. void hfi1_verbs_unregister_sysfs(struct hfi1_devdata *dd);
  1592. /* Hook for sysfs read of QSFP */
  1593. int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len);
  1594. int hfi1_pcie_init(struct pci_dev *pdev, const struct pci_device_id *ent);
  1595. void hfi1_pcie_cleanup(struct pci_dev *pdev);
  1596. int hfi1_pcie_ddinit(struct hfi1_devdata *dd, struct pci_dev *pdev);
  1597. void hfi1_pcie_ddcleanup(struct hfi1_devdata *);
  1598. int pcie_speeds(struct hfi1_devdata *dd);
  1599. void request_msix(struct hfi1_devdata *dd, u32 *nent,
  1600. struct hfi1_msix_entry *entry);
  1601. void hfi1_enable_intx(struct pci_dev *pdev);
  1602. void restore_pci_variables(struct hfi1_devdata *dd);
  1603. int do_pcie_gen3_transition(struct hfi1_devdata *dd);
  1604. int parse_platform_config(struct hfi1_devdata *dd);
  1605. int get_platform_config_field(struct hfi1_devdata *dd,
  1606. enum platform_config_table_type_encoding
  1607. table_type, int table_index, int field_index,
  1608. u32 *data, u32 len);
  1609. const char *get_unit_name(int unit);
  1610. const char *get_card_name(struct rvt_dev_info *rdi);
  1611. struct pci_dev *get_pci_dev(struct rvt_dev_info *rdi);
  1612. /*
  1613. * Flush write combining store buffers (if present) and perform a write
  1614. * barrier.
  1615. */
  1616. static inline void flush_wc(void)
  1617. {
  1618. asm volatile("sfence" : : : "memory");
  1619. }
  1620. void handle_eflags(struct hfi1_packet *packet);
  1621. int process_receive_ib(struct hfi1_packet *packet);
  1622. int process_receive_bypass(struct hfi1_packet *packet);
  1623. int process_receive_error(struct hfi1_packet *packet);
  1624. int kdeth_process_expected(struct hfi1_packet *packet);
  1625. int kdeth_process_eager(struct hfi1_packet *packet);
  1626. int process_receive_invalid(struct hfi1_packet *packet);
  1627. /* global module parameter variables */
  1628. extern unsigned int hfi1_max_mtu;
  1629. extern unsigned int hfi1_cu;
  1630. extern unsigned int user_credit_return_threshold;
  1631. extern int num_user_contexts;
  1632. extern unsigned long n_krcvqs;
  1633. extern uint krcvqs[];
  1634. extern int krcvqsset;
  1635. extern uint kdeth_qp;
  1636. extern uint loopback;
  1637. extern uint quick_linkup;
  1638. extern uint rcv_intr_timeout;
  1639. extern uint rcv_intr_count;
  1640. extern uint rcv_intr_dynamic;
  1641. extern ushort link_crc_mask;
  1642. extern struct mutex hfi1_mutex;
  1643. /* Number of seconds before our card status check... */
  1644. #define STATUS_TIMEOUT 60
  1645. #define DRIVER_NAME "hfi1"
  1646. #define HFI1_USER_MINOR_BASE 0
  1647. #define HFI1_TRACE_MINOR 127
  1648. #define HFI1_NMINORS 255
  1649. #define PCI_VENDOR_ID_INTEL 0x8086
  1650. #define PCI_DEVICE_ID_INTEL0 0x24f0
  1651. #define PCI_DEVICE_ID_INTEL1 0x24f1
  1652. #define HFI1_PKT_USER_SC_INTEGRITY \
  1653. (SEND_CTXT_CHECK_ENABLE_DISALLOW_NON_KDETH_PACKETS_SMASK \
  1654. | SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK \
  1655. | SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_SMASK \
  1656. | SEND_CTXT_CHECK_ENABLE_DISALLOW_GRH_SMASK)
  1657. #define HFI1_PKT_KERNEL_SC_INTEGRITY \
  1658. (SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK)
  1659. static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd,
  1660. u16 ctxt_type)
  1661. {
  1662. u64 base_sc_integrity;
  1663. /* No integrity checks if HFI1_CAP_NO_INTEGRITY is set */
  1664. if (HFI1_CAP_IS_KSET(NO_INTEGRITY))
  1665. return 0;
  1666. base_sc_integrity =
  1667. SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
  1668. | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK
  1669. | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
  1670. | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
  1671. | SEND_CTXT_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
  1672. | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_TEST_SMASK
  1673. | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_SMALL_BYPASS_PACKETS_SMASK
  1674. | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_SMALL_IB_PACKETS_SMASK
  1675. | SEND_CTXT_CHECK_ENABLE_DISALLOW_RAW_IPV6_SMASK
  1676. | SEND_CTXT_CHECK_ENABLE_DISALLOW_RAW_SMASK
  1677. | SEND_CTXT_CHECK_ENABLE_CHECK_BYPASS_VL_MAPPING_SMASK
  1678. | SEND_CTXT_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
  1679. | SEND_CTXT_CHECK_ENABLE_CHECK_OPCODE_SMASK
  1680. | SEND_CTXT_CHECK_ENABLE_CHECK_SLID_SMASK
  1681. | SEND_CTXT_CHECK_ENABLE_CHECK_VL_SMASK
  1682. | SEND_CTXT_CHECK_ENABLE_CHECK_ENABLE_SMASK;
  1683. if (ctxt_type == SC_USER)
  1684. base_sc_integrity |= HFI1_PKT_USER_SC_INTEGRITY;
  1685. else
  1686. base_sc_integrity |= HFI1_PKT_KERNEL_SC_INTEGRITY;
  1687. /* turn on send-side job key checks if !A0 */
  1688. if (!is_ax(dd))
  1689. base_sc_integrity |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  1690. return base_sc_integrity;
  1691. }
  1692. static inline u64 hfi1_pkt_base_sdma_integrity(struct hfi1_devdata *dd)
  1693. {
  1694. u64 base_sdma_integrity;
  1695. /* No integrity checks if HFI1_CAP_NO_INTEGRITY is set */
  1696. if (HFI1_CAP_IS_KSET(NO_INTEGRITY))
  1697. return 0;
  1698. base_sdma_integrity =
  1699. SEND_DMA_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
  1700. | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
  1701. | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
  1702. | SEND_DMA_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
  1703. | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_SMALL_BYPASS_PACKETS_SMASK
  1704. | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_SMALL_IB_PACKETS_SMASK
  1705. | SEND_DMA_CHECK_ENABLE_DISALLOW_RAW_IPV6_SMASK
  1706. | SEND_DMA_CHECK_ENABLE_DISALLOW_RAW_SMASK
  1707. | SEND_DMA_CHECK_ENABLE_CHECK_BYPASS_VL_MAPPING_SMASK
  1708. | SEND_DMA_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
  1709. | SEND_DMA_CHECK_ENABLE_CHECK_OPCODE_SMASK
  1710. | SEND_DMA_CHECK_ENABLE_CHECK_SLID_SMASK
  1711. | SEND_DMA_CHECK_ENABLE_CHECK_VL_SMASK
  1712. | SEND_DMA_CHECK_ENABLE_CHECK_ENABLE_SMASK;
  1713. if (!HFI1_CAP_IS_KSET(STATIC_RATE_CTRL))
  1714. base_sdma_integrity |=
  1715. SEND_DMA_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK;
  1716. /* turn on send-side job key checks if !A0 */
  1717. if (!is_ax(dd))
  1718. base_sdma_integrity |=
  1719. SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  1720. return base_sdma_integrity;
  1721. }
  1722. /*
  1723. * hfi1_early_err is used (only!) to print early errors before devdata is
  1724. * allocated, or when dd->pcidev may not be valid, and at the tail end of
  1725. * cleanup when devdata may have been freed, etc. hfi1_dev_porterr is
  1726. * the same as dd_dev_err, but is used when the message really needs
  1727. * the IB port# to be definitive as to what's happening..
  1728. */
  1729. #define hfi1_early_err(dev, fmt, ...) \
  1730. dev_err(dev, fmt, ##__VA_ARGS__)
  1731. #define hfi1_early_info(dev, fmt, ...) \
  1732. dev_info(dev, fmt, ##__VA_ARGS__)
  1733. #define dd_dev_emerg(dd, fmt, ...) \
  1734. dev_emerg(&(dd)->pcidev->dev, "%s: " fmt, \
  1735. get_unit_name((dd)->unit), ##__VA_ARGS__)
  1736. #define dd_dev_err(dd, fmt, ...) \
  1737. dev_err(&(dd)->pcidev->dev, "%s: " fmt, \
  1738. get_unit_name((dd)->unit), ##__VA_ARGS__)
  1739. #define dd_dev_warn(dd, fmt, ...) \
  1740. dev_warn(&(dd)->pcidev->dev, "%s: " fmt, \
  1741. get_unit_name((dd)->unit), ##__VA_ARGS__)
  1742. #define dd_dev_warn_ratelimited(dd, fmt, ...) \
  1743. dev_warn_ratelimited(&(dd)->pcidev->dev, "%s: " fmt, \
  1744. get_unit_name((dd)->unit), ##__VA_ARGS__)
  1745. #define dd_dev_info(dd, fmt, ...) \
  1746. dev_info(&(dd)->pcidev->dev, "%s: " fmt, \
  1747. get_unit_name((dd)->unit), ##__VA_ARGS__)
  1748. #define dd_dev_info_ratelimited(dd, fmt, ...) \
  1749. dev_info_ratelimited(&(dd)->pcidev->dev, "%s: " fmt, \
  1750. get_unit_name((dd)->unit), ##__VA_ARGS__)
  1751. #define dd_dev_dbg(dd, fmt, ...) \
  1752. dev_dbg(&(dd)->pcidev->dev, "%s: " fmt, \
  1753. get_unit_name((dd)->unit), ##__VA_ARGS__)
  1754. #define hfi1_dev_porterr(dd, port, fmt, ...) \
  1755. dev_err(&(dd)->pcidev->dev, "%s: port %u: " fmt, \
  1756. get_unit_name((dd)->unit), (port), ##__VA_ARGS__)
  1757. /*
  1758. * this is used for formatting hw error messages...
  1759. */
  1760. struct hfi1_hwerror_msgs {
  1761. u64 mask;
  1762. const char *msg;
  1763. size_t sz;
  1764. };
  1765. /* in intr.c... */
  1766. void hfi1_format_hwerrors(u64 hwerrs,
  1767. const struct hfi1_hwerror_msgs *hwerrmsgs,
  1768. size_t nhwerrmsgs, char *msg, size_t lmsg);
  1769. #define USER_OPCODE_CHECK_VAL 0xC0
  1770. #define USER_OPCODE_CHECK_MASK 0xC0
  1771. #define OPCODE_CHECK_VAL_DISABLED 0x0
  1772. #define OPCODE_CHECK_MASK_DISABLED 0x0
  1773. static inline void hfi1_reset_cpu_counters(struct hfi1_devdata *dd)
  1774. {
  1775. struct hfi1_pportdata *ppd;
  1776. int i;
  1777. dd->z_int_counter = get_all_cpu_total(dd->int_counter);
  1778. dd->z_rcv_limit = get_all_cpu_total(dd->rcv_limit);
  1779. dd->z_send_schedule = get_all_cpu_total(dd->send_schedule);
  1780. ppd = (struct hfi1_pportdata *)(dd + 1);
  1781. for (i = 0; i < dd->num_pports; i++, ppd++) {
  1782. ppd->ibport_data.rvp.z_rc_acks =
  1783. get_all_cpu_total(ppd->ibport_data.rvp.rc_acks);
  1784. ppd->ibport_data.rvp.z_rc_qacks =
  1785. get_all_cpu_total(ppd->ibport_data.rvp.rc_qacks);
  1786. }
  1787. }
  1788. /* Control LED state */
  1789. static inline void setextled(struct hfi1_devdata *dd, u32 on)
  1790. {
  1791. if (on)
  1792. write_csr(dd, DCC_CFG_LED_CNTRL, 0x1F);
  1793. else
  1794. write_csr(dd, DCC_CFG_LED_CNTRL, 0x10);
  1795. }
  1796. /* return the i2c resource given the target */
  1797. static inline u32 i2c_target(u32 target)
  1798. {
  1799. return target ? CR_I2C2 : CR_I2C1;
  1800. }
  1801. /* return the i2c chain chip resource that this HFI uses for QSFP */
  1802. static inline u32 qsfp_resource(struct hfi1_devdata *dd)
  1803. {
  1804. return i2c_target(dd->hfi1_id);
  1805. }
  1806. /* Is this device integrated or discrete? */
  1807. static inline bool is_integrated(struct hfi1_devdata *dd)
  1808. {
  1809. return dd->pcidev->device == PCI_DEVICE_ID_INTEL1;
  1810. }
  1811. int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp);
  1812. #define DD_DEV_ENTRY(dd) __string(dev, dev_name(&(dd)->pcidev->dev))
  1813. #define DD_DEV_ASSIGN(dd) __assign_str(dev, dev_name(&(dd)->pcidev->dev))
  1814. #define packettype_name(etype) { RHF_RCV_TYPE_##etype, #etype }
  1815. #define show_packettype(etype) \
  1816. __print_symbolic(etype, \
  1817. packettype_name(EXPECTED), \
  1818. packettype_name(EAGER), \
  1819. packettype_name(IB), \
  1820. packettype_name(ERROR), \
  1821. packettype_name(BYPASS))
  1822. #define ib_opcode_name(opcode) { IB_OPCODE_##opcode, #opcode }
  1823. #define show_ib_opcode(opcode) \
  1824. __print_symbolic(opcode, \
  1825. ib_opcode_name(RC_SEND_FIRST), \
  1826. ib_opcode_name(RC_SEND_MIDDLE), \
  1827. ib_opcode_name(RC_SEND_LAST), \
  1828. ib_opcode_name(RC_SEND_LAST_WITH_IMMEDIATE), \
  1829. ib_opcode_name(RC_SEND_ONLY), \
  1830. ib_opcode_name(RC_SEND_ONLY_WITH_IMMEDIATE), \
  1831. ib_opcode_name(RC_RDMA_WRITE_FIRST), \
  1832. ib_opcode_name(RC_RDMA_WRITE_MIDDLE), \
  1833. ib_opcode_name(RC_RDMA_WRITE_LAST), \
  1834. ib_opcode_name(RC_RDMA_WRITE_LAST_WITH_IMMEDIATE), \
  1835. ib_opcode_name(RC_RDMA_WRITE_ONLY), \
  1836. ib_opcode_name(RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE), \
  1837. ib_opcode_name(RC_RDMA_READ_REQUEST), \
  1838. ib_opcode_name(RC_RDMA_READ_RESPONSE_FIRST), \
  1839. ib_opcode_name(RC_RDMA_READ_RESPONSE_MIDDLE), \
  1840. ib_opcode_name(RC_RDMA_READ_RESPONSE_LAST), \
  1841. ib_opcode_name(RC_RDMA_READ_RESPONSE_ONLY), \
  1842. ib_opcode_name(RC_ACKNOWLEDGE), \
  1843. ib_opcode_name(RC_ATOMIC_ACKNOWLEDGE), \
  1844. ib_opcode_name(RC_COMPARE_SWAP), \
  1845. ib_opcode_name(RC_FETCH_ADD), \
  1846. ib_opcode_name(UC_SEND_FIRST), \
  1847. ib_opcode_name(UC_SEND_MIDDLE), \
  1848. ib_opcode_name(UC_SEND_LAST), \
  1849. ib_opcode_name(UC_SEND_LAST_WITH_IMMEDIATE), \
  1850. ib_opcode_name(UC_SEND_ONLY), \
  1851. ib_opcode_name(UC_SEND_ONLY_WITH_IMMEDIATE), \
  1852. ib_opcode_name(UC_RDMA_WRITE_FIRST), \
  1853. ib_opcode_name(UC_RDMA_WRITE_MIDDLE), \
  1854. ib_opcode_name(UC_RDMA_WRITE_LAST), \
  1855. ib_opcode_name(UC_RDMA_WRITE_LAST_WITH_IMMEDIATE), \
  1856. ib_opcode_name(UC_RDMA_WRITE_ONLY), \
  1857. ib_opcode_name(UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE), \
  1858. ib_opcode_name(UD_SEND_ONLY), \
  1859. ib_opcode_name(UD_SEND_ONLY_WITH_IMMEDIATE), \
  1860. ib_opcode_name(CNP))
  1861. #endif /* _HFI1_KERNEL_H */