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;
54 static int use_mcs = 0;
55 static int use_lro = 0;
56 static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
57 static int num_tx_qps = EHEA_NUM_TX_QP;
58 static int prop_carrier_state = 0;
60 module_param(msg_level, int, 0);
61 module_param(rq1_entries, int, 0);
62 module_param(rq2_entries, int, 0);
63 module_param(rq3_entries, int, 0);
64 module_param(sq_entries, int, 0);
65 module_param(prop_carrier_state, int, 0);
66 module_param(use_mcs, int, 0);
67 module_param(use_lro, int, 0);
68 module_param(lro_max_aggr, int, 0);
69 module_param(num_tx_qps, int, 0);
71 MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
72 MODULE_PARM_DESC(msg_level, "msg_level");
73 MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
74 "port to stack. 1:yes, 0:no. Default = 0 ");
75 MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
76 "[2^x - 1], x = [6..14]. Default = "
77 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
78 MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
81 MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
84 MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
87 MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
89 MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
90 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
91 MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
94 static int port_name_cnt = 0;
95 static LIST_HEAD(adapter_list);
96 u64 ehea_driver_flags = 0;
97 struct workqueue_struct *ehea_driver_wq;
98 struct work_struct ehea_rereg_mr_task;
100 struct semaphore dlpar_mem_lock;
102 static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev,
103 const struct of_device_id *id);
105 static int __devexit ehea_remove(struct ibmebus_dev *dev);
107 static struct of_device_id ehea_device_table[] = {
110 .compatible = "IBM,lhea",
115 static struct ibmebus_driver ehea_driver = {
117 .id_table = ehea_device_table,
118 .probe = ehea_probe_adapter,
119 .remove = ehea_remove,
122 void ehea_dump(void *adr, int len, char *msg) {
124 unsigned char *deb = adr;
125 for (x = 0; x < len; x += 16) {
126 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
127 deb, x, *((u64*)&deb[0]), *((u64*)&deb[8]));
132 static struct net_device_stats *ehea_get_stats(struct net_device *dev)
134 struct ehea_port *port = netdev_priv(dev);
135 struct net_device_stats *stats = &port->stats;
136 struct hcp_ehea_port_cb2 *cb2;
137 u64 hret, rx_packets;
140 memset(stats, 0, sizeof(*stats));
142 cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL);
144 ehea_error("no mem for cb2");
148 hret = ehea_h_query_ehea_port(port->adapter->handle,
149 port->logical_port_id,
150 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
151 if (hret != H_SUCCESS) {
152 ehea_error("query_ehea_port failed");
156 if (netif_msg_hw(port))
157 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
160 for (i = 0; i < port->num_def_qps; i++)
161 rx_packets += port->port_res[i].rx_packets;
163 stats->tx_packets = cb2->txucp + cb2->txmcp + cb2->txbcp;
164 stats->multicast = cb2->rxmcp;
165 stats->rx_errors = cb2->rxuerr;
166 stats->rx_bytes = cb2->rxo;
167 stats->tx_bytes = cb2->txo;
168 stats->rx_packets = rx_packets;
176 static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
178 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
179 struct net_device *dev = pr->port->netdev;
180 int max_index_mask = pr->rq1_skba.len - 1;
181 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
185 pr->rq1_skba.os_skbs = 0;
187 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
188 pr->rq1_skba.index = index;
189 pr->rq1_skba.os_skbs = fill_wqes;
193 for (i = 0; i < fill_wqes; i++) {
194 if (!skb_arr_rq1[index]) {
195 skb_arr_rq1[index] = netdev_alloc_skb(dev,
197 if (!skb_arr_rq1[index]) {
198 pr->rq1_skba.os_skbs = fill_wqes - i;
199 ehea_error("%s: no mem for skb/%d wqes filled",
205 index &= max_index_mask;
213 ehea_update_rq1a(pr->qp, adder);
216 static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
219 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
220 struct net_device *dev = pr->port->netdev;
223 for (i = 0; i < pr->rq1_skba.len; i++) {
224 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
225 if (!skb_arr_rq1[i]) {
226 ehea_error("%s: no mem for skb/%d wqes filled",
233 ehea_update_rq1a(pr->qp, nr_rq1a);
238 static int ehea_refill_rq_def(struct ehea_port_res *pr,
239 struct ehea_q_skb_arr *q_skba, int rq_nr,
240 int num_wqes, int wqe_type, int packet_size)
242 struct net_device *dev = pr->port->netdev;
243 struct ehea_qp *qp = pr->qp;
244 struct sk_buff **skb_arr = q_skba->arr;
245 struct ehea_rwqe *rwqe;
246 int i, index, max_index_mask, fill_wqes;
250 fill_wqes = q_skba->os_skbs + num_wqes;
253 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
254 q_skba->os_skbs = fill_wqes;
258 index = q_skba->index;
259 max_index_mask = q_skba->len - 1;
260 for (i = 0; i < fill_wqes; i++) {
262 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
264 ehea_error("%s: no mem for skb/%d wqes filled",
265 pr->port->netdev->name, i);
266 q_skba->os_skbs = fill_wqes - i;
270 skb_reserve(skb, NET_IP_ALIGN);
272 skb_arr[index] = skb;
273 tmp_addr = ehea_map_vaddr(skb->data);
274 if (tmp_addr == -1) {
276 q_skba->os_skbs = fill_wqes - i;
281 rwqe = ehea_get_next_rwqe(qp, rq_nr);
282 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
283 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
284 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
285 rwqe->sg_list[0].vaddr = tmp_addr;
286 rwqe->sg_list[0].len = packet_size;
287 rwqe->data_segments = 1;
290 index &= max_index_mask;
294 q_skba->index = index;
301 ehea_update_rq2a(pr->qp, adder);
303 ehea_update_rq3a(pr->qp, adder);
309 static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
311 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
312 nr_of_wqes, EHEA_RWQE2_TYPE,
313 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
317 static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
319 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
320 nr_of_wqes, EHEA_RWQE3_TYPE,
321 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
324 static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
326 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
327 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
329 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
330 (cqe->header_length == 0))
335 static inline void ehea_fill_skb(struct net_device *dev,
336 struct sk_buff *skb, struct ehea_cqe *cqe)
338 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
340 skb_put(skb, length);
341 skb->ip_summed = CHECKSUM_UNNECESSARY;
342 skb->protocol = eth_type_trans(skb, dev);
345 static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
347 struct ehea_cqe *cqe)
349 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
359 prefetchw(pref + EHEA_CACHE_LINE);
361 pref = (skb_array[x]->data);
363 prefetch(pref + EHEA_CACHE_LINE);
364 prefetch(pref + EHEA_CACHE_LINE * 2);
365 prefetch(pref + EHEA_CACHE_LINE * 3);
366 skb = skb_array[skb_index];
367 skb_array[skb_index] = NULL;
371 static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
372 int arr_len, int wqe_index)
383 prefetchw(pref + EHEA_CACHE_LINE);
385 pref = (skb_array[x]->data);
387 prefetchw(pref + EHEA_CACHE_LINE);
389 skb = skb_array[wqe_index];
390 skb_array[wqe_index] = NULL;
394 static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
395 struct ehea_cqe *cqe, int *processed_rq2,
400 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
401 pr->p_stats.err_tcp_cksum++;
402 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
403 pr->p_stats.err_ip_cksum++;
404 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
405 pr->p_stats.err_frame_crc++;
407 if (netif_msg_rx_err(pr->port)) {
408 ehea_error("CQE Error for QP %d", pr->qp->init_attr.qp_nr);
409 ehea_dump(cqe, sizeof(*cqe), "CQE");
414 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
416 } else if (rq == 3) {
418 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
422 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
423 ehea_error("Critical receive error. Resetting port.");
424 queue_work(pr->port->adapter->ehea_wq, &pr->port->reset_task);
431 static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
432 void **tcph, u64 *hdr_flags, void *priv)
434 struct ehea_cqe *cqe = priv;
438 /* non tcp/udp packets */
439 if (!cqe->header_length)
443 skb_reset_network_header(skb);
445 if (iph->protocol != IPPROTO_TCP)
448 ip_len = ip_hdrlen(skb);
449 skb_set_transport_header(skb, ip_len);
450 *tcph = tcp_hdr(skb);
452 /* check if ip header and tcp header are complete */
453 if (iph->tot_len < ip_len + tcp_hdrlen(skb))
456 *hdr_flags = LRO_IPV4 | LRO_TCP;
462 static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
465 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
470 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
475 lro_receive_skb(&pr->lro_mgr, skb, cqe);
478 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
481 netif_receive_skb(skb);
485 static int ehea_proc_rwqes(struct net_device *dev,
486 struct ehea_port_res *pr,
489 struct ehea_port *port = pr->port;
490 struct ehea_qp *qp = pr->qp;
491 struct ehea_cqe *cqe;
493 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
494 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
495 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
496 int skb_arr_rq1_len = pr->rq1_skba.len;
497 int skb_arr_rq2_len = pr->rq2_skba.len;
498 int skb_arr_rq3_len = pr->rq3_skba.len;
499 int processed, processed_rq1, processed_rq2, processed_rq3;
500 int wqe_index, last_wqe_index, rq, port_reset;
502 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
505 cqe = ehea_poll_rq1(qp, &wqe_index);
506 while ((processed < budget) && cqe) {
510 if (netif_msg_rx_status(port))
511 ehea_dump(cqe, sizeof(*cqe), "CQE");
513 last_wqe_index = wqe_index;
515 if (!ehea_check_cqe(cqe, &rq)) {
516 if (rq == 1) { /* LL RQ1 */
517 skb = get_skb_by_index_ll(skb_arr_rq1,
520 if (unlikely(!skb)) {
521 if (netif_msg_rx_err(port))
522 ehea_error("LL rq1: skb=NULL");
524 skb = netdev_alloc_skb(dev,
529 skb_copy_to_linear_data(skb, ((char*)cqe) + 64,
530 cqe->num_bytes_transfered - 4);
531 ehea_fill_skb(dev, skb, cqe);
532 } else if (rq == 2) { /* RQ2 */
533 skb = get_skb_by_index(skb_arr_rq2,
534 skb_arr_rq2_len, cqe);
535 if (unlikely(!skb)) {
536 if (netif_msg_rx_err(port))
537 ehea_error("rq2: skb=NULL");
540 ehea_fill_skb(dev, skb, cqe);
543 skb = get_skb_by_index(skb_arr_rq3,
544 skb_arr_rq3_len, cqe);
545 if (unlikely(!skb)) {
546 if (netif_msg_rx_err(port))
547 ehea_error("rq3: skb=NULL");
550 ehea_fill_skb(dev, skb, cqe);
554 ehea_proc_skb(pr, cqe, skb);
555 dev->last_rx = jiffies;
557 pr->p_stats.poll_receive_errors++;
558 port_reset = ehea_treat_poll_error(pr, rq, cqe,
564 cqe = ehea_poll_rq1(qp, &wqe_index);
567 lro_flush_all(&pr->lro_mgr);
569 pr->rx_packets += processed;
571 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
572 ehea_refill_rq2(pr, processed_rq2);
573 ehea_refill_rq3(pr, processed_rq3);
578 static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
581 struct ehea_cq *send_cq = pr->send_cq;
582 struct ehea_cqe *cqe;
583 int quota = my_quota;
589 cqe = ehea_poll_cq(send_cq);
590 while(cqe && (quota > 0)) {
591 ehea_inc_cq(send_cq);
595 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
596 ehea_error("Send Completion Error: Resetting port");
597 if (netif_msg_tx_err(pr->port))
598 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
599 queue_work(pr->port->adapter->ehea_wq,
600 &pr->port->reset_task);
604 if (netif_msg_tx_done(pr->port))
605 ehea_dump(cqe, sizeof(*cqe), "CQE");
607 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
608 == EHEA_SWQE2_TYPE)) {
610 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
611 skb = pr->sq_skba.arr[index];
613 pr->sq_skba.arr[index] = NULL;
616 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
619 cqe = ehea_poll_cq(send_cq);
622 ehea_update_feca(send_cq, cqe_counter);
623 atomic_add(swqe_av, &pr->swqe_avail);
625 spin_lock_irqsave(&pr->netif_queue, flags);
627 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
628 >= pr->swqe_refill_th)) {
629 netif_wake_queue(pr->port->netdev);
630 pr->queue_stopped = 0;
632 spin_unlock_irqrestore(&pr->netif_queue, flags);
637 #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
638 #define EHEA_POLL_MAX_CQES 65535
640 static int ehea_poll(struct napi_struct *napi, int budget)
642 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res, napi);
643 struct net_device *dev = pr->port->netdev;
644 struct ehea_cqe *cqe;
645 struct ehea_cqe *cqe_skb = NULL;
646 int force_irq, wqe_index;
649 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
650 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
653 rx += ehea_proc_rwqes(dev, pr, budget - rx);
655 while ((rx != budget) || force_irq) {
656 pr->poll_counter = 0;
658 netif_rx_complete(dev, napi);
659 ehea_reset_cq_ep(pr->recv_cq);
660 ehea_reset_cq_ep(pr->send_cq);
661 ehea_reset_cq_n1(pr->recv_cq);
662 ehea_reset_cq_n1(pr->send_cq);
663 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
664 cqe_skb = ehea_poll_cq(pr->send_cq);
666 if (!cqe && !cqe_skb)
669 if (!netif_rx_reschedule(dev, napi))
672 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
673 rx += ehea_proc_rwqes(dev, pr, budget - rx);
680 #ifdef CONFIG_NET_POLL_CONTROLLER
681 static void ehea_netpoll(struct net_device *dev)
683 struct ehea_port *port = netdev_priv(dev);
686 for (i = 0; i < port->num_def_qps; i++)
687 netif_rx_schedule(dev, &port->port_res[i].napi);
691 static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
693 struct ehea_port_res *pr = param;
695 netif_rx_schedule(pr->port->netdev, &pr->napi);
700 static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
702 struct ehea_port *port = param;
703 struct ehea_eqe *eqe;
707 eqe = ehea_poll_eq(port->qp_eq);
710 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
711 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
712 eqe->entry, qp_token);
714 qp = port->port_res[qp_token].qp;
715 ehea_error_data(port->adapter, qp->fw_handle);
716 eqe = ehea_poll_eq(port->qp_eq);
719 queue_work(port->adapter->ehea_wq, &port->reset_task);
724 static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
729 for (i = 0; i < EHEA_MAX_PORTS; i++)
730 if (adapter->port[i])
731 if (adapter->port[i]->logical_port_id == logical_port)
732 return adapter->port[i];
736 int ehea_sense_port_attr(struct ehea_port *port)
740 struct hcp_ehea_port_cb0 *cb0;
742 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC); /* May be called via */
743 if (!cb0) { /* ehea_neq_tasklet() */
744 ehea_error("no mem for cb0");
749 hret = ehea_h_query_ehea_port(port->adapter->handle,
750 port->logical_port_id, H_PORT_CB0,
751 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
753 if (hret != H_SUCCESS) {
759 port->mac_addr = cb0->port_mac_addr << 16;
761 if (!is_valid_ether_addr((u8*)&port->mac_addr)) {
762 ret = -EADDRNOTAVAIL;
767 switch (cb0->port_speed) {
769 port->port_speed = EHEA_SPEED_10M;
770 port->full_duplex = 0;
773 port->port_speed = EHEA_SPEED_10M;
774 port->full_duplex = 1;
777 port->port_speed = EHEA_SPEED_100M;
778 port->full_duplex = 0;
781 port->port_speed = EHEA_SPEED_100M;
782 port->full_duplex = 1;
785 port->port_speed = EHEA_SPEED_1G;
786 port->full_duplex = 1;
789 port->port_speed = EHEA_SPEED_10G;
790 port->full_duplex = 1;
793 port->port_speed = 0;
794 port->full_duplex = 0;
799 port->num_mcs = cb0->num_default_qps;
801 /* Number of default QPs */
803 port->num_def_qps = cb0->num_default_qps;
805 port->num_def_qps = 1;
807 if (!port->num_def_qps) {
812 port->num_tx_qps = num_tx_qps;
814 if (port->num_def_qps >= port->num_tx_qps)
815 port->num_add_tx_qps = 0;
817 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
821 if (ret || netif_msg_probe(port))
822 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
828 int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
830 struct hcp_ehea_port_cb4 *cb4;
834 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
836 ehea_error("no mem for cb4");
841 cb4->port_speed = port_speed;
843 netif_carrier_off(port->netdev);
845 hret = ehea_h_modify_ehea_port(port->adapter->handle,
846 port->logical_port_id,
847 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
848 if (hret == H_SUCCESS) {
849 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
851 hret = ehea_h_query_ehea_port(port->adapter->handle,
852 port->logical_port_id,
853 H_PORT_CB4, H_PORT_CB4_SPEED,
855 if (hret == H_SUCCESS) {
856 switch (cb4->port_speed) {
858 port->port_speed = EHEA_SPEED_10M;
859 port->full_duplex = 0;
862 port->port_speed = EHEA_SPEED_10M;
863 port->full_duplex = 1;
866 port->port_speed = EHEA_SPEED_100M;
867 port->full_duplex = 0;
870 port->port_speed = EHEA_SPEED_100M;
871 port->full_duplex = 1;
874 port->port_speed = EHEA_SPEED_1G;
875 port->full_duplex = 1;
878 port->port_speed = EHEA_SPEED_10G;
879 port->full_duplex = 1;
882 port->port_speed = 0;
883 port->full_duplex = 0;
887 ehea_error("Failed sensing port speed");
891 if (hret == H_AUTHORITY) {
892 ehea_info("Hypervisor denied setting port speed");
896 ehea_error("Failed setting port speed");
899 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
900 netif_carrier_on(port->netdev);
907 static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
912 struct ehea_port *port;
914 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
915 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
916 port = ehea_get_port(adapter, portnum);
919 case EHEA_EC_PORTSTATE_CHG: /* port state change */
922 ehea_error("unknown portnum %x", portnum);
926 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
927 if (!netif_carrier_ok(port->netdev)) {
928 ret = ehea_sense_port_attr(port);
930 ehea_error("failed resensing port "
935 if (netif_msg_link(port))
936 ehea_info("%s: Logical port up: %dMbps "
941 1 ? "Full" : "Half");
943 netif_carrier_on(port->netdev);
944 netif_wake_queue(port->netdev);
947 if (netif_carrier_ok(port->netdev)) {
948 if (netif_msg_link(port))
949 ehea_info("%s: Logical port down",
951 netif_carrier_off(port->netdev);
952 netif_stop_queue(port->netdev);
955 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
956 port->phy_link = EHEA_PHY_LINK_UP;
957 if (netif_msg_link(port))
958 ehea_info("%s: Physical port up",
960 if (prop_carrier_state)
961 netif_carrier_on(port->netdev);
963 port->phy_link = EHEA_PHY_LINK_DOWN;
964 if (netif_msg_link(port))
965 ehea_info("%s: Physical port down",
967 if (prop_carrier_state)
968 netif_carrier_off(port->netdev);
971 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
972 ehea_info("External switch port is primary port");
974 ehea_info("External switch port is backup port");
977 case EHEA_EC_ADAPTER_MALFUNC:
978 ehea_error("Adapter malfunction");
980 case EHEA_EC_PORT_MALFUNC:
981 ehea_info("Port malfunction: Device: %s", port->netdev->name);
982 netif_carrier_off(port->netdev);
983 netif_stop_queue(port->netdev);
986 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
991 static void ehea_neq_tasklet(unsigned long data)
993 struct ehea_adapter *adapter = (struct ehea_adapter*)data;
994 struct ehea_eqe *eqe;
997 eqe = ehea_poll_eq(adapter->neq);
998 ehea_debug("eqe=%p", eqe);
1001 ehea_debug("*eqe=%lx", eqe->entry);
1002 ehea_parse_eqe(adapter, eqe->entry);
1003 eqe = ehea_poll_eq(adapter->neq);
1004 ehea_debug("next eqe=%p", eqe);
1007 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1008 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1009 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1011 ehea_h_reset_events(adapter->handle,
1012 adapter->neq->fw_handle, event_mask);
1015 static irqreturn_t ehea_interrupt_neq(int irq, void *param)
1017 struct ehea_adapter *adapter = param;
1018 tasklet_hi_schedule(&adapter->neq_tasklet);
1023 static int ehea_fill_port_res(struct ehea_port_res *pr)
1026 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1028 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1029 - init_attr->act_nr_rwqes_rq2
1030 - init_attr->act_nr_rwqes_rq3 - 1);
1032 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
1034 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1039 static int ehea_reg_interrupts(struct net_device *dev)
1041 struct ehea_port *port = netdev_priv(dev);
1042 struct ehea_port_res *pr;
1046 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1049 ret = ibmebus_request_irq(NULL, port->qp_eq->attr.ist1,
1050 ehea_qp_aff_irq_handler,
1051 IRQF_DISABLED, port->int_aff_name, port);
1053 ehea_error("failed registering irq for qp_aff_irq_handler:"
1054 "ist=%X", port->qp_eq->attr.ist1);
1058 if (netif_msg_ifup(port))
1059 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1060 "registered", port->qp_eq->attr.ist1);
1063 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1064 pr = &port->port_res[i];
1065 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
1066 "%s-queue%d", dev->name, i);
1067 ret = ibmebus_request_irq(NULL, pr->eq->attr.ist1,
1068 ehea_recv_irq_handler,
1069 IRQF_DISABLED, pr->int_send_name,
1072 ehea_error("failed registering irq for ehea_queue "
1073 "port_res_nr:%d, ist=%X", i,
1077 if (netif_msg_ifup(port))
1078 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1079 "%d registered", pr->eq->attr.ist1, i);
1087 u32 ist = port->port_res[i].eq->attr.ist1;
1088 ibmebus_free_irq(NULL, ist, &port->port_res[i]);
1092 ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port);
1093 i = port->num_def_qps;
1099 static void ehea_free_interrupts(struct net_device *dev)
1101 struct ehea_port *port = netdev_priv(dev);
1102 struct ehea_port_res *pr;
1107 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1108 pr = &port->port_res[i];
1109 ibmebus_free_irq(NULL, pr->eq->attr.ist1, pr);
1110 if (netif_msg_intr(port))
1111 ehea_info("free send irq for res %d with handle 0x%X",
1112 i, pr->eq->attr.ist1);
1115 /* associated events */
1116 ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port);
1117 if (netif_msg_intr(port))
1118 ehea_info("associated event interrupt for handle 0x%X freed",
1119 port->qp_eq->attr.ist1);
1122 static int ehea_configure_port(struct ehea_port *port)
1126 struct hcp_ehea_port_cb0 *cb0;
1129 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1133 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1134 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1135 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1136 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1137 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1138 PXLY_RC_VLAN_FILTER)
1139 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1141 for (i = 0; i < port->num_mcs; i++)
1143 cb0->default_qpn_arr[i] =
1144 port->port_res[i].qp->init_attr.qp_nr;
1146 cb0->default_qpn_arr[i] =
1147 port->port_res[0].qp->init_attr.qp_nr;
1149 if (netif_msg_ifup(port))
1150 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1152 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1153 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1155 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1156 port->logical_port_id,
1157 H_PORT_CB0, mask, cb0);
1159 if (hret != H_SUCCESS)
1170 int ehea_gen_smrs(struct ehea_port_res *pr)
1173 struct ehea_adapter *adapter = pr->port->adapter;
1175 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1179 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1186 ehea_rem_mr(&pr->send_mr);
1188 ehea_error("Generating SMRS failed\n");
1192 int ehea_rem_smrs(struct ehea_port_res *pr)
1194 if ((ehea_rem_mr(&pr->send_mr))
1195 || (ehea_rem_mr(&pr->recv_mr)))
1201 static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1203 int arr_size = sizeof(void*) * max_q_entries;
1205 q_skba->arr = vmalloc(arr_size);
1209 memset(q_skba->arr, 0, arr_size);
1211 q_skba->len = max_q_entries;
1213 q_skba->os_skbs = 0;
1218 static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1219 struct port_res_cfg *pr_cfg, int queue_token)
1221 struct ehea_adapter *adapter = port->adapter;
1222 enum ehea_eq_type eq_type = EHEA_EQ;
1223 struct ehea_qp_init_attr *init_attr = NULL;
1226 memset(pr, 0, sizeof(struct ehea_port_res));
1229 spin_lock_init(&pr->xmit_lock);
1230 spin_lock_init(&pr->netif_queue);
1232 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1234 ehea_error("create_eq failed (eq)");
1238 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
1240 port->logical_port_id);
1242 ehea_error("create_cq failed (cq_recv)");
1246 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
1248 port->logical_port_id);
1250 ehea_error("create_cq failed (cq_send)");
1254 if (netif_msg_ifup(port))
1255 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1256 pr->send_cq->attr.act_nr_of_cqes,
1257 pr->recv_cq->attr.act_nr_of_cqes);
1259 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1262 ehea_error("no mem for ehea_qp_init_attr");
1266 init_attr->low_lat_rq1 = 1;
1267 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1268 init_attr->rq_count = 3;
1269 init_attr->qp_token = queue_token;
1270 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1271 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1272 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1273 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1274 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1275 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1276 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1277 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1278 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1279 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1280 init_attr->port_nr = port->logical_port_id;
1281 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1282 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1283 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1285 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1287 ehea_error("create_qp failed");
1292 if (netif_msg_ifup(port))
1293 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1294 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1295 init_attr->act_nr_send_wqes,
1296 init_attr->act_nr_rwqes_rq1,
1297 init_attr->act_nr_rwqes_rq2,
1298 init_attr->act_nr_rwqes_rq3);
1300 ret = ehea_init_q_skba(&pr->sq_skba, init_attr->act_nr_send_wqes + 1);
1301 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1302 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1303 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1307 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1308 if (ehea_gen_smrs(pr) != 0) {
1313 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1317 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
1319 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1320 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1321 pr->lro_mgr.lro_arr = pr->lro_desc;
1322 pr->lro_mgr.get_skb_header = get_skb_hdr;
1323 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1324 pr->lro_mgr.dev = port->netdev;
1325 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1326 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1333 vfree(pr->sq_skba.arr);
1334 vfree(pr->rq1_skba.arr);
1335 vfree(pr->rq2_skba.arr);
1336 vfree(pr->rq3_skba.arr);
1337 ehea_destroy_qp(pr->qp);
1338 ehea_destroy_cq(pr->send_cq);
1339 ehea_destroy_cq(pr->recv_cq);
1340 ehea_destroy_eq(pr->eq);
1345 static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1349 ret = ehea_destroy_qp(pr->qp);
1352 ehea_destroy_cq(pr->send_cq);
1353 ehea_destroy_cq(pr->recv_cq);
1354 ehea_destroy_eq(pr->eq);
1356 for (i = 0; i < pr->rq1_skba.len; i++)
1357 if (pr->rq1_skba.arr[i])
1358 dev_kfree_skb(pr->rq1_skba.arr[i]);
1360 for (i = 0; i < pr->rq2_skba.len; i++)
1361 if (pr->rq2_skba.arr[i])
1362 dev_kfree_skb(pr->rq2_skba.arr[i]);
1364 for (i = 0; i < pr->rq3_skba.len; i++)
1365 if (pr->rq3_skba.arr[i])
1366 dev_kfree_skb(pr->rq3_skba.arr[i]);
1368 for (i = 0; i < pr->sq_skba.len; i++)
1369 if (pr->sq_skba.arr[i])
1370 dev_kfree_skb(pr->sq_skba.arr[i]);
1372 vfree(pr->rq1_skba.arr);
1373 vfree(pr->rq2_skba.arr);
1374 vfree(pr->rq3_skba.arr);
1375 vfree(pr->sq_skba.arr);
1376 ret = ehea_rem_smrs(pr);
1382 * The write_* functions store information in swqe which is used by
1383 * the hardware to calculate the ip/tcp/udp checksum
1386 static inline void write_ip_start_end(struct ehea_swqe *swqe,
1387 const struct sk_buff *skb)
1389 swqe->ip_start = skb_network_offset(skb);
1390 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
1393 static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1394 const struct sk_buff *skb)
1397 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1399 swqe->tcp_end = (u16)skb->len - 1;
1402 static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1403 const struct sk_buff *skb)
1406 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1408 swqe->tcp_end = (u16)skb->len - 1;
1412 static void write_swqe2_TSO(struct sk_buff *skb,
1413 struct ehea_swqe *swqe, u32 lkey)
1415 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1416 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1417 int skb_data_size = skb->len - skb->data_len;
1420 /* Packet is TCP with TSO enabled */
1421 swqe->tx_control |= EHEA_SWQE_TSO;
1422 swqe->mss = skb_shinfo(skb)->gso_size;
1423 /* copy only eth/ip/tcp headers to immediate data and
1424 * the rest of skb->data to sg1entry
1426 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1428 skb_data_size = skb->len - skb->data_len;
1430 if (skb_data_size >= headersize) {
1431 /* copy immediate data */
1432 skb_copy_from_linear_data(skb, imm_data, headersize);
1433 swqe->immediate_data_length = headersize;
1435 if (skb_data_size > headersize) {
1436 /* set sg1entry data */
1437 sg1entry->l_key = lkey;
1438 sg1entry->len = skb_data_size - headersize;
1440 ehea_map_vaddr(skb->data + headersize);
1441 swqe->descriptors++;
1444 ehea_error("cannot handle fragmented headers");
1447 static void write_swqe2_nonTSO(struct sk_buff *skb,
1448 struct ehea_swqe *swqe, u32 lkey)
1450 int skb_data_size = skb->len - skb->data_len;
1451 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1452 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1454 /* Packet is any nonTSO type
1456 * Copy as much as possible skb->data to immediate data and
1457 * the rest to sg1entry
1459 if (skb_data_size >= SWQE2_MAX_IMM) {
1460 /* copy immediate data */
1461 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
1463 swqe->immediate_data_length = SWQE2_MAX_IMM;
1465 if (skb_data_size > SWQE2_MAX_IMM) {
1466 /* copy sg1entry data */
1467 sg1entry->l_key = lkey;
1468 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
1470 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
1471 swqe->descriptors++;
1474 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
1475 swqe->immediate_data_length = skb_data_size;
1479 static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1480 struct ehea_swqe *swqe, u32 lkey)
1482 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1484 int nfrags, sg1entry_contains_frag_data, i;
1486 nfrags = skb_shinfo(skb)->nr_frags;
1487 sg1entry = &swqe->u.immdata_desc.sg_entry;
1488 sg_list = (struct ehea_vsgentry*)&swqe->u.immdata_desc.sg_list;
1489 swqe->descriptors = 0;
1490 sg1entry_contains_frag_data = 0;
1492 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1493 write_swqe2_TSO(skb, swqe, lkey);
1495 write_swqe2_nonTSO(skb, swqe, lkey);
1497 /* write descriptors */
1499 if (swqe->descriptors == 0) {
1500 /* sg1entry not yet used */
1501 frag = &skb_shinfo(skb)->frags[0];
1503 /* copy sg1entry data */
1504 sg1entry->l_key = lkey;
1505 sg1entry->len = frag->size;
1507 ehea_map_vaddr(page_address(frag->page)
1508 + frag->page_offset);
1509 swqe->descriptors++;
1510 sg1entry_contains_frag_data = 1;
1513 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1515 frag = &skb_shinfo(skb)->frags[i];
1516 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1518 sgentry->l_key = lkey;
1519 sgentry->len = frag->size;
1521 ehea_map_vaddr(page_address(frag->page)
1522 + frag->page_offset);
1523 swqe->descriptors++;
1528 static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1534 /* De/Register untagged packets */
1535 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1536 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1537 port->logical_port_id,
1538 reg_type, port->mac_addr, 0, hcallid);
1539 if (hret != H_SUCCESS) {
1540 ehea_error("%sregistering bc address failed (tagged)",
1541 hcallid == H_REG_BCMC ? "" : "de");
1546 /* De/Register VLAN packets */
1547 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1548 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1549 port->logical_port_id,
1550 reg_type, port->mac_addr, 0, hcallid);
1551 if (hret != H_SUCCESS) {
1552 ehea_error("%sregistering bc address failed (vlan)",
1553 hcallid == H_REG_BCMC ? "" : "de");
1560 static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1562 struct ehea_port *port = netdev_priv(dev);
1563 struct sockaddr *mac_addr = sa;
1564 struct hcp_ehea_port_cb0 *cb0;
1568 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1569 ret = -EADDRNOTAVAIL;
1573 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
1575 ehea_error("no mem for cb0");
1580 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1582 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1584 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1585 port->logical_port_id, H_PORT_CB0,
1586 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1587 if (hret != H_SUCCESS) {
1592 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1594 /* Deregister old MAC in pHYP */
1595 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1599 port->mac_addr = cb0->port_mac_addr << 16;
1601 /* Register new MAC in pHYP */
1602 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1613 static void ehea_promiscuous_error(u64 hret, int enable)
1615 if (hret == H_AUTHORITY)
1616 ehea_info("Hypervisor denied %sabling promiscuous mode",
1617 enable == 1 ? "en" : "dis");
1619 ehea_error("failed %sabling promiscuous mode",
1620 enable == 1 ? "en" : "dis");
1623 static void ehea_promiscuous(struct net_device *dev, int enable)
1625 struct ehea_port *port = netdev_priv(dev);
1626 struct hcp_ehea_port_cb7 *cb7;
1629 if ((enable && port->promisc) || (!enable && !port->promisc))
1632 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
1634 ehea_error("no mem for cb7");
1638 /* Modify Pxs_DUCQPN in CB7 */
1639 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1641 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1642 port->logical_port_id,
1643 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1645 ehea_promiscuous_error(hret, enable);
1649 port->promisc = enable;
1655 static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1661 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1662 | EHEA_BCMC_UNTAGGED;
1664 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1665 port->logical_port_id,
1666 reg_type, mc_mac_addr, 0, hcallid);
1670 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1671 | EHEA_BCMC_VLANID_ALL;
1673 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1674 port->logical_port_id,
1675 reg_type, mc_mac_addr, 0, hcallid);
1680 static int ehea_drop_multicast_list(struct net_device *dev)
1682 struct ehea_port *port = netdev_priv(dev);
1683 struct ehea_mc_list *mc_entry = port->mc_list;
1684 struct list_head *pos;
1685 struct list_head *temp;
1689 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1690 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1692 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1695 ehea_error("failed deregistering mcast MAC");
1705 static void ehea_allmulti(struct net_device *dev, int enable)
1707 struct ehea_port *port = netdev_priv(dev);
1710 if (!port->allmulti) {
1712 /* Enable ALLMULTI */
1713 ehea_drop_multicast_list(dev);
1714 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1718 ehea_error("failed enabling IFF_ALLMULTI");
1722 /* Disable ALLMULTI */
1723 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1727 ehea_error("failed disabling IFF_ALLMULTI");
1731 static void ehea_add_multicast_entry(struct ehea_port* port, u8* mc_mac_addr)
1733 struct ehea_mc_list *ehea_mcl_entry;
1736 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
1737 if (!ehea_mcl_entry) {
1738 ehea_error("no mem for mcl_entry");
1742 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1744 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1746 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1749 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1751 ehea_error("failed registering mcast MAC");
1752 kfree(ehea_mcl_entry);
1756 static void ehea_set_multicast_list(struct net_device *dev)
1758 struct ehea_port *port = netdev_priv(dev);
1759 struct dev_mc_list *k_mcl_entry;
1762 if (dev->flags & IFF_PROMISC) {
1763 ehea_promiscuous(dev, 1);
1766 ehea_promiscuous(dev, 0);
1768 if (dev->flags & IFF_ALLMULTI) {
1769 ehea_allmulti(dev, 1);
1772 ehea_allmulti(dev, 0);
1774 if (dev->mc_count) {
1775 ret = ehea_drop_multicast_list(dev);
1777 /* Dropping the current multicast list failed.
1778 * Enabling ALL_MULTI is the best we can do.
1780 ehea_allmulti(dev, 1);
1783 if (dev->mc_count > port->adapter->max_mc_mac) {
1784 ehea_info("Mcast registration limit reached (0x%lx). "
1786 port->adapter->max_mc_mac);
1790 for (i = 0, k_mcl_entry = dev->mc_list;
1792 i++, k_mcl_entry = k_mcl_entry->next) {
1793 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
1800 static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1802 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1808 static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1809 struct ehea_swqe *swqe, u32 lkey)
1811 if (skb->protocol == htons(ETH_P_IP)) {
1812 const struct iphdr *iph = ip_hdr(skb);
1815 swqe->tx_control |= EHEA_SWQE_CRC
1816 | EHEA_SWQE_IP_CHECKSUM
1817 | EHEA_SWQE_TCP_CHECKSUM
1818 | EHEA_SWQE_IMM_DATA_PRESENT
1819 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1821 write_ip_start_end(swqe, skb);
1823 if (iph->protocol == IPPROTO_UDP) {
1824 if ((iph->frag_off & IP_MF)
1825 || (iph->frag_off & IP_OFFSET))
1826 /* IP fragment, so don't change cs */
1827 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
1829 write_udp_offset_end(swqe, skb);
1830 } else if (iph->protocol == IPPROTO_TCP) {
1831 write_tcp_offset_end(swqe, skb);
1834 /* icmp (big data) and ip segmentation packets (all other ip
1835 packets) do not require any special handling */
1838 /* Other Ethernet Protocol */
1839 swqe->tx_control |= EHEA_SWQE_CRC
1840 | EHEA_SWQE_IMM_DATA_PRESENT
1841 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1844 write_swqe2_data(skb, dev, swqe, lkey);
1847 static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
1848 struct ehea_swqe *swqe)
1850 int nfrags = skb_shinfo(skb)->nr_frags;
1851 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
1855 if (skb->protocol == htons(ETH_P_IP)) {
1856 const struct iphdr *iph = ip_hdr(skb);
1859 write_ip_start_end(swqe, skb);
1861 if (iph->protocol == IPPROTO_TCP) {
1862 swqe->tx_control |= EHEA_SWQE_CRC
1863 | EHEA_SWQE_IP_CHECKSUM
1864 | EHEA_SWQE_TCP_CHECKSUM
1865 | EHEA_SWQE_IMM_DATA_PRESENT;
1867 write_tcp_offset_end(swqe, skb);
1869 } else if (iph->protocol == IPPROTO_UDP) {
1870 if ((iph->frag_off & IP_MF)
1871 || (iph->frag_off & IP_OFFSET))
1872 /* IP fragment, so don't change cs */
1873 swqe->tx_control |= EHEA_SWQE_CRC
1874 | EHEA_SWQE_IMM_DATA_PRESENT;
1876 swqe->tx_control |= EHEA_SWQE_CRC
1877 | EHEA_SWQE_IP_CHECKSUM
1878 | EHEA_SWQE_TCP_CHECKSUM
1879 | EHEA_SWQE_IMM_DATA_PRESENT;
1881 write_udp_offset_end(swqe, skb);
1884 /* icmp (big data) and
1885 ip segmentation packets (all other ip packets) */
1886 swqe->tx_control |= EHEA_SWQE_CRC
1887 | EHEA_SWQE_IP_CHECKSUM
1888 | EHEA_SWQE_IMM_DATA_PRESENT;
1891 /* Other Ethernet Protocol */
1892 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
1894 /* copy (immediate) data */
1896 /* data is in a single piece */
1897 skb_copy_from_linear_data(skb, imm_data, skb->len);
1899 /* first copy data from the skb->data buffer ... */
1900 skb_copy_from_linear_data(skb, imm_data,
1901 skb->len - skb->data_len);
1902 imm_data += skb->len - skb->data_len;
1904 /* ... then copy data from the fragments */
1905 for (i = 0; i < nfrags; i++) {
1906 frag = &skb_shinfo(skb)->frags[i];
1908 page_address(frag->page) + frag->page_offset,
1910 imm_data += frag->size;
1913 swqe->immediate_data_length = skb->len;
1917 static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
1922 if ((skb->protocol == htons(ETH_P_IP)) &&
1923 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
1924 tcp = (struct tcphdr*)(skb_network_header(skb) + (ip_hdr(skb)->ihl * 4));
1925 tmp = (tcp->source + (tcp->dest << 16)) % 31;
1926 tmp += ip_hdr(skb)->daddr % 31;
1927 return tmp % num_qps;
1933 static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
1935 struct ehea_port *port = netdev_priv(dev);
1936 struct ehea_swqe *swqe;
1937 unsigned long flags;
1940 struct ehea_port_res *pr;
1942 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
1944 if (!spin_trylock(&pr->xmit_lock))
1945 return NETDEV_TX_BUSY;
1947 if (pr->queue_stopped) {
1948 spin_unlock(&pr->xmit_lock);
1949 return NETDEV_TX_BUSY;
1952 swqe = ehea_get_swqe(pr->qp, &swqe_index);
1953 memset(swqe, 0, SWQE_HEADER_SIZE);
1954 atomic_dec(&pr->swqe_avail);
1956 if (skb->len <= SWQE3_MAX_IMM) {
1957 u32 sig_iv = port->sig_comp_iv;
1958 u32 swqe_num = pr->swqe_id_counter;
1959 ehea_xmit3(skb, dev, swqe);
1960 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
1961 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
1962 if (pr->swqe_ll_count >= (sig_iv - 1)) {
1963 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
1965 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1966 pr->swqe_ll_count = 0;
1968 pr->swqe_ll_count += 1;
1971 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
1972 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
1973 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
1974 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
1975 pr->sq_skba.arr[pr->sq_skba.index] = skb;
1977 pr->sq_skba.index++;
1978 pr->sq_skba.index &= (pr->sq_skba.len - 1);
1980 lkey = pr->send_mr.lkey;
1981 ehea_xmit2(skb, dev, swqe, lkey);
1982 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1984 pr->swqe_id_counter += 1;
1986 if (port->vgrp && vlan_tx_tag_present(skb)) {
1987 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
1988 swqe->vlan_tag = vlan_tx_tag_get(skb);
1991 if (netif_msg_tx_queued(port)) {
1992 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
1993 ehea_dump(swqe, 512, "swqe");
1996 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
1997 netif_stop_queue(dev);
1998 swqe->tx_control |= EHEA_SWQE_PURGE;
2001 ehea_post_swqe(pr->qp, swqe);
2003 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2004 spin_lock_irqsave(&pr->netif_queue, flags);
2005 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2006 pr->p_stats.queue_stopped++;
2007 netif_stop_queue(dev);
2008 pr->queue_stopped = 1;
2010 spin_unlock_irqrestore(&pr->netif_queue, flags);
2012 dev->trans_start = jiffies;
2013 spin_unlock(&pr->xmit_lock);
2015 return NETDEV_TX_OK;
2018 static void ehea_vlan_rx_register(struct net_device *dev,
2019 struct vlan_group *grp)
2021 struct ehea_port *port = netdev_priv(dev);
2022 struct ehea_adapter *adapter = port->adapter;
2023 struct hcp_ehea_port_cb1 *cb1;
2028 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2030 ehea_error("no mem for cb1");
2034 memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
2036 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2037 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2038 if (hret != H_SUCCESS)
2039 ehea_error("modify_ehea_port failed");
2046 static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2048 struct ehea_port *port = netdev_priv(dev);
2049 struct ehea_adapter *adapter = port->adapter;
2050 struct hcp_ehea_port_cb1 *cb1;
2054 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2056 ehea_error("no mem for cb1");
2060 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2061 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2062 if (hret != H_SUCCESS) {
2063 ehea_error("query_ehea_port failed");
2068 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
2070 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2071 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2072 if (hret != H_SUCCESS)
2073 ehea_error("modify_ehea_port failed");
2079 static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2081 struct ehea_port *port = netdev_priv(dev);
2082 struct ehea_adapter *adapter = port->adapter;
2083 struct hcp_ehea_port_cb1 *cb1;
2087 vlan_group_set_device(port->vgrp, vid, NULL);
2089 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2091 ehea_error("no mem for cb1");
2095 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2096 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2097 if (hret != H_SUCCESS) {
2098 ehea_error("query_ehea_port failed");
2103 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
2105 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2106 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2107 if (hret != H_SUCCESS)
2108 ehea_error("modify_ehea_port failed");
2114 int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2120 struct hcp_modify_qp_cb0* cb0;
2122 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2128 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2129 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2130 if (hret != H_SUCCESS) {
2131 ehea_error("query_ehea_qp failed (1)");
2135 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2136 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2137 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2138 &dummy64, &dummy64, &dummy16, &dummy16);
2139 if (hret != H_SUCCESS) {
2140 ehea_error("modify_ehea_qp failed (1)");
2144 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2145 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2146 if (hret != H_SUCCESS) {
2147 ehea_error("query_ehea_qp failed (2)");
2151 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2152 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2153 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2154 &dummy64, &dummy64, &dummy16, &dummy16);
2155 if (hret != H_SUCCESS) {
2156 ehea_error("modify_ehea_qp failed (2)");
2160 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2161 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2162 if (hret != H_SUCCESS) {
2163 ehea_error("query_ehea_qp failed (3)");
2167 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2168 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2169 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2170 &dummy64, &dummy64, &dummy16, &dummy16);
2171 if (hret != H_SUCCESS) {
2172 ehea_error("modify_ehea_qp failed (3)");
2176 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2177 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2178 if (hret != H_SUCCESS) {
2179 ehea_error("query_ehea_qp failed (4)");
2189 static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2193 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2194 enum ehea_eq_type eq_type = EHEA_EQ;
2196 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2197 EHEA_MAX_ENTRIES_EQ, 1);
2200 ehea_error("ehea_create_eq failed (qp_eq)");
2204 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
2205 pr_cfg.max_entries_scq = sq_entries * 2;
2206 pr_cfg.max_entries_sq = sq_entries;
2207 pr_cfg.max_entries_rq1 = rq1_entries;
2208 pr_cfg.max_entries_rq2 = rq2_entries;
2209 pr_cfg.max_entries_rq3 = rq3_entries;
2211 pr_cfg_small_rx.max_entries_rcq = 1;
2212 pr_cfg_small_rx.max_entries_scq = sq_entries;
2213 pr_cfg_small_rx.max_entries_sq = sq_entries;
2214 pr_cfg_small_rx.max_entries_rq1 = 1;
2215 pr_cfg_small_rx.max_entries_rq2 = 1;
2216 pr_cfg_small_rx.max_entries_rq3 = 1;
2218 for (i = 0; i < def_qps; i++) {
2219 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2223 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2224 ret = ehea_init_port_res(port, &port->port_res[i],
2225 &pr_cfg_small_rx, i);
2234 ehea_clean_portres(port, &port->port_res[i]);
2237 ehea_destroy_eq(port->qp_eq);
2241 static int ehea_clean_all_portres(struct ehea_port *port)
2246 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2247 ret |= ehea_clean_portres(port, &port->port_res[i]);
2249 ret |= ehea_destroy_eq(port->qp_eq);
2254 static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
2256 if (adapter->active_ports)
2259 ehea_rem_mr(&adapter->mr);
2262 static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
2264 if (adapter->active_ports)
2267 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2270 static int ehea_up(struct net_device *dev)
2273 struct ehea_port *port = netdev_priv(dev);
2275 if (port->state == EHEA_PORT_UP)
2278 ret = ehea_port_res_setup(port, port->num_def_qps,
2279 port->num_add_tx_qps);
2281 ehea_error("port_res_failed");
2285 /* Set default QP for this port */
2286 ret = ehea_configure_port(port);
2288 ehea_error("ehea_configure_port failed. ret:%d", ret);
2292 ret = ehea_reg_interrupts(dev);
2294 ehea_error("reg_interrupts failed. ret:%d", ret);
2298 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2299 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2301 ehea_error("activate_qp failed");
2306 for(i = 0; i < port->num_def_qps; i++) {
2307 ret = ehea_fill_port_res(&port->port_res[i]);
2309 ehea_error("out_free_irqs");
2315 port->state = EHEA_PORT_UP;
2319 ehea_free_interrupts(dev);
2322 ehea_clean_all_portres(port);
2325 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2330 static void port_napi_disable(struct ehea_port *port)
2334 for (i = 0; i < port->num_def_qps; i++)
2335 napi_disable(&port->port_res[i].napi);
2338 static void port_napi_enable(struct ehea_port *port)
2342 for (i = 0; i < port->num_def_qps; i++)
2343 napi_enable(&port->port_res[i].napi);
2346 static int ehea_open(struct net_device *dev)
2349 struct ehea_port *port = netdev_priv(dev);
2351 down(&port->port_lock);
2353 if (netif_msg_ifup(port))
2354 ehea_info("enabling port %s", dev->name);
2358 port_napi_enable(port);
2359 netif_start_queue(dev);
2362 up(&port->port_lock);
2367 static int ehea_down(struct net_device *dev)
2370 struct ehea_port *port = netdev_priv(dev);
2372 if (port->state == EHEA_PORT_DOWN)
2375 ehea_drop_multicast_list(dev);
2376 ehea_free_interrupts(dev);
2378 port_napi_disable(port);
2380 port->state = EHEA_PORT_DOWN;
2382 ret = ehea_clean_all_portres(port);
2384 ehea_info("Failed freeing resources for %s. ret=%i",
2390 static int ehea_stop(struct net_device *dev)
2393 struct ehea_port *port = netdev_priv(dev);
2395 if (netif_msg_ifdown(port))
2396 ehea_info("disabling port %s", dev->name);
2398 flush_workqueue(port->adapter->ehea_wq);
2399 down(&port->port_lock);
2400 netif_stop_queue(dev);
2401 ret = ehea_down(dev);
2402 up(&port->port_lock);
2406 void ehea_purge_sq(struct ehea_qp *orig_qp)
2408 struct ehea_qp qp = *orig_qp;
2409 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2410 struct ehea_swqe *swqe;
2414 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2415 swqe = ehea_get_swqe(&qp, &wqe_index);
2416 swqe->tx_control |= EHEA_SWQE_PURGE;
2420 int ehea_stop_qps(struct net_device *dev)
2422 struct ehea_port *port = netdev_priv(dev);
2423 struct ehea_adapter *adapter = port->adapter;
2424 struct hcp_modify_qp_cb0* cb0;
2432 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2438 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2439 struct ehea_port_res *pr = &port->port_res[i];
2440 struct ehea_qp *qp = pr->qp;
2442 /* Purge send queue */
2445 /* Disable queue pair */
2446 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2447 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2449 if (hret != H_SUCCESS) {
2450 ehea_error("query_ehea_qp failed (1)");
2454 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2455 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2457 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2458 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2460 &dummy64, &dummy16, &dummy16);
2461 if (hret != H_SUCCESS) {
2462 ehea_error("modify_ehea_qp failed (1)");
2466 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2467 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2469 if (hret != H_SUCCESS) {
2470 ehea_error("query_ehea_qp failed (2)");
2474 /* deregister shared memory regions */
2475 dret = ehea_rem_smrs(pr);
2477 ehea_error("unreg shared memory region failed");
2489 void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res * pr)
2491 struct ehea_qp qp = *orig_qp;
2492 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2493 struct ehea_rwqe *rwqe;
2494 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2495 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2496 struct sk_buff *skb;
2497 u32 lkey = pr->recv_mr.lkey;
2503 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2504 rwqe = ehea_get_next_rwqe(&qp, 2);
2505 rwqe->sg_list[0].l_key = lkey;
2506 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2507 skb = skba_rq2[index];
2509 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2512 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2513 rwqe = ehea_get_next_rwqe(&qp, 3);
2514 rwqe->sg_list[0].l_key = lkey;
2515 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2516 skb = skba_rq3[index];
2518 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2522 int ehea_restart_qps(struct net_device *dev)
2524 struct ehea_port *port = netdev_priv(dev);
2525 struct ehea_adapter *adapter = port->adapter;
2529 struct hcp_modify_qp_cb0* cb0;
2534 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2540 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2541 struct ehea_port_res *pr = &port->port_res[i];
2542 struct ehea_qp *qp = pr->qp;
2544 ret = ehea_gen_smrs(pr);
2546 ehea_error("creation of shared memory regions failed");
2550 ehea_update_rqs(qp, pr);
2552 /* Enable queue pair */
2553 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2554 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2556 if (hret != H_SUCCESS) {
2557 ehea_error("query_ehea_qp failed (1)");
2561 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2562 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2564 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2565 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2567 &dummy64, &dummy16, &dummy16);
2568 if (hret != H_SUCCESS) {
2569 ehea_error("modify_ehea_qp failed (1)");
2573 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2574 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2576 if (hret != H_SUCCESS) {
2577 ehea_error("query_ehea_qp failed (2)");
2581 /* refill entire queue */
2582 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2583 ehea_refill_rq2(pr, 0);
2584 ehea_refill_rq3(pr, 0);
2592 static void ehea_reset_port(struct work_struct *work)
2595 struct ehea_port *port =
2596 container_of(work, struct ehea_port, reset_task);
2597 struct net_device *dev = port->netdev;
2600 down(&port->port_lock);
2601 netif_stop_queue(dev);
2603 port_napi_disable(port);
2611 ehea_set_multicast_list(dev);
2613 if (netif_msg_timer(port))
2614 ehea_info("Device %s resetted successfully", dev->name);
2616 port_napi_enable(port);
2618 netif_wake_queue(dev);
2620 up(&port->port_lock);
2624 static void ehea_rereg_mrs(struct work_struct *work)
2627 struct ehea_adapter *adapter;
2629 down(&dlpar_mem_lock);
2630 ehea_info("LPAR memory enlarged - re-initializing driver");
2632 list_for_each_entry(adapter, &adapter_list, list)
2633 if (adapter->active_ports) {
2634 /* Shutdown all ports */
2635 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2636 struct ehea_port *port = adapter->port[i];
2639 struct net_device *dev = port->netdev;
2641 if (dev->flags & IFF_UP) {
2642 down(&port->port_lock);
2643 netif_stop_queue(dev);
2644 ret = ehea_stop_qps(dev);
2646 up(&port->port_lock);
2649 port_napi_disable(port);
2650 up(&port->port_lock);
2655 /* Unregister old memory region */
2656 ret = ehea_rem_mr(&adapter->mr);
2658 ehea_error("unregister MR failed - driver"
2664 ehea_destroy_busmap();
2665 ret = ehea_create_busmap();
2667 ehea_error("creating ehea busmap failed");
2671 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2673 list_for_each_entry(adapter, &adapter_list, list)
2674 if (adapter->active_ports) {
2675 /* Register new memory region */
2676 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2678 ehea_error("register MR failed - driver"
2683 /* Restart all ports */
2684 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2685 struct ehea_port *port = adapter->port[i];
2688 struct net_device *dev = port->netdev;
2690 if (dev->flags & IFF_UP) {
2691 down(&port->port_lock);
2692 port_napi_enable(port);
2693 ret = ehea_restart_qps(dev);
2695 netif_wake_queue(dev);
2696 up(&port->port_lock);
2701 up(&dlpar_mem_lock);
2702 ehea_info("re-initializing driver complete");
2707 static void ehea_tx_watchdog(struct net_device *dev)
2709 struct ehea_port *port = netdev_priv(dev);
2711 if (netif_carrier_ok(dev) &&
2712 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
2713 queue_work(port->adapter->ehea_wq, &port->reset_task);
2716 int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2718 struct hcp_query_ehea *cb;
2722 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
2728 hret = ehea_h_query_ehea(adapter->handle, cb);
2730 if (hret != H_SUCCESS) {
2735 adapter->max_mc_mac = cb->max_mc_mac - 1;
2744 int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2746 struct hcp_ehea_port_cb4 *cb4;
2752 /* (Try to) enable *jumbo frames */
2753 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2755 ehea_error("no mem for cb4");
2759 hret = ehea_h_query_ehea_port(port->adapter->handle,
2760 port->logical_port_id,
2762 H_PORT_CB4_JUMBO, cb4);
2763 if (hret == H_SUCCESS) {
2764 if (cb4->jumbo_frame)
2767 cb4->jumbo_frame = 1;
2768 hret = ehea_h_modify_ehea_port(port->adapter->
2775 if (hret == H_SUCCESS)
2787 static ssize_t ehea_show_port_id(struct device *dev,
2788 struct device_attribute *attr, char *buf)
2790 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
2791 return sprintf(buf, "%d", port->logical_port_id);
2794 static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2797 static void __devinit logical_port_release(struct device *dev)
2799 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
2800 of_node_put(port->ofdev.node);
2803 static int ehea_driver_sysfs_add(struct device *dev,
2804 struct device_driver *driver)
2808 ret = sysfs_create_link(&driver->kobj, &dev->kobj,
2809 kobject_name(&dev->kobj));
2811 ret = sysfs_create_link(&dev->kobj, &driver->kobj,
2814 sysfs_remove_link(&driver->kobj,
2815 kobject_name(&dev->kobj));
2820 static void ehea_driver_sysfs_remove(struct device *dev,
2821 struct device_driver *driver)
2823 struct device_driver *drv = driver;
2826 sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
2827 sysfs_remove_link(&dev->kobj, "driver");
2831 static struct device *ehea_register_port(struct ehea_port *port,
2832 struct device_node *dn)
2836 port->ofdev.node = of_node_get(dn);
2837 port->ofdev.dev.parent = &port->adapter->ebus_dev->ofdev.dev;
2838 port->ofdev.dev.bus = &ibmebus_bus_type;
2840 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
2841 port->ofdev.dev.release = logical_port_release;
2843 ret = of_device_register(&port->ofdev);
2845 ehea_error("failed to register device. ret=%d", ret);
2849 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
2851 ehea_error("failed to register attributes, ret=%d", ret);
2852 goto out_unreg_of_dev;
2855 ret = ehea_driver_sysfs_add(&port->ofdev.dev, &ehea_driver.driver);
2857 ehea_error("failed to register sysfs driver link");
2858 goto out_rem_dev_file;
2861 return &port->ofdev.dev;
2864 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2866 of_device_unregister(&port->ofdev);
2871 static void ehea_unregister_port(struct ehea_port *port)
2873 ehea_driver_sysfs_remove(&port->ofdev.dev, &ehea_driver.driver);
2874 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2875 of_device_unregister(&port->ofdev);
2878 struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
2879 u32 logical_port_id,
2880 struct device_node *dn)
2883 struct net_device *dev;
2884 struct ehea_port *port;
2885 struct device *port_dev;
2888 /* allocate memory for the port structures */
2889 dev = alloc_etherdev(sizeof(struct ehea_port));
2892 ehea_error("no mem for net_device");
2897 port = netdev_priv(dev);
2899 sema_init(&port->port_lock, 1);
2900 port->state = EHEA_PORT_DOWN;
2901 port->sig_comp_iv = sq_entries / 10;
2903 port->adapter = adapter;
2905 port->logical_port_id = logical_port_id;
2907 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
2909 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
2910 if (!port->mc_list) {
2912 goto out_free_ethdev;
2915 INIT_LIST_HEAD(&port->mc_list->list);
2917 ret = ehea_sense_port_attr(port);
2919 goto out_free_mc_list;
2921 port_dev = ehea_register_port(port, dn);
2923 goto out_free_mc_list;
2925 SET_NETDEV_DEV(dev, port_dev);
2927 /* initialize net_device structure */
2928 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
2930 dev->open = ehea_open;
2931 #ifdef CONFIG_NET_POLL_CONTROLLER
2932 dev->poll_controller = ehea_netpoll;
2934 dev->stop = ehea_stop;
2935 dev->hard_start_xmit = ehea_start_xmit;
2936 dev->get_stats = ehea_get_stats;
2937 dev->set_multicast_list = ehea_set_multicast_list;
2938 dev->set_mac_address = ehea_set_mac_addr;
2939 dev->change_mtu = ehea_change_mtu;
2940 dev->vlan_rx_register = ehea_vlan_rx_register;
2941 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
2942 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
2943 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
2944 | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX
2945 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
2947 dev->tx_timeout = &ehea_tx_watchdog;
2948 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
2950 INIT_WORK(&port->reset_task, ehea_reset_port);
2952 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2955 goto out_unreg_port;
2958 ehea_set_ethtool_ops(dev);
2960 ret = register_netdev(dev);
2962 ehea_error("register_netdev failed. ret=%d", ret);
2966 port->lro_max_aggr = lro_max_aggr;
2968 ret = ehea_get_jumboframe_status(port, &jumbo);
2970 ehea_error("failed determining jumbo frame status for %s",
2971 port->netdev->name);
2973 ehea_info("%s: Jumbo frames are %sabled", dev->name,
2974 jumbo == 1 ? "en" : "dis");
2976 adapter->active_ports++;
2981 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2984 ehea_unregister_port(port);
2987 kfree(port->mc_list);
2993 ehea_error("setting up logical port with id=%d failed, ret=%d",
2994 logical_port_id, ret);
2998 static void ehea_shutdown_single_port(struct ehea_port *port)
3000 unregister_netdev(port->netdev);
3001 ehea_unregister_port(port);
3002 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
3003 kfree(port->mc_list);
3004 free_netdev(port->netdev);
3005 port->adapter->active_ports--;
3008 static int ehea_setup_ports(struct ehea_adapter *adapter)
3010 struct device_node *lhea_dn;
3011 struct device_node *eth_dn = NULL;
3013 const u32 *dn_log_port_id;
3016 lhea_dn = adapter->ebus_dev->ofdev.node;
3017 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
3019 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
3021 if (!dn_log_port_id) {
3022 ehea_error("bad device node: eth_dn name=%s",
3027 if (ehea_add_adapter_mr(adapter)) {
3028 ehea_error("creating MR failed");
3029 of_node_put(eth_dn);
3033 adapter->port[i] = ehea_setup_single_port(adapter,
3036 if (adapter->port[i])
3037 ehea_info("%s -> logical port id #%d",
3038 adapter->port[i]->netdev->name,
3041 ehea_remove_adapter_mr(adapter);
3049 static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3050 u32 logical_port_id)
3052 struct device_node *lhea_dn;
3053 struct device_node *eth_dn = NULL;
3054 const u32 *dn_log_port_id;
3056 lhea_dn = adapter->ebus_dev->ofdev.node;
3057 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
3059 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
3062 if (*dn_log_port_id == logical_port_id)
3069 static ssize_t ehea_probe_port(struct device *dev,
3070 struct device_attribute *attr,
3071 const char *buf, size_t count)
3073 struct ehea_adapter *adapter = dev->driver_data;
3074 struct ehea_port *port;
3075 struct device_node *eth_dn = NULL;
3078 u32 logical_port_id;
3080 sscanf(buf, "%d", &logical_port_id);
3082 port = ehea_get_port(adapter, logical_port_id);
3085 ehea_info("adding port with logical port id=%d failed. port "
3086 "already configured as %s.", logical_port_id,
3087 port->netdev->name);
3091 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3094 ehea_info("no logical port with id %d found", logical_port_id);
3098 if (ehea_add_adapter_mr(adapter)) {
3099 ehea_error("creating MR failed");
3103 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3105 of_node_put(eth_dn);
3108 for (i=0; i < EHEA_MAX_PORTS; i++)
3109 if (!adapter->port[i]) {
3110 adapter->port[i] = port;
3114 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3117 ehea_remove_adapter_mr(adapter);
3121 return (ssize_t) count;
3124 static ssize_t ehea_remove_port(struct device *dev,
3125 struct device_attribute *attr,
3126 const char *buf, size_t count)
3128 struct ehea_adapter *adapter = dev->driver_data;
3129 struct ehea_port *port;
3131 u32 logical_port_id;
3133 sscanf(buf, "%d", &logical_port_id);
3135 port = ehea_get_port(adapter, logical_port_id);
3138 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3141 ehea_shutdown_single_port(port);
3143 for (i=0; i < EHEA_MAX_PORTS; i++)
3144 if (adapter->port[i] == port) {
3145 adapter->port[i] = NULL;
3149 ehea_error("removing port with logical port id=%d failed. port "
3150 "not configured.", logical_port_id);
3154 ehea_remove_adapter_mr(adapter);
3156 return (ssize_t) count;
3159 static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3160 static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3162 int ehea_create_device_sysfs(struct ibmebus_dev *dev)
3164 int ret = device_create_file(&dev->ofdev.dev, &dev_attr_probe_port);
3168 ret = device_create_file(&dev->ofdev.dev, &dev_attr_remove_port);
3173 void ehea_remove_device_sysfs(struct ibmebus_dev *dev)
3175 device_remove_file(&dev->ofdev.dev, &dev_attr_probe_port);
3176 device_remove_file(&dev->ofdev.dev, &dev_attr_remove_port);
3179 static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev,
3180 const struct of_device_id *id)
3182 struct ehea_adapter *adapter;
3183 const u64 *adapter_handle;
3186 if (!dev || !dev->ofdev.node) {
3187 ehea_error("Invalid ibmebus device probed");
3191 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3194 dev_err(&dev->ofdev.dev, "no mem for ehea_adapter\n");
3198 list_add(&adapter->list, &adapter_list);
3200 adapter->ebus_dev = dev;
3202 adapter_handle = of_get_property(dev->ofdev.node, "ibm,hea-handle",
3205 adapter->handle = *adapter_handle;
3207 if (!adapter->handle) {
3208 dev_err(&dev->ofdev.dev, "failed getting handle for adapter"
3209 " '%s'\n", dev->ofdev.node->full_name);
3214 adapter->pd = EHEA_PD_ID;
3216 dev->ofdev.dev.driver_data = adapter;
3219 /* initialize adapter and ports */
3220 /* get adapter properties */
3221 ret = ehea_sense_adapter_attr(adapter);
3223 dev_err(&dev->ofdev.dev, "sense_adapter_attr failed: %d", ret);
3227 adapter->neq = ehea_create_eq(adapter,
3228 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3229 if (!adapter->neq) {
3231 dev_err(&dev->ofdev.dev, "NEQ creation failed");
3235 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3236 (unsigned long)adapter);
3238 ret = ibmebus_request_irq(NULL, adapter->neq->attr.ist1,
3239 ehea_interrupt_neq, IRQF_DISABLED,
3240 "ehea_neq", adapter);
3242 dev_err(&dev->ofdev.dev, "requesting NEQ IRQ failed");
3246 adapter->ehea_wq = create_workqueue("ehea_wq");
3247 if (!adapter->ehea_wq) {
3252 ret = ehea_create_device_sysfs(dev);
3256 ret = ehea_setup_ports(adapter);
3258 dev_err(&dev->ofdev.dev, "setup_ports failed");
3259 goto out_rem_dev_sysfs;
3266 ehea_remove_device_sysfs(dev);
3269 destroy_workqueue(adapter->ehea_wq);
3272 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
3275 ehea_destroy_eq(adapter->neq);
3283 static int __devexit ehea_remove(struct ibmebus_dev *dev)
3285 struct ehea_adapter *adapter = dev->ofdev.dev.driver_data;
3288 for (i = 0; i < EHEA_MAX_PORTS; i++)
3289 if (adapter->port[i]) {
3290 ehea_shutdown_single_port(adapter->port[i]);
3291 adapter->port[i] = NULL;
3294 ehea_remove_device_sysfs(dev);
3296 destroy_workqueue(adapter->ehea_wq);
3298 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
3299 tasklet_kill(&adapter->neq_tasklet);
3301 ehea_destroy_eq(adapter->neq);
3302 ehea_remove_adapter_mr(adapter);
3303 list_del(&adapter->list);
3310 static int check_module_parm(void)
3314 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3315 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3316 ehea_info("Bad parameter: rq1_entries");
3319 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3320 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3321 ehea_info("Bad parameter: rq2_entries");
3324 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3325 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3326 ehea_info("Bad parameter: rq3_entries");
3329 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3330 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3331 ehea_info("Bad parameter: sq_entries");
3338 static ssize_t ehea_show_capabilities(struct device_driver *drv,
3341 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3344 static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3345 ehea_show_capabilities, NULL);
3347 int __init ehea_module_init(void)
3351 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3354 ehea_driver_wq = create_workqueue("ehea_driver_wq");
3356 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
3357 sema_init(&dlpar_mem_lock, 1);
3359 ret = check_module_parm();
3363 ret = ehea_create_busmap();
3367 ret = ibmebus_register_driver(&ehea_driver);
3369 ehea_error("failed registering eHEA device driver on ebus");
3373 ret = driver_create_file(&ehea_driver.driver,
3374 &driver_attr_capabilities);
3376 ehea_error("failed to register capabilities attribute, ret=%d",
3378 ibmebus_unregister_driver(&ehea_driver);
3386 static void __exit ehea_module_exit(void)
3388 destroy_workqueue(ehea_driver_wq);
3389 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
3390 ibmebus_unregister_driver(&ehea_driver);
3391 ehea_destroy_busmap();
3394 module_init(ehea_module_init);
3395 module_exit(ehea_module_exit);