ipath_kernel.h 29 KB

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