ipath_driver.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  1. /*
  2. * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
  3. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/spinlock.h>
  34. #include <linux/idr.h>
  35. #include <linux/pci.h>
  36. #include <linux/io.h>
  37. #include <linux/delay.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/vmalloc.h>
  40. #include "ipath_kernel.h"
  41. #include "ipath_verbs.h"
  42. static void ipath_update_pio_bufs(struct ipath_devdata *);
  43. const char *ipath_get_unit_name(int unit)
  44. {
  45. static char iname[16];
  46. snprintf(iname, sizeof iname, "infinipath%u", unit);
  47. return iname;
  48. }
  49. #define DRIVER_LOAD_MSG "QLogic " IPATH_DRV_NAME " loaded: "
  50. #define PFX IPATH_DRV_NAME ": "
  51. /*
  52. * The size has to be longer than this string, so we can append
  53. * board/chip information to it in the init code.
  54. */
  55. const char ib_ipath_version[] = IPATH_IDSTR "\n";
  56. static struct idr unit_table;
  57. DEFINE_SPINLOCK(ipath_devs_lock);
  58. LIST_HEAD(ipath_dev_list);
  59. wait_queue_head_t ipath_state_wait;
  60. unsigned ipath_debug = __IPATH_INFO;
  61. module_param_named(debug, ipath_debug, uint, S_IWUSR | S_IRUGO);
  62. MODULE_PARM_DESC(debug, "mask for debug prints");
  63. EXPORT_SYMBOL_GPL(ipath_debug);
  64. unsigned ipath_mtu4096 = 1; /* max 4KB IB mtu by default, if supported */
  65. module_param_named(mtu4096, ipath_mtu4096, uint, S_IRUGO);
  66. MODULE_PARM_DESC(mtu4096, "enable MTU of 4096 bytes, if supported");
  67. static unsigned ipath_hol_timeout_ms = 13000;
  68. module_param_named(hol_timeout_ms, ipath_hol_timeout_ms, uint, S_IRUGO);
  69. MODULE_PARM_DESC(hol_timeout_ms,
  70. "duration of user app suspension after link failure");
  71. unsigned ipath_linkrecovery = 1;
  72. module_param_named(linkrecovery, ipath_linkrecovery, uint, S_IWUSR | S_IRUGO);
  73. MODULE_PARM_DESC(linkrecovery, "enable workaround for link recovery issue");
  74. MODULE_LICENSE("GPL");
  75. MODULE_AUTHOR("QLogic <support@qlogic.com>");
  76. MODULE_DESCRIPTION("QLogic InfiniPath driver");
  77. /*
  78. * Table to translate the LINKTRAININGSTATE portion of
  79. * IBCStatus to a human-readable form.
  80. */
  81. const char *ipath_ibcstatus_str[] = {
  82. "Disabled",
  83. "LinkUp",
  84. "PollActive",
  85. "PollQuiet",
  86. "SleepDelay",
  87. "SleepQuiet",
  88. "LState6", /* unused */
  89. "LState7", /* unused */
  90. "CfgDebounce",
  91. "CfgRcvfCfg",
  92. "CfgWaitRmt",
  93. "CfgIdle",
  94. "RecovRetrain",
  95. "CfgTxRevLane", /* unused before IBA7220 */
  96. "RecovWaitRmt",
  97. "RecovIdle",
  98. /* below were added for IBA7220 */
  99. "CfgEnhanced",
  100. "CfgTest",
  101. "CfgWaitRmtTest",
  102. "CfgWaitCfgEnhanced",
  103. "SendTS_T",
  104. "SendTstIdles",
  105. "RcvTS_T",
  106. "SendTst_TS1s",
  107. "LTState18", "LTState19", "LTState1A", "LTState1B",
  108. "LTState1C", "LTState1D", "LTState1E", "LTState1F"
  109. };
  110. static void __devexit ipath_remove_one(struct pci_dev *);
  111. static int __devinit ipath_init_one(struct pci_dev *,
  112. const struct pci_device_id *);
  113. /* Only needed for registration, nothing else needs this info */
  114. #define PCI_VENDOR_ID_PATHSCALE 0x1fc1
  115. #define PCI_VENDOR_ID_QLOGIC 0x1077
  116. #define PCI_DEVICE_ID_INFINIPATH_HT 0xd
  117. #define PCI_DEVICE_ID_INFINIPATH_PE800 0x10
  118. #define PCI_DEVICE_ID_INFINIPATH_7220 0x7220
  119. /* Number of seconds before our card status check... */
  120. #define STATUS_TIMEOUT 60
  121. static const struct pci_device_id ipath_pci_tbl[] = {
  122. { PCI_DEVICE(PCI_VENDOR_ID_PATHSCALE, PCI_DEVICE_ID_INFINIPATH_HT) },
  123. { PCI_DEVICE(PCI_VENDOR_ID_PATHSCALE, PCI_DEVICE_ID_INFINIPATH_PE800) },
  124. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_INFINIPATH_7220) },
  125. { 0, }
  126. };
  127. MODULE_DEVICE_TABLE(pci, ipath_pci_tbl);
  128. static struct pci_driver ipath_driver = {
  129. .name = IPATH_DRV_NAME,
  130. .probe = ipath_init_one,
  131. .remove = __devexit_p(ipath_remove_one),
  132. .id_table = ipath_pci_tbl,
  133. .driver = {
  134. .groups = ipath_driver_attr_groups,
  135. },
  136. };
  137. static inline void read_bars(struct ipath_devdata *dd, struct pci_dev *dev,
  138. u32 *bar0, u32 *bar1)
  139. {
  140. int ret;
  141. ret = pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
  142. if (ret)
  143. ipath_dev_err(dd, "failed to read bar0 before enable: "
  144. "error %d\n", -ret);
  145. ret = pci_read_config_dword(dev, PCI_BASE_ADDRESS_1, bar1);
  146. if (ret)
  147. ipath_dev_err(dd, "failed to read bar1 before enable: "
  148. "error %d\n", -ret);
  149. ipath_dbg("Read bar0 %x bar1 %x\n", *bar0, *bar1);
  150. }
  151. static void ipath_free_devdata(struct pci_dev *pdev,
  152. struct ipath_devdata *dd)
  153. {
  154. unsigned long flags;
  155. pci_set_drvdata(pdev, NULL);
  156. if (dd->ipath_unit != -1) {
  157. spin_lock_irqsave(&ipath_devs_lock, flags);
  158. idr_remove(&unit_table, dd->ipath_unit);
  159. list_del(&dd->ipath_list);
  160. spin_unlock_irqrestore(&ipath_devs_lock, flags);
  161. }
  162. vfree(dd);
  163. }
  164. static struct ipath_devdata *ipath_alloc_devdata(struct pci_dev *pdev)
  165. {
  166. unsigned long flags;
  167. struct ipath_devdata *dd;
  168. int ret;
  169. if (!idr_pre_get(&unit_table, GFP_KERNEL)) {
  170. dd = ERR_PTR(-ENOMEM);
  171. goto bail;
  172. }
  173. dd = vmalloc(sizeof(*dd));
  174. if (!dd) {
  175. dd = ERR_PTR(-ENOMEM);
  176. goto bail;
  177. }
  178. memset(dd, 0, sizeof(*dd));
  179. dd->ipath_unit = -1;
  180. spin_lock_irqsave(&ipath_devs_lock, flags);
  181. ret = idr_get_new(&unit_table, dd, &dd->ipath_unit);
  182. if (ret < 0) {
  183. printk(KERN_ERR IPATH_DRV_NAME
  184. ": Could not allocate unit ID: error %d\n", -ret);
  185. ipath_free_devdata(pdev, dd);
  186. dd = ERR_PTR(ret);
  187. goto bail_unlock;
  188. }
  189. dd->pcidev = pdev;
  190. pci_set_drvdata(pdev, dd);
  191. list_add(&dd->ipath_list, &ipath_dev_list);
  192. bail_unlock:
  193. spin_unlock_irqrestore(&ipath_devs_lock, flags);
  194. bail:
  195. return dd;
  196. }
  197. static inline struct ipath_devdata *__ipath_lookup(int unit)
  198. {
  199. return idr_find(&unit_table, unit);
  200. }
  201. struct ipath_devdata *ipath_lookup(int unit)
  202. {
  203. struct ipath_devdata *dd;
  204. unsigned long flags;
  205. spin_lock_irqsave(&ipath_devs_lock, flags);
  206. dd = __ipath_lookup(unit);
  207. spin_unlock_irqrestore(&ipath_devs_lock, flags);
  208. return dd;
  209. }
  210. int ipath_count_units(int *npresentp, int *nupp, int *maxportsp)
  211. {
  212. int nunits, npresent, nup;
  213. struct ipath_devdata *dd;
  214. unsigned long flags;
  215. int maxports;
  216. nunits = npresent = nup = maxports = 0;
  217. spin_lock_irqsave(&ipath_devs_lock, flags);
  218. list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
  219. nunits++;
  220. if ((dd->ipath_flags & IPATH_PRESENT) && dd->ipath_kregbase)
  221. npresent++;
  222. if (dd->ipath_lid &&
  223. !(dd->ipath_flags & (IPATH_DISABLED | IPATH_LINKDOWN
  224. | IPATH_LINKUNK)))
  225. nup++;
  226. if (dd->ipath_cfgports > maxports)
  227. maxports = dd->ipath_cfgports;
  228. }
  229. spin_unlock_irqrestore(&ipath_devs_lock, flags);
  230. if (npresentp)
  231. *npresentp = npresent;
  232. if (nupp)
  233. *nupp = nup;
  234. if (maxportsp)
  235. *maxportsp = maxports;
  236. return nunits;
  237. }
  238. /*
  239. * These next two routines are placeholders in case we don't have per-arch
  240. * code for controlling write combining. If explicit control of write
  241. * combining is not available, performance will probably be awful.
  242. */
  243. int __attribute__((weak)) ipath_enable_wc(struct ipath_devdata *dd)
  244. {
  245. return -EOPNOTSUPP;
  246. }
  247. void __attribute__((weak)) ipath_disable_wc(struct ipath_devdata *dd)
  248. {
  249. }
  250. /*
  251. * Perform a PIO buffer bandwidth write test, to verify proper system
  252. * configuration. Even when all the setup calls work, occasionally
  253. * BIOS or other issues can prevent write combining from working, or
  254. * can cause other bandwidth problems to the chip.
  255. *
  256. * This test simply writes the same buffer over and over again, and
  257. * measures close to the peak bandwidth to the chip (not testing
  258. * data bandwidth to the wire). On chips that use an address-based
  259. * trigger to send packets to the wire, this is easy. On chips that
  260. * use a count to trigger, we want to make sure that the packet doesn't
  261. * go out on the wire, or trigger flow control checks.
  262. */
  263. static void ipath_verify_pioperf(struct ipath_devdata *dd)
  264. {
  265. u32 pbnum, cnt, lcnt;
  266. u32 __iomem *piobuf;
  267. u32 *addr;
  268. u64 msecs, emsecs;
  269. piobuf = ipath_getpiobuf(dd, 0, &pbnum);
  270. if (!piobuf) {
  271. dev_info(&dd->pcidev->dev,
  272. "No PIObufs for checking perf, skipping\n");
  273. return;
  274. }
  275. /*
  276. * Enough to give us a reasonable test, less than piobuf size, and
  277. * likely multiple of store buffer length.
  278. */
  279. cnt = 1024;
  280. addr = vmalloc(cnt);
  281. if (!addr) {
  282. dev_info(&dd->pcidev->dev,
  283. "Couldn't get memory for checking PIO perf,"
  284. " skipping\n");
  285. goto done;
  286. }
  287. preempt_disable(); /* we want reasonably accurate elapsed time */
  288. msecs = 1 + jiffies_to_msecs(jiffies);
  289. for (lcnt = 0; lcnt < 10000U; lcnt++) {
  290. /* wait until we cross msec boundary */
  291. if (jiffies_to_msecs(jiffies) >= msecs)
  292. break;
  293. udelay(1);
  294. }
  295. ipath_disable_armlaunch(dd);
  296. /*
  297. * length 0, no dwords actually sent, and mark as VL15
  298. * on chips where that may matter (due to IB flowcontrol)
  299. */
  300. if ((dd->ipath_flags & IPATH_HAS_PBC_CNT))
  301. writeq(1UL << 63, piobuf);
  302. else
  303. writeq(0, piobuf);
  304. ipath_flush_wc();
  305. /*
  306. * this is only roughly accurate, since even with preempt we
  307. * still take interrupts that could take a while. Running for
  308. * >= 5 msec seems to get us "close enough" to accurate values
  309. */
  310. msecs = jiffies_to_msecs(jiffies);
  311. for (emsecs = lcnt = 0; emsecs <= 5UL; lcnt++) {
  312. __iowrite32_copy(piobuf + 64, addr, cnt >> 2);
  313. emsecs = jiffies_to_msecs(jiffies) - msecs;
  314. }
  315. /* 1 GiB/sec, slightly over IB SDR line rate */
  316. if (lcnt < (emsecs * 1024U))
  317. ipath_dev_err(dd,
  318. "Performance problem: bandwidth to PIO buffers is "
  319. "only %u MiB/sec\n",
  320. lcnt / (u32) emsecs);
  321. else
  322. ipath_dbg("PIO buffer bandwidth %u MiB/sec is OK\n",
  323. lcnt / (u32) emsecs);
  324. preempt_enable();
  325. vfree(addr);
  326. done:
  327. /* disarm piobuf, so it's available again */
  328. ipath_disarm_piobufs(dd, pbnum, 1);
  329. ipath_enable_armlaunch(dd);
  330. }
  331. static int __devinit ipath_init_one(struct pci_dev *pdev,
  332. const struct pci_device_id *ent)
  333. {
  334. int ret, len, j;
  335. struct ipath_devdata *dd;
  336. unsigned long long addr;
  337. u32 bar0 = 0, bar1 = 0;
  338. u8 rev;
  339. dd = ipath_alloc_devdata(pdev);
  340. if (IS_ERR(dd)) {
  341. ret = PTR_ERR(dd);
  342. printk(KERN_ERR IPATH_DRV_NAME
  343. ": Could not allocate devdata: error %d\n", -ret);
  344. goto bail;
  345. }
  346. ipath_cdbg(VERBOSE, "initializing unit #%u\n", dd->ipath_unit);
  347. ret = pci_enable_device(pdev);
  348. if (ret) {
  349. /* This can happen iff:
  350. *
  351. * We did a chip reset, and then failed to reprogram the
  352. * BAR, or the chip reset due to an internal error. We then
  353. * unloaded the driver and reloaded it.
  354. *
  355. * Both reset cases set the BAR back to initial state. For
  356. * the latter case, the AER sticky error bit at offset 0x718
  357. * should be set, but the Linux kernel doesn't yet know
  358. * about that, it appears. If the original BAR was retained
  359. * in the kernel data structures, this may be OK.
  360. */
  361. ipath_dev_err(dd, "enable unit %d failed: error %d\n",
  362. dd->ipath_unit, -ret);
  363. goto bail_devdata;
  364. }
  365. addr = pci_resource_start(pdev, 0);
  366. len = pci_resource_len(pdev, 0);
  367. ipath_cdbg(VERBOSE, "regbase (0) %llx len %d irq %d, vend %x/%x "
  368. "driver_data %lx\n", addr, len, pdev->irq, ent->vendor,
  369. ent->device, ent->driver_data);
  370. read_bars(dd, pdev, &bar0, &bar1);
  371. if (!bar1 && !(bar0 & ~0xf)) {
  372. if (addr) {
  373. dev_info(&pdev->dev, "BAR is 0 (probable RESET), "
  374. "rewriting as %llx\n", addr);
  375. ret = pci_write_config_dword(
  376. pdev, PCI_BASE_ADDRESS_0, addr);
  377. if (ret) {
  378. ipath_dev_err(dd, "rewrite of BAR0 "
  379. "failed: err %d\n", -ret);
  380. goto bail_disable;
  381. }
  382. ret = pci_write_config_dword(
  383. pdev, PCI_BASE_ADDRESS_1, addr >> 32);
  384. if (ret) {
  385. ipath_dev_err(dd, "rewrite of BAR1 "
  386. "failed: err %d\n", -ret);
  387. goto bail_disable;
  388. }
  389. } else {
  390. ipath_dev_err(dd, "BAR is 0 (probable RESET), "
  391. "not usable until reboot\n");
  392. ret = -ENODEV;
  393. goto bail_disable;
  394. }
  395. }
  396. ret = pci_request_regions(pdev, IPATH_DRV_NAME);
  397. if (ret) {
  398. dev_info(&pdev->dev, "pci_request_regions unit %u fails: "
  399. "err %d\n", dd->ipath_unit, -ret);
  400. goto bail_disable;
  401. }
  402. ret = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  403. if (ret) {
  404. /*
  405. * if the 64 bit setup fails, try 32 bit. Some systems
  406. * do not setup 64 bit maps on systems with 2GB or less
  407. * memory installed.
  408. */
  409. ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  410. if (ret) {
  411. dev_info(&pdev->dev,
  412. "Unable to set DMA mask for unit %u: %d\n",
  413. dd->ipath_unit, ret);
  414. goto bail_regions;
  415. }
  416. else {
  417. ipath_dbg("No 64bit DMA mask, used 32 bit mask\n");
  418. ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  419. if (ret)
  420. dev_info(&pdev->dev,
  421. "Unable to set DMA consistent mask "
  422. "for unit %u: %d\n",
  423. dd->ipath_unit, ret);
  424. }
  425. }
  426. else {
  427. ret = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  428. if (ret)
  429. dev_info(&pdev->dev,
  430. "Unable to set DMA consistent mask "
  431. "for unit %u: %d\n",
  432. dd->ipath_unit, ret);
  433. }
  434. pci_set_master(pdev);
  435. /*
  436. * Save BARs to rewrite after device reset. Save all 64 bits of
  437. * BAR, just in case.
  438. */
  439. dd->ipath_pcibar0 = addr;
  440. dd->ipath_pcibar1 = addr >> 32;
  441. dd->ipath_deviceid = ent->device; /* save for later use */
  442. dd->ipath_vendorid = ent->vendor;
  443. /* setup the chip-specific functions, as early as possible. */
  444. switch (ent->device) {
  445. case PCI_DEVICE_ID_INFINIPATH_HT:
  446. #ifdef CONFIG_HT_IRQ
  447. ipath_init_iba6110_funcs(dd);
  448. break;
  449. #else
  450. ipath_dev_err(dd, "QLogic HT device 0x%x cannot work if "
  451. "CONFIG_HT_IRQ is not enabled\n", ent->device);
  452. return -ENODEV;
  453. #endif
  454. case PCI_DEVICE_ID_INFINIPATH_PE800:
  455. #ifdef CONFIG_PCI_MSI
  456. ipath_init_iba6120_funcs(dd);
  457. break;
  458. #else
  459. ipath_dev_err(dd, "QLogic PCIE device 0x%x cannot work if "
  460. "CONFIG_PCI_MSI is not enabled\n", ent->device);
  461. return -ENODEV;
  462. #endif
  463. case PCI_DEVICE_ID_INFINIPATH_7220:
  464. #ifndef CONFIG_PCI_MSI
  465. ipath_dbg("CONFIG_PCI_MSI is not enabled, "
  466. "using INTx for unit %u\n", dd->ipath_unit);
  467. #endif
  468. ipath_init_iba7220_funcs(dd);
  469. break;
  470. default:
  471. ipath_dev_err(dd, "Found unknown QLogic deviceid 0x%x, "
  472. "failing\n", ent->device);
  473. return -ENODEV;
  474. }
  475. for (j = 0; j < 6; j++) {
  476. if (!pdev->resource[j].start)
  477. continue;
  478. ipath_cdbg(VERBOSE, "BAR %d start %llx, end %llx, len %llx\n",
  479. j, (unsigned long long)pdev->resource[j].start,
  480. (unsigned long long)pdev->resource[j].end,
  481. (unsigned long long)pci_resource_len(pdev, j));
  482. }
  483. if (!addr) {
  484. ipath_dev_err(dd, "No valid address in BAR 0!\n");
  485. ret = -ENODEV;
  486. goto bail_regions;
  487. }
  488. ret = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  489. if (ret) {
  490. ipath_dev_err(dd, "Failed to read PCI revision ID unit "
  491. "%u: err %d\n", dd->ipath_unit, -ret);
  492. goto bail_regions; /* shouldn't ever happen */
  493. }
  494. dd->ipath_pcirev = rev;
  495. #if defined(__powerpc__)
  496. /* There isn't a generic way to specify writethrough mappings */
  497. dd->ipath_kregbase = __ioremap(addr, len,
  498. (_PAGE_NO_CACHE|_PAGE_WRITETHRU));
  499. #else
  500. dd->ipath_kregbase = ioremap_nocache(addr, len);
  501. #endif
  502. if (!dd->ipath_kregbase) {
  503. ipath_dbg("Unable to map io addr %llx to kvirt, failing\n",
  504. addr);
  505. ret = -ENOMEM;
  506. goto bail_iounmap;
  507. }
  508. dd->ipath_kregend = (u64 __iomem *)
  509. ((void __iomem *)dd->ipath_kregbase + len);
  510. dd->ipath_physaddr = addr; /* used for io_remap, etc. */
  511. /* for user mmap */
  512. ipath_cdbg(VERBOSE, "mapped io addr %llx to kregbase %p\n",
  513. addr, dd->ipath_kregbase);
  514. if (dd->ipath_f_bus(dd, pdev))
  515. ipath_dev_err(dd, "Failed to setup config space; "
  516. "continuing anyway\n");
  517. /*
  518. * set up our interrupt handler; IRQF_SHARED probably not needed,
  519. * since MSI interrupts shouldn't be shared but won't hurt for now.
  520. * check 0 irq after we return from chip-specific bus setup, since
  521. * that can affect this due to setup
  522. */
  523. if (!dd->ipath_irq)
  524. ipath_dev_err(dd, "irq is 0, BIOS error? Interrupts won't "
  525. "work\n");
  526. else {
  527. ret = request_irq(dd->ipath_irq, ipath_intr, IRQF_SHARED,
  528. IPATH_DRV_NAME, dd);
  529. if (ret) {
  530. ipath_dev_err(dd, "Couldn't setup irq handler, "
  531. "irq=%d: %d\n", dd->ipath_irq, ret);
  532. goto bail_iounmap;
  533. }
  534. }
  535. ret = ipath_init_chip(dd, 0); /* do the chip-specific init */
  536. if (ret)
  537. goto bail_irqsetup;
  538. ret = ipath_enable_wc(dd);
  539. if (ret) {
  540. ipath_dev_err(dd, "Write combining not enabled "
  541. "(err %d): performance may be poor\n",
  542. -ret);
  543. ret = 0;
  544. }
  545. ipath_verify_pioperf(dd);
  546. ipath_device_create_group(&pdev->dev, dd);
  547. ipathfs_add_device(dd);
  548. ipath_user_add(dd);
  549. ipath_diag_add(dd);
  550. ipath_register_ib_device(dd);
  551. goto bail;
  552. bail_irqsetup:
  553. if (pdev->irq)
  554. free_irq(pdev->irq, dd);
  555. bail_iounmap:
  556. iounmap((volatile void __iomem *) dd->ipath_kregbase);
  557. bail_regions:
  558. pci_release_regions(pdev);
  559. bail_disable:
  560. pci_disable_device(pdev);
  561. bail_devdata:
  562. ipath_free_devdata(pdev, dd);
  563. bail:
  564. return ret;
  565. }
  566. static void __devexit cleanup_device(struct ipath_devdata *dd)
  567. {
  568. int port;
  569. if (*dd->ipath_statusp & IPATH_STATUS_CHIP_PRESENT) {
  570. /* can't do anything more with chip; needs re-init */
  571. *dd->ipath_statusp &= ~IPATH_STATUS_CHIP_PRESENT;
  572. if (dd->ipath_kregbase) {
  573. /*
  574. * if we haven't already cleaned up before these are
  575. * to ensure any register reads/writes "fail" until
  576. * re-init
  577. */
  578. dd->ipath_kregbase = NULL;
  579. dd->ipath_uregbase = 0;
  580. dd->ipath_sregbase = 0;
  581. dd->ipath_cregbase = 0;
  582. dd->ipath_kregsize = 0;
  583. }
  584. ipath_disable_wc(dd);
  585. }
  586. if (dd->ipath_spectriggerhit)
  587. dev_info(&dd->pcidev->dev, "%lu special trigger hits\n",
  588. dd->ipath_spectriggerhit);
  589. if (dd->ipath_pioavailregs_dma) {
  590. dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
  591. (void *) dd->ipath_pioavailregs_dma,
  592. dd->ipath_pioavailregs_phys);
  593. dd->ipath_pioavailregs_dma = NULL;
  594. }
  595. if (dd->ipath_dummy_hdrq) {
  596. dma_free_coherent(&dd->pcidev->dev,
  597. dd->ipath_pd[0]->port_rcvhdrq_size,
  598. dd->ipath_dummy_hdrq, dd->ipath_dummy_hdrq_phys);
  599. dd->ipath_dummy_hdrq = NULL;
  600. }
  601. if (dd->ipath_pageshadow) {
  602. struct page **tmpp = dd->ipath_pageshadow;
  603. dma_addr_t *tmpd = dd->ipath_physshadow;
  604. int i, cnt = 0;
  605. ipath_cdbg(VERBOSE, "Unlocking any expTID pages still "
  606. "locked\n");
  607. for (port = 0; port < dd->ipath_cfgports; port++) {
  608. int port_tidbase = port * dd->ipath_rcvtidcnt;
  609. int maxtid = port_tidbase + dd->ipath_rcvtidcnt;
  610. for (i = port_tidbase; i < maxtid; i++) {
  611. if (!tmpp[i])
  612. continue;
  613. pci_unmap_page(dd->pcidev, tmpd[i],
  614. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  615. ipath_release_user_pages(&tmpp[i], 1);
  616. tmpp[i] = NULL;
  617. cnt++;
  618. }
  619. }
  620. if (cnt) {
  621. ipath_stats.sps_pageunlocks += cnt;
  622. ipath_cdbg(VERBOSE, "There were still %u expTID "
  623. "entries locked\n", cnt);
  624. }
  625. if (ipath_stats.sps_pagelocks ||
  626. ipath_stats.sps_pageunlocks)
  627. ipath_cdbg(VERBOSE, "%llu pages locked, %llu "
  628. "unlocked via ipath_m{un}lock\n",
  629. (unsigned long long)
  630. ipath_stats.sps_pagelocks,
  631. (unsigned long long)
  632. ipath_stats.sps_pageunlocks);
  633. ipath_cdbg(VERBOSE, "Free shadow page tid array at %p\n",
  634. dd->ipath_pageshadow);
  635. tmpp = dd->ipath_pageshadow;
  636. dd->ipath_pageshadow = NULL;
  637. vfree(tmpp);
  638. dd->ipath_egrtidbase = NULL;
  639. }
  640. /*
  641. * free any resources still in use (usually just kernel ports)
  642. * at unload; we do for portcnt, not cfgports, because cfgports
  643. * could have changed while we were loaded.
  644. */
  645. for (port = 0; port < dd->ipath_portcnt; port++) {
  646. struct ipath_portdata *pd = dd->ipath_pd[port];
  647. dd->ipath_pd[port] = NULL;
  648. ipath_free_pddata(dd, pd);
  649. }
  650. kfree(dd->ipath_pd);
  651. /*
  652. * debuggability, in case some cleanup path tries to use it
  653. * after this
  654. */
  655. dd->ipath_pd = NULL;
  656. }
  657. static void __devexit ipath_remove_one(struct pci_dev *pdev)
  658. {
  659. struct ipath_devdata *dd = pci_get_drvdata(pdev);
  660. ipath_cdbg(VERBOSE, "removing, pdev=%p, dd=%p\n", pdev, dd);
  661. /*
  662. * disable the IB link early, to be sure no new packets arrive, which
  663. * complicates the shutdown process
  664. */
  665. ipath_shutdown_device(dd);
  666. flush_scheduled_work();
  667. if (dd->verbs_dev)
  668. ipath_unregister_ib_device(dd->verbs_dev);
  669. ipath_diag_remove(dd);
  670. ipath_user_remove(dd);
  671. ipathfs_remove_device(dd);
  672. ipath_device_remove_group(&pdev->dev, dd);
  673. ipath_cdbg(VERBOSE, "Releasing pci memory regions, dd %p, "
  674. "unit %u\n", dd, (u32) dd->ipath_unit);
  675. cleanup_device(dd);
  676. /*
  677. * turn off rcv, send, and interrupts for all ports, all drivers
  678. * should also hard reset the chip here?
  679. * free up port 0 (kernel) rcvhdr, egr bufs, and eventually tid bufs
  680. * for all versions of the driver, if they were allocated
  681. */
  682. if (dd->ipath_irq) {
  683. ipath_cdbg(VERBOSE, "unit %u free irq %d\n",
  684. dd->ipath_unit, dd->ipath_irq);
  685. dd->ipath_f_free_irq(dd);
  686. } else
  687. ipath_dbg("irq is 0, not doing free_irq "
  688. "for unit %u\n", dd->ipath_unit);
  689. /*
  690. * we check for NULL here, because it's outside
  691. * the kregbase check, and we need to call it
  692. * after the free_irq. Thus it's possible that
  693. * the function pointers were never initialized.
  694. */
  695. if (dd->ipath_f_cleanup)
  696. /* clean up chip-specific stuff */
  697. dd->ipath_f_cleanup(dd);
  698. ipath_cdbg(VERBOSE, "Unmapping kregbase %p\n", dd->ipath_kregbase);
  699. iounmap((volatile void __iomem *) dd->ipath_kregbase);
  700. pci_release_regions(pdev);
  701. ipath_cdbg(VERBOSE, "calling pci_disable_device\n");
  702. pci_disable_device(pdev);
  703. ipath_free_devdata(pdev, dd);
  704. }
  705. /* general driver use */
  706. DEFINE_MUTEX(ipath_mutex);
  707. static DEFINE_SPINLOCK(ipath_pioavail_lock);
  708. /**
  709. * ipath_disarm_piobufs - cancel a range of PIO buffers
  710. * @dd: the infinipath device
  711. * @first: the first PIO buffer to cancel
  712. * @cnt: the number of PIO buffers to cancel
  713. *
  714. * cancel a range of PIO buffers, used when they might be armed, but
  715. * not triggered. Used at init to ensure buffer state, and also user
  716. * process close, in case it died while writing to a PIO buffer
  717. * Also after errors.
  718. */
  719. void ipath_disarm_piobufs(struct ipath_devdata *dd, unsigned first,
  720. unsigned cnt)
  721. {
  722. unsigned i, last = first + cnt;
  723. unsigned long flags;
  724. ipath_cdbg(PKT, "disarm %u PIObufs first=%u\n", cnt, first);
  725. for (i = first; i < last; i++) {
  726. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  727. /*
  728. * The disarm-related bits are write-only, so it
  729. * is ok to OR them in with our copy of sendctrl
  730. * while we hold the lock.
  731. */
  732. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  733. dd->ipath_sendctrl | INFINIPATH_S_DISARM |
  734. (i << INFINIPATH_S_DISARMPIOBUF_SHIFT));
  735. /* can't disarm bufs back-to-back per iba7220 spec */
  736. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  737. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  738. }
  739. /* on some older chips, update may not happen after cancel */
  740. ipath_force_pio_avail_update(dd);
  741. }
  742. /**
  743. * ipath_wait_linkstate - wait for an IB link state change to occur
  744. * @dd: the infinipath device
  745. * @state: the state to wait for
  746. * @msecs: the number of milliseconds to wait
  747. *
  748. * wait up to msecs milliseconds for IB link state change to occur for
  749. * now, take the easy polling route. Currently used only by
  750. * ipath_set_linkstate. Returns 0 if state reached, otherwise
  751. * -ETIMEDOUT state can have multiple states set, for any of several
  752. * transitions.
  753. */
  754. int ipath_wait_linkstate(struct ipath_devdata *dd, u32 state, int msecs)
  755. {
  756. dd->ipath_state_wanted = state;
  757. wait_event_interruptible_timeout(ipath_state_wait,
  758. (dd->ipath_flags & state),
  759. msecs_to_jiffies(msecs));
  760. dd->ipath_state_wanted = 0;
  761. if (!(dd->ipath_flags & state)) {
  762. u64 val;
  763. ipath_cdbg(VERBOSE, "Didn't reach linkstate %s within %u"
  764. " ms\n",
  765. /* test INIT ahead of DOWN, both can be set */
  766. (state & IPATH_LINKINIT) ? "INIT" :
  767. ((state & IPATH_LINKDOWN) ? "DOWN" :
  768. ((state & IPATH_LINKARMED) ? "ARM" : "ACTIVE")),
  769. msecs);
  770. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
  771. ipath_cdbg(VERBOSE, "ibcc=%llx ibcstatus=%llx (%s)\n",
  772. (unsigned long long) ipath_read_kreg64(
  773. dd, dd->ipath_kregs->kr_ibcctrl),
  774. (unsigned long long) val,
  775. ipath_ibcstatus_str[val & dd->ibcs_lts_mask]);
  776. }
  777. return (dd->ipath_flags & state) ? 0 : -ETIMEDOUT;
  778. }
  779. static void decode_sdma_errs(struct ipath_devdata *dd, ipath_err_t err,
  780. char *buf, size_t blen)
  781. {
  782. static const struct {
  783. ipath_err_t err;
  784. const char *msg;
  785. } errs[] = {
  786. { INFINIPATH_E_SDMAGENMISMATCH, "SDmaGenMismatch" },
  787. { INFINIPATH_E_SDMAOUTOFBOUND, "SDmaOutOfBound" },
  788. { INFINIPATH_E_SDMATAILOUTOFBOUND, "SDmaTailOutOfBound" },
  789. { INFINIPATH_E_SDMABASE, "SDmaBase" },
  790. { INFINIPATH_E_SDMA1STDESC, "SDma1stDesc" },
  791. { INFINIPATH_E_SDMARPYTAG, "SDmaRpyTag" },
  792. { INFINIPATH_E_SDMADWEN, "SDmaDwEn" },
  793. { INFINIPATH_E_SDMAMISSINGDW, "SDmaMissingDw" },
  794. { INFINIPATH_E_SDMAUNEXPDATA, "SDmaUnexpData" },
  795. { INFINIPATH_E_SDMADESCADDRMISALIGN, "SDmaDescAddrMisalign" },
  796. { INFINIPATH_E_SENDBUFMISUSE, "SendBufMisuse" },
  797. { INFINIPATH_E_SDMADISABLED, "SDmaDisabled" },
  798. };
  799. int i;
  800. int expected;
  801. size_t bidx = 0;
  802. for (i = 0; i < ARRAY_SIZE(errs); i++) {
  803. expected = (errs[i].err != INFINIPATH_E_SDMADISABLED) ? 0 :
  804. test_bit(IPATH_SDMA_ABORTING, &dd->ipath_sdma_status);
  805. if ((err & errs[i].err) && !expected)
  806. bidx += snprintf(buf + bidx, blen - bidx,
  807. "%s ", errs[i].msg);
  808. }
  809. }
  810. /*
  811. * Decode the error status into strings, deciding whether to always
  812. * print * it or not depending on "normal packet errors" vs everything
  813. * else. Return 1 if "real" errors, otherwise 0 if only packet
  814. * errors, so caller can decide what to print with the string.
  815. */
  816. int ipath_decode_err(struct ipath_devdata *dd, char *buf, size_t blen,
  817. ipath_err_t err)
  818. {
  819. int iserr = 1;
  820. *buf = '\0';
  821. if (err & INFINIPATH_E_PKTERRS) {
  822. if (!(err & ~INFINIPATH_E_PKTERRS))
  823. iserr = 0; // if only packet errors.
  824. if (ipath_debug & __IPATH_ERRPKTDBG) {
  825. if (err & INFINIPATH_E_REBP)
  826. strlcat(buf, "EBP ", blen);
  827. if (err & INFINIPATH_E_RVCRC)
  828. strlcat(buf, "VCRC ", blen);
  829. if (err & INFINIPATH_E_RICRC) {
  830. strlcat(buf, "CRC ", blen);
  831. // clear for check below, so only once
  832. err &= INFINIPATH_E_RICRC;
  833. }
  834. if (err & INFINIPATH_E_RSHORTPKTLEN)
  835. strlcat(buf, "rshortpktlen ", blen);
  836. if (err & INFINIPATH_E_SDROPPEDDATAPKT)
  837. strlcat(buf, "sdroppeddatapkt ", blen);
  838. if (err & INFINIPATH_E_SPKTLEN)
  839. strlcat(buf, "spktlen ", blen);
  840. }
  841. if ((err & INFINIPATH_E_RICRC) &&
  842. !(err&(INFINIPATH_E_RVCRC|INFINIPATH_E_REBP)))
  843. strlcat(buf, "CRC ", blen);
  844. if (!iserr)
  845. goto done;
  846. }
  847. if (err & INFINIPATH_E_RHDRLEN)
  848. strlcat(buf, "rhdrlen ", blen);
  849. if (err & INFINIPATH_E_RBADTID)
  850. strlcat(buf, "rbadtid ", blen);
  851. if (err & INFINIPATH_E_RBADVERSION)
  852. strlcat(buf, "rbadversion ", blen);
  853. if (err & INFINIPATH_E_RHDR)
  854. strlcat(buf, "rhdr ", blen);
  855. if (err & INFINIPATH_E_SENDSPECIALTRIGGER)
  856. strlcat(buf, "sendspecialtrigger ", blen);
  857. if (err & INFINIPATH_E_RLONGPKTLEN)
  858. strlcat(buf, "rlongpktlen ", blen);
  859. if (err & INFINIPATH_E_RMAXPKTLEN)
  860. strlcat(buf, "rmaxpktlen ", blen);
  861. if (err & INFINIPATH_E_RMINPKTLEN)
  862. strlcat(buf, "rminpktlen ", blen);
  863. if (err & INFINIPATH_E_SMINPKTLEN)
  864. strlcat(buf, "sminpktlen ", blen);
  865. if (err & INFINIPATH_E_RFORMATERR)
  866. strlcat(buf, "rformaterr ", blen);
  867. if (err & INFINIPATH_E_RUNSUPVL)
  868. strlcat(buf, "runsupvl ", blen);
  869. if (err & INFINIPATH_E_RUNEXPCHAR)
  870. strlcat(buf, "runexpchar ", blen);
  871. if (err & INFINIPATH_E_RIBFLOW)
  872. strlcat(buf, "ribflow ", blen);
  873. if (err & INFINIPATH_E_SUNDERRUN)
  874. strlcat(buf, "sunderrun ", blen);
  875. if (err & INFINIPATH_E_SPIOARMLAUNCH)
  876. strlcat(buf, "spioarmlaunch ", blen);
  877. if (err & INFINIPATH_E_SUNEXPERRPKTNUM)
  878. strlcat(buf, "sunexperrpktnum ", blen);
  879. if (err & INFINIPATH_E_SDROPPEDSMPPKT)
  880. strlcat(buf, "sdroppedsmppkt ", blen);
  881. if (err & INFINIPATH_E_SMAXPKTLEN)
  882. strlcat(buf, "smaxpktlen ", blen);
  883. if (err & INFINIPATH_E_SUNSUPVL)
  884. strlcat(buf, "sunsupVL ", blen);
  885. if (err & INFINIPATH_E_INVALIDADDR)
  886. strlcat(buf, "invalidaddr ", blen);
  887. if (err & INFINIPATH_E_RRCVEGRFULL)
  888. strlcat(buf, "rcvegrfull ", blen);
  889. if (err & INFINIPATH_E_RRCVHDRFULL)
  890. strlcat(buf, "rcvhdrfull ", blen);
  891. if (err & INFINIPATH_E_IBSTATUSCHANGED)
  892. strlcat(buf, "ibcstatuschg ", blen);
  893. if (err & INFINIPATH_E_RIBLOSTLINK)
  894. strlcat(buf, "riblostlink ", blen);
  895. if (err & INFINIPATH_E_HARDWARE)
  896. strlcat(buf, "hardware ", blen);
  897. if (err & INFINIPATH_E_RESET)
  898. strlcat(buf, "reset ", blen);
  899. if (err & INFINIPATH_E_SDMAERRS)
  900. decode_sdma_errs(dd, err, buf, blen);
  901. if (err & INFINIPATH_E_INVALIDEEPCMD)
  902. strlcat(buf, "invalideepromcmd ", blen);
  903. done:
  904. return iserr;
  905. }
  906. /**
  907. * get_rhf_errstring - decode RHF errors
  908. * @err: the err number
  909. * @msg: the output buffer
  910. * @len: the length of the output buffer
  911. *
  912. * only used one place now, may want more later
  913. */
  914. static void get_rhf_errstring(u32 err, char *msg, size_t len)
  915. {
  916. /* if no errors, and so don't need to check what's first */
  917. *msg = '\0';
  918. if (err & INFINIPATH_RHF_H_ICRCERR)
  919. strlcat(msg, "icrcerr ", len);
  920. if (err & INFINIPATH_RHF_H_VCRCERR)
  921. strlcat(msg, "vcrcerr ", len);
  922. if (err & INFINIPATH_RHF_H_PARITYERR)
  923. strlcat(msg, "parityerr ", len);
  924. if (err & INFINIPATH_RHF_H_LENERR)
  925. strlcat(msg, "lenerr ", len);
  926. if (err & INFINIPATH_RHF_H_MTUERR)
  927. strlcat(msg, "mtuerr ", len);
  928. if (err & INFINIPATH_RHF_H_IHDRERR)
  929. /* infinipath hdr checksum error */
  930. strlcat(msg, "ipathhdrerr ", len);
  931. if (err & INFINIPATH_RHF_H_TIDERR)
  932. strlcat(msg, "tiderr ", len);
  933. if (err & INFINIPATH_RHF_H_MKERR)
  934. /* bad port, offset, etc. */
  935. strlcat(msg, "invalid ipathhdr ", len);
  936. if (err & INFINIPATH_RHF_H_IBERR)
  937. strlcat(msg, "iberr ", len);
  938. if (err & INFINIPATH_RHF_L_SWA)
  939. strlcat(msg, "swA ", len);
  940. if (err & INFINIPATH_RHF_L_SWB)
  941. strlcat(msg, "swB ", len);
  942. }
  943. /**
  944. * ipath_get_egrbuf - get an eager buffer
  945. * @dd: the infinipath device
  946. * @bufnum: the eager buffer to get
  947. *
  948. * must only be called if ipath_pd[port] is known to be allocated
  949. */
  950. static inline void *ipath_get_egrbuf(struct ipath_devdata *dd, u32 bufnum)
  951. {
  952. return dd->ipath_port0_skbinfo ?
  953. (void *) dd->ipath_port0_skbinfo[bufnum].skb->data : NULL;
  954. }
  955. /**
  956. * ipath_alloc_skb - allocate an skb and buffer with possible constraints
  957. * @dd: the infinipath device
  958. * @gfp_mask: the sk_buff SFP mask
  959. */
  960. struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd,
  961. gfp_t gfp_mask)
  962. {
  963. struct sk_buff *skb;
  964. u32 len;
  965. /*
  966. * Only fully supported way to handle this is to allocate lots
  967. * extra, align as needed, and then do skb_reserve(). That wastes
  968. * a lot of memory... I'll have to hack this into infinipath_copy
  969. * also.
  970. */
  971. /*
  972. * We need 2 extra bytes for ipath_ether data sent in the
  973. * key header. In order to keep everything dword aligned,
  974. * we'll reserve 4 bytes.
  975. */
  976. len = dd->ipath_ibmaxlen + 4;
  977. if (dd->ipath_flags & IPATH_4BYTE_TID) {
  978. /* We need a 2KB multiple alignment, and there is no way
  979. * to do it except to allocate extra and then skb_reserve
  980. * enough to bring it up to the right alignment.
  981. */
  982. len += 2047;
  983. }
  984. skb = __dev_alloc_skb(len, gfp_mask);
  985. if (!skb) {
  986. ipath_dev_err(dd, "Failed to allocate skbuff, length %u\n",
  987. len);
  988. goto bail;
  989. }
  990. skb_reserve(skb, 4);
  991. if (dd->ipath_flags & IPATH_4BYTE_TID) {
  992. u32 una = (unsigned long)skb->data & 2047;
  993. if (una)
  994. skb_reserve(skb, 2048 - una);
  995. }
  996. bail:
  997. return skb;
  998. }
  999. static void ipath_rcv_hdrerr(struct ipath_devdata *dd,
  1000. u32 eflags,
  1001. u32 l,
  1002. u32 etail,
  1003. __le32 *rhf_addr,
  1004. struct ipath_message_header *hdr)
  1005. {
  1006. char emsg[128];
  1007. get_rhf_errstring(eflags, emsg, sizeof emsg);
  1008. ipath_cdbg(PKT, "RHFerrs %x hdrqtail=%x typ=%u "
  1009. "tlen=%x opcode=%x egridx=%x: %s\n",
  1010. eflags, l,
  1011. ipath_hdrget_rcv_type(rhf_addr),
  1012. ipath_hdrget_length_in_bytes(rhf_addr),
  1013. be32_to_cpu(hdr->bth[0]) >> 24,
  1014. etail, emsg);
  1015. /* Count local link integrity errors. */
  1016. if (eflags & (INFINIPATH_RHF_H_ICRCERR | INFINIPATH_RHF_H_VCRCERR)) {
  1017. u8 n = (dd->ipath_ibcctrl >>
  1018. INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
  1019. INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
  1020. if (++dd->ipath_lli_counter > n) {
  1021. dd->ipath_lli_counter = 0;
  1022. dd->ipath_lli_errors++;
  1023. }
  1024. }
  1025. }
  1026. /*
  1027. * ipath_kreceive - receive a packet
  1028. * @pd: the infinipath port
  1029. *
  1030. * called from interrupt handler for errors or receive interrupt
  1031. */
  1032. void ipath_kreceive(struct ipath_portdata *pd)
  1033. {
  1034. struct ipath_devdata *dd = pd->port_dd;
  1035. __le32 *rhf_addr;
  1036. void *ebuf;
  1037. const u32 rsize = dd->ipath_rcvhdrentsize; /* words */
  1038. const u32 maxcnt = dd->ipath_rcvhdrcnt * rsize; /* words */
  1039. u32 etail = -1, l, hdrqtail;
  1040. struct ipath_message_header *hdr;
  1041. u32 eflags, i, etype, tlen, pkttot = 0, updegr = 0, reloop = 0;
  1042. static u64 totcalls; /* stats, may eventually remove */
  1043. int last;
  1044. l = pd->port_head;
  1045. rhf_addr = (__le32 *) pd->port_rcvhdrq + l + dd->ipath_rhf_offset;
  1046. if (dd->ipath_flags & IPATH_NODMA_RTAIL) {
  1047. u32 seq = ipath_hdrget_seq(rhf_addr);
  1048. if (seq != pd->port_seq_cnt)
  1049. goto bail;
  1050. hdrqtail = 0;
  1051. } else {
  1052. hdrqtail = ipath_get_rcvhdrtail(pd);
  1053. if (l == hdrqtail)
  1054. goto bail;
  1055. smp_rmb();
  1056. }
  1057. reloop:
  1058. for (last = 0, i = 1; !last; i++) {
  1059. hdr = dd->ipath_f_get_msgheader(dd, rhf_addr);
  1060. eflags = ipath_hdrget_err_flags(rhf_addr);
  1061. etype = ipath_hdrget_rcv_type(rhf_addr);
  1062. /* total length */
  1063. tlen = ipath_hdrget_length_in_bytes(rhf_addr);
  1064. ebuf = NULL;
  1065. if ((dd->ipath_flags & IPATH_NODMA_RTAIL) ?
  1066. ipath_hdrget_use_egr_buf(rhf_addr) :
  1067. (etype != RCVHQ_RCV_TYPE_EXPECTED)) {
  1068. /*
  1069. * It turns out that the chip uses an eager buffer
  1070. * for all non-expected packets, whether it "needs"
  1071. * one or not. So always get the index, but don't
  1072. * set ebuf (so we try to copy data) unless the
  1073. * length requires it.
  1074. */
  1075. etail = ipath_hdrget_index(rhf_addr);
  1076. updegr = 1;
  1077. if (tlen > sizeof(*hdr) ||
  1078. etype == RCVHQ_RCV_TYPE_NON_KD)
  1079. ebuf = ipath_get_egrbuf(dd, etail);
  1080. }
  1081. /*
  1082. * both tiderr and ipathhdrerr are set for all plain IB
  1083. * packets; only ipathhdrerr should be set.
  1084. */
  1085. if (etype != RCVHQ_RCV_TYPE_NON_KD &&
  1086. etype != RCVHQ_RCV_TYPE_ERROR &&
  1087. ipath_hdrget_ipath_ver(hdr->iph.ver_port_tid_offset) !=
  1088. IPS_PROTO_VERSION)
  1089. ipath_cdbg(PKT, "Bad InfiniPath protocol version "
  1090. "%x\n", etype);
  1091. if (unlikely(eflags))
  1092. ipath_rcv_hdrerr(dd, eflags, l, etail, rhf_addr, hdr);
  1093. else if (etype == RCVHQ_RCV_TYPE_NON_KD) {
  1094. ipath_ib_rcv(dd->verbs_dev, (u32 *)hdr, ebuf, tlen);
  1095. if (dd->ipath_lli_counter)
  1096. dd->ipath_lli_counter--;
  1097. } else if (etype == RCVHQ_RCV_TYPE_EAGER) {
  1098. u8 opcode = be32_to_cpu(hdr->bth[0]) >> 24;
  1099. u32 qp = be32_to_cpu(hdr->bth[1]) & 0xffffff;
  1100. ipath_cdbg(PKT, "typ %x, opcode %x (eager, "
  1101. "qp=%x), len %x; ignored\n",
  1102. etype, opcode, qp, tlen);
  1103. }
  1104. else if (etype == RCVHQ_RCV_TYPE_EXPECTED)
  1105. ipath_dbg("Bug: Expected TID, opcode %x; ignored\n",
  1106. be32_to_cpu(hdr->bth[0]) >> 24);
  1107. else {
  1108. /*
  1109. * error packet, type of error unknown.
  1110. * Probably type 3, but we don't know, so don't
  1111. * even try to print the opcode, etc.
  1112. * Usually caused by a "bad packet", that has no
  1113. * BTH, when the LRH says it should.
  1114. */
  1115. ipath_cdbg(ERRPKT, "Error Pkt, but no eflags! egrbuf"
  1116. " %x, len %x hdrq+%x rhf: %Lx\n",
  1117. etail, tlen, l,
  1118. le64_to_cpu(*(__le64 *) rhf_addr));
  1119. if (ipath_debug & __IPATH_ERRPKTDBG) {
  1120. u32 j, *d, dw = rsize-2;
  1121. if (rsize > (tlen>>2))
  1122. dw = tlen>>2;
  1123. d = (u32 *)hdr;
  1124. printk(KERN_DEBUG "EPkt rcvhdr(%x dw):\n",
  1125. dw);
  1126. for (j = 0; j < dw; j++)
  1127. printk(KERN_DEBUG "%8x%s", d[j],
  1128. (j%8) == 7 ? "\n" : " ");
  1129. printk(KERN_DEBUG ".\n");
  1130. }
  1131. }
  1132. l += rsize;
  1133. if (l >= maxcnt)
  1134. l = 0;
  1135. rhf_addr = (__le32 *) pd->port_rcvhdrq +
  1136. l + dd->ipath_rhf_offset;
  1137. if (dd->ipath_flags & IPATH_NODMA_RTAIL) {
  1138. u32 seq = ipath_hdrget_seq(rhf_addr);
  1139. if (++pd->port_seq_cnt > 13)
  1140. pd->port_seq_cnt = 1;
  1141. if (seq != pd->port_seq_cnt)
  1142. last = 1;
  1143. } else if (l == hdrqtail)
  1144. last = 1;
  1145. /*
  1146. * update head regs on last packet, and every 16 packets.
  1147. * Reduce bus traffic, while still trying to prevent
  1148. * rcvhdrq overflows, for when the queue is nearly full
  1149. */
  1150. if (last || !(i & 0xf)) {
  1151. u64 lval = l;
  1152. /* request IBA6120 and 7220 interrupt only on last */
  1153. if (last)
  1154. lval |= dd->ipath_rhdrhead_intr_off;
  1155. ipath_write_ureg(dd, ur_rcvhdrhead, lval,
  1156. pd->port_port);
  1157. if (updegr) {
  1158. ipath_write_ureg(dd, ur_rcvegrindexhead,
  1159. etail, pd->port_port);
  1160. updegr = 0;
  1161. }
  1162. }
  1163. }
  1164. if (!dd->ipath_rhdrhead_intr_off && !reloop &&
  1165. !(dd->ipath_flags & IPATH_NODMA_RTAIL)) {
  1166. /* IBA6110 workaround; we can have a race clearing chip
  1167. * interrupt with another interrupt about to be delivered,
  1168. * and can clear it before it is delivered on the GPIO
  1169. * workaround. By doing the extra check here for the
  1170. * in-memory tail register updating while we were doing
  1171. * earlier packets, we "almost" guarantee we have covered
  1172. * that case.
  1173. */
  1174. u32 hqtail = ipath_get_rcvhdrtail(pd);
  1175. if (hqtail != hdrqtail) {
  1176. hdrqtail = hqtail;
  1177. reloop = 1; /* loop 1 extra time at most */
  1178. goto reloop;
  1179. }
  1180. }
  1181. pkttot += i;
  1182. pd->port_head = l;
  1183. if (pkttot > ipath_stats.sps_maxpkts_call)
  1184. ipath_stats.sps_maxpkts_call = pkttot;
  1185. ipath_stats.sps_port0pkts += pkttot;
  1186. ipath_stats.sps_avgpkts_call =
  1187. ipath_stats.sps_port0pkts / ++totcalls;
  1188. bail:;
  1189. }
  1190. /**
  1191. * ipath_update_pio_bufs - update shadow copy of the PIO availability map
  1192. * @dd: the infinipath device
  1193. *
  1194. * called whenever our local copy indicates we have run out of send buffers
  1195. * NOTE: This can be called from interrupt context by some code
  1196. * and from non-interrupt context by ipath_getpiobuf().
  1197. */
  1198. static void ipath_update_pio_bufs(struct ipath_devdata *dd)
  1199. {
  1200. unsigned long flags;
  1201. int i;
  1202. const unsigned piobregs = (unsigned)dd->ipath_pioavregs;
  1203. /* If the generation (check) bits have changed, then we update the
  1204. * busy bit for the corresponding PIO buffer. This algorithm will
  1205. * modify positions to the value they already have in some cases
  1206. * (i.e., no change), but it's faster than changing only the bits
  1207. * that have changed.
  1208. *
  1209. * We would like to do this atomicly, to avoid spinlocks in the
  1210. * critical send path, but that's not really possible, given the
  1211. * type of changes, and that this routine could be called on
  1212. * multiple cpu's simultaneously, so we lock in this routine only,
  1213. * to avoid conflicting updates; all we change is the shadow, and
  1214. * it's a single 64 bit memory location, so by definition the update
  1215. * is atomic in terms of what other cpu's can see in testing the
  1216. * bits. The spin_lock overhead isn't too bad, since it only
  1217. * happens when all buffers are in use, so only cpu overhead, not
  1218. * latency or bandwidth is affected.
  1219. */
  1220. if (!dd->ipath_pioavailregs_dma) {
  1221. ipath_dbg("Update shadow pioavail, but regs_dma NULL!\n");
  1222. return;
  1223. }
  1224. if (ipath_debug & __IPATH_VERBDBG) {
  1225. /* only if packet debug and verbose */
  1226. volatile __le64 *dma = dd->ipath_pioavailregs_dma;
  1227. unsigned long *shadow = dd->ipath_pioavailshadow;
  1228. ipath_cdbg(PKT, "Refill avail, dma0=%llx shad0=%lx, "
  1229. "d1=%llx s1=%lx, d2=%llx s2=%lx, d3=%llx "
  1230. "s3=%lx\n",
  1231. (unsigned long long) le64_to_cpu(dma[0]),
  1232. shadow[0],
  1233. (unsigned long long) le64_to_cpu(dma[1]),
  1234. shadow[1],
  1235. (unsigned long long) le64_to_cpu(dma[2]),
  1236. shadow[2],
  1237. (unsigned long long) le64_to_cpu(dma[3]),
  1238. shadow[3]);
  1239. if (piobregs > 4)
  1240. ipath_cdbg(
  1241. PKT, "2nd group, dma4=%llx shad4=%lx, "
  1242. "d5=%llx s5=%lx, d6=%llx s6=%lx, "
  1243. "d7=%llx s7=%lx\n",
  1244. (unsigned long long) le64_to_cpu(dma[4]),
  1245. shadow[4],
  1246. (unsigned long long) le64_to_cpu(dma[5]),
  1247. shadow[5],
  1248. (unsigned long long) le64_to_cpu(dma[6]),
  1249. shadow[6],
  1250. (unsigned long long) le64_to_cpu(dma[7]),
  1251. shadow[7]);
  1252. }
  1253. spin_lock_irqsave(&ipath_pioavail_lock, flags);
  1254. for (i = 0; i < piobregs; i++) {
  1255. u64 pchbusy, pchg, piov, pnew;
  1256. /*
  1257. * Chip Errata: bug 6641; even and odd qwords>3 are swapped
  1258. */
  1259. if (i > 3 && (dd->ipath_flags & IPATH_SWAP_PIOBUFS))
  1260. piov = le64_to_cpu(dd->ipath_pioavailregs_dma[i ^ 1]);
  1261. else
  1262. piov = le64_to_cpu(dd->ipath_pioavailregs_dma[i]);
  1263. pchg = dd->ipath_pioavailkernel[i] &
  1264. ~(dd->ipath_pioavailshadow[i] ^ piov);
  1265. pchbusy = pchg << INFINIPATH_SENDPIOAVAIL_BUSY_SHIFT;
  1266. if (pchg && (pchbusy & dd->ipath_pioavailshadow[i])) {
  1267. pnew = dd->ipath_pioavailshadow[i] & ~pchbusy;
  1268. pnew |= piov & pchbusy;
  1269. dd->ipath_pioavailshadow[i] = pnew;
  1270. }
  1271. }
  1272. spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
  1273. }
  1274. /**
  1275. * ipath_setrcvhdrsize - set the receive header size
  1276. * @dd: the infinipath device
  1277. * @rhdrsize: the receive header size
  1278. *
  1279. * called from user init code, and also layered driver init
  1280. */
  1281. int ipath_setrcvhdrsize(struct ipath_devdata *dd, unsigned rhdrsize)
  1282. {
  1283. int ret = 0;
  1284. if (dd->ipath_flags & IPATH_RCVHDRSZ_SET) {
  1285. if (dd->ipath_rcvhdrsize != rhdrsize) {
  1286. dev_info(&dd->pcidev->dev,
  1287. "Error: can't set protocol header "
  1288. "size %u, already %u\n",
  1289. rhdrsize, dd->ipath_rcvhdrsize);
  1290. ret = -EAGAIN;
  1291. } else
  1292. ipath_cdbg(VERBOSE, "Reuse same protocol header "
  1293. "size %u\n", dd->ipath_rcvhdrsize);
  1294. } else if (rhdrsize > (dd->ipath_rcvhdrentsize -
  1295. (sizeof(u64) / sizeof(u32)))) {
  1296. ipath_dbg("Error: can't set protocol header size %u "
  1297. "(> max %u)\n", rhdrsize,
  1298. dd->ipath_rcvhdrentsize -
  1299. (u32) (sizeof(u64) / sizeof(u32)));
  1300. ret = -EOVERFLOW;
  1301. } else {
  1302. dd->ipath_flags |= IPATH_RCVHDRSZ_SET;
  1303. dd->ipath_rcvhdrsize = rhdrsize;
  1304. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrsize,
  1305. dd->ipath_rcvhdrsize);
  1306. ipath_cdbg(VERBOSE, "Set protocol header size to %u\n",
  1307. dd->ipath_rcvhdrsize);
  1308. }
  1309. return ret;
  1310. }
  1311. /*
  1312. * debugging code and stats updates if no pio buffers available.
  1313. */
  1314. static noinline void no_pio_bufs(struct ipath_devdata *dd)
  1315. {
  1316. unsigned long *shadow = dd->ipath_pioavailshadow;
  1317. __le64 *dma = (__le64 *)dd->ipath_pioavailregs_dma;
  1318. dd->ipath_upd_pio_shadow = 1;
  1319. /*
  1320. * not atomic, but if we lose a stat count in a while, that's OK
  1321. */
  1322. ipath_stats.sps_nopiobufs++;
  1323. if (!(++dd->ipath_consec_nopiobuf % 100000)) {
  1324. ipath_dbg("%u pio sends with no bufavail; dmacopy: "
  1325. "%llx %llx %llx %llx; shadow: %lx %lx %lx %lx\n",
  1326. dd->ipath_consec_nopiobuf,
  1327. (unsigned long long) le64_to_cpu(dma[0]),
  1328. (unsigned long long) le64_to_cpu(dma[1]),
  1329. (unsigned long long) le64_to_cpu(dma[2]),
  1330. (unsigned long long) le64_to_cpu(dma[3]),
  1331. shadow[0], shadow[1], shadow[2], shadow[3]);
  1332. /*
  1333. * 4 buffers per byte, 4 registers above, cover rest
  1334. * below
  1335. */
  1336. if ((dd->ipath_piobcnt2k + dd->ipath_piobcnt4k) >
  1337. (sizeof(shadow[0]) * 4 * 4))
  1338. ipath_dbg("2nd group: dmacopy: %llx %llx "
  1339. "%llx %llx; shadow: %lx %lx %lx %lx\n",
  1340. (unsigned long long)le64_to_cpu(dma[4]),
  1341. (unsigned long long)le64_to_cpu(dma[5]),
  1342. (unsigned long long)le64_to_cpu(dma[6]),
  1343. (unsigned long long)le64_to_cpu(dma[7]),
  1344. shadow[4], shadow[5], shadow[6],
  1345. shadow[7]);
  1346. }
  1347. }
  1348. /*
  1349. * common code for normal driver pio buffer allocation, and reserved
  1350. * allocation.
  1351. *
  1352. * do appropriate marking as busy, etc.
  1353. * returns buffer number if one found (>=0), negative number is error.
  1354. */
  1355. static u32 __iomem *ipath_getpiobuf_range(struct ipath_devdata *dd,
  1356. u32 *pbufnum, u32 first, u32 last, u32 firsti)
  1357. {
  1358. int i, j, updated = 0;
  1359. unsigned piobcnt;
  1360. unsigned long flags;
  1361. unsigned long *shadow = dd->ipath_pioavailshadow;
  1362. u32 __iomem *buf;
  1363. piobcnt = last - first;
  1364. if (dd->ipath_upd_pio_shadow) {
  1365. /*
  1366. * Minor optimization. If we had no buffers on last call,
  1367. * start out by doing the update; continue and do scan even
  1368. * if no buffers were updated, to be paranoid
  1369. */
  1370. ipath_update_pio_bufs(dd);
  1371. updated++;
  1372. i = first;
  1373. } else
  1374. i = firsti;
  1375. rescan:
  1376. /*
  1377. * while test_and_set_bit() is atomic, we do that and then the
  1378. * change_bit(), and the pair is not. See if this is the cause
  1379. * of the remaining armlaunch errors.
  1380. */
  1381. spin_lock_irqsave(&ipath_pioavail_lock, flags);
  1382. for (j = 0; j < piobcnt; j++, i++) {
  1383. if (i >= last)
  1384. i = first;
  1385. if (__test_and_set_bit((2 * i) + 1, shadow))
  1386. continue;
  1387. /* flip generation bit */
  1388. __change_bit(2 * i, shadow);
  1389. break;
  1390. }
  1391. spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
  1392. if (j == piobcnt) {
  1393. if (!updated) {
  1394. /*
  1395. * first time through; shadow exhausted, but may be
  1396. * buffers available, try an update and then rescan.
  1397. */
  1398. ipath_update_pio_bufs(dd);
  1399. updated++;
  1400. i = first;
  1401. goto rescan;
  1402. } else if (updated == 1 && piobcnt <=
  1403. ((dd->ipath_sendctrl
  1404. >> INFINIPATH_S_UPDTHRESH_SHIFT) &
  1405. INFINIPATH_S_UPDTHRESH_MASK)) {
  1406. /*
  1407. * for chips supporting and using the update
  1408. * threshold we need to force an update of the
  1409. * in-memory copy if the count is less than the
  1410. * thershold, then check one more time.
  1411. */
  1412. ipath_force_pio_avail_update(dd);
  1413. ipath_update_pio_bufs(dd);
  1414. updated++;
  1415. i = first;
  1416. goto rescan;
  1417. }
  1418. no_pio_bufs(dd);
  1419. buf = NULL;
  1420. } else {
  1421. if (i < dd->ipath_piobcnt2k)
  1422. buf = (u32 __iomem *) (dd->ipath_pio2kbase +
  1423. i * dd->ipath_palign);
  1424. else
  1425. buf = (u32 __iomem *)
  1426. (dd->ipath_pio4kbase +
  1427. (i - dd->ipath_piobcnt2k) * dd->ipath_4kalign);
  1428. if (pbufnum)
  1429. *pbufnum = i;
  1430. }
  1431. return buf;
  1432. }
  1433. /**
  1434. * ipath_getpiobuf - find an available pio buffer
  1435. * @dd: the infinipath device
  1436. * @plen: the size of the PIO buffer needed in 32-bit words
  1437. * @pbufnum: the buffer number is placed here
  1438. */
  1439. u32 __iomem *ipath_getpiobuf(struct ipath_devdata *dd, u32 plen, u32 *pbufnum)
  1440. {
  1441. u32 __iomem *buf;
  1442. u32 pnum, nbufs;
  1443. u32 first, lasti;
  1444. if (plen + 1 >= IPATH_SMALLBUF_DWORDS) {
  1445. first = dd->ipath_piobcnt2k;
  1446. lasti = dd->ipath_lastpioindexl;
  1447. } else {
  1448. first = 0;
  1449. lasti = dd->ipath_lastpioindex;
  1450. }
  1451. nbufs = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
  1452. buf = ipath_getpiobuf_range(dd, &pnum, first, nbufs, lasti);
  1453. if (buf) {
  1454. /*
  1455. * Set next starting place. It's just an optimization,
  1456. * it doesn't matter who wins on this, so no locking
  1457. */
  1458. if (plen + 1 >= IPATH_SMALLBUF_DWORDS)
  1459. dd->ipath_lastpioindexl = pnum + 1;
  1460. else
  1461. dd->ipath_lastpioindex = pnum + 1;
  1462. if (dd->ipath_upd_pio_shadow)
  1463. dd->ipath_upd_pio_shadow = 0;
  1464. if (dd->ipath_consec_nopiobuf)
  1465. dd->ipath_consec_nopiobuf = 0;
  1466. ipath_cdbg(VERBOSE, "Return piobuf%u %uk @ %p\n",
  1467. pnum, (pnum < dd->ipath_piobcnt2k) ? 2 : 4, buf);
  1468. if (pbufnum)
  1469. *pbufnum = pnum;
  1470. }
  1471. return buf;
  1472. }
  1473. /**
  1474. * ipath_chg_pioavailkernel - change which send buffers are available for kernel
  1475. * @dd: the infinipath device
  1476. * @start: the starting send buffer number
  1477. * @len: the number of send buffers
  1478. * @avail: true if the buffers are available for kernel use, false otherwise
  1479. */
  1480. void ipath_chg_pioavailkernel(struct ipath_devdata *dd, unsigned start,
  1481. unsigned len, int avail)
  1482. {
  1483. unsigned long flags;
  1484. unsigned end;
  1485. /* There are two bits per send buffer (busy and generation) */
  1486. start *= 2;
  1487. len *= 2;
  1488. end = start + len;
  1489. /* Set or clear the generation bits. */
  1490. spin_lock_irqsave(&ipath_pioavail_lock, flags);
  1491. while (start < end) {
  1492. if (avail) {
  1493. __clear_bit(start + INFINIPATH_SENDPIOAVAIL_BUSY_SHIFT,
  1494. dd->ipath_pioavailshadow);
  1495. __set_bit(start, dd->ipath_pioavailkernel);
  1496. } else {
  1497. __set_bit(start + INFINIPATH_SENDPIOAVAIL_BUSY_SHIFT,
  1498. dd->ipath_pioavailshadow);
  1499. __clear_bit(start, dd->ipath_pioavailkernel);
  1500. }
  1501. start += 2;
  1502. }
  1503. spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
  1504. }
  1505. /**
  1506. * ipath_create_rcvhdrq - create a receive header queue
  1507. * @dd: the infinipath device
  1508. * @pd: the port data
  1509. *
  1510. * this must be contiguous memory (from an i/o perspective), and must be
  1511. * DMA'able (which means for some systems, it will go through an IOMMU,
  1512. * or be forced into a low address range).
  1513. */
  1514. int ipath_create_rcvhdrq(struct ipath_devdata *dd,
  1515. struct ipath_portdata *pd)
  1516. {
  1517. int ret = 0;
  1518. if (!pd->port_rcvhdrq) {
  1519. dma_addr_t phys_hdrqtail;
  1520. gfp_t gfp_flags = GFP_USER | __GFP_COMP;
  1521. int amt = ALIGN(dd->ipath_rcvhdrcnt * dd->ipath_rcvhdrentsize *
  1522. sizeof(u32), PAGE_SIZE);
  1523. pd->port_rcvhdrq = dma_alloc_coherent(
  1524. &dd->pcidev->dev, amt, &pd->port_rcvhdrq_phys,
  1525. gfp_flags);
  1526. if (!pd->port_rcvhdrq) {
  1527. ipath_dev_err(dd, "attempt to allocate %d bytes "
  1528. "for port %u rcvhdrq failed\n",
  1529. amt, pd->port_port);
  1530. ret = -ENOMEM;
  1531. goto bail;
  1532. }
  1533. if (!(dd->ipath_flags & IPATH_NODMA_RTAIL)) {
  1534. pd->port_rcvhdrtail_kvaddr = dma_alloc_coherent(
  1535. &dd->pcidev->dev, PAGE_SIZE, &phys_hdrqtail,
  1536. GFP_KERNEL);
  1537. if (!pd->port_rcvhdrtail_kvaddr) {
  1538. ipath_dev_err(dd, "attempt to allocate 1 page "
  1539. "for port %u rcvhdrqtailaddr "
  1540. "failed\n", pd->port_port);
  1541. ret = -ENOMEM;
  1542. dma_free_coherent(&dd->pcidev->dev, amt,
  1543. pd->port_rcvhdrq,
  1544. pd->port_rcvhdrq_phys);
  1545. pd->port_rcvhdrq = NULL;
  1546. goto bail;
  1547. }
  1548. pd->port_rcvhdrqtailaddr_phys = phys_hdrqtail;
  1549. ipath_cdbg(VERBOSE, "port %d hdrtailaddr, %llx "
  1550. "physical\n", pd->port_port,
  1551. (unsigned long long) phys_hdrqtail);
  1552. }
  1553. pd->port_rcvhdrq_size = amt;
  1554. ipath_cdbg(VERBOSE, "%d pages at %p (phys %lx) size=%lu "
  1555. "for port %u rcvhdr Q\n",
  1556. amt >> PAGE_SHIFT, pd->port_rcvhdrq,
  1557. (unsigned long) pd->port_rcvhdrq_phys,
  1558. (unsigned long) pd->port_rcvhdrq_size,
  1559. pd->port_port);
  1560. }
  1561. else
  1562. ipath_cdbg(VERBOSE, "reuse port %d rcvhdrq @%p %llx phys; "
  1563. "hdrtailaddr@%p %llx physical\n",
  1564. pd->port_port, pd->port_rcvhdrq,
  1565. (unsigned long long) pd->port_rcvhdrq_phys,
  1566. pd->port_rcvhdrtail_kvaddr, (unsigned long long)
  1567. pd->port_rcvhdrqtailaddr_phys);
  1568. /* clear for security and sanity on each use */
  1569. memset(pd->port_rcvhdrq, 0, pd->port_rcvhdrq_size);
  1570. if (pd->port_rcvhdrtail_kvaddr)
  1571. memset(pd->port_rcvhdrtail_kvaddr, 0, PAGE_SIZE);
  1572. /*
  1573. * tell chip each time we init it, even if we are re-using previous
  1574. * memory (we zero the register at process close)
  1575. */
  1576. ipath_write_kreg_port(dd, dd->ipath_kregs->kr_rcvhdrtailaddr,
  1577. pd->port_port, pd->port_rcvhdrqtailaddr_phys);
  1578. ipath_write_kreg_port(dd, dd->ipath_kregs->kr_rcvhdraddr,
  1579. pd->port_port, pd->port_rcvhdrq_phys);
  1580. bail:
  1581. return ret;
  1582. }
  1583. /*
  1584. * Flush all sends that might be in the ready to send state, as well as any
  1585. * that are in the process of being sent. Used whenever we need to be
  1586. * sure the send side is idle. Cleans up all buffer state by canceling
  1587. * all pio buffers, and issuing an abort, which cleans up anything in the
  1588. * launch fifo. The cancel is superfluous on some chip versions, but
  1589. * it's safer to always do it.
  1590. * PIOAvail bits are updated by the chip as if normal send had happened.
  1591. */
  1592. void ipath_cancel_sends(struct ipath_devdata *dd, int restore_sendctrl)
  1593. {
  1594. unsigned long flags;
  1595. if (dd->ipath_flags & IPATH_IB_AUTONEG_INPROG) {
  1596. ipath_cdbg(VERBOSE, "Ignore while in autonegotiation\n");
  1597. goto bail;
  1598. }
  1599. /*
  1600. * If we have SDMA, and it's not disabled, we have to kick off the
  1601. * abort state machine, provided we aren't already aborting.
  1602. * If we are in the process of aborting SDMA (!DISABLED, but ABORTING),
  1603. * we skip the rest of this routine. It is already "in progress"
  1604. */
  1605. if (dd->ipath_flags & IPATH_HAS_SEND_DMA) {
  1606. int skip_cancel;
  1607. u64 *statp = &dd->ipath_sdma_status;
  1608. spin_lock_irqsave(&dd->ipath_sdma_lock, flags);
  1609. skip_cancel =
  1610. !test_bit(IPATH_SDMA_DISABLED, statp) &&
  1611. test_and_set_bit(IPATH_SDMA_ABORTING, statp);
  1612. spin_unlock_irqrestore(&dd->ipath_sdma_lock, flags);
  1613. if (skip_cancel)
  1614. goto bail;
  1615. }
  1616. ipath_dbg("Cancelling all in-progress send buffers\n");
  1617. /* skip armlaunch errs for a while */
  1618. dd->ipath_lastcancel = jiffies + HZ / 2;
  1619. /*
  1620. * The abort bit is auto-clearing. We also don't want pioavail
  1621. * update happening during this, and we don't want any other
  1622. * sends going out, so turn those off for the duration. We read
  1623. * the scratch register to be sure that cancels and the abort
  1624. * have taken effect in the chip. Otherwise two parts are same
  1625. * as ipath_force_pio_avail_update()
  1626. */
  1627. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  1628. dd->ipath_sendctrl &= ~(INFINIPATH_S_PIOBUFAVAILUPD
  1629. | INFINIPATH_S_PIOENABLE);
  1630. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  1631. dd->ipath_sendctrl | INFINIPATH_S_ABORT);
  1632. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  1633. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  1634. /* disarm all send buffers */
  1635. ipath_disarm_piobufs(dd, 0,
  1636. dd->ipath_piobcnt2k + dd->ipath_piobcnt4k);
  1637. if (restore_sendctrl) {
  1638. /* else done by caller later if needed */
  1639. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  1640. dd->ipath_sendctrl |= INFINIPATH_S_PIOBUFAVAILUPD |
  1641. INFINIPATH_S_PIOENABLE;
  1642. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  1643. dd->ipath_sendctrl);
  1644. /* and again, be sure all have hit the chip */
  1645. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  1646. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  1647. }
  1648. if ((dd->ipath_flags & IPATH_HAS_SEND_DMA) &&
  1649. !test_bit(IPATH_SDMA_DISABLED, &dd->ipath_sdma_status) &&
  1650. test_bit(IPATH_SDMA_RUNNING, &dd->ipath_sdma_status)) {
  1651. spin_lock_irqsave(&dd->ipath_sdma_lock, flags);
  1652. /* only wait so long for intr */
  1653. dd->ipath_sdma_abort_intr_timeout = jiffies + HZ;
  1654. dd->ipath_sdma_reset_wait = 200;
  1655. __set_bit(IPATH_SDMA_DISARMED, &dd->ipath_sdma_status);
  1656. if (!test_bit(IPATH_SDMA_SHUTDOWN, &dd->ipath_sdma_status))
  1657. tasklet_hi_schedule(&dd->ipath_sdma_abort_task);
  1658. spin_unlock_irqrestore(&dd->ipath_sdma_lock, flags);
  1659. }
  1660. bail:;
  1661. }
  1662. /*
  1663. * Force an update of in-memory copy of the pioavail registers, when
  1664. * needed for any of a variety of reasons. We read the scratch register
  1665. * to make it highly likely that the update will have happened by the
  1666. * time we return. If already off (as in cancel_sends above), this
  1667. * routine is a nop, on the assumption that the caller will "do the
  1668. * right thing".
  1669. */
  1670. void ipath_force_pio_avail_update(struct ipath_devdata *dd)
  1671. {
  1672. unsigned long flags;
  1673. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  1674. if (dd->ipath_sendctrl & INFINIPATH_S_PIOBUFAVAILUPD) {
  1675. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  1676. dd->ipath_sendctrl & ~INFINIPATH_S_PIOBUFAVAILUPD);
  1677. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  1678. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
  1679. dd->ipath_sendctrl);
  1680. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  1681. }
  1682. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  1683. }
  1684. static void ipath_set_ib_lstate(struct ipath_devdata *dd, int linkcmd,
  1685. int linitcmd)
  1686. {
  1687. u64 mod_wd;
  1688. static const char *what[4] = {
  1689. [0] = "NOP",
  1690. [INFINIPATH_IBCC_LINKCMD_DOWN] = "DOWN",
  1691. [INFINIPATH_IBCC_LINKCMD_ARMED] = "ARMED",
  1692. [INFINIPATH_IBCC_LINKCMD_ACTIVE] = "ACTIVE"
  1693. };
  1694. if (linitcmd == INFINIPATH_IBCC_LINKINITCMD_DISABLE) {
  1695. /*
  1696. * If we are told to disable, note that so link-recovery
  1697. * code does not attempt to bring us back up.
  1698. */
  1699. preempt_disable();
  1700. dd->ipath_flags |= IPATH_IB_LINK_DISABLED;
  1701. preempt_enable();
  1702. } else if (linitcmd) {
  1703. /*
  1704. * Any other linkinitcmd will lead to LINKDOWN and then
  1705. * to INIT (if all is well), so clear flag to let
  1706. * link-recovery code attempt to bring us back up.
  1707. */
  1708. preempt_disable();
  1709. dd->ipath_flags &= ~IPATH_IB_LINK_DISABLED;
  1710. preempt_enable();
  1711. }
  1712. mod_wd = (linkcmd << dd->ibcc_lc_shift) |
  1713. (linitcmd << INFINIPATH_IBCC_LINKINITCMD_SHIFT);
  1714. ipath_cdbg(VERBOSE,
  1715. "Moving unit %u to %s (initcmd=0x%x), current ltstate is %s\n",
  1716. dd->ipath_unit, what[linkcmd], linitcmd,
  1717. ipath_ibcstatus_str[ipath_ib_linktrstate(dd,
  1718. ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus))]);
  1719. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
  1720. dd->ipath_ibcctrl | mod_wd);
  1721. /* read from chip so write is flushed */
  1722. (void) ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
  1723. }
  1724. int ipath_set_linkstate(struct ipath_devdata *dd, u8 newstate)
  1725. {
  1726. u32 lstate;
  1727. int ret;
  1728. switch (newstate) {
  1729. case IPATH_IB_LINKDOWN_ONLY:
  1730. ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_DOWN, 0);
  1731. /* don't wait */
  1732. ret = 0;
  1733. goto bail;
  1734. case IPATH_IB_LINKDOWN:
  1735. ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_DOWN,
  1736. INFINIPATH_IBCC_LINKINITCMD_POLL);
  1737. /* don't wait */
  1738. ret = 0;
  1739. goto bail;
  1740. case IPATH_IB_LINKDOWN_SLEEP:
  1741. ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_DOWN,
  1742. INFINIPATH_IBCC_LINKINITCMD_SLEEP);
  1743. /* don't wait */
  1744. ret = 0;
  1745. goto bail;
  1746. case IPATH_IB_LINKDOWN_DISABLE:
  1747. ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_DOWN,
  1748. INFINIPATH_IBCC_LINKINITCMD_DISABLE);
  1749. /* don't wait */
  1750. ret = 0;
  1751. goto bail;
  1752. case IPATH_IB_LINKARM:
  1753. if (dd->ipath_flags & IPATH_LINKARMED) {
  1754. ret = 0;
  1755. goto bail;
  1756. }
  1757. if (!(dd->ipath_flags &
  1758. (IPATH_LINKINIT | IPATH_LINKACTIVE))) {
  1759. ret = -EINVAL;
  1760. goto bail;
  1761. }
  1762. ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_ARMED, 0);
  1763. /*
  1764. * Since the port can transition to ACTIVE by receiving
  1765. * a non VL 15 packet, wait for either state.
  1766. */
  1767. lstate = IPATH_LINKARMED | IPATH_LINKACTIVE;
  1768. break;
  1769. case IPATH_IB_LINKACTIVE:
  1770. if (dd->ipath_flags & IPATH_LINKACTIVE) {
  1771. ret = 0;
  1772. goto bail;
  1773. }
  1774. if (!(dd->ipath_flags & IPATH_LINKARMED)) {
  1775. ret = -EINVAL;
  1776. goto bail;
  1777. }
  1778. ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_ACTIVE, 0);
  1779. lstate = IPATH_LINKACTIVE;
  1780. break;
  1781. case IPATH_IB_LINK_LOOPBACK:
  1782. dev_info(&dd->pcidev->dev, "Enabling IB local loopback\n");
  1783. dd->ipath_ibcctrl |= INFINIPATH_IBCC_LOOPBACK;
  1784. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
  1785. dd->ipath_ibcctrl);
  1786. /* turn heartbeat off, as it causes loopback to fail */
  1787. dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT,
  1788. IPATH_IB_HRTBT_OFF);
  1789. /* don't wait */
  1790. ret = 0;
  1791. goto bail;
  1792. case IPATH_IB_LINK_EXTERNAL:
  1793. dev_info(&dd->pcidev->dev,
  1794. "Disabling IB local loopback (normal)\n");
  1795. dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT,
  1796. IPATH_IB_HRTBT_ON);
  1797. dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LOOPBACK;
  1798. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
  1799. dd->ipath_ibcctrl);
  1800. /* don't wait */
  1801. ret = 0;
  1802. goto bail;
  1803. /*
  1804. * Heartbeat can be explicitly enabled by the user via
  1805. * "hrtbt_enable" "file", and if disabled, trying to enable here
  1806. * will have no effect. Implicit changes (heartbeat off when
  1807. * loopback on, and vice versa) are included to ease testing.
  1808. */
  1809. case IPATH_IB_LINK_HRTBT:
  1810. ret = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT,
  1811. IPATH_IB_HRTBT_ON);
  1812. goto bail;
  1813. case IPATH_IB_LINK_NO_HRTBT:
  1814. ret = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT,
  1815. IPATH_IB_HRTBT_OFF);
  1816. goto bail;
  1817. default:
  1818. ipath_dbg("Invalid linkstate 0x%x requested\n", newstate);
  1819. ret = -EINVAL;
  1820. goto bail;
  1821. }
  1822. ret = ipath_wait_linkstate(dd, lstate, 2000);
  1823. bail:
  1824. return ret;
  1825. }
  1826. /**
  1827. * ipath_set_mtu - set the MTU
  1828. * @dd: the infinipath device
  1829. * @arg: the new MTU
  1830. *
  1831. * we can handle "any" incoming size, the issue here is whether we
  1832. * need to restrict our outgoing size. For now, we don't do any
  1833. * sanity checking on this, and we don't deal with what happens to
  1834. * programs that are already running when the size changes.
  1835. * NOTE: changing the MTU will usually cause the IBC to go back to
  1836. * link INIT state...
  1837. */
  1838. int ipath_set_mtu(struct ipath_devdata *dd, u16 arg)
  1839. {
  1840. u32 piosize;
  1841. int changed = 0;
  1842. int ret;
  1843. /*
  1844. * mtu is IB data payload max. It's the largest power of 2 less
  1845. * than piosize (or even larger, since it only really controls the
  1846. * largest we can receive; we can send the max of the mtu and
  1847. * piosize). We check that it's one of the valid IB sizes.
  1848. */
  1849. if (arg != 256 && arg != 512 && arg != 1024 && arg != 2048 &&
  1850. (arg != 4096 || !ipath_mtu4096)) {
  1851. ipath_dbg("Trying to set invalid mtu %u, failing\n", arg);
  1852. ret = -EINVAL;
  1853. goto bail;
  1854. }
  1855. if (dd->ipath_ibmtu == arg) {
  1856. ret = 0; /* same as current */
  1857. goto bail;
  1858. }
  1859. piosize = dd->ipath_ibmaxlen;
  1860. dd->ipath_ibmtu = arg;
  1861. if (arg >= (piosize - IPATH_PIO_MAXIBHDR)) {
  1862. /* Only if it's not the initial value (or reset to it) */
  1863. if (piosize != dd->ipath_init_ibmaxlen) {
  1864. if (arg > piosize && arg <= dd->ipath_init_ibmaxlen)
  1865. piosize = dd->ipath_init_ibmaxlen;
  1866. dd->ipath_ibmaxlen = piosize;
  1867. changed = 1;
  1868. }
  1869. } else if ((arg + IPATH_PIO_MAXIBHDR) != dd->ipath_ibmaxlen) {
  1870. piosize = arg + IPATH_PIO_MAXIBHDR;
  1871. ipath_cdbg(VERBOSE, "ibmaxlen was 0x%x, setting to 0x%x "
  1872. "(mtu 0x%x)\n", dd->ipath_ibmaxlen, piosize,
  1873. arg);
  1874. dd->ipath_ibmaxlen = piosize;
  1875. changed = 1;
  1876. }
  1877. if (changed) {
  1878. u64 ibc = dd->ipath_ibcctrl, ibdw;
  1879. /*
  1880. * update our housekeeping variables, and set IBC max
  1881. * size, same as init code; max IBC is max we allow in
  1882. * buffer, less the qword pbc, plus 1 for ICRC, in dwords
  1883. */
  1884. dd->ipath_ibmaxlen = piosize - 2 * sizeof(u32);
  1885. ibdw = (dd->ipath_ibmaxlen >> 2) + 1;
  1886. ibc &= ~(INFINIPATH_IBCC_MAXPKTLEN_MASK <<
  1887. dd->ibcc_mpl_shift);
  1888. ibc |= ibdw << dd->ibcc_mpl_shift;
  1889. dd->ipath_ibcctrl = ibc;
  1890. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
  1891. dd->ipath_ibcctrl);
  1892. dd->ipath_f_tidtemplate(dd);
  1893. }
  1894. ret = 0;
  1895. bail:
  1896. return ret;
  1897. }
  1898. int ipath_set_lid(struct ipath_devdata *dd, u32 lid, u8 lmc)
  1899. {
  1900. dd->ipath_lid = lid;
  1901. dd->ipath_lmc = lmc;
  1902. dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LIDLMC, lid |
  1903. (~((1U << lmc) - 1)) << 16);
  1904. dev_info(&dd->pcidev->dev, "We got a lid: 0x%x\n", lid);
  1905. return 0;
  1906. }
  1907. /**
  1908. * ipath_write_kreg_port - write a device's per-port 64-bit kernel register
  1909. * @dd: the infinipath device
  1910. * @regno: the register number to write
  1911. * @port: the port containing the register
  1912. * @value: the value to write
  1913. *
  1914. * Registers that vary with the chip implementation constants (port)
  1915. * use this routine.
  1916. */
  1917. void ipath_write_kreg_port(const struct ipath_devdata *dd, ipath_kreg regno,
  1918. unsigned port, u64 value)
  1919. {
  1920. u16 where;
  1921. if (port < dd->ipath_portcnt &&
  1922. (regno == dd->ipath_kregs->kr_rcvhdraddr ||
  1923. regno == dd->ipath_kregs->kr_rcvhdrtailaddr))
  1924. where = regno + port;
  1925. else
  1926. where = -1;
  1927. ipath_write_kreg(dd, where, value);
  1928. }
  1929. /*
  1930. * Following deal with the "obviously simple" task of overriding the state
  1931. * of the LEDS, which normally indicate link physical and logical status.
  1932. * The complications arise in dealing with different hardware mappings
  1933. * and the board-dependent routine being called from interrupts.
  1934. * and then there's the requirement to _flash_ them.
  1935. */
  1936. #define LED_OVER_FREQ_SHIFT 8
  1937. #define LED_OVER_FREQ_MASK (0xFF<<LED_OVER_FREQ_SHIFT)
  1938. /* Below is "non-zero" to force override, but both actual LEDs are off */
  1939. #define LED_OVER_BOTH_OFF (8)
  1940. static void ipath_run_led_override(unsigned long opaque)
  1941. {
  1942. struct ipath_devdata *dd = (struct ipath_devdata *)opaque;
  1943. int timeoff;
  1944. int pidx;
  1945. u64 lstate, ltstate, val;
  1946. if (!(dd->ipath_flags & IPATH_INITTED))
  1947. return;
  1948. pidx = dd->ipath_led_override_phase++ & 1;
  1949. dd->ipath_led_override = dd->ipath_led_override_vals[pidx];
  1950. timeoff = dd->ipath_led_override_timeoff;
  1951. /*
  1952. * below potentially restores the LED values per current status,
  1953. * should also possibly setup the traffic-blink register,
  1954. * but leave that to per-chip functions.
  1955. */
  1956. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
  1957. ltstate = ipath_ib_linktrstate(dd, val);
  1958. lstate = ipath_ib_linkstate(dd, val);
  1959. dd->ipath_f_setextled(dd, lstate, ltstate);
  1960. mod_timer(&dd->ipath_led_override_timer, jiffies + timeoff);
  1961. }
  1962. void ipath_set_led_override(struct ipath_devdata *dd, unsigned int val)
  1963. {
  1964. int timeoff, freq;
  1965. if (!(dd->ipath_flags & IPATH_INITTED))
  1966. return;
  1967. /* First check if we are blinking. If not, use 1HZ polling */
  1968. timeoff = HZ;
  1969. freq = (val & LED_OVER_FREQ_MASK) >> LED_OVER_FREQ_SHIFT;
  1970. if (freq) {
  1971. /* For blink, set each phase from one nybble of val */
  1972. dd->ipath_led_override_vals[0] = val & 0xF;
  1973. dd->ipath_led_override_vals[1] = (val >> 4) & 0xF;
  1974. timeoff = (HZ << 4)/freq;
  1975. } else {
  1976. /* Non-blink set both phases the same. */
  1977. dd->ipath_led_override_vals[0] = val & 0xF;
  1978. dd->ipath_led_override_vals[1] = val & 0xF;
  1979. }
  1980. dd->ipath_led_override_timeoff = timeoff;
  1981. /*
  1982. * If the timer has not already been started, do so. Use a "quick"
  1983. * timeout so the function will be called soon, to look at our request.
  1984. */
  1985. if (atomic_inc_return(&dd->ipath_led_override_timer_active) == 1) {
  1986. /* Need to start timer */
  1987. init_timer(&dd->ipath_led_override_timer);
  1988. dd->ipath_led_override_timer.function =
  1989. ipath_run_led_override;
  1990. dd->ipath_led_override_timer.data = (unsigned long) dd;
  1991. dd->ipath_led_override_timer.expires = jiffies + 1;
  1992. add_timer(&dd->ipath_led_override_timer);
  1993. } else
  1994. atomic_dec(&dd->ipath_led_override_timer_active);
  1995. }
  1996. /**
  1997. * ipath_shutdown_device - shut down a device
  1998. * @dd: the infinipath device
  1999. *
  2000. * This is called to make the device quiet when we are about to
  2001. * unload the driver, and also when the device is administratively
  2002. * disabled. It does not free any data structures.
  2003. * Everything it does has to be setup again by ipath_init_chip(dd,1)
  2004. */
  2005. void ipath_shutdown_device(struct ipath_devdata *dd)
  2006. {
  2007. unsigned long flags;
  2008. ipath_dbg("Shutting down the device\n");
  2009. ipath_hol_up(dd); /* make sure user processes aren't suspended */
  2010. dd->ipath_flags |= IPATH_LINKUNK;
  2011. dd->ipath_flags &= ~(IPATH_INITTED | IPATH_LINKDOWN |
  2012. IPATH_LINKINIT | IPATH_LINKARMED |
  2013. IPATH_LINKACTIVE);
  2014. *dd->ipath_statusp &= ~(IPATH_STATUS_IB_CONF |
  2015. IPATH_STATUS_IB_READY);
  2016. /* mask interrupts, but not errors */
  2017. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
  2018. dd->ipath_rcvctrl = 0;
  2019. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  2020. dd->ipath_rcvctrl);
  2021. if (dd->ipath_flags & IPATH_HAS_SEND_DMA)
  2022. teardown_sdma(dd);
  2023. /*
  2024. * gracefully stop all sends allowing any in progress to trickle out
  2025. * first.
  2026. */
  2027. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  2028. dd->ipath_sendctrl = 0;
  2029. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl, dd->ipath_sendctrl);
  2030. /* flush it */
  2031. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  2032. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  2033. /*
  2034. * enough for anything that's going to trickle out to have actually
  2035. * done so.
  2036. */
  2037. udelay(5);
  2038. dd->ipath_f_setextled(dd, 0, 0); /* make sure LEDs are off */
  2039. ipath_set_ib_lstate(dd, 0, INFINIPATH_IBCC_LINKINITCMD_DISABLE);
  2040. ipath_cancel_sends(dd, 0);
  2041. /*
  2042. * we are shutting down, so tell components that care. We don't do
  2043. * this on just a link state change, much like ethernet, a cable
  2044. * unplug, etc. doesn't change driver state
  2045. */
  2046. signal_ib_event(dd, IB_EVENT_PORT_ERR);
  2047. /* disable IBC */
  2048. dd->ipath_control &= ~INFINIPATH_C_LINKENABLE;
  2049. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  2050. dd->ipath_control | INFINIPATH_C_FREEZEMODE);
  2051. /*
  2052. * clear SerdesEnable and turn the leds off; do this here because
  2053. * we are unloading, so don't count on interrupts to move along
  2054. * Turn the LEDs off explictly for the same reason.
  2055. */
  2056. dd->ipath_f_quiet_serdes(dd);
  2057. /* stop all the timers that might still be running */
  2058. del_timer_sync(&dd->ipath_hol_timer);
  2059. if (dd->ipath_stats_timer_active) {
  2060. del_timer_sync(&dd->ipath_stats_timer);
  2061. dd->ipath_stats_timer_active = 0;
  2062. }
  2063. if (dd->ipath_intrchk_timer.data) {
  2064. del_timer_sync(&dd->ipath_intrchk_timer);
  2065. dd->ipath_intrchk_timer.data = 0;
  2066. }
  2067. if (atomic_read(&dd->ipath_led_override_timer_active)) {
  2068. del_timer_sync(&dd->ipath_led_override_timer);
  2069. atomic_set(&dd->ipath_led_override_timer_active, 0);
  2070. }
  2071. /*
  2072. * clear all interrupts and errors, so that the next time the driver
  2073. * is loaded or device is enabled, we know that whatever is set
  2074. * happened while we were unloaded
  2075. */
  2076. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  2077. ~0ULL & ~INFINIPATH_HWE_MEMBISTFAILED);
  2078. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, -1LL);
  2079. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, -1LL);
  2080. ipath_cdbg(VERBOSE, "Flush time and errors to EEPROM\n");
  2081. ipath_update_eeprom_log(dd);
  2082. }
  2083. /**
  2084. * ipath_free_pddata - free a port's allocated data
  2085. * @dd: the infinipath device
  2086. * @pd: the portdata structure
  2087. *
  2088. * free up any allocated data for a port
  2089. * This should not touch anything that would affect a simultaneous
  2090. * re-allocation of port data, because it is called after ipath_mutex
  2091. * is released (and can be called from reinit as well).
  2092. * It should never change any chip state, or global driver state.
  2093. * (The only exception to global state is freeing the port0 port0_skbs.)
  2094. */
  2095. void ipath_free_pddata(struct ipath_devdata *dd, struct ipath_portdata *pd)
  2096. {
  2097. if (!pd)
  2098. return;
  2099. if (pd->port_rcvhdrq) {
  2100. ipath_cdbg(VERBOSE, "free closed port %d rcvhdrq @ %p "
  2101. "(size=%lu)\n", pd->port_port, pd->port_rcvhdrq,
  2102. (unsigned long) pd->port_rcvhdrq_size);
  2103. dma_free_coherent(&dd->pcidev->dev, pd->port_rcvhdrq_size,
  2104. pd->port_rcvhdrq, pd->port_rcvhdrq_phys);
  2105. pd->port_rcvhdrq = NULL;
  2106. if (pd->port_rcvhdrtail_kvaddr) {
  2107. dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
  2108. pd->port_rcvhdrtail_kvaddr,
  2109. pd->port_rcvhdrqtailaddr_phys);
  2110. pd->port_rcvhdrtail_kvaddr = NULL;
  2111. }
  2112. }
  2113. if (pd->port_port && pd->port_rcvegrbuf) {
  2114. unsigned e;
  2115. for (e = 0; e < pd->port_rcvegrbuf_chunks; e++) {
  2116. void *base = pd->port_rcvegrbuf[e];
  2117. size_t size = pd->port_rcvegrbuf_size;
  2118. ipath_cdbg(VERBOSE, "egrbuf free(%p, %lu), "
  2119. "chunk %u/%u\n", base,
  2120. (unsigned long) size,
  2121. e, pd->port_rcvegrbuf_chunks);
  2122. dma_free_coherent(&dd->pcidev->dev, size,
  2123. base, pd->port_rcvegrbuf_phys[e]);
  2124. }
  2125. kfree(pd->port_rcvegrbuf);
  2126. pd->port_rcvegrbuf = NULL;
  2127. kfree(pd->port_rcvegrbuf_phys);
  2128. pd->port_rcvegrbuf_phys = NULL;
  2129. pd->port_rcvegrbuf_chunks = 0;
  2130. } else if (pd->port_port == 0 && dd->ipath_port0_skbinfo) {
  2131. unsigned e;
  2132. struct ipath_skbinfo *skbinfo = dd->ipath_port0_skbinfo;
  2133. dd->ipath_port0_skbinfo = NULL;
  2134. ipath_cdbg(VERBOSE, "free closed port %d "
  2135. "ipath_port0_skbinfo @ %p\n", pd->port_port,
  2136. skbinfo);
  2137. for (e = 0; e < dd->ipath_p0_rcvegrcnt; e++)
  2138. if (skbinfo[e].skb) {
  2139. pci_unmap_single(dd->pcidev, skbinfo[e].phys,
  2140. dd->ipath_ibmaxlen,
  2141. PCI_DMA_FROMDEVICE);
  2142. dev_kfree_skb(skbinfo[e].skb);
  2143. }
  2144. vfree(skbinfo);
  2145. }
  2146. kfree(pd->port_tid_pg_list);
  2147. vfree(pd->subport_uregbase);
  2148. vfree(pd->subport_rcvegrbuf);
  2149. vfree(pd->subport_rcvhdr_base);
  2150. kfree(pd);
  2151. }
  2152. static int __init infinipath_init(void)
  2153. {
  2154. int ret;
  2155. if (ipath_debug & __IPATH_DBG)
  2156. printk(KERN_INFO DRIVER_LOAD_MSG "%s", ib_ipath_version);
  2157. /*
  2158. * These must be called before the driver is registered with
  2159. * the PCI subsystem.
  2160. */
  2161. idr_init(&unit_table);
  2162. if (!idr_pre_get(&unit_table, GFP_KERNEL)) {
  2163. printk(KERN_ERR IPATH_DRV_NAME ": idr_pre_get() failed\n");
  2164. ret = -ENOMEM;
  2165. goto bail;
  2166. }
  2167. ret = pci_register_driver(&ipath_driver);
  2168. if (ret < 0) {
  2169. printk(KERN_ERR IPATH_DRV_NAME
  2170. ": Unable to register driver: error %d\n", -ret);
  2171. goto bail_unit;
  2172. }
  2173. ret = ipath_init_ipathfs();
  2174. if (ret < 0) {
  2175. printk(KERN_ERR IPATH_DRV_NAME ": Unable to create "
  2176. "ipathfs: error %d\n", -ret);
  2177. goto bail_pci;
  2178. }
  2179. goto bail;
  2180. bail_pci:
  2181. pci_unregister_driver(&ipath_driver);
  2182. bail_unit:
  2183. idr_destroy(&unit_table);
  2184. bail:
  2185. return ret;
  2186. }
  2187. static void __exit infinipath_cleanup(void)
  2188. {
  2189. ipath_exit_ipathfs();
  2190. ipath_cdbg(VERBOSE, "Unregistering pci driver\n");
  2191. pci_unregister_driver(&ipath_driver);
  2192. idr_destroy(&unit_table);
  2193. }
  2194. /**
  2195. * ipath_reset_device - reset the chip if possible
  2196. * @unit: the device to reset
  2197. *
  2198. * Whether or not reset is successful, we attempt to re-initialize the chip
  2199. * (that is, much like a driver unload/reload). We clear the INITTED flag
  2200. * so that the various entry points will fail until we reinitialize. For
  2201. * now, we only allow this if no user ports are open that use chip resources
  2202. */
  2203. int ipath_reset_device(int unit)
  2204. {
  2205. int ret, i;
  2206. struct ipath_devdata *dd = ipath_lookup(unit);
  2207. if (!dd) {
  2208. ret = -ENODEV;
  2209. goto bail;
  2210. }
  2211. if (atomic_read(&dd->ipath_led_override_timer_active)) {
  2212. /* Need to stop LED timer, _then_ shut off LEDs */
  2213. del_timer_sync(&dd->ipath_led_override_timer);
  2214. atomic_set(&dd->ipath_led_override_timer_active, 0);
  2215. }
  2216. /* Shut off LEDs after we are sure timer is not running */
  2217. dd->ipath_led_override = LED_OVER_BOTH_OFF;
  2218. dd->ipath_f_setextled(dd, 0, 0);
  2219. dev_info(&dd->pcidev->dev, "Reset on unit %u requested\n", unit);
  2220. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT)) {
  2221. dev_info(&dd->pcidev->dev, "Invalid unit number %u or "
  2222. "not initialized or not present\n", unit);
  2223. ret = -ENXIO;
  2224. goto bail;
  2225. }
  2226. if (dd->ipath_pd)
  2227. for (i = 1; i < dd->ipath_cfgports; i++) {
  2228. if (dd->ipath_pd[i] && dd->ipath_pd[i]->port_cnt) {
  2229. ipath_dbg("unit %u port %d is in use "
  2230. "(PID %u cmd %s), can't reset\n",
  2231. unit, i,
  2232. dd->ipath_pd[i]->port_pid,
  2233. dd->ipath_pd[i]->port_comm);
  2234. ret = -EBUSY;
  2235. goto bail;
  2236. }
  2237. }
  2238. if (dd->ipath_flags & IPATH_HAS_SEND_DMA)
  2239. teardown_sdma(dd);
  2240. dd->ipath_flags &= ~IPATH_INITTED;
  2241. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
  2242. ret = dd->ipath_f_reset(dd);
  2243. if (ret == 1) {
  2244. ipath_dbg("Reinitializing unit %u after reset attempt\n",
  2245. unit);
  2246. ret = ipath_init_chip(dd, 1);
  2247. } else
  2248. ret = -EAGAIN;
  2249. if (ret)
  2250. ipath_dev_err(dd, "Reinitialize unit %u after "
  2251. "reset failed with %d\n", unit, ret);
  2252. else
  2253. dev_info(&dd->pcidev->dev, "Reinitialized unit %u after "
  2254. "resetting\n", unit);
  2255. bail:
  2256. return ret;
  2257. }
  2258. /*
  2259. * send a signal to all the processes that have the driver open
  2260. * through the normal interfaces (i.e., everything other than diags
  2261. * interface). Returns number of signalled processes.
  2262. */
  2263. static int ipath_signal_procs(struct ipath_devdata *dd, int sig)
  2264. {
  2265. int i, sub, any = 0;
  2266. pid_t pid;
  2267. if (!dd->ipath_pd)
  2268. return 0;
  2269. for (i = 1; i < dd->ipath_cfgports; i++) {
  2270. if (!dd->ipath_pd[i] || !dd->ipath_pd[i]->port_cnt ||
  2271. !dd->ipath_pd[i]->port_pid)
  2272. continue;
  2273. pid = dd->ipath_pd[i]->port_pid;
  2274. dev_info(&dd->pcidev->dev, "context %d in use "
  2275. "(PID %u), sending signal %d\n",
  2276. i, pid, sig);
  2277. kill_proc(pid, sig, 1);
  2278. any++;
  2279. for (sub = 0; sub < INFINIPATH_MAX_SUBPORT; sub++) {
  2280. pid = dd->ipath_pd[i]->port_subpid[sub];
  2281. if (!pid)
  2282. continue;
  2283. dev_info(&dd->pcidev->dev, "sub-context "
  2284. "%d:%d in use (PID %u), sending "
  2285. "signal %d\n", i, sub, pid, sig);
  2286. kill_proc(pid, sig, 1);
  2287. any++;
  2288. }
  2289. }
  2290. return any;
  2291. }
  2292. static void ipath_hol_signal_down(struct ipath_devdata *dd)
  2293. {
  2294. if (ipath_signal_procs(dd, SIGSTOP))
  2295. ipath_dbg("Stopped some processes\n");
  2296. ipath_cancel_sends(dd, 1);
  2297. }
  2298. static void ipath_hol_signal_up(struct ipath_devdata *dd)
  2299. {
  2300. if (ipath_signal_procs(dd, SIGCONT))
  2301. ipath_dbg("Continued some processes\n");
  2302. }
  2303. /*
  2304. * link is down, stop any users processes, and flush pending sends
  2305. * to prevent HoL blocking, then start the HoL timer that
  2306. * periodically continues, then stop procs, so they can detect
  2307. * link down if they want, and do something about it.
  2308. * Timer may already be running, so use __mod_timer, not add_timer.
  2309. */
  2310. void ipath_hol_down(struct ipath_devdata *dd)
  2311. {
  2312. dd->ipath_hol_state = IPATH_HOL_DOWN;
  2313. ipath_hol_signal_down(dd);
  2314. dd->ipath_hol_next = IPATH_HOL_DOWNCONT;
  2315. dd->ipath_hol_timer.expires = jiffies +
  2316. msecs_to_jiffies(ipath_hol_timeout_ms);
  2317. __mod_timer(&dd->ipath_hol_timer, dd->ipath_hol_timer.expires);
  2318. }
  2319. /*
  2320. * link is up, continue any user processes, and ensure timer
  2321. * is a nop, if running. Let timer keep running, if set; it
  2322. * will nop when it sees the link is up
  2323. */
  2324. void ipath_hol_up(struct ipath_devdata *dd)
  2325. {
  2326. ipath_hol_signal_up(dd);
  2327. dd->ipath_hol_state = IPATH_HOL_UP;
  2328. }
  2329. /*
  2330. * toggle the running/not running state of user proceses
  2331. * to prevent HoL blocking on chip resources, but still allow
  2332. * user processes to do link down special case handling.
  2333. * Should only be called via the timer
  2334. */
  2335. void ipath_hol_event(unsigned long opaque)
  2336. {
  2337. struct ipath_devdata *dd = (struct ipath_devdata *)opaque;
  2338. if (dd->ipath_hol_next == IPATH_HOL_DOWNSTOP
  2339. && dd->ipath_hol_state != IPATH_HOL_UP) {
  2340. dd->ipath_hol_next = IPATH_HOL_DOWNCONT;
  2341. ipath_dbg("Stopping processes\n");
  2342. ipath_hol_signal_down(dd);
  2343. } else { /* may do "extra" if also in ipath_hol_up() */
  2344. dd->ipath_hol_next = IPATH_HOL_DOWNSTOP;
  2345. ipath_dbg("Continuing processes\n");
  2346. ipath_hol_signal_up(dd);
  2347. }
  2348. if (dd->ipath_hol_state == IPATH_HOL_UP)
  2349. ipath_dbg("link's up, don't resched timer\n");
  2350. else {
  2351. dd->ipath_hol_timer.expires = jiffies +
  2352. msecs_to_jiffies(ipath_hol_timeout_ms);
  2353. __mod_timer(&dd->ipath_hol_timer,
  2354. dd->ipath_hol_timer.expires);
  2355. }
  2356. }
  2357. int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv)
  2358. {
  2359. u64 val;
  2360. if (new_pol_inv > INFINIPATH_XGXS_RX_POL_MASK)
  2361. return -1;
  2362. if (dd->ipath_rx_pol_inv != new_pol_inv) {
  2363. dd->ipath_rx_pol_inv = new_pol_inv;
  2364. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
  2365. val &= ~(INFINIPATH_XGXS_RX_POL_MASK <<
  2366. INFINIPATH_XGXS_RX_POL_SHIFT);
  2367. val |= ((u64)dd->ipath_rx_pol_inv) <<
  2368. INFINIPATH_XGXS_RX_POL_SHIFT;
  2369. ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
  2370. }
  2371. return 0;
  2372. }
  2373. /*
  2374. * Disable and enable the armlaunch error. Used for PIO bandwidth testing on
  2375. * the 7220, which is count-based, rather than trigger-based. Safe for the
  2376. * driver check, since it's at init. Not completely safe when used for
  2377. * user-mode checking, since some error checking can be lost, but not
  2378. * particularly risky, and only has problematic side-effects in the face of
  2379. * very buggy user code. There is no reference counting, but that's also
  2380. * fine, given the intended use.
  2381. */
  2382. void ipath_enable_armlaunch(struct ipath_devdata *dd)
  2383. {
  2384. dd->ipath_lasterror &= ~INFINIPATH_E_SPIOARMLAUNCH;
  2385. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear,
  2386. INFINIPATH_E_SPIOARMLAUNCH);
  2387. dd->ipath_errormask |= INFINIPATH_E_SPIOARMLAUNCH;
  2388. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  2389. dd->ipath_errormask);
  2390. }
  2391. void ipath_disable_armlaunch(struct ipath_devdata *dd)
  2392. {
  2393. /* so don't re-enable if already set */
  2394. dd->ipath_maskederrs &= ~INFINIPATH_E_SPIOARMLAUNCH;
  2395. dd->ipath_errormask &= ~INFINIPATH_E_SPIOARMLAUNCH;
  2396. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  2397. dd->ipath_errormask);
  2398. }
  2399. module_init(infinipath_init);
  2400. module_exit(infinipath_cleanup);