hfi.h 73 KB

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