ipath_kernel.h 27 KB

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