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>
40 #include "ehea_phyp.h"
43 MODULE_LICENSE("GPL");
44 MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
45 MODULE_DESCRIPTION("IBM eServer HEA Driver");
46 MODULE_VERSION(DRV_VERSION);
49 static int msg_level = -1;
50 static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
51 static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
52 static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
53 static int sq_entries = EHEA_DEF_ENTRIES_SQ;
55 module_param(msg_level, int, 0);
56 module_param(rq1_entries, int, 0);
57 module_param(rq2_entries, int, 0);
58 module_param(rq3_entries, int, 0);
59 module_param(sq_entries, int, 0);
61 MODULE_PARM_DESC(msg_level, "msg_level");
62 MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
63 "[2^x - 1], x = [6..14]. Default = "
64 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
65 MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
66 "[2^x - 1], x = [6..14]. Default = "
67 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
68 MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
69 "[2^x - 1], x = [6..14]. Default = "
70 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
71 MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
72 "[2^x - 1], x = [6..14]. Default = "
73 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
75 void ehea_dump(void *adr, int len, char *msg) {
77 unsigned char *deb = adr;
78 for (x = 0; x < len; x += 16) {
79 printk(DRV_NAME "%s adr=%p ofs=%04x %016lx %016lx\n", msg,
80 deb, x, *((u64*)&deb[0]), *((u64*)&deb[8]));
85 static struct net_device_stats *ehea_get_stats(struct net_device *dev)
87 struct ehea_port *port = netdev_priv(dev);
88 struct net_device_stats *stats = &port->stats;
89 struct hcp_ehea_port_cb2 *cb2;
93 memset(stats, 0, sizeof(*stats));
95 cb2 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
97 ehea_error("no mem for cb2");
101 hret = ehea_h_query_ehea_port(port->adapter->handle,
102 port->logical_port_id,
103 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
104 if (hret != H_SUCCESS) {
105 ehea_error("query_ehea_port failed");
109 if (netif_msg_hw(port))
110 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
113 for (i = 0; i < port->num_def_qps; i++)
114 rx_packets += port->port_res[i].rx_packets;
116 stats->tx_packets = cb2->txucp + cb2->txmcp + cb2->txbcp;
117 stats->multicast = cb2->rxmcp;
118 stats->rx_errors = cb2->rxuerr;
119 stats->rx_bytes = cb2->rxo;
120 stats->tx_bytes = cb2->txo;
121 stats->rx_packets = rx_packets;
129 static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
131 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
132 struct net_device *dev = pr->port->netdev;
133 int max_index_mask = pr->rq1_skba.len - 1;
139 for (i = 0; i < nr_of_wqes; i++) {
140 if (!skb_arr_rq1[index]) {
141 skb_arr_rq1[index] = netdev_alloc_skb(dev,
143 if (!skb_arr_rq1[index]) {
144 ehea_error("%s: no mem for skb/%d wqes filled",
150 index &= max_index_mask;
153 ehea_update_rq1a(pr->qp, i);
156 static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
159 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
160 struct net_device *dev = pr->port->netdev;
163 for (i = 0; i < pr->rq1_skba.len; i++) {
164 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
165 if (!skb_arr_rq1[i]) {
166 ehea_error("%s: no mem for skb/%d wqes filled",
173 ehea_update_rq1a(pr->qp, nr_rq1a);
178 static int ehea_refill_rq_def(struct ehea_port_res *pr,
179 struct ehea_q_skb_arr *q_skba, int rq_nr,
180 int num_wqes, int wqe_type, int packet_size)
182 struct net_device *dev = pr->port->netdev;
183 struct ehea_qp *qp = pr->qp;
184 struct sk_buff **skb_arr = q_skba->arr;
185 struct ehea_rwqe *rwqe;
186 int i, index, max_index_mask, fill_wqes;
189 fill_wqes = q_skba->os_skbs + num_wqes;
194 index = q_skba->index;
195 max_index_mask = q_skba->len - 1;
196 for (i = 0; i < fill_wqes; i++) {
197 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
199 ehea_error("%s: no mem for skb/%d wqes filled",
201 q_skba->os_skbs = fill_wqes - i;
205 skb_reserve(skb, NET_IP_ALIGN);
207 skb_arr[index] = skb;
209 rwqe = ehea_get_next_rwqe(qp, rq_nr);
210 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
211 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
212 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
213 rwqe->sg_list[0].vaddr = (u64)skb->data;
214 rwqe->sg_list[0].len = packet_size;
215 rwqe->data_segments = 1;
218 index &= max_index_mask;
220 q_skba->index = index;
225 ehea_update_rq2a(pr->qp, i);
227 ehea_update_rq3a(pr->qp, i);
233 static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
235 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
236 nr_of_wqes, EHEA_RWQE2_TYPE,
237 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
241 static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
243 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
244 nr_of_wqes, EHEA_RWQE3_TYPE,
245 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
248 static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
250 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
251 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
253 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
254 (cqe->header_length == 0))
259 static inline void ehea_fill_skb(struct net_device *dev,
260 struct sk_buff *skb, struct ehea_cqe *cqe)
262 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
264 skb_put(skb, length);
265 skb->ip_summed = CHECKSUM_UNNECESSARY;
266 skb->protocol = eth_type_trans(skb, dev);
269 static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
271 struct ehea_cqe *cqe)
273 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
283 prefetchw(pref + EHEA_CACHE_LINE);
285 pref = (skb_array[x]->data);
287 prefetch(pref + EHEA_CACHE_LINE);
288 prefetch(pref + EHEA_CACHE_LINE * 2);
289 prefetch(pref + EHEA_CACHE_LINE * 3);
290 skb = skb_array[skb_index];
291 skb_array[skb_index] = NULL;
295 static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
296 int arr_len, int wqe_index)
307 prefetchw(pref + EHEA_CACHE_LINE);
309 pref = (skb_array[x]->data);
311 prefetchw(pref + EHEA_CACHE_LINE);
313 skb = skb_array[wqe_index];
314 skb_array[wqe_index] = NULL;
318 static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
319 struct ehea_cqe *cqe, int *processed_rq2,
324 if (netif_msg_rx_err(pr->port)) {
325 ehea_error("CQE Error for QP %d", pr->qp->init_attr.qp_nr);
326 ehea_dump(cqe, sizeof(*cqe), "CQE");
331 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
333 } else if (rq == 3) {
335 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
339 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
340 ehea_error("Critical receive error. Resetting port.");
341 queue_work(pr->port->adapter->ehea_wq, &pr->port->reset_task);
348 static int ehea_poll(struct net_device *dev, int *budget)
350 struct ehea_port *port = netdev_priv(dev);
351 struct ehea_port_res *pr = &port->port_res[0];
352 struct ehea_qp *qp = pr->qp;
353 struct ehea_cqe *cqe;
355 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
356 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
357 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
358 int skb_arr_rq1_len = pr->rq1_skba.len;
359 int skb_arr_rq2_len = pr->rq2_skba.len;
360 int skb_arr_rq3_len = pr->rq3_skba.len;
361 int processed, processed_rq1, processed_rq2, processed_rq3;
362 int wqe_index, last_wqe_index, rq, intreq, my_quota, port_reset;
364 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
366 my_quota = min(*budget, dev->quota);
367 my_quota = min(my_quota, EHEA_POLL_MAX_RWQE);
369 /* rq0 is low latency RQ */
370 cqe = ehea_poll_rq1(qp, &wqe_index);
371 while ((my_quota > 0) && cqe) {
376 if (netif_msg_rx_status(port))
377 ehea_dump(cqe, sizeof(*cqe), "CQE");
379 last_wqe_index = wqe_index;
381 if (!ehea_check_cqe(cqe, &rq)) {
382 if (rq == 1) { /* LL RQ1 */
383 skb = get_skb_by_index_ll(skb_arr_rq1,
386 if (unlikely(!skb)) {
387 if (netif_msg_rx_err(port))
388 ehea_error("LL rq1: skb=NULL");
389 skb = netdev_alloc_skb(dev,
394 memcpy(skb->data, ((char*)cqe) + 64,
395 cqe->num_bytes_transfered - 4);
396 ehea_fill_skb(dev, skb, cqe);
397 } else if (rq == 2) { /* RQ2 */
398 skb = get_skb_by_index(skb_arr_rq2,
399 skb_arr_rq2_len, cqe);
400 if (unlikely(!skb)) {
401 if (netif_msg_rx_err(port))
402 ehea_error("rq2: skb=NULL");
405 ehea_fill_skb(dev, skb, cqe);
408 skb = get_skb_by_index(skb_arr_rq3,
409 skb_arr_rq3_len, cqe);
410 if (unlikely(!skb)) {
411 if (netif_msg_rx_err(port))
412 ehea_error("rq3: skb=NULL");
415 ehea_fill_skb(dev, skb, cqe);
419 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
420 vlan_hwaccel_receive_skb(skb, port->vgrp,
423 netif_receive_skb(skb);
425 } else { /* Error occured */
426 pr->p_state.poll_receive_errors++;
427 port_reset = ehea_treat_poll_error(pr, rq, cqe,
433 cqe = ehea_poll_rq1(qp, &wqe_index);
436 dev->quota -= processed;
437 *budget -= processed;
439 pr->p_state.ehea_poll += 1;
440 pr->rx_packets += processed;
442 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
443 ehea_refill_rq2(pr, processed_rq2);
444 ehea_refill_rq3(pr, processed_rq3);
446 intreq = ((pr->p_state.ehea_poll & 0xF) == 0xF);
448 if (!cqe || intreq) {
449 netif_rx_complete(dev);
450 ehea_reset_cq_ep(pr->recv_cq);
451 ehea_reset_cq_n1(pr->recv_cq);
452 cqe = hw_qeit_get_valid(&qp->hw_rqueue1);
455 if (!netif_rx_reschedule(dev, my_quota))
461 void free_sent_skbs(struct ehea_cqe *cqe, struct ehea_port_res *pr)
464 int index, max_index_mask, i;
466 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
467 max_index_mask = pr->sq_skba.len - 1;
468 for (i = 0; i < EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id); i++) {
469 skb = pr->sq_skba.arr[index];
472 pr->sq_skba.arr[index] = NULL;
474 ehea_error("skb=NULL, wr_id=%lX, loop=%d, index=%d",
475 cqe->wr_id, i, index);
478 index &= max_index_mask;
482 #define MAX_SENDCOMP_QUOTA 400
483 void ehea_send_irq_tasklet(unsigned long data)
485 struct ehea_port_res *pr = (struct ehea_port_res*)data;
486 struct ehea_cq *send_cq = pr->send_cq;
487 struct ehea_cqe *cqe;
488 int quota = MAX_SENDCOMP_QUOTA;
494 cqe = ehea_poll_cq(send_cq);
496 ehea_reset_cq_ep(send_cq);
497 ehea_reset_cq_n1(send_cq);
498 cqe = ehea_poll_cq(send_cq);
504 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
505 ehea_error("Send Completion Error: Resetting port");
506 if (netif_msg_tx_err(pr->port))
507 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
508 queue_work(pr->port->adapter->ehea_wq,
509 &pr->port->reset_task);
513 if (netif_msg_tx_done(pr->port))
514 ehea_dump(cqe, sizeof(*cqe), "CQE");
516 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
518 free_sent_skbs(cqe, pr);
520 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
524 ehea_update_feca(send_cq, cqe_counter);
525 atomic_add(swqe_av, &pr->swqe_avail);
527 spin_lock_irqsave(&pr->netif_queue, flags);
528 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
529 >= pr->swqe_refill_th)) {
530 netif_wake_queue(pr->port->netdev);
531 pr->queue_stopped = 0;
533 spin_unlock_irqrestore(&pr->netif_queue, flags);
536 tasklet_hi_schedule(&pr->send_comp_task);
539 static irqreturn_t ehea_send_irq_handler(int irq, void *param,
540 struct pt_regs *regs)
542 struct ehea_port_res *pr = param;
543 tasklet_hi_schedule(&pr->send_comp_task);
547 static irqreturn_t ehea_recv_irq_handler(int irq, void *param,
548 struct pt_regs *regs)
550 struct ehea_port_res *pr = param;
551 struct ehea_port *port = pr->port;
552 netif_rx_schedule(port->netdev);
556 static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param,
557 struct pt_regs *regs)
559 struct ehea_port *port = param;
560 struct ehea_eqe *eqe;
563 eqe = ehea_poll_eq(port->qp_eq);
564 ehea_debug("eqe=%p", eqe);
566 ehea_debug("*eqe=%lx", *(u64*)eqe);
567 eqe = ehea_poll_eq(port->qp_eq);
568 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
569 ehea_debug("next eqe=%p", eqe);
575 static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
580 for (i = 0; i < adapter->num_ports; i++)
581 if (adapter->port[i]->logical_port_id == logical_port)
582 return adapter->port[i];
586 int ehea_sense_port_attr(struct ehea_port *port)
590 struct hcp_ehea_port_cb0 *cb0;
592 cb0 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
594 ehea_error("no mem for cb0");
599 hret = ehea_h_query_ehea_port(port->adapter->handle,
600 port->logical_port_id, H_PORT_CB0,
601 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
603 if (hret != H_SUCCESS) {
609 port->mac_addr = cb0->port_mac_addr << 16;
611 if (!is_valid_ether_addr((u8*)&port->mac_addr)) {
612 ret = -EADDRNOTAVAIL;
617 switch (cb0->port_speed) {
619 port->port_speed = EHEA_SPEED_10M;
620 port->full_duplex = 0;
623 port->port_speed = EHEA_SPEED_10M;
624 port->full_duplex = 1;
627 port->port_speed = EHEA_SPEED_100M;
628 port->full_duplex = 0;
631 port->port_speed = EHEA_SPEED_100M;
632 port->full_duplex = 1;
635 port->port_speed = EHEA_SPEED_1G;
636 port->full_duplex = 1;
639 port->port_speed = EHEA_SPEED_10G;
640 port->full_duplex = 1;
643 port->port_speed = 0;
644 port->full_duplex = 0;
648 /* Number of default QPs */
649 port->num_def_qps = cb0->num_default_qps;
651 if (!port->num_def_qps) {
656 if (port->num_def_qps >= EHEA_NUM_TX_QP)
657 port->num_add_tx_qps = 0;
659 port->num_add_tx_qps = EHEA_NUM_TX_QP - port->num_def_qps;
663 if (ret || netif_msg_probe(port))
664 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
670 int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
672 struct hcp_ehea_port_cb4 *cb4;
676 cb4 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
678 ehea_error("no mem for cb4");
683 cb4->port_speed = port_speed;
685 netif_carrier_off(port->netdev);
687 hret = ehea_h_modify_ehea_port(port->adapter->handle,
688 port->logical_port_id,
689 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
690 if (hret == H_SUCCESS) {
691 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
693 hret = ehea_h_query_ehea_port(port->adapter->handle,
694 port->logical_port_id,
695 H_PORT_CB4, H_PORT_CB4_SPEED,
697 if (hret == H_SUCCESS) {
698 switch (cb4->port_speed) {
700 port->port_speed = EHEA_SPEED_10M;
701 port->full_duplex = 0;
704 port->port_speed = EHEA_SPEED_10M;
705 port->full_duplex = 1;
708 port->port_speed = EHEA_SPEED_100M;
709 port->full_duplex = 0;
712 port->port_speed = EHEA_SPEED_100M;
713 port->full_duplex = 1;
716 port->port_speed = EHEA_SPEED_1G;
717 port->full_duplex = 1;
720 port->port_speed = EHEA_SPEED_10G;
721 port->full_duplex = 1;
724 port->port_speed = 0;
725 port->full_duplex = 0;
729 ehea_error("Failed sensing port speed");
733 if (hret == H_AUTHORITY) {
734 ehea_info("Hypervisor denied setting port speed. Either"
735 " this partition is not authorized to set "
736 "port speed or another partition has modified"
737 " port speed first.");
741 ehea_error("Failed setting port speed");
744 netif_carrier_on(port->netdev);
750 static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
755 struct ehea_port *port;
757 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
758 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
759 port = ehea_get_port(adapter, portnum);
762 case EHEA_EC_PORTSTATE_CHG: /* port state change */
765 ehea_error("unknown portnum %x", portnum);
769 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
770 if (!netif_carrier_ok(port->netdev)) {
771 ret = ehea_sense_port_attr(
772 adapter->port[portnum]);
774 ehea_error("failed resensing port "
779 if (netif_msg_link(port))
780 ehea_info("%s: Logical port up: %dMbps "
785 1 ? "Full" : "Half");
787 netif_carrier_on(port->netdev);
788 netif_wake_queue(port->netdev);
791 if (netif_carrier_ok(port->netdev)) {
792 if (netif_msg_link(port))
793 ehea_info("%s: Logical port down",
795 netif_carrier_off(port->netdev);
796 netif_stop_queue(port->netdev);
799 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
800 if (netif_msg_link(port))
801 ehea_info("%s: Physical port up",
804 if (netif_msg_link(port))
805 ehea_info("%s: Physical port down",
809 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
810 ehea_info("External switch port is primary port");
812 ehea_info("External switch port is backup port");
815 case EHEA_EC_ADAPTER_MALFUNC:
816 ehea_error("Adapter malfunction");
818 case EHEA_EC_PORT_MALFUNC:
819 ehea_info("Port malfunction: Device: %s", port->netdev->name);
820 netif_carrier_off(port->netdev);
821 netif_stop_queue(port->netdev);
824 ehea_error("unknown event code %x", ec);
829 static void ehea_neq_tasklet(unsigned long data)
831 struct ehea_adapter *adapter = (struct ehea_adapter*)data;
832 struct ehea_eqe *eqe;
835 eqe = ehea_poll_eq(adapter->neq);
836 ehea_debug("eqe=%p", eqe);
839 ehea_debug("*eqe=%lx", eqe->entry);
840 ehea_parse_eqe(adapter, eqe->entry);
841 eqe = ehea_poll_eq(adapter->neq);
842 ehea_debug("next eqe=%p", eqe);
845 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
846 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
847 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
849 ehea_h_reset_events(adapter->handle,
850 adapter->neq->fw_handle, event_mask);
853 static irqreturn_t ehea_interrupt_neq(int irq, void *param,
854 struct pt_regs *regs)
856 struct ehea_adapter *adapter = param;
857 tasklet_hi_schedule(&adapter->neq_tasklet);
862 static int ehea_fill_port_res(struct ehea_port_res *pr)
865 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
867 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
868 - init_attr->act_nr_rwqes_rq2
869 - init_attr->act_nr_rwqes_rq3 - 1);
871 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
873 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
878 static int ehea_reg_interrupts(struct net_device *dev)
880 struct ehea_port *port = netdev_priv(dev);
881 struct ehea_port_res *pr;
884 for (i = 0; i < port->num_def_qps; i++) {
885 pr = &port->port_res[i];
886 snprintf(pr->int_recv_name, EHEA_IRQ_NAME_SIZE - 1
887 , "%s-recv%d", dev->name, i);
888 ret = ibmebus_request_irq(NULL, pr->recv_eq->attr.ist1,
889 ehea_recv_irq_handler,
890 SA_INTERRUPT, pr->int_recv_name, pr);
892 ehea_error("failed registering irq for ehea_recv_int:"
893 "port_res_nr:%d, ist=%X", i,
894 pr->recv_eq->attr.ist1);
897 if (netif_msg_ifup(port))
898 ehea_info("irq_handle 0x%X for funct ehea_recv_int %d "
899 "registered", pr->recv_eq->attr.ist1, i);
902 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
905 ret = ibmebus_request_irq(NULL, port->qp_eq->attr.ist1,
906 ehea_qp_aff_irq_handler,
907 SA_INTERRUPT, port->int_aff_name, port);
909 ehea_error("failed registering irq for qp_aff_irq_handler:"
910 "ist=%X", port->qp_eq->attr.ist1);
914 if (netif_msg_ifup(port))
915 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
916 "registered", port->qp_eq->attr.ist1);
918 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
919 pr = &port->port_res[i];
920 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
921 "%s-send%d", dev->name, i);
922 ret = ibmebus_request_irq(NULL, pr->send_eq->attr.ist1,
923 ehea_send_irq_handler,
924 SA_INTERRUPT, pr->int_send_name,
927 ehea_error("failed registering irq for ehea_send "
928 "port_res_nr:%d, ist=%X", i,
929 pr->send_eq->attr.ist1);
932 if (netif_msg_ifup(port))
933 ehea_info("irq_handle 0x%X for function ehea_send_int "
934 "%d registered", pr->send_eq->attr.ist1, i);
941 u32 ist = port->port_res[i].send_eq->attr.ist1;
942 ibmebus_free_irq(NULL, ist, &port->port_res[i]);
945 ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port);
946 i = port->num_def_qps;
949 u32 ist = port->port_res[i].recv_eq->attr.ist1;
950 ibmebus_free_irq(NULL, ist, &port->port_res[i]);
955 static void ehea_free_interrupts(struct net_device *dev)
957 struct ehea_port *port = netdev_priv(dev);
958 struct ehea_port_res *pr;
962 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
963 pr = &port->port_res[i];
964 ibmebus_free_irq(NULL, pr->send_eq->attr.ist1, pr);
965 if (netif_msg_intr(port))
966 ehea_info("free send irq for res %d with handle 0x%X",
967 i, pr->send_eq->attr.ist1);
971 for (i = 0; i < port->num_def_qps; i++) {
972 pr = &port->port_res[i];
973 ibmebus_free_irq(NULL, pr->recv_eq->attr.ist1, pr);
974 if (netif_msg_intr(port))
975 ehea_info("free recv irq for res %d with handle 0x%X",
976 i, pr->recv_eq->attr.ist1);
979 /* associated events */
980 ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port);
981 if (netif_msg_intr(port))
982 ehea_info("associated event interrupt for handle 0x%X freed",
983 port->qp_eq->attr.ist1);
986 static int ehea_configure_port(struct ehea_port *port)
990 struct hcp_ehea_port_cb0 *cb0;
993 cb0 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
997 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
998 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
999 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1000 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1001 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1002 PXLY_RC_VLAN_FILTER)
1003 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1005 for (i = 0; i < port->num_def_qps; i++)
1006 cb0->default_qpn_arr[i] = port->port_res[i].qp->init_attr.qp_nr;
1008 if (netif_msg_ifup(port))
1009 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1011 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1012 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1014 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1015 port->logical_port_id,
1016 H_PORT_CB0, mask, cb0);
1018 if (hret != H_SUCCESS)
1029 static int ehea_gen_smrs(struct ehea_port_res *pr)
1032 struct ehea_adapter *adapter = pr->port->adapter;
1034 hret = ehea_h_register_smr(adapter->handle, adapter->mr.handle,
1035 adapter->mr.vaddr, EHEA_MR_ACC_CTRL,
1036 adapter->pd, &pr->send_mr);
1037 if (hret != H_SUCCESS)
1040 hret = ehea_h_register_smr(adapter->handle, adapter->mr.handle,
1041 adapter->mr.vaddr, EHEA_MR_ACC_CTRL,
1042 adapter->pd, &pr->recv_mr);
1043 if (hret != H_SUCCESS)
1049 hret = ehea_h_free_resource(adapter->handle, pr->send_mr.handle);
1050 if (hret != H_SUCCESS)
1051 ehea_error("failed freeing SMR");
1056 static int ehea_rem_smrs(struct ehea_port_res *pr)
1058 struct ehea_adapter *adapter = pr->port->adapter;
1062 hret = ehea_h_free_resource(adapter->handle, pr->send_mr.handle);
1063 if (hret != H_SUCCESS) {
1065 ehea_error("failed freeing send SMR for pr=%p", pr);
1068 hret = ehea_h_free_resource(adapter->handle, pr->recv_mr.handle);
1069 if (hret != H_SUCCESS) {
1071 ehea_error("failed freeing recv SMR for pr=%p", pr);
1077 static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1079 int arr_size = sizeof(void*) * max_q_entries;
1081 q_skba->arr = vmalloc(arr_size);
1085 memset(q_skba->arr, 0, arr_size);
1087 q_skba->len = max_q_entries;
1089 q_skba->os_skbs = 0;
1094 static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1095 struct port_res_cfg *pr_cfg, int queue_token)
1097 struct ehea_adapter *adapter = port->adapter;
1098 enum ehea_eq_type eq_type = EHEA_EQ;
1099 struct ehea_qp_init_attr *init_attr = NULL;
1102 memset(pr, 0, sizeof(struct ehea_port_res));
1105 spin_lock_init(&pr->send_lock);
1106 spin_lock_init(&pr->recv_lock);
1107 spin_lock_init(&pr->xmit_lock);
1108 spin_lock_init(&pr->netif_queue);
1110 pr->recv_eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1112 ehea_error("create_eq failed (recv_eq)");
1116 pr->send_eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1118 ehea_error("create_eq failed (send_eq)");
1122 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
1123 pr->recv_eq->fw_handle,
1124 port->logical_port_id);
1126 ehea_error("create_cq failed (cq_recv)");
1130 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
1131 pr->send_eq->fw_handle,
1132 port->logical_port_id);
1134 ehea_error("create_cq failed (cq_send)");
1138 if (netif_msg_ifup(port))
1139 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1140 pr->send_cq->attr.act_nr_of_cqes,
1141 pr->recv_cq->attr.act_nr_of_cqes);
1143 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1146 ehea_error("no mem for ehea_qp_init_attr");
1150 init_attr->low_lat_rq1 = 1;
1151 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1152 init_attr->rq_count = 3;
1153 init_attr->qp_token = queue_token;
1154 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1155 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1156 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1157 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1158 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1159 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1160 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1161 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1162 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1163 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1164 init_attr->port_nr = port->logical_port_id;
1165 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1166 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1167 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1169 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1171 ehea_error("create_qp failed");
1176 if (netif_msg_ifup(port))
1177 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1178 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1179 init_attr->act_nr_send_wqes,
1180 init_attr->act_nr_rwqes_rq1,
1181 init_attr->act_nr_rwqes_rq2,
1182 init_attr->act_nr_rwqes_rq3);
1184 ret = ehea_init_q_skba(&pr->sq_skba, init_attr->act_nr_send_wqes + 1);
1185 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1186 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1187 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1191 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1192 if (ehea_gen_smrs(pr) != 0) {
1196 tasklet_init(&pr->send_comp_task, ehea_send_irq_tasklet,
1198 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1206 vfree(pr->sq_skba.arr);
1207 vfree(pr->rq1_skba.arr);
1208 vfree(pr->rq2_skba.arr);
1209 vfree(pr->rq3_skba.arr);
1210 ehea_destroy_qp(pr->qp);
1211 ehea_destroy_cq(pr->send_cq);
1212 ehea_destroy_cq(pr->recv_cq);
1213 ehea_destroy_eq(pr->send_eq);
1214 ehea_destroy_eq(pr->recv_eq);
1219 static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1223 ret = ehea_destroy_qp(pr->qp);
1226 ehea_destroy_cq(pr->send_cq);
1227 ehea_destroy_cq(pr->recv_cq);
1228 ehea_destroy_eq(pr->send_eq);
1229 ehea_destroy_eq(pr->recv_eq);
1231 for (i = 0; i < pr->rq1_skba.len; i++)
1232 if (pr->rq1_skba.arr[i])
1233 dev_kfree_skb(pr->rq1_skba.arr[i]);
1235 for (i = 0; i < pr->rq2_skba.len; i++)
1236 if (pr->rq2_skba.arr[i])
1237 dev_kfree_skb(pr->rq2_skba.arr[i]);
1239 for (i = 0; i < pr->rq3_skba.len; i++)
1240 if (pr->rq3_skba.arr[i])
1241 dev_kfree_skb(pr->rq3_skba.arr[i]);
1243 for (i = 0; i < pr->sq_skba.len; i++)
1244 if (pr->sq_skba.arr[i])
1245 dev_kfree_skb(pr->sq_skba.arr[i]);
1247 vfree(pr->rq1_skba.arr);
1248 vfree(pr->rq2_skba.arr);
1249 vfree(pr->rq3_skba.arr);
1250 vfree(pr->sq_skba.arr);
1251 ret = ehea_rem_smrs(pr);
1257 * The write_* functions store information in swqe which is used by
1258 * the hardware to calculate the ip/tcp/udp checksum
1261 static inline void write_ip_start_end(struct ehea_swqe *swqe,
1262 const struct sk_buff *skb)
1264 swqe->ip_start = (u8)(((u64)skb->nh.iph) - ((u64)skb->data));
1265 swqe->ip_end = (u8)(swqe->ip_start + skb->nh.iph->ihl * 4 - 1);
1268 static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1269 const struct sk_buff *skb)
1272 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1274 swqe->tcp_end = (u16)skb->len - 1;
1277 static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1278 const struct sk_buff *skb)
1281 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1283 swqe->tcp_end = (u16)skb->len - 1;
1287 static void write_swqe2_TSO(struct sk_buff *skb,
1288 struct ehea_swqe *swqe, u32 lkey)
1290 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1291 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1292 int skb_data_size = skb->len - skb->data_len;
1296 /* Packet is TCP with TSO enabled */
1297 swqe->tx_control |= EHEA_SWQE_TSO;
1298 swqe->mss = skb_shinfo(skb)->gso_size;
1299 /* copy only eth/ip/tcp headers to immediate data and
1300 * the rest of skb->data to sg1entry
1302 headersize = ETH_HLEN + (skb->nh.iph->ihl * 4) + (skb->h.th->doff * 4);
1304 skb_data_size = skb->len - skb->data_len;
1306 if (skb_data_size >= headersize) {
1307 /* copy immediate data */
1308 memcpy(imm_data, skb->data, headersize);
1309 swqe->immediate_data_length = headersize;
1311 if (skb_data_size > headersize) {
1312 /* set sg1entry data */
1313 sg1entry->l_key = lkey;
1314 sg1entry->len = skb_data_size - headersize;
1316 tmp_addr = (u64)(skb->data + headersize);
1317 sg1entry->vaddr = tmp_addr;
1318 swqe->descriptors++;
1321 ehea_error("cannot handle fragmented headers");
1324 static void write_swqe2_nonTSO(struct sk_buff *skb,
1325 struct ehea_swqe *swqe, u32 lkey)
1327 int skb_data_size = skb->len - skb->data_len;
1328 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1329 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1332 /* Packet is any nonTSO type
1334 * Copy as much as possible skb->data to immediate data and
1335 * the rest to sg1entry
1337 if (skb_data_size >= SWQE2_MAX_IMM) {
1338 /* copy immediate data */
1339 memcpy(imm_data, skb->data, SWQE2_MAX_IMM);
1341 swqe->immediate_data_length = SWQE2_MAX_IMM;
1343 if (skb_data_size > SWQE2_MAX_IMM) {
1344 /* copy sg1entry data */
1345 sg1entry->l_key = lkey;
1346 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
1347 tmp_addr = (u64)(skb->data + SWQE2_MAX_IMM);
1348 sg1entry->vaddr = tmp_addr;
1349 swqe->descriptors++;
1352 memcpy(imm_data, skb->data, skb_data_size);
1353 swqe->immediate_data_length = skb_data_size;
1357 static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1358 struct ehea_swqe *swqe, u32 lkey)
1360 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1362 int nfrags, sg1entry_contains_frag_data, i;
1365 nfrags = skb_shinfo(skb)->nr_frags;
1366 sg1entry = &swqe->u.immdata_desc.sg_entry;
1367 sg_list = (struct ehea_vsgentry*)&swqe->u.immdata_desc.sg_list;
1368 swqe->descriptors = 0;
1369 sg1entry_contains_frag_data = 0;
1371 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1372 write_swqe2_TSO(skb, swqe, lkey);
1374 write_swqe2_nonTSO(skb, swqe, lkey);
1376 /* write descriptors */
1378 if (swqe->descriptors == 0) {
1379 /* sg1entry not yet used */
1380 frag = &skb_shinfo(skb)->frags[0];
1382 /* copy sg1entry data */
1383 sg1entry->l_key = lkey;
1384 sg1entry->len = frag->size;
1385 tmp_addr = (u64)(page_address(frag->page)
1386 + frag->page_offset);
1387 sg1entry->vaddr = tmp_addr;
1388 swqe->descriptors++;
1389 sg1entry_contains_frag_data = 1;
1392 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1394 frag = &skb_shinfo(skb)->frags[i];
1395 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1397 sgentry->l_key = lkey;
1398 sgentry->len = frag->size;
1400 tmp_addr = (u64)(page_address(frag->page)
1401 + frag->page_offset);
1402 sgentry->vaddr = tmp_addr;
1403 swqe->descriptors++;
1408 static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1414 /* De/Register untagged packets */
1415 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1416 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1417 port->logical_port_id,
1418 reg_type, port->mac_addr, 0, hcallid);
1419 if (hret != H_SUCCESS) {
1420 ehea_error("reg_dereg_bcmc failed (tagged)");
1425 /* De/Register VLAN packets */
1426 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1427 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1428 port->logical_port_id,
1429 reg_type, port->mac_addr, 0, hcallid);
1430 if (hret != H_SUCCESS) {
1431 ehea_error("reg_dereg_bcmc failed (vlan)");
1438 static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1440 struct ehea_port *port = netdev_priv(dev);
1441 struct sockaddr *mac_addr = sa;
1442 struct hcp_ehea_port_cb0 *cb0;
1446 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1447 ret = -EADDRNOTAVAIL;
1451 cb0 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
1453 ehea_error("no mem for cb0");
1458 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1460 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1462 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1463 port->logical_port_id, H_PORT_CB0,
1464 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1465 if (hret != H_SUCCESS) {
1470 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1472 /* Deregister old MAC in pHYP */
1473 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1477 port->mac_addr = cb0->port_mac_addr << 16;
1479 /* Register new MAC in pHYP */
1480 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1491 static void ehea_promiscuous_error(u64 hret, int enable)
1493 ehea_info("Hypervisor denied %sabling promiscuous mode.%s",
1494 enable == 1 ? "en" : "dis",
1495 hret != H_AUTHORITY ? "" : " Another partition owning a "
1496 "logical port on the same physical port might have altered "
1497 "promiscuous mode first.");
1500 static void ehea_promiscuous(struct net_device *dev, int enable)
1502 struct ehea_port *port = netdev_priv(dev);
1503 struct hcp_ehea_port_cb7 *cb7;
1506 if ((enable && port->promisc) || (!enable && !port->promisc))
1509 cb7 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
1511 ehea_error("no mem for cb7");
1515 /* Modify Pxs_DUCQPN in CB7 */
1516 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1518 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1519 port->logical_port_id,
1520 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1522 ehea_promiscuous_error(hret, enable);
1526 port->promisc = enable;
1532 static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1538 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1539 | EHEA_BCMC_UNTAGGED;
1541 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1542 port->logical_port_id,
1543 reg_type, mc_mac_addr, 0, hcallid);
1547 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1548 | EHEA_BCMC_VLANID_ALL;
1550 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1551 port->logical_port_id,
1552 reg_type, mc_mac_addr, 0, hcallid);
1557 static int ehea_drop_multicast_list(struct net_device *dev)
1559 struct ehea_port *port = netdev_priv(dev);
1560 struct ehea_mc_list *mc_entry = port->mc_list;
1561 struct list_head *pos;
1562 struct list_head *temp;
1566 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1567 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1569 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1572 ehea_error("failed deregistering mcast MAC");
1582 static void ehea_allmulti(struct net_device *dev, int enable)
1584 struct ehea_port *port = netdev_priv(dev);
1587 if (!port->allmulti) {
1589 /* Enable ALLMULTI */
1590 ehea_drop_multicast_list(dev);
1591 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1595 ehea_error("failed enabling IFF_ALLMULTI");
1599 /* Disable ALLMULTI */
1600 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1604 ehea_error("failed disabling IFF_ALLMULTI");
1608 static void ehea_add_multicast_entry(struct ehea_port* port, u8* mc_mac_addr)
1610 struct ehea_mc_list *ehea_mcl_entry;
1613 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_KERNEL);
1614 if (!ehea_mcl_entry) {
1615 ehea_error("no mem for mcl_entry");
1619 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1621 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1623 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1626 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1628 ehea_error("failed registering mcast MAC");
1629 kfree(ehea_mcl_entry);
1633 static void ehea_set_multicast_list(struct net_device *dev)
1635 struct ehea_port *port = netdev_priv(dev);
1636 struct dev_mc_list *k_mcl_entry;
1639 if (dev->flags & IFF_PROMISC) {
1640 ehea_promiscuous(dev, 1);
1643 ehea_promiscuous(dev, 0);
1645 if (dev->flags & IFF_ALLMULTI) {
1646 ehea_allmulti(dev, 1);
1649 ehea_allmulti(dev, 0);
1651 if (dev->mc_count) {
1652 ret = ehea_drop_multicast_list(dev);
1654 /* Dropping the current multicast list failed.
1655 * Enabling ALL_MULTI is the best we can do.
1657 ehea_allmulti(dev, 1);
1660 if (dev->mc_count > port->adapter->max_mc_mac) {
1661 ehea_info("Mcast registration limit reached (0x%lx). "
1663 port->adapter->max_mc_mac);
1667 for (i = 0, k_mcl_entry = dev->mc_list;
1669 i++, k_mcl_entry = k_mcl_entry->next) {
1670 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
1677 static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1679 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1685 static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1686 struct ehea_swqe *swqe, u32 lkey)
1688 if (skb->protocol == htons(ETH_P_IP)) {
1690 swqe->tx_control |= EHEA_SWQE_CRC
1691 | EHEA_SWQE_IP_CHECKSUM
1692 | EHEA_SWQE_TCP_CHECKSUM
1693 | EHEA_SWQE_IMM_DATA_PRESENT
1694 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1696 write_ip_start_end(swqe, skb);
1698 if (skb->nh.iph->protocol == IPPROTO_UDP) {
1699 if ((skb->nh.iph->frag_off & IP_MF) ||
1700 (skb->nh.iph->frag_off & IP_OFFSET))
1701 /* IP fragment, so don't change cs */
1702 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
1704 write_udp_offset_end(swqe, skb);
1706 } else if (skb->nh.iph->protocol == IPPROTO_TCP) {
1707 write_tcp_offset_end(swqe, skb);
1710 /* icmp (big data) and ip segmentation packets (all other ip
1711 packets) do not require any special handling */
1714 /* Other Ethernet Protocol */
1715 swqe->tx_control |= EHEA_SWQE_CRC
1716 | EHEA_SWQE_IMM_DATA_PRESENT
1717 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1720 write_swqe2_data(skb, dev, swqe, lkey);
1723 static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
1724 struct ehea_swqe *swqe)
1726 int nfrags = skb_shinfo(skb)->nr_frags;
1727 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
1731 if (skb->protocol == htons(ETH_P_IP)) {
1733 write_ip_start_end(swqe, skb);
1735 if (skb->nh.iph->protocol == IPPROTO_TCP) {
1736 swqe->tx_control |= EHEA_SWQE_CRC
1737 | EHEA_SWQE_IP_CHECKSUM
1738 | EHEA_SWQE_TCP_CHECKSUM
1739 | EHEA_SWQE_IMM_DATA_PRESENT;
1741 write_tcp_offset_end(swqe, skb);
1743 } else if (skb->nh.iph->protocol == IPPROTO_UDP) {
1744 if ((skb->nh.iph->frag_off & IP_MF) ||
1745 (skb->nh.iph->frag_off & IP_OFFSET))
1746 /* IP fragment, so don't change cs */
1747 swqe->tx_control |= EHEA_SWQE_CRC
1748 | EHEA_SWQE_IMM_DATA_PRESENT;
1750 swqe->tx_control |= EHEA_SWQE_CRC
1751 | EHEA_SWQE_IP_CHECKSUM
1752 | EHEA_SWQE_TCP_CHECKSUM
1753 | EHEA_SWQE_IMM_DATA_PRESENT;
1755 write_udp_offset_end(swqe, skb);
1758 /* icmp (big data) and
1759 ip segmentation packets (all other ip packets) */
1760 swqe->tx_control |= EHEA_SWQE_CRC
1761 | EHEA_SWQE_IP_CHECKSUM
1762 | EHEA_SWQE_IMM_DATA_PRESENT;
1765 /* Other Ethernet Protocol */
1766 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
1768 /* copy (immediate) data */
1770 /* data is in a single piece */
1771 memcpy(imm_data, skb->data, skb->len);
1773 /* first copy data from the skb->data buffer ... */
1774 memcpy(imm_data, skb->data, skb->len - skb->data_len);
1775 imm_data += skb->len - skb->data_len;
1777 /* ... then copy data from the fragments */
1778 for (i = 0; i < nfrags; i++) {
1779 frag = &skb_shinfo(skb)->frags[i];
1781 page_address(frag->page) + frag->page_offset,
1783 imm_data += frag->size;
1786 swqe->immediate_data_length = skb->len;
1790 static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
1792 struct ehea_port *port = netdev_priv(dev);
1793 struct ehea_swqe *swqe;
1794 unsigned long flags;
1797 struct ehea_port_res *pr = &port->port_res[0];
1799 spin_lock(&pr->xmit_lock);
1801 swqe = ehea_get_swqe(pr->qp, &swqe_index);
1802 memset(swqe, 0, SWQE_HEADER_SIZE);
1803 atomic_dec(&pr->swqe_avail);
1805 if (skb->len <= SWQE3_MAX_IMM) {
1806 u32 sig_iv = port->sig_comp_iv;
1807 u32 swqe_num = pr->swqe_id_counter;
1808 ehea_xmit3(skb, dev, swqe);
1809 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
1810 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
1811 if (pr->swqe_ll_count >= (sig_iv - 1)) {
1812 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
1814 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1815 pr->swqe_ll_count = 0;
1817 pr->swqe_ll_count += 1;
1820 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
1821 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
1822 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
1823 pr->sq_skba.arr[pr->sq_skba.index] = skb;
1825 pr->sq_skba.index++;
1826 pr->sq_skba.index &= (pr->sq_skba.len - 1);
1828 lkey = pr->send_mr.lkey;
1829 ehea_xmit2(skb, dev, swqe, lkey);
1831 if (pr->swqe_count >= (EHEA_SIG_IV_LONG - 1)) {
1832 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
1834 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1837 pr->swqe_count += 1;
1839 pr->swqe_id_counter += 1;
1841 if (port->vgrp && vlan_tx_tag_present(skb)) {
1842 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
1843 swqe->vlan_tag = vlan_tx_tag_get(skb);
1846 if (netif_msg_tx_queued(port)) {
1847 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
1848 ehea_dump(swqe, sizeof(*swqe), "swqe");
1851 ehea_post_swqe(pr->qp, swqe);
1854 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
1855 spin_lock_irqsave(&pr->netif_queue, flags);
1856 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
1857 netif_stop_queue(dev);
1858 pr->queue_stopped = 1;
1860 spin_unlock_irqrestore(&pr->netif_queue, flags);
1862 dev->trans_start = jiffies;
1863 spin_unlock(&pr->xmit_lock);
1865 return NETDEV_TX_OK;
1868 static void ehea_vlan_rx_register(struct net_device *dev,
1869 struct vlan_group *grp)
1871 struct ehea_port *port = netdev_priv(dev);
1872 struct ehea_adapter *adapter = port->adapter;
1873 struct hcp_ehea_port_cb1 *cb1;
1878 cb1 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
1880 ehea_error("no mem for cb1");
1885 memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
1887 memset(cb1->vlan_filter, 0xFF, sizeof(cb1->vlan_filter));
1889 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1890 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1891 if (hret != H_SUCCESS)
1892 ehea_error("modify_ehea_port failed");
1899 static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1901 struct ehea_port *port = netdev_priv(dev);
1902 struct ehea_adapter *adapter = port->adapter;
1903 struct hcp_ehea_port_cb1 *cb1;
1907 cb1 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
1909 ehea_error("no mem for cb1");
1913 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
1914 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1915 if (hret != H_SUCCESS) {
1916 ehea_error("query_ehea_port failed");
1921 cb1->vlan_filter[index] |= ((u64)(1 << (vid & 0x3F)));
1923 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1924 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1925 if (hret != H_SUCCESS)
1926 ehea_error("modify_ehea_port failed");
1932 static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1934 struct ehea_port *port = netdev_priv(dev);
1935 struct ehea_adapter *adapter = port->adapter;
1936 struct hcp_ehea_port_cb1 *cb1;
1941 port->vgrp->vlan_devices[vid] = NULL;
1943 cb1 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
1945 ehea_error("no mem for cb1");
1949 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
1950 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1951 if (hret != H_SUCCESS) {
1952 ehea_error("query_ehea_port failed");
1957 cb1->vlan_filter[index] &= ~((u64)(1 << (vid & 0x3F)));
1959 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1960 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1961 if (hret != H_SUCCESS)
1962 ehea_error("modify_ehea_port failed");
1968 int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
1974 struct hcp_modify_qp_cb0* cb0;
1976 cb0 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
1982 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
1983 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
1984 if (hret != H_SUCCESS) {
1985 ehea_error("query_ehea_qp failed (1)");
1989 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
1990 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
1991 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
1992 &dummy64, &dummy64, &dummy16, &dummy16);
1993 if (hret != H_SUCCESS) {
1994 ehea_error("modify_ehea_qp failed (1)");
1998 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
1999 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2000 if (hret != H_SUCCESS) {
2001 ehea_error("query_ehea_qp failed (2)");
2005 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2006 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2007 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2008 &dummy64, &dummy64, &dummy16, &dummy16);
2009 if (hret != H_SUCCESS) {
2010 ehea_error("modify_ehea_qp failed (2)");
2014 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2015 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2016 if (hret != H_SUCCESS) {
2017 ehea_error("query_ehea_qp failed (3)");
2021 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2022 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2023 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2024 &dummy64, &dummy64, &dummy16, &dummy16);
2025 if (hret != H_SUCCESS) {
2026 ehea_error("modify_ehea_qp failed (3)");
2030 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2031 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2032 if (hret != H_SUCCESS) {
2033 ehea_error("query_ehea_qp failed (4)");
2043 static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2047 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2048 enum ehea_eq_type eq_type = EHEA_EQ;
2050 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2051 EHEA_MAX_ENTRIES_EQ, 1);
2054 ehea_error("ehea_create_eq failed (qp_eq)");
2058 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
2059 pr_cfg.max_entries_scq = sq_entries;
2060 pr_cfg.max_entries_sq = sq_entries;
2061 pr_cfg.max_entries_rq1 = rq1_entries;
2062 pr_cfg.max_entries_rq2 = rq2_entries;
2063 pr_cfg.max_entries_rq3 = rq3_entries;
2065 pr_cfg_small_rx.max_entries_rcq = 1;
2066 pr_cfg_small_rx.max_entries_scq = sq_entries;
2067 pr_cfg_small_rx.max_entries_sq = sq_entries;
2068 pr_cfg_small_rx.max_entries_rq1 = 1;
2069 pr_cfg_small_rx.max_entries_rq2 = 1;
2070 pr_cfg_small_rx.max_entries_rq3 = 1;
2072 for (i = 0; i < def_qps; i++) {
2073 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2077 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2078 ret = ehea_init_port_res(port, &port->port_res[i],
2079 &pr_cfg_small_rx, i);
2088 ehea_clean_portres(port, &port->port_res[i]);
2091 ehea_destroy_eq(port->qp_eq);
2095 static int ehea_clean_all_portres(struct ehea_port *port)
2100 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2101 ret |= ehea_clean_portres(port, &port->port_res[i]);
2103 ret |= ehea_destroy_eq(port->qp_eq);
2108 static int ehea_up(struct net_device *dev)
2111 struct ehea_port *port = netdev_priv(dev);
2114 if (port->state == EHEA_PORT_UP)
2117 ret = ehea_port_res_setup(port, port->num_def_qps,
2118 port->num_add_tx_qps);
2120 ehea_error("port_res_failed");
2124 /* Set default QP for this port */
2125 ret = ehea_configure_port(port);
2127 ehea_error("ehea_configure_port failed. ret:%d", ret);
2131 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2134 ehea_error("out_clean_pr");
2137 mac_addr = (*(u64*)dev->dev_addr) >> 16;
2139 ret = ehea_reg_interrupts(dev);
2141 ehea_error("out_dereg_bc");
2145 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2146 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2148 ehea_error("activate_qp failed");
2153 for(i = 0; i < port->num_def_qps; i++) {
2154 ret = ehea_fill_port_res(&port->port_res[i]);
2156 ehea_error("out_free_irqs");
2162 port->state = EHEA_PORT_UP;
2166 ehea_free_interrupts(dev);
2169 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2172 ehea_clean_all_portres(port);
2177 static int ehea_open(struct net_device *dev)
2180 struct ehea_port *port = netdev_priv(dev);
2182 down(&port->port_lock);
2184 if (netif_msg_ifup(port))
2185 ehea_info("enabling port %s", dev->name);
2189 netif_start_queue(dev);
2191 up(&port->port_lock);
2196 static int ehea_down(struct net_device *dev)
2199 struct ehea_port *port = netdev_priv(dev);
2201 if (port->state == EHEA_PORT_DOWN)
2204 ehea_drop_multicast_list(dev);
2205 ehea_free_interrupts(dev);
2207 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2208 tasklet_kill(&port->port_res[i].send_comp_task);
2210 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2211 ret = ehea_clean_all_portres(port);
2212 port->state = EHEA_PORT_DOWN;
2216 static int ehea_stop(struct net_device *dev)
2219 struct ehea_port *port = netdev_priv(dev);
2221 if (netif_msg_ifdown(port))
2222 ehea_info("disabling port %s", dev->name);
2224 flush_workqueue(port->adapter->ehea_wq);
2225 down(&port->port_lock);
2226 netif_stop_queue(dev);
2227 ret = ehea_down(dev);
2228 up(&port->port_lock);
2232 static void ehea_reset_port(void *data)
2235 struct net_device *dev = data;
2236 struct ehea_port *port = netdev_priv(dev);
2239 down(&port->port_lock);
2240 netif_stop_queue(dev);
2241 netif_poll_disable(dev);
2243 ret = ehea_down(dev);
2245 ehea_error("ehea_down failed. not all resources are freed");
2249 ehea_error("Reset device %s failed: ret=%d", dev->name, ret);
2253 if (netif_msg_timer(port))
2254 ehea_info("Device %s resetted successfully", dev->name);
2256 netif_poll_enable(dev);
2257 netif_wake_queue(dev);
2259 up(&port->port_lock);
2263 static void ehea_tx_watchdog(struct net_device *dev)
2265 struct ehea_port *port = netdev_priv(dev);
2267 if (netif_carrier_ok(dev))
2268 queue_work(port->adapter->ehea_wq, &port->reset_task);
2271 int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2273 struct hcp_query_ehea *cb;
2277 cb = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
2283 hret = ehea_h_query_ehea(adapter->handle, cb);
2285 if (hret != H_SUCCESS) {
2290 adapter->num_ports = cb->num_ports;
2291 adapter->max_mc_mac = cb->max_mc_mac - 1;
2300 static int ehea_setup_single_port(struct ehea_port *port,
2301 struct device_node *dn)
2305 struct net_device *dev = port->netdev;
2306 struct ehea_adapter *adapter = port->adapter;
2307 struct hcp_ehea_port_cb4 *cb4;
2308 u32 *dn_log_port_id;
2310 sema_init(&port->port_lock, 1);
2311 port->state = EHEA_PORT_DOWN;
2312 port->sig_comp_iv = sq_entries / 10;
2315 ehea_error("bad device node: dn=%p", dn);
2320 port->of_dev_node = dn;
2322 /* Determine logical port id */
2323 dn_log_port_id = (u32*)get_property(dn, "ibm,hea-port-no", NULL);
2325 if (!dn_log_port_id) {
2326 ehea_error("bad device node: dn_log_port_id=%p",
2331 port->logical_port_id = *dn_log_port_id;
2333 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
2334 if (!port->mc_list) {
2339 INIT_LIST_HEAD(&port->mc_list->list);
2341 ehea_set_portspeed(port, EHEA_SPEED_AUTONEG);
2343 ret = ehea_sense_port_attr(port);
2347 /* Enable Jumbo frames */
2348 cb4 = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
2350 ehea_error("no mem for cb4");
2352 cb4->jumbo_frame = 1;
2353 hret = ehea_h_modify_ehea_port(adapter->handle,
2354 port->logical_port_id,
2355 H_PORT_CB4, H_PORT_CB4_JUMBO,
2357 if (hret != H_SUCCESS) {
2358 ehea_info("Jumbo frames not activated");
2363 /* initialize net_device structure */
2364 SET_MODULE_OWNER(dev);
2366 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
2368 dev->open = ehea_open;
2369 dev->poll = ehea_poll;
2371 dev->stop = ehea_stop;
2372 dev->hard_start_xmit = ehea_start_xmit;
2373 dev->get_stats = ehea_get_stats;
2374 dev->set_multicast_list = ehea_set_multicast_list;
2375 dev->set_mac_address = ehea_set_mac_addr;
2376 dev->change_mtu = ehea_change_mtu;
2377 dev->vlan_rx_register = ehea_vlan_rx_register;
2378 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
2379 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
2380 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
2381 | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX
2382 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
2384 dev->tx_timeout = &ehea_tx_watchdog;
2385 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
2387 INIT_WORK(&port->reset_task, ehea_reset_port, dev);
2389 ehea_set_ethtool_ops(dev);
2391 ret = register_netdev(dev);
2393 ehea_error("register_netdev failed. ret=%d", ret);
2402 kfree(port->mc_list);
2407 static int ehea_setup_ports(struct ehea_adapter *adapter)
2410 int port_setup_ok = 0;
2411 struct ehea_port *port;
2412 struct device_node *dn = NULL;
2413 struct net_device *dev;
2416 /* get port properties for all ports */
2417 for (i = 0; i < adapter->num_ports; i++) {
2419 if (adapter->port[i])
2420 continue; /* port already up and running */
2422 /* allocate memory for the port structures */
2423 dev = alloc_etherdev(sizeof(struct ehea_port));
2426 ehea_error("no mem for net_device");
2430 port = netdev_priv(dev);
2431 port->adapter = adapter;
2433 adapter->port[i] = port;
2434 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
2436 dn = of_find_node_by_name(dn, "ethernet");
2437 ret = ehea_setup_single_port(port, dn);
2439 /* Free mem for this port struct. The others will be
2440 processed on rollback */
2442 adapter->port[i] = NULL;
2443 ehea_error("eHEA port %d setup failed, ret=%d", i, ret);
2449 /* Check for succesfully set up ports */
2450 for (i = 0; i < adapter->num_ports; i++)
2451 if (adapter->port[i])
2455 ret = 0; /* At least some ports are setup correctly */
2462 static int __devinit ehea_probe(struct ibmebus_dev *dev,
2463 const struct of_device_id *id)
2465 struct ehea_adapter *adapter;
2466 u64 *adapter_handle;
2469 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
2472 dev_err(&dev->ofdev.dev, "no mem for ehea_adapter\n");
2476 adapter_handle = (u64*)get_property(dev->ofdev.node, "ibm,hea-handle",
2478 if (!adapter_handle) {
2479 dev_err(&dev->ofdev.dev, "failed getting handle for adapter"
2480 " '%s'\n", dev->ofdev.node->full_name);
2485 adapter->handle = *adapter_handle;
2486 adapter->pd = EHEA_PD_ID;
2488 dev->ofdev.dev.driver_data = adapter;
2490 ret = ehea_reg_mr_adapter(adapter);
2492 dev_err(&dev->ofdev.dev, "reg_mr_adapter failed\n");
2496 /* initialize adapter and ports */
2497 /* get adapter properties */
2498 ret = ehea_sense_adapter_attr(adapter);
2500 dev_err(&dev->ofdev.dev, "sense_adapter_attr failed: %d", ret);
2503 dev_info(&dev->ofdev.dev, "%d eHEA ports found\n", adapter->num_ports);
2505 adapter->neq = ehea_create_eq(adapter,
2506 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
2507 if (!adapter->neq) {
2508 dev_err(&dev->ofdev.dev, "NEQ creation failed");
2512 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
2513 (unsigned long)adapter);
2515 ret = ibmebus_request_irq(NULL, adapter->neq->attr.ist1,
2516 ehea_interrupt_neq, SA_INTERRUPT,
2517 "ehea_neq", adapter);
2519 dev_err(&dev->ofdev.dev, "requesting NEQ IRQ failed");
2523 adapter->ehea_wq = create_workqueue("ehea_wq");
2524 if (!adapter->ehea_wq)
2527 ret = ehea_setup_ports(adapter);
2529 dev_err(&dev->ofdev.dev, "setup_ports failed");
2537 destroy_workqueue(adapter->ehea_wq);
2540 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
2543 ehea_destroy_eq(adapter->neq);
2546 ehea_h_free_resource(adapter->handle, adapter->mr.handle);
2554 static void ehea_shutdown_single_port(struct ehea_port *port)
2556 unregister_netdev(port->netdev);
2557 kfree(port->mc_list);
2558 free_netdev(port->netdev);
2561 static int __devexit ehea_remove(struct ibmebus_dev *dev)
2563 struct ehea_adapter *adapter = dev->ofdev.dev.driver_data;
2567 for (i = 0; i < adapter->num_ports; i++)
2568 if (adapter->port[i]) {
2569 ehea_shutdown_single_port(adapter->port[i]);
2570 adapter->port[i] = NULL;
2572 destroy_workqueue(adapter->ehea_wq);
2574 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
2576 ehea_destroy_eq(adapter->neq);
2578 hret = ehea_h_free_resource(adapter->handle, adapter->mr.handle);
2580 dev_err(&dev->ofdev.dev, "free_resource_mr failed");
2587 static int check_module_parm(void)
2591 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
2592 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
2593 ehea_info("Bad parameter: rq1_entries");
2596 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
2597 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
2598 ehea_info("Bad parameter: rq2_entries");
2601 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
2602 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
2603 ehea_info("Bad parameter: rq3_entries");
2606 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
2607 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
2608 ehea_info("Bad parameter: sq_entries");
2615 static struct of_device_id ehea_device_table[] = {
2618 .compatible = "IBM,lhea",
2623 static struct ibmebus_driver ehea_driver = {
2625 .id_table = ehea_device_table,
2626 .probe = ehea_probe,
2627 .remove = ehea_remove,
2630 int __init ehea_module_init(void)
2634 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
2637 ret = check_module_parm();
2640 ret = ibmebus_register_driver(&ehea_driver);
2642 ehea_error("failed registering eHEA device driver on ebus");
2648 static void __exit ehea_module_exit(void)
2650 ibmebus_unregister_driver(&ehea_driver);
2653 module_init(ehea_module_init);
2654 module_exit(ehea_module_exit);