2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems. All rights reserved.
5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7 * Copyright (c) 2006 SilverStorm Technologies, Inc. All rights reserved.
9 * This software is available to you under a choice of one of two
10 * licenses. You may choose to be licensed under the terms of the GNU
11 * General Public License (GPL) Version 2, available from the file
12 * COPYING in the main directory of this source tree, or the
13 * OpenIB.org BSD license below:
15 * Redistribution and use in source and binary forms, with or
16 * without modification, are permitted provided that the following
19 * - Redistributions of source code must retain the above
20 * copyright notice, this list of conditions and the following
23 * - Redistributions in binary form must reproduce the above
24 * copyright notice, this list of conditions and the following
25 * disclaimer in the documentation and/or other materials
26 * provided with the distribution.
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 * $Id: mthca_dev.h 3047 2005-08-10 03:59:35Z roland $
43 #include "hca_driver.h"
44 #include "mthca_log.h"
45 #include "mthca_provider.h"
46 #include "mthca_doorbell.h"
48 // must be synchronized with MTHCA.INF
49 #define DRV_NAME "mthca"
50 #define PFX DRV_NAME ": "
51 #define DRV_VERSION "1.0.0000.331"
52 #define DRV_RELDATE "04/26/2006"
54 #define HZ 1000000 /* 1 sec in usecs */
57 MTHCA_FLAG_DDR_HIDDEN = 1 << 1,
58 MTHCA_FLAG_SRQ = 1 << 2,
59 MTHCA_FLAG_MSI = 1 << 3,
60 MTHCA_FLAG_MSI_X = 1 << 4,
61 MTHCA_FLAG_NO_LAM = 1 << 5,
62 MTHCA_FLAG_FMR = 1 << 6,
63 MTHCA_FLAG_MEMFREE = 1 << 7,
64 MTHCA_FLAG_PCIE = 1 << 8
72 MTHCA_BOARD_ID_LEN = 64
76 MTHCA_EQ_CONTEXT_SIZE = 0x40,
77 MTHCA_CQ_CONTEXT_SIZE = 0x40,
78 MTHCA_QP_CONTEXT_SIZE = 0x200,
79 MTHCA_RDB_ENTRY_SIZE = 0x20,
81 MTHCA_MGM_ENTRY_SIZE = 0x40,
83 /* Arbel FW gives us these, but we need them for Tavor */
84 MTHCA_MPT_ENTRY_SIZE = 0x40,
85 MTHCA_MTT_SEG_SIZE = 0x40,
87 MTHCA_QP_PER_MGM = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2)
98 MTHCA_OPCODE_NOP = 0x00,
99 MTHCA_OPCODE_RDMA_WRITE = 0x08,
100 MTHCA_OPCODE_RDMA_WRITE_IMM = 0x09,
101 MTHCA_OPCODE_SEND = 0x0a,
102 MTHCA_OPCODE_SEND_IMM = 0x0b,
103 MTHCA_OPCODE_RDMA_READ = 0x10,
104 MTHCA_OPCODE_ATOMIC_CS = 0x11,
105 MTHCA_OPCODE_ATOMIC_FA = 0x12,
106 MTHCA_OPCODE_BIND_MW = 0x18,
107 MTHCA_OPCODE_INVALID = 0xff
111 struct pci_pool *pool;
115 KSEMAPHORE event_sem;
117 spinlock_t context_lock;
119 struct mthca_cmd_context *context;
123 struct mthca_limits {
129 int local_ca_ack_delay;
135 int max_qp_init_rdma;
149 int fmr_reserved_mtts;
169 unsigned long *table;
179 struct mthca_uar_table {
180 struct mthca_alloc alloc;
185 struct mthca_pd_table {
186 struct mthca_alloc alloc;
190 unsigned long **bits;
195 struct mthca_mr_table {
196 struct mthca_alloc mpt_alloc;
197 struct mthca_buddy mtt_buddy;
198 struct mthca_buddy *fmr_mtt_buddy;
201 struct mthca_icm_table *mtt_table;
202 struct mthca_icm_table *mpt_table;
204 void __iomem *mpt_base;
205 SIZE_T mpt_base_size;
206 void __iomem *mtt_base;
207 SIZE_T mtt_base_size;
208 struct mthca_buddy mtt_buddy;
212 struct mthca_eq_table {
213 struct mthca_alloc alloc;
214 void __iomem *clr_int;
217 struct mthca_eq eq[MTHCA_NUM_EQ];
219 struct scatterlist sg;
222 KLOCK_QUEUE_HANDLE lockh;
225 struct mthca_cq_table {
226 struct mthca_alloc alloc;
228 struct mthca_array cq;
229 struct mthca_icm_table *table;
232 struct mthca_srq_table {
233 struct mthca_alloc alloc;
235 struct mthca_array srq;
236 struct mthca_icm_table *table;
239 struct mthca_qp_table {
240 struct mthca_alloc alloc;
245 struct mthca_array qp;
246 struct mthca_icm_table *qp_table;
247 struct mthca_icm_table *eqp_table;
248 struct mthca_icm_table *rdb_table;
251 struct mthca_av_table {
252 struct pci_pool *pool;
255 void __iomem *av_map;
257 struct mthca_alloc alloc;
260 struct mthca_mcg_table {
262 struct mthca_alloc alloc;
263 struct mthca_icm_table *table;
266 struct mthca_catas_err {
274 LARGE_INTEGER interval;
278 struct ib_device ib_dev;
282 unsigned long mthca_flags;
283 unsigned long device_cap_flags;
286 char board_id[MTHCA_BOARD_ID_LEN];
299 struct mthca_icm *fw_icm;
300 struct mthca_icm *aux_icm;
308 MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)
309 KMUTEX cap_mask_mutex;
315 u8 __iomem *clr_base;
316 SIZE_T clr_base_size;
319 void __iomem *ecr_base;
320 SIZE_T ecr_base_size;
323 void __iomem *eq_arm;
325 void __iomem *eq_set_ci_base;
326 SIZE_T eq_set_ci_base_size;
330 struct mthca_cmd cmd;
331 struct mthca_limits limits;
333 struct mthca_uar_table uar_table;
334 struct mthca_pd_table pd_table;
335 struct mthca_mr_table mr_table;
336 struct mthca_eq_table eq_table;
337 struct mthca_cq_table cq_table;
338 struct mthca_srq_table srq_table;
339 struct mthca_qp_table qp_table;
340 struct mthca_av_table av_table;
341 struct mthca_mcg_table mcg_table;
342 struct mthca_catas_err catas_err;
343 struct mthca_uar driver_uar;
344 struct mthca_db_table *db_tab;
345 struct mthca_pd driver_pd;
346 struct mthca_mr driver_mr;
348 struct ib_mad_agent *send_agent[MTHCA_MAX_PORTS][2];
349 struct ib_ah *sm_ah[MTHCA_MAX_PORTS];
356 MTHCA_DEV_UNINITIALIZED,
357 MTHCA_DEV_INITIALIZED,
362 MTHCA_CQ_ENTRY_SIZE = 0x20
367 #define MTHCA_GET(dest, source, offset) \
369 void *__p = (char *) (source) + (offset); \
370 void *__q = &(dest); \
371 switch (sizeof (dest)) { \
372 case 1: *(u8 *)__q = *(u8 *) __p; break; \
373 case 2: *(u16 *)__q = (u16)cl_ntoh16(*(u16 *)__p); break; \
374 case 4: *(u32 *)__q = (u32)cl_ntoh32(*(u32 *)__p); break; \
375 case 8: *(u64 *)__q = (u64)cl_ntoh64(*(u64 *)__p); break; \
376 default: ASSERT(0); \
381 #define MTHCA_PUT(dest, source, offset) \
383 void *__d = ((char *) (dest) + (offset)); \
384 switch (sizeof(source)) { \
385 case 1: *(u8 *) __d = (u8)(source); break; \
386 case 2: *(__be16 *) __d = cl_hton16((u16)source); break; \
387 case 4: *(__be32 *) __d = cl_hton32((u32)source); break; \
388 case 8: *(__be64 *) __d = cl_hton64((u64)source); break; \
389 default: ASSERT(0); \
393 NTSTATUS mthca_reset(struct mthca_dev *mdev);
395 u32 mthca_alloc(struct mthca_alloc *alloc);
396 void mthca_free(struct mthca_alloc *alloc, u32 obj);
397 int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
399 void mthca_alloc_cleanup(struct mthca_alloc *alloc);
400 void *mthca_array_get(struct mthca_array *array, int index);
401 int mthca_array_set(struct mthca_array *array, int index, void *value);
402 void mthca_array_clear(struct mthca_array *array, int index);
403 int mthca_array_init(struct mthca_array *array, int nent);
404 void mthca_array_cleanup(struct mthca_array *array, int nent);
405 int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,
406 union mthca_buf *buf, int *is_direct, struct mthca_pd *pd,
407 int hca_write, struct mthca_mr *mr);
408 void mthca_buf_free(struct mthca_dev *dev, int size, union mthca_buf *buf,
409 int is_direct, struct mthca_mr *mr);
411 int mthca_init_uar_table(struct mthca_dev *dev);
412 int mthca_init_pd_table(struct mthca_dev *dev);
413 int mthca_init_mr_table(struct mthca_dev *dev);
414 int mthca_init_eq_table(struct mthca_dev *dev);
415 int mthca_init_cq_table(struct mthca_dev *dev);
416 int mthca_init_srq_table(struct mthca_dev *dev);
417 int mthca_init_qp_table(struct mthca_dev *dev);
418 int mthca_init_av_table(struct mthca_dev *dev);
419 int mthca_init_mcg_table(struct mthca_dev *dev);
421 void mthca_cleanup_uar_table(struct mthca_dev *dev);
422 void mthca_cleanup_pd_table(struct mthca_dev *dev);
423 void mthca_cleanup_mr_table(struct mthca_dev *dev);
424 void mthca_cleanup_eq_table(struct mthca_dev *dev);
425 void mthca_cleanup_cq_table(struct mthca_dev *dev);
426 void mthca_cleanup_srq_table(struct mthca_dev *dev);
427 void mthca_cleanup_qp_table(struct mthca_dev *dev);
428 void mthca_cleanup_av_table(struct mthca_dev *dev);
429 void mthca_cleanup_mcg_table(struct mthca_dev *dev);
431 int mthca_register_device(struct mthca_dev *dev);
432 void mthca_unregister_device(struct mthca_dev *dev);
434 void mthca_start_catas_poll(struct mthca_dev *dev);
435 void mthca_stop_catas_poll(struct mthca_dev *dev);
437 int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar);
438 void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);
440 int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd);
441 void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);
443 struct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size);
444 void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt);
445 int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
446 int start_index, u64 *buffer_list, int list_len);
447 int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
448 u64 iova, u64 total_size, mthca_mpt_access_t access, struct mthca_mr *mr);
449 int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
450 mthca_mpt_access_t access, struct mthca_mr *mr);
451 int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
452 u64 *buffer_list, int buffer_size_shift,
453 int list_len, u64 iova, u64 total_size,
454 mthca_mpt_access_t access, struct mthca_mr *mr);
455 void mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr);
457 int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
458 mthca_mpt_access_t access, struct mthca_fmr *fmr);
459 int mthca_tavor_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
460 int list_len, u64 iova);
461 void mthca_tavor_fmr_unmap(struct mthca_dev *dev, struct mthca_fmr *fmr);
462 int mthca_arbel_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
463 int list_len, u64 iova);
464 void mthca_arbel_fmr_unmap(struct mthca_dev *dev, struct mthca_fmr *fmr);
465 int mthca_free_fmr(struct mthca_dev *dev, struct mthca_fmr *fmr);
467 int mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt);
468 void mthca_unmap_eq_icm(struct mthca_dev *dev);
470 int mthca_poll_cq(struct ib_cq *ibcq, int num_entries,
471 struct _ib_wc *entry);
472 int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify);
473 int mthca_arbel_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify);
474 int mthca_init_cq(struct mthca_dev *dev, int nent,
475 struct mthca_ucontext *ctx, u32 pdn,
476 struct mthca_cq *cq);
477 void mthca_free_cq(struct mthca_dev *dev,
478 struct mthca_cq *cq);
479 void mthca_cq_completion(struct mthca_dev *dev, u32 cqn);
480 void mthca_cq_event(struct mthca_dev *dev, u32 cqn,
481 enum ib_event_type event_type);
482 void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,
483 struct mthca_srq *srq);
485 int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
486 struct ib_srq_attr *attr, struct mthca_srq *srq);
487 void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);
488 int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
489 enum ib_srq_attr_mask attr_mask);
490 void mthca_srq_event(struct mthca_dev *dev, u32 srqn,
491 enum ib_event_type event_type);
492 void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);
493 int mthca_tavor_post_srq_recv(struct ib_srq *srq, struct _ib_recv_wr *wr,
494 struct _ib_recv_wr **bad_wr);
495 int mthca_arbel_post_srq_recv(struct ib_srq *srq, struct _ib_recv_wr *wr,
496 struct _ib_recv_wr **bad_wr);
498 void mthca_qp_event(struct mthca_dev *dev, u32 qpn,
499 enum ib_event_type event_type);
500 int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask);
501 int mthca_tavor_post_send(struct ib_qp *ibqp, struct _ib_send_wr *wr,
502 struct _ib_send_wr **bad_wr);
503 int mthca_tavor_post_receive(struct ib_qp *ibqp, struct _ib_recv_wr *wr,
504 struct _ib_recv_wr **bad_wr);
505 int mthca_arbel_post_send(struct ib_qp *ibqp, struct _ib_send_wr *wr,
506 struct _ib_send_wr **bad_wr);
507 int mthca_arbel_post_receive(struct ib_qp *ibqp, struct _ib_recv_wr *wr,
508 struct _ib_recv_wr **bad_wr);
509 void mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
510 int index, int *dbd, __be32 *new_wqe);
511 int mthca_alloc_qp(struct mthca_dev *dev,
513 struct mthca_cq *send_cq,
514 struct mthca_cq *recv_cq,
515 enum ib_qp_type_t type,
516 enum ib_sig_type send_policy,
517 struct ib_qp_cap *cap,
518 struct mthca_qp *qp);
519 int mthca_alloc_sqp(struct mthca_dev *dev,
521 struct mthca_cq *send_cq,
522 struct mthca_cq *recv_cq,
523 enum ib_sig_type send_policy,
524 struct ib_qp_cap *cap,
527 struct mthca_sqp *sqp);
528 void mthca_free_qp(struct mthca_dev *dev, struct mthca_qp *qp);
529 int mthca_create_ah(struct mthca_dev *dev,
531 struct ib_ah_attr *ah_attr,
532 struct mthca_ah *ah);
533 int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah);
534 int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
535 struct ib_ud_header *header);
537 int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
538 int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
540 int mthca_process_mad(struct ib_device *ibdev,
543 struct _ib_wc *in_wc,
544 struct ib_grh *in_grh,
545 struct ib_mad *in_mad,
546 struct ib_mad *out_mad);
548 static inline struct mthca_dev *to_mdev(struct ib_device *ibdev)
550 return container_of(ibdev, struct mthca_dev, ib_dev);
553 static inline int mthca_is_memfree(struct mthca_dev *dev)
555 return dev->mthca_flags & MTHCA_FLAG_MEMFREE;
558 void mthca_get_av_params( struct mthca_ah *ah_p, u8 *port_num, __be16 *dlid, u8 *sr, u8 *path_bits );
560 void mthca_set_av_params( struct mthca_dev *dev, struct mthca_ah *ah_p, struct ib_ah_attr *ah_attr );
562 int ib_uverbs_init(void);
563 void ib_uverbs_cleanup(void);
564 int mthca_ah_grh_present(struct mthca_ah *ah);
574 ULONG pi_UniqueErrorCode,
575 ULONG pi_FinalStatus,
581 WriteEventLogEntryStr(
584 ULONG pi_UniqueErrorCode,
585 ULONG pi_FinalStatus,
586 PWCHAR pi_InsertionStr,
591 #endif /* MTHCA_DEV_H */