ntb_hw_gen1.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2012 Intel Corporation. All rights reserved.
  8. * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
  9. * Copyright (C) 2016 T-Platforms. All Rights Reserved.
  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. * BSD LICENSE
  16. *
  17. * Copyright(c) 2012 Intel Corporation. All rights reserved.
  18. * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
  19. * Copyright (C) 2016 T-Platforms. All Rights Reserved.
  20. *
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions
  23. * are met:
  24. *
  25. * * Redistributions of source code must retain the above copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * * Redistributions in binary form must reproduce the above copy
  28. * notice, this list of conditions and the following disclaimer in
  29. * the documentation and/or other materials provided with the
  30. * distribution.
  31. * * Neither the name of Intel Corporation nor the names of its
  32. * contributors may be used to endorse or promote products derived
  33. * from this software without specific prior written permission.
  34. *
  35. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  36. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  37. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  38. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  39. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  42. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  43. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  45. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. * Intel PCIe NTB Linux driver
  48. */
  49. #include <linux/debugfs.h>
  50. #include <linux/delay.h>
  51. #include <linux/init.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/module.h>
  54. #include <linux/pci.h>
  55. #include <linux/random.h>
  56. #include <linux/slab.h>
  57. #include <linux/ntb.h>
  58. #include "ntb_hw_intel.h"
  59. #include "ntb_hw_gen1.h"
  60. #include "ntb_hw_gen3.h"
  61. #include "ntb_hw_gen4.h"
  62. #define NTB_NAME "ntb_hw_intel"
  63. #define NTB_DESC "Intel(R) PCI-E Non-Transparent Bridge Driver"
  64. #define NTB_VER "2.0"
  65. MODULE_DESCRIPTION(NTB_DESC);
  66. MODULE_VERSION(NTB_VER);
  67. MODULE_LICENSE("Dual BSD/GPL");
  68. MODULE_AUTHOR("Intel Corporation");
  69. #define bar0_off(base, bar) ((base) + ((bar) << 2))
  70. #define bar2_off(base, bar) bar0_off(base, (bar) - 2)
  71. static const struct intel_ntb_reg xeon_reg;
  72. static const struct intel_ntb_alt_reg xeon_pri_reg;
  73. static const struct intel_ntb_alt_reg xeon_sec_reg;
  74. static const struct intel_ntb_alt_reg xeon_b2b_reg;
  75. static const struct intel_ntb_xlat_reg xeon_pri_xlat;
  76. static const struct intel_ntb_xlat_reg xeon_sec_xlat;
  77. static const struct ntb_dev_ops intel_ntb_ops;
  78. static const struct file_operations intel_ntb_debugfs_info;
  79. static struct dentry *debugfs_dir;
  80. static int b2b_mw_idx = -1;
  81. module_param(b2b_mw_idx, int, 0644);
  82. MODULE_PARM_DESC(b2b_mw_idx, "Use this mw idx to access the peer ntb. A "
  83. "value of zero or positive starts from first mw idx, and a "
  84. "negative value starts from last mw idx. Both sides MUST "
  85. "set the same value here!");
  86. static unsigned int b2b_mw_share;
  87. module_param(b2b_mw_share, uint, 0644);
  88. MODULE_PARM_DESC(b2b_mw_share, "If the b2b mw is large enough, configure the "
  89. "ntb so that the peer ntb only occupies the first half of "
  90. "the mw, so the second half can still be used as a mw. Both "
  91. "sides MUST set the same value here!");
  92. module_param_named(xeon_b2b_usd_bar2_addr64,
  93. xeon_b2b_usd_addr.bar2_addr64, ullong, 0644);
  94. MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64,
  95. "XEON B2B USD BAR 2 64-bit address");
  96. module_param_named(xeon_b2b_usd_bar4_addr64,
  97. xeon_b2b_usd_addr.bar4_addr64, ullong, 0644);
  98. MODULE_PARM_DESC(xeon_b2b_usd_bar4_addr64,
  99. "XEON B2B USD BAR 4 64-bit address");
  100. module_param_named(xeon_b2b_usd_bar4_addr32,
  101. xeon_b2b_usd_addr.bar4_addr32, ullong, 0644);
  102. MODULE_PARM_DESC(xeon_b2b_usd_bar4_addr32,
  103. "XEON B2B USD split-BAR 4 32-bit address");
  104. module_param_named(xeon_b2b_usd_bar5_addr32,
  105. xeon_b2b_usd_addr.bar5_addr32, ullong, 0644);
  106. MODULE_PARM_DESC(xeon_b2b_usd_bar5_addr32,
  107. "XEON B2B USD split-BAR 5 32-bit address");
  108. module_param_named(xeon_b2b_dsd_bar2_addr64,
  109. xeon_b2b_dsd_addr.bar2_addr64, ullong, 0644);
  110. MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64,
  111. "XEON B2B DSD BAR 2 64-bit address");
  112. module_param_named(xeon_b2b_dsd_bar4_addr64,
  113. xeon_b2b_dsd_addr.bar4_addr64, ullong, 0644);
  114. MODULE_PARM_DESC(xeon_b2b_dsd_bar4_addr64,
  115. "XEON B2B DSD BAR 4 64-bit address");
  116. module_param_named(xeon_b2b_dsd_bar4_addr32,
  117. xeon_b2b_dsd_addr.bar4_addr32, ullong, 0644);
  118. MODULE_PARM_DESC(xeon_b2b_dsd_bar4_addr32,
  119. "XEON B2B DSD split-BAR 4 32-bit address");
  120. module_param_named(xeon_b2b_dsd_bar5_addr32,
  121. xeon_b2b_dsd_addr.bar5_addr32, ullong, 0644);
  122. MODULE_PARM_DESC(xeon_b2b_dsd_bar5_addr32,
  123. "XEON B2B DSD split-BAR 5 32-bit address");
  124. static int xeon_init_isr(struct intel_ntb_dev *ndev);
  125. static inline void ndev_reset_unsafe_flags(struct intel_ntb_dev *ndev)
  126. {
  127. ndev->unsafe_flags = 0;
  128. ndev->unsafe_flags_ignore = 0;
  129. /* Only B2B has a workaround to avoid SDOORBELL */
  130. if (ndev->hwerr_flags & NTB_HWERR_SDOORBELL_LOCKUP)
  131. if (!ntb_topo_is_b2b(ndev->ntb.topo))
  132. ndev->unsafe_flags |= NTB_UNSAFE_DB;
  133. /* No low level workaround to avoid SB01BASE */
  134. if (ndev->hwerr_flags & NTB_HWERR_SB01BASE_LOCKUP) {
  135. ndev->unsafe_flags |= NTB_UNSAFE_DB;
  136. ndev->unsafe_flags |= NTB_UNSAFE_SPAD;
  137. }
  138. }
  139. static inline int ndev_is_unsafe(struct intel_ntb_dev *ndev,
  140. unsigned long flag)
  141. {
  142. return !!(flag & ndev->unsafe_flags & ~ndev->unsafe_flags_ignore);
  143. }
  144. static inline int ndev_ignore_unsafe(struct intel_ntb_dev *ndev,
  145. unsigned long flag)
  146. {
  147. flag &= ndev->unsafe_flags;
  148. ndev->unsafe_flags_ignore |= flag;
  149. return !!flag;
  150. }
  151. int ndev_mw_to_bar(struct intel_ntb_dev *ndev, int idx)
  152. {
  153. if (idx < 0 || idx >= ndev->mw_count)
  154. return -EINVAL;
  155. return ndev->reg->mw_bar[idx];
  156. }
  157. void ndev_db_addr(struct intel_ntb_dev *ndev,
  158. phys_addr_t *db_addr, resource_size_t *db_size,
  159. phys_addr_t reg_addr, unsigned long reg)
  160. {
  161. if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
  162. pr_warn_once("%s: NTB unsafe doorbell access", __func__);
  163. if (db_addr) {
  164. *db_addr = reg_addr + reg;
  165. dev_dbg(&ndev->ntb.pdev->dev, "Peer db addr %llx\n", *db_addr);
  166. }
  167. if (db_size) {
  168. *db_size = ndev->reg->db_size;
  169. dev_dbg(&ndev->ntb.pdev->dev, "Peer db size %llx\n", *db_size);
  170. }
  171. }
  172. u64 ndev_db_read(struct intel_ntb_dev *ndev,
  173. void __iomem *mmio)
  174. {
  175. if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
  176. pr_warn_once("%s: NTB unsafe doorbell access", __func__);
  177. return ndev->reg->db_ioread(mmio);
  178. }
  179. int ndev_db_write(struct intel_ntb_dev *ndev, u64 db_bits,
  180. void __iomem *mmio)
  181. {
  182. if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
  183. pr_warn_once("%s: NTB unsafe doorbell access", __func__);
  184. if (db_bits & ~ndev->db_valid_mask)
  185. return -EINVAL;
  186. ndev->reg->db_iowrite(db_bits, mmio);
  187. return 0;
  188. }
  189. static inline int ndev_db_set_mask(struct intel_ntb_dev *ndev, u64 db_bits,
  190. void __iomem *mmio)
  191. {
  192. unsigned long irqflags;
  193. if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
  194. pr_warn_once("%s: NTB unsafe doorbell access", __func__);
  195. if (db_bits & ~ndev->db_valid_mask)
  196. return -EINVAL;
  197. spin_lock_irqsave(&ndev->db_mask_lock, irqflags);
  198. {
  199. ndev->db_mask |= db_bits;
  200. ndev->reg->db_iowrite(ndev->db_mask, mmio);
  201. }
  202. spin_unlock_irqrestore(&ndev->db_mask_lock, irqflags);
  203. return 0;
  204. }
  205. static inline int ndev_db_clear_mask(struct intel_ntb_dev *ndev, u64 db_bits,
  206. void __iomem *mmio)
  207. {
  208. unsigned long irqflags;
  209. if (ndev_is_unsafe(ndev, NTB_UNSAFE_DB))
  210. pr_warn_once("%s: NTB unsafe doorbell access", __func__);
  211. if (db_bits & ~ndev->db_valid_mask)
  212. return -EINVAL;
  213. spin_lock_irqsave(&ndev->db_mask_lock, irqflags);
  214. {
  215. ndev->db_mask &= ~db_bits;
  216. ndev->reg->db_iowrite(ndev->db_mask, mmio);
  217. }
  218. spin_unlock_irqrestore(&ndev->db_mask_lock, irqflags);
  219. return 0;
  220. }
  221. static inline u64 ndev_vec_mask(struct intel_ntb_dev *ndev, int db_vector)
  222. {
  223. u64 shift, mask;
  224. shift = ndev->db_vec_shift;
  225. mask = BIT_ULL(shift) - 1;
  226. return mask << (shift * db_vector);
  227. }
  228. static inline int ndev_spad_addr(struct intel_ntb_dev *ndev, int idx,
  229. phys_addr_t *spad_addr, phys_addr_t reg_addr,
  230. unsigned long reg)
  231. {
  232. if (ndev_is_unsafe(ndev, NTB_UNSAFE_SPAD))
  233. pr_warn_once("%s: NTB unsafe scratchpad access", __func__);
  234. if (idx < 0 || idx >= ndev->spad_count)
  235. return -EINVAL;
  236. if (spad_addr) {
  237. *spad_addr = reg_addr + reg + (idx << 2);
  238. dev_dbg(&ndev->ntb.pdev->dev, "Peer spad addr %llx\n",
  239. *spad_addr);
  240. }
  241. return 0;
  242. }
  243. static inline u32 ndev_spad_read(struct intel_ntb_dev *ndev, int idx,
  244. void __iomem *mmio)
  245. {
  246. if (ndev_is_unsafe(ndev, NTB_UNSAFE_SPAD))
  247. pr_warn_once("%s: NTB unsafe scratchpad access", __func__);
  248. if (idx < 0 || idx >= ndev->spad_count)
  249. return 0;
  250. return ioread32(mmio + (idx << 2));
  251. }
  252. static inline int ndev_spad_write(struct intel_ntb_dev *ndev, int idx, u32 val,
  253. void __iomem *mmio)
  254. {
  255. if (ndev_is_unsafe(ndev, NTB_UNSAFE_SPAD))
  256. pr_warn_once("%s: NTB unsafe scratchpad access", __func__);
  257. if (idx < 0 || idx >= ndev->spad_count)
  258. return -EINVAL;
  259. iowrite32(val, mmio + (idx << 2));
  260. return 0;
  261. }
  262. static irqreturn_t ndev_interrupt(struct intel_ntb_dev *ndev, int vec)
  263. {
  264. u64 vec_mask;
  265. vec_mask = ndev_vec_mask(ndev, vec);
  266. if ((ndev->hwerr_flags & NTB_HWERR_MSIX_VECTOR32_BAD) && (vec == 31))
  267. vec_mask |= ndev->db_link_mask;
  268. dev_dbg(&ndev->ntb.pdev->dev, "vec %d vec_mask %llx\n", vec, vec_mask);
  269. ndev->last_ts = jiffies;
  270. if (vec_mask & ndev->db_link_mask) {
  271. if (ndev->reg->poll_link(ndev))
  272. ntb_link_event(&ndev->ntb);
  273. }
  274. if (vec_mask & ndev->db_valid_mask)
  275. ntb_db_event(&ndev->ntb, vec);
  276. return IRQ_HANDLED;
  277. }
  278. static irqreturn_t ndev_vec_isr(int irq, void *dev)
  279. {
  280. struct intel_ntb_vec *nvec = dev;
  281. dev_dbg(&nvec->ndev->ntb.pdev->dev, "irq: %d nvec->num: %d\n",
  282. irq, nvec->num);
  283. return ndev_interrupt(nvec->ndev, nvec->num);
  284. }
  285. static irqreturn_t ndev_irq_isr(int irq, void *dev)
  286. {
  287. struct intel_ntb_dev *ndev = dev;
  288. return ndev_interrupt(ndev, irq - ndev->ntb.pdev->irq);
  289. }
  290. int ndev_init_isr(struct intel_ntb_dev *ndev,
  291. int msix_min, int msix_max,
  292. int msix_shift, int total_shift)
  293. {
  294. struct pci_dev *pdev;
  295. int rc, i, msix_count, node;
  296. pdev = ndev->ntb.pdev;
  297. node = dev_to_node(&pdev->dev);
  298. /* Mask all doorbell interrupts */
  299. ndev->db_mask = ndev->db_valid_mask;
  300. ndev->reg->db_iowrite(ndev->db_mask,
  301. ndev->self_mmio +
  302. ndev->self_reg->db_mask);
  303. /* Try to set up msix irq */
  304. ndev->vec = kcalloc_node(msix_max, sizeof(*ndev->vec),
  305. GFP_KERNEL, node);
  306. if (!ndev->vec)
  307. goto err_msix_vec_alloc;
  308. ndev->msix = kcalloc_node(msix_max, sizeof(*ndev->msix),
  309. GFP_KERNEL, node);
  310. if (!ndev->msix)
  311. goto err_msix_alloc;
  312. for (i = 0; i < msix_max; ++i)
  313. ndev->msix[i].entry = i;
  314. msix_count = pci_enable_msix_range(pdev, ndev->msix,
  315. msix_min, msix_max);
  316. if (msix_count < 0)
  317. goto err_msix_enable;
  318. for (i = 0; i < msix_count; ++i) {
  319. ndev->vec[i].ndev = ndev;
  320. ndev->vec[i].num = i;
  321. rc = request_irq(ndev->msix[i].vector, ndev_vec_isr, 0,
  322. "ndev_vec_isr", &ndev->vec[i]);
  323. if (rc)
  324. goto err_msix_request;
  325. }
  326. dev_dbg(&pdev->dev, "Using %d msix interrupts\n", msix_count);
  327. ndev->db_vec_count = msix_count;
  328. ndev->db_vec_shift = msix_shift;
  329. return 0;
  330. err_msix_request:
  331. while (i-- > 0)
  332. free_irq(ndev->msix[i].vector, &ndev->vec[i]);
  333. pci_disable_msix(pdev);
  334. err_msix_enable:
  335. kfree(ndev->msix);
  336. err_msix_alloc:
  337. kfree(ndev->vec);
  338. err_msix_vec_alloc:
  339. ndev->msix = NULL;
  340. ndev->vec = NULL;
  341. /* Try to set up msi irq */
  342. rc = pci_enable_msi(pdev);
  343. if (rc)
  344. goto err_msi_enable;
  345. rc = request_irq(pdev->irq, ndev_irq_isr, 0,
  346. "ndev_irq_isr", ndev);
  347. if (rc)
  348. goto err_msi_request;
  349. dev_dbg(&pdev->dev, "Using msi interrupts\n");
  350. ndev->db_vec_count = 1;
  351. ndev->db_vec_shift = total_shift;
  352. return 0;
  353. err_msi_request:
  354. pci_disable_msi(pdev);
  355. err_msi_enable:
  356. /* Try to set up intx irq */
  357. pci_intx(pdev, 1);
  358. rc = request_irq(pdev->irq, ndev_irq_isr, IRQF_SHARED,
  359. "ndev_irq_isr", ndev);
  360. if (rc)
  361. goto err_intx_request;
  362. dev_dbg(&pdev->dev, "Using intx interrupts\n");
  363. ndev->db_vec_count = 1;
  364. ndev->db_vec_shift = total_shift;
  365. return 0;
  366. err_intx_request:
  367. return rc;
  368. }
  369. static void ndev_deinit_isr(struct intel_ntb_dev *ndev)
  370. {
  371. struct pci_dev *pdev;
  372. int i;
  373. pdev = ndev->ntb.pdev;
  374. /* Mask all doorbell interrupts */
  375. ndev->db_mask = ndev->db_valid_mask;
  376. ndev->reg->db_iowrite(ndev->db_mask,
  377. ndev->self_mmio +
  378. ndev->self_reg->db_mask);
  379. if (ndev->msix) {
  380. i = ndev->db_vec_count;
  381. while (i--)
  382. free_irq(ndev->msix[i].vector, &ndev->vec[i]);
  383. pci_disable_msix(pdev);
  384. kfree(ndev->msix);
  385. kfree(ndev->vec);
  386. } else {
  387. free_irq(pdev->irq, ndev);
  388. if (pci_dev_msi_enabled(pdev))
  389. pci_disable_msi(pdev);
  390. }
  391. }
  392. static ssize_t ndev_ntb_debugfs_read(struct file *filp, char __user *ubuf,
  393. size_t count, loff_t *offp)
  394. {
  395. struct intel_ntb_dev *ndev;
  396. struct pci_dev *pdev;
  397. void __iomem *mmio;
  398. char *buf;
  399. size_t buf_size;
  400. ssize_t ret, off;
  401. union { u64 v64; u32 v32; u16 v16; u8 v8; } u;
  402. ndev = filp->private_data;
  403. pdev = ndev->ntb.pdev;
  404. mmio = ndev->self_mmio;
  405. buf_size = min(count, 0x800ul);
  406. buf = kmalloc(buf_size, GFP_KERNEL);
  407. if (!buf)
  408. return -ENOMEM;
  409. off = 0;
  410. off += scnprintf(buf + off, buf_size - off,
  411. "NTB Device Information:\n");
  412. off += scnprintf(buf + off, buf_size - off,
  413. "Connection Topology -\t%s\n",
  414. ntb_topo_string(ndev->ntb.topo));
  415. if (ndev->b2b_idx != UINT_MAX) {
  416. off += scnprintf(buf + off, buf_size - off,
  417. "B2B MW Idx -\t\t%u\n", ndev->b2b_idx);
  418. off += scnprintf(buf + off, buf_size - off,
  419. "B2B Offset -\t\t%#lx\n", ndev->b2b_off);
  420. }
  421. off += scnprintf(buf + off, buf_size - off,
  422. "BAR4 Split -\t\t%s\n",
  423. ndev->bar4_split ? "yes" : "no");
  424. off += scnprintf(buf + off, buf_size - off,
  425. "NTB CTL -\t\t%#06x\n", ndev->ntb_ctl);
  426. off += scnprintf(buf + off, buf_size - off,
  427. "LNK STA -\t\t%#06x\n", ndev->lnk_sta);
  428. if (!ndev->reg->link_is_up(ndev)) {
  429. off += scnprintf(buf + off, buf_size - off,
  430. "Link Status -\t\tDown\n");
  431. } else {
  432. off += scnprintf(buf + off, buf_size - off,
  433. "Link Status -\t\tUp\n");
  434. off += scnprintf(buf + off, buf_size - off,
  435. "Link Speed -\t\tPCI-E Gen %u\n",
  436. NTB_LNK_STA_SPEED(ndev->lnk_sta));
  437. off += scnprintf(buf + off, buf_size - off,
  438. "Link Width -\t\tx%u\n",
  439. NTB_LNK_STA_WIDTH(ndev->lnk_sta));
  440. }
  441. off += scnprintf(buf + off, buf_size - off,
  442. "Memory Window Count -\t%u\n", ndev->mw_count);
  443. off += scnprintf(buf + off, buf_size - off,
  444. "Scratchpad Count -\t%u\n", ndev->spad_count);
  445. off += scnprintf(buf + off, buf_size - off,
  446. "Doorbell Count -\t%u\n", ndev->db_count);
  447. off += scnprintf(buf + off, buf_size - off,
  448. "Doorbell Vector Count -\t%u\n", ndev->db_vec_count);
  449. off += scnprintf(buf + off, buf_size - off,
  450. "Doorbell Vector Shift -\t%u\n", ndev->db_vec_shift);
  451. off += scnprintf(buf + off, buf_size - off,
  452. "Doorbell Valid Mask -\t%#llx\n", ndev->db_valid_mask);
  453. off += scnprintf(buf + off, buf_size - off,
  454. "Doorbell Link Mask -\t%#llx\n", ndev->db_link_mask);
  455. off += scnprintf(buf + off, buf_size - off,
  456. "Doorbell Mask Cached -\t%#llx\n", ndev->db_mask);
  457. u.v64 = ndev_db_read(ndev, mmio + ndev->self_reg->db_mask);
  458. off += scnprintf(buf + off, buf_size - off,
  459. "Doorbell Mask -\t\t%#llx\n", u.v64);
  460. u.v64 = ndev_db_read(ndev, mmio + ndev->self_reg->db_bell);
  461. off += scnprintf(buf + off, buf_size - off,
  462. "Doorbell Bell -\t\t%#llx\n", u.v64);
  463. off += scnprintf(buf + off, buf_size - off,
  464. "\nNTB Window Size:\n");
  465. pci_read_config_byte(pdev, XEON_PBAR23SZ_OFFSET, &u.v8);
  466. off += scnprintf(buf + off, buf_size - off,
  467. "PBAR23SZ %hhu\n", u.v8);
  468. if (!ndev->bar4_split) {
  469. pci_read_config_byte(pdev, XEON_PBAR45SZ_OFFSET, &u.v8);
  470. off += scnprintf(buf + off, buf_size - off,
  471. "PBAR45SZ %hhu\n", u.v8);
  472. } else {
  473. pci_read_config_byte(pdev, XEON_PBAR4SZ_OFFSET, &u.v8);
  474. off += scnprintf(buf + off, buf_size - off,
  475. "PBAR4SZ %hhu\n", u.v8);
  476. pci_read_config_byte(pdev, XEON_PBAR5SZ_OFFSET, &u.v8);
  477. off += scnprintf(buf + off, buf_size - off,
  478. "PBAR5SZ %hhu\n", u.v8);
  479. }
  480. pci_read_config_byte(pdev, XEON_SBAR23SZ_OFFSET, &u.v8);
  481. off += scnprintf(buf + off, buf_size - off,
  482. "SBAR23SZ %hhu\n", u.v8);
  483. if (!ndev->bar4_split) {
  484. pci_read_config_byte(pdev, XEON_SBAR45SZ_OFFSET, &u.v8);
  485. off += scnprintf(buf + off, buf_size - off,
  486. "SBAR45SZ %hhu\n", u.v8);
  487. } else {
  488. pci_read_config_byte(pdev, XEON_SBAR4SZ_OFFSET, &u.v8);
  489. off += scnprintf(buf + off, buf_size - off,
  490. "SBAR4SZ %hhu\n", u.v8);
  491. pci_read_config_byte(pdev, XEON_SBAR5SZ_OFFSET, &u.v8);
  492. off += scnprintf(buf + off, buf_size - off,
  493. "SBAR5SZ %hhu\n", u.v8);
  494. }
  495. off += scnprintf(buf + off, buf_size - off,
  496. "\nNTB Incoming XLAT:\n");
  497. u.v64 = ioread64(mmio + bar2_off(ndev->xlat_reg->bar2_xlat, 2));
  498. off += scnprintf(buf + off, buf_size - off,
  499. "XLAT23 -\t\t%#018llx\n", u.v64);
  500. if (ndev->bar4_split) {
  501. u.v32 = ioread32(mmio + bar2_off(ndev->xlat_reg->bar2_xlat, 4));
  502. off += scnprintf(buf + off, buf_size - off,
  503. "XLAT4 -\t\t\t%#06x\n", u.v32);
  504. u.v32 = ioread32(mmio + bar2_off(ndev->xlat_reg->bar2_xlat, 5));
  505. off += scnprintf(buf + off, buf_size - off,
  506. "XLAT5 -\t\t\t%#06x\n", u.v32);
  507. } else {
  508. u.v64 = ioread64(mmio + bar2_off(ndev->xlat_reg->bar2_xlat, 4));
  509. off += scnprintf(buf + off, buf_size - off,
  510. "XLAT45 -\t\t%#018llx\n", u.v64);
  511. }
  512. u.v64 = ioread64(mmio + bar2_off(ndev->xlat_reg->bar2_limit, 2));
  513. off += scnprintf(buf + off, buf_size - off,
  514. "LMT23 -\t\t\t%#018llx\n", u.v64);
  515. if (ndev->bar4_split) {
  516. u.v32 = ioread32(mmio + bar2_off(ndev->xlat_reg->bar2_limit, 4));
  517. off += scnprintf(buf + off, buf_size - off,
  518. "LMT4 -\t\t\t%#06x\n", u.v32);
  519. u.v32 = ioread32(mmio + bar2_off(ndev->xlat_reg->bar2_limit, 5));
  520. off += scnprintf(buf + off, buf_size - off,
  521. "LMT5 -\t\t\t%#06x\n", u.v32);
  522. } else {
  523. u.v64 = ioread64(mmio + bar2_off(ndev->xlat_reg->bar2_limit, 4));
  524. off += scnprintf(buf + off, buf_size - off,
  525. "LMT45 -\t\t\t%#018llx\n", u.v64);
  526. }
  527. if (pdev_is_gen1(pdev)) {
  528. if (ntb_topo_is_b2b(ndev->ntb.topo)) {
  529. off += scnprintf(buf + off, buf_size - off,
  530. "\nNTB Outgoing B2B XLAT:\n");
  531. u.v64 = ioread64(mmio + XEON_PBAR23XLAT_OFFSET);
  532. off += scnprintf(buf + off, buf_size - off,
  533. "B2B XLAT23 -\t\t%#018llx\n", u.v64);
  534. if (ndev->bar4_split) {
  535. u.v32 = ioread32(mmio + XEON_PBAR4XLAT_OFFSET);
  536. off += scnprintf(buf + off, buf_size - off,
  537. "B2B XLAT4 -\t\t%#06x\n",
  538. u.v32);
  539. u.v32 = ioread32(mmio + XEON_PBAR5XLAT_OFFSET);
  540. off += scnprintf(buf + off, buf_size - off,
  541. "B2B XLAT5 -\t\t%#06x\n",
  542. u.v32);
  543. } else {
  544. u.v64 = ioread64(mmio + XEON_PBAR45XLAT_OFFSET);
  545. off += scnprintf(buf + off, buf_size - off,
  546. "B2B XLAT45 -\t\t%#018llx\n",
  547. u.v64);
  548. }
  549. u.v64 = ioread64(mmio + XEON_PBAR23LMT_OFFSET);
  550. off += scnprintf(buf + off, buf_size - off,
  551. "B2B LMT23 -\t\t%#018llx\n", u.v64);
  552. if (ndev->bar4_split) {
  553. u.v32 = ioread32(mmio + XEON_PBAR4LMT_OFFSET);
  554. off += scnprintf(buf + off, buf_size - off,
  555. "B2B LMT4 -\t\t%#06x\n",
  556. u.v32);
  557. u.v32 = ioread32(mmio + XEON_PBAR5LMT_OFFSET);
  558. off += scnprintf(buf + off, buf_size - off,
  559. "B2B LMT5 -\t\t%#06x\n",
  560. u.v32);
  561. } else {
  562. u.v64 = ioread64(mmio + XEON_PBAR45LMT_OFFSET);
  563. off += scnprintf(buf + off, buf_size - off,
  564. "B2B LMT45 -\t\t%#018llx\n",
  565. u.v64);
  566. }
  567. off += scnprintf(buf + off, buf_size - off,
  568. "\nNTB Secondary BAR:\n");
  569. u.v64 = ioread64(mmio + XEON_SBAR0BASE_OFFSET);
  570. off += scnprintf(buf + off, buf_size - off,
  571. "SBAR01 -\t\t%#018llx\n", u.v64);
  572. u.v64 = ioread64(mmio + XEON_SBAR23BASE_OFFSET);
  573. off += scnprintf(buf + off, buf_size - off,
  574. "SBAR23 -\t\t%#018llx\n", u.v64);
  575. if (ndev->bar4_split) {
  576. u.v32 = ioread32(mmio + XEON_SBAR4BASE_OFFSET);
  577. off += scnprintf(buf + off, buf_size - off,
  578. "SBAR4 -\t\t\t%#06x\n", u.v32);
  579. u.v32 = ioread32(mmio + XEON_SBAR5BASE_OFFSET);
  580. off += scnprintf(buf + off, buf_size - off,
  581. "SBAR5 -\t\t\t%#06x\n", u.v32);
  582. } else {
  583. u.v64 = ioread64(mmio + XEON_SBAR45BASE_OFFSET);
  584. off += scnprintf(buf + off, buf_size - off,
  585. "SBAR45 -\t\t%#018llx\n",
  586. u.v64);
  587. }
  588. }
  589. off += scnprintf(buf + off, buf_size - off,
  590. "\nXEON NTB Statistics:\n");
  591. u.v16 = ioread16(mmio + XEON_USMEMMISS_OFFSET);
  592. off += scnprintf(buf + off, buf_size - off,
  593. "Upstream Memory Miss -\t%u\n", u.v16);
  594. off += scnprintf(buf + off, buf_size - off,
  595. "\nXEON NTB Hardware Errors:\n");
  596. if (!pci_read_config_word(pdev,
  597. XEON_DEVSTS_OFFSET, &u.v16))
  598. off += scnprintf(buf + off, buf_size - off,
  599. "DEVSTS -\t\t%#06x\n", u.v16);
  600. if (!pci_read_config_word(pdev,
  601. XEON_LINK_STATUS_OFFSET, &u.v16))
  602. off += scnprintf(buf + off, buf_size - off,
  603. "LNKSTS -\t\t%#06x\n", u.v16);
  604. if (!pci_read_config_dword(pdev,
  605. XEON_UNCERRSTS_OFFSET, &u.v32))
  606. off += scnprintf(buf + off, buf_size - off,
  607. "UNCERRSTS -\t\t%#06x\n", u.v32);
  608. if (!pci_read_config_dword(pdev,
  609. XEON_CORERRSTS_OFFSET, &u.v32))
  610. off += scnprintf(buf + off, buf_size - off,
  611. "CORERRSTS -\t\t%#06x\n", u.v32);
  612. }
  613. ret = simple_read_from_buffer(ubuf, count, offp, buf, off);
  614. kfree(buf);
  615. return ret;
  616. }
  617. static ssize_t ndev_debugfs_read(struct file *filp, char __user *ubuf,
  618. size_t count, loff_t *offp)
  619. {
  620. struct intel_ntb_dev *ndev = filp->private_data;
  621. if (pdev_is_gen1(ndev->ntb.pdev))
  622. return ndev_ntb_debugfs_read(filp, ubuf, count, offp);
  623. else if (pdev_is_gen3(ndev->ntb.pdev))
  624. return ndev_ntb3_debugfs_read(filp, ubuf, count, offp);
  625. else if (pdev_is_gen4(ndev->ntb.pdev) || pdev_is_gen5(ndev->ntb.pdev) ||
  626. pdev_is_gen6(ndev->ntb.pdev))
  627. return ndev_ntb4_debugfs_read(filp, ubuf, count, offp);
  628. return -ENXIO;
  629. }
  630. static void ndev_init_debugfs(struct intel_ntb_dev *ndev)
  631. {
  632. if (!debugfs_dir) {
  633. ndev->debugfs_dir = NULL;
  634. ndev->debugfs_info = NULL;
  635. } else {
  636. ndev->debugfs_dir =
  637. debugfs_create_dir(pci_name(ndev->ntb.pdev),
  638. debugfs_dir);
  639. if (IS_ERR(ndev->debugfs_dir))
  640. ndev->debugfs_info = NULL;
  641. else
  642. ndev->debugfs_info =
  643. debugfs_create_file("info", S_IRUSR,
  644. ndev->debugfs_dir, ndev,
  645. &intel_ntb_debugfs_info);
  646. }
  647. }
  648. static void ndev_deinit_debugfs(struct intel_ntb_dev *ndev)
  649. {
  650. debugfs_remove_recursive(ndev->debugfs_dir);
  651. }
  652. int intel_ntb_mw_count(struct ntb_dev *ntb, int pidx)
  653. {
  654. if (pidx != NTB_DEF_PEER_IDX)
  655. return -EINVAL;
  656. return ntb_ndev(ntb)->mw_count;
  657. }
  658. int intel_ntb_mw_get_align(struct ntb_dev *ntb, int pidx, int idx,
  659. resource_size_t *addr_align,
  660. resource_size_t *size_align,
  661. resource_size_t *size_max)
  662. {
  663. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  664. resource_size_t bar_size, mw_size;
  665. int bar;
  666. if (pidx != NTB_DEF_PEER_IDX)
  667. return -EINVAL;
  668. if (idx >= ndev->b2b_idx && !ndev->b2b_off)
  669. idx += 1;
  670. bar = ndev_mw_to_bar(ndev, idx);
  671. if (bar < 0)
  672. return bar;
  673. bar_size = pci_resource_len(ndev->ntb.pdev, bar);
  674. if (idx == ndev->b2b_idx)
  675. mw_size = bar_size - ndev->b2b_off;
  676. else
  677. mw_size = bar_size;
  678. if (addr_align)
  679. *addr_align = pci_resource_len(ndev->ntb.pdev, bar);
  680. if (size_align)
  681. *size_align = 1;
  682. if (size_max)
  683. *size_max = mw_size;
  684. return 0;
  685. }
  686. static int intel_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx,
  687. dma_addr_t addr, resource_size_t size)
  688. {
  689. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  690. unsigned long base_reg, xlat_reg, limit_reg;
  691. resource_size_t bar_size, mw_size;
  692. void __iomem *mmio;
  693. u64 base, limit, reg_val;
  694. int bar;
  695. if (pidx != NTB_DEF_PEER_IDX)
  696. return -EINVAL;
  697. if (idx >= ndev->b2b_idx && !ndev->b2b_off)
  698. idx += 1;
  699. bar = ndev_mw_to_bar(ndev, idx);
  700. if (bar < 0)
  701. return bar;
  702. bar_size = pci_resource_len(ndev->ntb.pdev, bar);
  703. if (idx == ndev->b2b_idx)
  704. mw_size = bar_size - ndev->b2b_off;
  705. else
  706. mw_size = bar_size;
  707. /* hardware requires that addr is aligned to bar size */
  708. if (addr & (bar_size - 1))
  709. return -EINVAL;
  710. /* make sure the range fits in the usable mw size */
  711. if (size > mw_size)
  712. return -EINVAL;
  713. mmio = ndev->self_mmio;
  714. base_reg = bar0_off(ndev->xlat_reg->bar0_base, bar);
  715. xlat_reg = bar2_off(ndev->xlat_reg->bar2_xlat, bar);
  716. limit_reg = bar2_off(ndev->xlat_reg->bar2_limit, bar);
  717. if (bar < 4 || !ndev->bar4_split) {
  718. base = ioread64(mmio + base_reg) & NTB_BAR_MASK_64;
  719. /* Set the limit if supported, if size is not mw_size */
  720. if (limit_reg && size != mw_size)
  721. limit = base + size;
  722. else
  723. limit = 0;
  724. /* set and verify setting the translation address */
  725. iowrite64(addr, mmio + xlat_reg);
  726. reg_val = ioread64(mmio + xlat_reg);
  727. if (reg_val != addr) {
  728. iowrite64(0, mmio + xlat_reg);
  729. return -EIO;
  730. }
  731. /* set and verify setting the limit */
  732. iowrite64(limit, mmio + limit_reg);
  733. reg_val = ioread64(mmio + limit_reg);
  734. if (reg_val != limit) {
  735. iowrite64(base, mmio + limit_reg);
  736. iowrite64(0, mmio + xlat_reg);
  737. return -EIO;
  738. }
  739. } else {
  740. /* split bar addr range must all be 32 bit */
  741. if (addr & (~0ull << 32))
  742. return -EINVAL;
  743. if ((addr + size) & (~0ull << 32))
  744. return -EINVAL;
  745. base = ioread32(mmio + base_reg) & NTB_BAR_MASK_32;
  746. /* Set the limit if supported, if size is not mw_size */
  747. if (limit_reg && size != mw_size)
  748. limit = base + size;
  749. else
  750. limit = 0;
  751. /* set and verify setting the translation address */
  752. iowrite32(addr, mmio + xlat_reg);
  753. reg_val = ioread32(mmio + xlat_reg);
  754. if (reg_val != addr) {
  755. iowrite32(0, mmio + xlat_reg);
  756. return -EIO;
  757. }
  758. /* set and verify setting the limit */
  759. iowrite32(limit, mmio + limit_reg);
  760. reg_val = ioread32(mmio + limit_reg);
  761. if (reg_val != limit) {
  762. iowrite32(base, mmio + limit_reg);
  763. iowrite32(0, mmio + xlat_reg);
  764. return -EIO;
  765. }
  766. }
  767. return 0;
  768. }
  769. u64 intel_ntb_link_is_up(struct ntb_dev *ntb, enum ntb_speed *speed,
  770. enum ntb_width *width)
  771. {
  772. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  773. if (ndev->reg->link_is_up(ndev)) {
  774. if (speed)
  775. *speed = NTB_LNK_STA_SPEED(ndev->lnk_sta);
  776. if (width)
  777. *width = NTB_LNK_STA_WIDTH(ndev->lnk_sta);
  778. return 1;
  779. } else {
  780. /* TODO MAYBE: is it possible to observe the link speed and
  781. * width while link is training? */
  782. if (speed)
  783. *speed = NTB_SPEED_NONE;
  784. if (width)
  785. *width = NTB_WIDTH_NONE;
  786. return 0;
  787. }
  788. }
  789. static int intel_ntb_link_enable(struct ntb_dev *ntb,
  790. enum ntb_speed max_speed,
  791. enum ntb_width max_width)
  792. {
  793. struct intel_ntb_dev *ndev;
  794. u32 ntb_ctl;
  795. ndev = container_of(ntb, struct intel_ntb_dev, ntb);
  796. if (ndev->ntb.topo == NTB_TOPO_SEC)
  797. return -EINVAL;
  798. dev_dbg(&ntb->pdev->dev,
  799. "Enabling link with max_speed %d max_width %d\n",
  800. max_speed, max_width);
  801. if (max_speed != NTB_SPEED_AUTO)
  802. dev_dbg(&ntb->pdev->dev, "ignoring max_speed %d\n", max_speed);
  803. if (max_width != NTB_WIDTH_AUTO)
  804. dev_dbg(&ntb->pdev->dev, "ignoring max_width %d\n", max_width);
  805. ntb_ctl = ioread32(ndev->self_mmio + ndev->reg->ntb_ctl);
  806. ntb_ctl &= ~(NTB_CTL_DISABLE | NTB_CTL_CFG_LOCK);
  807. ntb_ctl |= NTB_CTL_P2S_BAR2_SNOOP | NTB_CTL_S2P_BAR2_SNOOP;
  808. ntb_ctl |= NTB_CTL_P2S_BAR4_SNOOP | NTB_CTL_S2P_BAR4_SNOOP;
  809. if (ndev->bar4_split)
  810. ntb_ctl |= NTB_CTL_P2S_BAR5_SNOOP | NTB_CTL_S2P_BAR5_SNOOP;
  811. iowrite32(ntb_ctl, ndev->self_mmio + ndev->reg->ntb_ctl);
  812. return 0;
  813. }
  814. int intel_ntb_link_disable(struct ntb_dev *ntb)
  815. {
  816. struct intel_ntb_dev *ndev;
  817. u32 ntb_cntl;
  818. ndev = container_of(ntb, struct intel_ntb_dev, ntb);
  819. if (ndev->ntb.topo == NTB_TOPO_SEC)
  820. return -EINVAL;
  821. dev_dbg(&ntb->pdev->dev, "Disabling link\n");
  822. /* Bring NTB link down */
  823. ntb_cntl = ioread32(ndev->self_mmio + ndev->reg->ntb_ctl);
  824. ntb_cntl &= ~(NTB_CTL_P2S_BAR2_SNOOP | NTB_CTL_S2P_BAR2_SNOOP);
  825. ntb_cntl &= ~(NTB_CTL_P2S_BAR4_SNOOP | NTB_CTL_S2P_BAR4_SNOOP);
  826. if (ndev->bar4_split)
  827. ntb_cntl &= ~(NTB_CTL_P2S_BAR5_SNOOP | NTB_CTL_S2P_BAR5_SNOOP);
  828. ntb_cntl |= NTB_CTL_DISABLE | NTB_CTL_CFG_LOCK;
  829. iowrite32(ntb_cntl, ndev->self_mmio + ndev->reg->ntb_ctl);
  830. return 0;
  831. }
  832. int intel_ntb_peer_mw_count(struct ntb_dev *ntb)
  833. {
  834. /* Numbers of inbound and outbound memory windows match */
  835. return ntb_ndev(ntb)->mw_count;
  836. }
  837. int intel_ntb_peer_mw_get_addr(struct ntb_dev *ntb, int idx,
  838. phys_addr_t *base, resource_size_t *size)
  839. {
  840. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  841. int bar;
  842. if (idx >= ndev->b2b_idx && !ndev->b2b_off)
  843. idx += 1;
  844. bar = ndev_mw_to_bar(ndev, idx);
  845. if (bar < 0)
  846. return bar;
  847. if (base)
  848. *base = pci_resource_start(ndev->ntb.pdev, bar) +
  849. (idx == ndev->b2b_idx ? ndev->b2b_off : 0);
  850. if (size)
  851. *size = pci_resource_len(ndev->ntb.pdev, bar) -
  852. (idx == ndev->b2b_idx ? ndev->b2b_off : 0);
  853. return 0;
  854. }
  855. static int intel_ntb_db_is_unsafe(struct ntb_dev *ntb)
  856. {
  857. return ndev_ignore_unsafe(ntb_ndev(ntb), NTB_UNSAFE_DB);
  858. }
  859. u64 intel_ntb_db_valid_mask(struct ntb_dev *ntb)
  860. {
  861. return ntb_ndev(ntb)->db_valid_mask;
  862. }
  863. int intel_ntb_db_vector_count(struct ntb_dev *ntb)
  864. {
  865. struct intel_ntb_dev *ndev;
  866. ndev = container_of(ntb, struct intel_ntb_dev, ntb);
  867. return ndev->db_vec_count;
  868. }
  869. u64 intel_ntb_db_vector_mask(struct ntb_dev *ntb, int db_vector)
  870. {
  871. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  872. if (db_vector < 0 || db_vector > ndev->db_vec_count)
  873. return 0;
  874. return ndev->db_valid_mask & ndev_vec_mask(ndev, db_vector);
  875. }
  876. static u64 intel_ntb_db_read(struct ntb_dev *ntb)
  877. {
  878. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  879. return ndev_db_read(ndev,
  880. ndev->self_mmio +
  881. ndev->self_reg->db_bell);
  882. }
  883. static int intel_ntb_db_clear(struct ntb_dev *ntb, u64 db_bits)
  884. {
  885. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  886. return ndev_db_write(ndev, db_bits,
  887. ndev->self_mmio +
  888. ndev->self_reg->db_bell);
  889. }
  890. int intel_ntb_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
  891. {
  892. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  893. return ndev_db_set_mask(ndev, db_bits,
  894. ndev->self_mmio +
  895. ndev->self_reg->db_mask);
  896. }
  897. int intel_ntb_db_clear_mask(struct ntb_dev *ntb, u64 db_bits)
  898. {
  899. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  900. return ndev_db_clear_mask(ndev, db_bits,
  901. ndev->self_mmio +
  902. ndev->self_reg->db_mask);
  903. }
  904. static int intel_ntb_peer_db_addr(struct ntb_dev *ntb, phys_addr_t *db_addr,
  905. resource_size_t *db_size, u64 *db_data, int db_bit)
  906. {
  907. u64 db_bits;
  908. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  909. if (unlikely(db_bit >= BITS_PER_LONG_LONG))
  910. return -EINVAL;
  911. db_bits = BIT_ULL(db_bit);
  912. if (unlikely(db_bits & ~ntb_ndev(ntb)->db_valid_mask))
  913. return -EINVAL;
  914. ndev_db_addr(ndev, db_addr, db_size, ndev->peer_addr,
  915. ndev->peer_reg->db_bell);
  916. if (db_data)
  917. *db_data = db_bits;
  918. return 0;
  919. }
  920. static int intel_ntb_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
  921. {
  922. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  923. return ndev_db_write(ndev, db_bits,
  924. ndev->peer_mmio +
  925. ndev->peer_reg->db_bell);
  926. }
  927. int intel_ntb_spad_is_unsafe(struct ntb_dev *ntb)
  928. {
  929. return ndev_ignore_unsafe(ntb_ndev(ntb), NTB_UNSAFE_SPAD);
  930. }
  931. int intel_ntb_spad_count(struct ntb_dev *ntb)
  932. {
  933. struct intel_ntb_dev *ndev;
  934. ndev = container_of(ntb, struct intel_ntb_dev, ntb);
  935. return ndev->spad_count;
  936. }
  937. u32 intel_ntb_spad_read(struct ntb_dev *ntb, int idx)
  938. {
  939. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  940. return ndev_spad_read(ndev, idx,
  941. ndev->self_mmio +
  942. ndev->self_reg->spad);
  943. }
  944. int intel_ntb_spad_write(struct ntb_dev *ntb, int idx, u32 val)
  945. {
  946. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  947. return ndev_spad_write(ndev, idx, val,
  948. ndev->self_mmio +
  949. ndev->self_reg->spad);
  950. }
  951. int intel_ntb_peer_spad_addr(struct ntb_dev *ntb, int pidx, int sidx,
  952. phys_addr_t *spad_addr)
  953. {
  954. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  955. return ndev_spad_addr(ndev, sidx, spad_addr, ndev->peer_addr,
  956. ndev->peer_reg->spad);
  957. }
  958. u32 intel_ntb_peer_spad_read(struct ntb_dev *ntb, int pidx, int sidx)
  959. {
  960. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  961. return ndev_spad_read(ndev, sidx,
  962. ndev->peer_mmio +
  963. ndev->peer_reg->spad);
  964. }
  965. int intel_ntb_peer_spad_write(struct ntb_dev *ntb, int pidx, int sidx,
  966. u32 val)
  967. {
  968. struct intel_ntb_dev *ndev = ntb_ndev(ntb);
  969. return ndev_spad_write(ndev, sidx, val,
  970. ndev->peer_mmio +
  971. ndev->peer_reg->spad);
  972. }
  973. static u64 xeon_db_ioread(const void __iomem *mmio)
  974. {
  975. return (u64)ioread16(mmio);
  976. }
  977. static void xeon_db_iowrite(u64 bits, void __iomem *mmio)
  978. {
  979. iowrite16((u16)bits, mmio);
  980. }
  981. static int xeon_poll_link(struct intel_ntb_dev *ndev)
  982. {
  983. u16 reg_val;
  984. int rc;
  985. ndev->reg->db_iowrite(ndev->db_link_mask,
  986. ndev->self_mmio +
  987. ndev->self_reg->db_bell);
  988. rc = pci_read_config_word(ndev->ntb.pdev,
  989. XEON_LINK_STATUS_OFFSET, &reg_val);
  990. if (rc)
  991. return 0;
  992. if (reg_val == ndev->lnk_sta)
  993. return 0;
  994. ndev->lnk_sta = reg_val;
  995. return 1;
  996. }
  997. int xeon_link_is_up(struct intel_ntb_dev *ndev)
  998. {
  999. if (ndev->ntb.topo == NTB_TOPO_SEC)
  1000. return 1;
  1001. return NTB_LNK_STA_ACTIVE(ndev->lnk_sta);
  1002. }
  1003. enum ntb_topo xeon_ppd_topo(struct intel_ntb_dev *ndev, u8 ppd)
  1004. {
  1005. switch (ppd & XEON_PPD_TOPO_MASK) {
  1006. case XEON_PPD_TOPO_B2B_USD:
  1007. return NTB_TOPO_B2B_USD;
  1008. case XEON_PPD_TOPO_B2B_DSD:
  1009. return NTB_TOPO_B2B_DSD;
  1010. case XEON_PPD_TOPO_PRI_USD:
  1011. case XEON_PPD_TOPO_PRI_DSD: /* accept bogus PRI_DSD */
  1012. return NTB_TOPO_PRI;
  1013. case XEON_PPD_TOPO_SEC_USD:
  1014. case XEON_PPD_TOPO_SEC_DSD: /* accept bogus SEC_DSD */
  1015. return NTB_TOPO_SEC;
  1016. }
  1017. return NTB_TOPO_NONE;
  1018. }
  1019. static inline int xeon_ppd_bar4_split(struct intel_ntb_dev *ndev, u8 ppd)
  1020. {
  1021. if (ppd & XEON_PPD_SPLIT_BAR_MASK) {
  1022. dev_dbg(&ndev->ntb.pdev->dev, "PPD %d split bar\n", ppd);
  1023. return 1;
  1024. }
  1025. return 0;
  1026. }
  1027. static int xeon_init_isr(struct intel_ntb_dev *ndev)
  1028. {
  1029. return ndev_init_isr(ndev, XEON_DB_MSIX_VECTOR_COUNT,
  1030. XEON_DB_MSIX_VECTOR_COUNT,
  1031. XEON_DB_MSIX_VECTOR_SHIFT,
  1032. XEON_DB_TOTAL_SHIFT);
  1033. }
  1034. static void xeon_deinit_isr(struct intel_ntb_dev *ndev)
  1035. {
  1036. ndev_deinit_isr(ndev);
  1037. }
  1038. static int xeon_setup_b2b_mw(struct intel_ntb_dev *ndev,
  1039. const struct intel_b2b_addr *addr,
  1040. const struct intel_b2b_addr *peer_addr)
  1041. {
  1042. struct pci_dev *pdev;
  1043. void __iomem *mmio;
  1044. resource_size_t bar_size;
  1045. phys_addr_t bar_addr;
  1046. int b2b_bar;
  1047. u8 bar_sz;
  1048. pdev = ndev->ntb.pdev;
  1049. mmio = ndev->self_mmio;
  1050. if (ndev->b2b_idx == UINT_MAX) {
  1051. dev_dbg(&pdev->dev, "not using b2b mw\n");
  1052. b2b_bar = 0;
  1053. ndev->b2b_off = 0;
  1054. } else {
  1055. b2b_bar = ndev_mw_to_bar(ndev, ndev->b2b_idx);
  1056. if (b2b_bar < 0)
  1057. return -EIO;
  1058. dev_dbg(&pdev->dev, "using b2b mw bar %d\n", b2b_bar);
  1059. bar_size = pci_resource_len(ndev->ntb.pdev, b2b_bar);
  1060. dev_dbg(&pdev->dev, "b2b bar size %#llx\n", bar_size);
  1061. if (b2b_mw_share && XEON_B2B_MIN_SIZE <= bar_size >> 1) {
  1062. dev_dbg(&pdev->dev, "b2b using first half of bar\n");
  1063. ndev->b2b_off = bar_size >> 1;
  1064. } else if (XEON_B2B_MIN_SIZE <= bar_size) {
  1065. dev_dbg(&pdev->dev, "b2b using whole bar\n");
  1066. ndev->b2b_off = 0;
  1067. --ndev->mw_count;
  1068. } else {
  1069. dev_dbg(&pdev->dev, "b2b bar size is too small\n");
  1070. return -EIO;
  1071. }
  1072. }
  1073. /* Reset the secondary bar sizes to match the primary bar sizes,
  1074. * except disable or halve the size of the b2b secondary bar.
  1075. *
  1076. * Note: code for each specific bar size register, because the register
  1077. * offsets are not in a consistent order (bar5sz comes after ppd, odd).
  1078. */
  1079. pci_read_config_byte(pdev, XEON_PBAR23SZ_OFFSET, &bar_sz);
  1080. dev_dbg(&pdev->dev, "PBAR23SZ %#x\n", bar_sz);
  1081. if (b2b_bar == 2) {
  1082. if (ndev->b2b_off)
  1083. bar_sz -= 1;
  1084. else
  1085. bar_sz = 0;
  1086. }
  1087. pci_write_config_byte(pdev, XEON_SBAR23SZ_OFFSET, bar_sz);
  1088. pci_read_config_byte(pdev, XEON_SBAR23SZ_OFFSET, &bar_sz);
  1089. dev_dbg(&pdev->dev, "SBAR23SZ %#x\n", bar_sz);
  1090. if (!ndev->bar4_split) {
  1091. pci_read_config_byte(pdev, XEON_PBAR45SZ_OFFSET, &bar_sz);
  1092. dev_dbg(&pdev->dev, "PBAR45SZ %#x\n", bar_sz);
  1093. if (b2b_bar == 4) {
  1094. if (ndev->b2b_off)
  1095. bar_sz -= 1;
  1096. else
  1097. bar_sz = 0;
  1098. }
  1099. pci_write_config_byte(pdev, XEON_SBAR45SZ_OFFSET, bar_sz);
  1100. pci_read_config_byte(pdev, XEON_SBAR45SZ_OFFSET, &bar_sz);
  1101. dev_dbg(&pdev->dev, "SBAR45SZ %#x\n", bar_sz);
  1102. } else {
  1103. pci_read_config_byte(pdev, XEON_PBAR4SZ_OFFSET, &bar_sz);
  1104. dev_dbg(&pdev->dev, "PBAR4SZ %#x\n", bar_sz);
  1105. if (b2b_bar == 4) {
  1106. if (ndev->b2b_off)
  1107. bar_sz -= 1;
  1108. else
  1109. bar_sz = 0;
  1110. }
  1111. pci_write_config_byte(pdev, XEON_SBAR4SZ_OFFSET, bar_sz);
  1112. pci_read_config_byte(pdev, XEON_SBAR4SZ_OFFSET, &bar_sz);
  1113. dev_dbg(&pdev->dev, "SBAR4SZ %#x\n", bar_sz);
  1114. pci_read_config_byte(pdev, XEON_PBAR5SZ_OFFSET, &bar_sz);
  1115. dev_dbg(&pdev->dev, "PBAR5SZ %#x\n", bar_sz);
  1116. if (b2b_bar == 5) {
  1117. if (ndev->b2b_off)
  1118. bar_sz -= 1;
  1119. else
  1120. bar_sz = 0;
  1121. }
  1122. pci_write_config_byte(pdev, XEON_SBAR5SZ_OFFSET, bar_sz);
  1123. pci_read_config_byte(pdev, XEON_SBAR5SZ_OFFSET, &bar_sz);
  1124. dev_dbg(&pdev->dev, "SBAR5SZ %#x\n", bar_sz);
  1125. }
  1126. /* SBAR01 hit by first part of the b2b bar */
  1127. if (b2b_bar == 0)
  1128. bar_addr = addr->bar0_addr;
  1129. else if (b2b_bar == 2)
  1130. bar_addr = addr->bar2_addr64;
  1131. else if (b2b_bar == 4 && !ndev->bar4_split)
  1132. bar_addr = addr->bar4_addr64;
  1133. else if (b2b_bar == 4)
  1134. bar_addr = addr->bar4_addr32;
  1135. else if (b2b_bar == 5)
  1136. bar_addr = addr->bar5_addr32;
  1137. else
  1138. return -EIO;
  1139. dev_dbg(&pdev->dev, "SBAR01 %#018llx\n", bar_addr);
  1140. iowrite64(bar_addr, mmio + XEON_SBAR0BASE_OFFSET);
  1141. /* Other SBAR are normally hit by the PBAR xlat, except for b2b bar.
  1142. * The b2b bar is either disabled above, or configured half-size, and
  1143. * it starts at the PBAR xlat + offset.
  1144. */
  1145. bar_addr = addr->bar2_addr64 + (b2b_bar == 2 ? ndev->b2b_off : 0);
  1146. iowrite64(bar_addr, mmio + XEON_SBAR23BASE_OFFSET);
  1147. bar_addr = ioread64(mmio + XEON_SBAR23BASE_OFFSET);
  1148. dev_dbg(&pdev->dev, "SBAR23 %#018llx\n", bar_addr);
  1149. if (!ndev->bar4_split) {
  1150. bar_addr = addr->bar4_addr64 +
  1151. (b2b_bar == 4 ? ndev->b2b_off : 0);
  1152. iowrite64(bar_addr, mmio + XEON_SBAR45BASE_OFFSET);
  1153. bar_addr = ioread64(mmio + XEON_SBAR45BASE_OFFSET);
  1154. dev_dbg(&pdev->dev, "SBAR45 %#018llx\n", bar_addr);
  1155. } else {
  1156. bar_addr = addr->bar4_addr32 +
  1157. (b2b_bar == 4 ? ndev->b2b_off : 0);
  1158. iowrite32(bar_addr, mmio + XEON_SBAR4BASE_OFFSET);
  1159. bar_addr = ioread32(mmio + XEON_SBAR4BASE_OFFSET);
  1160. dev_dbg(&pdev->dev, "SBAR4 %#010llx\n", bar_addr);
  1161. bar_addr = addr->bar5_addr32 +
  1162. (b2b_bar == 5 ? ndev->b2b_off : 0);
  1163. iowrite32(bar_addr, mmio + XEON_SBAR5BASE_OFFSET);
  1164. bar_addr = ioread32(mmio + XEON_SBAR5BASE_OFFSET);
  1165. dev_dbg(&pdev->dev, "SBAR5 %#010llx\n", bar_addr);
  1166. }
  1167. /* setup incoming bar limits == base addrs (zero length windows) */
  1168. bar_addr = addr->bar2_addr64 + (b2b_bar == 2 ? ndev->b2b_off : 0);
  1169. iowrite64(bar_addr, mmio + XEON_SBAR23LMT_OFFSET);
  1170. bar_addr = ioread64(mmio + XEON_SBAR23LMT_OFFSET);
  1171. dev_dbg(&pdev->dev, "SBAR23LMT %#018llx\n", bar_addr);
  1172. if (!ndev->bar4_split) {
  1173. bar_addr = addr->bar4_addr64 +
  1174. (b2b_bar == 4 ? ndev->b2b_off : 0);
  1175. iowrite64(bar_addr, mmio + XEON_SBAR45LMT_OFFSET);
  1176. bar_addr = ioread64(mmio + XEON_SBAR45LMT_OFFSET);
  1177. dev_dbg(&pdev->dev, "SBAR45LMT %#018llx\n", bar_addr);
  1178. } else {
  1179. bar_addr = addr->bar4_addr32 +
  1180. (b2b_bar == 4 ? ndev->b2b_off : 0);
  1181. iowrite32(bar_addr, mmio + XEON_SBAR4LMT_OFFSET);
  1182. bar_addr = ioread32(mmio + XEON_SBAR4LMT_OFFSET);
  1183. dev_dbg(&pdev->dev, "SBAR4LMT %#010llx\n", bar_addr);
  1184. bar_addr = addr->bar5_addr32 +
  1185. (b2b_bar == 5 ? ndev->b2b_off : 0);
  1186. iowrite32(bar_addr, mmio + XEON_SBAR5LMT_OFFSET);
  1187. bar_addr = ioread32(mmio + XEON_SBAR5LMT_OFFSET);
  1188. dev_dbg(&pdev->dev, "SBAR5LMT %#05llx\n", bar_addr);
  1189. }
  1190. /* zero incoming translation addrs */
  1191. iowrite64(0, mmio + XEON_SBAR23XLAT_OFFSET);
  1192. if (!ndev->bar4_split) {
  1193. iowrite64(0, mmio + XEON_SBAR45XLAT_OFFSET);
  1194. } else {
  1195. iowrite32(0, mmio + XEON_SBAR4XLAT_OFFSET);
  1196. iowrite32(0, mmio + XEON_SBAR5XLAT_OFFSET);
  1197. }
  1198. /* zero outgoing translation limits (whole bar size windows) */
  1199. iowrite64(0, mmio + XEON_PBAR23LMT_OFFSET);
  1200. if (!ndev->bar4_split) {
  1201. iowrite64(0, mmio + XEON_PBAR45LMT_OFFSET);
  1202. } else {
  1203. iowrite32(0, mmio + XEON_PBAR4LMT_OFFSET);
  1204. iowrite32(0, mmio + XEON_PBAR5LMT_OFFSET);
  1205. }
  1206. /* set outgoing translation offsets */
  1207. bar_addr = peer_addr->bar2_addr64;
  1208. iowrite64(bar_addr, mmio + XEON_PBAR23XLAT_OFFSET);
  1209. bar_addr = ioread64(mmio + XEON_PBAR23XLAT_OFFSET);
  1210. dev_dbg(&pdev->dev, "PBAR23XLAT %#018llx\n", bar_addr);
  1211. if (!ndev->bar4_split) {
  1212. bar_addr = peer_addr->bar4_addr64;
  1213. iowrite64(bar_addr, mmio + XEON_PBAR45XLAT_OFFSET);
  1214. bar_addr = ioread64(mmio + XEON_PBAR45XLAT_OFFSET);
  1215. dev_dbg(&pdev->dev, "PBAR45XLAT %#018llx\n", bar_addr);
  1216. } else {
  1217. bar_addr = peer_addr->bar4_addr32;
  1218. iowrite32(bar_addr, mmio + XEON_PBAR4XLAT_OFFSET);
  1219. bar_addr = ioread32(mmio + XEON_PBAR4XLAT_OFFSET);
  1220. dev_dbg(&pdev->dev, "PBAR4XLAT %#010llx\n", bar_addr);
  1221. bar_addr = peer_addr->bar5_addr32;
  1222. iowrite32(bar_addr, mmio + XEON_PBAR5XLAT_OFFSET);
  1223. bar_addr = ioread32(mmio + XEON_PBAR5XLAT_OFFSET);
  1224. dev_dbg(&pdev->dev, "PBAR5XLAT %#010llx\n", bar_addr);
  1225. }
  1226. /* set the translation offset for b2b registers */
  1227. if (b2b_bar == 0)
  1228. bar_addr = peer_addr->bar0_addr;
  1229. else if (b2b_bar == 2)
  1230. bar_addr = peer_addr->bar2_addr64;
  1231. else if (b2b_bar == 4 && !ndev->bar4_split)
  1232. bar_addr = peer_addr->bar4_addr64;
  1233. else if (b2b_bar == 4)
  1234. bar_addr = peer_addr->bar4_addr32;
  1235. else if (b2b_bar == 5)
  1236. bar_addr = peer_addr->bar5_addr32;
  1237. else
  1238. return -EIO;
  1239. /* B2B_XLAT_OFFSET is 64bit, but can only take 32bit writes */
  1240. dev_dbg(&pdev->dev, "B2BXLAT %#018llx\n", bar_addr);
  1241. iowrite32(bar_addr, mmio + XEON_B2B_XLAT_OFFSETL);
  1242. iowrite32(bar_addr >> 32, mmio + XEON_B2B_XLAT_OFFSETU);
  1243. if (b2b_bar) {
  1244. /* map peer ntb mmio config space registers */
  1245. ndev->peer_mmio = pci_iomap(pdev, b2b_bar,
  1246. XEON_B2B_MIN_SIZE);
  1247. if (!ndev->peer_mmio)
  1248. return -EIO;
  1249. ndev->peer_addr = pci_resource_start(pdev, b2b_bar);
  1250. }
  1251. return 0;
  1252. }
  1253. static int xeon_init_ntb(struct intel_ntb_dev *ndev)
  1254. {
  1255. struct device *dev = &ndev->ntb.pdev->dev;
  1256. int rc;
  1257. u32 ntb_ctl;
  1258. if (ndev->bar4_split)
  1259. ndev->mw_count = HSX_SPLIT_BAR_MW_COUNT;
  1260. else
  1261. ndev->mw_count = XEON_MW_COUNT;
  1262. ndev->spad_count = XEON_SPAD_COUNT;
  1263. ndev->db_count = XEON_DB_COUNT;
  1264. ndev->db_link_mask = XEON_DB_LINK_BIT;
  1265. switch (ndev->ntb.topo) {
  1266. case NTB_TOPO_PRI:
  1267. if (ndev->hwerr_flags & NTB_HWERR_SDOORBELL_LOCKUP) {
  1268. dev_err(dev, "NTB Primary config disabled\n");
  1269. return -EINVAL;
  1270. }
  1271. /* enable link to allow secondary side device to appear */
  1272. ntb_ctl = ioread32(ndev->self_mmio + ndev->reg->ntb_ctl);
  1273. ntb_ctl &= ~NTB_CTL_DISABLE;
  1274. iowrite32(ntb_ctl, ndev->self_mmio + ndev->reg->ntb_ctl);
  1275. /* use half the spads for the peer */
  1276. ndev->spad_count >>= 1;
  1277. ndev->self_reg = &xeon_pri_reg;
  1278. ndev->peer_reg = &xeon_sec_reg;
  1279. ndev->xlat_reg = &xeon_sec_xlat;
  1280. break;
  1281. case NTB_TOPO_SEC:
  1282. if (ndev->hwerr_flags & NTB_HWERR_SDOORBELL_LOCKUP) {
  1283. dev_err(dev, "NTB Secondary config disabled\n");
  1284. return -EINVAL;
  1285. }
  1286. /* use half the spads for the peer */
  1287. ndev->spad_count >>= 1;
  1288. ndev->self_reg = &xeon_sec_reg;
  1289. ndev->peer_reg = &xeon_pri_reg;
  1290. ndev->xlat_reg = &xeon_pri_xlat;
  1291. break;
  1292. case NTB_TOPO_B2B_USD:
  1293. case NTB_TOPO_B2B_DSD:
  1294. ndev->self_reg = &xeon_pri_reg;
  1295. ndev->peer_reg = &xeon_b2b_reg;
  1296. ndev->xlat_reg = &xeon_sec_xlat;
  1297. if (ndev->hwerr_flags & NTB_HWERR_SDOORBELL_LOCKUP) {
  1298. ndev->peer_reg = &xeon_pri_reg;
  1299. if (b2b_mw_idx < 0)
  1300. ndev->b2b_idx = b2b_mw_idx + ndev->mw_count;
  1301. else
  1302. ndev->b2b_idx = b2b_mw_idx;
  1303. if (ndev->b2b_idx >= ndev->mw_count) {
  1304. dev_dbg(dev,
  1305. "b2b_mw_idx %d invalid for mw_count %u\n",
  1306. b2b_mw_idx, ndev->mw_count);
  1307. return -EINVAL;
  1308. }
  1309. dev_dbg(dev, "setting up b2b mw idx %d means %d\n",
  1310. b2b_mw_idx, ndev->b2b_idx);
  1311. } else if (ndev->hwerr_flags & NTB_HWERR_B2BDOORBELL_BIT14) {
  1312. dev_warn(dev, "Reduce doorbell count by 1\n");
  1313. ndev->db_count -= 1;
  1314. }
  1315. if (ndev->ntb.topo == NTB_TOPO_B2B_USD) {
  1316. rc = xeon_setup_b2b_mw(ndev,
  1317. &xeon_b2b_dsd_addr,
  1318. &xeon_b2b_usd_addr);
  1319. } else {
  1320. rc = xeon_setup_b2b_mw(ndev,
  1321. &xeon_b2b_usd_addr,
  1322. &xeon_b2b_dsd_addr);
  1323. }
  1324. if (rc)
  1325. return rc;
  1326. /* Enable Bus Master and Memory Space on the secondary side */
  1327. iowrite16(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER,
  1328. ndev->self_mmio + XEON_SPCICMD_OFFSET);
  1329. break;
  1330. default:
  1331. return -EINVAL;
  1332. }
  1333. ndev->db_valid_mask = BIT_ULL(ndev->db_count) - 1;
  1334. ndev->reg->db_iowrite(ndev->db_valid_mask,
  1335. ndev->self_mmio +
  1336. ndev->self_reg->db_mask);
  1337. return 0;
  1338. }
  1339. static int xeon_init_dev(struct intel_ntb_dev *ndev)
  1340. {
  1341. struct pci_dev *pdev;
  1342. u8 ppd;
  1343. int rc, mem;
  1344. pdev = ndev->ntb.pdev;
  1345. switch (pdev->device) {
  1346. /* There is a Xeon hardware errata related to writes to SDOORBELL or
  1347. * B2BDOORBELL in conjunction with inbound access to NTB MMIO Space,
  1348. * which may hang the system. To workaround this use the second memory
  1349. * window to access the interrupt and scratch pad registers on the
  1350. * remote system.
  1351. */
  1352. case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
  1353. case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
  1354. case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
  1355. case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
  1356. case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
  1357. case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
  1358. case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
  1359. case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
  1360. case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
  1361. case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
  1362. case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
  1363. case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
  1364. case PCI_DEVICE_ID_INTEL_NTB_SS_BDX:
  1365. case PCI_DEVICE_ID_INTEL_NTB_PS_BDX:
  1366. case PCI_DEVICE_ID_INTEL_NTB_B2B_BDX:
  1367. ndev->hwerr_flags |= NTB_HWERR_SDOORBELL_LOCKUP;
  1368. break;
  1369. }
  1370. switch (pdev->device) {
  1371. /* There is a hardware errata related to accessing any register in
  1372. * SB01BASE in the presence of bidirectional traffic crossing the NTB.
  1373. */
  1374. case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
  1375. case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
  1376. case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
  1377. case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
  1378. case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
  1379. case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
  1380. case PCI_DEVICE_ID_INTEL_NTB_SS_BDX:
  1381. case PCI_DEVICE_ID_INTEL_NTB_PS_BDX:
  1382. case PCI_DEVICE_ID_INTEL_NTB_B2B_BDX:
  1383. ndev->hwerr_flags |= NTB_HWERR_SB01BASE_LOCKUP;
  1384. break;
  1385. }
  1386. switch (pdev->device) {
  1387. /* HW Errata on bit 14 of b2bdoorbell register. Writes will not be
  1388. * mirrored to the remote system. Shrink the number of bits by one,
  1389. * since bit 14 is the last bit.
  1390. */
  1391. case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
  1392. case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
  1393. case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
  1394. case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
  1395. case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
  1396. case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
  1397. case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
  1398. case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
  1399. case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
  1400. case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
  1401. case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
  1402. case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
  1403. case PCI_DEVICE_ID_INTEL_NTB_SS_BDX:
  1404. case PCI_DEVICE_ID_INTEL_NTB_PS_BDX:
  1405. case PCI_DEVICE_ID_INTEL_NTB_B2B_BDX:
  1406. ndev->hwerr_flags |= NTB_HWERR_B2BDOORBELL_BIT14;
  1407. break;
  1408. }
  1409. ndev->reg = &xeon_reg;
  1410. rc = pci_read_config_byte(pdev, XEON_PPD_OFFSET, &ppd);
  1411. if (rc)
  1412. return -EIO;
  1413. ndev->ntb.topo = xeon_ppd_topo(ndev, ppd);
  1414. dev_dbg(&pdev->dev, "ppd %#x topo %s\n", ppd,
  1415. ntb_topo_string(ndev->ntb.topo));
  1416. if (ndev->ntb.topo == NTB_TOPO_NONE)
  1417. return -EINVAL;
  1418. if (ndev->ntb.topo != NTB_TOPO_SEC) {
  1419. ndev->bar4_split = xeon_ppd_bar4_split(ndev, ppd);
  1420. dev_dbg(&pdev->dev, "ppd %#x bar4_split %d\n",
  1421. ppd, ndev->bar4_split);
  1422. } else {
  1423. /* This is a way for transparent BAR to figure out if we are
  1424. * doing split BAR or not. There is no way for the hw on the
  1425. * transparent side to know and set the PPD.
  1426. */
  1427. mem = pci_select_bars(pdev, IORESOURCE_MEM);
  1428. ndev->bar4_split = hweight32(mem) ==
  1429. HSX_SPLIT_BAR_MW_COUNT + 1;
  1430. dev_dbg(&pdev->dev, "mem %#x bar4_split %d\n",
  1431. mem, ndev->bar4_split);
  1432. }
  1433. rc = xeon_init_ntb(ndev);
  1434. if (rc)
  1435. return rc;
  1436. return xeon_init_isr(ndev);
  1437. }
  1438. static void xeon_deinit_dev(struct intel_ntb_dev *ndev)
  1439. {
  1440. xeon_deinit_isr(ndev);
  1441. }
  1442. static int intel_ntb_init_pci(struct intel_ntb_dev *ndev, struct pci_dev *pdev)
  1443. {
  1444. int rc;
  1445. pci_set_drvdata(pdev, ndev);
  1446. rc = pci_enable_device(pdev);
  1447. if (rc)
  1448. goto err_pci_enable;
  1449. rc = pci_request_regions(pdev, NTB_NAME);
  1450. if (rc)
  1451. goto err_pci_regions;
  1452. pci_set_master(pdev);
  1453. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  1454. if (rc) {
  1455. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  1456. if (rc)
  1457. goto err_dma_mask;
  1458. dev_warn(&pdev->dev, "Cannot DMA highmem\n");
  1459. }
  1460. ndev->self_mmio = pci_iomap(pdev, 0, 0);
  1461. if (!ndev->self_mmio) {
  1462. rc = -EIO;
  1463. goto err_mmio;
  1464. }
  1465. ndev->peer_mmio = ndev->self_mmio;
  1466. ndev->peer_addr = pci_resource_start(pdev, 0);
  1467. return 0;
  1468. err_mmio:
  1469. err_dma_mask:
  1470. pci_release_regions(pdev);
  1471. err_pci_regions:
  1472. pci_disable_device(pdev);
  1473. err_pci_enable:
  1474. pci_set_drvdata(pdev, NULL);
  1475. return rc;
  1476. }
  1477. static void intel_ntb_deinit_pci(struct intel_ntb_dev *ndev)
  1478. {
  1479. struct pci_dev *pdev = ndev->ntb.pdev;
  1480. if (ndev->peer_mmio && ndev->peer_mmio != ndev->self_mmio)
  1481. pci_iounmap(pdev, ndev->peer_mmio);
  1482. pci_iounmap(pdev, ndev->self_mmio);
  1483. pci_release_regions(pdev);
  1484. pci_disable_device(pdev);
  1485. pci_set_drvdata(pdev, NULL);
  1486. }
  1487. static inline void ndev_init_struct(struct intel_ntb_dev *ndev,
  1488. struct pci_dev *pdev)
  1489. {
  1490. ndev->ntb.pdev = pdev;
  1491. ndev->ntb.topo = NTB_TOPO_NONE;
  1492. ndev->ntb.ops = &intel_ntb_ops;
  1493. ndev->b2b_off = 0;
  1494. ndev->b2b_idx = UINT_MAX;
  1495. ndev->bar4_split = 0;
  1496. ndev->mw_count = 0;
  1497. ndev->spad_count = 0;
  1498. ndev->db_count = 0;
  1499. ndev->db_vec_count = 0;
  1500. ndev->db_vec_shift = 0;
  1501. ndev->ntb_ctl = 0;
  1502. ndev->lnk_sta = 0;
  1503. ndev->db_valid_mask = 0;
  1504. ndev->db_link_mask = 0;
  1505. ndev->db_mask = 0;
  1506. spin_lock_init(&ndev->db_mask_lock);
  1507. }
  1508. static int intel_ntb_pci_probe(struct pci_dev *pdev,
  1509. const struct pci_device_id *id)
  1510. {
  1511. struct intel_ntb_dev *ndev;
  1512. int rc, node;
  1513. node = dev_to_node(&pdev->dev);
  1514. ndev = kzalloc_node(sizeof(*ndev), GFP_KERNEL, node);
  1515. if (!ndev) {
  1516. rc = -ENOMEM;
  1517. goto err_ndev;
  1518. }
  1519. ndev_init_struct(ndev, pdev);
  1520. if (pdev_is_gen1(pdev)) {
  1521. rc = intel_ntb_init_pci(ndev, pdev);
  1522. if (rc)
  1523. goto err_init_pci;
  1524. rc = xeon_init_dev(ndev);
  1525. if (rc)
  1526. goto err_init_dev;
  1527. } else if (pdev_is_gen3(pdev)) {
  1528. ndev->ntb.ops = &intel_ntb3_ops;
  1529. rc = intel_ntb_init_pci(ndev, pdev);
  1530. if (rc)
  1531. goto err_init_pci;
  1532. rc = gen3_init_dev(ndev);
  1533. if (rc)
  1534. goto err_init_dev;
  1535. } else if (pdev_is_gen4(pdev) || pdev_is_gen5(pdev) ||
  1536. pdev_is_gen6(pdev)) {
  1537. ndev->ntb.ops = &intel_ntb4_ops;
  1538. rc = intel_ntb_init_pci(ndev, pdev);
  1539. if (rc)
  1540. goto err_init_pci;
  1541. rc = gen4_init_dev(ndev);
  1542. if (rc)
  1543. goto err_init_dev;
  1544. } else {
  1545. rc = -EINVAL;
  1546. goto err_init_pci;
  1547. }
  1548. ndev_reset_unsafe_flags(ndev);
  1549. ndev->reg->poll_link(ndev);
  1550. ndev_init_debugfs(ndev);
  1551. rc = ntb_register_device(&ndev->ntb);
  1552. if (rc)
  1553. goto err_register;
  1554. dev_info(&pdev->dev, "NTB device registered.\n");
  1555. return 0;
  1556. err_register:
  1557. ndev_deinit_debugfs(ndev);
  1558. if (pdev_is_gen1(pdev) || pdev_is_gen3(pdev) ||
  1559. pdev_is_gen4(pdev) || pdev_is_gen5(pdev) ||
  1560. pdev_is_gen6(pdev))
  1561. xeon_deinit_dev(ndev);
  1562. err_init_dev:
  1563. intel_ntb_deinit_pci(ndev);
  1564. err_init_pci:
  1565. kfree(ndev);
  1566. err_ndev:
  1567. return rc;
  1568. }
  1569. static void intel_ntb_pci_remove(struct pci_dev *pdev)
  1570. {
  1571. struct intel_ntb_dev *ndev = pci_get_drvdata(pdev);
  1572. ntb_unregister_device(&ndev->ntb);
  1573. ndev_deinit_debugfs(ndev);
  1574. if (pdev_is_gen1(pdev) || pdev_is_gen3(pdev) ||
  1575. pdev_is_gen4(pdev) || pdev_is_gen5(pdev) ||
  1576. pdev_is_gen6(pdev))
  1577. xeon_deinit_dev(ndev);
  1578. intel_ntb_deinit_pci(ndev);
  1579. kfree(ndev);
  1580. }
  1581. static const struct intel_ntb_reg xeon_reg = {
  1582. .poll_link = xeon_poll_link,
  1583. .link_is_up = xeon_link_is_up,
  1584. .db_ioread = xeon_db_ioread,
  1585. .db_iowrite = xeon_db_iowrite,
  1586. .db_size = sizeof(u32),
  1587. .ntb_ctl = XEON_NTBCNTL_OFFSET,
  1588. .mw_bar = {2, 4, 5},
  1589. };
  1590. static const struct intel_ntb_alt_reg xeon_pri_reg = {
  1591. .db_bell = XEON_PDOORBELL_OFFSET,
  1592. .db_mask = XEON_PDBMSK_OFFSET,
  1593. .spad = XEON_SPAD_OFFSET,
  1594. };
  1595. static const struct intel_ntb_alt_reg xeon_sec_reg = {
  1596. .db_bell = XEON_SDOORBELL_OFFSET,
  1597. .db_mask = XEON_SDBMSK_OFFSET,
  1598. /* second half of the scratchpads */
  1599. .spad = XEON_SPAD_OFFSET + (XEON_SPAD_COUNT << 1),
  1600. };
  1601. static const struct intel_ntb_alt_reg xeon_b2b_reg = {
  1602. .db_bell = XEON_B2B_DOORBELL_OFFSET,
  1603. .spad = XEON_B2B_SPAD_OFFSET,
  1604. };
  1605. static const struct intel_ntb_xlat_reg xeon_pri_xlat = {
  1606. /* Note: no primary .bar0_base visible to the secondary side.
  1607. *
  1608. * The secondary side cannot get the base address stored in primary
  1609. * bars. The base address is necessary to set the limit register to
  1610. * any value other than zero, or unlimited.
  1611. *
  1612. * WITHOUT THE BASE ADDRESS, THE SECONDARY SIDE CANNOT DISABLE the
  1613. * window by setting the limit equal to base, nor can it limit the size
  1614. * of the memory window by setting the limit to base + size.
  1615. */
  1616. .bar2_limit = XEON_PBAR23LMT_OFFSET,
  1617. .bar2_xlat = XEON_PBAR23XLAT_OFFSET,
  1618. };
  1619. static const struct intel_ntb_xlat_reg xeon_sec_xlat = {
  1620. .bar0_base = XEON_SBAR0BASE_OFFSET,
  1621. .bar2_limit = XEON_SBAR23LMT_OFFSET,
  1622. .bar2_xlat = XEON_SBAR23XLAT_OFFSET,
  1623. };
  1624. struct intel_b2b_addr xeon_b2b_usd_addr = {
  1625. .bar2_addr64 = XEON_B2B_BAR2_ADDR64,
  1626. .bar4_addr64 = XEON_B2B_BAR4_ADDR64,
  1627. .bar4_addr32 = XEON_B2B_BAR4_ADDR32,
  1628. .bar5_addr32 = XEON_B2B_BAR5_ADDR32,
  1629. };
  1630. struct intel_b2b_addr xeon_b2b_dsd_addr = {
  1631. .bar2_addr64 = XEON_B2B_BAR2_ADDR64,
  1632. .bar4_addr64 = XEON_B2B_BAR4_ADDR64,
  1633. .bar4_addr32 = XEON_B2B_BAR4_ADDR32,
  1634. .bar5_addr32 = XEON_B2B_BAR5_ADDR32,
  1635. };
  1636. /* operations for primary side of local ntb */
  1637. static const struct ntb_dev_ops intel_ntb_ops = {
  1638. .mw_count = intel_ntb_mw_count,
  1639. .mw_get_align = intel_ntb_mw_get_align,
  1640. .mw_set_trans = intel_ntb_mw_set_trans,
  1641. .peer_mw_count = intel_ntb_peer_mw_count,
  1642. .peer_mw_get_addr = intel_ntb_peer_mw_get_addr,
  1643. .link_is_up = intel_ntb_link_is_up,
  1644. .link_enable = intel_ntb_link_enable,
  1645. .link_disable = intel_ntb_link_disable,
  1646. .db_is_unsafe = intel_ntb_db_is_unsafe,
  1647. .db_valid_mask = intel_ntb_db_valid_mask,
  1648. .db_vector_count = intel_ntb_db_vector_count,
  1649. .db_vector_mask = intel_ntb_db_vector_mask,
  1650. .db_read = intel_ntb_db_read,
  1651. .db_clear = intel_ntb_db_clear,
  1652. .db_set_mask = intel_ntb_db_set_mask,
  1653. .db_clear_mask = intel_ntb_db_clear_mask,
  1654. .peer_db_addr = intel_ntb_peer_db_addr,
  1655. .peer_db_set = intel_ntb_peer_db_set,
  1656. .spad_is_unsafe = intel_ntb_spad_is_unsafe,
  1657. .spad_count = intel_ntb_spad_count,
  1658. .spad_read = intel_ntb_spad_read,
  1659. .spad_write = intel_ntb_spad_write,
  1660. .peer_spad_addr = intel_ntb_peer_spad_addr,
  1661. .peer_spad_read = intel_ntb_peer_spad_read,
  1662. .peer_spad_write = intel_ntb_peer_spad_write,
  1663. };
  1664. static const struct file_operations intel_ntb_debugfs_info = {
  1665. .owner = THIS_MODULE,
  1666. .open = simple_open,
  1667. .read = ndev_debugfs_read,
  1668. };
  1669. static const struct pci_device_id intel_ntb_pci_tbl[] = {
  1670. /* GEN1 */
  1671. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_JSF)},
  1672. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_SNB)},
  1673. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_IVT)},
  1674. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_HSX)},
  1675. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_BDX)},
  1676. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_JSF)},
  1677. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_SNB)},
  1678. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_IVT)},
  1679. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_HSX)},
  1680. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_PS_BDX)},
  1681. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_JSF)},
  1682. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_SNB)},
  1683. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_IVT)},
  1684. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_HSX)},
  1685. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_SS_BDX)},
  1686. /* GEN3 */
  1687. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_SKX)},
  1688. /* GEN4 */
  1689. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_ICX)},
  1690. /* GEN5 PCIe */
  1691. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_GNR)},
  1692. /* GEN6 PCIe */
  1693. {PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_NTB_B2B_DMR)},
  1694. {0}
  1695. };
  1696. MODULE_DEVICE_TABLE(pci, intel_ntb_pci_tbl);
  1697. static struct pci_driver intel_ntb_pci_driver = {
  1698. .name = KBUILD_MODNAME,
  1699. .id_table = intel_ntb_pci_tbl,
  1700. .probe = intel_ntb_pci_probe,
  1701. .remove = intel_ntb_pci_remove,
  1702. };
  1703. static int __init intel_ntb_pci_driver_init(void)
  1704. {
  1705. int ret;
  1706. pr_info("%s %s\n", NTB_DESC, NTB_VER);
  1707. if (debugfs_initialized())
  1708. debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
  1709. ret = pci_register_driver(&intel_ntb_pci_driver);
  1710. if (ret)
  1711. debugfs_remove_recursive(debugfs_dir);
  1712. return ret;
  1713. }
  1714. module_init(intel_ntb_pci_driver_init);
  1715. static void __exit intel_ntb_pci_driver_exit(void)
  1716. {
  1717. pci_unregister_driver(&intel_ntb_pci_driver);
  1718. debugfs_remove_recursive(debugfs_dir);
  1719. }
  1720. module_exit(intel_ntb_pci_driver_exit);