2 * linux/drivers/net/ehea/ehea_main.c
4 * eHEA ethernet device driver for IBM eServer System p
6 * (C) Copyright IBM Corp. 2006
9 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <linux/tcp.h>
32 #include <linux/udp.h>
34 #include <linux/list.h>
35 #include <linux/if_ether.h>
36 #include <linux/notifier.h>
37 #include <linux/reboot.h>
38 #include <linux/memory.h>
39 #include <asm/kexec.h>
40 #include <linux/mutex.h>
46 #include "ehea_phyp.h"
49 MODULE_LICENSE("GPL");
50 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
51 MODULE_DESCRIPTION("IBM eServer HEA Driver");
52 MODULE_VERSION(DRV_VERSION);
55 static int msg_level = -1;
56 static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
57 static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
58 static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
59 static int sq_entries = EHEA_DEF_ENTRIES_SQ;
62 static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
63 static int num_tx_qps = EHEA_NUM_TX_QP;
64 static int prop_carrier_state;
66 module_param(msg_level, int, 0);
67 module_param(rq1_entries, int, 0);
68 module_param(rq2_entries, int, 0);
69 module_param(rq3_entries, int, 0);
70 module_param(sq_entries, int, 0);
71 module_param(prop_carrier_state, int, 0);
72 module_param(use_mcs, int, 0);
73 module_param(use_lro, int, 0);
74 module_param(lro_max_aggr, int, 0);
75 module_param(num_tx_qps, int, 0);
77 MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
78 MODULE_PARM_DESC(msg_level, "msg_level");
79 MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
80 "port to stack. 1:yes, 0:no. Default = 0 ");
81 MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
84 MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
87 MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
90 MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
91 "[2^x - 1], x = [6..14]. Default = "
92 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
93 MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
95 MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
96 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
97 MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
100 static int port_name_cnt;
101 static LIST_HEAD(adapter_list);
102 u64 ehea_driver_flags;
103 struct work_struct ehea_rereg_mr_task;
104 static DEFINE_MUTEX(dlpar_mem_lock);
105 struct ehea_fw_handle_array ehea_fw_handles;
106 struct ehea_bcmc_reg_array ehea_bcmc_regs;
109 static int __devinit ehea_probe_adapter(struct of_device *dev,
110 const struct of_device_id *id);
112 static int __devexit ehea_remove(struct of_device *dev);
114 static struct of_device_id ehea_device_table[] = {
117 .compatible = "IBM,lhea",
122 static struct of_platform_driver ehea_driver = {
124 .match_table = ehea_device_table,
125 .probe = ehea_probe_adapter,
126 .remove = ehea_remove,
129 void ehea_dump(void *adr, int len, char *msg)
132 unsigned char *deb = adr;
133 for (x = 0; x < len; x += 16) {
134 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
135 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
140 static void ehea_update_firmware_handles(void)
142 struct ehea_fw_handle_entry *arr = NULL;
143 struct ehea_adapter *adapter;
144 int num_adapters = 0;
148 int num_fw_handles, k, l;
150 /* Determine number of handles */
151 list_for_each_entry(adapter, &adapter_list, list) {
154 for (k = 0; k < EHEA_MAX_PORTS; k++) {
155 struct ehea_port *port = adapter->port[k];
157 if (!port || (port->state != EHEA_PORT_UP))
161 num_portres += port->num_def_qps + port->num_add_tx_qps;
165 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
166 num_ports * EHEA_NUM_PORT_FW_HANDLES +
167 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
169 if (num_fw_handles) {
170 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
172 return; /* Keep the existing array */
176 list_for_each_entry(adapter, &adapter_list, list) {
177 for (k = 0; k < EHEA_MAX_PORTS; k++) {
178 struct ehea_port *port = adapter->port[k];
180 if (!port || (port->state != EHEA_PORT_UP))
184 l < port->num_def_qps + port->num_add_tx_qps;
186 struct ehea_port_res *pr = &port->port_res[l];
188 arr[i].adh = adapter->handle;
189 arr[i++].fwh = pr->qp->fw_handle;
190 arr[i].adh = adapter->handle;
191 arr[i++].fwh = pr->send_cq->fw_handle;
192 arr[i].adh = adapter->handle;
193 arr[i++].fwh = pr->recv_cq->fw_handle;
194 arr[i].adh = adapter->handle;
195 arr[i++].fwh = pr->eq->fw_handle;
196 arr[i].adh = adapter->handle;
197 arr[i++].fwh = pr->send_mr.handle;
198 arr[i].adh = adapter->handle;
199 arr[i++].fwh = pr->recv_mr.handle;
201 arr[i].adh = adapter->handle;
202 arr[i++].fwh = port->qp_eq->fw_handle;
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = adapter->neq->fw_handle;
208 if (adapter->mr.handle) {
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = adapter->mr.handle;
215 kfree(ehea_fw_handles.arr);
216 ehea_fw_handles.arr = arr;
217 ehea_fw_handles.num_entries = i;
220 static void ehea_update_bcmc_registrations(void)
222 struct ehea_bcmc_reg_entry *arr = NULL;
223 struct ehea_adapter *adapter;
224 struct ehea_mc_list *mc_entry;
225 int num_registrations = 0;
229 /* Determine number of registrations */
230 list_for_each_entry(adapter, &adapter_list, list)
231 for (k = 0; k < EHEA_MAX_PORTS; k++) {
232 struct ehea_port *port = adapter->port[k];
234 if (!port || (port->state != EHEA_PORT_UP))
237 num_registrations += 2; /* Broadcast registrations */
239 list_for_each_entry(mc_entry, &port->mc_list->list,list)
240 num_registrations += 2;
243 if (num_registrations) {
244 arr = kzalloc(num_registrations * sizeof(*arr), GFP_KERNEL);
246 return; /* Keep the existing array */
250 list_for_each_entry(adapter, &adapter_list, list) {
251 for (k = 0; k < EHEA_MAX_PORTS; k++) {
252 struct ehea_port *port = adapter->port[k];
254 if (!port || (port->state != EHEA_PORT_UP))
257 arr[i].adh = adapter->handle;
258 arr[i].port_id = port->logical_port_id;
259 arr[i].reg_type = EHEA_BCMC_BROADCAST |
261 arr[i++].macaddr = port->mac_addr;
263 arr[i].adh = adapter->handle;
264 arr[i].port_id = port->logical_port_id;
265 arr[i].reg_type = EHEA_BCMC_BROADCAST |
266 EHEA_BCMC_VLANID_ALL;
267 arr[i++].macaddr = port->mac_addr;
269 list_for_each_entry(mc_entry,
270 &port->mc_list->list, list) {
271 arr[i].adh = adapter->handle;
272 arr[i].port_id = port->logical_port_id;
273 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
274 EHEA_BCMC_MULTICAST |
276 arr[i++].macaddr = mc_entry->macaddr;
278 arr[i].adh = adapter->handle;
279 arr[i].port_id = port->logical_port_id;
280 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
281 EHEA_BCMC_MULTICAST |
282 EHEA_BCMC_VLANID_ALL;
283 arr[i++].macaddr = mc_entry->macaddr;
289 kfree(ehea_bcmc_regs.arr);
290 ehea_bcmc_regs.arr = arr;
291 ehea_bcmc_regs.num_entries = i;
294 static struct net_device_stats *ehea_get_stats(struct net_device *dev)
296 struct ehea_port *port = netdev_priv(dev);
297 struct net_device_stats *stats = &port->stats;
298 struct hcp_ehea_port_cb2 *cb2;
299 u64 hret, rx_packets, tx_packets;
302 memset(stats, 0, sizeof(*stats));
304 cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL);
306 ehea_error("no mem for cb2");
310 hret = ehea_h_query_ehea_port(port->adapter->handle,
311 port->logical_port_id,
312 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
313 if (hret != H_SUCCESS) {
314 ehea_error("query_ehea_port failed");
318 if (netif_msg_hw(port))
319 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
322 for (i = 0; i < port->num_def_qps; i++)
323 rx_packets += port->port_res[i].rx_packets;
326 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
327 tx_packets += port->port_res[i].tx_packets;
329 stats->tx_packets = tx_packets;
330 stats->multicast = cb2->rxmcp;
331 stats->rx_errors = cb2->rxuerr;
332 stats->rx_bytes = cb2->rxo;
333 stats->tx_bytes = cb2->txo;
334 stats->rx_packets = rx_packets;
342 static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
344 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
345 struct net_device *dev = pr->port->netdev;
346 int max_index_mask = pr->rq1_skba.len - 1;
347 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
351 pr->rq1_skba.os_skbs = 0;
353 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
355 pr->rq1_skba.index = index;
356 pr->rq1_skba.os_skbs = fill_wqes;
360 for (i = 0; i < fill_wqes; i++) {
361 if (!skb_arr_rq1[index]) {
362 skb_arr_rq1[index] = netdev_alloc_skb(dev,
364 if (!skb_arr_rq1[index]) {
365 pr->rq1_skba.os_skbs = fill_wqes - i;
366 ehea_error("%s: no mem for skb/%d wqes filled",
372 index &= max_index_mask;
380 ehea_update_rq1a(pr->qp, adder);
383 static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
386 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
387 struct net_device *dev = pr->port->netdev;
390 for (i = 0; i < pr->rq1_skba.len; i++) {
391 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
392 if (!skb_arr_rq1[i]) {
393 ehea_error("%s: no mem for skb/%d wqes filled",
400 ehea_update_rq1a(pr->qp, nr_rq1a);
405 static int ehea_refill_rq_def(struct ehea_port_res *pr,
406 struct ehea_q_skb_arr *q_skba, int rq_nr,
407 int num_wqes, int wqe_type, int packet_size)
409 struct net_device *dev = pr->port->netdev;
410 struct ehea_qp *qp = pr->qp;
411 struct sk_buff **skb_arr = q_skba->arr;
412 struct ehea_rwqe *rwqe;
413 int i, index, max_index_mask, fill_wqes;
417 fill_wqes = q_skba->os_skbs + num_wqes;
420 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
421 q_skba->os_skbs = fill_wqes;
425 index = q_skba->index;
426 max_index_mask = q_skba->len - 1;
427 for (i = 0; i < fill_wqes; i++) {
429 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
431 ehea_error("%s: no mem for skb/%d wqes filled",
432 pr->port->netdev->name, i);
433 q_skba->os_skbs = fill_wqes - i;
437 skb_reserve(skb, NET_IP_ALIGN);
439 skb_arr[index] = skb;
440 tmp_addr = ehea_map_vaddr(skb->data);
441 if (tmp_addr == -1) {
443 q_skba->os_skbs = fill_wqes - i;
448 rwqe = ehea_get_next_rwqe(qp, rq_nr);
449 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
450 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
451 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
452 rwqe->sg_list[0].vaddr = tmp_addr;
453 rwqe->sg_list[0].len = packet_size;
454 rwqe->data_segments = 1;
457 index &= max_index_mask;
461 q_skba->index = index;
468 ehea_update_rq2a(pr->qp, adder);
470 ehea_update_rq3a(pr->qp, adder);
476 static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
478 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
479 nr_of_wqes, EHEA_RWQE2_TYPE,
480 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
484 static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
486 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
487 nr_of_wqes, EHEA_RWQE3_TYPE,
488 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
491 static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
493 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
494 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
496 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
497 (cqe->header_length == 0))
502 static inline void ehea_fill_skb(struct net_device *dev,
503 struct sk_buff *skb, struct ehea_cqe *cqe)
505 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
507 skb_put(skb, length);
508 skb->ip_summed = CHECKSUM_UNNECESSARY;
509 skb->protocol = eth_type_trans(skb, dev);
512 static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
514 struct ehea_cqe *cqe)
516 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
526 prefetchw(pref + EHEA_CACHE_LINE);
528 pref = (skb_array[x]->data);
530 prefetch(pref + EHEA_CACHE_LINE);
531 prefetch(pref + EHEA_CACHE_LINE * 2);
532 prefetch(pref + EHEA_CACHE_LINE * 3);
533 skb = skb_array[skb_index];
534 skb_array[skb_index] = NULL;
538 static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
539 int arr_len, int wqe_index)
550 prefetchw(pref + EHEA_CACHE_LINE);
552 pref = (skb_array[x]->data);
554 prefetchw(pref + EHEA_CACHE_LINE);
556 skb = skb_array[wqe_index];
557 skb_array[wqe_index] = NULL;
561 static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
562 struct ehea_cqe *cqe, int *processed_rq2,
567 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
568 pr->p_stats.err_tcp_cksum++;
569 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
570 pr->p_stats.err_ip_cksum++;
571 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
572 pr->p_stats.err_frame_crc++;
576 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
578 } else if (rq == 3) {
580 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
584 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
585 if (netif_msg_rx_err(pr->port)) {
586 ehea_error("Critical receive error for QP %d. "
587 "Resetting port.", pr->qp->init_attr.qp_nr);
588 ehea_dump(cqe, sizeof(*cqe), "CQE");
590 schedule_work(&pr->port->reset_task);
597 static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
598 void **tcph, u64 *hdr_flags, void *priv)
600 struct ehea_cqe *cqe = priv;
604 /* non tcp/udp packets */
605 if (!cqe->header_length)
609 skb_reset_network_header(skb);
611 if (iph->protocol != IPPROTO_TCP)
614 ip_len = ip_hdrlen(skb);
615 skb_set_transport_header(skb, ip_len);
616 *tcph = tcp_hdr(skb);
618 /* check if ip header and tcp header are complete */
619 if (iph->tot_len < ip_len + tcp_hdrlen(skb))
622 *hdr_flags = LRO_IPV4 | LRO_TCP;
628 static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
631 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
636 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
641 lro_receive_skb(&pr->lro_mgr, skb, cqe);
644 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
647 netif_receive_skb(skb);
651 static int ehea_proc_rwqes(struct net_device *dev,
652 struct ehea_port_res *pr,
655 struct ehea_port *port = pr->port;
656 struct ehea_qp *qp = pr->qp;
657 struct ehea_cqe *cqe;
659 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
660 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
661 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
662 int skb_arr_rq1_len = pr->rq1_skba.len;
663 int skb_arr_rq2_len = pr->rq2_skba.len;
664 int skb_arr_rq3_len = pr->rq3_skba.len;
665 int processed, processed_rq1, processed_rq2, processed_rq3;
666 int wqe_index, last_wqe_index, rq, port_reset;
668 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
671 cqe = ehea_poll_rq1(qp, &wqe_index);
672 while ((processed < budget) && cqe) {
676 if (netif_msg_rx_status(port))
677 ehea_dump(cqe, sizeof(*cqe), "CQE");
679 last_wqe_index = wqe_index;
681 if (!ehea_check_cqe(cqe, &rq)) {
684 skb = get_skb_by_index_ll(skb_arr_rq1,
687 if (unlikely(!skb)) {
688 if (netif_msg_rx_err(port))
689 ehea_error("LL rq1: skb=NULL");
691 skb = netdev_alloc_skb(dev,
696 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
697 cqe->num_bytes_transfered - 4);
698 ehea_fill_skb(dev, skb, cqe);
699 } else if (rq == 2) {
701 skb = get_skb_by_index(skb_arr_rq2,
702 skb_arr_rq2_len, cqe);
703 if (unlikely(!skb)) {
704 if (netif_msg_rx_err(port))
705 ehea_error("rq2: skb=NULL");
708 ehea_fill_skb(dev, skb, cqe);
712 skb = get_skb_by_index(skb_arr_rq3,
713 skb_arr_rq3_len, cqe);
714 if (unlikely(!skb)) {
715 if (netif_msg_rx_err(port))
716 ehea_error("rq3: skb=NULL");
719 ehea_fill_skb(dev, skb, cqe);
723 ehea_proc_skb(pr, cqe, skb);
724 dev->last_rx = jiffies;
726 pr->p_stats.poll_receive_errors++;
727 port_reset = ehea_treat_poll_error(pr, rq, cqe,
733 cqe = ehea_poll_rq1(qp, &wqe_index);
736 lro_flush_all(&pr->lro_mgr);
738 pr->rx_packets += processed;
740 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
741 ehea_refill_rq2(pr, processed_rq2);
742 ehea_refill_rq3(pr, processed_rq3);
747 static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
750 struct ehea_cq *send_cq = pr->send_cq;
751 struct ehea_cqe *cqe;
752 int quota = my_quota;
758 cqe = ehea_poll_cq(send_cq);
759 while (cqe && (quota > 0)) {
760 ehea_inc_cq(send_cq);
764 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
765 ehea_error("Send Completion Error: Resetting port");
766 if (netif_msg_tx_err(pr->port))
767 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
768 schedule_work(&pr->port->reset_task);
772 if (netif_msg_tx_done(pr->port))
773 ehea_dump(cqe, sizeof(*cqe), "CQE");
775 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
776 == EHEA_SWQE2_TYPE)) {
778 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
779 skb = pr->sq_skba.arr[index];
781 pr->sq_skba.arr[index] = NULL;
784 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
787 cqe = ehea_poll_cq(send_cq);
790 ehea_update_feca(send_cq, cqe_counter);
791 atomic_add(swqe_av, &pr->swqe_avail);
793 spin_lock_irqsave(&pr->netif_queue, flags);
795 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
796 >= pr->swqe_refill_th)) {
797 netif_wake_queue(pr->port->netdev);
798 pr->queue_stopped = 0;
800 spin_unlock_irqrestore(&pr->netif_queue, flags);
805 #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
806 #define EHEA_POLL_MAX_CQES 65535
808 static int ehea_poll(struct napi_struct *napi, int budget)
810 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
812 struct net_device *dev = pr->port->netdev;
813 struct ehea_cqe *cqe;
814 struct ehea_cqe *cqe_skb = NULL;
815 int force_irq, wqe_index;
818 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
819 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
822 rx += ehea_proc_rwqes(dev, pr, budget - rx);
824 while ((rx != budget) || force_irq) {
825 pr->poll_counter = 0;
827 netif_rx_complete(dev, napi);
828 ehea_reset_cq_ep(pr->recv_cq);
829 ehea_reset_cq_ep(pr->send_cq);
830 ehea_reset_cq_n1(pr->recv_cq);
831 ehea_reset_cq_n1(pr->send_cq);
832 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
833 cqe_skb = ehea_poll_cq(pr->send_cq);
835 if (!cqe && !cqe_skb)
838 if (!netif_rx_reschedule(dev, napi))
841 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
842 rx += ehea_proc_rwqes(dev, pr, budget - rx);
849 #ifdef CONFIG_NET_POLL_CONTROLLER
850 static void ehea_netpoll(struct net_device *dev)
852 struct ehea_port *port = netdev_priv(dev);
855 for (i = 0; i < port->num_def_qps; i++)
856 netif_rx_schedule(dev, &port->port_res[i].napi);
860 static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
862 struct ehea_port_res *pr = param;
864 netif_rx_schedule(pr->port->netdev, &pr->napi);
869 static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
871 struct ehea_port *port = param;
872 struct ehea_eqe *eqe;
876 eqe = ehea_poll_eq(port->qp_eq);
879 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
880 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
881 eqe->entry, qp_token);
883 qp = port->port_res[qp_token].qp;
884 ehea_error_data(port->adapter, qp->fw_handle);
885 eqe = ehea_poll_eq(port->qp_eq);
888 schedule_work(&port->reset_task);
893 static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
898 for (i = 0; i < EHEA_MAX_PORTS; i++)
899 if (adapter->port[i])
900 if (adapter->port[i]->logical_port_id == logical_port)
901 return adapter->port[i];
905 int ehea_sense_port_attr(struct ehea_port *port)
909 struct hcp_ehea_port_cb0 *cb0;
911 /* may be called via ehea_neq_tasklet() */
912 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
914 ehea_error("no mem for cb0");
919 hret = ehea_h_query_ehea_port(port->adapter->handle,
920 port->logical_port_id, H_PORT_CB0,
921 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
923 if (hret != H_SUCCESS) {
929 port->mac_addr = cb0->port_mac_addr << 16;
931 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
932 ret = -EADDRNOTAVAIL;
937 switch (cb0->port_speed) {
939 port->port_speed = EHEA_SPEED_10M;
940 port->full_duplex = 0;
943 port->port_speed = EHEA_SPEED_10M;
944 port->full_duplex = 1;
947 port->port_speed = EHEA_SPEED_100M;
948 port->full_duplex = 0;
951 port->port_speed = EHEA_SPEED_100M;
952 port->full_duplex = 1;
955 port->port_speed = EHEA_SPEED_1G;
956 port->full_duplex = 1;
959 port->port_speed = EHEA_SPEED_10G;
960 port->full_duplex = 1;
963 port->port_speed = 0;
964 port->full_duplex = 0;
969 port->num_mcs = cb0->num_default_qps;
971 /* Number of default QPs */
973 port->num_def_qps = cb0->num_default_qps;
975 port->num_def_qps = 1;
977 if (!port->num_def_qps) {
982 port->num_tx_qps = num_tx_qps;
984 if (port->num_def_qps >= port->num_tx_qps)
985 port->num_add_tx_qps = 0;
987 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
991 if (ret || netif_msg_probe(port))
992 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
998 int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1000 struct hcp_ehea_port_cb4 *cb4;
1004 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1006 ehea_error("no mem for cb4");
1011 cb4->port_speed = port_speed;
1013 netif_carrier_off(port->netdev);
1015 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1016 port->logical_port_id,
1017 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1018 if (hret == H_SUCCESS) {
1019 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1021 hret = ehea_h_query_ehea_port(port->adapter->handle,
1022 port->logical_port_id,
1023 H_PORT_CB4, H_PORT_CB4_SPEED,
1025 if (hret == H_SUCCESS) {
1026 switch (cb4->port_speed) {
1028 port->port_speed = EHEA_SPEED_10M;
1029 port->full_duplex = 0;
1032 port->port_speed = EHEA_SPEED_10M;
1033 port->full_duplex = 1;
1035 case H_SPEED_100M_H:
1036 port->port_speed = EHEA_SPEED_100M;
1037 port->full_duplex = 0;
1039 case H_SPEED_100M_F:
1040 port->port_speed = EHEA_SPEED_100M;
1041 port->full_duplex = 1;
1044 port->port_speed = EHEA_SPEED_1G;
1045 port->full_duplex = 1;
1048 port->port_speed = EHEA_SPEED_10G;
1049 port->full_duplex = 1;
1052 port->port_speed = 0;
1053 port->full_duplex = 0;
1057 ehea_error("Failed sensing port speed");
1061 if (hret == H_AUTHORITY) {
1062 ehea_info("Hypervisor denied setting port speed");
1066 ehea_error("Failed setting port speed");
1069 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1070 netif_carrier_on(port->netdev);
1077 static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1082 struct ehea_port *port;
1084 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1085 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1086 port = ehea_get_port(adapter, portnum);
1089 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1092 ehea_error("unknown portnum %x", portnum);
1096 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1097 if (!netif_carrier_ok(port->netdev)) {
1098 ret = ehea_sense_port_attr(port);
1100 ehea_error("failed resensing port "
1105 if (netif_msg_link(port))
1106 ehea_info("%s: Logical port up: %dMbps "
1110 port->full_duplex ==
1111 1 ? "Full" : "Half");
1113 netif_carrier_on(port->netdev);
1114 netif_wake_queue(port->netdev);
1117 if (netif_carrier_ok(port->netdev)) {
1118 if (netif_msg_link(port))
1119 ehea_info("%s: Logical port down",
1120 port->netdev->name);
1121 netif_carrier_off(port->netdev);
1122 netif_stop_queue(port->netdev);
1125 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
1126 port->phy_link = EHEA_PHY_LINK_UP;
1127 if (netif_msg_link(port))
1128 ehea_info("%s: Physical port up",
1129 port->netdev->name);
1130 if (prop_carrier_state)
1131 netif_carrier_on(port->netdev);
1133 port->phy_link = EHEA_PHY_LINK_DOWN;
1134 if (netif_msg_link(port))
1135 ehea_info("%s: Physical port down",
1136 port->netdev->name);
1137 if (prop_carrier_state)
1138 netif_carrier_off(port->netdev);
1141 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1142 ehea_info("External switch port is primary port");
1144 ehea_info("External switch port is backup port");
1147 case EHEA_EC_ADAPTER_MALFUNC:
1148 ehea_error("Adapter malfunction");
1150 case EHEA_EC_PORT_MALFUNC:
1151 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1152 netif_carrier_off(port->netdev);
1153 netif_stop_queue(port->netdev);
1156 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
1161 static void ehea_neq_tasklet(unsigned long data)
1163 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
1164 struct ehea_eqe *eqe;
1167 eqe = ehea_poll_eq(adapter->neq);
1168 ehea_debug("eqe=%p", eqe);
1171 ehea_debug("*eqe=%lx", eqe->entry);
1172 ehea_parse_eqe(adapter, eqe->entry);
1173 eqe = ehea_poll_eq(adapter->neq);
1174 ehea_debug("next eqe=%p", eqe);
1177 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1178 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1179 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1181 ehea_h_reset_events(adapter->handle,
1182 adapter->neq->fw_handle, event_mask);
1185 static irqreturn_t ehea_interrupt_neq(int irq, void *param)
1187 struct ehea_adapter *adapter = param;
1188 tasklet_hi_schedule(&adapter->neq_tasklet);
1193 static int ehea_fill_port_res(struct ehea_port_res *pr)
1196 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1198 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1199 - init_attr->act_nr_rwqes_rq2
1200 - init_attr->act_nr_rwqes_rq3 - 1);
1202 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
1204 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1209 static int ehea_reg_interrupts(struct net_device *dev)
1211 struct ehea_port *port = netdev_priv(dev);
1212 struct ehea_port_res *pr;
1216 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1219 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
1220 ehea_qp_aff_irq_handler,
1221 IRQF_DISABLED, port->int_aff_name, port);
1223 ehea_error("failed registering irq for qp_aff_irq_handler:"
1224 "ist=%X", port->qp_eq->attr.ist1);
1228 if (netif_msg_ifup(port))
1229 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1230 "registered", port->qp_eq->attr.ist1);
1233 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1234 pr = &port->port_res[i];
1235 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
1236 "%s-queue%d", dev->name, i);
1237 ret = ibmebus_request_irq(pr->eq->attr.ist1,
1238 ehea_recv_irq_handler,
1239 IRQF_DISABLED, pr->int_send_name,
1242 ehea_error("failed registering irq for ehea_queue "
1243 "port_res_nr:%d, ist=%X", i,
1247 if (netif_msg_ifup(port))
1248 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1249 "%d registered", pr->eq->attr.ist1, i);
1257 u32 ist = port->port_res[i].eq->attr.ist1;
1258 ibmebus_free_irq(ist, &port->port_res[i]);
1262 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
1263 i = port->num_def_qps;
1269 static void ehea_free_interrupts(struct net_device *dev)
1271 struct ehea_port *port = netdev_priv(dev);
1272 struct ehea_port_res *pr;
1277 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1278 pr = &port->port_res[i];
1279 ibmebus_free_irq(pr->eq->attr.ist1, pr);
1280 if (netif_msg_intr(port))
1281 ehea_info("free send irq for res %d with handle 0x%X",
1282 i, pr->eq->attr.ist1);
1285 /* associated events */
1286 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
1287 if (netif_msg_intr(port))
1288 ehea_info("associated event interrupt for handle 0x%X freed",
1289 port->qp_eq->attr.ist1);
1292 static int ehea_configure_port(struct ehea_port *port)
1296 struct hcp_ehea_port_cb0 *cb0;
1299 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1303 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1304 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1305 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1306 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1307 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1308 PXLY_RC_VLAN_FILTER)
1309 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1311 for (i = 0; i < port->num_mcs; i++)
1313 cb0->default_qpn_arr[i] =
1314 port->port_res[i].qp->init_attr.qp_nr;
1316 cb0->default_qpn_arr[i] =
1317 port->port_res[0].qp->init_attr.qp_nr;
1319 if (netif_msg_ifup(port))
1320 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1322 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1323 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1325 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1326 port->logical_port_id,
1327 H_PORT_CB0, mask, cb0);
1329 if (hret != H_SUCCESS)
1340 int ehea_gen_smrs(struct ehea_port_res *pr)
1343 struct ehea_adapter *adapter = pr->port->adapter;
1345 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1349 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1356 ehea_rem_mr(&pr->send_mr);
1358 ehea_error("Generating SMRS failed\n");
1362 int ehea_rem_smrs(struct ehea_port_res *pr)
1364 if ((ehea_rem_mr(&pr->send_mr))
1365 || (ehea_rem_mr(&pr->recv_mr)))
1371 static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1373 int arr_size = sizeof(void *) * max_q_entries;
1375 q_skba->arr = vmalloc(arr_size);
1379 memset(q_skba->arr, 0, arr_size);
1381 q_skba->len = max_q_entries;
1383 q_skba->os_skbs = 0;
1388 static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1389 struct port_res_cfg *pr_cfg, int queue_token)
1391 struct ehea_adapter *adapter = port->adapter;
1392 enum ehea_eq_type eq_type = EHEA_EQ;
1393 struct ehea_qp_init_attr *init_attr = NULL;
1396 memset(pr, 0, sizeof(struct ehea_port_res));
1399 spin_lock_init(&pr->xmit_lock);
1400 spin_lock_init(&pr->netif_queue);
1402 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1404 ehea_error("create_eq failed (eq)");
1408 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
1410 port->logical_port_id);
1412 ehea_error("create_cq failed (cq_recv)");
1416 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
1418 port->logical_port_id);
1420 ehea_error("create_cq failed (cq_send)");
1424 if (netif_msg_ifup(port))
1425 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1426 pr->send_cq->attr.act_nr_of_cqes,
1427 pr->recv_cq->attr.act_nr_of_cqes);
1429 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1432 ehea_error("no mem for ehea_qp_init_attr");
1436 init_attr->low_lat_rq1 = 1;
1437 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1438 init_attr->rq_count = 3;
1439 init_attr->qp_token = queue_token;
1440 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1441 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1442 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1443 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1444 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1445 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1446 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1447 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1448 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1449 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1450 init_attr->port_nr = port->logical_port_id;
1451 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1452 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1453 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1455 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1457 ehea_error("create_qp failed");
1462 if (netif_msg_ifup(port))
1463 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1464 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1465 init_attr->act_nr_send_wqes,
1466 init_attr->act_nr_rwqes_rq1,
1467 init_attr->act_nr_rwqes_rq2,
1468 init_attr->act_nr_rwqes_rq3);
1470 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1472 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
1473 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1474 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1475 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1479 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1480 if (ehea_gen_smrs(pr) != 0) {
1485 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1489 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
1491 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1492 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1493 pr->lro_mgr.lro_arr = pr->lro_desc;
1494 pr->lro_mgr.get_skb_header = get_skb_hdr;
1495 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1496 pr->lro_mgr.dev = port->netdev;
1497 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1498 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1505 vfree(pr->sq_skba.arr);
1506 vfree(pr->rq1_skba.arr);
1507 vfree(pr->rq2_skba.arr);
1508 vfree(pr->rq3_skba.arr);
1509 ehea_destroy_qp(pr->qp);
1510 ehea_destroy_cq(pr->send_cq);
1511 ehea_destroy_cq(pr->recv_cq);
1512 ehea_destroy_eq(pr->eq);
1517 static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1521 ret = ehea_destroy_qp(pr->qp);
1524 ehea_destroy_cq(pr->send_cq);
1525 ehea_destroy_cq(pr->recv_cq);
1526 ehea_destroy_eq(pr->eq);
1528 for (i = 0; i < pr->rq1_skba.len; i++)
1529 if (pr->rq1_skba.arr[i])
1530 dev_kfree_skb(pr->rq1_skba.arr[i]);
1532 for (i = 0; i < pr->rq2_skba.len; i++)
1533 if (pr->rq2_skba.arr[i])
1534 dev_kfree_skb(pr->rq2_skba.arr[i]);
1536 for (i = 0; i < pr->rq3_skba.len; i++)
1537 if (pr->rq3_skba.arr[i])
1538 dev_kfree_skb(pr->rq3_skba.arr[i]);
1540 for (i = 0; i < pr->sq_skba.len; i++)
1541 if (pr->sq_skba.arr[i])
1542 dev_kfree_skb(pr->sq_skba.arr[i]);
1544 vfree(pr->rq1_skba.arr);
1545 vfree(pr->rq2_skba.arr);
1546 vfree(pr->rq3_skba.arr);
1547 vfree(pr->sq_skba.arr);
1548 ret = ehea_rem_smrs(pr);
1554 * The write_* functions store information in swqe which is used by
1555 * the hardware to calculate the ip/tcp/udp checksum
1558 static inline void write_ip_start_end(struct ehea_swqe *swqe,
1559 const struct sk_buff *skb)
1561 swqe->ip_start = skb_network_offset(skb);
1562 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
1565 static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1566 const struct sk_buff *skb)
1569 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1571 swqe->tcp_end = (u16)skb->len - 1;
1574 static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1575 const struct sk_buff *skb)
1578 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1580 swqe->tcp_end = (u16)skb->len - 1;
1584 static void write_swqe2_TSO(struct sk_buff *skb,
1585 struct ehea_swqe *swqe, u32 lkey)
1587 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1588 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1589 int skb_data_size = skb->len - skb->data_len;
1592 /* Packet is TCP with TSO enabled */
1593 swqe->tx_control |= EHEA_SWQE_TSO;
1594 swqe->mss = skb_shinfo(skb)->gso_size;
1595 /* copy only eth/ip/tcp headers to immediate data and
1596 * the rest of skb->data to sg1entry
1598 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1600 skb_data_size = skb->len - skb->data_len;
1602 if (skb_data_size >= headersize) {
1603 /* copy immediate data */
1604 skb_copy_from_linear_data(skb, imm_data, headersize);
1605 swqe->immediate_data_length = headersize;
1607 if (skb_data_size > headersize) {
1608 /* set sg1entry data */
1609 sg1entry->l_key = lkey;
1610 sg1entry->len = skb_data_size - headersize;
1612 ehea_map_vaddr(skb->data + headersize);
1613 swqe->descriptors++;
1616 ehea_error("cannot handle fragmented headers");
1619 static void write_swqe2_nonTSO(struct sk_buff *skb,
1620 struct ehea_swqe *swqe, u32 lkey)
1622 int skb_data_size = skb->len - skb->data_len;
1623 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1624 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1626 /* Packet is any nonTSO type
1628 * Copy as much as possible skb->data to immediate data and
1629 * the rest to sg1entry
1631 if (skb_data_size >= SWQE2_MAX_IMM) {
1632 /* copy immediate data */
1633 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
1635 swqe->immediate_data_length = SWQE2_MAX_IMM;
1637 if (skb_data_size > SWQE2_MAX_IMM) {
1638 /* copy sg1entry data */
1639 sg1entry->l_key = lkey;
1640 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
1642 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
1643 swqe->descriptors++;
1646 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
1647 swqe->immediate_data_length = skb_data_size;
1651 static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1652 struct ehea_swqe *swqe, u32 lkey)
1654 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1656 int nfrags, sg1entry_contains_frag_data, i;
1658 nfrags = skb_shinfo(skb)->nr_frags;
1659 sg1entry = &swqe->u.immdata_desc.sg_entry;
1660 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
1661 swqe->descriptors = 0;
1662 sg1entry_contains_frag_data = 0;
1664 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1665 write_swqe2_TSO(skb, swqe, lkey);
1667 write_swqe2_nonTSO(skb, swqe, lkey);
1669 /* write descriptors */
1671 if (swqe->descriptors == 0) {
1672 /* sg1entry not yet used */
1673 frag = &skb_shinfo(skb)->frags[0];
1675 /* copy sg1entry data */
1676 sg1entry->l_key = lkey;
1677 sg1entry->len = frag->size;
1679 ehea_map_vaddr(page_address(frag->page)
1680 + frag->page_offset);
1681 swqe->descriptors++;
1682 sg1entry_contains_frag_data = 1;
1685 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1687 frag = &skb_shinfo(skb)->frags[i];
1688 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1690 sgentry->l_key = lkey;
1691 sgentry->len = frag->size;
1693 ehea_map_vaddr(page_address(frag->page)
1694 + frag->page_offset);
1695 swqe->descriptors++;
1700 static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1706 /* De/Register untagged packets */
1707 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1708 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1709 port->logical_port_id,
1710 reg_type, port->mac_addr, 0, hcallid);
1711 if (hret != H_SUCCESS) {
1712 ehea_error("%sregistering bc address failed (tagged)",
1713 hcallid == H_REG_BCMC ? "" : "de");
1718 /* De/Register VLAN packets */
1719 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1720 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1721 port->logical_port_id,
1722 reg_type, port->mac_addr, 0, hcallid);
1723 if (hret != H_SUCCESS) {
1724 ehea_error("%sregistering bc address failed (vlan)",
1725 hcallid == H_REG_BCMC ? "" : "de");
1732 static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1734 struct ehea_port *port = netdev_priv(dev);
1735 struct sockaddr *mac_addr = sa;
1736 struct hcp_ehea_port_cb0 *cb0;
1740 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1741 ret = -EADDRNOTAVAIL;
1745 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1747 ehea_error("no mem for cb0");
1752 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1754 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1756 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1757 port->logical_port_id, H_PORT_CB0,
1758 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1759 if (hret != H_SUCCESS) {
1764 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1766 mutex_lock(&ehea_bcmc_regs.lock);
1768 /* Deregister old MAC in pHYP */
1769 if (port->state == EHEA_PORT_UP) {
1770 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1775 port->mac_addr = cb0->port_mac_addr << 16;
1777 /* Register new MAC in pHYP */
1778 if (port->state == EHEA_PORT_UP) {
1779 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1787 ehea_update_bcmc_registrations();
1788 mutex_unlock(&ehea_bcmc_regs.lock);
1795 static void ehea_promiscuous_error(u64 hret, int enable)
1797 if (hret == H_AUTHORITY)
1798 ehea_info("Hypervisor denied %sabling promiscuous mode",
1799 enable == 1 ? "en" : "dis");
1801 ehea_error("failed %sabling promiscuous mode",
1802 enable == 1 ? "en" : "dis");
1805 static void ehea_promiscuous(struct net_device *dev, int enable)
1807 struct ehea_port *port = netdev_priv(dev);
1808 struct hcp_ehea_port_cb7 *cb7;
1811 if ((enable && port->promisc) || (!enable && !port->promisc))
1814 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
1816 ehea_error("no mem for cb7");
1820 /* Modify Pxs_DUCQPN in CB7 */
1821 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1823 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1824 port->logical_port_id,
1825 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1827 ehea_promiscuous_error(hret, enable);
1831 port->promisc = enable;
1837 static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1843 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1844 | EHEA_BCMC_UNTAGGED;
1846 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1847 port->logical_port_id,
1848 reg_type, mc_mac_addr, 0, hcallid);
1852 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1853 | EHEA_BCMC_VLANID_ALL;
1855 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1856 port->logical_port_id,
1857 reg_type, mc_mac_addr, 0, hcallid);
1862 static int ehea_drop_multicast_list(struct net_device *dev)
1864 struct ehea_port *port = netdev_priv(dev);
1865 struct ehea_mc_list *mc_entry = port->mc_list;
1866 struct list_head *pos;
1867 struct list_head *temp;
1871 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1872 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1874 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1877 ehea_error("failed deregistering mcast MAC");
1887 static void ehea_allmulti(struct net_device *dev, int enable)
1889 struct ehea_port *port = netdev_priv(dev);
1892 if (!port->allmulti) {
1894 /* Enable ALLMULTI */
1895 ehea_drop_multicast_list(dev);
1896 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1900 ehea_error("failed enabling IFF_ALLMULTI");
1904 /* Disable ALLMULTI */
1905 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1909 ehea_error("failed disabling IFF_ALLMULTI");
1913 static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
1915 struct ehea_mc_list *ehea_mcl_entry;
1918 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
1919 if (!ehea_mcl_entry) {
1920 ehea_error("no mem for mcl_entry");
1924 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1926 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1928 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1931 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1933 ehea_error("failed registering mcast MAC");
1934 kfree(ehea_mcl_entry);
1938 static void ehea_set_multicast_list(struct net_device *dev)
1940 struct ehea_port *port = netdev_priv(dev);
1941 struct dev_mc_list *k_mcl_entry;
1944 if (dev->flags & IFF_PROMISC) {
1945 ehea_promiscuous(dev, 1);
1948 ehea_promiscuous(dev, 0);
1950 mutex_lock(&ehea_bcmc_regs.lock);
1952 if (dev->flags & IFF_ALLMULTI) {
1953 ehea_allmulti(dev, 1);
1956 ehea_allmulti(dev, 0);
1958 if (dev->mc_count) {
1959 ret = ehea_drop_multicast_list(dev);
1961 /* Dropping the current multicast list failed.
1962 * Enabling ALL_MULTI is the best we can do.
1964 ehea_allmulti(dev, 1);
1967 if (dev->mc_count > port->adapter->max_mc_mac) {
1968 ehea_info("Mcast registration limit reached (0x%lx). "
1970 port->adapter->max_mc_mac);
1974 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
1975 k_mcl_entry = k_mcl_entry->next)
1976 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
1980 ehea_update_bcmc_registrations();
1981 mutex_unlock(&ehea_bcmc_regs.lock);
1985 static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1987 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1993 static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1994 struct ehea_swqe *swqe, u32 lkey)
1996 if (skb->protocol == htons(ETH_P_IP)) {
1997 const struct iphdr *iph = ip_hdr(skb);
2000 swqe->tx_control |= EHEA_SWQE_CRC
2001 | EHEA_SWQE_IP_CHECKSUM
2002 | EHEA_SWQE_TCP_CHECKSUM
2003 | EHEA_SWQE_IMM_DATA_PRESENT
2004 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2006 write_ip_start_end(swqe, skb);
2008 if (iph->protocol == IPPROTO_UDP) {
2009 if ((iph->frag_off & IP_MF)
2010 || (iph->frag_off & IP_OFFSET))
2011 /* IP fragment, so don't change cs */
2012 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2014 write_udp_offset_end(swqe, skb);
2015 } else if (iph->protocol == IPPROTO_TCP) {
2016 write_tcp_offset_end(swqe, skb);
2019 /* icmp (big data) and ip segmentation packets (all other ip
2020 packets) do not require any special handling */
2023 /* Other Ethernet Protocol */
2024 swqe->tx_control |= EHEA_SWQE_CRC
2025 | EHEA_SWQE_IMM_DATA_PRESENT
2026 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2029 write_swqe2_data(skb, dev, swqe, lkey);
2032 static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2033 struct ehea_swqe *swqe)
2035 int nfrags = skb_shinfo(skb)->nr_frags;
2036 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2040 if (skb->protocol == htons(ETH_P_IP)) {
2041 const struct iphdr *iph = ip_hdr(skb);
2044 write_ip_start_end(swqe, skb);
2046 if (iph->protocol == IPPROTO_TCP) {
2047 swqe->tx_control |= EHEA_SWQE_CRC
2048 | EHEA_SWQE_IP_CHECKSUM
2049 | EHEA_SWQE_TCP_CHECKSUM
2050 | EHEA_SWQE_IMM_DATA_PRESENT;
2052 write_tcp_offset_end(swqe, skb);
2054 } else if (iph->protocol == IPPROTO_UDP) {
2055 if ((iph->frag_off & IP_MF)
2056 || (iph->frag_off & IP_OFFSET))
2057 /* IP fragment, so don't change cs */
2058 swqe->tx_control |= EHEA_SWQE_CRC
2059 | EHEA_SWQE_IMM_DATA_PRESENT;
2061 swqe->tx_control |= EHEA_SWQE_CRC
2062 | EHEA_SWQE_IP_CHECKSUM
2063 | EHEA_SWQE_TCP_CHECKSUM
2064 | EHEA_SWQE_IMM_DATA_PRESENT;
2066 write_udp_offset_end(swqe, skb);
2069 /* icmp (big data) and
2070 ip segmentation packets (all other ip packets) */
2071 swqe->tx_control |= EHEA_SWQE_CRC
2072 | EHEA_SWQE_IP_CHECKSUM
2073 | EHEA_SWQE_IMM_DATA_PRESENT;
2076 /* Other Ethernet Protocol */
2077 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2079 /* copy (immediate) data */
2081 /* data is in a single piece */
2082 skb_copy_from_linear_data(skb, imm_data, skb->len);
2084 /* first copy data from the skb->data buffer ... */
2085 skb_copy_from_linear_data(skb, imm_data,
2086 skb->len - skb->data_len);
2087 imm_data += skb->len - skb->data_len;
2089 /* ... then copy data from the fragments */
2090 for (i = 0; i < nfrags; i++) {
2091 frag = &skb_shinfo(skb)->frags[i];
2093 page_address(frag->page) + frag->page_offset,
2095 imm_data += frag->size;
2098 swqe->immediate_data_length = skb->len;
2102 static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2107 if ((skb->protocol == htons(ETH_P_IP)) &&
2108 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
2109 tcp = (struct tcphdr *)(skb_network_header(skb) +
2110 (ip_hdr(skb)->ihl * 4));
2111 tmp = (tcp->source + (tcp->dest << 16)) % 31;
2112 tmp += ip_hdr(skb)->daddr % 31;
2113 return tmp % num_qps;
2118 static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2120 struct ehea_port *port = netdev_priv(dev);
2121 struct ehea_swqe *swqe;
2122 unsigned long flags;
2125 struct ehea_port_res *pr;
2127 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2129 if (!spin_trylock(&pr->xmit_lock))
2130 return NETDEV_TX_BUSY;
2132 if (pr->queue_stopped) {
2133 spin_unlock(&pr->xmit_lock);
2134 return NETDEV_TX_BUSY;
2137 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2138 memset(swqe, 0, SWQE_HEADER_SIZE);
2139 atomic_dec(&pr->swqe_avail);
2141 if (skb->len <= SWQE3_MAX_IMM) {
2142 u32 sig_iv = port->sig_comp_iv;
2143 u32 swqe_num = pr->swqe_id_counter;
2144 ehea_xmit3(skb, dev, swqe);
2145 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2146 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2147 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2148 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2150 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2151 pr->swqe_ll_count = 0;
2153 pr->swqe_ll_count += 1;
2156 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2157 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
2158 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
2159 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2160 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2162 pr->sq_skba.index++;
2163 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2165 lkey = pr->send_mr.lkey;
2166 ehea_xmit2(skb, dev, swqe, lkey);
2167 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2169 pr->swqe_id_counter += 1;
2171 if (port->vgrp && vlan_tx_tag_present(skb)) {
2172 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2173 swqe->vlan_tag = vlan_tx_tag_get(skb);
2176 if (netif_msg_tx_queued(port)) {
2177 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
2178 ehea_dump(swqe, 512, "swqe");
2181 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2182 netif_stop_queue(dev);
2183 swqe->tx_control |= EHEA_SWQE_PURGE;
2186 ehea_post_swqe(pr->qp, swqe);
2189 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2190 spin_lock_irqsave(&pr->netif_queue, flags);
2191 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2192 pr->p_stats.queue_stopped++;
2193 netif_stop_queue(dev);
2194 pr->queue_stopped = 1;
2196 spin_unlock_irqrestore(&pr->netif_queue, flags);
2198 dev->trans_start = jiffies;
2199 spin_unlock(&pr->xmit_lock);
2201 return NETDEV_TX_OK;
2204 static void ehea_vlan_rx_register(struct net_device *dev,
2205 struct vlan_group *grp)
2207 struct ehea_port *port = netdev_priv(dev);
2208 struct ehea_adapter *adapter = port->adapter;
2209 struct hcp_ehea_port_cb1 *cb1;
2214 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2216 ehea_error("no mem for cb1");
2220 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2221 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2222 if (hret != H_SUCCESS)
2223 ehea_error("modify_ehea_port failed");
2230 static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2232 struct ehea_port *port = netdev_priv(dev);
2233 struct ehea_adapter *adapter = port->adapter;
2234 struct hcp_ehea_port_cb1 *cb1;
2238 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2240 ehea_error("no mem for cb1");
2244 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2245 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2246 if (hret != H_SUCCESS) {
2247 ehea_error("query_ehea_port failed");
2252 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
2254 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2255 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2256 if (hret != H_SUCCESS)
2257 ehea_error("modify_ehea_port failed");
2263 static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2265 struct ehea_port *port = netdev_priv(dev);
2266 struct ehea_adapter *adapter = port->adapter;
2267 struct hcp_ehea_port_cb1 *cb1;
2271 vlan_group_set_device(port->vgrp, vid, NULL);
2273 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2275 ehea_error("no mem for cb1");
2279 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2280 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2281 if (hret != H_SUCCESS) {
2282 ehea_error("query_ehea_port failed");
2287 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
2289 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2290 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2291 if (hret != H_SUCCESS)
2292 ehea_error("modify_ehea_port failed");
2298 int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2304 struct hcp_modify_qp_cb0 *cb0;
2306 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2312 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2313 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2314 if (hret != H_SUCCESS) {
2315 ehea_error("query_ehea_qp failed (1)");
2319 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2320 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2321 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2322 &dummy64, &dummy64, &dummy16, &dummy16);
2323 if (hret != H_SUCCESS) {
2324 ehea_error("modify_ehea_qp failed (1)");
2328 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2329 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2330 if (hret != H_SUCCESS) {
2331 ehea_error("query_ehea_qp failed (2)");
2335 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2336 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2337 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2338 &dummy64, &dummy64, &dummy16, &dummy16);
2339 if (hret != H_SUCCESS) {
2340 ehea_error("modify_ehea_qp failed (2)");
2344 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2345 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2346 if (hret != H_SUCCESS) {
2347 ehea_error("query_ehea_qp failed (3)");
2351 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2352 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2353 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2354 &dummy64, &dummy64, &dummy16, &dummy16);
2355 if (hret != H_SUCCESS) {
2356 ehea_error("modify_ehea_qp failed (3)");
2360 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2361 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2362 if (hret != H_SUCCESS) {
2363 ehea_error("query_ehea_qp failed (4)");
2373 static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2377 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2378 enum ehea_eq_type eq_type = EHEA_EQ;
2380 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2381 EHEA_MAX_ENTRIES_EQ, 1);
2384 ehea_error("ehea_create_eq failed (qp_eq)");
2388 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
2389 pr_cfg.max_entries_scq = sq_entries * 2;
2390 pr_cfg.max_entries_sq = sq_entries;
2391 pr_cfg.max_entries_rq1 = rq1_entries;
2392 pr_cfg.max_entries_rq2 = rq2_entries;
2393 pr_cfg.max_entries_rq3 = rq3_entries;
2395 pr_cfg_small_rx.max_entries_rcq = 1;
2396 pr_cfg_small_rx.max_entries_scq = sq_entries;
2397 pr_cfg_small_rx.max_entries_sq = sq_entries;
2398 pr_cfg_small_rx.max_entries_rq1 = 1;
2399 pr_cfg_small_rx.max_entries_rq2 = 1;
2400 pr_cfg_small_rx.max_entries_rq3 = 1;
2402 for (i = 0; i < def_qps; i++) {
2403 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2407 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2408 ret = ehea_init_port_res(port, &port->port_res[i],
2409 &pr_cfg_small_rx, i);
2418 ehea_clean_portres(port, &port->port_res[i]);
2421 ehea_destroy_eq(port->qp_eq);
2425 static int ehea_clean_all_portres(struct ehea_port *port)
2430 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2431 ret |= ehea_clean_portres(port, &port->port_res[i]);
2433 ret |= ehea_destroy_eq(port->qp_eq);
2438 static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
2440 if (adapter->active_ports)
2443 ehea_rem_mr(&adapter->mr);
2446 static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
2448 if (adapter->active_ports)
2451 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2454 static int ehea_up(struct net_device *dev)
2457 struct ehea_port *port = netdev_priv(dev);
2459 if (port->state == EHEA_PORT_UP)
2462 mutex_lock(&ehea_fw_handles.lock);
2464 ret = ehea_port_res_setup(port, port->num_def_qps,
2465 port->num_add_tx_qps);
2467 ehea_error("port_res_failed");
2471 /* Set default QP for this port */
2472 ret = ehea_configure_port(port);
2474 ehea_error("ehea_configure_port failed. ret:%d", ret);
2478 ret = ehea_reg_interrupts(dev);
2480 ehea_error("reg_interrupts failed. ret:%d", ret);
2484 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2485 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2487 ehea_error("activate_qp failed");
2492 for (i = 0; i < port->num_def_qps; i++) {
2493 ret = ehea_fill_port_res(&port->port_res[i]);
2495 ehea_error("out_free_irqs");
2500 mutex_lock(&ehea_bcmc_regs.lock);
2502 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2508 port->state = EHEA_PORT_UP;
2514 ehea_free_interrupts(dev);
2517 ehea_clean_all_portres(port);
2520 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2522 ehea_update_bcmc_registrations();
2523 mutex_unlock(&ehea_bcmc_regs.lock);
2525 ehea_update_firmware_handles();
2526 mutex_unlock(&ehea_fw_handles.lock);
2531 static void port_napi_disable(struct ehea_port *port)
2535 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2536 napi_disable(&port->port_res[i].napi);
2539 static void port_napi_enable(struct ehea_port *port)
2543 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2544 napi_enable(&port->port_res[i].napi);
2547 static int ehea_open(struct net_device *dev)
2550 struct ehea_port *port = netdev_priv(dev);
2552 mutex_lock(&port->port_lock);
2554 if (netif_msg_ifup(port))
2555 ehea_info("enabling port %s", dev->name);
2559 port_napi_enable(port);
2560 netif_start_queue(dev);
2563 mutex_unlock(&port->port_lock);
2568 static int ehea_down(struct net_device *dev)
2571 struct ehea_port *port = netdev_priv(dev);
2573 if (port->state == EHEA_PORT_DOWN)
2576 mutex_lock(&ehea_fw_handles.lock);
2578 mutex_lock(&ehea_bcmc_regs.lock);
2579 ehea_drop_multicast_list(dev);
2580 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2582 ehea_free_interrupts(dev);
2584 port->state = EHEA_PORT_DOWN;
2586 ehea_update_bcmc_registrations();
2587 mutex_unlock(&ehea_bcmc_regs.lock);
2589 ret = ehea_clean_all_portres(port);
2591 ehea_info("Failed freeing resources for %s. ret=%i",
2594 ehea_update_firmware_handles();
2595 mutex_unlock(&ehea_fw_handles.lock);
2600 static int ehea_stop(struct net_device *dev)
2603 struct ehea_port *port = netdev_priv(dev);
2605 if (netif_msg_ifdown(port))
2606 ehea_info("disabling port %s", dev->name);
2608 cancel_work_sync(&port->reset_task);
2610 mutex_lock(&port->port_lock);
2611 netif_stop_queue(dev);
2612 port_napi_disable(port);
2613 ret = ehea_down(dev);
2614 mutex_unlock(&port->port_lock);
2618 static void ehea_purge_sq(struct ehea_qp *orig_qp)
2620 struct ehea_qp qp = *orig_qp;
2621 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2622 struct ehea_swqe *swqe;
2626 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2627 swqe = ehea_get_swqe(&qp, &wqe_index);
2628 swqe->tx_control |= EHEA_SWQE_PURGE;
2632 static void ehea_flush_sq(struct ehea_port *port)
2636 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2637 struct ehea_port_res *pr = &port->port_res[i];
2638 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2640 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2648 int ehea_stop_qps(struct net_device *dev)
2650 struct ehea_port *port = netdev_priv(dev);
2651 struct ehea_adapter *adapter = port->adapter;
2652 struct hcp_modify_qp_cb0 *cb0;
2660 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2666 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2667 struct ehea_port_res *pr = &port->port_res[i];
2668 struct ehea_qp *qp = pr->qp;
2670 /* Purge send queue */
2673 /* Disable queue pair */
2674 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2675 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2677 if (hret != H_SUCCESS) {
2678 ehea_error("query_ehea_qp failed (1)");
2682 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2683 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2685 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2686 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2688 &dummy64, &dummy16, &dummy16);
2689 if (hret != H_SUCCESS) {
2690 ehea_error("modify_ehea_qp failed (1)");
2694 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2695 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2697 if (hret != H_SUCCESS) {
2698 ehea_error("query_ehea_qp failed (2)");
2702 /* deregister shared memory regions */
2703 dret = ehea_rem_smrs(pr);
2705 ehea_error("unreg shared memory region failed");
2717 void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
2719 struct ehea_qp qp = *orig_qp;
2720 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2721 struct ehea_rwqe *rwqe;
2722 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2723 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2724 struct sk_buff *skb;
2725 u32 lkey = pr->recv_mr.lkey;
2731 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2732 rwqe = ehea_get_next_rwqe(&qp, 2);
2733 rwqe->sg_list[0].l_key = lkey;
2734 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2735 skb = skba_rq2[index];
2737 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2740 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2741 rwqe = ehea_get_next_rwqe(&qp, 3);
2742 rwqe->sg_list[0].l_key = lkey;
2743 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2744 skb = skba_rq3[index];
2746 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2750 int ehea_restart_qps(struct net_device *dev)
2752 struct ehea_port *port = netdev_priv(dev);
2753 struct ehea_adapter *adapter = port->adapter;
2757 struct hcp_modify_qp_cb0 *cb0;
2762 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2768 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2769 struct ehea_port_res *pr = &port->port_res[i];
2770 struct ehea_qp *qp = pr->qp;
2772 ret = ehea_gen_smrs(pr);
2774 ehea_error("creation of shared memory regions failed");
2778 ehea_update_rqs(qp, pr);
2780 /* Enable queue pair */
2781 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2782 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2784 if (hret != H_SUCCESS) {
2785 ehea_error("query_ehea_qp failed (1)");
2789 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2790 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2792 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2793 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2795 &dummy64, &dummy16, &dummy16);
2796 if (hret != H_SUCCESS) {
2797 ehea_error("modify_ehea_qp failed (1)");
2801 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2802 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2804 if (hret != H_SUCCESS) {
2805 ehea_error("query_ehea_qp failed (2)");
2809 /* refill entire queue */
2810 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2811 ehea_refill_rq2(pr, 0);
2812 ehea_refill_rq3(pr, 0);
2820 static void ehea_reset_port(struct work_struct *work)
2823 struct ehea_port *port =
2824 container_of(work, struct ehea_port, reset_task);
2825 struct net_device *dev = port->netdev;
2828 mutex_lock(&port->port_lock);
2829 netif_stop_queue(dev);
2831 port_napi_disable(port);
2839 ehea_set_multicast_list(dev);
2841 if (netif_msg_timer(port))
2842 ehea_info("Device %s resetted successfully", dev->name);
2844 port_napi_enable(port);
2846 netif_wake_queue(dev);
2848 mutex_unlock(&port->port_lock);
2852 static void ehea_rereg_mrs(struct work_struct *work)
2855 struct ehea_adapter *adapter;
2857 mutex_lock(&dlpar_mem_lock);
2858 ehea_info("LPAR memory enlarged - re-initializing driver");
2860 list_for_each_entry(adapter, &adapter_list, list)
2861 if (adapter->active_ports) {
2862 /* Shutdown all ports */
2863 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2864 struct ehea_port *port = adapter->port[i];
2865 struct net_device *dev;
2872 if (dev->flags & IFF_UP) {
2873 mutex_lock(&port->port_lock);
2874 netif_stop_queue(dev);
2875 ehea_flush_sq(port);
2876 ret = ehea_stop_qps(dev);
2878 mutex_unlock(&port->port_lock);
2881 port_napi_disable(port);
2882 mutex_unlock(&port->port_lock);
2886 /* Unregister old memory region */
2887 ret = ehea_rem_mr(&adapter->mr);
2889 ehea_error("unregister MR failed - driver"
2895 ehea_destroy_busmap();
2896 ret = ehea_create_busmap();
2898 ehea_error("creating ehea busmap failed");
2902 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2904 list_for_each_entry(adapter, &adapter_list, list)
2905 if (adapter->active_ports) {
2906 /* Register new memory region */
2907 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2909 ehea_error("register MR failed - driver"
2914 /* Restart all ports */
2915 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2916 struct ehea_port *port = adapter->port[i];
2919 struct net_device *dev = port->netdev;
2921 if (dev->flags & IFF_UP) {
2922 mutex_lock(&port->port_lock);
2923 port_napi_enable(port);
2924 ret = ehea_restart_qps(dev);
2926 netif_wake_queue(dev);
2927 mutex_unlock(&port->port_lock);
2932 mutex_unlock(&dlpar_mem_lock);
2933 ehea_info("re-initializing driver complete");
2938 static void ehea_tx_watchdog(struct net_device *dev)
2940 struct ehea_port *port = netdev_priv(dev);
2942 if (netif_carrier_ok(dev) &&
2943 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
2944 schedule_work(&port->reset_task);
2947 int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2949 struct hcp_query_ehea *cb;
2953 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
2959 hret = ehea_h_query_ehea(adapter->handle, cb);
2961 if (hret != H_SUCCESS) {
2966 adapter->max_mc_mac = cb->max_mc_mac - 1;
2975 int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2977 struct hcp_ehea_port_cb4 *cb4;
2983 /* (Try to) enable *jumbo frames */
2984 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2986 ehea_error("no mem for cb4");
2990 hret = ehea_h_query_ehea_port(port->adapter->handle,
2991 port->logical_port_id,
2993 H_PORT_CB4_JUMBO, cb4);
2994 if (hret == H_SUCCESS) {
2995 if (cb4->jumbo_frame)
2998 cb4->jumbo_frame = 1;
2999 hret = ehea_h_modify_ehea_port(port->adapter->
3006 if (hret == H_SUCCESS)
3018 static ssize_t ehea_show_port_id(struct device *dev,
3019 struct device_attribute *attr, char *buf)
3021 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3022 return sprintf(buf, "%d", port->logical_port_id);
3025 static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3028 static void __devinit logical_port_release(struct device *dev)
3030 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3031 of_node_put(port->ofdev.node);
3034 static struct device *ehea_register_port(struct ehea_port *port,
3035 struct device_node *dn)
3039 port->ofdev.node = of_node_get(dn);
3040 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
3041 port->ofdev.dev.bus = &ibmebus_bus_type;
3043 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
3044 port->ofdev.dev.release = logical_port_release;
3046 ret = of_device_register(&port->ofdev);
3048 ehea_error("failed to register device. ret=%d", ret);
3052 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
3054 ehea_error("failed to register attributes, ret=%d", ret);
3055 goto out_unreg_of_dev;
3058 return &port->ofdev.dev;
3061 of_device_unregister(&port->ofdev);
3066 static void ehea_unregister_port(struct ehea_port *port)
3068 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3069 of_device_unregister(&port->ofdev);
3072 struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3073 u32 logical_port_id,
3074 struct device_node *dn)
3077 struct net_device *dev;
3078 struct ehea_port *port;
3079 struct device *port_dev;
3082 /* allocate memory for the port structures */
3083 dev = alloc_etherdev(sizeof(struct ehea_port));
3086 ehea_error("no mem for net_device");
3091 port = netdev_priv(dev);
3093 mutex_init(&port->port_lock);
3094 port->state = EHEA_PORT_DOWN;
3095 port->sig_comp_iv = sq_entries / 10;
3097 port->adapter = adapter;
3099 port->logical_port_id = logical_port_id;
3101 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
3103 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3104 if (!port->mc_list) {
3106 goto out_free_ethdev;
3109 INIT_LIST_HEAD(&port->mc_list->list);
3111 ret = ehea_sense_port_attr(port);
3113 goto out_free_mc_list;
3115 port_dev = ehea_register_port(port, dn);
3117 goto out_free_mc_list;
3119 SET_NETDEV_DEV(dev, port_dev);
3121 /* initialize net_device structure */
3122 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3124 dev->open = ehea_open;
3125 #ifdef CONFIG_NET_POLL_CONTROLLER
3126 dev->poll_controller = ehea_netpoll;
3128 dev->stop = ehea_stop;
3129 dev->hard_start_xmit = ehea_start_xmit;
3130 dev->get_stats = ehea_get_stats;
3131 dev->set_multicast_list = ehea_set_multicast_list;
3132 dev->set_mac_address = ehea_set_mac_addr;
3133 dev->change_mtu = ehea_change_mtu;
3134 dev->vlan_rx_register = ehea_vlan_rx_register;
3135 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
3136 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
3137 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
3138 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
3139 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3141 dev->tx_timeout = &ehea_tx_watchdog;
3142 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3144 INIT_WORK(&port->reset_task, ehea_reset_port);
3145 ehea_set_ethtool_ops(dev);
3147 ret = register_netdev(dev);
3149 ehea_error("register_netdev failed. ret=%d", ret);
3150 goto out_unreg_port;
3153 port->lro_max_aggr = lro_max_aggr;
3155 ret = ehea_get_jumboframe_status(port, &jumbo);
3157 ehea_error("failed determining jumbo frame status for %s",
3158 port->netdev->name);
3160 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3161 jumbo == 1 ? "en" : "dis");
3163 adapter->active_ports++;
3168 ehea_unregister_port(port);
3171 kfree(port->mc_list);
3177 ehea_error("setting up logical port with id=%d failed, ret=%d",
3178 logical_port_id, ret);
3182 static void ehea_shutdown_single_port(struct ehea_port *port)
3184 struct ehea_adapter *adapter = port->adapter;
3185 unregister_netdev(port->netdev);
3186 ehea_unregister_port(port);
3187 kfree(port->mc_list);
3188 free_netdev(port->netdev);
3189 adapter->active_ports--;
3192 static int ehea_setup_ports(struct ehea_adapter *adapter)
3194 struct device_node *lhea_dn;
3195 struct device_node *eth_dn = NULL;
3197 const u32 *dn_log_port_id;
3200 lhea_dn = adapter->ofdev->node;
3201 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
3203 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
3205 if (!dn_log_port_id) {
3206 ehea_error("bad device node: eth_dn name=%s",
3211 if (ehea_add_adapter_mr(adapter)) {
3212 ehea_error("creating MR failed");
3213 of_node_put(eth_dn);
3217 adapter->port[i] = ehea_setup_single_port(adapter,
3220 if (adapter->port[i])
3221 ehea_info("%s -> logical port id #%d",
3222 adapter->port[i]->netdev->name,
3225 ehea_remove_adapter_mr(adapter);
3232 static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3233 u32 logical_port_id)
3235 struct device_node *lhea_dn;
3236 struct device_node *eth_dn = NULL;
3237 const u32 *dn_log_port_id;
3239 lhea_dn = adapter->ofdev->node;
3240 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
3242 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
3245 if (*dn_log_port_id == logical_port_id)
3252 static ssize_t ehea_probe_port(struct device *dev,
3253 struct device_attribute *attr,
3254 const char *buf, size_t count)
3256 struct ehea_adapter *adapter = dev->driver_data;
3257 struct ehea_port *port;
3258 struct device_node *eth_dn = NULL;
3261 u32 logical_port_id;
3263 sscanf(buf, "%d", &logical_port_id);
3265 port = ehea_get_port(adapter, logical_port_id);
3268 ehea_info("adding port with logical port id=%d failed. port "
3269 "already configured as %s.", logical_port_id,
3270 port->netdev->name);
3274 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3277 ehea_info("no logical port with id %d found", logical_port_id);
3281 if (ehea_add_adapter_mr(adapter)) {
3282 ehea_error("creating MR failed");
3286 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3288 of_node_put(eth_dn);
3291 for (i = 0; i < EHEA_MAX_PORTS; i++)
3292 if (!adapter->port[i]) {
3293 adapter->port[i] = port;
3297 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3300 ehea_remove_adapter_mr(adapter);
3304 return (ssize_t) count;
3307 static ssize_t ehea_remove_port(struct device *dev,
3308 struct device_attribute *attr,
3309 const char *buf, size_t count)
3311 struct ehea_adapter *adapter = dev->driver_data;
3312 struct ehea_port *port;
3314 u32 logical_port_id;
3316 sscanf(buf, "%d", &logical_port_id);
3318 port = ehea_get_port(adapter, logical_port_id);
3321 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3324 ehea_shutdown_single_port(port);
3326 for (i = 0; i < EHEA_MAX_PORTS; i++)
3327 if (adapter->port[i] == port) {
3328 adapter->port[i] = NULL;
3332 ehea_error("removing port with logical port id=%d failed. port "
3333 "not configured.", logical_port_id);
3337 ehea_remove_adapter_mr(adapter);
3339 return (ssize_t) count;
3342 static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3343 static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3345 int ehea_create_device_sysfs(struct of_device *dev)
3347 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
3351 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
3356 void ehea_remove_device_sysfs(struct of_device *dev)
3358 device_remove_file(&dev->dev, &dev_attr_probe_port);
3359 device_remove_file(&dev->dev, &dev_attr_remove_port);
3362 static int __devinit ehea_probe_adapter(struct of_device *dev,
3363 const struct of_device_id *id)
3365 struct ehea_adapter *adapter;
3366 const u64 *adapter_handle;
3369 if (!dev || !dev->node) {
3370 ehea_error("Invalid ibmebus device probed");
3373 mutex_lock(&ehea_fw_handles.lock);
3375 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3378 dev_err(&dev->dev, "no mem for ehea_adapter\n");
3382 list_add(&adapter->list, &adapter_list);
3384 adapter->ofdev = dev;
3386 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
3389 adapter->handle = *adapter_handle;
3391 if (!adapter->handle) {
3392 dev_err(&dev->dev, "failed getting handle for adapter"
3393 " '%s'\n", dev->node->full_name);
3398 adapter->pd = EHEA_PD_ID;
3400 dev->dev.driver_data = adapter;
3403 /* initialize adapter and ports */
3404 /* get adapter properties */
3405 ret = ehea_sense_adapter_attr(adapter);
3407 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
3411 adapter->neq = ehea_create_eq(adapter,
3412 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3413 if (!adapter->neq) {
3415 dev_err(&dev->dev, "NEQ creation failed\n");
3419 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3420 (unsigned long)adapter);
3422 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
3423 ehea_interrupt_neq, IRQF_DISABLED,
3424 "ehea_neq", adapter);
3426 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3430 ret = ehea_create_device_sysfs(dev);
3434 ret = ehea_setup_ports(adapter);
3436 dev_err(&dev->dev, "setup_ports failed\n");
3437 goto out_rem_dev_sysfs;
3444 ehea_remove_device_sysfs(dev);
3447 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
3450 ehea_destroy_eq(adapter->neq);
3456 ehea_update_firmware_handles();
3457 mutex_unlock(&ehea_fw_handles.lock);
3461 static int __devexit ehea_remove(struct of_device *dev)
3463 struct ehea_adapter *adapter = dev->dev.driver_data;
3466 for (i = 0; i < EHEA_MAX_PORTS; i++)
3467 if (adapter->port[i]) {
3468 ehea_shutdown_single_port(adapter->port[i]);
3469 adapter->port[i] = NULL;
3472 ehea_remove_device_sysfs(dev);
3474 flush_scheduled_work();
3476 mutex_lock(&ehea_fw_handles.lock);
3478 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
3479 tasklet_kill(&adapter->neq_tasklet);
3481 ehea_destroy_eq(adapter->neq);
3482 ehea_remove_adapter_mr(adapter);
3483 list_del(&adapter->list);
3486 ehea_update_firmware_handles();
3487 mutex_unlock(&ehea_fw_handles.lock);
3492 void ehea_crash_handler(void)
3496 if (ehea_fw_handles.arr)
3497 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3498 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3499 ehea_fw_handles.arr[i].fwh,
3502 if (ehea_bcmc_regs.arr)
3503 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3504 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3505 ehea_bcmc_regs.arr[i].port_id,
3506 ehea_bcmc_regs.arr[i].reg_type,
3507 ehea_bcmc_regs.arr[i].macaddr,
3511 static int ehea_mem_notifier(struct notifier_block *nb,
3512 unsigned long action, void *data)
3516 ehea_info("memory has been removed");
3517 ehea_rereg_mrs(NULL);
3525 static struct notifier_block ehea_mem_nb = {
3526 .notifier_call = ehea_mem_notifier,
3529 static int ehea_reboot_notifier(struct notifier_block *nb,
3530 unsigned long action, void *unused)
3532 if (action == SYS_RESTART) {
3533 ehea_info("Reboot: freeing all eHEA resources");
3534 ibmebus_unregister_driver(&ehea_driver);
3539 static struct notifier_block ehea_reboot_nb = {
3540 .notifier_call = ehea_reboot_notifier,
3543 static int check_module_parm(void)
3547 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3548 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3549 ehea_info("Bad parameter: rq1_entries");
3552 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3553 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3554 ehea_info("Bad parameter: rq2_entries");
3557 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3558 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3559 ehea_info("Bad parameter: rq3_entries");
3562 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3563 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3564 ehea_info("Bad parameter: sq_entries");
3571 static ssize_t ehea_show_capabilities(struct device_driver *drv,
3574 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3577 static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3578 ehea_show_capabilities, NULL);
3580 int __init ehea_module_init(void)
3584 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3588 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
3589 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3590 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3592 mutex_init(&ehea_fw_handles.lock);
3593 mutex_init(&ehea_bcmc_regs.lock);
3595 ret = check_module_parm();
3599 ret = ehea_create_busmap();
3603 ret = register_reboot_notifier(&ehea_reboot_nb);
3605 ehea_info("failed registering reboot notifier");
3607 ret = register_memory_notifier(&ehea_mem_nb);
3609 ehea_info("failed registering memory remove notifier");
3611 ret = crash_shutdown_register(&ehea_crash_handler);
3613 ehea_info("failed registering crash handler");
3615 ret = ibmebus_register_driver(&ehea_driver);
3617 ehea_error("failed registering eHEA device driver on ebus");
3621 ret = driver_create_file(&ehea_driver.driver,
3622 &driver_attr_capabilities);
3624 ehea_error("failed to register capabilities attribute, ret=%d",
3632 ibmebus_unregister_driver(&ehea_driver);
3634 unregister_memory_notifier(&ehea_mem_nb);
3635 unregister_reboot_notifier(&ehea_reboot_nb);
3636 crash_shutdown_unregister(&ehea_crash_handler);
3641 static void __exit ehea_module_exit(void)
3645 flush_scheduled_work();
3646 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
3647 ibmebus_unregister_driver(&ehea_driver);
3648 unregister_reboot_notifier(&ehea_reboot_nb);
3649 ret = crash_shutdown_unregister(&ehea_crash_handler);
3651 ehea_info("failed unregistering crash handler");
3652 unregister_memory_notifier(&ehea_mem_nb);
3653 kfree(ehea_fw_handles.arr);
3654 kfree(ehea_bcmc_regs.arr);
3655 ehea_destroy_busmap();
3658 module_init(ehea_module_init);
3659 module_exit(ehea_module_exit);