ipath_kernel.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. #ifndef _IPATH_KERNEL_H
  2. #define _IPATH_KERNEL_H
  3. /*
  4. * Copyright (c) 2006 QLogic, Inc. All rights reserved.
  5. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. /*
  36. * This header file is the base header file for infinipath kernel code
  37. * ipath_user.h serves a similar purpose for user code.
  38. */
  39. #include <linux/interrupt.h>
  40. #include <linux/pci.h>
  41. #include <linux/dma-mapping.h>
  42. #include <asm/io.h>
  43. #include "ipath_common.h"
  44. #include "ipath_debug.h"
  45. #include "ipath_registers.h"
  46. /* only s/w major version of InfiniPath we can handle */
  47. #define IPATH_CHIP_VERS_MAJ 2U
  48. /* don't care about this except printing */
  49. #define IPATH_CHIP_VERS_MIN 0U
  50. /* temporary, maybe always */
  51. extern struct infinipath_stats ipath_stats;
  52. #define IPATH_CHIP_SWVERSION IPATH_CHIP_VERS_MAJ
  53. struct ipath_portdata {
  54. void **port_rcvegrbuf;
  55. dma_addr_t *port_rcvegrbuf_phys;
  56. /* rcvhdrq base, needs mmap before useful */
  57. void *port_rcvhdrq;
  58. /* kernel virtual address where hdrqtail is updated */
  59. void *port_rcvhdrtail_kvaddr;
  60. /*
  61. * temp buffer for expected send setup, allocated at open, instead
  62. * of each setup call
  63. */
  64. void *port_tid_pg_list;
  65. /* when waiting for rcv or pioavail */
  66. wait_queue_head_t port_wait;
  67. /*
  68. * rcvegr bufs base, physical, must fit
  69. * in 44 bits so 32 bit programs mmap64 44 bit works)
  70. */
  71. dma_addr_t port_rcvegr_phys;
  72. /* mmap of hdrq, must fit in 44 bits */
  73. dma_addr_t port_rcvhdrq_phys;
  74. dma_addr_t port_rcvhdrqtailaddr_phys;
  75. /*
  76. * number of opens (including slave subports) on this instance
  77. * (ignoring forks, dup, etc. for now)
  78. */
  79. int port_cnt;
  80. /*
  81. * how much space to leave at start of eager TID entries for
  82. * protocol use, on each TID
  83. */
  84. /* instead of calculating it */
  85. unsigned port_port;
  86. /* non-zero if port is being shared. */
  87. u16 port_subport_cnt;
  88. /* non-zero if port is being shared. */
  89. u16 port_subport_id;
  90. /* chip offset of PIO buffers for this port */
  91. u32 port_piobufs;
  92. /* how many alloc_pages() chunks in port_rcvegrbuf_pages */
  93. u32 port_rcvegrbuf_chunks;
  94. /* how many egrbufs per chunk */
  95. u32 port_rcvegrbufs_perchunk;
  96. /* order for port_rcvegrbuf_pages */
  97. size_t port_rcvegrbuf_size;
  98. /* rcvhdrq size (for freeing) */
  99. size_t port_rcvhdrq_size;
  100. /* next expected TID to check when looking for free */
  101. u32 port_tidcursor;
  102. /* next expected TID to check */
  103. unsigned long port_flag;
  104. /* WAIT_RCV that timed out, no interrupt */
  105. u32 port_rcvwait_to;
  106. /* WAIT_PIO that timed out, no interrupt */
  107. u32 port_piowait_to;
  108. /* WAIT_RCV already happened, no wait */
  109. u32 port_rcvnowait;
  110. /* WAIT_PIO already happened, no wait */
  111. u32 port_pionowait;
  112. /* total number of rcvhdrqfull errors */
  113. u32 port_hdrqfull;
  114. /* pid of process using this port */
  115. pid_t port_pid;
  116. /* same size as task_struct .comm[] */
  117. char port_comm[16];
  118. /* pkeys set by this use of this port */
  119. u16 port_pkeys[4];
  120. /* so file ops can get at unit */
  121. struct ipath_devdata *port_dd;
  122. /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
  123. void *subport_uregbase;
  124. /* An array of pages for the eager receive buffers * N */
  125. void *subport_rcvegrbuf;
  126. /* An array of pages for the eager header queue entries * N */
  127. void *subport_rcvhdr_base;
  128. /* The version of the library which opened this port */
  129. u32 userversion;
  130. /* Bitmask of active slaves */
  131. u32 active_slaves;
  132. };
  133. struct sk_buff;
  134. /*
  135. * control information for layered drivers
  136. */
  137. struct _ipath_layer {
  138. void *l_arg;
  139. };
  140. struct ipath_skbinfo {
  141. struct sk_buff *skb;
  142. dma_addr_t phys;
  143. };
  144. struct ipath_devdata {
  145. struct list_head ipath_list;
  146. struct ipath_kregs const *ipath_kregs;
  147. struct ipath_cregs const *ipath_cregs;
  148. /* mem-mapped pointer to base of chip regs */
  149. u64 __iomem *ipath_kregbase;
  150. /* end of mem-mapped chip space; range checking */
  151. u64 __iomem *ipath_kregend;
  152. /* physical address of chip for io_remap, etc. */
  153. unsigned long ipath_physaddr;
  154. /* base of memory alloced for ipath_kregbase, for free */
  155. u64 *ipath_kregalloc;
  156. /*
  157. * virtual address where port0 rcvhdrqtail updated for this unit.
  158. * only written to by the chip, not the driver.
  159. */
  160. volatile __le64 *ipath_hdrqtailptr;
  161. /* ipath_cfgports pointers */
  162. struct ipath_portdata **ipath_pd;
  163. /* sk_buffs used by port 0 eager receive queue */
  164. struct ipath_skbinfo *ipath_port0_skbinfo;
  165. /* kvirt address of 1st 2k pio buffer */
  166. void __iomem *ipath_pio2kbase;
  167. /* kvirt address of 1st 4k pio buffer */
  168. void __iomem *ipath_pio4kbase;
  169. /*
  170. * points to area where PIOavail registers will be DMA'ed.
  171. * Has to be on a page of it's own, because the page will be
  172. * mapped into user program space. This copy is *ONLY* ever
  173. * written by DMA, not by the driver! Need a copy per device
  174. * when we get to multiple devices
  175. */
  176. volatile __le64 *ipath_pioavailregs_dma;
  177. /* physical address where updates occur */
  178. dma_addr_t ipath_pioavailregs_phys;
  179. struct _ipath_layer ipath_layer;
  180. /* setup intr */
  181. int (*ipath_f_intrsetup)(struct ipath_devdata *);
  182. /* setup on-chip bus config */
  183. int (*ipath_f_bus)(struct ipath_devdata *, struct pci_dev *);
  184. /* hard reset chip */
  185. int (*ipath_f_reset)(struct ipath_devdata *);
  186. int (*ipath_f_get_boardname)(struct ipath_devdata *, char *,
  187. size_t);
  188. void (*ipath_f_init_hwerrors)(struct ipath_devdata *);
  189. void (*ipath_f_handle_hwerrors)(struct ipath_devdata *, char *,
  190. size_t);
  191. void (*ipath_f_quiet_serdes)(struct ipath_devdata *);
  192. int (*ipath_f_bringup_serdes)(struct ipath_devdata *);
  193. int (*ipath_f_early_init)(struct ipath_devdata *);
  194. void (*ipath_f_clear_tids)(struct ipath_devdata *, unsigned);
  195. void (*ipath_f_put_tid)(struct ipath_devdata *, u64 __iomem*,
  196. u32, unsigned long);
  197. void (*ipath_f_tidtemplate)(struct ipath_devdata *);
  198. void (*ipath_f_cleanup)(struct ipath_devdata *);
  199. void (*ipath_f_setextled)(struct ipath_devdata *, u64, u64);
  200. /* fill out chip-specific fields */
  201. int (*ipath_f_get_base_info)(struct ipath_portdata *, void *);
  202. struct ipath_ibdev *verbs_dev;
  203. struct timer_list verbs_timer;
  204. /* total dwords sent (summed from counter) */
  205. u64 ipath_sword;
  206. /* total dwords rcvd (summed from counter) */
  207. u64 ipath_rword;
  208. /* total packets sent (summed from counter) */
  209. u64 ipath_spkts;
  210. /* total packets rcvd (summed from counter) */
  211. u64 ipath_rpkts;
  212. /* ipath_statusp initially points to this. */
  213. u64 _ipath_status;
  214. /* GUID for this interface, in network order */
  215. __be64 ipath_guid;
  216. /*
  217. * aggregrate of error bits reported since last cleared, for
  218. * limiting of error reporting
  219. */
  220. ipath_err_t ipath_lasterror;
  221. /*
  222. * aggregrate of error bits reported since last cleared, for
  223. * limiting of hwerror reporting
  224. */
  225. ipath_err_t ipath_lasthwerror;
  226. /*
  227. * errors masked because they occur too fast, also includes errors
  228. * that are always ignored (ipath_ignorederrs)
  229. */
  230. ipath_err_t ipath_maskederrs;
  231. /* time in jiffies at which to re-enable maskederrs */
  232. unsigned long ipath_unmasktime;
  233. /*
  234. * errors always ignored (masked), at least for a given
  235. * chip/device, because they are wrong or not useful
  236. */
  237. ipath_err_t ipath_ignorederrs;
  238. /* count of egrfull errors, combined for all ports */
  239. u64 ipath_last_tidfull;
  240. /* for ipath_qcheck() */
  241. u64 ipath_lastport0rcv_cnt;
  242. /* template for writing TIDs */
  243. u64 ipath_tidtemplate;
  244. /* value to write to free TIDs */
  245. u64 ipath_tidinvalid;
  246. /* IBA6120 rcv interrupt setup */
  247. u64 ipath_rhdrhead_intr_off;
  248. /* size of memory at ipath_kregbase */
  249. u32 ipath_kregsize;
  250. /* number of registers used for pioavail */
  251. u32 ipath_pioavregs;
  252. /* IPATH_POLL, etc. */
  253. u32 ipath_flags;
  254. /* ipath_flags driver is waiting for */
  255. u32 ipath_state_wanted;
  256. /* last buffer for user use, first buf for kernel use is this
  257. * index. */
  258. u32 ipath_lastport_piobuf;
  259. /* is a stats timer active */
  260. u32 ipath_stats_timer_active;
  261. /* dwords sent read from counter */
  262. u32 ipath_lastsword;
  263. /* dwords received read from counter */
  264. u32 ipath_lastrword;
  265. /* sent packets read from counter */
  266. u32 ipath_lastspkts;
  267. /* received packets read from counter */
  268. u32 ipath_lastrpkts;
  269. /* pio bufs allocated per port */
  270. u32 ipath_pbufsport;
  271. /*
  272. * number of ports configured as max; zero is set to number chip
  273. * supports, less gives more pio bufs/port, etc.
  274. */
  275. u32 ipath_cfgports;
  276. /* port0 rcvhdrq head offset */
  277. u32 ipath_port0head;
  278. /* count of port 0 hdrqfull errors */
  279. u32 ipath_p0_hdrqfull;
  280. /*
  281. * (*cfgports) used to suppress multiple instances of same
  282. * port staying stuck at same point
  283. */
  284. u32 *ipath_lastrcvhdrqtails;
  285. /*
  286. * (*cfgports) used to suppress multiple instances of same
  287. * port staying stuck at same point
  288. */
  289. u32 *ipath_lastegrheads;
  290. /*
  291. * index of last piobuffer we used. Speeds up searching, by
  292. * starting at this point. Doesn't matter if multiple cpu's use and
  293. * update, last updater is only write that matters. Whenever it
  294. * wraps, we update shadow copies. Need a copy per device when we
  295. * get to multiple devices
  296. */
  297. u32 ipath_lastpioindex;
  298. /* max length of freezemsg */
  299. u32 ipath_freezelen;
  300. /*
  301. * consecutive times we wanted a PIO buffer but were unable to
  302. * get one
  303. */
  304. u32 ipath_consec_nopiobuf;
  305. /*
  306. * hint that we should update ipath_pioavailshadow before
  307. * looking for a PIO buffer
  308. */
  309. u32 ipath_upd_pio_shadow;
  310. /* so we can rewrite it after a chip reset */
  311. u32 ipath_pcibar0;
  312. /* so we can rewrite it after a chip reset */
  313. u32 ipath_pcibar1;
  314. /* HT/PCI Vendor ID (here for NodeInfo) */
  315. u16 ipath_vendorid;
  316. /* HT/PCI Device ID (here for NodeInfo) */
  317. u16 ipath_deviceid;
  318. /* offset in HT config space of slave/primary interface block */
  319. u8 ipath_ht_slave_off;
  320. /* for write combining settings */
  321. unsigned long ipath_wc_cookie;
  322. unsigned long ipath_wc_base;
  323. unsigned long ipath_wc_len;
  324. /* ref count for each pkey */
  325. atomic_t ipath_pkeyrefs[4];
  326. /* shadow copy of all exptids physaddr; used only by funcsim */
  327. u64 *ipath_tidsimshadow;
  328. /* shadow copy of struct page *'s for exp tid pages */
  329. struct page **ipath_pageshadow;
  330. /* shadow copy of dma handles for exp tid pages */
  331. dma_addr_t *ipath_physshadow;
  332. /* lock to workaround chip bug 9437 */
  333. spinlock_t ipath_tid_lock;
  334. /*
  335. * IPATH_STATUS_*,
  336. * this address is mapped readonly into user processes so they can
  337. * get status cheaply, whenever they want.
  338. */
  339. u64 *ipath_statusp;
  340. /* freeze msg if hw error put chip in freeze */
  341. char *ipath_freezemsg;
  342. /* pci access data structure */
  343. struct pci_dev *pcidev;
  344. struct cdev *user_cdev;
  345. struct cdev *diag_cdev;
  346. struct class_device *user_class_dev;
  347. struct class_device *diag_class_dev;
  348. /* timer used to prevent stats overflow, error throttling, etc. */
  349. struct timer_list ipath_stats_timer;
  350. /* check for stale messages in rcv queue */
  351. /* only allow one intr at a time. */
  352. unsigned long ipath_rcv_pending;
  353. void *ipath_dummy_hdrq; /* used after port close */
  354. dma_addr_t ipath_dummy_hdrq_phys;
  355. /*
  356. * Shadow copies of registers; size indicates read access size.
  357. * Most of them are readonly, but some are write-only register,
  358. * where we manipulate the bits in the shadow copy, and then write
  359. * the shadow copy to infinipath.
  360. *
  361. * We deliberately make most of these 32 bits, since they have
  362. * restricted range. For any that we read, we won't to generate 32
  363. * bit accesses, since Opteron will generate 2 separate 32 bit HT
  364. * transactions for a 64 bit read, and we want to avoid unnecessary
  365. * HT transactions.
  366. */
  367. /* This is the 64 bit group */
  368. /*
  369. * shadow of pioavail, check to be sure it's large enough at
  370. * init time.
  371. */
  372. unsigned long ipath_pioavailshadow[8];
  373. /* shadow of kr_gpio_out, for rmw ops */
  374. u64 ipath_gpio_out;
  375. /* kr_revision shadow */
  376. u64 ipath_revision;
  377. /*
  378. * shadow of ibcctrl, for interrupt handling of link changes,
  379. * etc.
  380. */
  381. u64 ipath_ibcctrl;
  382. /*
  383. * last ibcstatus, to suppress "duplicate" status change messages,
  384. * mostly from 2 to 3
  385. */
  386. u64 ipath_lastibcstat;
  387. /* hwerrmask shadow */
  388. ipath_err_t ipath_hwerrmask;
  389. /* interrupt config reg shadow */
  390. u64 ipath_intconfig;
  391. /* kr_sendpiobufbase value */
  392. u64 ipath_piobufbase;
  393. /* these are the "32 bit" regs */
  394. /*
  395. * number of GUIDs in the flash for this interface; may need some
  396. * rethinking for setting on other ifaces
  397. */
  398. u32 ipath_nguid;
  399. /*
  400. * the following two are 32-bit bitmasks, but {test,clear,set}_bit
  401. * all expect bit fields to be "unsigned long"
  402. */
  403. /* shadow kr_rcvctrl */
  404. unsigned long ipath_rcvctrl;
  405. /* shadow kr_sendctrl */
  406. unsigned long ipath_sendctrl;
  407. /* ports waiting for PIOavail intr */
  408. unsigned long ipath_portpiowait;
  409. unsigned long ipath_lastcancel; /* to not count armlaunch after cancel */
  410. /* value we put in kr_rcvhdrcnt */
  411. u32 ipath_rcvhdrcnt;
  412. /* value we put in kr_rcvhdrsize */
  413. u32 ipath_rcvhdrsize;
  414. /* value we put in kr_rcvhdrentsize */
  415. u32 ipath_rcvhdrentsize;
  416. /* offset of last entry in rcvhdrq */
  417. u32 ipath_hdrqlast;
  418. /* kr_portcnt value */
  419. u32 ipath_portcnt;
  420. /* kr_pagealign value */
  421. u32 ipath_palign;
  422. /* number of "2KB" PIO buffers */
  423. u32 ipath_piobcnt2k;
  424. /* size in bytes of "2KB" PIO buffers */
  425. u32 ipath_piosize2k;
  426. /* number of "4KB" PIO buffers */
  427. u32 ipath_piobcnt4k;
  428. /* size in bytes of "4KB" PIO buffers */
  429. u32 ipath_piosize4k;
  430. /* kr_rcvegrbase value */
  431. u32 ipath_rcvegrbase;
  432. /* kr_rcvegrcnt value */
  433. u32 ipath_rcvegrcnt;
  434. /* kr_rcvtidbase value */
  435. u32 ipath_rcvtidbase;
  436. /* kr_rcvtidcnt value */
  437. u32 ipath_rcvtidcnt;
  438. /* kr_sendregbase */
  439. u32 ipath_sregbase;
  440. /* kr_userregbase */
  441. u32 ipath_uregbase;
  442. /* kr_counterregbase */
  443. u32 ipath_cregbase;
  444. /* shadow the control register contents */
  445. u32 ipath_control;
  446. /* shadow the gpio output contents */
  447. u32 ipath_extctrl;
  448. /* PCI revision register (HTC rev on FPGA) */
  449. u32 ipath_pcirev;
  450. /* chip address space used by 4k pio buffers */
  451. u32 ipath_4kalign;
  452. /* The MTU programmed for this unit */
  453. u32 ipath_ibmtu;
  454. /*
  455. * The max size IB packet, included IB headers that we can send.
  456. * Starts same as ipath_piosize, but is affected when ibmtu is
  457. * changed, or by size of eager buffers
  458. */
  459. u32 ipath_ibmaxlen;
  460. /*
  461. * ibmaxlen at init time, limited by chip and by receive buffer
  462. * size. Not changed after init.
  463. */
  464. u32 ipath_init_ibmaxlen;
  465. /* size of each rcvegrbuffer */
  466. u32 ipath_rcvegrbufsize;
  467. /* width (2,4,8,16,32) from HT config reg */
  468. u32 ipath_htwidth;
  469. /* HT speed (200,400,800,1000) from HT config */
  470. u32 ipath_htspeed;
  471. /*
  472. * number of sequential ibcstatus change for polling active/quiet
  473. * (i.e., link not coming up).
  474. */
  475. u32 ipath_ibpollcnt;
  476. /* low and high portions of MSI capability/vector */
  477. u32 ipath_msi_lo;
  478. /* saved after PCIe init for restore after reset */
  479. u32 ipath_msi_hi;
  480. /* MSI data (vector) saved for restore */
  481. u16 ipath_msi_data;
  482. /* MLID programmed for this instance */
  483. u16 ipath_mlid;
  484. /* LID programmed for this instance */
  485. u16 ipath_lid;
  486. /* list of pkeys programmed; 0 if not set */
  487. u16 ipath_pkeys[4];
  488. /*
  489. * ASCII serial number, from flash, large enough for original
  490. * all digit strings, and longer QLogic serial number format
  491. */
  492. u8 ipath_serial[16];
  493. /* human readable board version */
  494. u8 ipath_boardversion[80];
  495. /* chip major rev, from ipath_revision */
  496. u8 ipath_majrev;
  497. /* chip minor rev, from ipath_revision */
  498. u8 ipath_minrev;
  499. /* board rev, from ipath_revision */
  500. u8 ipath_boardrev;
  501. /* unit # of this chip, if present */
  502. int ipath_unit;
  503. /* saved for restore after reset */
  504. u8 ipath_pci_cacheline;
  505. /* LID mask control */
  506. u8 ipath_lmc;
  507. /* Rx Polarity inversion (compensate for ~tx on partner) */
  508. u8 ipath_rx_pol_inv;
  509. /* local link integrity counter */
  510. u32 ipath_lli_counter;
  511. /* local link integrity errors */
  512. u32 ipath_lli_errors;
  513. /*
  514. * Above counts only cases where _successive_ LocalLinkIntegrity
  515. * errors were seen in the receive headers of kern-packets.
  516. * Below are the three (monotonically increasing) counters
  517. * maintained via GPIO interrupts on iba6120-rev2.
  518. */
  519. u32 ipath_rxfc_unsupvl_errs;
  520. u32 ipath_overrun_thresh_errs;
  521. u32 ipath_lli_errs;
  522. /*
  523. * Not all devices managed by a driver instance are the same
  524. * type, so these fields must be per-device.
  525. */
  526. u64 ipath_i_bitsextant;
  527. ipath_err_t ipath_e_bitsextant;
  528. ipath_err_t ipath_hwe_bitsextant;
  529. /*
  530. * Below should be computable from number of ports,
  531. * since they are never modified.
  532. */
  533. u32 ipath_i_rcvavail_mask;
  534. u32 ipath_i_rcvurg_mask;
  535. /*
  536. * Register bits for selecting i2c direction and values, used for
  537. * I2C serial flash.
  538. */
  539. u16 ipath_gpio_sda_num;
  540. u16 ipath_gpio_scl_num;
  541. u64 ipath_gpio_sda;
  542. u64 ipath_gpio_scl;
  543. };
  544. /* Private data for file operations */
  545. struct ipath_filedata {
  546. struct ipath_portdata *pd;
  547. unsigned subport;
  548. unsigned tidcursor;
  549. };
  550. extern struct list_head ipath_dev_list;
  551. extern spinlock_t ipath_devs_lock;
  552. extern struct ipath_devdata *ipath_lookup(int unit);
  553. int ipath_init_chip(struct ipath_devdata *, int);
  554. int ipath_enable_wc(struct ipath_devdata *dd);
  555. void ipath_disable_wc(struct ipath_devdata *dd);
  556. int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp);
  557. void ipath_shutdown_device(struct ipath_devdata *);
  558. void ipath_disarm_senderrbufs(struct ipath_devdata *);
  559. struct file_operations;
  560. int ipath_cdev_init(int minor, char *name, struct file_operations *fops,
  561. struct cdev **cdevp, struct class_device **class_devp);
  562. void ipath_cdev_cleanup(struct cdev **cdevp,
  563. struct class_device **class_devp);
  564. int ipath_diag_add(struct ipath_devdata *);
  565. void ipath_diag_remove(struct ipath_devdata *);
  566. extern wait_queue_head_t ipath_state_wait;
  567. int ipath_user_add(struct ipath_devdata *dd);
  568. void ipath_user_remove(struct ipath_devdata *dd);
  569. struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
  570. extern int ipath_diag_inuse;
  571. irqreturn_t ipath_intr(int irq, void *devid);
  572. void ipath_decode_err(char *buf, size_t blen, ipath_err_t err);
  573. #if __IPATH_INFO || __IPATH_DBG
  574. extern const char *ipath_ibcstatus_str[];
  575. #endif
  576. /* clean up any per-chip chip-specific stuff */
  577. void ipath_chip_cleanup(struct ipath_devdata *);
  578. /* clean up any chip type-specific stuff */
  579. void ipath_chip_done(void);
  580. /* check to see if we have to force ordering for write combining */
  581. int ipath_unordered_wc(void);
  582. void ipath_disarm_piobufs(struct ipath_devdata *, unsigned first,
  583. unsigned cnt);
  584. int ipath_create_rcvhdrq(struct ipath_devdata *, struct ipath_portdata *);
  585. void ipath_free_pddata(struct ipath_devdata *, struct ipath_portdata *);
  586. int ipath_parse_ushort(const char *str, unsigned short *valp);
  587. void ipath_kreceive(struct ipath_devdata *);
  588. int ipath_setrcvhdrsize(struct ipath_devdata *, unsigned);
  589. int ipath_reset_device(int);
  590. void ipath_get_faststats(unsigned long);
  591. int ipath_set_linkstate(struct ipath_devdata *, u8);
  592. int ipath_set_mtu(struct ipath_devdata *, u16);
  593. int ipath_set_lid(struct ipath_devdata *, u32, u8);
  594. int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv);
  595. /* for use in system calls, where we want to know device type, etc. */
  596. #define port_fp(fp) ((struct ipath_filedata *)(fp)->private_data)->pd
  597. #define subport_fp(fp) \
  598. ((struct ipath_filedata *)(fp)->private_data)->subport
  599. #define tidcursor_fp(fp) \
  600. ((struct ipath_filedata *)(fp)->private_data)->tidcursor
  601. /*
  602. * values for ipath_flags
  603. */
  604. /* The chip is up and initted */
  605. #define IPATH_INITTED 0x2
  606. /* set if any user code has set kr_rcvhdrsize */
  607. #define IPATH_RCVHDRSZ_SET 0x4
  608. /* The chip is present and valid for accesses */
  609. #define IPATH_PRESENT 0x8
  610. /* HT link0 is only 8 bits wide, ignore upper byte crc
  611. * errors, etc. */
  612. #define IPATH_8BIT_IN_HT0 0x10
  613. /* HT link1 is only 8 bits wide, ignore upper byte crc
  614. * errors, etc. */
  615. #define IPATH_8BIT_IN_HT1 0x20
  616. /* The link is down */
  617. #define IPATH_LINKDOWN 0x40
  618. /* The link level is up (0x11) */
  619. #define IPATH_LINKINIT 0x80
  620. /* The link is in the armed (0x21) state */
  621. #define IPATH_LINKARMED 0x100
  622. /* The link is in the active (0x31) state */
  623. #define IPATH_LINKACTIVE 0x200
  624. /* link current state is unknown */
  625. #define IPATH_LINKUNK 0x400
  626. /* no IB cable, or no device on IB cable */
  627. #define IPATH_NOCABLE 0x4000
  628. /* Supports port zero per packet receive interrupts via
  629. * GPIO */
  630. #define IPATH_GPIO_INTR 0x8000
  631. /* uses the coded 4byte TID, not 8 byte */
  632. #define IPATH_4BYTE_TID 0x10000
  633. /* packet/word counters are 32 bit, else those 4 counters
  634. * are 64bit */
  635. #define IPATH_32BITCOUNTERS 0x20000
  636. /* can miss port0 rx interrupts */
  637. #define IPATH_POLL_RX_INTR 0x40000
  638. #define IPATH_DISABLED 0x80000 /* administratively disabled */
  639. /* Use GPIO interrupts for new counters */
  640. #define IPATH_GPIO_ERRINTRS 0x100000
  641. /* Bits in GPIO for the added interrupts */
  642. #define IPATH_GPIO_PORT0_BIT 2
  643. #define IPATH_GPIO_RXUVL_BIT 3
  644. #define IPATH_GPIO_OVRUN_BIT 4
  645. #define IPATH_GPIO_LLI_BIT 5
  646. #define IPATH_GPIO_ERRINTR_MASK 0x38
  647. /* portdata flag bit offsets */
  648. /* waiting for a packet to arrive */
  649. #define IPATH_PORT_WAITING_RCV 2
  650. /* waiting for a PIO buffer to be available */
  651. #define IPATH_PORT_WAITING_PIO 3
  652. /* free up any allocated data at closes */
  653. void ipath_free_data(struct ipath_portdata *dd);
  654. int ipath_waitfor_mdio_cmdready(struct ipath_devdata *);
  655. int ipath_waitfor_complete(struct ipath_devdata *, ipath_kreg, u64, u64 *);
  656. u32 __iomem *ipath_getpiobuf(struct ipath_devdata *, u32 *);
  657. void ipath_init_iba6120_funcs(struct ipath_devdata *);
  658. void ipath_init_iba6110_funcs(struct ipath_devdata *);
  659. void ipath_get_eeprom_info(struct ipath_devdata *);
  660. u64 ipath_snap_cntr(struct ipath_devdata *, ipath_creg);
  661. /*
  662. * number of words used for protocol header if not set by ipath_userinit();
  663. */
  664. #define IPATH_DFLT_RCVHDRSIZE 9
  665. #define IPATH_MDIO_CMD_WRITE 1
  666. #define IPATH_MDIO_CMD_READ 2
  667. #define IPATH_MDIO_CLD_DIV 25 /* to get 2.5 Mhz mdio clock */
  668. #define IPATH_MDIO_CMDVALID 0x40000000 /* bit 30 */
  669. #define IPATH_MDIO_DATAVALID 0x80000000 /* bit 31 */
  670. #define IPATH_MDIO_CTRL_STD 0x0
  671. static inline u64 ipath_mdio_req(int cmd, int dev, int reg, int data)
  672. {
  673. return (((u64) IPATH_MDIO_CLD_DIV) << 32) |
  674. (cmd << 26) |
  675. (dev << 21) |
  676. (reg << 16) |
  677. (data & 0xFFFF);
  678. }
  679. /* signal and fifo status, in bank 31 */
  680. #define IPATH_MDIO_CTRL_XGXS_REG_8 0x8
  681. /* controls loopback, redundancy */
  682. #define IPATH_MDIO_CTRL_8355_REG_1 0x10
  683. /* premph, encdec, etc. */
  684. #define IPATH_MDIO_CTRL_8355_REG_2 0x11
  685. /* Kchars, etc. */
  686. #define IPATH_MDIO_CTRL_8355_REG_6 0x15
  687. #define IPATH_MDIO_CTRL_8355_REG_9 0x18
  688. #define IPATH_MDIO_CTRL_8355_REG_10 0x1D
  689. int ipath_get_user_pages(unsigned long, size_t, struct page **);
  690. int ipath_get_user_pages_nocopy(unsigned long, struct page **);
  691. void ipath_release_user_pages(struct page **, size_t);
  692. void ipath_release_user_pages_on_close(struct page **, size_t);
  693. int ipath_eeprom_read(struct ipath_devdata *, u8, void *, int);
  694. int ipath_eeprom_write(struct ipath_devdata *, u8, const void *, int);
  695. /* these are used for the registers that vary with port */
  696. void ipath_write_kreg_port(const struct ipath_devdata *, ipath_kreg,
  697. unsigned, u64);
  698. u64 ipath_read_kreg64_port(const struct ipath_devdata *, ipath_kreg,
  699. unsigned);
  700. /*
  701. * We could have a single register get/put routine, that takes a group type,
  702. * but this is somewhat clearer and cleaner. It also gives us some error
  703. * checking. 64 bit register reads should always work, but are inefficient
  704. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  705. * so we use kreg32 wherever possible. User register and counter register
  706. * reads are always 32 bit reads, so only one form of those routines.
  707. */
  708. /*
  709. * At the moment, none of the s-registers are writable, so no
  710. * ipath_write_sreg(), and none of the c-registers are writable, so no
  711. * ipath_write_creg().
  712. */
  713. /**
  714. * ipath_read_ureg32 - read 32-bit virtualized per-port register
  715. * @dd: device
  716. * @regno: register number
  717. * @port: port number
  718. *
  719. * Return the contents of a register that is virtualized to be per port.
  720. * Returns -1 on errors (not distinguishable from valid contents at
  721. * runtime; we may add a separate error variable at some point).
  722. */
  723. static inline u32 ipath_read_ureg32(const struct ipath_devdata *dd,
  724. ipath_ureg regno, int port)
  725. {
  726. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  727. return 0;
  728. return readl(regno + (u64 __iomem *)
  729. (dd->ipath_uregbase +
  730. (char __iomem *)dd->ipath_kregbase +
  731. dd->ipath_palign * port));
  732. }
  733. /**
  734. * ipath_write_ureg - write 32-bit virtualized per-port register
  735. * @dd: device
  736. * @regno: register number
  737. * @value: value
  738. * @port: port
  739. *
  740. * Write the contents of a register that is virtualized to be per port.
  741. */
  742. static inline void ipath_write_ureg(const struct ipath_devdata *dd,
  743. ipath_ureg regno, u64 value, int port)
  744. {
  745. u64 __iomem *ubase = (u64 __iomem *)
  746. (dd->ipath_uregbase + (char __iomem *) dd->ipath_kregbase +
  747. dd->ipath_palign * port);
  748. if (dd->ipath_kregbase)
  749. writeq(value, &ubase[regno]);
  750. }
  751. static inline u32 ipath_read_kreg32(const struct ipath_devdata *dd,
  752. ipath_kreg regno)
  753. {
  754. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  755. return -1;
  756. return readl((u32 __iomem *) & dd->ipath_kregbase[regno]);
  757. }
  758. static inline u64 ipath_read_kreg64(const struct ipath_devdata *dd,
  759. ipath_kreg regno)
  760. {
  761. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  762. return -1;
  763. return readq(&dd->ipath_kregbase[regno]);
  764. }
  765. static inline void ipath_write_kreg(const struct ipath_devdata *dd,
  766. ipath_kreg regno, u64 value)
  767. {
  768. if (dd->ipath_kregbase)
  769. writeq(value, &dd->ipath_kregbase[regno]);
  770. }
  771. static inline u64 ipath_read_creg(const struct ipath_devdata *dd,
  772. ipath_sreg regno)
  773. {
  774. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  775. return 0;
  776. return readq(regno + (u64 __iomem *)
  777. (dd->ipath_cregbase +
  778. (char __iomem *)dd->ipath_kregbase));
  779. }
  780. static inline u32 ipath_read_creg32(const struct ipath_devdata *dd,
  781. ipath_sreg regno)
  782. {
  783. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  784. return 0;
  785. return readl(regno + (u64 __iomem *)
  786. (dd->ipath_cregbase +
  787. (char __iomem *)dd->ipath_kregbase));
  788. }
  789. /*
  790. * sysfs interface.
  791. */
  792. struct device_driver;
  793. extern const char ib_ipath_version[];
  794. int ipath_driver_create_group(struct device_driver *);
  795. void ipath_driver_remove_group(struct device_driver *);
  796. int ipath_device_create_group(struct device *, struct ipath_devdata *);
  797. void ipath_device_remove_group(struct device *, struct ipath_devdata *);
  798. int ipath_expose_reset(struct device *);
  799. int ipath_init_ipathfs(void);
  800. void ipath_exit_ipathfs(void);
  801. int ipathfs_add_device(struct ipath_devdata *);
  802. int ipathfs_remove_device(struct ipath_devdata *);
  803. /*
  804. * dma_addr wrappers - all 0's invalid for hw
  805. */
  806. dma_addr_t ipath_map_page(struct pci_dev *, struct page *, unsigned long,
  807. size_t, int);
  808. dma_addr_t ipath_map_single(struct pci_dev *, void *, size_t, int);
  809. /*
  810. * Flush write combining store buffers (if present) and perform a write
  811. * barrier.
  812. */
  813. #if defined(CONFIG_X86_64)
  814. #define ipath_flush_wc() asm volatile("sfence" ::: "memory")
  815. #else
  816. #define ipath_flush_wc() wmb()
  817. #endif
  818. extern unsigned ipath_debug; /* debugging bit mask */
  819. const char *ipath_get_unit_name(int unit);
  820. extern struct mutex ipath_mutex;
  821. #define IPATH_DRV_NAME "ib_ipath"
  822. #define IPATH_MAJOR 233
  823. #define IPATH_USER_MINOR_BASE 0
  824. #define IPATH_DIAGPKT_MINOR 127
  825. #define IPATH_DIAG_MINOR_BASE 129
  826. #define IPATH_NMINORS 255
  827. #define ipath_dev_err(dd,fmt,...) \
  828. do { \
  829. const struct ipath_devdata *__dd = (dd); \
  830. if (__dd->pcidev) \
  831. dev_err(&__dd->pcidev->dev, "%s: " fmt, \
  832. ipath_get_unit_name(__dd->ipath_unit), \
  833. ##__VA_ARGS__); \
  834. else \
  835. printk(KERN_ERR IPATH_DRV_NAME ": %s: " fmt, \
  836. ipath_get_unit_name(__dd->ipath_unit), \
  837. ##__VA_ARGS__); \
  838. } while (0)
  839. #if _IPATH_DEBUGGING
  840. # define __IPATH_DBG_WHICH(which,fmt,...) \
  841. do { \
  842. if(unlikely(ipath_debug&(which))) \
  843. printk(KERN_DEBUG IPATH_DRV_NAME ": %s: " fmt, \
  844. __func__,##__VA_ARGS__); \
  845. } while(0)
  846. # define ipath_dbg(fmt,...) \
  847. __IPATH_DBG_WHICH(__IPATH_DBG,fmt,##__VA_ARGS__)
  848. # define ipath_cdbg(which,fmt,...) \
  849. __IPATH_DBG_WHICH(__IPATH_##which##DBG,fmt,##__VA_ARGS__)
  850. #else /* ! _IPATH_DEBUGGING */
  851. # define ipath_dbg(fmt,...)
  852. # define ipath_cdbg(which,fmt,...)
  853. #endif /* _IPATH_DEBUGGING */
  854. /*
  855. * this is used for formatting hw error messages...
  856. */
  857. struct ipath_hwerror_msgs {
  858. u64 mask;
  859. const char *msg;
  860. };
  861. #define INFINIPATH_HWE_MSG(a, b) { .mask = INFINIPATH_HWE_##a, .msg = b }
  862. /* in ipath_intr.c... */
  863. void ipath_format_hwerrors(u64 hwerrs,
  864. const struct ipath_hwerror_msgs *hwerrmsgs,
  865. size_t nhwerrmsgs,
  866. char *msg, size_t lmsg);
  867. #endif /* _IPATH_KERNEL_H */