ipath_kernel.h 32 KB

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