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",
121 MODULE_DEVICE_TABLE(of, ehea_device_table);
123 static struct of_platform_driver ehea_driver = {
125 .match_table = ehea_device_table,
126 .probe = ehea_probe_adapter,
127 .remove = ehea_remove,
130 void ehea_dump(void *adr, int len, char *msg)
133 unsigned char *deb = adr;
134 for (x = 0; x < len; x += 16) {
135 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
136 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
141 void ehea_schedule_port_reset(struct ehea_port *port)
143 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
144 schedule_work(&port->reset_task);
147 static void ehea_update_firmware_handles(void)
149 struct ehea_fw_handle_entry *arr = NULL;
150 struct ehea_adapter *adapter;
151 int num_adapters = 0;
155 int num_fw_handles, k, l;
157 /* Determine number of handles */
158 list_for_each_entry(adapter, &adapter_list, list) {
161 for (k = 0; k < EHEA_MAX_PORTS; k++) {
162 struct ehea_port *port = adapter->port[k];
164 if (!port || (port->state != EHEA_PORT_UP))
168 num_portres += port->num_def_qps + port->num_add_tx_qps;
172 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
173 num_ports * EHEA_NUM_PORT_FW_HANDLES +
174 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
176 if (num_fw_handles) {
177 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
179 return; /* Keep the existing array */
183 list_for_each_entry(adapter, &adapter_list, list) {
184 for (k = 0; k < EHEA_MAX_PORTS; k++) {
185 struct ehea_port *port = adapter->port[k];
187 if (!port || (port->state != EHEA_PORT_UP))
191 l < port->num_def_qps + port->num_add_tx_qps;
193 struct ehea_port_res *pr = &port->port_res[l];
195 arr[i].adh = adapter->handle;
196 arr[i++].fwh = pr->qp->fw_handle;
197 arr[i].adh = adapter->handle;
198 arr[i++].fwh = pr->send_cq->fw_handle;
199 arr[i].adh = adapter->handle;
200 arr[i++].fwh = pr->recv_cq->fw_handle;
201 arr[i].adh = adapter->handle;
202 arr[i++].fwh = pr->eq->fw_handle;
203 arr[i].adh = adapter->handle;
204 arr[i++].fwh = pr->send_mr.handle;
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = pr->recv_mr.handle;
208 arr[i].adh = adapter->handle;
209 arr[i++].fwh = port->qp_eq->fw_handle;
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = adapter->neq->fw_handle;
215 if (adapter->mr.handle) {
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = adapter->mr.handle;
222 kfree(ehea_fw_handles.arr);
223 ehea_fw_handles.arr = arr;
224 ehea_fw_handles.num_entries = i;
227 static void ehea_update_bcmc_registrations(void)
229 struct ehea_bcmc_reg_entry *arr = NULL;
230 struct ehea_adapter *adapter;
231 struct ehea_mc_list *mc_entry;
232 int num_registrations = 0;
236 /* Determine number of registrations */
237 list_for_each_entry(adapter, &adapter_list, list)
238 for (k = 0; k < EHEA_MAX_PORTS; k++) {
239 struct ehea_port *port = adapter->port[k];
241 if (!port || (port->state != EHEA_PORT_UP))
244 num_registrations += 2; /* Broadcast registrations */
246 list_for_each_entry(mc_entry, &port->mc_list->list,list)
247 num_registrations += 2;
250 if (num_registrations) {
251 arr = kzalloc(num_registrations * sizeof(*arr), GFP_ATOMIC);
253 return; /* Keep the existing array */
257 list_for_each_entry(adapter, &adapter_list, list) {
258 for (k = 0; k < EHEA_MAX_PORTS; k++) {
259 struct ehea_port *port = adapter->port[k];
261 if (!port || (port->state != EHEA_PORT_UP))
264 arr[i].adh = adapter->handle;
265 arr[i].port_id = port->logical_port_id;
266 arr[i].reg_type = EHEA_BCMC_BROADCAST |
268 arr[i++].macaddr = port->mac_addr;
270 arr[i].adh = adapter->handle;
271 arr[i].port_id = port->logical_port_id;
272 arr[i].reg_type = EHEA_BCMC_BROADCAST |
273 EHEA_BCMC_VLANID_ALL;
274 arr[i++].macaddr = port->mac_addr;
276 list_for_each_entry(mc_entry,
277 &port->mc_list->list, list) {
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 |
283 arr[i++].macaddr = mc_entry->macaddr;
285 arr[i].adh = adapter->handle;
286 arr[i].port_id = port->logical_port_id;
287 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
288 EHEA_BCMC_MULTICAST |
289 EHEA_BCMC_VLANID_ALL;
290 arr[i++].macaddr = mc_entry->macaddr;
296 kfree(ehea_bcmc_regs.arr);
297 ehea_bcmc_regs.arr = arr;
298 ehea_bcmc_regs.num_entries = i;
301 static struct net_device_stats *ehea_get_stats(struct net_device *dev)
303 struct ehea_port *port = netdev_priv(dev);
304 struct net_device_stats *stats = &port->stats;
305 struct hcp_ehea_port_cb2 *cb2;
306 u64 hret, rx_packets, tx_packets;
309 memset(stats, 0, sizeof(*stats));
311 cb2 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
313 ehea_error("no mem for cb2");
317 hret = ehea_h_query_ehea_port(port->adapter->handle,
318 port->logical_port_id,
319 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
320 if (hret != H_SUCCESS) {
321 ehea_error("query_ehea_port failed");
325 if (netif_msg_hw(port))
326 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
329 for (i = 0; i < port->num_def_qps; i++)
330 rx_packets += port->port_res[i].rx_packets;
333 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
334 tx_packets += port->port_res[i].tx_packets;
336 stats->tx_packets = tx_packets;
337 stats->multicast = cb2->rxmcp;
338 stats->rx_errors = cb2->rxuerr;
339 stats->rx_bytes = cb2->rxo;
340 stats->tx_bytes = cb2->txo;
341 stats->rx_packets = rx_packets;
349 static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
351 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
352 struct net_device *dev = pr->port->netdev;
353 int max_index_mask = pr->rq1_skba.len - 1;
354 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
358 pr->rq1_skba.os_skbs = 0;
360 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
362 pr->rq1_skba.index = index;
363 pr->rq1_skba.os_skbs = fill_wqes;
367 for (i = 0; i < fill_wqes; i++) {
368 if (!skb_arr_rq1[index]) {
369 skb_arr_rq1[index] = netdev_alloc_skb(dev,
371 if (!skb_arr_rq1[index]) {
372 pr->rq1_skba.os_skbs = fill_wqes - i;
373 ehea_error("%s: no mem for skb/%d wqes filled",
379 index &= max_index_mask;
387 ehea_update_rq1a(pr->qp, adder);
390 static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
393 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
394 struct net_device *dev = pr->port->netdev;
397 for (i = 0; i < pr->rq1_skba.len; i++) {
398 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
399 if (!skb_arr_rq1[i]) {
400 ehea_error("%s: no mem for skb/%d wqes filled",
407 ehea_update_rq1a(pr->qp, nr_rq1a);
412 static int ehea_refill_rq_def(struct ehea_port_res *pr,
413 struct ehea_q_skb_arr *q_skba, int rq_nr,
414 int num_wqes, int wqe_type, int packet_size)
416 struct net_device *dev = pr->port->netdev;
417 struct ehea_qp *qp = pr->qp;
418 struct sk_buff **skb_arr = q_skba->arr;
419 struct ehea_rwqe *rwqe;
420 int i, index, max_index_mask, fill_wqes;
424 fill_wqes = q_skba->os_skbs + num_wqes;
427 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
428 q_skba->os_skbs = fill_wqes;
432 index = q_skba->index;
433 max_index_mask = q_skba->len - 1;
434 for (i = 0; i < fill_wqes; i++) {
436 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
438 ehea_error("%s: no mem for skb/%d wqes filled",
439 pr->port->netdev->name, i);
440 q_skba->os_skbs = fill_wqes - i;
444 skb_reserve(skb, NET_IP_ALIGN);
446 skb_arr[index] = skb;
447 tmp_addr = ehea_map_vaddr(skb->data);
448 if (tmp_addr == -1) {
450 q_skba->os_skbs = fill_wqes - i;
455 rwqe = ehea_get_next_rwqe(qp, rq_nr);
456 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
457 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
458 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
459 rwqe->sg_list[0].vaddr = tmp_addr;
460 rwqe->sg_list[0].len = packet_size;
461 rwqe->data_segments = 1;
464 index &= max_index_mask;
468 q_skba->index = index;
475 ehea_update_rq2a(pr->qp, adder);
477 ehea_update_rq3a(pr->qp, adder);
483 static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
485 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
486 nr_of_wqes, EHEA_RWQE2_TYPE,
487 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
491 static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
493 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
494 nr_of_wqes, EHEA_RWQE3_TYPE,
495 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
498 static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
500 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
501 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
503 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
504 (cqe->header_length == 0))
509 static inline void ehea_fill_skb(struct net_device *dev,
510 struct sk_buff *skb, struct ehea_cqe *cqe)
512 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
514 skb_put(skb, length);
515 skb->ip_summed = CHECKSUM_UNNECESSARY;
516 skb->protocol = eth_type_trans(skb, dev);
519 static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
521 struct ehea_cqe *cqe)
523 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
533 prefetchw(pref + EHEA_CACHE_LINE);
535 pref = (skb_array[x]->data);
537 prefetch(pref + EHEA_CACHE_LINE);
538 prefetch(pref + EHEA_CACHE_LINE * 2);
539 prefetch(pref + EHEA_CACHE_LINE * 3);
540 skb = skb_array[skb_index];
541 skb_array[skb_index] = NULL;
545 static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
546 int arr_len, int wqe_index)
557 prefetchw(pref + EHEA_CACHE_LINE);
559 pref = (skb_array[x]->data);
561 prefetchw(pref + EHEA_CACHE_LINE);
563 skb = skb_array[wqe_index];
564 skb_array[wqe_index] = NULL;
568 static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
569 struct ehea_cqe *cqe, int *processed_rq2,
574 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
575 pr->p_stats.err_tcp_cksum++;
576 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
577 pr->p_stats.err_ip_cksum++;
578 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
579 pr->p_stats.err_frame_crc++;
583 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
585 } else if (rq == 3) {
587 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
591 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
592 if (netif_msg_rx_err(pr->port)) {
593 ehea_error("Critical receive error for QP %d. "
594 "Resetting port.", pr->qp->init_attr.qp_nr);
595 ehea_dump(cqe, sizeof(*cqe), "CQE");
597 ehea_schedule_port_reset(pr->port);
604 static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
605 void **tcph, u64 *hdr_flags, void *priv)
607 struct ehea_cqe *cqe = priv;
611 /* non tcp/udp packets */
612 if (!cqe->header_length)
616 skb_reset_network_header(skb);
618 if (iph->protocol != IPPROTO_TCP)
621 ip_len = ip_hdrlen(skb);
622 skb_set_transport_header(skb, ip_len);
623 *tcph = tcp_hdr(skb);
625 /* check if ip header and tcp header are complete */
626 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
629 *hdr_flags = LRO_IPV4 | LRO_TCP;
635 static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
638 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
643 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
648 lro_receive_skb(&pr->lro_mgr, skb, cqe);
651 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
654 netif_receive_skb(skb);
658 static int ehea_proc_rwqes(struct net_device *dev,
659 struct ehea_port_res *pr,
662 struct ehea_port *port = pr->port;
663 struct ehea_qp *qp = pr->qp;
664 struct ehea_cqe *cqe;
666 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
667 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
668 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
669 int skb_arr_rq1_len = pr->rq1_skba.len;
670 int skb_arr_rq2_len = pr->rq2_skba.len;
671 int skb_arr_rq3_len = pr->rq3_skba.len;
672 int processed, processed_rq1, processed_rq2, processed_rq3;
673 int wqe_index, last_wqe_index, rq, port_reset;
675 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
678 cqe = ehea_poll_rq1(qp, &wqe_index);
679 while ((processed < budget) && cqe) {
683 if (netif_msg_rx_status(port))
684 ehea_dump(cqe, sizeof(*cqe), "CQE");
686 last_wqe_index = wqe_index;
688 if (!ehea_check_cqe(cqe, &rq)) {
691 skb = get_skb_by_index_ll(skb_arr_rq1,
694 if (unlikely(!skb)) {
695 if (netif_msg_rx_err(port))
696 ehea_error("LL rq1: skb=NULL");
698 skb = netdev_alloc_skb(dev,
703 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
704 cqe->num_bytes_transfered - 4);
705 ehea_fill_skb(dev, skb, cqe);
706 } else if (rq == 2) {
708 skb = get_skb_by_index(skb_arr_rq2,
709 skb_arr_rq2_len, cqe);
710 if (unlikely(!skb)) {
711 if (netif_msg_rx_err(port))
712 ehea_error("rq2: skb=NULL");
715 ehea_fill_skb(dev, skb, cqe);
719 skb = get_skb_by_index(skb_arr_rq3,
720 skb_arr_rq3_len, cqe);
721 if (unlikely(!skb)) {
722 if (netif_msg_rx_err(port))
723 ehea_error("rq3: skb=NULL");
726 ehea_fill_skb(dev, skb, cqe);
730 ehea_proc_skb(pr, cqe, skb);
731 dev->last_rx = jiffies;
733 pr->p_stats.poll_receive_errors++;
734 port_reset = ehea_treat_poll_error(pr, rq, cqe,
740 cqe = ehea_poll_rq1(qp, &wqe_index);
743 lro_flush_all(&pr->lro_mgr);
745 pr->rx_packets += processed;
747 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
748 ehea_refill_rq2(pr, processed_rq2);
749 ehea_refill_rq3(pr, processed_rq3);
754 static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
757 struct ehea_cq *send_cq = pr->send_cq;
758 struct ehea_cqe *cqe;
759 int quota = my_quota;
765 cqe = ehea_poll_cq(send_cq);
766 while (cqe && (quota > 0)) {
767 ehea_inc_cq(send_cq);
771 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
772 ehea_error("Send Completion Error: Resetting port");
773 if (netif_msg_tx_err(pr->port))
774 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
775 ehea_schedule_port_reset(pr->port);
779 if (netif_msg_tx_done(pr->port))
780 ehea_dump(cqe, sizeof(*cqe), "CQE");
782 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
783 == EHEA_SWQE2_TYPE)) {
785 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
786 skb = pr->sq_skba.arr[index];
788 pr->sq_skba.arr[index] = NULL;
791 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
794 cqe = ehea_poll_cq(send_cq);
797 ehea_update_feca(send_cq, cqe_counter);
798 atomic_add(swqe_av, &pr->swqe_avail);
800 spin_lock_irqsave(&pr->netif_queue, flags);
802 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
803 >= pr->swqe_refill_th)) {
804 netif_wake_queue(pr->port->netdev);
805 pr->queue_stopped = 0;
807 spin_unlock_irqrestore(&pr->netif_queue, flags);
812 #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
813 #define EHEA_POLL_MAX_CQES 65535
815 static int ehea_poll(struct napi_struct *napi, int budget)
817 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
819 struct net_device *dev = pr->port->netdev;
820 struct ehea_cqe *cqe;
821 struct ehea_cqe *cqe_skb = NULL;
822 int force_irq, wqe_index;
825 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
826 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
829 rx += ehea_proc_rwqes(dev, pr, budget - rx);
831 while ((rx != budget) || force_irq) {
832 pr->poll_counter = 0;
834 netif_rx_complete(dev, napi);
835 ehea_reset_cq_ep(pr->recv_cq);
836 ehea_reset_cq_ep(pr->send_cq);
837 ehea_reset_cq_n1(pr->recv_cq);
838 ehea_reset_cq_n1(pr->send_cq);
839 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
840 cqe_skb = ehea_poll_cq(pr->send_cq);
842 if (!cqe && !cqe_skb)
845 if (!netif_rx_reschedule(dev, napi))
848 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
849 rx += ehea_proc_rwqes(dev, pr, budget - rx);
856 #ifdef CONFIG_NET_POLL_CONTROLLER
857 static void ehea_netpoll(struct net_device *dev)
859 struct ehea_port *port = netdev_priv(dev);
862 for (i = 0; i < port->num_def_qps; i++)
863 netif_rx_schedule(dev, &port->port_res[i].napi);
867 static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
869 struct ehea_port_res *pr = param;
871 netif_rx_schedule(pr->port->netdev, &pr->napi);
876 static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
878 struct ehea_port *port = param;
879 struct ehea_eqe *eqe;
883 eqe = ehea_poll_eq(port->qp_eq);
886 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
887 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
888 eqe->entry, qp_token);
890 qp = port->port_res[qp_token].qp;
891 ehea_error_data(port->adapter, qp->fw_handle);
892 eqe = ehea_poll_eq(port->qp_eq);
895 ehea_schedule_port_reset(port);
900 static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
905 for (i = 0; i < EHEA_MAX_PORTS; i++)
906 if (adapter->port[i])
907 if (adapter->port[i]->logical_port_id == logical_port)
908 return adapter->port[i];
912 int ehea_sense_port_attr(struct ehea_port *port)
916 struct hcp_ehea_port_cb0 *cb0;
918 /* may be called via ehea_neq_tasklet() */
919 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
921 ehea_error("no mem for cb0");
926 hret = ehea_h_query_ehea_port(port->adapter->handle,
927 port->logical_port_id, H_PORT_CB0,
928 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
930 if (hret != H_SUCCESS) {
936 port->mac_addr = cb0->port_mac_addr << 16;
938 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
939 ret = -EADDRNOTAVAIL;
944 switch (cb0->port_speed) {
946 port->port_speed = EHEA_SPEED_10M;
947 port->full_duplex = 0;
950 port->port_speed = EHEA_SPEED_10M;
951 port->full_duplex = 1;
954 port->port_speed = EHEA_SPEED_100M;
955 port->full_duplex = 0;
958 port->port_speed = EHEA_SPEED_100M;
959 port->full_duplex = 1;
962 port->port_speed = EHEA_SPEED_1G;
963 port->full_duplex = 1;
966 port->port_speed = EHEA_SPEED_10G;
967 port->full_duplex = 1;
970 port->port_speed = 0;
971 port->full_duplex = 0;
976 port->num_mcs = cb0->num_default_qps;
978 /* Number of default QPs */
980 port->num_def_qps = cb0->num_default_qps;
982 port->num_def_qps = 1;
984 if (!port->num_def_qps) {
989 port->num_tx_qps = num_tx_qps;
991 if (port->num_def_qps >= port->num_tx_qps)
992 port->num_add_tx_qps = 0;
994 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
998 if (ret || netif_msg_probe(port))
999 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
1005 int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1007 struct hcp_ehea_port_cb4 *cb4;
1011 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1013 ehea_error("no mem for cb4");
1018 cb4->port_speed = port_speed;
1020 netif_carrier_off(port->netdev);
1022 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1023 port->logical_port_id,
1024 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1025 if (hret == H_SUCCESS) {
1026 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1028 hret = ehea_h_query_ehea_port(port->adapter->handle,
1029 port->logical_port_id,
1030 H_PORT_CB4, H_PORT_CB4_SPEED,
1032 if (hret == H_SUCCESS) {
1033 switch (cb4->port_speed) {
1035 port->port_speed = EHEA_SPEED_10M;
1036 port->full_duplex = 0;
1039 port->port_speed = EHEA_SPEED_10M;
1040 port->full_duplex = 1;
1042 case H_SPEED_100M_H:
1043 port->port_speed = EHEA_SPEED_100M;
1044 port->full_duplex = 0;
1046 case H_SPEED_100M_F:
1047 port->port_speed = EHEA_SPEED_100M;
1048 port->full_duplex = 1;
1051 port->port_speed = EHEA_SPEED_1G;
1052 port->full_duplex = 1;
1055 port->port_speed = EHEA_SPEED_10G;
1056 port->full_duplex = 1;
1059 port->port_speed = 0;
1060 port->full_duplex = 0;
1064 ehea_error("Failed sensing port speed");
1068 if (hret == H_AUTHORITY) {
1069 ehea_info("Hypervisor denied setting port speed");
1073 ehea_error("Failed setting port speed");
1076 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1077 netif_carrier_on(port->netdev);
1084 static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1089 struct ehea_port *port;
1091 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1092 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1093 port = ehea_get_port(adapter, portnum);
1096 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1099 ehea_error("unknown portnum %x", portnum);
1103 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1104 if (!netif_carrier_ok(port->netdev)) {
1105 ret = ehea_sense_port_attr(port);
1107 ehea_error("failed resensing port "
1112 if (netif_msg_link(port))
1113 ehea_info("%s: Logical port up: %dMbps "
1117 port->full_duplex ==
1118 1 ? "Full" : "Half");
1120 netif_carrier_on(port->netdev);
1121 netif_wake_queue(port->netdev);
1124 if (netif_carrier_ok(port->netdev)) {
1125 if (netif_msg_link(port))
1126 ehea_info("%s: Logical port down",
1127 port->netdev->name);
1128 netif_carrier_off(port->netdev);
1129 netif_stop_queue(port->netdev);
1132 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
1133 port->phy_link = EHEA_PHY_LINK_UP;
1134 if (netif_msg_link(port))
1135 ehea_info("%s: Physical port up",
1136 port->netdev->name);
1137 if (prop_carrier_state)
1138 netif_carrier_on(port->netdev);
1140 port->phy_link = EHEA_PHY_LINK_DOWN;
1141 if (netif_msg_link(port))
1142 ehea_info("%s: Physical port down",
1143 port->netdev->name);
1144 if (prop_carrier_state)
1145 netif_carrier_off(port->netdev);
1148 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1149 ehea_info("External switch port is primary port");
1151 ehea_info("External switch port is backup port");
1154 case EHEA_EC_ADAPTER_MALFUNC:
1155 ehea_error("Adapter malfunction");
1157 case EHEA_EC_PORT_MALFUNC:
1158 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1159 netif_carrier_off(port->netdev);
1160 netif_stop_queue(port->netdev);
1163 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
1168 static void ehea_neq_tasklet(unsigned long data)
1170 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
1171 struct ehea_eqe *eqe;
1174 eqe = ehea_poll_eq(adapter->neq);
1175 ehea_debug("eqe=%p", eqe);
1178 ehea_debug("*eqe=%lx", eqe->entry);
1179 ehea_parse_eqe(adapter, eqe->entry);
1180 eqe = ehea_poll_eq(adapter->neq);
1181 ehea_debug("next eqe=%p", eqe);
1184 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1185 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1186 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1188 ehea_h_reset_events(adapter->handle,
1189 adapter->neq->fw_handle, event_mask);
1192 static irqreturn_t ehea_interrupt_neq(int irq, void *param)
1194 struct ehea_adapter *adapter = param;
1195 tasklet_hi_schedule(&adapter->neq_tasklet);
1200 static int ehea_fill_port_res(struct ehea_port_res *pr)
1203 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1205 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1206 - init_attr->act_nr_rwqes_rq2
1207 - init_attr->act_nr_rwqes_rq3 - 1);
1209 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
1211 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1216 static int ehea_reg_interrupts(struct net_device *dev)
1218 struct ehea_port *port = netdev_priv(dev);
1219 struct ehea_port_res *pr;
1223 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1226 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
1227 ehea_qp_aff_irq_handler,
1228 IRQF_DISABLED, port->int_aff_name, port);
1230 ehea_error("failed registering irq for qp_aff_irq_handler:"
1231 "ist=%X", port->qp_eq->attr.ist1);
1235 if (netif_msg_ifup(port))
1236 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1237 "registered", port->qp_eq->attr.ist1);
1240 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1241 pr = &port->port_res[i];
1242 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
1243 "%s-queue%d", dev->name, i);
1244 ret = ibmebus_request_irq(pr->eq->attr.ist1,
1245 ehea_recv_irq_handler,
1246 IRQF_DISABLED, pr->int_send_name,
1249 ehea_error("failed registering irq for ehea_queue "
1250 "port_res_nr:%d, ist=%X", i,
1254 if (netif_msg_ifup(port))
1255 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1256 "%d registered", pr->eq->attr.ist1, i);
1264 u32 ist = port->port_res[i].eq->attr.ist1;
1265 ibmebus_free_irq(ist, &port->port_res[i]);
1269 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
1270 i = port->num_def_qps;
1276 static void ehea_free_interrupts(struct net_device *dev)
1278 struct ehea_port *port = netdev_priv(dev);
1279 struct ehea_port_res *pr;
1284 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1285 pr = &port->port_res[i];
1286 ibmebus_free_irq(pr->eq->attr.ist1, pr);
1287 if (netif_msg_intr(port))
1288 ehea_info("free send irq for res %d with handle 0x%X",
1289 i, pr->eq->attr.ist1);
1292 /* associated events */
1293 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
1294 if (netif_msg_intr(port))
1295 ehea_info("associated event interrupt for handle 0x%X freed",
1296 port->qp_eq->attr.ist1);
1299 static int ehea_configure_port(struct ehea_port *port)
1303 struct hcp_ehea_port_cb0 *cb0;
1306 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1310 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1311 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1312 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1313 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1314 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1315 PXLY_RC_VLAN_FILTER)
1316 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1318 for (i = 0; i < port->num_mcs; i++)
1320 cb0->default_qpn_arr[i] =
1321 port->port_res[i].qp->init_attr.qp_nr;
1323 cb0->default_qpn_arr[i] =
1324 port->port_res[0].qp->init_attr.qp_nr;
1326 if (netif_msg_ifup(port))
1327 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1329 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1330 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1332 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1333 port->logical_port_id,
1334 H_PORT_CB0, mask, cb0);
1336 if (hret != H_SUCCESS)
1347 int ehea_gen_smrs(struct ehea_port_res *pr)
1350 struct ehea_adapter *adapter = pr->port->adapter;
1352 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1356 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1363 ehea_rem_mr(&pr->send_mr);
1365 ehea_error("Generating SMRS failed\n");
1369 int ehea_rem_smrs(struct ehea_port_res *pr)
1371 if ((ehea_rem_mr(&pr->send_mr))
1372 || (ehea_rem_mr(&pr->recv_mr)))
1378 static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1380 int arr_size = sizeof(void *) * max_q_entries;
1382 q_skba->arr = vmalloc(arr_size);
1386 memset(q_skba->arr, 0, arr_size);
1388 q_skba->len = max_q_entries;
1390 q_skba->os_skbs = 0;
1395 static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1396 struct port_res_cfg *pr_cfg, int queue_token)
1398 struct ehea_adapter *adapter = port->adapter;
1399 enum ehea_eq_type eq_type = EHEA_EQ;
1400 struct ehea_qp_init_attr *init_attr = NULL;
1403 memset(pr, 0, sizeof(struct ehea_port_res));
1406 spin_lock_init(&pr->xmit_lock);
1407 spin_lock_init(&pr->netif_queue);
1409 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1411 ehea_error("create_eq failed (eq)");
1415 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
1417 port->logical_port_id);
1419 ehea_error("create_cq failed (cq_recv)");
1423 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
1425 port->logical_port_id);
1427 ehea_error("create_cq failed (cq_send)");
1431 if (netif_msg_ifup(port))
1432 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1433 pr->send_cq->attr.act_nr_of_cqes,
1434 pr->recv_cq->attr.act_nr_of_cqes);
1436 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1439 ehea_error("no mem for ehea_qp_init_attr");
1443 init_attr->low_lat_rq1 = 1;
1444 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1445 init_attr->rq_count = 3;
1446 init_attr->qp_token = queue_token;
1447 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1448 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1449 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1450 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1451 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1452 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1453 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1454 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1455 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1456 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1457 init_attr->port_nr = port->logical_port_id;
1458 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1459 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1460 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1462 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1464 ehea_error("create_qp failed");
1469 if (netif_msg_ifup(port))
1470 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1471 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1472 init_attr->act_nr_send_wqes,
1473 init_attr->act_nr_rwqes_rq1,
1474 init_attr->act_nr_rwqes_rq2,
1475 init_attr->act_nr_rwqes_rq3);
1477 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1479 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
1480 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1481 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1482 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1486 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1487 if (ehea_gen_smrs(pr) != 0) {
1492 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1496 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
1498 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1499 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1500 pr->lro_mgr.lro_arr = pr->lro_desc;
1501 pr->lro_mgr.get_skb_header = get_skb_hdr;
1502 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1503 pr->lro_mgr.dev = port->netdev;
1504 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1505 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1512 vfree(pr->sq_skba.arr);
1513 vfree(pr->rq1_skba.arr);
1514 vfree(pr->rq2_skba.arr);
1515 vfree(pr->rq3_skba.arr);
1516 ehea_destroy_qp(pr->qp);
1517 ehea_destroy_cq(pr->send_cq);
1518 ehea_destroy_cq(pr->recv_cq);
1519 ehea_destroy_eq(pr->eq);
1524 static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1528 ret = ehea_destroy_qp(pr->qp);
1531 ehea_destroy_cq(pr->send_cq);
1532 ehea_destroy_cq(pr->recv_cq);
1533 ehea_destroy_eq(pr->eq);
1535 for (i = 0; i < pr->rq1_skba.len; i++)
1536 if (pr->rq1_skba.arr[i])
1537 dev_kfree_skb(pr->rq1_skba.arr[i]);
1539 for (i = 0; i < pr->rq2_skba.len; i++)
1540 if (pr->rq2_skba.arr[i])
1541 dev_kfree_skb(pr->rq2_skba.arr[i]);
1543 for (i = 0; i < pr->rq3_skba.len; i++)
1544 if (pr->rq3_skba.arr[i])
1545 dev_kfree_skb(pr->rq3_skba.arr[i]);
1547 for (i = 0; i < pr->sq_skba.len; i++)
1548 if (pr->sq_skba.arr[i])
1549 dev_kfree_skb(pr->sq_skba.arr[i]);
1551 vfree(pr->rq1_skba.arr);
1552 vfree(pr->rq2_skba.arr);
1553 vfree(pr->rq3_skba.arr);
1554 vfree(pr->sq_skba.arr);
1555 ret = ehea_rem_smrs(pr);
1561 * The write_* functions store information in swqe which is used by
1562 * the hardware to calculate the ip/tcp/udp checksum
1565 static inline void write_ip_start_end(struct ehea_swqe *swqe,
1566 const struct sk_buff *skb)
1568 swqe->ip_start = skb_network_offset(skb);
1569 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
1572 static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1573 const struct sk_buff *skb)
1576 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1578 swqe->tcp_end = (u16)skb->len - 1;
1581 static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1582 const struct sk_buff *skb)
1585 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1587 swqe->tcp_end = (u16)skb->len - 1;
1591 static void write_swqe2_TSO(struct sk_buff *skb,
1592 struct ehea_swqe *swqe, u32 lkey)
1594 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1595 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1596 int skb_data_size = skb->len - skb->data_len;
1599 /* Packet is TCP with TSO enabled */
1600 swqe->tx_control |= EHEA_SWQE_TSO;
1601 swqe->mss = skb_shinfo(skb)->gso_size;
1602 /* copy only eth/ip/tcp headers to immediate data and
1603 * the rest of skb->data to sg1entry
1605 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1607 skb_data_size = skb->len - skb->data_len;
1609 if (skb_data_size >= headersize) {
1610 /* copy immediate data */
1611 skb_copy_from_linear_data(skb, imm_data, headersize);
1612 swqe->immediate_data_length = headersize;
1614 if (skb_data_size > headersize) {
1615 /* set sg1entry data */
1616 sg1entry->l_key = lkey;
1617 sg1entry->len = skb_data_size - headersize;
1619 ehea_map_vaddr(skb->data + headersize);
1620 swqe->descriptors++;
1623 ehea_error("cannot handle fragmented headers");
1626 static void write_swqe2_nonTSO(struct sk_buff *skb,
1627 struct ehea_swqe *swqe, u32 lkey)
1629 int skb_data_size = skb->len - skb->data_len;
1630 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1631 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1633 /* Packet is any nonTSO type
1635 * Copy as much as possible skb->data to immediate data and
1636 * the rest to sg1entry
1638 if (skb_data_size >= SWQE2_MAX_IMM) {
1639 /* copy immediate data */
1640 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
1642 swqe->immediate_data_length = SWQE2_MAX_IMM;
1644 if (skb_data_size > SWQE2_MAX_IMM) {
1645 /* copy sg1entry data */
1646 sg1entry->l_key = lkey;
1647 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
1649 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
1650 swqe->descriptors++;
1653 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
1654 swqe->immediate_data_length = skb_data_size;
1658 static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1659 struct ehea_swqe *swqe, u32 lkey)
1661 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1663 int nfrags, sg1entry_contains_frag_data, i;
1665 nfrags = skb_shinfo(skb)->nr_frags;
1666 sg1entry = &swqe->u.immdata_desc.sg_entry;
1667 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
1668 swqe->descriptors = 0;
1669 sg1entry_contains_frag_data = 0;
1671 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1672 write_swqe2_TSO(skb, swqe, lkey);
1674 write_swqe2_nonTSO(skb, swqe, lkey);
1676 /* write descriptors */
1678 if (swqe->descriptors == 0) {
1679 /* sg1entry not yet used */
1680 frag = &skb_shinfo(skb)->frags[0];
1682 /* copy sg1entry data */
1683 sg1entry->l_key = lkey;
1684 sg1entry->len = frag->size;
1686 ehea_map_vaddr(page_address(frag->page)
1687 + frag->page_offset);
1688 swqe->descriptors++;
1689 sg1entry_contains_frag_data = 1;
1692 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1694 frag = &skb_shinfo(skb)->frags[i];
1695 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1697 sgentry->l_key = lkey;
1698 sgentry->len = frag->size;
1700 ehea_map_vaddr(page_address(frag->page)
1701 + frag->page_offset);
1702 swqe->descriptors++;
1707 static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1713 /* De/Register untagged packets */
1714 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1715 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1716 port->logical_port_id,
1717 reg_type, port->mac_addr, 0, hcallid);
1718 if (hret != H_SUCCESS) {
1719 ehea_error("%sregistering bc address failed (tagged)",
1720 hcallid == H_REG_BCMC ? "" : "de");
1725 /* De/Register VLAN packets */
1726 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1727 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1728 port->logical_port_id,
1729 reg_type, port->mac_addr, 0, hcallid);
1730 if (hret != H_SUCCESS) {
1731 ehea_error("%sregistering bc address failed (vlan)",
1732 hcallid == H_REG_BCMC ? "" : "de");
1739 static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1741 struct ehea_port *port = netdev_priv(dev);
1742 struct sockaddr *mac_addr = sa;
1743 struct hcp_ehea_port_cb0 *cb0;
1747 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1748 ret = -EADDRNOTAVAIL;
1752 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1754 ehea_error("no mem for cb0");
1759 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1761 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1763 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1764 port->logical_port_id, H_PORT_CB0,
1765 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1766 if (hret != H_SUCCESS) {
1771 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1773 spin_lock(&ehea_bcmc_regs.lock);
1775 /* Deregister old MAC in pHYP */
1776 if (port->state == EHEA_PORT_UP) {
1777 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1782 port->mac_addr = cb0->port_mac_addr << 16;
1784 /* Register new MAC in pHYP */
1785 if (port->state == EHEA_PORT_UP) {
1786 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1794 ehea_update_bcmc_registrations();
1795 spin_unlock(&ehea_bcmc_regs.lock);
1802 static void ehea_promiscuous_error(u64 hret, int enable)
1804 if (hret == H_AUTHORITY)
1805 ehea_info("Hypervisor denied %sabling promiscuous mode",
1806 enable == 1 ? "en" : "dis");
1808 ehea_error("failed %sabling promiscuous mode",
1809 enable == 1 ? "en" : "dis");
1812 static void ehea_promiscuous(struct net_device *dev, int enable)
1814 struct ehea_port *port = netdev_priv(dev);
1815 struct hcp_ehea_port_cb7 *cb7;
1818 if ((enable && port->promisc) || (!enable && !port->promisc))
1821 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
1823 ehea_error("no mem for cb7");
1827 /* Modify Pxs_DUCQPN in CB7 */
1828 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1830 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1831 port->logical_port_id,
1832 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1834 ehea_promiscuous_error(hret, enable);
1838 port->promisc = enable;
1844 static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1850 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1851 | EHEA_BCMC_UNTAGGED;
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id,
1855 reg_type, mc_mac_addr, 0, hcallid);
1859 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1860 | EHEA_BCMC_VLANID_ALL;
1862 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1863 port->logical_port_id,
1864 reg_type, mc_mac_addr, 0, hcallid);
1869 static int ehea_drop_multicast_list(struct net_device *dev)
1871 struct ehea_port *port = netdev_priv(dev);
1872 struct ehea_mc_list *mc_entry = port->mc_list;
1873 struct list_head *pos;
1874 struct list_head *temp;
1878 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1879 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1881 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1884 ehea_error("failed deregistering mcast MAC");
1894 static void ehea_allmulti(struct net_device *dev, int enable)
1896 struct ehea_port *port = netdev_priv(dev);
1899 if (!port->allmulti) {
1901 /* Enable ALLMULTI */
1902 ehea_drop_multicast_list(dev);
1903 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1907 ehea_error("failed enabling IFF_ALLMULTI");
1911 /* Disable ALLMULTI */
1912 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1916 ehea_error("failed disabling IFF_ALLMULTI");
1920 static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
1922 struct ehea_mc_list *ehea_mcl_entry;
1925 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
1926 if (!ehea_mcl_entry) {
1927 ehea_error("no mem for mcl_entry");
1931 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1933 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1935 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1938 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1940 ehea_error("failed registering mcast MAC");
1941 kfree(ehea_mcl_entry);
1945 static void ehea_set_multicast_list(struct net_device *dev)
1947 struct ehea_port *port = netdev_priv(dev);
1948 struct dev_mc_list *k_mcl_entry;
1951 if (dev->flags & IFF_PROMISC) {
1952 ehea_promiscuous(dev, 1);
1955 ehea_promiscuous(dev, 0);
1957 spin_lock(&ehea_bcmc_regs.lock);
1959 if (dev->flags & IFF_ALLMULTI) {
1960 ehea_allmulti(dev, 1);
1963 ehea_allmulti(dev, 0);
1965 if (dev->mc_count) {
1966 ret = ehea_drop_multicast_list(dev);
1968 /* Dropping the current multicast list failed.
1969 * Enabling ALL_MULTI is the best we can do.
1971 ehea_allmulti(dev, 1);
1974 if (dev->mc_count > port->adapter->max_mc_mac) {
1975 ehea_info("Mcast registration limit reached (0x%lx). "
1977 port->adapter->max_mc_mac);
1981 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
1982 k_mcl_entry = k_mcl_entry->next)
1983 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
1987 ehea_update_bcmc_registrations();
1988 spin_unlock(&ehea_bcmc_regs.lock);
1992 static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1994 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2000 static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2001 struct ehea_swqe *swqe, u32 lkey)
2003 if (skb->protocol == htons(ETH_P_IP)) {
2004 const struct iphdr *iph = ip_hdr(skb);
2007 swqe->tx_control |= EHEA_SWQE_CRC
2008 | EHEA_SWQE_IP_CHECKSUM
2009 | EHEA_SWQE_TCP_CHECKSUM
2010 | EHEA_SWQE_IMM_DATA_PRESENT
2011 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2013 write_ip_start_end(swqe, skb);
2015 if (iph->protocol == IPPROTO_UDP) {
2016 if ((iph->frag_off & IP_MF)
2017 || (iph->frag_off & IP_OFFSET))
2018 /* IP fragment, so don't change cs */
2019 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2021 write_udp_offset_end(swqe, skb);
2022 } else if (iph->protocol == IPPROTO_TCP) {
2023 write_tcp_offset_end(swqe, skb);
2026 /* icmp (big data) and ip segmentation packets (all other ip
2027 packets) do not require any special handling */
2030 /* Other Ethernet Protocol */
2031 swqe->tx_control |= EHEA_SWQE_CRC
2032 | EHEA_SWQE_IMM_DATA_PRESENT
2033 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2036 write_swqe2_data(skb, dev, swqe, lkey);
2039 static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2040 struct ehea_swqe *swqe)
2042 int nfrags = skb_shinfo(skb)->nr_frags;
2043 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2047 if (skb->protocol == htons(ETH_P_IP)) {
2048 const struct iphdr *iph = ip_hdr(skb);
2051 write_ip_start_end(swqe, skb);
2053 if (iph->protocol == IPPROTO_TCP) {
2054 swqe->tx_control |= EHEA_SWQE_CRC
2055 | EHEA_SWQE_IP_CHECKSUM
2056 | EHEA_SWQE_TCP_CHECKSUM
2057 | EHEA_SWQE_IMM_DATA_PRESENT;
2059 write_tcp_offset_end(swqe, skb);
2061 } else if (iph->protocol == IPPROTO_UDP) {
2062 if ((iph->frag_off & IP_MF)
2063 || (iph->frag_off & IP_OFFSET))
2064 /* IP fragment, so don't change cs */
2065 swqe->tx_control |= EHEA_SWQE_CRC
2066 | EHEA_SWQE_IMM_DATA_PRESENT;
2068 swqe->tx_control |= EHEA_SWQE_CRC
2069 | EHEA_SWQE_IP_CHECKSUM
2070 | EHEA_SWQE_TCP_CHECKSUM
2071 | EHEA_SWQE_IMM_DATA_PRESENT;
2073 write_udp_offset_end(swqe, skb);
2076 /* icmp (big data) and
2077 ip segmentation packets (all other ip packets) */
2078 swqe->tx_control |= EHEA_SWQE_CRC
2079 | EHEA_SWQE_IP_CHECKSUM
2080 | EHEA_SWQE_IMM_DATA_PRESENT;
2083 /* Other Ethernet Protocol */
2084 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2086 /* copy (immediate) data */
2088 /* data is in a single piece */
2089 skb_copy_from_linear_data(skb, imm_data, skb->len);
2091 /* first copy data from the skb->data buffer ... */
2092 skb_copy_from_linear_data(skb, imm_data,
2093 skb->len - skb->data_len);
2094 imm_data += skb->len - skb->data_len;
2096 /* ... then copy data from the fragments */
2097 for (i = 0; i < nfrags; i++) {
2098 frag = &skb_shinfo(skb)->frags[i];
2100 page_address(frag->page) + frag->page_offset,
2102 imm_data += frag->size;
2105 swqe->immediate_data_length = skb->len;
2109 static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2114 if ((skb->protocol == htons(ETH_P_IP)) &&
2115 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
2116 tcp = (struct tcphdr *)(skb_network_header(skb) +
2117 (ip_hdr(skb)->ihl * 4));
2118 tmp = (tcp->source + (tcp->dest << 16)) % 31;
2119 tmp += ip_hdr(skb)->daddr % 31;
2120 return tmp % num_qps;
2125 static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2127 struct ehea_port *port = netdev_priv(dev);
2128 struct ehea_swqe *swqe;
2129 unsigned long flags;
2132 struct ehea_port_res *pr;
2134 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2136 if (!spin_trylock(&pr->xmit_lock))
2137 return NETDEV_TX_BUSY;
2139 if (pr->queue_stopped) {
2140 spin_unlock(&pr->xmit_lock);
2141 return NETDEV_TX_BUSY;
2144 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2145 memset(swqe, 0, SWQE_HEADER_SIZE);
2146 atomic_dec(&pr->swqe_avail);
2148 if (skb->len <= SWQE3_MAX_IMM) {
2149 u32 sig_iv = port->sig_comp_iv;
2150 u32 swqe_num = pr->swqe_id_counter;
2151 ehea_xmit3(skb, dev, swqe);
2152 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2153 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2154 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2155 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2157 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2158 pr->swqe_ll_count = 0;
2160 pr->swqe_ll_count += 1;
2163 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2164 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
2165 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
2166 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2167 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2169 pr->sq_skba.index++;
2170 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2172 lkey = pr->send_mr.lkey;
2173 ehea_xmit2(skb, dev, swqe, lkey);
2174 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2176 pr->swqe_id_counter += 1;
2178 if (port->vgrp && vlan_tx_tag_present(skb)) {
2179 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2180 swqe->vlan_tag = vlan_tx_tag_get(skb);
2183 if (netif_msg_tx_queued(port)) {
2184 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
2185 ehea_dump(swqe, 512, "swqe");
2188 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2189 netif_stop_queue(dev);
2190 swqe->tx_control |= EHEA_SWQE_PURGE;
2193 ehea_post_swqe(pr->qp, swqe);
2196 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2197 spin_lock_irqsave(&pr->netif_queue, flags);
2198 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2199 pr->p_stats.queue_stopped++;
2200 netif_stop_queue(dev);
2201 pr->queue_stopped = 1;
2203 spin_unlock_irqrestore(&pr->netif_queue, flags);
2205 dev->trans_start = jiffies;
2206 spin_unlock(&pr->xmit_lock);
2208 return NETDEV_TX_OK;
2211 static void ehea_vlan_rx_register(struct net_device *dev,
2212 struct vlan_group *grp)
2214 struct ehea_port *port = netdev_priv(dev);
2215 struct ehea_adapter *adapter = port->adapter;
2216 struct hcp_ehea_port_cb1 *cb1;
2221 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2223 ehea_error("no mem for cb1");
2227 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2228 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2229 if (hret != H_SUCCESS)
2230 ehea_error("modify_ehea_port failed");
2237 static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2239 struct ehea_port *port = netdev_priv(dev);
2240 struct ehea_adapter *adapter = port->adapter;
2241 struct hcp_ehea_port_cb1 *cb1;
2245 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2247 ehea_error("no mem for cb1");
2251 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2252 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2253 if (hret != H_SUCCESS) {
2254 ehea_error("query_ehea_port failed");
2259 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
2261 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2262 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2263 if (hret != H_SUCCESS)
2264 ehea_error("modify_ehea_port failed");
2270 static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2272 struct ehea_port *port = netdev_priv(dev);
2273 struct ehea_adapter *adapter = port->adapter;
2274 struct hcp_ehea_port_cb1 *cb1;
2278 vlan_group_set_device(port->vgrp, vid, NULL);
2280 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2282 ehea_error("no mem for cb1");
2286 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2287 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2288 if (hret != H_SUCCESS) {
2289 ehea_error("query_ehea_port failed");
2294 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
2296 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2297 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2298 if (hret != H_SUCCESS)
2299 ehea_error("modify_ehea_port failed");
2305 int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2311 struct hcp_modify_qp_cb0 *cb0;
2313 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2319 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2320 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2321 if (hret != H_SUCCESS) {
2322 ehea_error("query_ehea_qp failed (1)");
2326 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2327 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2328 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2329 &dummy64, &dummy64, &dummy16, &dummy16);
2330 if (hret != H_SUCCESS) {
2331 ehea_error("modify_ehea_qp failed (1)");
2335 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2336 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2337 if (hret != H_SUCCESS) {
2338 ehea_error("query_ehea_qp failed (2)");
2342 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2343 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2344 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2345 &dummy64, &dummy64, &dummy16, &dummy16);
2346 if (hret != H_SUCCESS) {
2347 ehea_error("modify_ehea_qp failed (2)");
2351 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2352 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2353 if (hret != H_SUCCESS) {
2354 ehea_error("query_ehea_qp failed (3)");
2358 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2359 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2360 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2361 &dummy64, &dummy64, &dummy16, &dummy16);
2362 if (hret != H_SUCCESS) {
2363 ehea_error("modify_ehea_qp failed (3)");
2367 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2368 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2369 if (hret != H_SUCCESS) {
2370 ehea_error("query_ehea_qp failed (4)");
2380 static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2384 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2385 enum ehea_eq_type eq_type = EHEA_EQ;
2387 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2388 EHEA_MAX_ENTRIES_EQ, 1);
2391 ehea_error("ehea_create_eq failed (qp_eq)");
2395 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
2396 pr_cfg.max_entries_scq = sq_entries * 2;
2397 pr_cfg.max_entries_sq = sq_entries;
2398 pr_cfg.max_entries_rq1 = rq1_entries;
2399 pr_cfg.max_entries_rq2 = rq2_entries;
2400 pr_cfg.max_entries_rq3 = rq3_entries;
2402 pr_cfg_small_rx.max_entries_rcq = 1;
2403 pr_cfg_small_rx.max_entries_scq = sq_entries;
2404 pr_cfg_small_rx.max_entries_sq = sq_entries;
2405 pr_cfg_small_rx.max_entries_rq1 = 1;
2406 pr_cfg_small_rx.max_entries_rq2 = 1;
2407 pr_cfg_small_rx.max_entries_rq3 = 1;
2409 for (i = 0; i < def_qps; i++) {
2410 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2414 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2415 ret = ehea_init_port_res(port, &port->port_res[i],
2416 &pr_cfg_small_rx, i);
2425 ehea_clean_portres(port, &port->port_res[i]);
2428 ehea_destroy_eq(port->qp_eq);
2432 static int ehea_clean_all_portres(struct ehea_port *port)
2437 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2438 ret |= ehea_clean_portres(port, &port->port_res[i]);
2440 ret |= ehea_destroy_eq(port->qp_eq);
2445 static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
2447 if (adapter->active_ports)
2450 ehea_rem_mr(&adapter->mr);
2453 static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
2455 if (adapter->active_ports)
2458 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2461 static int ehea_up(struct net_device *dev)
2464 struct ehea_port *port = netdev_priv(dev);
2466 if (port->state == EHEA_PORT_UP)
2469 mutex_lock(&ehea_fw_handles.lock);
2471 ret = ehea_port_res_setup(port, port->num_def_qps,
2472 port->num_add_tx_qps);
2474 ehea_error("port_res_failed");
2478 /* Set default QP for this port */
2479 ret = ehea_configure_port(port);
2481 ehea_error("ehea_configure_port failed. ret:%d", ret);
2485 ret = ehea_reg_interrupts(dev);
2487 ehea_error("reg_interrupts failed. ret:%d", ret);
2491 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2492 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2494 ehea_error("activate_qp failed");
2499 for (i = 0; i < port->num_def_qps; i++) {
2500 ret = ehea_fill_port_res(&port->port_res[i]);
2502 ehea_error("out_free_irqs");
2507 spin_lock(&ehea_bcmc_regs.lock);
2509 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2515 port->state = EHEA_PORT_UP;
2521 ehea_free_interrupts(dev);
2524 ehea_clean_all_portres(port);
2527 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2529 ehea_update_bcmc_registrations();
2530 spin_unlock(&ehea_bcmc_regs.lock);
2532 ehea_update_firmware_handles();
2533 mutex_unlock(&ehea_fw_handles.lock);
2538 static void port_napi_disable(struct ehea_port *port)
2542 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2543 napi_disable(&port->port_res[i].napi);
2546 static void port_napi_enable(struct ehea_port *port)
2550 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2551 napi_enable(&port->port_res[i].napi);
2554 static int ehea_open(struct net_device *dev)
2557 struct ehea_port *port = netdev_priv(dev);
2559 mutex_lock(&port->port_lock);
2561 if (netif_msg_ifup(port))
2562 ehea_info("enabling port %s", dev->name);
2566 port_napi_enable(port);
2567 netif_start_queue(dev);
2570 mutex_unlock(&port->port_lock);
2575 static int ehea_down(struct net_device *dev)
2578 struct ehea_port *port = netdev_priv(dev);
2580 if (port->state == EHEA_PORT_DOWN)
2583 mutex_lock(&ehea_fw_handles.lock);
2585 spin_lock(&ehea_bcmc_regs.lock);
2586 ehea_drop_multicast_list(dev);
2587 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2589 ehea_free_interrupts(dev);
2591 port->state = EHEA_PORT_DOWN;
2593 ehea_update_bcmc_registrations();
2594 spin_unlock(&ehea_bcmc_regs.lock);
2596 ret = ehea_clean_all_portres(port);
2598 ehea_info("Failed freeing resources for %s. ret=%i",
2601 ehea_update_firmware_handles();
2602 mutex_unlock(&ehea_fw_handles.lock);
2607 static int ehea_stop(struct net_device *dev)
2610 struct ehea_port *port = netdev_priv(dev);
2612 if (netif_msg_ifdown(port))
2613 ehea_info("disabling port %s", dev->name);
2615 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
2616 cancel_work_sync(&port->reset_task);
2617 mutex_lock(&port->port_lock);
2618 netif_stop_queue(dev);
2619 port_napi_disable(port);
2620 ret = ehea_down(dev);
2621 mutex_unlock(&port->port_lock);
2622 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
2626 static void ehea_purge_sq(struct ehea_qp *orig_qp)
2628 struct ehea_qp qp = *orig_qp;
2629 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2630 struct ehea_swqe *swqe;
2634 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2635 swqe = ehea_get_swqe(&qp, &wqe_index);
2636 swqe->tx_control |= EHEA_SWQE_PURGE;
2640 static void ehea_flush_sq(struct ehea_port *port)
2644 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2645 struct ehea_port_res *pr = &port->port_res[i];
2646 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2648 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2656 int ehea_stop_qps(struct net_device *dev)
2658 struct ehea_port *port = netdev_priv(dev);
2659 struct ehea_adapter *adapter = port->adapter;
2660 struct hcp_modify_qp_cb0 *cb0;
2668 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2674 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2675 struct ehea_port_res *pr = &port->port_res[i];
2676 struct ehea_qp *qp = pr->qp;
2678 /* Purge send queue */
2681 /* Disable queue pair */
2682 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2683 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2685 if (hret != H_SUCCESS) {
2686 ehea_error("query_ehea_qp failed (1)");
2690 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2691 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2693 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2694 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2696 &dummy64, &dummy16, &dummy16);
2697 if (hret != H_SUCCESS) {
2698 ehea_error("modify_ehea_qp failed (1)");
2702 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2703 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2705 if (hret != H_SUCCESS) {
2706 ehea_error("query_ehea_qp failed (2)");
2710 /* deregister shared memory regions */
2711 dret = ehea_rem_smrs(pr);
2713 ehea_error("unreg shared memory region failed");
2725 void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
2727 struct ehea_qp qp = *orig_qp;
2728 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2729 struct ehea_rwqe *rwqe;
2730 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2731 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2732 struct sk_buff *skb;
2733 u32 lkey = pr->recv_mr.lkey;
2739 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2740 rwqe = ehea_get_next_rwqe(&qp, 2);
2741 rwqe->sg_list[0].l_key = lkey;
2742 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2743 skb = skba_rq2[index];
2745 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2748 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2749 rwqe = ehea_get_next_rwqe(&qp, 3);
2750 rwqe->sg_list[0].l_key = lkey;
2751 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2752 skb = skba_rq3[index];
2754 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2758 int ehea_restart_qps(struct net_device *dev)
2760 struct ehea_port *port = netdev_priv(dev);
2761 struct ehea_adapter *adapter = port->adapter;
2765 struct hcp_modify_qp_cb0 *cb0;
2770 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2776 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2777 struct ehea_port_res *pr = &port->port_res[i];
2778 struct ehea_qp *qp = pr->qp;
2780 ret = ehea_gen_smrs(pr);
2782 ehea_error("creation of shared memory regions failed");
2786 ehea_update_rqs(qp, pr);
2788 /* Enable queue pair */
2789 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2790 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2792 if (hret != H_SUCCESS) {
2793 ehea_error("query_ehea_qp failed (1)");
2797 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2798 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2800 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2801 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2803 &dummy64, &dummy16, &dummy16);
2804 if (hret != H_SUCCESS) {
2805 ehea_error("modify_ehea_qp failed (1)");
2809 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2810 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2812 if (hret != H_SUCCESS) {
2813 ehea_error("query_ehea_qp failed (2)");
2817 /* refill entire queue */
2818 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2819 ehea_refill_rq2(pr, 0);
2820 ehea_refill_rq3(pr, 0);
2828 static void ehea_reset_port(struct work_struct *work)
2831 struct ehea_port *port =
2832 container_of(work, struct ehea_port, reset_task);
2833 struct net_device *dev = port->netdev;
2836 mutex_lock(&port->port_lock);
2837 netif_stop_queue(dev);
2839 port_napi_disable(port);
2847 ehea_set_multicast_list(dev);
2849 if (netif_msg_timer(port))
2850 ehea_info("Device %s resetted successfully", dev->name);
2852 port_napi_enable(port);
2854 netif_wake_queue(dev);
2856 mutex_unlock(&port->port_lock);
2860 static void ehea_rereg_mrs(struct work_struct *work)
2863 struct ehea_adapter *adapter;
2865 mutex_lock(&dlpar_mem_lock);
2866 ehea_info("LPAR memory changed - re-initializing driver");
2868 list_for_each_entry(adapter, &adapter_list, list)
2869 if (adapter->active_ports) {
2870 /* Shutdown all ports */
2871 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2872 struct ehea_port *port = adapter->port[i];
2873 struct net_device *dev;
2880 if (dev->flags & IFF_UP) {
2881 mutex_lock(&port->port_lock);
2882 netif_stop_queue(dev);
2883 ehea_flush_sq(port);
2884 ret = ehea_stop_qps(dev);
2886 mutex_unlock(&port->port_lock);
2889 port_napi_disable(port);
2890 mutex_unlock(&port->port_lock);
2894 /* Unregister old memory region */
2895 ret = ehea_rem_mr(&adapter->mr);
2897 ehea_error("unregister MR failed - driver"
2903 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2905 list_for_each_entry(adapter, &adapter_list, list)
2906 if (adapter->active_ports) {
2907 /* Register new memory region */
2908 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2910 ehea_error("register MR failed - driver"
2915 /* Restart all ports */
2916 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2917 struct ehea_port *port = adapter->port[i];
2920 struct net_device *dev = port->netdev;
2922 if (dev->flags & IFF_UP) {
2923 mutex_lock(&port->port_lock);
2924 port_napi_enable(port);
2925 ret = ehea_restart_qps(dev);
2927 netif_wake_queue(dev);
2928 mutex_unlock(&port->port_lock);
2933 ehea_info("re-initializing driver complete");
2935 mutex_unlock(&dlpar_mem_lock);
2939 static void ehea_tx_watchdog(struct net_device *dev)
2941 struct ehea_port *port = netdev_priv(dev);
2943 if (netif_carrier_ok(dev) &&
2944 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
2945 ehea_schedule_port_reset(port);
2948 int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2950 struct hcp_query_ehea *cb;
2954 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
2960 hret = ehea_h_query_ehea(adapter->handle, cb);
2962 if (hret != H_SUCCESS) {
2967 adapter->max_mc_mac = cb->max_mc_mac - 1;
2976 int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2978 struct hcp_ehea_port_cb4 *cb4;
2984 /* (Try to) enable *jumbo frames */
2985 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2987 ehea_error("no mem for cb4");
2991 hret = ehea_h_query_ehea_port(port->adapter->handle,
2992 port->logical_port_id,
2994 H_PORT_CB4_JUMBO, cb4);
2995 if (hret == H_SUCCESS) {
2996 if (cb4->jumbo_frame)
2999 cb4->jumbo_frame = 1;
3000 hret = ehea_h_modify_ehea_port(port->adapter->
3007 if (hret == H_SUCCESS)
3019 static ssize_t ehea_show_port_id(struct device *dev,
3020 struct device_attribute *attr, char *buf)
3022 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3023 return sprintf(buf, "%d", port->logical_port_id);
3026 static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3029 static void __devinit logical_port_release(struct device *dev)
3031 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3032 of_node_put(port->ofdev.node);
3035 static struct device *ehea_register_port(struct ehea_port *port,
3036 struct device_node *dn)
3040 port->ofdev.node = of_node_get(dn);
3041 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
3042 port->ofdev.dev.bus = &ibmebus_bus_type;
3044 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
3045 port->ofdev.dev.release = logical_port_release;
3047 ret = of_device_register(&port->ofdev);
3049 ehea_error("failed to register device. ret=%d", ret);
3053 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
3055 ehea_error("failed to register attributes, ret=%d", ret);
3056 goto out_unreg_of_dev;
3059 return &port->ofdev.dev;
3062 of_device_unregister(&port->ofdev);
3067 static void ehea_unregister_port(struct ehea_port *port)
3069 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3070 of_device_unregister(&port->ofdev);
3073 struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3074 u32 logical_port_id,
3075 struct device_node *dn)
3078 struct net_device *dev;
3079 struct ehea_port *port;
3080 struct device *port_dev;
3083 /* allocate memory for the port structures */
3084 dev = alloc_etherdev(sizeof(struct ehea_port));
3087 ehea_error("no mem for net_device");
3092 port = netdev_priv(dev);
3094 mutex_init(&port->port_lock);
3095 port->state = EHEA_PORT_DOWN;
3096 port->sig_comp_iv = sq_entries / 10;
3098 port->adapter = adapter;
3100 port->logical_port_id = logical_port_id;
3102 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
3104 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3105 if (!port->mc_list) {
3107 goto out_free_ethdev;
3110 INIT_LIST_HEAD(&port->mc_list->list);
3112 ret = ehea_sense_port_attr(port);
3114 goto out_free_mc_list;
3116 port_dev = ehea_register_port(port, dn);
3118 goto out_free_mc_list;
3120 SET_NETDEV_DEV(dev, port_dev);
3122 /* initialize net_device structure */
3123 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3125 dev->open = ehea_open;
3126 #ifdef CONFIG_NET_POLL_CONTROLLER
3127 dev->poll_controller = ehea_netpoll;
3129 dev->stop = ehea_stop;
3130 dev->hard_start_xmit = ehea_start_xmit;
3131 dev->get_stats = ehea_get_stats;
3132 dev->set_multicast_list = ehea_set_multicast_list;
3133 dev->set_mac_address = ehea_set_mac_addr;
3134 dev->change_mtu = ehea_change_mtu;
3135 dev->vlan_rx_register = ehea_vlan_rx_register;
3136 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
3137 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
3138 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
3139 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
3140 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3142 dev->tx_timeout = &ehea_tx_watchdog;
3143 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3145 INIT_WORK(&port->reset_task, ehea_reset_port);
3146 ehea_set_ethtool_ops(dev);
3148 ret = register_netdev(dev);
3150 ehea_error("register_netdev failed. ret=%d", ret);
3151 goto out_unreg_port;
3154 port->lro_max_aggr = lro_max_aggr;
3156 ret = ehea_get_jumboframe_status(port, &jumbo);
3158 ehea_error("failed determining jumbo frame status for %s",
3159 port->netdev->name);
3161 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3162 jumbo == 1 ? "en" : "dis");
3164 adapter->active_ports++;
3169 ehea_unregister_port(port);
3172 kfree(port->mc_list);
3178 ehea_error("setting up logical port with id=%d failed, ret=%d",
3179 logical_port_id, ret);
3183 static void ehea_shutdown_single_port(struct ehea_port *port)
3185 struct ehea_adapter *adapter = port->adapter;
3186 unregister_netdev(port->netdev);
3187 ehea_unregister_port(port);
3188 kfree(port->mc_list);
3189 free_netdev(port->netdev);
3190 adapter->active_ports--;
3193 static int ehea_setup_ports(struct ehea_adapter *adapter)
3195 struct device_node *lhea_dn;
3196 struct device_node *eth_dn = NULL;
3198 const u32 *dn_log_port_id;
3201 lhea_dn = adapter->ofdev->node;
3202 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
3204 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
3206 if (!dn_log_port_id) {
3207 ehea_error("bad device node: eth_dn name=%s",
3212 if (ehea_add_adapter_mr(adapter)) {
3213 ehea_error("creating MR failed");
3214 of_node_put(eth_dn);
3218 adapter->port[i] = ehea_setup_single_port(adapter,
3221 if (adapter->port[i])
3222 ehea_info("%s -> logical port id #%d",
3223 adapter->port[i]->netdev->name,
3226 ehea_remove_adapter_mr(adapter);
3233 static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3234 u32 logical_port_id)
3236 struct device_node *lhea_dn;
3237 struct device_node *eth_dn = NULL;
3238 const u32 *dn_log_port_id;
3240 lhea_dn = adapter->ofdev->node;
3241 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
3243 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
3246 if (*dn_log_port_id == logical_port_id)
3253 static ssize_t ehea_probe_port(struct device *dev,
3254 struct device_attribute *attr,
3255 const char *buf, size_t count)
3257 struct ehea_adapter *adapter = dev->driver_data;
3258 struct ehea_port *port;
3259 struct device_node *eth_dn = NULL;
3262 u32 logical_port_id;
3264 sscanf(buf, "%d", &logical_port_id);
3266 port = ehea_get_port(adapter, logical_port_id);
3269 ehea_info("adding port with logical port id=%d failed. port "
3270 "already configured as %s.", logical_port_id,
3271 port->netdev->name);
3275 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3278 ehea_info("no logical port with id %d found", logical_port_id);
3282 if (ehea_add_adapter_mr(adapter)) {
3283 ehea_error("creating MR failed");
3287 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3289 of_node_put(eth_dn);
3292 for (i = 0; i < EHEA_MAX_PORTS; i++)
3293 if (!adapter->port[i]) {
3294 adapter->port[i] = port;
3298 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3301 ehea_remove_adapter_mr(adapter);
3305 return (ssize_t) count;
3308 static ssize_t ehea_remove_port(struct device *dev,
3309 struct device_attribute *attr,
3310 const char *buf, size_t count)
3312 struct ehea_adapter *adapter = dev->driver_data;
3313 struct ehea_port *port;
3315 u32 logical_port_id;
3317 sscanf(buf, "%d", &logical_port_id);
3319 port = ehea_get_port(adapter, logical_port_id);
3322 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3325 ehea_shutdown_single_port(port);
3327 for (i = 0; i < EHEA_MAX_PORTS; i++)
3328 if (adapter->port[i] == port) {
3329 adapter->port[i] = NULL;
3333 ehea_error("removing port with logical port id=%d failed. port "
3334 "not configured.", logical_port_id);
3338 ehea_remove_adapter_mr(adapter);
3340 return (ssize_t) count;
3343 static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3344 static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3346 int ehea_create_device_sysfs(struct of_device *dev)
3348 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
3352 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
3357 void ehea_remove_device_sysfs(struct of_device *dev)
3359 device_remove_file(&dev->dev, &dev_attr_probe_port);
3360 device_remove_file(&dev->dev, &dev_attr_remove_port);
3363 static int __devinit ehea_probe_adapter(struct of_device *dev,
3364 const struct of_device_id *id)
3366 struct ehea_adapter *adapter;
3367 const u64 *adapter_handle;
3370 if (!dev || !dev->node) {
3371 ehea_error("Invalid ibmebus device probed");
3374 mutex_lock(&ehea_fw_handles.lock);
3376 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3379 dev_err(&dev->dev, "no mem for ehea_adapter\n");
3383 list_add(&adapter->list, &adapter_list);
3385 adapter->ofdev = dev;
3387 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
3390 adapter->handle = *adapter_handle;
3392 if (!adapter->handle) {
3393 dev_err(&dev->dev, "failed getting handle for adapter"
3394 " '%s'\n", dev->node->full_name);
3399 adapter->pd = EHEA_PD_ID;
3401 dev->dev.driver_data = adapter;
3404 /* initialize adapter and ports */
3405 /* get adapter properties */
3406 ret = ehea_sense_adapter_attr(adapter);
3408 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
3412 adapter->neq = ehea_create_eq(adapter,
3413 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3414 if (!adapter->neq) {
3416 dev_err(&dev->dev, "NEQ creation failed\n");
3420 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3421 (unsigned long)adapter);
3423 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
3424 ehea_interrupt_neq, IRQF_DISABLED,
3425 "ehea_neq", adapter);
3427 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3431 ret = ehea_create_device_sysfs(dev);
3435 ret = ehea_setup_ports(adapter);
3437 dev_err(&dev->dev, "setup_ports failed\n");
3438 goto out_rem_dev_sysfs;
3445 ehea_remove_device_sysfs(dev);
3448 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
3451 ehea_destroy_eq(adapter->neq);
3457 ehea_update_firmware_handles();
3458 mutex_unlock(&ehea_fw_handles.lock);
3462 static int __devexit ehea_remove(struct of_device *dev)
3464 struct ehea_adapter *adapter = dev->dev.driver_data;
3467 for (i = 0; i < EHEA_MAX_PORTS; i++)
3468 if (adapter->port[i]) {
3469 ehea_shutdown_single_port(adapter->port[i]);
3470 adapter->port[i] = NULL;
3473 ehea_remove_device_sysfs(dev);
3475 flush_scheduled_work();
3477 mutex_lock(&ehea_fw_handles.lock);
3479 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
3480 tasklet_kill(&adapter->neq_tasklet);
3482 ehea_destroy_eq(adapter->neq);
3483 ehea_remove_adapter_mr(adapter);
3484 list_del(&adapter->list);
3487 ehea_update_firmware_handles();
3488 mutex_unlock(&ehea_fw_handles.lock);
3493 void ehea_crash_handler(void)
3497 if (ehea_fw_handles.arr)
3498 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3499 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3500 ehea_fw_handles.arr[i].fwh,
3503 if (ehea_bcmc_regs.arr)
3504 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3505 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3506 ehea_bcmc_regs.arr[i].port_id,
3507 ehea_bcmc_regs.arr[i].reg_type,
3508 ehea_bcmc_regs.arr[i].macaddr,
3512 static int ehea_mem_notifier(struct notifier_block *nb,
3513 unsigned long action, void *data)
3515 struct memory_notify *arg = data;
3517 case MEM_CANCEL_OFFLINE:
3518 ehea_info("memory offlining canceled");
3519 /* Readd canceled memory block */
3521 ehea_info("memory is going online");
3522 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
3524 ehea_rereg_mrs(NULL);
3526 case MEM_GOING_OFFLINE:
3527 ehea_info("memory is going offline");
3528 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
3530 ehea_rereg_mrs(NULL);
3538 static struct notifier_block ehea_mem_nb = {
3539 .notifier_call = ehea_mem_notifier,
3542 static int ehea_reboot_notifier(struct notifier_block *nb,
3543 unsigned long action, void *unused)
3545 if (action == SYS_RESTART) {
3546 ehea_info("Reboot: freeing all eHEA resources");
3547 ibmebus_unregister_driver(&ehea_driver);
3552 static struct notifier_block ehea_reboot_nb = {
3553 .notifier_call = ehea_reboot_notifier,
3556 static int check_module_parm(void)
3560 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3561 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3562 ehea_info("Bad parameter: rq1_entries");
3565 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3566 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3567 ehea_info("Bad parameter: rq2_entries");
3570 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3571 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3572 ehea_info("Bad parameter: rq3_entries");
3575 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3576 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3577 ehea_info("Bad parameter: sq_entries");
3584 static ssize_t ehea_show_capabilities(struct device_driver *drv,
3587 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3590 static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3591 ehea_show_capabilities, NULL);
3593 int __init ehea_module_init(void)
3597 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3601 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
3602 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3603 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3605 mutex_init(&ehea_fw_handles.lock);
3606 spin_lock_init(&ehea_bcmc_regs.lock);
3608 ret = check_module_parm();
3612 ret = ehea_create_busmap();
3616 ret = register_reboot_notifier(&ehea_reboot_nb);
3618 ehea_info("failed registering reboot notifier");
3620 ret = register_memory_notifier(&ehea_mem_nb);
3622 ehea_info("failed registering memory remove notifier");
3624 ret = crash_shutdown_register(&ehea_crash_handler);
3626 ehea_info("failed registering crash handler");
3628 ret = ibmebus_register_driver(&ehea_driver);
3630 ehea_error("failed registering eHEA device driver on ebus");
3634 ret = driver_create_file(&ehea_driver.driver,
3635 &driver_attr_capabilities);
3637 ehea_error("failed to register capabilities attribute, ret=%d",
3645 ibmebus_unregister_driver(&ehea_driver);
3647 unregister_memory_notifier(&ehea_mem_nb);
3648 unregister_reboot_notifier(&ehea_reboot_nb);
3649 crash_shutdown_unregister(&ehea_crash_handler);
3654 static void __exit ehea_module_exit(void)
3658 flush_scheduled_work();
3659 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
3660 ibmebus_unregister_driver(&ehea_driver);
3661 unregister_reboot_notifier(&ehea_reboot_nb);
3662 ret = crash_shutdown_unregister(&ehea_crash_handler);
3664 ehea_info("failed unregistering crash handler");
3665 unregister_memory_notifier(&ehea_mem_nb);
3666 kfree(ehea_fw_handles.arr);
3667 kfree(ehea_bcmc_regs.arr);
3668 ehea_destroy_busmap();
3671 module_init(ehea_module_init);
3672 module_exit(ehea_module_exit);