hfi.h 62 KB

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