43 #ifdef CONFIG_PPC_64K_PAGES
44 #include <linux/slab.h>
55 #define HCAD_VERSION "0029"
62 static bool ehca_open_aqp1 = 0;
63 static int ehca_hw_level = 0;
64 static bool ehca_poll_all_eqs = 1;
90 "Open AQP1 on startup (default: no)");
92 "Amount of debug output (0: none (default), 1: traces, "
93 "2: some dumps, 3: lots)");
95 "Hardware level (0: autosensing (default), "
96 "0x10..0x14: eHCA, 0x20..0x23: eHCA2)");
98 "number of connected ports (-1: autodetect (default), "
99 "1: port one only, 2: two ports)");
101 "Use high performance MRs (default: no)");
103 "Time to wait for port activation (default: 30 sec)");
105 "Poll all event queues periodically (default: yes)");
107 "Set permanent static rate (default: no static rate)");
109 "Enable scaling code (default: no)");
111 "Serialize all hCalls made by the driver "
112 "(default: autodetect)");
114 "Max number of CQs which can be allocated "
115 "(default: autodetect)");
117 "Max number of QPs which can be allocated "
118 "(default: autodetect)");
130 #ifdef CONFIG_PPC_64K_PAGES
135 void *
ret = kmem_cache_zalloc(ctblk_cache, flags);
157 case H_NOT_ENOUGH_RESOURCES:
166 static int ehca_create_slab_caches(
void)
179 goto create_slab_caches2;
185 goto create_slab_caches3;
191 goto create_slab_caches4;
197 goto create_slab_caches5;
203 goto create_slab_caches6;
206 #ifdef CONFIG_PPC_64K_PAGES
214 goto create_slab_caches6;
237 static void ehca_destroy_slab_caches(
void)
245 #ifdef CONFIG_PPC_64K_PAGES
251 #define EHCA_HCAAVER EHCA_BMASK_IBM(32, 39)
252 #define EHCA_REVID EHCA_BMASK_IBM(40, 63)
254 static struct cap_descr {
257 } hca_cap_descr[] = {
278 static int ehca_sense_attributes(
struct ehca_shca *shca)
284 const char *loc_code;
286 static const u32 pgsize_map[] = {
294 shca->
ofdev->dev.of_node->full_name);
307 if (h_ret != H_SUCCESS) {
308 ehca_gen_err(
"Cannot query device properties. h_ret=%lli",
311 goto sense_attributes1;
321 if (ehca_hw_level == 0) {
328 ehca_gen_dbg(
" ... hardware version=%x:%x", hcaaver, revid);
332 shca->
hw_level = 0x10 | (revid + 1);
335 }
else if (hcaaver == 2) {
338 else if (revid == 0x10)
340 else if (revid == 0x20 || revid == 0x21)
346 " - assuming default level");
355 for (i = 0; i <
ARRAY_SIZE(hca_cap_descr); i++)
368 for (i = 0; i <
ARRAY_SIZE(pgsize_map); i += 2)
378 "(1 - %i) specified by HW. Value is set to %i",
388 "(1 - %i) specified by HW. Value is set to %i",
395 if (h_ret != H_SUCCESS) {
396 ehca_gen_err(
"Cannot query port properties. h_ret=%lli",
399 goto sense_attributes1;
409 static int init_node_guid(
struct ehca_shca *shca)
423 goto init_node_guid1;
433 static int ehca_init_device(
struct ehca_shca *shca)
437 ret = init_node_guid(shca);
530 static int ehca_create_aqp1(
struct ehca_shca *shca,
u32 port)
546 return PTR_ERR(ibcq);
557 qp_init_attr.send_cq = ibcq;
558 qp_init_attr.recv_cq = ibcq;
560 qp_init_attr.cap.max_send_wr = 100;
561 qp_init_attr.cap.max_recv_wr = 100;
562 qp_init_attr.cap.max_send_sge = 2;
563 qp_init_attr.cap.max_recv_sge = 1;
565 qp_init_attr.port_num =
port;
566 qp_init_attr.qp_context =
NULL;
567 qp_init_attr.event_handler =
NULL;
568 qp_init_attr.srq =
NULL;
585 static int ehca_destroy_aqp1(
struct ehca_sport *sport)
610 int value = (*buf) -
'0';
611 if (value >= 0 && value <= 9)
617 ehca_show_debug_level, ehca_store_debug_level);
619 static struct attribute *ehca_drv_attrs[] = {
620 &driver_attr_debug_level.attr,
625 .attrs = ehca_drv_attrs
633 #define EHCA_RESOURCE_ATTR(name) \
634 static ssize_t ehca_show_##name(struct device *dev, \
635 struct device_attribute *attr, \
638 struct ehca_shca *shca; \
639 struct hipz_query_hca *rblock; \
642 shca = dev_get_drvdata(dev); \
644 rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \
646 dev_err(dev, "Can't allocate rblock memory.\n"); \
650 if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \
651 dev_err(dev, "Can't query device properties\n"); \
652 ehca_free_fw_ctrlblock(rblock); \
656 data = rblock->name; \
657 ehca_free_fw_ctrlblock(rblock); \
659 if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \
660 return snprintf(buf, 256, "1\n"); \
662 return snprintf(buf, 256, "%d\n", data); \
665 static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL);
693 static struct attribute *ehca_dev_attrs[] = {
694 &dev_attr_adapter_handle.attr,
695 &dev_attr_num_ports.attr,
696 &dev_attr_hw_ver.attr,
697 &dev_attr_max_eq.attr,
698 &dev_attr_cur_eq.attr,
699 &dev_attr_max_cq.attr,
700 &dev_attr_cur_cq.attr,
701 &dev_attr_max_qp.attr,
702 &dev_attr_cur_qp.attr,
703 &dev_attr_max_mr.attr,
704 &dev_attr_cur_mr.attr,
705 &dev_attr_max_mw.attr,
706 &dev_attr_cur_mw.attr,
707 &dev_attr_max_pd.attr,
708 &dev_attr_max_ah.attr,
713 .attrs = ehca_dev_attrs
728 dev->
dev.of_node->full_name);
734 dev->
dev.of_node->full_name);
757 ret = ehca_sense_attributes(shca);
763 ret = ehca_init_device(shca);
806 "ib_register_device() failed ret=%i", ret);
811 if (ehca_open_aqp1 == 1) {
813 ret = ehca_create_aqp1(shca, 1);
816 "Cannot create AQP1 for port 1.");
822 if ((ehca_open_aqp1 == 1) && (shca->
num_ports == 2)) {
824 ret = ehca_create_aqp1(shca, 2);
827 "Cannot create AQP1 for port 2.");
835 "Cannot create device attributes ret=%d", ret);
839 spin_unlock_irqrestore(&shca_list_lock, flags);
844 ret = ehca_destroy_aqp1(&shca->
sport[0]);
847 "Cannot destroy AQP1 for port 1. ret=%i", ret);
856 "Cannot destroy internal MR. ret=%x", ret);
862 "Cannot destroy internal PD. ret=%x", ret);
868 "Cannot destroy NEQ. ret=%x", ret);
874 "Cannot destroy EQ. ret=%x", ret);
890 if (ehca_open_aqp1 == 1) {
893 ret = ehca_destroy_aqp1(&shca->
sport[i]);
896 "Cannot destroy AQP1 for port %x "
906 "Cannot destroy internal MR. ret=%i", ret);
911 "Cannot destroy internal PD. ret=%i", ret);
925 spin_unlock_irqrestore(&shca_list_lock, flags);
934 .compatible =
"IBM,lhca",
940 static struct of_platform_driver ehca_driver = {
942 .remove = ehca_remove,
946 .groups = ehca_drv_attr_groups,
947 .of_match_table = ehca_device_table,
957 if (shca->
eq.is_initialized) {
961 volatile u64 q_ofs, q_ofs2;
965 spin_unlock_irqrestore(&eq->
spinlock, flags);
969 spin_unlock_irqrestore(&eq->
spinlock, flags);
971 }
while (q_ofs == q_ofs2 && max > 0);
983 static unsigned long ehca_dmem_warn_time;
996 if (list_empty(&shca_list)) {
997 spin_unlock_irqrestore(&shca_list_lock, flags);
1000 spin_unlock_irqrestore(&shca_list_lock, flags);
1001 if (printk_timed_ratelimit(&ehca_dmem_warn_time,
1004 "in conjunction with eHCA");
1012 .notifier_call = ehca_mem_notifier,
1015 static int __init ehca_module_init(
void)
1028 ret = ehca_create_slab_caches();
1050 ehca_gen_err(
"Failed registering memory add/remove notifier");
1054 if (ehca_poll_all_eqs != 1) {
1073 ehca_destroy_slab_caches();
1080 static void __exit ehca_module_exit(
void)
1082 if (ehca_poll_all_eqs == 1)
1091 ehca_destroy_slab_caches();