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(PAGE_SIZE, 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)
541 struct ehea_port_res *pr = param;
542 tasklet_hi_schedule(&pr->send_comp_task);
546 static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
548 struct ehea_port_res *pr = param;
549 struct ehea_port *port = pr->port;
550 netif_rx_schedule(port->netdev);
554 static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
556 struct ehea_port *port = param;
557 struct ehea_eqe *eqe;
561 eqe = ehea_poll_eq(port->qp_eq);
564 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
565 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
566 eqe->entry, qp_token);
568 qp = port->port_res[qp_token].qp;
569 ehea_error_data(port->adapter, qp->fw_handle);
570 eqe = ehea_poll_eq(port->qp_eq);
573 queue_work(port->adapter->ehea_wq, &port->reset_task);
578 static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
583 for (i = 0; i < adapter->num_ports; i++)
584 if (adapter->port[i])
585 if (adapter->port[i]->logical_port_id == logical_port)
586 return adapter->port[i];
590 int ehea_sense_port_attr(struct ehea_port *port)
594 struct hcp_ehea_port_cb0 *cb0;
596 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC); /* May be called via */
597 if (!cb0) { /* ehea_neq_tasklet() */
598 ehea_error("no mem for cb0");
603 hret = ehea_h_query_ehea_port(port->adapter->handle,
604 port->logical_port_id, H_PORT_CB0,
605 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
607 if (hret != H_SUCCESS) {
613 port->mac_addr = cb0->port_mac_addr << 16;
615 if (!is_valid_ether_addr((u8*)&port->mac_addr)) {
616 ret = -EADDRNOTAVAIL;
621 switch (cb0->port_speed) {
623 port->port_speed = EHEA_SPEED_10M;
624 port->full_duplex = 0;
627 port->port_speed = EHEA_SPEED_10M;
628 port->full_duplex = 1;
631 port->port_speed = EHEA_SPEED_100M;
632 port->full_duplex = 0;
635 port->port_speed = EHEA_SPEED_100M;
636 port->full_duplex = 1;
639 port->port_speed = EHEA_SPEED_1G;
640 port->full_duplex = 1;
643 port->port_speed = EHEA_SPEED_10G;
644 port->full_duplex = 1;
647 port->port_speed = 0;
648 port->full_duplex = 0;
654 /* Number of default QPs */
655 port->num_def_qps = cb0->num_default_qps;
657 if (!port->num_def_qps) {
662 if (port->num_def_qps >= EHEA_NUM_TX_QP)
663 port->num_add_tx_qps = 0;
665 port->num_add_tx_qps = EHEA_NUM_TX_QP - port->num_def_qps;
669 if (ret || netif_msg_probe(port))
670 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
676 int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
678 struct hcp_ehea_port_cb4 *cb4;
682 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
684 ehea_error("no mem for cb4");
689 cb4->port_speed = port_speed;
691 netif_carrier_off(port->netdev);
693 hret = ehea_h_modify_ehea_port(port->adapter->handle,
694 port->logical_port_id,
695 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
696 if (hret == H_SUCCESS) {
697 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
699 hret = ehea_h_query_ehea_port(port->adapter->handle,
700 port->logical_port_id,
701 H_PORT_CB4, H_PORT_CB4_SPEED,
703 if (hret == H_SUCCESS) {
704 switch (cb4->port_speed) {
706 port->port_speed = EHEA_SPEED_10M;
707 port->full_duplex = 0;
710 port->port_speed = EHEA_SPEED_10M;
711 port->full_duplex = 1;
714 port->port_speed = EHEA_SPEED_100M;
715 port->full_duplex = 0;
718 port->port_speed = EHEA_SPEED_100M;
719 port->full_duplex = 1;
722 port->port_speed = EHEA_SPEED_1G;
723 port->full_duplex = 1;
726 port->port_speed = EHEA_SPEED_10G;
727 port->full_duplex = 1;
730 port->port_speed = 0;
731 port->full_duplex = 0;
735 ehea_error("Failed sensing port speed");
739 if (hret == H_AUTHORITY) {
740 ehea_info("Hypervisor denied setting port speed");
744 ehea_error("Failed setting port speed");
747 netif_carrier_on(port->netdev);
753 static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
758 struct ehea_port *port;
760 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
761 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
762 port = ehea_get_port(adapter, portnum);
765 case EHEA_EC_PORTSTATE_CHG: /* port state change */
768 ehea_error("unknown portnum %x", portnum);
772 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
773 if (!netif_carrier_ok(port->netdev)) {
774 ret = ehea_sense_port_attr(port);
776 ehea_error("failed resensing port "
781 if (netif_msg_link(port))
782 ehea_info("%s: Logical port up: %dMbps "
787 1 ? "Full" : "Half");
789 netif_carrier_on(port->netdev);
790 netif_wake_queue(port->netdev);
793 if (netif_carrier_ok(port->netdev)) {
794 if (netif_msg_link(port))
795 ehea_info("%s: Logical port down",
797 netif_carrier_off(port->netdev);
798 netif_stop_queue(port->netdev);
801 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
802 if (netif_msg_link(port))
803 ehea_info("%s: Physical port up",
806 if (netif_msg_link(port))
807 ehea_info("%s: Physical port down",
811 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
812 ehea_info("External switch port is primary port");
814 ehea_info("External switch port is backup port");
817 case EHEA_EC_ADAPTER_MALFUNC:
818 ehea_error("Adapter malfunction");
820 case EHEA_EC_PORT_MALFUNC:
821 ehea_info("Port malfunction: Device: %s", port->netdev->name);
822 netif_carrier_off(port->netdev);
823 netif_stop_queue(port->netdev);
826 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
831 static void ehea_neq_tasklet(unsigned long data)
833 struct ehea_adapter *adapter = (struct ehea_adapter*)data;
834 struct ehea_eqe *eqe;
837 eqe = ehea_poll_eq(adapter->neq);
838 ehea_debug("eqe=%p", eqe);
841 ehea_debug("*eqe=%lx", eqe->entry);
842 ehea_parse_eqe(adapter, eqe->entry);
843 eqe = ehea_poll_eq(adapter->neq);
844 ehea_debug("next eqe=%p", eqe);
847 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
848 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
849 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
851 ehea_h_reset_events(adapter->handle,
852 adapter->neq->fw_handle, event_mask);
855 static irqreturn_t ehea_interrupt_neq(int irq, void *param)
857 struct ehea_adapter *adapter = param;
858 tasklet_hi_schedule(&adapter->neq_tasklet);
863 static int ehea_fill_port_res(struct ehea_port_res *pr)
866 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
868 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
869 - init_attr->act_nr_rwqes_rq2
870 - init_attr->act_nr_rwqes_rq3 - 1);
872 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
874 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
879 static int ehea_reg_interrupts(struct net_device *dev)
881 struct ehea_port *port = netdev_priv(dev);
882 struct ehea_port_res *pr;
885 for (i = 0; i < port->num_def_qps; i++) {
886 pr = &port->port_res[i];
887 snprintf(pr->int_recv_name, EHEA_IRQ_NAME_SIZE - 1
888 , "%s-recv%d", dev->name, i);
889 ret = ibmebus_request_irq(NULL, pr->recv_eq->attr.ist1,
890 ehea_recv_irq_handler,
891 IRQF_DISABLED, pr->int_recv_name, pr);
893 ehea_error("failed registering irq for ehea_recv_int:"
894 "port_res_nr:%d, ist=%X", i,
895 pr->recv_eq->attr.ist1);
898 if (netif_msg_ifup(port))
899 ehea_info("irq_handle 0x%X for funct ehea_recv_int %d "
900 "registered", pr->recv_eq->attr.ist1, i);
903 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
906 ret = ibmebus_request_irq(NULL, port->qp_eq->attr.ist1,
907 ehea_qp_aff_irq_handler,
908 IRQF_DISABLED, port->int_aff_name, port);
910 ehea_error("failed registering irq for qp_aff_irq_handler:"
911 "ist=%X", port->qp_eq->attr.ist1);
915 if (netif_msg_ifup(port))
916 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
917 "registered", port->qp_eq->attr.ist1);
919 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
920 pr = &port->port_res[i];
921 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
922 "%s-send%d", dev->name, i);
923 ret = ibmebus_request_irq(NULL, pr->send_eq->attr.ist1,
924 ehea_send_irq_handler,
925 IRQF_DISABLED, pr->int_send_name,
928 ehea_error("failed registering irq for ehea_send "
929 "port_res_nr:%d, ist=%X", i,
930 pr->send_eq->attr.ist1);
933 if (netif_msg_ifup(port))
934 ehea_info("irq_handle 0x%X for function ehea_send_int "
935 "%d registered", pr->send_eq->attr.ist1, i);
942 u32 ist = port->port_res[i].send_eq->attr.ist1;
943 ibmebus_free_irq(NULL, ist, &port->port_res[i]);
946 ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port);
947 i = port->num_def_qps;
950 u32 ist = port->port_res[i].recv_eq->attr.ist1;
951 ibmebus_free_irq(NULL, ist, &port->port_res[i]);
956 static void ehea_free_interrupts(struct net_device *dev)
958 struct ehea_port *port = netdev_priv(dev);
959 struct ehea_port_res *pr;
963 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
964 pr = &port->port_res[i];
965 ibmebus_free_irq(NULL, pr->send_eq->attr.ist1, pr);
966 if (netif_msg_intr(port))
967 ehea_info("free send irq for res %d with handle 0x%X",
968 i, pr->send_eq->attr.ist1);
972 for (i = 0; i < port->num_def_qps; i++) {
973 pr = &port->port_res[i];
974 ibmebus_free_irq(NULL, pr->recv_eq->attr.ist1, pr);
975 if (netif_msg_intr(port))
976 ehea_info("free recv irq for res %d with handle 0x%X",
977 i, pr->recv_eq->attr.ist1);
980 /* associated events */
981 ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port);
982 if (netif_msg_intr(port))
983 ehea_info("associated event interrupt for handle 0x%X freed",
984 port->qp_eq->attr.ist1);
987 static int ehea_configure_port(struct ehea_port *port)
991 struct hcp_ehea_port_cb0 *cb0;
994 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
998 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
999 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1000 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1001 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1002 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1003 PXLY_RC_VLAN_FILTER)
1004 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1006 for (i = 0; i < port->num_def_qps; i++)
1007 cb0->default_qpn_arr[i] = port->port_res[0].qp->init_attr.qp_nr;
1009 if (netif_msg_ifup(port))
1010 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1012 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1013 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1015 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1016 port->logical_port_id,
1017 H_PORT_CB0, mask, cb0);
1019 if (hret != H_SUCCESS)
1030 static int ehea_gen_smrs(struct ehea_port_res *pr)
1033 struct ehea_adapter *adapter = pr->port->adapter;
1035 hret = ehea_h_register_smr(adapter->handle, adapter->mr.handle,
1036 adapter->mr.vaddr, EHEA_MR_ACC_CTRL,
1037 adapter->pd, &pr->send_mr);
1038 if (hret != H_SUCCESS)
1041 hret = ehea_h_register_smr(adapter->handle, adapter->mr.handle,
1042 adapter->mr.vaddr, EHEA_MR_ACC_CTRL,
1043 adapter->pd, &pr->recv_mr);
1044 if (hret != H_SUCCESS)
1050 hret = ehea_h_free_resource(adapter->handle, pr->send_mr.handle);
1051 if (hret != H_SUCCESS)
1052 ehea_error("failed freeing SMR");
1057 static int ehea_rem_smrs(struct ehea_port_res *pr)
1059 struct ehea_adapter *adapter = pr->port->adapter;
1063 hret = ehea_h_free_resource(adapter->handle, pr->send_mr.handle);
1064 if (hret != H_SUCCESS) {
1066 ehea_error("failed freeing send SMR for pr=%p", pr);
1069 hret = ehea_h_free_resource(adapter->handle, pr->recv_mr.handle);
1070 if (hret != H_SUCCESS) {
1072 ehea_error("failed freeing recv SMR for pr=%p", pr);
1078 static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1080 int arr_size = sizeof(void*) * max_q_entries;
1082 q_skba->arr = vmalloc(arr_size);
1086 memset(q_skba->arr, 0, arr_size);
1088 q_skba->len = max_q_entries;
1090 q_skba->os_skbs = 0;
1095 static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1096 struct port_res_cfg *pr_cfg, int queue_token)
1098 struct ehea_adapter *adapter = port->adapter;
1099 enum ehea_eq_type eq_type = EHEA_EQ;
1100 struct ehea_qp_init_attr *init_attr = NULL;
1103 memset(pr, 0, sizeof(struct ehea_port_res));
1106 spin_lock_init(&pr->send_lock);
1107 spin_lock_init(&pr->recv_lock);
1108 spin_lock_init(&pr->xmit_lock);
1109 spin_lock_init(&pr->netif_queue);
1111 pr->recv_eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1113 ehea_error("create_eq failed (recv_eq)");
1117 pr->send_eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1119 ehea_error("create_eq failed (send_eq)");
1123 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
1124 pr->recv_eq->fw_handle,
1125 port->logical_port_id);
1127 ehea_error("create_cq failed (cq_recv)");
1131 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
1132 pr->send_eq->fw_handle,
1133 port->logical_port_id);
1135 ehea_error("create_cq failed (cq_send)");
1139 if (netif_msg_ifup(port))
1140 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1141 pr->send_cq->attr.act_nr_of_cqes,
1142 pr->recv_cq->attr.act_nr_of_cqes);
1144 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1147 ehea_error("no mem for ehea_qp_init_attr");
1151 init_attr->low_lat_rq1 = 1;
1152 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1153 init_attr->rq_count = 3;
1154 init_attr->qp_token = queue_token;
1155 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1156 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1157 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1158 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1159 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1160 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1161 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1162 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1163 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1164 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1165 init_attr->port_nr = port->logical_port_id;
1166 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1167 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1168 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1170 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1172 ehea_error("create_qp failed");
1177 if (netif_msg_ifup(port))
1178 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1179 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1180 init_attr->act_nr_send_wqes,
1181 init_attr->act_nr_rwqes_rq1,
1182 init_attr->act_nr_rwqes_rq2,
1183 init_attr->act_nr_rwqes_rq3);
1185 ret = ehea_init_q_skba(&pr->sq_skba, init_attr->act_nr_send_wqes + 1);
1186 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1187 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1188 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1192 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1193 if (ehea_gen_smrs(pr) != 0) {
1197 tasklet_init(&pr->send_comp_task, ehea_send_irq_tasklet,
1199 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1207 vfree(pr->sq_skba.arr);
1208 vfree(pr->rq1_skba.arr);
1209 vfree(pr->rq2_skba.arr);
1210 vfree(pr->rq3_skba.arr);
1211 ehea_destroy_qp(pr->qp);
1212 ehea_destroy_cq(pr->send_cq);
1213 ehea_destroy_cq(pr->recv_cq);
1214 ehea_destroy_eq(pr->send_eq);
1215 ehea_destroy_eq(pr->recv_eq);
1220 static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1224 ret = ehea_destroy_qp(pr->qp);
1227 ehea_destroy_cq(pr->send_cq);
1228 ehea_destroy_cq(pr->recv_cq);
1229 ehea_destroy_eq(pr->send_eq);
1230 ehea_destroy_eq(pr->recv_eq);
1232 for (i = 0; i < pr->rq1_skba.len; i++)
1233 if (pr->rq1_skba.arr[i])
1234 dev_kfree_skb(pr->rq1_skba.arr[i]);
1236 for (i = 0; i < pr->rq2_skba.len; i++)
1237 if (pr->rq2_skba.arr[i])
1238 dev_kfree_skb(pr->rq2_skba.arr[i]);
1240 for (i = 0; i < pr->rq3_skba.len; i++)
1241 if (pr->rq3_skba.arr[i])
1242 dev_kfree_skb(pr->rq3_skba.arr[i]);
1244 for (i = 0; i < pr->sq_skba.len; i++)
1245 if (pr->sq_skba.arr[i])
1246 dev_kfree_skb(pr->sq_skba.arr[i]);
1248 vfree(pr->rq1_skba.arr);
1249 vfree(pr->rq2_skba.arr);
1250 vfree(pr->rq3_skba.arr);
1251 vfree(pr->sq_skba.arr);
1252 ret = ehea_rem_smrs(pr);
1258 * The write_* functions store information in swqe which is used by
1259 * the hardware to calculate the ip/tcp/udp checksum
1262 static inline void write_ip_start_end(struct ehea_swqe *swqe,
1263 const struct sk_buff *skb)
1265 swqe->ip_start = (u8)(((u64)skb->nh.iph) - ((u64)skb->data));
1266 swqe->ip_end = (u8)(swqe->ip_start + skb->nh.iph->ihl * 4 - 1);
1269 static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1270 const struct sk_buff *skb)
1273 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1275 swqe->tcp_end = (u16)skb->len - 1;
1278 static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1279 const struct sk_buff *skb)
1282 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1284 swqe->tcp_end = (u16)skb->len - 1;
1288 static void write_swqe2_TSO(struct sk_buff *skb,
1289 struct ehea_swqe *swqe, u32 lkey)
1291 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1292 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1293 int skb_data_size = skb->len - skb->data_len;
1297 /* Packet is TCP with TSO enabled */
1298 swqe->tx_control |= EHEA_SWQE_TSO;
1299 swqe->mss = skb_shinfo(skb)->gso_size;
1300 /* copy only eth/ip/tcp headers to immediate data and
1301 * the rest of skb->data to sg1entry
1303 headersize = ETH_HLEN + (skb->nh.iph->ihl * 4) + (skb->h.th->doff * 4);
1305 skb_data_size = skb->len - skb->data_len;
1307 if (skb_data_size >= headersize) {
1308 /* copy immediate data */
1309 memcpy(imm_data, skb->data, headersize);
1310 swqe->immediate_data_length = headersize;
1312 if (skb_data_size > headersize) {
1313 /* set sg1entry data */
1314 sg1entry->l_key = lkey;
1315 sg1entry->len = skb_data_size - headersize;
1317 tmp_addr = (u64)(skb->data + headersize);
1318 sg1entry->vaddr = tmp_addr;
1319 swqe->descriptors++;
1322 ehea_error("cannot handle fragmented headers");
1325 static void write_swqe2_nonTSO(struct sk_buff *skb,
1326 struct ehea_swqe *swqe, u32 lkey)
1328 int skb_data_size = skb->len - skb->data_len;
1329 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1330 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1333 /* Packet is any nonTSO type
1335 * Copy as much as possible skb->data to immediate data and
1336 * the rest to sg1entry
1338 if (skb_data_size >= SWQE2_MAX_IMM) {
1339 /* copy immediate data */
1340 memcpy(imm_data, skb->data, SWQE2_MAX_IMM);
1342 swqe->immediate_data_length = SWQE2_MAX_IMM;
1344 if (skb_data_size > SWQE2_MAX_IMM) {
1345 /* copy sg1entry data */
1346 sg1entry->l_key = lkey;
1347 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
1348 tmp_addr = (u64)(skb->data + SWQE2_MAX_IMM);
1349 sg1entry->vaddr = tmp_addr;
1350 swqe->descriptors++;
1353 memcpy(imm_data, skb->data, skb_data_size);
1354 swqe->immediate_data_length = skb_data_size;
1358 static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1359 struct ehea_swqe *swqe, u32 lkey)
1361 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1363 int nfrags, sg1entry_contains_frag_data, i;
1366 nfrags = skb_shinfo(skb)->nr_frags;
1367 sg1entry = &swqe->u.immdata_desc.sg_entry;
1368 sg_list = (struct ehea_vsgentry*)&swqe->u.immdata_desc.sg_list;
1369 swqe->descriptors = 0;
1370 sg1entry_contains_frag_data = 0;
1372 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1373 write_swqe2_TSO(skb, swqe, lkey);
1375 write_swqe2_nonTSO(skb, swqe, lkey);
1377 /* write descriptors */
1379 if (swqe->descriptors == 0) {
1380 /* sg1entry not yet used */
1381 frag = &skb_shinfo(skb)->frags[0];
1383 /* copy sg1entry data */
1384 sg1entry->l_key = lkey;
1385 sg1entry->len = frag->size;
1386 tmp_addr = (u64)(page_address(frag->page)
1387 + frag->page_offset);
1388 sg1entry->vaddr = tmp_addr;
1389 swqe->descriptors++;
1390 sg1entry_contains_frag_data = 1;
1393 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1395 frag = &skb_shinfo(skb)->frags[i];
1396 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1398 sgentry->l_key = lkey;
1399 sgentry->len = frag->size;
1401 tmp_addr = (u64)(page_address(frag->page)
1402 + frag->page_offset);
1403 sgentry->vaddr = tmp_addr;
1404 swqe->descriptors++;
1409 static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1415 /* De/Register untagged packets */
1416 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1417 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1418 port->logical_port_id,
1419 reg_type, port->mac_addr, 0, hcallid);
1420 if (hret != H_SUCCESS) {
1421 ehea_error("reg_dereg_bcmc failed (tagged)");
1426 /* De/Register VLAN packets */
1427 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1428 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1429 port->logical_port_id,
1430 reg_type, port->mac_addr, 0, hcallid);
1431 if (hret != H_SUCCESS) {
1432 ehea_error("reg_dereg_bcmc failed (vlan)");
1439 static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1441 struct ehea_port *port = netdev_priv(dev);
1442 struct sockaddr *mac_addr = sa;
1443 struct hcp_ehea_port_cb0 *cb0;
1447 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1448 ret = -EADDRNOTAVAIL;
1452 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1454 ehea_error("no mem for cb0");
1459 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1461 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1463 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1464 port->logical_port_id, H_PORT_CB0,
1465 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1466 if (hret != H_SUCCESS) {
1471 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1473 /* Deregister old MAC in pHYP */
1474 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1478 port->mac_addr = cb0->port_mac_addr << 16;
1480 /* Register new MAC in pHYP */
1481 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1492 static void ehea_promiscuous_error(u64 hret, int enable)
1494 if (hret == H_AUTHORITY)
1495 ehea_info("Hypervisor denied %sabling promiscuous mode",
1496 enable == 1 ? "en" : "dis");
1498 ehea_error("failed %sabling promiscuous mode",
1499 enable == 1 ? "en" : "dis");
1502 static void ehea_promiscuous(struct net_device *dev, int enable)
1504 struct ehea_port *port = netdev_priv(dev);
1505 struct hcp_ehea_port_cb7 *cb7;
1508 if ((enable && port->promisc) || (!enable && !port->promisc))
1511 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
1513 ehea_error("no mem for cb7");
1517 /* Modify Pxs_DUCQPN in CB7 */
1518 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1520 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1521 port->logical_port_id,
1522 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1524 ehea_promiscuous_error(hret, enable);
1528 port->promisc = enable;
1534 static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1540 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1541 | EHEA_BCMC_UNTAGGED;
1543 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1544 port->logical_port_id,
1545 reg_type, mc_mac_addr, 0, hcallid);
1549 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1550 | EHEA_BCMC_VLANID_ALL;
1552 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1553 port->logical_port_id,
1554 reg_type, mc_mac_addr, 0, hcallid);
1559 static int ehea_drop_multicast_list(struct net_device *dev)
1561 struct ehea_port *port = netdev_priv(dev);
1562 struct ehea_mc_list *mc_entry = port->mc_list;
1563 struct list_head *pos;
1564 struct list_head *temp;
1568 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1569 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1571 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1574 ehea_error("failed deregistering mcast MAC");
1584 static void ehea_allmulti(struct net_device *dev, int enable)
1586 struct ehea_port *port = netdev_priv(dev);
1589 if (!port->allmulti) {
1591 /* Enable ALLMULTI */
1592 ehea_drop_multicast_list(dev);
1593 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1597 ehea_error("failed enabling IFF_ALLMULTI");
1601 /* Disable ALLMULTI */
1602 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1606 ehea_error("failed disabling IFF_ALLMULTI");
1610 static void ehea_add_multicast_entry(struct ehea_port* port, u8* mc_mac_addr)
1612 struct ehea_mc_list *ehea_mcl_entry;
1615 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
1616 if (!ehea_mcl_entry) {
1617 ehea_error("no mem for mcl_entry");
1621 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1623 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1625 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1628 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1630 ehea_error("failed registering mcast MAC");
1631 kfree(ehea_mcl_entry);
1635 static void ehea_set_multicast_list(struct net_device *dev)
1637 struct ehea_port *port = netdev_priv(dev);
1638 struct dev_mc_list *k_mcl_entry;
1641 if (dev->flags & IFF_PROMISC) {
1642 ehea_promiscuous(dev, 1);
1645 ehea_promiscuous(dev, 0);
1647 if (dev->flags & IFF_ALLMULTI) {
1648 ehea_allmulti(dev, 1);
1651 ehea_allmulti(dev, 0);
1653 if (dev->mc_count) {
1654 ret = ehea_drop_multicast_list(dev);
1656 /* Dropping the current multicast list failed.
1657 * Enabling ALL_MULTI is the best we can do.
1659 ehea_allmulti(dev, 1);
1662 if (dev->mc_count > port->adapter->max_mc_mac) {
1663 ehea_info("Mcast registration limit reached (0x%lx). "
1665 port->adapter->max_mc_mac);
1669 for (i = 0, k_mcl_entry = dev->mc_list;
1671 i++, k_mcl_entry = k_mcl_entry->next) {
1672 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
1679 static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1681 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1687 static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1688 struct ehea_swqe *swqe, u32 lkey)
1690 if (skb->protocol == htons(ETH_P_IP)) {
1692 swqe->tx_control |= EHEA_SWQE_CRC
1693 | EHEA_SWQE_IP_CHECKSUM
1694 | EHEA_SWQE_TCP_CHECKSUM
1695 | EHEA_SWQE_IMM_DATA_PRESENT
1696 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1698 write_ip_start_end(swqe, skb);
1700 if (skb->nh.iph->protocol == IPPROTO_UDP) {
1701 if ((skb->nh.iph->frag_off & IP_MF) ||
1702 (skb->nh.iph->frag_off & IP_OFFSET))
1703 /* IP fragment, so don't change cs */
1704 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
1706 write_udp_offset_end(swqe, skb);
1708 } else if (skb->nh.iph->protocol == IPPROTO_TCP) {
1709 write_tcp_offset_end(swqe, skb);
1712 /* icmp (big data) and ip segmentation packets (all other ip
1713 packets) do not require any special handling */
1716 /* Other Ethernet Protocol */
1717 swqe->tx_control |= EHEA_SWQE_CRC
1718 | EHEA_SWQE_IMM_DATA_PRESENT
1719 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1722 write_swqe2_data(skb, dev, swqe, lkey);
1725 static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
1726 struct ehea_swqe *swqe)
1728 int nfrags = skb_shinfo(skb)->nr_frags;
1729 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
1733 if (skb->protocol == htons(ETH_P_IP)) {
1735 write_ip_start_end(swqe, skb);
1737 if (skb->nh.iph->protocol == IPPROTO_TCP) {
1738 swqe->tx_control |= EHEA_SWQE_CRC
1739 | EHEA_SWQE_IP_CHECKSUM
1740 | EHEA_SWQE_TCP_CHECKSUM
1741 | EHEA_SWQE_IMM_DATA_PRESENT;
1743 write_tcp_offset_end(swqe, skb);
1745 } else if (skb->nh.iph->protocol == IPPROTO_UDP) {
1746 if ((skb->nh.iph->frag_off & IP_MF) ||
1747 (skb->nh.iph->frag_off & IP_OFFSET))
1748 /* IP fragment, so don't change cs */
1749 swqe->tx_control |= EHEA_SWQE_CRC
1750 | EHEA_SWQE_IMM_DATA_PRESENT;
1752 swqe->tx_control |= EHEA_SWQE_CRC
1753 | EHEA_SWQE_IP_CHECKSUM
1754 | EHEA_SWQE_TCP_CHECKSUM
1755 | EHEA_SWQE_IMM_DATA_PRESENT;
1757 write_udp_offset_end(swqe, skb);
1760 /* icmp (big data) and
1761 ip segmentation packets (all other ip packets) */
1762 swqe->tx_control |= EHEA_SWQE_CRC
1763 | EHEA_SWQE_IP_CHECKSUM
1764 | EHEA_SWQE_IMM_DATA_PRESENT;
1767 /* Other Ethernet Protocol */
1768 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
1770 /* copy (immediate) data */
1772 /* data is in a single piece */
1773 memcpy(imm_data, skb->data, skb->len);
1775 /* first copy data from the skb->data buffer ... */
1776 memcpy(imm_data, skb->data, skb->len - skb->data_len);
1777 imm_data += skb->len - skb->data_len;
1779 /* ... then copy data from the fragments */
1780 for (i = 0; i < nfrags; i++) {
1781 frag = &skb_shinfo(skb)->frags[i];
1783 page_address(frag->page) + frag->page_offset,
1785 imm_data += frag->size;
1788 swqe->immediate_data_length = skb->len;
1792 static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
1794 struct ehea_port *port = netdev_priv(dev);
1795 struct ehea_swqe *swqe;
1796 unsigned long flags;
1799 struct ehea_port_res *pr = &port->port_res[0];
1801 spin_lock(&pr->xmit_lock);
1803 swqe = ehea_get_swqe(pr->qp, &swqe_index);
1804 memset(swqe, 0, SWQE_HEADER_SIZE);
1805 atomic_dec(&pr->swqe_avail);
1807 if (skb->len <= SWQE3_MAX_IMM) {
1808 u32 sig_iv = port->sig_comp_iv;
1809 u32 swqe_num = pr->swqe_id_counter;
1810 ehea_xmit3(skb, dev, swqe);
1811 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
1812 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
1813 if (pr->swqe_ll_count >= (sig_iv - 1)) {
1814 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
1816 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1817 pr->swqe_ll_count = 0;
1819 pr->swqe_ll_count += 1;
1822 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
1823 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
1824 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
1825 pr->sq_skba.arr[pr->sq_skba.index] = skb;
1827 pr->sq_skba.index++;
1828 pr->sq_skba.index &= (pr->sq_skba.len - 1);
1830 lkey = pr->send_mr.lkey;
1831 ehea_xmit2(skb, dev, swqe, lkey);
1833 if (pr->swqe_count >= (EHEA_SIG_IV_LONG - 1)) {
1834 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
1836 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1839 pr->swqe_count += 1;
1841 pr->swqe_id_counter += 1;
1843 if (port->vgrp && vlan_tx_tag_present(skb)) {
1844 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
1845 swqe->vlan_tag = vlan_tx_tag_get(skb);
1848 if (netif_msg_tx_queued(port)) {
1849 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
1850 ehea_dump(swqe, 512, "swqe");
1853 ehea_post_swqe(pr->qp, swqe);
1856 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
1857 spin_lock_irqsave(&pr->netif_queue, flags);
1858 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
1859 netif_stop_queue(dev);
1860 pr->queue_stopped = 1;
1862 spin_unlock_irqrestore(&pr->netif_queue, flags);
1864 dev->trans_start = jiffies;
1865 spin_unlock(&pr->xmit_lock);
1867 return NETDEV_TX_OK;
1870 static void ehea_vlan_rx_register(struct net_device *dev,
1871 struct vlan_group *grp)
1873 struct ehea_port *port = netdev_priv(dev);
1874 struct ehea_adapter *adapter = port->adapter;
1875 struct hcp_ehea_port_cb1 *cb1;
1880 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1882 ehea_error("no mem for cb1");
1887 memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
1889 memset(cb1->vlan_filter, 0xFF, sizeof(cb1->vlan_filter));
1891 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1892 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1893 if (hret != H_SUCCESS)
1894 ehea_error("modify_ehea_port failed");
1901 static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
1903 struct ehea_port *port = netdev_priv(dev);
1904 struct ehea_adapter *adapter = port->adapter;
1905 struct hcp_ehea_port_cb1 *cb1;
1909 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1911 ehea_error("no mem for cb1");
1915 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
1916 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1917 if (hret != H_SUCCESS) {
1918 ehea_error("query_ehea_port failed");
1923 cb1->vlan_filter[index] |= ((u64)(1 << (vid & 0x3F)));
1925 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1926 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1927 if (hret != H_SUCCESS)
1928 ehea_error("modify_ehea_port failed");
1934 static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
1936 struct ehea_port *port = netdev_priv(dev);
1937 struct ehea_adapter *adapter = port->adapter;
1938 struct hcp_ehea_port_cb1 *cb1;
1943 port->vgrp->vlan_devices[vid] = NULL;
1945 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1947 ehea_error("no mem for cb1");
1951 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
1952 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1953 if (hret != H_SUCCESS) {
1954 ehea_error("query_ehea_port failed");
1959 cb1->vlan_filter[index] &= ~((u64)(1 << (vid & 0x3F)));
1961 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
1962 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
1963 if (hret != H_SUCCESS)
1964 ehea_error("modify_ehea_port failed");
1970 int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
1976 struct hcp_modify_qp_cb0* cb0;
1978 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1984 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
1985 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
1986 if (hret != H_SUCCESS) {
1987 ehea_error("query_ehea_qp failed (1)");
1991 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
1992 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
1993 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
1994 &dummy64, &dummy64, &dummy16, &dummy16);
1995 if (hret != H_SUCCESS) {
1996 ehea_error("modify_ehea_qp failed (1)");
2000 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2001 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2002 if (hret != H_SUCCESS) {
2003 ehea_error("query_ehea_qp failed (2)");
2007 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2008 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2009 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2010 &dummy64, &dummy64, &dummy16, &dummy16);
2011 if (hret != H_SUCCESS) {
2012 ehea_error("modify_ehea_qp failed (2)");
2016 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2017 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2018 if (hret != H_SUCCESS) {
2019 ehea_error("query_ehea_qp failed (3)");
2023 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2024 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2025 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2026 &dummy64, &dummy64, &dummy16, &dummy16);
2027 if (hret != H_SUCCESS) {
2028 ehea_error("modify_ehea_qp failed (3)");
2032 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2033 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2034 if (hret != H_SUCCESS) {
2035 ehea_error("query_ehea_qp failed (4)");
2045 static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2049 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2050 enum ehea_eq_type eq_type = EHEA_EQ;
2052 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2053 EHEA_MAX_ENTRIES_EQ, 1);
2056 ehea_error("ehea_create_eq failed (qp_eq)");
2060 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
2061 pr_cfg.max_entries_scq = sq_entries;
2062 pr_cfg.max_entries_sq = sq_entries;
2063 pr_cfg.max_entries_rq1 = rq1_entries;
2064 pr_cfg.max_entries_rq2 = rq2_entries;
2065 pr_cfg.max_entries_rq3 = rq3_entries;
2067 pr_cfg_small_rx.max_entries_rcq = 1;
2068 pr_cfg_small_rx.max_entries_scq = sq_entries;
2069 pr_cfg_small_rx.max_entries_sq = sq_entries;
2070 pr_cfg_small_rx.max_entries_rq1 = 1;
2071 pr_cfg_small_rx.max_entries_rq2 = 1;
2072 pr_cfg_small_rx.max_entries_rq3 = 1;
2074 for (i = 0; i < def_qps; i++) {
2075 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2079 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2080 ret = ehea_init_port_res(port, &port->port_res[i],
2081 &pr_cfg_small_rx, i);
2090 ehea_clean_portres(port, &port->port_res[i]);
2093 ehea_destroy_eq(port->qp_eq);
2097 static int ehea_clean_all_portres(struct ehea_port *port)
2102 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2103 ret |= ehea_clean_portres(port, &port->port_res[i]);
2105 ret |= ehea_destroy_eq(port->qp_eq);
2110 static int ehea_up(struct net_device *dev)
2113 struct ehea_port *port = netdev_priv(dev);
2116 if (port->state == EHEA_PORT_UP)
2119 ret = ehea_port_res_setup(port, port->num_def_qps,
2120 port->num_add_tx_qps);
2122 ehea_error("port_res_failed");
2126 /* Set default QP for this port */
2127 ret = ehea_configure_port(port);
2129 ehea_error("ehea_configure_port failed. ret:%d", ret);
2133 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2136 ehea_error("out_clean_pr");
2139 mac_addr = (*(u64*)dev->dev_addr) >> 16;
2141 ret = ehea_reg_interrupts(dev);
2143 ehea_error("out_dereg_bc");
2147 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2148 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2150 ehea_error("activate_qp failed");
2155 for(i = 0; i < port->num_def_qps; i++) {
2156 ret = ehea_fill_port_res(&port->port_res[i]);
2158 ehea_error("out_free_irqs");
2164 port->state = EHEA_PORT_UP;
2168 ehea_free_interrupts(dev);
2171 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2174 ehea_clean_all_portres(port);
2179 static int ehea_open(struct net_device *dev)
2182 struct ehea_port *port = netdev_priv(dev);
2184 down(&port->port_lock);
2186 if (netif_msg_ifup(port))
2187 ehea_info("enabling port %s", dev->name);
2191 netif_start_queue(dev);
2193 up(&port->port_lock);
2198 static int ehea_down(struct net_device *dev)
2201 struct ehea_port *port = netdev_priv(dev);
2203 if (port->state == EHEA_PORT_DOWN)
2206 ehea_drop_multicast_list(dev);
2207 ehea_free_interrupts(dev);
2209 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2210 tasklet_kill(&port->port_res[i].send_comp_task);
2212 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2213 ret = ehea_clean_all_portres(port);
2214 port->state = EHEA_PORT_DOWN;
2218 static int ehea_stop(struct net_device *dev)
2221 struct ehea_port *port = netdev_priv(dev);
2223 if (netif_msg_ifdown(port))
2224 ehea_info("disabling port %s", dev->name);
2226 flush_workqueue(port->adapter->ehea_wq);
2227 down(&port->port_lock);
2228 netif_stop_queue(dev);
2229 ret = ehea_down(dev);
2230 up(&port->port_lock);
2234 static void ehea_reset_port(struct work_struct *work)
2237 struct ehea_port *port =
2238 container_of(work, struct ehea_port, reset_task);
2239 struct net_device *dev = port->netdev;
2242 down(&port->port_lock);
2243 netif_stop_queue(dev);
2244 netif_poll_disable(dev);
2246 ret = ehea_down(dev);
2248 ehea_error("ehea_down failed. not all resources are freed");
2252 ehea_error("Reset device %s failed: ret=%d", dev->name, ret);
2256 if (netif_msg_timer(port))
2257 ehea_info("Device %s resetted successfully", dev->name);
2259 netif_poll_enable(dev);
2260 netif_wake_queue(dev);
2262 up(&port->port_lock);
2266 static void ehea_tx_watchdog(struct net_device *dev)
2268 struct ehea_port *port = netdev_priv(dev);
2270 if (netif_carrier_ok(dev))
2271 queue_work(port->adapter->ehea_wq, &port->reset_task);
2274 int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2276 struct hcp_query_ehea *cb;
2277 struct device_node *lhea_dn = NULL;
2278 struct device_node *eth_dn = NULL;
2282 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
2288 hret = ehea_h_query_ehea(adapter->handle, cb);
2290 if (hret != H_SUCCESS) {
2295 /* Determine the number of available logical ports
2296 * by counting the child nodes of the lhea OFDT entry
2298 adapter->num_ports = 0;
2299 lhea_dn = of_find_node_by_name(lhea_dn, "lhea");
2301 eth_dn = of_get_next_child(lhea_dn, eth_dn);
2303 adapter->num_ports++;
2305 of_node_put(lhea_dn);
2307 adapter->max_mc_mac = cb->max_mc_mac - 1;
2316 static int ehea_setup_single_port(struct ehea_port *port,
2317 struct device_node *dn)
2321 struct net_device *dev = port->netdev;
2322 struct ehea_adapter *adapter = port->adapter;
2323 struct hcp_ehea_port_cb4 *cb4;
2324 u32 *dn_log_port_id;
2327 sema_init(&port->port_lock, 1);
2328 port->state = EHEA_PORT_DOWN;
2329 port->sig_comp_iv = sq_entries / 10;
2332 ehea_error("bad device node: dn=%p", dn);
2337 port->of_dev_node = dn;
2339 /* Determine logical port id */
2340 dn_log_port_id = (u32*)get_property(dn, "ibm,hea-port-no", NULL);
2342 if (!dn_log_port_id) {
2343 ehea_error("bad device node: dn_log_port_id=%p",
2348 port->logical_port_id = *dn_log_port_id;
2350 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
2351 if (!port->mc_list) {
2356 INIT_LIST_HEAD(&port->mc_list->list);
2358 ret = ehea_sense_port_attr(port);
2362 /* Enable Jumbo frames */
2363 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2365 ehea_error("no mem for cb4");
2367 hret = ehea_h_query_ehea_port(adapter->handle,
2368 port->logical_port_id,
2370 H_PORT_CB4_JUMBO, cb4);
2372 if (hret == H_SUCCESS) {
2373 if (cb4->jumbo_frame)
2376 cb4->jumbo_frame = 1;
2377 hret = ehea_h_modify_ehea_port(adapter->handle,
2383 if (hret == H_SUCCESS)
2390 /* initialize net_device structure */
2391 SET_MODULE_OWNER(dev);
2393 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
2395 dev->open = ehea_open;
2396 dev->poll = ehea_poll;
2398 dev->stop = ehea_stop;
2399 dev->hard_start_xmit = ehea_start_xmit;
2400 dev->get_stats = ehea_get_stats;
2401 dev->set_multicast_list = ehea_set_multicast_list;
2402 dev->set_mac_address = ehea_set_mac_addr;
2403 dev->change_mtu = ehea_change_mtu;
2404 dev->vlan_rx_register = ehea_vlan_rx_register;
2405 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
2406 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
2407 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
2408 | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX
2409 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
2411 dev->tx_timeout = &ehea_tx_watchdog;
2412 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
2414 INIT_WORK(&port->reset_task, ehea_reset_port);
2416 ehea_set_ethtool_ops(dev);
2418 ret = register_netdev(dev);
2420 ehea_error("register_netdev failed. ret=%d", ret);
2424 ehea_info("%s: Jumbo frames are %sabled", dev->name,
2425 jumbo == 1 ? "en" : "dis");
2432 kfree(port->mc_list);
2437 static int ehea_setup_ports(struct ehea_adapter *adapter)
2440 int port_setup_ok = 0;
2441 struct ehea_port *port;
2442 struct device_node *dn = NULL;
2443 struct net_device *dev;
2446 /* get port properties for all ports */
2447 for (i = 0; i < adapter->num_ports; i++) {
2449 if (adapter->port[i])
2450 continue; /* port already up and running */
2452 /* allocate memory for the port structures */
2453 dev = alloc_etherdev(sizeof(struct ehea_port));
2456 ehea_error("no mem for net_device");
2460 port = netdev_priv(dev);
2461 port->adapter = adapter;
2463 adapter->port[i] = port;
2464 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
2466 dn = of_find_node_by_name(dn, "ethernet");
2467 ret = ehea_setup_single_port(port, dn);
2469 /* Free mem for this port struct. The others will be
2470 processed on rollback */
2472 adapter->port[i] = NULL;
2473 ehea_error("eHEA port %d setup failed, ret=%d", i, ret);
2479 /* Check for succesfully set up ports */
2480 for (i = 0; i < adapter->num_ports; i++)
2481 if (adapter->port[i])
2485 ret = 0; /* At least some ports are setup correctly */
2492 static int __devinit ehea_probe(struct ibmebus_dev *dev,
2493 const struct of_device_id *id)
2495 struct ehea_adapter *adapter;
2496 u64 *adapter_handle;
2499 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
2502 dev_err(&dev->ofdev.dev, "no mem for ehea_adapter\n");
2506 adapter_handle = (u64*)get_property(dev->ofdev.node, "ibm,hea-handle",
2509 adapter->handle = *adapter_handle;
2511 if (!adapter->handle) {
2512 dev_err(&dev->ofdev.dev, "failed getting handle for adapter"
2513 " '%s'\n", dev->ofdev.node->full_name);
2518 adapter->pd = EHEA_PD_ID;
2520 dev->ofdev.dev.driver_data = adapter;
2522 ret = ehea_reg_mr_adapter(adapter);
2524 dev_err(&dev->ofdev.dev, "reg_mr_adapter failed\n");
2528 /* initialize adapter and ports */
2529 /* get adapter properties */
2530 ret = ehea_sense_adapter_attr(adapter);
2532 dev_err(&dev->ofdev.dev, "sense_adapter_attr failed: %d", ret);
2535 dev_info(&dev->ofdev.dev, "%d eHEA ports found\n", adapter->num_ports);
2537 adapter->neq = ehea_create_eq(adapter,
2538 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
2539 if (!adapter->neq) {
2540 dev_err(&dev->ofdev.dev, "NEQ creation failed");
2544 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
2545 (unsigned long)adapter);
2547 ret = ibmebus_request_irq(NULL, adapter->neq->attr.ist1,
2548 ehea_interrupt_neq, IRQF_DISABLED,
2549 "ehea_neq", adapter);
2551 dev_err(&dev->ofdev.dev, "requesting NEQ IRQ failed");
2555 adapter->ehea_wq = create_workqueue("ehea_wq");
2556 if (!adapter->ehea_wq)
2559 ret = ehea_setup_ports(adapter);
2561 dev_err(&dev->ofdev.dev, "setup_ports failed");
2569 destroy_workqueue(adapter->ehea_wq);
2572 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
2575 ehea_destroy_eq(adapter->neq);
2578 ehea_h_free_resource(adapter->handle, adapter->mr.handle);
2586 static void ehea_shutdown_single_port(struct ehea_port *port)
2588 unregister_netdev(port->netdev);
2589 kfree(port->mc_list);
2590 free_netdev(port->netdev);
2593 static int __devexit ehea_remove(struct ibmebus_dev *dev)
2595 struct ehea_adapter *adapter = dev->ofdev.dev.driver_data;
2599 for (i = 0; i < adapter->num_ports; i++)
2600 if (adapter->port[i]) {
2601 ehea_shutdown_single_port(adapter->port[i]);
2602 adapter->port[i] = NULL;
2604 destroy_workqueue(adapter->ehea_wq);
2606 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
2607 tasklet_kill(&adapter->neq_tasklet);
2609 ehea_destroy_eq(adapter->neq);
2611 hret = ehea_h_free_resource(adapter->handle, adapter->mr.handle);
2613 dev_err(&dev->ofdev.dev, "free_resource_mr failed");
2620 static int check_module_parm(void)
2624 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
2625 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
2626 ehea_info("Bad parameter: rq1_entries");
2629 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
2630 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
2631 ehea_info("Bad parameter: rq2_entries");
2634 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
2635 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
2636 ehea_info("Bad parameter: rq3_entries");
2639 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
2640 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
2641 ehea_info("Bad parameter: sq_entries");
2648 static struct of_device_id ehea_device_table[] = {
2651 .compatible = "IBM,lhea",
2656 static struct ibmebus_driver ehea_driver = {
2658 .id_table = ehea_device_table,
2659 .probe = ehea_probe,
2660 .remove = ehea_remove,
2663 int __init ehea_module_init(void)
2667 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
2670 ret = check_module_parm();
2673 ret = ibmebus_register_driver(&ehea_driver);
2675 ehea_error("failed registering eHEA device driver on ebus");
2681 static void __exit ehea_module_exit(void)
2683 ibmebus_unregister_driver(&ehea_driver);
2686 module_init(ehea_module_init);
2687 module_exit(ehea_module_exit);