ipath_kernel.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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. /* free irq */
  203. void (*ipath_f_free_irq)(struct ipath_devdata *);
  204. struct ipath_ibdev *verbs_dev;
  205. struct timer_list verbs_timer;
  206. /* total dwords sent (summed from counter) */
  207. u64 ipath_sword;
  208. /* total dwords rcvd (summed from counter) */
  209. u64 ipath_rword;
  210. /* total packets sent (summed from counter) */
  211. u64 ipath_spkts;
  212. /* total packets rcvd (summed from counter) */
  213. u64 ipath_rpkts;
  214. /* ipath_statusp initially points to this. */
  215. u64 _ipath_status;
  216. /* GUID for this interface, in network order */
  217. __be64 ipath_guid;
  218. /*
  219. * aggregrate of error bits reported since last cleared, for
  220. * limiting of error reporting
  221. */
  222. ipath_err_t ipath_lasterror;
  223. /*
  224. * aggregrate of error bits reported since last cleared, for
  225. * limiting of hwerror reporting
  226. */
  227. ipath_err_t ipath_lasthwerror;
  228. /*
  229. * errors masked because they occur too fast, also includes errors
  230. * that are always ignored (ipath_ignorederrs)
  231. */
  232. ipath_err_t ipath_maskederrs;
  233. /* time in jiffies at which to re-enable maskederrs */
  234. unsigned long ipath_unmasktime;
  235. /*
  236. * errors always ignored (masked), at least for a given
  237. * chip/device, because they are wrong or not useful
  238. */
  239. ipath_err_t ipath_ignorederrs;
  240. /* count of egrfull errors, combined for all ports */
  241. u64 ipath_last_tidfull;
  242. /* for ipath_qcheck() */
  243. u64 ipath_lastport0rcv_cnt;
  244. /* template for writing TIDs */
  245. u64 ipath_tidtemplate;
  246. /* value to write to free TIDs */
  247. u64 ipath_tidinvalid;
  248. /* IBA6120 rcv interrupt setup */
  249. u64 ipath_rhdrhead_intr_off;
  250. /* size of memory at ipath_kregbase */
  251. u32 ipath_kregsize;
  252. /* number of registers used for pioavail */
  253. u32 ipath_pioavregs;
  254. /* IPATH_POLL, etc. */
  255. u32 ipath_flags;
  256. /* ipath_flags driver is waiting for */
  257. u32 ipath_state_wanted;
  258. /* last buffer for user use, first buf for kernel use is this
  259. * index. */
  260. u32 ipath_lastport_piobuf;
  261. /* is a stats timer active */
  262. u32 ipath_stats_timer_active;
  263. /* dwords sent read from counter */
  264. u32 ipath_lastsword;
  265. /* dwords received read from counter */
  266. u32 ipath_lastrword;
  267. /* sent packets read from counter */
  268. u32 ipath_lastspkts;
  269. /* received packets read from counter */
  270. u32 ipath_lastrpkts;
  271. /* pio bufs allocated per port */
  272. u32 ipath_pbufsport;
  273. /*
  274. * number of ports configured as max; zero is set to number chip
  275. * supports, less gives more pio bufs/port, etc.
  276. */
  277. u32 ipath_cfgports;
  278. /* port0 rcvhdrq head offset */
  279. u32 ipath_port0head;
  280. /* count of port 0 hdrqfull errors */
  281. u32 ipath_p0_hdrqfull;
  282. /*
  283. * (*cfgports) used to suppress multiple instances of same
  284. * port staying stuck at same point
  285. */
  286. u32 *ipath_lastrcvhdrqtails;
  287. /*
  288. * (*cfgports) used to suppress multiple instances of same
  289. * port staying stuck at same point
  290. */
  291. u32 *ipath_lastegrheads;
  292. /*
  293. * index of last piobuffer we used. Speeds up searching, by
  294. * starting at this point. Doesn't matter if multiple cpu's use and
  295. * update, last updater is only write that matters. Whenever it
  296. * wraps, we update shadow copies. Need a copy per device when we
  297. * get to multiple devices
  298. */
  299. u32 ipath_lastpioindex;
  300. /* max length of freezemsg */
  301. u32 ipath_freezelen;
  302. /*
  303. * consecutive times we wanted a PIO buffer but were unable to
  304. * get one
  305. */
  306. u32 ipath_consec_nopiobuf;
  307. /*
  308. * hint that we should update ipath_pioavailshadow before
  309. * looking for a PIO buffer
  310. */
  311. u32 ipath_upd_pio_shadow;
  312. /* so we can rewrite it after a chip reset */
  313. u32 ipath_pcibar0;
  314. /* so we can rewrite it after a chip reset */
  315. u32 ipath_pcibar1;
  316. /* interrupt number */
  317. int ipath_irq;
  318. /* HT/PCI Vendor ID (here for NodeInfo) */
  319. u16 ipath_vendorid;
  320. /* HT/PCI Device ID (here for NodeInfo) */
  321. u16 ipath_deviceid;
  322. /* offset in HT config space of slave/primary interface block */
  323. u8 ipath_ht_slave_off;
  324. /* for write combining settings */
  325. unsigned long ipath_wc_cookie;
  326. unsigned long ipath_wc_base;
  327. unsigned long ipath_wc_len;
  328. /* ref count for each pkey */
  329. atomic_t ipath_pkeyrefs[4];
  330. /* shadow copy of all exptids physaddr; used only by funcsim */
  331. u64 *ipath_tidsimshadow;
  332. /* shadow copy of struct page *'s for exp tid pages */
  333. struct page **ipath_pageshadow;
  334. /* shadow copy of dma handles for exp tid pages */
  335. dma_addr_t *ipath_physshadow;
  336. /* lock to workaround chip bug 9437 */
  337. spinlock_t ipath_tid_lock;
  338. /*
  339. * IPATH_STATUS_*,
  340. * this address is mapped readonly into user processes so they can
  341. * get status cheaply, whenever they want.
  342. */
  343. u64 *ipath_statusp;
  344. /* freeze msg if hw error put chip in freeze */
  345. char *ipath_freezemsg;
  346. /* pci access data structure */
  347. struct pci_dev *pcidev;
  348. struct cdev *user_cdev;
  349. struct cdev *diag_cdev;
  350. struct class_device *user_class_dev;
  351. struct class_device *diag_class_dev;
  352. /* timer used to prevent stats overflow, error throttling, etc. */
  353. struct timer_list ipath_stats_timer;
  354. /* check for stale messages in rcv queue */
  355. /* only allow one intr at a time. */
  356. unsigned long ipath_rcv_pending;
  357. void *ipath_dummy_hdrq; /* used after port close */
  358. dma_addr_t ipath_dummy_hdrq_phys;
  359. /*
  360. * Shadow copies of registers; size indicates read access size.
  361. * Most of them are readonly, but some are write-only register,
  362. * where we manipulate the bits in the shadow copy, and then write
  363. * the shadow copy to infinipath.
  364. *
  365. * We deliberately make most of these 32 bits, since they have
  366. * restricted range. For any that we read, we won't to generate 32
  367. * bit accesses, since Opteron will generate 2 separate 32 bit HT
  368. * transactions for a 64 bit read, and we want to avoid unnecessary
  369. * HT transactions.
  370. */
  371. /* This is the 64 bit group */
  372. /*
  373. * shadow of pioavail, check to be sure it's large enough at
  374. * init time.
  375. */
  376. unsigned long ipath_pioavailshadow[8];
  377. /* shadow of kr_gpio_out, for rmw ops */
  378. u64 ipath_gpio_out;
  379. /* shadow the gpio mask register */
  380. u64 ipath_gpio_mask;
  381. /* kr_revision shadow */
  382. u64 ipath_revision;
  383. /*
  384. * shadow of ibcctrl, for interrupt handling of link changes,
  385. * etc.
  386. */
  387. u64 ipath_ibcctrl;
  388. /*
  389. * last ibcstatus, to suppress "duplicate" status change messages,
  390. * mostly from 2 to 3
  391. */
  392. u64 ipath_lastibcstat;
  393. /* hwerrmask shadow */
  394. ipath_err_t ipath_hwerrmask;
  395. /* interrupt config reg shadow */
  396. u64 ipath_intconfig;
  397. /* kr_sendpiobufbase value */
  398. u64 ipath_piobufbase;
  399. /* these are the "32 bit" regs */
  400. /*
  401. * number of GUIDs in the flash for this interface; may need some
  402. * rethinking for setting on other ifaces
  403. */
  404. u32 ipath_nguid;
  405. /*
  406. * the following two are 32-bit bitmasks, but {test,clear,set}_bit
  407. * all expect bit fields to be "unsigned long"
  408. */
  409. /* shadow kr_rcvctrl */
  410. unsigned long ipath_rcvctrl;
  411. /* shadow kr_sendctrl */
  412. unsigned long ipath_sendctrl;
  413. /* ports waiting for PIOavail intr */
  414. unsigned long ipath_portpiowait;
  415. unsigned long ipath_lastcancel; /* to not count armlaunch after cancel */
  416. /* value we put in kr_rcvhdrcnt */
  417. u32 ipath_rcvhdrcnt;
  418. /* value we put in kr_rcvhdrsize */
  419. u32 ipath_rcvhdrsize;
  420. /* value we put in kr_rcvhdrentsize */
  421. u32 ipath_rcvhdrentsize;
  422. /* offset of last entry in rcvhdrq */
  423. u32 ipath_hdrqlast;
  424. /* kr_portcnt value */
  425. u32 ipath_portcnt;
  426. /* kr_pagealign value */
  427. u32 ipath_palign;
  428. /* number of "2KB" PIO buffers */
  429. u32 ipath_piobcnt2k;
  430. /* size in bytes of "2KB" PIO buffers */
  431. u32 ipath_piosize2k;
  432. /* number of "4KB" PIO buffers */
  433. u32 ipath_piobcnt4k;
  434. /* size in bytes of "4KB" PIO buffers */
  435. u32 ipath_piosize4k;
  436. /* kr_rcvegrbase value */
  437. u32 ipath_rcvegrbase;
  438. /* kr_rcvegrcnt value */
  439. u32 ipath_rcvegrcnt;
  440. /* kr_rcvtidbase value */
  441. u32 ipath_rcvtidbase;
  442. /* kr_rcvtidcnt value */
  443. u32 ipath_rcvtidcnt;
  444. /* kr_sendregbase */
  445. u32 ipath_sregbase;
  446. /* kr_userregbase */
  447. u32 ipath_uregbase;
  448. /* kr_counterregbase */
  449. u32 ipath_cregbase;
  450. /* shadow the control register contents */
  451. u32 ipath_control;
  452. /* shadow the gpio output contents */
  453. u32 ipath_extctrl;
  454. /* PCI revision register (HTC rev on FPGA) */
  455. u32 ipath_pcirev;
  456. /* chip address space used by 4k pio buffers */
  457. u32 ipath_4kalign;
  458. /* The MTU programmed for this unit */
  459. u32 ipath_ibmtu;
  460. /*
  461. * The max size IB packet, included IB headers that we can send.
  462. * Starts same as ipath_piosize, but is affected when ibmtu is
  463. * changed, or by size of eager buffers
  464. */
  465. u32 ipath_ibmaxlen;
  466. /*
  467. * ibmaxlen at init time, limited by chip and by receive buffer
  468. * size. Not changed after init.
  469. */
  470. u32 ipath_init_ibmaxlen;
  471. /* size of each rcvegrbuffer */
  472. u32 ipath_rcvegrbufsize;
  473. /* width (2,4,8,16,32) from HT config reg */
  474. u32 ipath_htwidth;
  475. /* HT speed (200,400,800,1000) from HT config */
  476. u32 ipath_htspeed;
  477. /*
  478. * number of sequential ibcstatus change for polling active/quiet
  479. * (i.e., link not coming up).
  480. */
  481. u32 ipath_ibpollcnt;
  482. /* low and high portions of MSI capability/vector */
  483. u32 ipath_msi_lo;
  484. /* saved after PCIe init for restore after reset */
  485. u32 ipath_msi_hi;
  486. /* MSI data (vector) saved for restore */
  487. u16 ipath_msi_data;
  488. /* MLID programmed for this instance */
  489. u16 ipath_mlid;
  490. /* LID programmed for this instance */
  491. u16 ipath_lid;
  492. /* list of pkeys programmed; 0 if not set */
  493. u16 ipath_pkeys[4];
  494. /*
  495. * ASCII serial number, from flash, large enough for original
  496. * all digit strings, and longer QLogic serial number format
  497. */
  498. u8 ipath_serial[16];
  499. /* human readable board version */
  500. u8 ipath_boardversion[80];
  501. /* chip major rev, from ipath_revision */
  502. u8 ipath_majrev;
  503. /* chip minor rev, from ipath_revision */
  504. u8 ipath_minrev;
  505. /* board rev, from ipath_revision */
  506. u8 ipath_boardrev;
  507. /* unit # of this chip, if present */
  508. int ipath_unit;
  509. /* saved for restore after reset */
  510. u8 ipath_pci_cacheline;
  511. /* LID mask control */
  512. u8 ipath_lmc;
  513. /* Rx Polarity inversion (compensate for ~tx on partner) */
  514. u8 ipath_rx_pol_inv;
  515. /* local link integrity counter */
  516. u32 ipath_lli_counter;
  517. /* local link integrity errors */
  518. u32 ipath_lli_errors;
  519. /*
  520. * Above counts only cases where _successive_ LocalLinkIntegrity
  521. * errors were seen in the receive headers of kern-packets.
  522. * Below are the three (monotonically increasing) counters
  523. * maintained via GPIO interrupts on iba6120-rev2.
  524. */
  525. u32 ipath_rxfc_unsupvl_errs;
  526. u32 ipath_overrun_thresh_errs;
  527. u32 ipath_lli_errs;
  528. /*
  529. * Not all devices managed by a driver instance are the same
  530. * type, so these fields must be per-device.
  531. */
  532. u64 ipath_i_bitsextant;
  533. ipath_err_t ipath_e_bitsextant;
  534. ipath_err_t ipath_hwe_bitsextant;
  535. /*
  536. * Below should be computable from number of ports,
  537. * since they are never modified.
  538. */
  539. u32 ipath_i_rcvavail_mask;
  540. u32 ipath_i_rcvurg_mask;
  541. /*
  542. * Register bits for selecting i2c direction and values, used for
  543. * I2C serial flash.
  544. */
  545. u16 ipath_gpio_sda_num;
  546. u16 ipath_gpio_scl_num;
  547. u64 ipath_gpio_sda;
  548. u64 ipath_gpio_scl;
  549. };
  550. /* Private data for file operations */
  551. struct ipath_filedata {
  552. struct ipath_portdata *pd;
  553. unsigned subport;
  554. unsigned tidcursor;
  555. };
  556. extern struct list_head ipath_dev_list;
  557. extern spinlock_t ipath_devs_lock;
  558. extern struct ipath_devdata *ipath_lookup(int unit);
  559. int ipath_init_chip(struct ipath_devdata *, int);
  560. int ipath_enable_wc(struct ipath_devdata *dd);
  561. void ipath_disable_wc(struct ipath_devdata *dd);
  562. int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp);
  563. void ipath_shutdown_device(struct ipath_devdata *);
  564. struct file_operations;
  565. int ipath_cdev_init(int minor, char *name, const struct file_operations *fops,
  566. struct cdev **cdevp, struct class_device **class_devp);
  567. void ipath_cdev_cleanup(struct cdev **cdevp,
  568. struct class_device **class_devp);
  569. int ipath_diag_add(struct ipath_devdata *);
  570. void ipath_diag_remove(struct ipath_devdata *);
  571. extern wait_queue_head_t ipath_state_wait;
  572. int ipath_user_add(struct ipath_devdata *dd);
  573. void ipath_user_remove(struct ipath_devdata *dd);
  574. struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
  575. extern int ipath_diag_inuse;
  576. irqreturn_t ipath_intr(int irq, void *devid);
  577. int ipath_decode_err(char *buf, size_t blen, ipath_err_t err);
  578. #if __IPATH_INFO || __IPATH_DBG
  579. extern const char *ipath_ibcstatus_str[];
  580. #endif
  581. /* clean up any per-chip chip-specific stuff */
  582. void ipath_chip_cleanup(struct ipath_devdata *);
  583. /* clean up any chip type-specific stuff */
  584. void ipath_chip_done(void);
  585. /* check to see if we have to force ordering for write combining */
  586. int ipath_unordered_wc(void);
  587. void ipath_disarm_piobufs(struct ipath_devdata *, unsigned first,
  588. unsigned cnt);
  589. int ipath_create_rcvhdrq(struct ipath_devdata *, struct ipath_portdata *);
  590. void ipath_free_pddata(struct ipath_devdata *, struct ipath_portdata *);
  591. int ipath_parse_ushort(const char *str, unsigned short *valp);
  592. void ipath_kreceive(struct ipath_devdata *);
  593. int ipath_setrcvhdrsize(struct ipath_devdata *, unsigned);
  594. int ipath_reset_device(int);
  595. void ipath_get_faststats(unsigned long);
  596. int ipath_set_linkstate(struct ipath_devdata *, u8);
  597. int ipath_set_mtu(struct ipath_devdata *, u16);
  598. int ipath_set_lid(struct ipath_devdata *, u32, u8);
  599. int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv);
  600. /* for use in system calls, where we want to know device type, etc. */
  601. #define port_fp(fp) ((struct ipath_filedata *)(fp)->private_data)->pd
  602. #define subport_fp(fp) \
  603. ((struct ipath_filedata *)(fp)->private_data)->subport
  604. #define tidcursor_fp(fp) \
  605. ((struct ipath_filedata *)(fp)->private_data)->tidcursor
  606. /*
  607. * values for ipath_flags
  608. */
  609. /* The chip is up and initted */
  610. #define IPATH_INITTED 0x2
  611. /* set if any user code has set kr_rcvhdrsize */
  612. #define IPATH_RCVHDRSZ_SET 0x4
  613. /* The chip is present and valid for accesses */
  614. #define IPATH_PRESENT 0x8
  615. /* HT link0 is only 8 bits wide, ignore upper byte crc
  616. * errors, etc. */
  617. #define IPATH_8BIT_IN_HT0 0x10
  618. /* HT link1 is only 8 bits wide, ignore upper byte crc
  619. * errors, etc. */
  620. #define IPATH_8BIT_IN_HT1 0x20
  621. /* The link is down */
  622. #define IPATH_LINKDOWN 0x40
  623. /* The link level is up (0x11) */
  624. #define IPATH_LINKINIT 0x80
  625. /* The link is in the armed (0x21) state */
  626. #define IPATH_LINKARMED 0x100
  627. /* The link is in the active (0x31) state */
  628. #define IPATH_LINKACTIVE 0x200
  629. /* link current state is unknown */
  630. #define IPATH_LINKUNK 0x400
  631. /* no IB cable, or no device on IB cable */
  632. #define IPATH_NOCABLE 0x4000
  633. /* Supports port zero per packet receive interrupts via
  634. * GPIO */
  635. #define IPATH_GPIO_INTR 0x8000
  636. /* uses the coded 4byte TID, not 8 byte */
  637. #define IPATH_4BYTE_TID 0x10000
  638. /* packet/word counters are 32 bit, else those 4 counters
  639. * are 64bit */
  640. #define IPATH_32BITCOUNTERS 0x20000
  641. /* can miss port0 rx interrupts */
  642. #define IPATH_POLL_RX_INTR 0x40000
  643. #define IPATH_DISABLED 0x80000 /* administratively disabled */
  644. /* Use GPIO interrupts for new counters */
  645. #define IPATH_GPIO_ERRINTRS 0x100000
  646. /* Bits in GPIO for the added interrupts */
  647. #define IPATH_GPIO_PORT0_BIT 2
  648. #define IPATH_GPIO_RXUVL_BIT 3
  649. #define IPATH_GPIO_OVRUN_BIT 4
  650. #define IPATH_GPIO_LLI_BIT 5
  651. #define IPATH_GPIO_ERRINTR_MASK 0x38
  652. /* portdata flag bit offsets */
  653. /* waiting for a packet to arrive */
  654. #define IPATH_PORT_WAITING_RCV 2
  655. /* waiting for a PIO buffer to be available */
  656. #define IPATH_PORT_WAITING_PIO 3
  657. /* master has not finished initializing */
  658. #define IPATH_PORT_MASTER_UNINIT 4
  659. /* free up any allocated data at closes */
  660. void ipath_free_data(struct ipath_portdata *dd);
  661. int ipath_waitfor_mdio_cmdready(struct ipath_devdata *);
  662. int ipath_waitfor_complete(struct ipath_devdata *, ipath_kreg, u64, u64 *);
  663. u32 __iomem *ipath_getpiobuf(struct ipath_devdata *, u32 *);
  664. void ipath_init_iba6120_funcs(struct ipath_devdata *);
  665. void ipath_init_iba6110_funcs(struct ipath_devdata *);
  666. void ipath_get_eeprom_info(struct ipath_devdata *);
  667. u64 ipath_snap_cntr(struct ipath_devdata *, ipath_creg);
  668. void ipath_disarm_senderrbufs(struct ipath_devdata *, int);
  669. /*
  670. * number of words used for protocol header if not set by ipath_userinit();
  671. */
  672. #define IPATH_DFLT_RCVHDRSIZE 9
  673. #define IPATH_MDIO_CMD_WRITE 1
  674. #define IPATH_MDIO_CMD_READ 2
  675. #define IPATH_MDIO_CLD_DIV 25 /* to get 2.5 Mhz mdio clock */
  676. #define IPATH_MDIO_CMDVALID 0x40000000 /* bit 30 */
  677. #define IPATH_MDIO_DATAVALID 0x80000000 /* bit 31 */
  678. #define IPATH_MDIO_CTRL_STD 0x0
  679. static inline u64 ipath_mdio_req(int cmd, int dev, int reg, int data)
  680. {
  681. return (((u64) IPATH_MDIO_CLD_DIV) << 32) |
  682. (cmd << 26) |
  683. (dev << 21) |
  684. (reg << 16) |
  685. (data & 0xFFFF);
  686. }
  687. /* signal and fifo status, in bank 31 */
  688. #define IPATH_MDIO_CTRL_XGXS_REG_8 0x8
  689. /* controls loopback, redundancy */
  690. #define IPATH_MDIO_CTRL_8355_REG_1 0x10
  691. /* premph, encdec, etc. */
  692. #define IPATH_MDIO_CTRL_8355_REG_2 0x11
  693. /* Kchars, etc. */
  694. #define IPATH_MDIO_CTRL_8355_REG_6 0x15
  695. #define IPATH_MDIO_CTRL_8355_REG_9 0x18
  696. #define IPATH_MDIO_CTRL_8355_REG_10 0x1D
  697. int ipath_get_user_pages(unsigned long, size_t, struct page **);
  698. int ipath_get_user_pages_nocopy(unsigned long, struct page **);
  699. void ipath_release_user_pages(struct page **, size_t);
  700. void ipath_release_user_pages_on_close(struct page **, size_t);
  701. int ipath_eeprom_read(struct ipath_devdata *, u8, void *, int);
  702. int ipath_eeprom_write(struct ipath_devdata *, u8, const void *, int);
  703. /* these are used for the registers that vary with port */
  704. void ipath_write_kreg_port(const struct ipath_devdata *, ipath_kreg,
  705. unsigned, u64);
  706. /*
  707. * We could have a single register get/put routine, that takes a group type,
  708. * but this is somewhat clearer and cleaner. It also gives us some error
  709. * checking. 64 bit register reads should always work, but are inefficient
  710. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  711. * so we use kreg32 wherever possible. User register and counter register
  712. * reads are always 32 bit reads, so only one form of those routines.
  713. */
  714. /*
  715. * At the moment, none of the s-registers are writable, so no
  716. * ipath_write_sreg(), and none of the c-registers are writable, so no
  717. * ipath_write_creg().
  718. */
  719. /**
  720. * ipath_read_ureg32 - read 32-bit virtualized per-port register
  721. * @dd: device
  722. * @regno: register number
  723. * @port: port number
  724. *
  725. * Return the contents of a register that is virtualized to be per port.
  726. * Returns -1 on errors (not distinguishable from valid contents at
  727. * runtime; we may add a separate error variable at some point).
  728. */
  729. static inline u32 ipath_read_ureg32(const struct ipath_devdata *dd,
  730. ipath_ureg regno, int port)
  731. {
  732. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  733. return 0;
  734. return readl(regno + (u64 __iomem *)
  735. (dd->ipath_uregbase +
  736. (char __iomem *)dd->ipath_kregbase +
  737. dd->ipath_palign * port));
  738. }
  739. /**
  740. * ipath_write_ureg - write 32-bit virtualized per-port register
  741. * @dd: device
  742. * @regno: register number
  743. * @value: value
  744. * @port: port
  745. *
  746. * Write the contents of a register that is virtualized to be per port.
  747. */
  748. static inline void ipath_write_ureg(const struct ipath_devdata *dd,
  749. ipath_ureg regno, u64 value, int port)
  750. {
  751. u64 __iomem *ubase = (u64 __iomem *)
  752. (dd->ipath_uregbase + (char __iomem *) dd->ipath_kregbase +
  753. dd->ipath_palign * port);
  754. if (dd->ipath_kregbase)
  755. writeq(value, &ubase[regno]);
  756. }
  757. static inline u32 ipath_read_kreg32(const struct ipath_devdata *dd,
  758. ipath_kreg regno)
  759. {
  760. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  761. return -1;
  762. return readl((u32 __iomem *) & dd->ipath_kregbase[regno]);
  763. }
  764. static inline u64 ipath_read_kreg64(const struct ipath_devdata *dd,
  765. ipath_kreg regno)
  766. {
  767. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  768. return -1;
  769. return readq(&dd->ipath_kregbase[regno]);
  770. }
  771. static inline void ipath_write_kreg(const struct ipath_devdata *dd,
  772. ipath_kreg regno, u64 value)
  773. {
  774. if (dd->ipath_kregbase)
  775. writeq(value, &dd->ipath_kregbase[regno]);
  776. }
  777. static inline u64 ipath_read_creg(const struct ipath_devdata *dd,
  778. ipath_sreg regno)
  779. {
  780. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  781. return 0;
  782. return readq(regno + (u64 __iomem *)
  783. (dd->ipath_cregbase +
  784. (char __iomem *)dd->ipath_kregbase));
  785. }
  786. static inline u32 ipath_read_creg32(const struct ipath_devdata *dd,
  787. ipath_sreg regno)
  788. {
  789. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  790. return 0;
  791. return readl(regno + (u64 __iomem *)
  792. (dd->ipath_cregbase +
  793. (char __iomem *)dd->ipath_kregbase));
  794. }
  795. /*
  796. * sysfs interface.
  797. */
  798. struct device_driver;
  799. extern const char ib_ipath_version[];
  800. int ipath_driver_create_group(struct device_driver *);
  801. void ipath_driver_remove_group(struct device_driver *);
  802. int ipath_device_create_group(struct device *, struct ipath_devdata *);
  803. void ipath_device_remove_group(struct device *, struct ipath_devdata *);
  804. int ipath_expose_reset(struct device *);
  805. int ipath_init_ipathfs(void);
  806. void ipath_exit_ipathfs(void);
  807. int ipathfs_add_device(struct ipath_devdata *);
  808. int ipathfs_remove_device(struct ipath_devdata *);
  809. /*
  810. * dma_addr wrappers - all 0's invalid for hw
  811. */
  812. dma_addr_t ipath_map_page(struct pci_dev *, struct page *, unsigned long,
  813. size_t, int);
  814. dma_addr_t ipath_map_single(struct pci_dev *, void *, size_t, int);
  815. /*
  816. * Flush write combining store buffers (if present) and perform a write
  817. * barrier.
  818. */
  819. #if defined(CONFIG_X86_64)
  820. #define ipath_flush_wc() asm volatile("sfence" ::: "memory")
  821. #else
  822. #define ipath_flush_wc() wmb()
  823. #endif
  824. extern unsigned ipath_debug; /* debugging bit mask */
  825. #define IPATH_MAX_PARITY_ATTEMPTS 10000 /* max times to try recovery */
  826. const char *ipath_get_unit_name(int unit);
  827. extern struct mutex ipath_mutex;
  828. #define IPATH_DRV_NAME "ib_ipath"
  829. #define IPATH_MAJOR 233
  830. #define IPATH_USER_MINOR_BASE 0
  831. #define IPATH_DIAGPKT_MINOR 127
  832. #define IPATH_DIAG_MINOR_BASE 129
  833. #define IPATH_NMINORS 255
  834. #define ipath_dev_err(dd,fmt,...) \
  835. do { \
  836. const struct ipath_devdata *__dd = (dd); \
  837. if (__dd->pcidev) \
  838. dev_err(&__dd->pcidev->dev, "%s: " fmt, \
  839. ipath_get_unit_name(__dd->ipath_unit), \
  840. ##__VA_ARGS__); \
  841. else \
  842. printk(KERN_ERR IPATH_DRV_NAME ": %s: " fmt, \
  843. ipath_get_unit_name(__dd->ipath_unit), \
  844. ##__VA_ARGS__); \
  845. } while (0)
  846. #if _IPATH_DEBUGGING
  847. # define __IPATH_DBG_WHICH(which,fmt,...) \
  848. do { \
  849. if(unlikely(ipath_debug&(which))) \
  850. printk(KERN_DEBUG IPATH_DRV_NAME ": %s: " fmt, \
  851. __func__,##__VA_ARGS__); \
  852. } while(0)
  853. # define ipath_dbg(fmt,...) \
  854. __IPATH_DBG_WHICH(__IPATH_DBG,fmt,##__VA_ARGS__)
  855. # define ipath_cdbg(which,fmt,...) \
  856. __IPATH_DBG_WHICH(__IPATH_##which##DBG,fmt,##__VA_ARGS__)
  857. #else /* ! _IPATH_DEBUGGING */
  858. # define ipath_dbg(fmt,...)
  859. # define ipath_cdbg(which,fmt,...)
  860. #endif /* _IPATH_DEBUGGING */
  861. /*
  862. * this is used for formatting hw error messages...
  863. */
  864. struct ipath_hwerror_msgs {
  865. u64 mask;
  866. const char *msg;
  867. };
  868. #define INFINIPATH_HWE_MSG(a, b) { .mask = INFINIPATH_HWE_##a, .msg = b }
  869. /* in ipath_intr.c... */
  870. void ipath_format_hwerrors(u64 hwerrs,
  871. const struct ipath_hwerror_msgs *hwerrmsgs,
  872. size_t nhwerrmsgs,
  873. char *msg, size_t lmsg);
  874. #endif /* _IPATH_KERNEL_H */