c2.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /*
  2. * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
  3. * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #ifndef __C2_H
  34. #define __C2_H
  35. #include <linux/netdevice.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/kernel.h>
  38. #include <linux/pci.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/idr.h>
  41. #include "c2_provider.h"
  42. #include "c2_mq.h"
  43. #include "c2_status.h"
  44. #define DRV_NAME "c2"
  45. #define DRV_VERSION "1.1"
  46. #define PFX DRV_NAME ": "
  47. #define BAR_0 0
  48. #define BAR_2 2
  49. #define BAR_4 4
  50. #define RX_BUF_SIZE (1536 + 8)
  51. #define ETH_JUMBO_MTU 9000
  52. #define C2_MAGIC "CEPHEUS"
  53. #define C2_VERSION 4
  54. #define C2_IVN (18 & 0x7fffffff)
  55. #define C2_REG0_SIZE (16 * 1024)
  56. #define C2_REG2_SIZE (2 * 1024 * 1024)
  57. #define C2_REG4_SIZE (256 * 1024 * 1024)
  58. #define C2_NUM_TX_DESC 341
  59. #define C2_NUM_RX_DESC 256
  60. #define C2_PCI_REGS_OFFSET (0x10000)
  61. #define C2_RXP_HRXDQ_OFFSET (((C2_REG4_SIZE)/2))
  62. #define C2_RXP_HRXDQ_SIZE (4096)
  63. #define C2_TXP_HTXDQ_OFFSET (((C2_REG4_SIZE)/2) + C2_RXP_HRXDQ_SIZE)
  64. #define C2_TXP_HTXDQ_SIZE (4096)
  65. #define C2_TX_TIMEOUT (6*HZ)
  66. /* CEPHEUS */
  67. static const u8 c2_magic[] = {
  68. 0x43, 0x45, 0x50, 0x48, 0x45, 0x55, 0x53
  69. };
  70. enum adapter_pci_regs {
  71. C2_REGS_MAGIC = 0x0000,
  72. C2_REGS_VERS = 0x0008,
  73. C2_REGS_IVN = 0x000C,
  74. C2_REGS_PCI_WINSIZE = 0x0010,
  75. C2_REGS_Q0_QSIZE = 0x0014,
  76. C2_REGS_Q0_MSGSIZE = 0x0018,
  77. C2_REGS_Q0_POOLSTART = 0x001C,
  78. C2_REGS_Q0_SHARED = 0x0020,
  79. C2_REGS_Q1_QSIZE = 0x0024,
  80. C2_REGS_Q1_MSGSIZE = 0x0028,
  81. C2_REGS_Q1_SHARED = 0x0030,
  82. C2_REGS_Q2_QSIZE = 0x0034,
  83. C2_REGS_Q2_MSGSIZE = 0x0038,
  84. C2_REGS_Q2_SHARED = 0x0040,
  85. C2_REGS_ENADDR = 0x004C,
  86. C2_REGS_RDMA_ENADDR = 0x0054,
  87. C2_REGS_HRX_CUR = 0x006C,
  88. };
  89. struct c2_adapter_pci_regs {
  90. char reg_magic[8];
  91. u32 version;
  92. u32 ivn;
  93. u32 pci_window_size;
  94. u32 q0_q_size;
  95. u32 q0_msg_size;
  96. u32 q0_pool_start;
  97. u32 q0_shared;
  98. u32 q1_q_size;
  99. u32 q1_msg_size;
  100. u32 q1_pool_start;
  101. u32 q1_shared;
  102. u32 q2_q_size;
  103. u32 q2_msg_size;
  104. u32 q2_pool_start;
  105. u32 q2_shared;
  106. u32 log_start;
  107. u32 log_size;
  108. u8 host_enaddr[8];
  109. u8 rdma_enaddr[8];
  110. u32 crash_entry;
  111. u32 crash_ready[2];
  112. u32 fw_txd_cur;
  113. u32 fw_hrxd_cur;
  114. u32 fw_rxd_cur;
  115. };
  116. enum pci_regs {
  117. C2_HISR = 0x0000,
  118. C2_DISR = 0x0004,
  119. C2_HIMR = 0x0008,
  120. C2_DIMR = 0x000C,
  121. C2_NISR0 = 0x0010,
  122. C2_NISR1 = 0x0014,
  123. C2_NIMR0 = 0x0018,
  124. C2_NIMR1 = 0x001C,
  125. C2_IDIS = 0x0020,
  126. };
  127. enum {
  128. C2_PCI_HRX_INT = 1 << 8,
  129. C2_PCI_HTX_INT = 1 << 17,
  130. C2_PCI_HRX_QUI = 1 << 31,
  131. };
  132. /*
  133. * Cepheus registers in BAR0.
  134. */
  135. struct c2_pci_regs {
  136. u32 hostisr;
  137. u32 dmaisr;
  138. u32 hostimr;
  139. u32 dmaimr;
  140. u32 netisr0;
  141. u32 netisr1;
  142. u32 netimr0;
  143. u32 netimr1;
  144. u32 int_disable;
  145. };
  146. /* TXP flags */
  147. enum c2_txp_flags {
  148. TXP_HTXD_DONE = 0,
  149. TXP_HTXD_READY = 1 << 0,
  150. TXP_HTXD_UNINIT = 1 << 1,
  151. };
  152. /* RXP flags */
  153. enum c2_rxp_flags {
  154. RXP_HRXD_UNINIT = 0,
  155. RXP_HRXD_READY = 1 << 0,
  156. RXP_HRXD_DONE = 1 << 1,
  157. };
  158. /* RXP status */
  159. enum c2_rxp_status {
  160. RXP_HRXD_ZERO = 0,
  161. RXP_HRXD_OK = 1 << 0,
  162. RXP_HRXD_BUF_OV = 1 << 1,
  163. };
  164. /* TXP descriptor fields */
  165. enum txp_desc {
  166. C2_TXP_FLAGS = 0x0000,
  167. C2_TXP_LEN = 0x0002,
  168. C2_TXP_ADDR = 0x0004,
  169. };
  170. /* RXP descriptor fields */
  171. enum rxp_desc {
  172. C2_RXP_FLAGS = 0x0000,
  173. C2_RXP_STATUS = 0x0002,
  174. C2_RXP_COUNT = 0x0004,
  175. C2_RXP_LEN = 0x0006,
  176. C2_RXP_ADDR = 0x0008,
  177. };
  178. struct c2_txp_desc {
  179. u16 flags;
  180. u16 len;
  181. u64 addr;
  182. } __attribute__ ((packed));
  183. struct c2_rxp_desc {
  184. u16 flags;
  185. u16 status;
  186. u16 count;
  187. u16 len;
  188. u64 addr;
  189. } __attribute__ ((packed));
  190. struct c2_rxp_hdr {
  191. u16 flags;
  192. u16 status;
  193. u16 len;
  194. u16 rsvd;
  195. } __attribute__ ((packed));
  196. struct c2_tx_desc {
  197. u32 len;
  198. u32 status;
  199. dma_addr_t next_offset;
  200. };
  201. struct c2_rx_desc {
  202. u32 len;
  203. u32 status;
  204. dma_addr_t next_offset;
  205. };
  206. struct c2_alloc {
  207. u32 last;
  208. u32 max;
  209. spinlock_t lock;
  210. unsigned long *table;
  211. };
  212. struct c2_array {
  213. struct {
  214. void **page;
  215. int used;
  216. } *page_list;
  217. };
  218. /*
  219. * The MQ shared pointer pool is organized as a linked list of
  220. * chunks. Each chunk contains a linked list of free shared pointers
  221. * that can be allocated to a given user mode client.
  222. *
  223. */
  224. struct sp_chunk {
  225. struct sp_chunk *next;
  226. dma_addr_t dma_addr;
  227. DEFINE_DMA_UNMAP_ADDR(mapping);
  228. u16 head;
  229. u16 shared_ptr[0];
  230. };
  231. struct c2_pd_table {
  232. u32 last;
  233. u32 max;
  234. spinlock_t lock;
  235. unsigned long *table;
  236. };
  237. struct c2_qp_table {
  238. struct idr idr;
  239. spinlock_t lock;
  240. int last;
  241. };
  242. struct c2_element {
  243. struct c2_element *next;
  244. void *ht_desc; /* host descriptor */
  245. void __iomem *hw_desc; /* hardware descriptor */
  246. struct sk_buff *skb;
  247. dma_addr_t mapaddr;
  248. u32 maplen;
  249. };
  250. struct c2_ring {
  251. struct c2_element *to_clean;
  252. struct c2_element *to_use;
  253. struct c2_element *start;
  254. unsigned long count;
  255. };
  256. struct c2_dev {
  257. struct ib_device ibdev;
  258. void __iomem *regs;
  259. void __iomem *mmio_txp_ring; /* remapped adapter memory for hw rings */
  260. void __iomem *mmio_rxp_ring;
  261. spinlock_t lock;
  262. struct pci_dev *pcidev;
  263. struct net_device *netdev;
  264. struct net_device *pseudo_netdev;
  265. unsigned int cur_tx;
  266. unsigned int cur_rx;
  267. u32 adapter_handle;
  268. int device_cap_flags;
  269. void __iomem *kva; /* KVA device memory */
  270. unsigned long pa; /* PA device memory */
  271. void **qptr_array;
  272. struct kmem_cache *host_msg_cache;
  273. struct list_head cca_link; /* adapter list */
  274. struct list_head eh_wakeup_list; /* event wakeup list */
  275. wait_queue_head_t req_vq_wo;
  276. /* Cached RNIC properties */
  277. struct ib_device_attr props;
  278. struct c2_pd_table pd_table;
  279. struct c2_qp_table qp_table;
  280. int ports; /* num of GigE ports */
  281. int devnum;
  282. spinlock_t vqlock; /* sync vbs req MQ */
  283. /* Verbs Queues */
  284. struct c2_mq req_vq; /* Verbs Request MQ */
  285. struct c2_mq rep_vq; /* Verbs Reply MQ */
  286. struct c2_mq aeq; /* Async Events MQ */
  287. /* Kernel client MQs */
  288. struct sp_chunk *kern_mqsp_pool;
  289. /* Device updates these values when posting messages to a host
  290. * target queue */
  291. u16 req_vq_shared;
  292. u16 rep_vq_shared;
  293. u16 aeq_shared;
  294. u16 irq_claimed;
  295. /*
  296. * Shared host target pages for user-accessible MQs.
  297. */
  298. int hthead; /* index of first free entry */
  299. void *htpages; /* kernel vaddr */
  300. int htlen; /* length of htpages memory */
  301. void *htuva; /* user mapped vaddr */
  302. spinlock_t htlock; /* serialize allocation */
  303. u64 adapter_hint_uva; /* access to the activity FIFO */
  304. // spinlock_t aeq_lock;
  305. // spinlock_t rnic_lock;
  306. __be16 *hint_count;
  307. dma_addr_t hint_count_dma;
  308. u16 hints_read;
  309. int init; /* TRUE if it's ready */
  310. char ae_cache_name[16];
  311. char vq_cache_name[16];
  312. };
  313. struct c2_port {
  314. u32 msg_enable;
  315. struct c2_dev *c2dev;
  316. struct net_device *netdev;
  317. spinlock_t tx_lock;
  318. u32 tx_avail;
  319. struct c2_ring tx_ring;
  320. struct c2_ring rx_ring;
  321. void *mem; /* PCI memory for host rings */
  322. dma_addr_t dma;
  323. unsigned long mem_size;
  324. u32 rx_buf_size;
  325. };
  326. /*
  327. * Activity FIFO registers in BAR0.
  328. */
  329. #define PCI_BAR0_HOST_HINT 0x100
  330. #define PCI_BAR0_ADAPTER_HINT 0x2000
  331. /*
  332. * Ammasso PCI vendor id and Cepheus PCI device id.
  333. */
  334. #define CQ_ARMED 0x01
  335. #define CQ_WAIT_FOR_DMA 0x80
  336. /*
  337. * The format of a hint is as follows:
  338. * Lower 16 bits are the count of hints for the queue.
  339. * Next 15 bits are the qp_index
  340. * Upper most bit depends on who reads it:
  341. * If read by producer, then it means Full (1) or Not-Full (0)
  342. * If read by consumer, then it means Empty (1) or Not-Empty (0)
  343. */
  344. #define C2_HINT_MAKE(q_index, hint_count) (((q_index) << 16) | hint_count)
  345. #define C2_HINT_GET_INDEX(hint) (((hint) & 0x7FFF0000) >> 16)
  346. #define C2_HINT_GET_COUNT(hint) ((hint) & 0x0000FFFF)
  347. /*
  348. * The following defines the offset in SDRAM for the c2_adapter_pci_regs_t
  349. * struct.
  350. */
  351. #define C2_ADAPTER_PCI_REGS_OFFSET 0x10000
  352. #ifndef readq
  353. static inline u64 readq(const void __iomem * addr)
  354. {
  355. u64 ret = readl(addr + 4);
  356. ret <<= 32;
  357. ret |= readl(addr);
  358. return ret;
  359. }
  360. #endif
  361. #ifndef writeq
  362. static inline void __raw_writeq(u64 val, void __iomem * addr)
  363. {
  364. __raw_writel((u32) (val), addr);
  365. __raw_writel((u32) (val >> 32), (addr + 4));
  366. }
  367. #endif
  368. #define C2_SET_CUR_RX(c2dev, cur_rx) \
  369. __raw_writel((__force u32) cpu_to_be32(cur_rx), c2dev->mmio_txp_ring + 4092)
  370. #define C2_GET_CUR_RX(c2dev) \
  371. be32_to_cpu((__force __be32) readl(c2dev->mmio_txp_ring + 4092))
  372. static inline struct c2_dev *to_c2dev(struct ib_device *ibdev)
  373. {
  374. return container_of(ibdev, struct c2_dev, ibdev);
  375. }
  376. static inline int c2_errno(void *reply)
  377. {
  378. switch (c2_wr_get_result(reply)) {
  379. case C2_OK:
  380. return 0;
  381. case CCERR_NO_BUFS:
  382. case CCERR_INSUFFICIENT_RESOURCES:
  383. case CCERR_ZERO_RDMA_READ_RESOURCES:
  384. return -ENOMEM;
  385. case CCERR_MR_IN_USE:
  386. case CCERR_QP_IN_USE:
  387. return -EBUSY;
  388. case CCERR_ADDR_IN_USE:
  389. return -EADDRINUSE;
  390. case CCERR_ADDR_NOT_AVAIL:
  391. return -EADDRNOTAVAIL;
  392. case CCERR_CONN_RESET:
  393. return -ECONNRESET;
  394. case CCERR_NOT_IMPLEMENTED:
  395. case CCERR_INVALID_WQE:
  396. return -ENOSYS;
  397. case CCERR_QP_NOT_PRIVILEGED:
  398. return -EPERM;
  399. case CCERR_STACK_ERROR:
  400. return -EPROTO;
  401. case CCERR_ACCESS_VIOLATION:
  402. case CCERR_BASE_AND_BOUNDS_VIOLATION:
  403. return -EFAULT;
  404. case CCERR_STAG_STATE_NOT_INVALID:
  405. case CCERR_INVALID_ADDRESS:
  406. case CCERR_INVALID_CQ:
  407. case CCERR_INVALID_EP:
  408. case CCERR_INVALID_MODIFIER:
  409. case CCERR_INVALID_MTU:
  410. case CCERR_INVALID_PD_ID:
  411. case CCERR_INVALID_QP:
  412. case CCERR_INVALID_RNIC:
  413. case CCERR_INVALID_STAG:
  414. return -EINVAL;
  415. default:
  416. return -EAGAIN;
  417. }
  418. }
  419. /* Device */
  420. extern int c2_register_device(struct c2_dev *c2dev);
  421. extern void c2_unregister_device(struct c2_dev *c2dev);
  422. extern int c2_rnic_init(struct c2_dev *c2dev);
  423. extern void c2_rnic_term(struct c2_dev *c2dev);
  424. extern void c2_rnic_interrupt(struct c2_dev *c2dev);
  425. extern int c2_del_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask);
  426. extern int c2_add_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask);
  427. /* QPs */
  428. extern int c2_alloc_qp(struct c2_dev *c2dev, struct c2_pd *pd,
  429. struct ib_qp_init_attr *qp_attrs, struct c2_qp *qp);
  430. extern void c2_free_qp(struct c2_dev *c2dev, struct c2_qp *qp);
  431. extern struct ib_qp *c2_get_qp(struct ib_device *device, int qpn);
  432. extern int c2_qp_modify(struct c2_dev *c2dev, struct c2_qp *qp,
  433. struct ib_qp_attr *attr, int attr_mask);
  434. extern int c2_qp_set_read_limits(struct c2_dev *c2dev, struct c2_qp *qp,
  435. int ord, int ird);
  436. extern int c2_post_send(struct ib_qp *ibqp, struct ib_send_wr *ib_wr,
  437. struct ib_send_wr **bad_wr);
  438. extern int c2_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *ib_wr,
  439. struct ib_recv_wr **bad_wr);
  440. extern void __devinit c2_init_qp_table(struct c2_dev *c2dev);
  441. extern void __devexit c2_cleanup_qp_table(struct c2_dev *c2dev);
  442. extern void c2_set_qp_state(struct c2_qp *, int);
  443. extern struct c2_qp *c2_find_qpn(struct c2_dev *c2dev, int qpn);
  444. /* PDs */
  445. extern int c2_pd_alloc(struct c2_dev *c2dev, int privileged, struct c2_pd *pd);
  446. extern void c2_pd_free(struct c2_dev *c2dev, struct c2_pd *pd);
  447. extern int __devinit c2_init_pd_table(struct c2_dev *c2dev);
  448. extern void __devexit c2_cleanup_pd_table(struct c2_dev *c2dev);
  449. /* CQs */
  450. extern int c2_init_cq(struct c2_dev *c2dev, int entries,
  451. struct c2_ucontext *ctx, struct c2_cq *cq);
  452. extern void c2_free_cq(struct c2_dev *c2dev, struct c2_cq *cq);
  453. extern void c2_cq_event(struct c2_dev *c2dev, u32 mq_index);
  454. extern void c2_cq_clean(struct c2_dev *c2dev, struct c2_qp *qp, u32 mq_index);
  455. extern int c2_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
  456. extern int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
  457. /* CM */
  458. extern int c2_llp_connect(struct iw_cm_id *cm_id,
  459. struct iw_cm_conn_param *iw_param);
  460. extern int c2_llp_accept(struct iw_cm_id *cm_id,
  461. struct iw_cm_conn_param *iw_param);
  462. extern int c2_llp_reject(struct iw_cm_id *cm_id, const void *pdata,
  463. u8 pdata_len);
  464. extern int c2_llp_service_create(struct iw_cm_id *cm_id, int backlog);
  465. extern int c2_llp_service_destroy(struct iw_cm_id *cm_id);
  466. /* MM */
  467. extern int c2_nsmr_register_phys_kern(struct c2_dev *c2dev, u64 *addr_list,
  468. int page_size, int pbl_depth, u32 length,
  469. u32 off, u64 *va, enum c2_acf acf,
  470. struct c2_mr *mr);
  471. extern int c2_stag_dealloc(struct c2_dev *c2dev, u32 stag_index);
  472. /* AE */
  473. extern void c2_ae_event(struct c2_dev *c2dev, u32 mq_index);
  474. /* MQSP Allocator */
  475. extern int c2_init_mqsp_pool(struct c2_dev *c2dev, gfp_t gfp_mask,
  476. struct sp_chunk **root);
  477. extern void c2_free_mqsp_pool(struct c2_dev *c2dev, struct sp_chunk *root);
  478. extern __be16 *c2_alloc_mqsp(struct c2_dev *c2dev, struct sp_chunk *head,
  479. dma_addr_t *dma_addr, gfp_t gfp_mask);
  480. extern void c2_free_mqsp(__be16* mqsp);
  481. #endif