Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/net/ehea/ehea_main.c |
| 3 | * |
| 4 | * eHEA ethernet device driver for IBM eServer System p |
| 5 | * |
| 6 | * (C) Copyright IBM Corp. 2006 |
| 7 | * |
| 8 | * Authors: |
| 9 | * Christoph Raisch <raisch@de.ibm.com> |
| 10 | * Jan-Bernd Themann <themann@de.ibm.com> |
| 11 | * Thomas Klein <tklein@de.ibm.com> |
| 12 | * |
| 13 | * |
| 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) |
| 17 | * any later version. |
| 18 | * |
| 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. |
| 23 | * |
| 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. |
| 27 | */ |
| 28 | |
| 29 | #include <linux/in.h> |
| 30 | #include <linux/ip.h> |
| 31 | #include <linux/tcp.h> |
| 32 | #include <linux/udp.h> |
| 33 | #include <linux/if.h> |
| 34 | #include <linux/list.h> |
| 35 | #include <linux/if_ether.h> |
| 36 | #include <net/ip.h> |
| 37 | |
| 38 | #include "ehea.h" |
| 39 | #include "ehea_qmr.h" |
| 40 | #include "ehea_phyp.h" |
| 41 | |
| 42 | |
| 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); |
| 47 | |
| 48 | |
| 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; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 54 | static int use_mcs = 0; |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 55 | static int use_lro = 0; |
| 56 | static int lro_max_aggr = EHEA_LRO_MAX_AGGR; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 57 | static int num_tx_qps = EHEA_NUM_TX_QP; |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 58 | static int prop_carrier_state = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 59 | |
| 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); |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 65 | module_param(prop_carrier_state, int, 0); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 66 | module_param(use_mcs, int, 0); |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 67 | module_param(use_lro, int, 0); |
| 68 | module_param(lro_max_aggr, int, 0); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 69 | module_param(num_tx_qps, int, 0); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 70 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 71 | MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 72 | MODULE_PARM_DESC(msg_level, "msg_level"); |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 73 | MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical " |
| 74 | "port to stack. 1:yes, 0:no. Default = 0 "); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 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) ")"); |
Jan-Bernd Themann | 18072a5 | 2007-08-22 16:21:24 +0200 | [diff] [blame] | 87 | MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 "); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 88 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 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, " |
| 92 | "Default = 0"); |
| 93 | |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 94 | static int port_name_cnt = 0; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 95 | static LIST_HEAD(adapter_list); |
| 96 | u64 ehea_driver_flags = 0; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 97 | struct work_struct ehea_rereg_mr_task; |
| 98 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 99 | struct semaphore dlpar_mem_lock; |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 100 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 101 | static int __devinit ehea_probe_adapter(struct of_device *dev, |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 102 | const struct of_device_id *id); |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 103 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 104 | static int __devexit ehea_remove(struct of_device *dev); |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 105 | |
| 106 | static struct of_device_id ehea_device_table[] = { |
| 107 | { |
| 108 | .name = "lhea", |
| 109 | .compatible = "IBM,lhea", |
| 110 | }, |
| 111 | {}, |
| 112 | }; |
| 113 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 114 | static struct of_platform_driver ehea_driver = { |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 115 | .name = "ehea", |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 116 | .match_table = ehea_device_table, |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 117 | .probe = ehea_probe_adapter, |
| 118 | .remove = ehea_remove, |
| 119 | }; |
| 120 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 121 | void ehea_dump(void *adr, int len, char *msg) { |
| 122 | int x; |
| 123 | unsigned char *deb = adr; |
| 124 | for (x = 0; x < len; x += 16) { |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 125 | printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 126 | deb, x, *((u64*)&deb[0]), *((u64*)&deb[8])); |
| 127 | deb += 16; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static struct net_device_stats *ehea_get_stats(struct net_device *dev) |
| 132 | { |
| 133 | struct ehea_port *port = netdev_priv(dev); |
| 134 | struct net_device_stats *stats = &port->stats; |
| 135 | struct hcp_ehea_port_cb2 *cb2; |
| 136 | u64 hret, rx_packets; |
| 137 | int i; |
| 138 | |
| 139 | memset(stats, 0, sizeof(*stats)); |
| 140 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 141 | cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 142 | if (!cb2) { |
| 143 | ehea_error("no mem for cb2"); |
| 144 | goto out; |
| 145 | } |
| 146 | |
| 147 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
| 148 | port->logical_port_id, |
| 149 | H_PORT_CB2, H_PORT_CB2_ALL, cb2); |
| 150 | if (hret != H_SUCCESS) { |
| 151 | ehea_error("query_ehea_port failed"); |
| 152 | goto out_herr; |
| 153 | } |
| 154 | |
| 155 | if (netif_msg_hw(port)) |
| 156 | ehea_dump(cb2, sizeof(*cb2), "net_device_stats"); |
| 157 | |
| 158 | rx_packets = 0; |
| 159 | for (i = 0; i < port->num_def_qps; i++) |
| 160 | rx_packets += port->port_res[i].rx_packets; |
| 161 | |
| 162 | stats->tx_packets = cb2->txucp + cb2->txmcp + cb2->txbcp; |
| 163 | stats->multicast = cb2->rxmcp; |
| 164 | stats->rx_errors = cb2->rxuerr; |
| 165 | stats->rx_bytes = cb2->rxo; |
| 166 | stats->tx_bytes = cb2->txo; |
| 167 | stats->rx_packets = rx_packets; |
| 168 | |
| 169 | out_herr: |
| 170 | kfree(cb2); |
| 171 | out: |
| 172 | return stats; |
| 173 | } |
| 174 | |
| 175 | static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes) |
| 176 | { |
| 177 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; |
| 178 | struct net_device *dev = pr->port->netdev; |
| 179 | int max_index_mask = pr->rq1_skba.len - 1; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 180 | int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes; |
| 181 | int adder = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 182 | int i; |
| 183 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 184 | pr->rq1_skba.os_skbs = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 185 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 186 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { |
| 187 | pr->rq1_skba.index = index; |
| 188 | pr->rq1_skba.os_skbs = fill_wqes; |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | for (i = 0; i < fill_wqes; i++) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 193 | if (!skb_arr_rq1[index]) { |
| 194 | skb_arr_rq1[index] = netdev_alloc_skb(dev, |
| 195 | EHEA_L_PKT_SIZE); |
| 196 | if (!skb_arr_rq1[index]) { |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 197 | pr->rq1_skba.os_skbs = fill_wqes - i; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 198 | ehea_error("%s: no mem for skb/%d wqes filled", |
| 199 | dev->name, i); |
| 200 | break; |
| 201 | } |
| 202 | } |
| 203 | index--; |
| 204 | index &= max_index_mask; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 205 | adder++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 206 | } |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 207 | |
| 208 | if (adder == 0) |
| 209 | return; |
| 210 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 211 | /* Ring doorbell */ |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 212 | ehea_update_rq1a(pr->qp, adder); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a) |
| 216 | { |
| 217 | int ret = 0; |
| 218 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; |
| 219 | struct net_device *dev = pr->port->netdev; |
| 220 | int i; |
| 221 | |
| 222 | for (i = 0; i < pr->rq1_skba.len; i++) { |
| 223 | skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE); |
| 224 | if (!skb_arr_rq1[i]) { |
| 225 | ehea_error("%s: no mem for skb/%d wqes filled", |
| 226 | dev->name, i); |
| 227 | ret = -ENOMEM; |
| 228 | goto out; |
| 229 | } |
| 230 | } |
| 231 | /* Ring doorbell */ |
| 232 | ehea_update_rq1a(pr->qp, nr_rq1a); |
| 233 | out: |
| 234 | return ret; |
| 235 | } |
| 236 | |
| 237 | static int ehea_refill_rq_def(struct ehea_port_res *pr, |
| 238 | struct ehea_q_skb_arr *q_skba, int rq_nr, |
| 239 | int num_wqes, int wqe_type, int packet_size) |
| 240 | { |
| 241 | struct net_device *dev = pr->port->netdev; |
| 242 | struct ehea_qp *qp = pr->qp; |
| 243 | struct sk_buff **skb_arr = q_skba->arr; |
| 244 | struct ehea_rwqe *rwqe; |
| 245 | int i, index, max_index_mask, fill_wqes; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 246 | int adder = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 247 | int ret = 0; |
| 248 | |
| 249 | fill_wqes = q_skba->os_skbs + num_wqes; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 250 | q_skba->os_skbs = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 251 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 252 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { |
| 253 | q_skba->os_skbs = fill_wqes; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 254 | return ret; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 255 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 256 | |
| 257 | index = q_skba->index; |
| 258 | max_index_mask = q_skba->len - 1; |
| 259 | for (i = 0; i < fill_wqes; i++) { |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 260 | u64 tmp_addr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 261 | struct sk_buff *skb = netdev_alloc_skb(dev, packet_size); |
| 262 | if (!skb) { |
| 263 | ehea_error("%s: no mem for skb/%d wqes filled", |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 264 | pr->port->netdev->name, i); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 265 | q_skba->os_skbs = fill_wqes - i; |
| 266 | ret = -ENOMEM; |
| 267 | break; |
| 268 | } |
| 269 | skb_reserve(skb, NET_IP_ALIGN); |
| 270 | |
| 271 | skb_arr[index] = skb; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 272 | tmp_addr = ehea_map_vaddr(skb->data); |
| 273 | if (tmp_addr == -1) { |
| 274 | dev_kfree_skb(skb); |
| 275 | q_skba->os_skbs = fill_wqes - i; |
| 276 | ret = 0; |
| 277 | break; |
| 278 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 279 | |
| 280 | rwqe = ehea_get_next_rwqe(qp, rq_nr); |
| 281 | rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type) |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 282 | | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 283 | rwqe->sg_list[0].l_key = pr->recv_mr.lkey; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 284 | rwqe->sg_list[0].vaddr = tmp_addr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 285 | rwqe->sg_list[0].len = packet_size; |
| 286 | rwqe->data_segments = 1; |
| 287 | |
| 288 | index++; |
| 289 | index &= max_index_mask; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 290 | adder++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 291 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 292 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 293 | q_skba->index = index; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 294 | if (adder == 0) |
| 295 | goto out; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 296 | |
| 297 | /* Ring doorbell */ |
| 298 | iosync(); |
| 299 | if (rq_nr == 2) |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 300 | ehea_update_rq2a(pr->qp, adder); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 301 | else |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 302 | ehea_update_rq3a(pr->qp, adder); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 303 | out: |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes) |
| 309 | { |
| 310 | return ehea_refill_rq_def(pr, &pr->rq2_skba, 2, |
| 311 | nr_of_wqes, EHEA_RWQE2_TYPE, |
| 312 | EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN); |
| 313 | } |
| 314 | |
| 315 | |
| 316 | static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes) |
| 317 | { |
| 318 | return ehea_refill_rq_def(pr, &pr->rq3_skba, 3, |
| 319 | nr_of_wqes, EHEA_RWQE3_TYPE, |
| 320 | EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN); |
| 321 | } |
| 322 | |
| 323 | static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num) |
| 324 | { |
| 325 | *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5; |
| 326 | if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0) |
| 327 | return 0; |
| 328 | if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) && |
| 329 | (cqe->header_length == 0)) |
| 330 | return 0; |
| 331 | return -EINVAL; |
| 332 | } |
| 333 | |
| 334 | static inline void ehea_fill_skb(struct net_device *dev, |
| 335 | struct sk_buff *skb, struct ehea_cqe *cqe) |
| 336 | { |
| 337 | int length = cqe->num_bytes_transfered - 4; /*remove CRC */ |
| 338 | |
| 339 | skb_put(skb, length); |
| 340 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 341 | skb->protocol = eth_type_trans(skb, dev); |
| 342 | } |
| 343 | |
| 344 | static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array, |
| 345 | int arr_len, |
| 346 | struct ehea_cqe *cqe) |
| 347 | { |
| 348 | int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id); |
| 349 | struct sk_buff *skb; |
| 350 | void *pref; |
| 351 | int x; |
| 352 | |
| 353 | x = skb_index + 1; |
| 354 | x &= (arr_len - 1); |
| 355 | |
| 356 | pref = skb_array[x]; |
| 357 | prefetchw(pref); |
| 358 | prefetchw(pref + EHEA_CACHE_LINE); |
| 359 | |
| 360 | pref = (skb_array[x]->data); |
| 361 | prefetch(pref); |
| 362 | prefetch(pref + EHEA_CACHE_LINE); |
| 363 | prefetch(pref + EHEA_CACHE_LINE * 2); |
| 364 | prefetch(pref + EHEA_CACHE_LINE * 3); |
| 365 | skb = skb_array[skb_index]; |
| 366 | skb_array[skb_index] = NULL; |
| 367 | return skb; |
| 368 | } |
| 369 | |
| 370 | static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array, |
| 371 | int arr_len, int wqe_index) |
| 372 | { |
| 373 | struct sk_buff *skb; |
| 374 | void *pref; |
| 375 | int x; |
| 376 | |
| 377 | x = wqe_index + 1; |
| 378 | x &= (arr_len - 1); |
| 379 | |
| 380 | pref = skb_array[x]; |
| 381 | prefetchw(pref); |
| 382 | prefetchw(pref + EHEA_CACHE_LINE); |
| 383 | |
| 384 | pref = (skb_array[x]->data); |
| 385 | prefetchw(pref); |
| 386 | prefetchw(pref + EHEA_CACHE_LINE); |
| 387 | |
| 388 | skb = skb_array[wqe_index]; |
| 389 | skb_array[wqe_index] = NULL; |
| 390 | return skb; |
| 391 | } |
| 392 | |
| 393 | static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq, |
| 394 | struct ehea_cqe *cqe, int *processed_rq2, |
| 395 | int *processed_rq3) |
| 396 | { |
| 397 | struct sk_buff *skb; |
| 398 | |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 399 | if (cqe->status & EHEA_CQE_STAT_ERR_TCP) |
| 400 | pr->p_stats.err_tcp_cksum++; |
| 401 | if (cqe->status & EHEA_CQE_STAT_ERR_IP) |
| 402 | pr->p_stats.err_ip_cksum++; |
| 403 | if (cqe->status & EHEA_CQE_STAT_ERR_CRC) |
| 404 | pr->p_stats.err_frame_crc++; |
| 405 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 406 | if (netif_msg_rx_err(pr->port)) { |
| 407 | ehea_error("CQE Error for QP %d", pr->qp->init_attr.qp_nr); |
| 408 | ehea_dump(cqe, sizeof(*cqe), "CQE"); |
| 409 | } |
| 410 | |
| 411 | if (rq == 2) { |
| 412 | *processed_rq2 += 1; |
| 413 | skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe); |
| 414 | dev_kfree_skb(skb); |
| 415 | } else if (rq == 3) { |
| 416 | *processed_rq3 += 1; |
| 417 | skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe); |
| 418 | dev_kfree_skb(skb); |
| 419 | } |
| 420 | |
| 421 | if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) { |
| 422 | ehea_error("Critical receive error. Resetting port."); |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 423 | schedule_work(&pr->port->reset_task); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 424 | return 1; |
| 425 | } |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 430 | static int get_skb_hdr(struct sk_buff *skb, void **iphdr, |
| 431 | void **tcph, u64 *hdr_flags, void *priv) |
| 432 | { |
| 433 | struct ehea_cqe *cqe = priv; |
| 434 | unsigned int ip_len; |
| 435 | struct iphdr *iph; |
| 436 | |
| 437 | /* non tcp/udp packets */ |
| 438 | if (!cqe->header_length) |
| 439 | return -1; |
| 440 | |
| 441 | /* non tcp packet */ |
| 442 | skb_reset_network_header(skb); |
| 443 | iph = ip_hdr(skb); |
| 444 | if (iph->protocol != IPPROTO_TCP) |
| 445 | return -1; |
| 446 | |
| 447 | ip_len = ip_hdrlen(skb); |
| 448 | skb_set_transport_header(skb, ip_len); |
| 449 | *tcph = tcp_hdr(skb); |
| 450 | |
| 451 | /* check if ip header and tcp header are complete */ |
| 452 | if (iph->tot_len < ip_len + tcp_hdrlen(skb)) |
| 453 | return -1; |
| 454 | |
| 455 | *hdr_flags = LRO_IPV4 | LRO_TCP; |
| 456 | *iphdr = iph; |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe, |
| 462 | struct sk_buff *skb) |
| 463 | { |
| 464 | int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) |
| 465 | && pr->port->vgrp; |
| 466 | |
| 467 | if (use_lro) { |
| 468 | if (vlan_extracted) |
| 469 | lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb, |
| 470 | pr->port->vgrp, |
| 471 | cqe->vlan_tag, |
| 472 | cqe); |
| 473 | else |
| 474 | lro_receive_skb(&pr->lro_mgr, skb, cqe); |
| 475 | } else { |
| 476 | if (vlan_extracted) |
| 477 | vlan_hwaccel_receive_skb(skb, pr->port->vgrp, |
| 478 | cqe->vlan_tag); |
| 479 | else |
| 480 | netif_receive_skb(skb); |
| 481 | } |
| 482 | } |
| 483 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 484 | static int ehea_proc_rwqes(struct net_device *dev, |
| 485 | struct ehea_port_res *pr, |
| 486 | int budget) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 487 | { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 488 | struct ehea_port *port = pr->port; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 489 | struct ehea_qp *qp = pr->qp; |
| 490 | struct ehea_cqe *cqe; |
| 491 | struct sk_buff *skb; |
| 492 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; |
| 493 | struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr; |
| 494 | struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr; |
| 495 | int skb_arr_rq1_len = pr->rq1_skba.len; |
| 496 | int skb_arr_rq2_len = pr->rq2_skba.len; |
| 497 | int skb_arr_rq3_len = pr->rq3_skba.len; |
| 498 | int processed, processed_rq1, processed_rq2, processed_rq3; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 499 | int wqe_index, last_wqe_index, rq, port_reset; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 500 | |
| 501 | processed = processed_rq1 = processed_rq2 = processed_rq3 = 0; |
| 502 | last_wqe_index = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 503 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 504 | cqe = ehea_poll_rq1(qp, &wqe_index); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 505 | while ((processed < budget) && cqe) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 506 | ehea_inc_rq1(qp); |
| 507 | processed_rq1++; |
| 508 | processed++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 509 | if (netif_msg_rx_status(port)) |
| 510 | ehea_dump(cqe, sizeof(*cqe), "CQE"); |
| 511 | |
| 512 | last_wqe_index = wqe_index; |
| 513 | rmb(); |
| 514 | if (!ehea_check_cqe(cqe, &rq)) { |
| 515 | if (rq == 1) { /* LL RQ1 */ |
| 516 | skb = get_skb_by_index_ll(skb_arr_rq1, |
| 517 | skb_arr_rq1_len, |
| 518 | wqe_index); |
| 519 | if (unlikely(!skb)) { |
| 520 | if (netif_msg_rx_err(port)) |
| 521 | ehea_error("LL rq1: skb=NULL"); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 522 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 523 | skb = netdev_alloc_skb(dev, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 524 | EHEA_L_PKT_SIZE); |
| 525 | if (!skb) |
| 526 | break; |
| 527 | } |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 528 | skb_copy_to_linear_data(skb, ((char*)cqe) + 64, |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 529 | cqe->num_bytes_transfered - 4); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 530 | ehea_fill_skb(dev, skb, cqe); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 531 | } else if (rq == 2) { /* RQ2 */ |
| 532 | skb = get_skb_by_index(skb_arr_rq2, |
| 533 | skb_arr_rq2_len, cqe); |
| 534 | if (unlikely(!skb)) { |
| 535 | if (netif_msg_rx_err(port)) |
| 536 | ehea_error("rq2: skb=NULL"); |
| 537 | break; |
| 538 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 539 | ehea_fill_skb(dev, skb, cqe); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 540 | processed_rq2++; |
| 541 | } else { /* RQ3 */ |
| 542 | skb = get_skb_by_index(skb_arr_rq3, |
| 543 | skb_arr_rq3_len, cqe); |
| 544 | if (unlikely(!skb)) { |
| 545 | if (netif_msg_rx_err(port)) |
| 546 | ehea_error("rq3: skb=NULL"); |
| 547 | break; |
| 548 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 549 | ehea_fill_skb(dev, skb, cqe); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 550 | processed_rq3++; |
| 551 | } |
| 552 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 553 | ehea_proc_skb(pr, cqe, skb); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 554 | dev->last_rx = jiffies; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 555 | } else { |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 556 | pr->p_stats.poll_receive_errors++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 557 | port_reset = ehea_treat_poll_error(pr, rq, cqe, |
| 558 | &processed_rq2, |
| 559 | &processed_rq3); |
| 560 | if (port_reset) |
| 561 | break; |
| 562 | } |
| 563 | cqe = ehea_poll_rq1(qp, &wqe_index); |
| 564 | } |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 565 | if (use_lro) |
| 566 | lro_flush_all(&pr->lro_mgr); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 567 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 568 | pr->rx_packets += processed; |
| 569 | |
| 570 | ehea_refill_rq1(pr, last_wqe_index, processed_rq1); |
| 571 | ehea_refill_rq2(pr, processed_rq2); |
| 572 | ehea_refill_rq3(pr, processed_rq3); |
| 573 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 574 | return processed; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 577 | static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 578 | { |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 579 | struct sk_buff *skb; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 580 | struct ehea_cq *send_cq = pr->send_cq; |
| 581 | struct ehea_cqe *cqe; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 582 | int quota = my_quota; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 583 | int cqe_counter = 0; |
| 584 | int swqe_av = 0; |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 585 | int index; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 586 | unsigned long flags; |
| 587 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 588 | cqe = ehea_poll_cq(send_cq); |
| 589 | while(cqe && (quota > 0)) { |
| 590 | ehea_inc_cq(send_cq); |
| 591 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 592 | cqe_counter++; |
| 593 | rmb(); |
| 594 | if (cqe->status & EHEA_CQE_STAT_ERR_MASK) { |
| 595 | ehea_error("Send Completion Error: Resetting port"); |
| 596 | if (netif_msg_tx_err(pr->port)) |
| 597 | ehea_dump(cqe, sizeof(*cqe), "Send CQE"); |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 598 | schedule_work(&pr->port->reset_task); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 599 | break; |
| 600 | } |
| 601 | |
| 602 | if (netif_msg_tx_done(pr->port)) |
| 603 | ehea_dump(cqe, sizeof(*cqe), "CQE"); |
| 604 | |
| 605 | if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id) |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 606 | == EHEA_SWQE2_TYPE)) { |
| 607 | |
| 608 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id); |
| 609 | skb = pr->sq_skba.arr[index]; |
| 610 | dev_kfree_skb(skb); |
| 611 | pr->sq_skba.arr[index] = NULL; |
| 612 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 613 | |
| 614 | swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id); |
| 615 | quota--; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 616 | |
| 617 | cqe = ehea_poll_cq(send_cq); |
| 618 | }; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 619 | |
| 620 | ehea_update_feca(send_cq, cqe_counter); |
| 621 | atomic_add(swqe_av, &pr->swqe_avail); |
| 622 | |
| 623 | spin_lock_irqsave(&pr->netif_queue, flags); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 624 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 625 | if (pr->queue_stopped && (atomic_read(&pr->swqe_avail) |
| 626 | >= pr->swqe_refill_th)) { |
| 627 | netif_wake_queue(pr->port->netdev); |
| 628 | pr->queue_stopped = 0; |
| 629 | } |
| 630 | spin_unlock_irqrestore(&pr->netif_queue, flags); |
| 631 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 632 | return cqe; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 635 | #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16 |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 636 | #define EHEA_POLL_MAX_CQES 65535 |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 637 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 638 | static int ehea_poll(struct napi_struct *napi, int budget) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 639 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 640 | struct ehea_port_res *pr = container_of(napi, struct ehea_port_res, napi); |
| 641 | struct net_device *dev = pr->port->netdev; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 642 | struct ehea_cqe *cqe; |
| 643 | struct ehea_cqe *cqe_skb = NULL; |
| 644 | int force_irq, wqe_index; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 645 | int rx = 0; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 646 | |
| 647 | force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 648 | cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 649 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 650 | if (!force_irq) |
| 651 | rx += ehea_proc_rwqes(dev, pr, budget - rx); |
| 652 | |
| 653 | while ((rx != budget) || force_irq) { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 654 | pr->poll_counter = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 655 | force_irq = 0; |
| 656 | netif_rx_complete(dev, napi); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 657 | ehea_reset_cq_ep(pr->recv_cq); |
| 658 | ehea_reset_cq_ep(pr->send_cq); |
| 659 | ehea_reset_cq_n1(pr->recv_cq); |
| 660 | ehea_reset_cq_n1(pr->send_cq); |
| 661 | cqe = ehea_poll_rq1(pr->qp, &wqe_index); |
| 662 | cqe_skb = ehea_poll_cq(pr->send_cq); |
| 663 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 664 | if (!cqe && !cqe_skb) |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 665 | return rx; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 666 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 667 | if (!netif_rx_reschedule(dev, napi)) |
| 668 | return rx; |
| 669 | |
| 670 | cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES); |
| 671 | rx += ehea_proc_rwqes(dev, pr, budget - rx); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 672 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 673 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 674 | pr->poll_counter++; |
| 675 | return rx; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 676 | } |
| 677 | |
Jan-Bernd Themann | 8d22c97 | 2007-07-23 16:05:03 +0200 | [diff] [blame] | 678 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 679 | static void ehea_netpoll(struct net_device *dev) |
| 680 | { |
| 681 | struct ehea_port *port = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 682 | int i; |
Jan-Bernd Themann | 8d22c97 | 2007-07-23 16:05:03 +0200 | [diff] [blame] | 683 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 684 | for (i = 0; i < port->num_def_qps; i++) |
| 685 | netif_rx_schedule(dev, &port->port_res[i].napi); |
Jan-Bernd Themann | 8d22c97 | 2007-07-23 16:05:03 +0200 | [diff] [blame] | 686 | } |
| 687 | #endif |
| 688 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 689 | static irqreturn_t ehea_recv_irq_handler(int irq, void *param) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 690 | { |
| 691 | struct ehea_port_res *pr = param; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 692 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 693 | netif_rx_schedule(pr->port->netdev, &pr->napi); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 694 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 695 | return IRQ_HANDLED; |
| 696 | } |
| 697 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 698 | static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 699 | { |
| 700 | struct ehea_port *port = param; |
| 701 | struct ehea_eqe *eqe; |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 702 | struct ehea_qp *qp; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 703 | u32 qp_token; |
| 704 | |
| 705 | eqe = ehea_poll_eq(port->qp_eq); |
Thomas Klein | bb3a644 | 2007-01-22 12:54:50 +0100 | [diff] [blame] | 706 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 707 | while (eqe) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 708 | qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry); |
Thomas Klein | bb3a644 | 2007-01-22 12:54:50 +0100 | [diff] [blame] | 709 | ehea_error("QP aff_err: entry=0x%lx, token=0x%x", |
| 710 | eqe->entry, qp_token); |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 711 | |
| 712 | qp = port->port_res[qp_token].qp; |
| 713 | ehea_error_data(port->adapter, qp->fw_handle); |
Thomas Klein | bb3a644 | 2007-01-22 12:54:50 +0100 | [diff] [blame] | 714 | eqe = ehea_poll_eq(port->qp_eq); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 715 | } |
| 716 | |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 717 | schedule_work(&port->reset_task); |
Jan-Bernd Themann | d2db9ee | 2007-02-09 09:10:51 +0100 | [diff] [blame] | 718 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 719 | return IRQ_HANDLED; |
| 720 | } |
| 721 | |
| 722 | static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter, |
| 723 | int logical_port) |
| 724 | { |
| 725 | int i; |
| 726 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 727 | for (i = 0; i < EHEA_MAX_PORTS; i++) |
Thomas Klein | 41b69c7 | 2007-01-22 12:55:20 +0100 | [diff] [blame] | 728 | if (adapter->port[i]) |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 729 | if (adapter->port[i]->logical_port_id == logical_port) |
Thomas Klein | 41b69c7 | 2007-01-22 12:55:20 +0100 | [diff] [blame] | 730 | return adapter->port[i]; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 731 | return NULL; |
| 732 | } |
| 733 | |
| 734 | int ehea_sense_port_attr(struct ehea_port *port) |
| 735 | { |
| 736 | int ret; |
| 737 | u64 hret; |
| 738 | struct hcp_ehea_port_cb0 *cb0; |
| 739 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 740 | cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC); /* May be called via */ |
| 741 | if (!cb0) { /* ehea_neq_tasklet() */ |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 742 | ehea_error("no mem for cb0"); |
| 743 | ret = -ENOMEM; |
| 744 | goto out; |
| 745 | } |
| 746 | |
| 747 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
| 748 | port->logical_port_id, H_PORT_CB0, |
| 749 | EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF), |
| 750 | cb0); |
| 751 | if (hret != H_SUCCESS) { |
| 752 | ret = -EIO; |
| 753 | goto out_free; |
| 754 | } |
| 755 | |
| 756 | /* MAC address */ |
| 757 | port->mac_addr = cb0->port_mac_addr << 16; |
| 758 | |
| 759 | if (!is_valid_ether_addr((u8*)&port->mac_addr)) { |
| 760 | ret = -EADDRNOTAVAIL; |
| 761 | goto out_free; |
| 762 | } |
| 763 | |
| 764 | /* Port speed */ |
| 765 | switch (cb0->port_speed) { |
| 766 | case H_SPEED_10M_H: |
| 767 | port->port_speed = EHEA_SPEED_10M; |
| 768 | port->full_duplex = 0; |
| 769 | break; |
| 770 | case H_SPEED_10M_F: |
| 771 | port->port_speed = EHEA_SPEED_10M; |
| 772 | port->full_duplex = 1; |
| 773 | break; |
| 774 | case H_SPEED_100M_H: |
| 775 | port->port_speed = EHEA_SPEED_100M; |
| 776 | port->full_duplex = 0; |
| 777 | break; |
| 778 | case H_SPEED_100M_F: |
| 779 | port->port_speed = EHEA_SPEED_100M; |
| 780 | port->full_duplex = 1; |
| 781 | break; |
| 782 | case H_SPEED_1G_F: |
| 783 | port->port_speed = EHEA_SPEED_1G; |
| 784 | port->full_duplex = 1; |
| 785 | break; |
| 786 | case H_SPEED_10G_F: |
| 787 | port->port_speed = EHEA_SPEED_10G; |
| 788 | port->full_duplex = 1; |
| 789 | break; |
| 790 | default: |
| 791 | port->port_speed = 0; |
| 792 | port->full_duplex = 0; |
| 793 | break; |
| 794 | } |
| 795 | |
Thomas Klein | e919b59 | 2007-01-22 12:53:20 +0100 | [diff] [blame] | 796 | port->autoneg = 1; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 797 | port->num_mcs = cb0->num_default_qps; |
Thomas Klein | e919b59 | 2007-01-22 12:53:20 +0100 | [diff] [blame] | 798 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 799 | /* Number of default QPs */ |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 800 | if (use_mcs) |
| 801 | port->num_def_qps = cb0->num_default_qps; |
| 802 | else |
| 803 | port->num_def_qps = 1; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 804 | |
| 805 | if (!port->num_def_qps) { |
| 806 | ret = -EINVAL; |
| 807 | goto out_free; |
| 808 | } |
| 809 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 810 | port->num_tx_qps = num_tx_qps; |
| 811 | |
| 812 | if (port->num_def_qps >= port->num_tx_qps) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 813 | port->num_add_tx_qps = 0; |
| 814 | else |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 815 | port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 816 | |
| 817 | ret = 0; |
| 818 | out_free: |
| 819 | if (ret || netif_msg_probe(port)) |
| 820 | ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr"); |
| 821 | kfree(cb0); |
| 822 | out: |
| 823 | return ret; |
| 824 | } |
| 825 | |
| 826 | int ehea_set_portspeed(struct ehea_port *port, u32 port_speed) |
| 827 | { |
| 828 | struct hcp_ehea_port_cb4 *cb4; |
| 829 | u64 hret; |
| 830 | int ret = 0; |
| 831 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 832 | cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 833 | if (!cb4) { |
| 834 | ehea_error("no mem for cb4"); |
| 835 | ret = -ENOMEM; |
| 836 | goto out; |
| 837 | } |
| 838 | |
| 839 | cb4->port_speed = port_speed; |
| 840 | |
| 841 | netif_carrier_off(port->netdev); |
| 842 | |
| 843 | hret = ehea_h_modify_ehea_port(port->adapter->handle, |
| 844 | port->logical_port_id, |
| 845 | H_PORT_CB4, H_PORT_CB4_SPEED, cb4); |
| 846 | if (hret == H_SUCCESS) { |
| 847 | port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0; |
| 848 | |
| 849 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
| 850 | port->logical_port_id, |
| 851 | H_PORT_CB4, H_PORT_CB4_SPEED, |
| 852 | cb4); |
| 853 | if (hret == H_SUCCESS) { |
| 854 | switch (cb4->port_speed) { |
| 855 | case H_SPEED_10M_H: |
| 856 | port->port_speed = EHEA_SPEED_10M; |
| 857 | port->full_duplex = 0; |
| 858 | break; |
| 859 | case H_SPEED_10M_F: |
| 860 | port->port_speed = EHEA_SPEED_10M; |
| 861 | port->full_duplex = 1; |
| 862 | break; |
| 863 | case H_SPEED_100M_H: |
| 864 | port->port_speed = EHEA_SPEED_100M; |
| 865 | port->full_duplex = 0; |
| 866 | break; |
| 867 | case H_SPEED_100M_F: |
| 868 | port->port_speed = EHEA_SPEED_100M; |
| 869 | port->full_duplex = 1; |
| 870 | break; |
| 871 | case H_SPEED_1G_F: |
| 872 | port->port_speed = EHEA_SPEED_1G; |
| 873 | port->full_duplex = 1; |
| 874 | break; |
| 875 | case H_SPEED_10G_F: |
| 876 | port->port_speed = EHEA_SPEED_10G; |
| 877 | port->full_duplex = 1; |
| 878 | break; |
| 879 | default: |
| 880 | port->port_speed = 0; |
| 881 | port->full_duplex = 0; |
| 882 | break; |
| 883 | } |
| 884 | } else { |
| 885 | ehea_error("Failed sensing port speed"); |
| 886 | ret = -EIO; |
| 887 | } |
| 888 | } else { |
| 889 | if (hret == H_AUTHORITY) { |
Thomas Klein | 7674a58 | 2007-01-22 12:54:20 +0100 | [diff] [blame] | 890 | ehea_info("Hypervisor denied setting port speed"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 891 | ret = -EPERM; |
| 892 | } else { |
| 893 | ret = -EIO; |
| 894 | ehea_error("Failed setting port speed"); |
| 895 | } |
| 896 | } |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 897 | if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP)) |
| 898 | netif_carrier_on(port->netdev); |
| 899 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 900 | kfree(cb4); |
| 901 | out: |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe) |
| 906 | { |
| 907 | int ret; |
| 908 | u8 ec; |
| 909 | u8 portnum; |
| 910 | struct ehea_port *port; |
| 911 | |
| 912 | ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe); |
| 913 | portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe); |
| 914 | port = ehea_get_port(adapter, portnum); |
| 915 | |
| 916 | switch (ec) { |
| 917 | case EHEA_EC_PORTSTATE_CHG: /* port state change */ |
| 918 | |
| 919 | if (!port) { |
| 920 | ehea_error("unknown portnum %x", portnum); |
| 921 | break; |
| 922 | } |
| 923 | |
| 924 | if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) { |
| 925 | if (!netif_carrier_ok(port->netdev)) { |
Jan-Bernd Themann | 1e1675c | 2006-10-25 13:11:42 +0200 | [diff] [blame] | 926 | ret = ehea_sense_port_attr(port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 927 | if (ret) { |
| 928 | ehea_error("failed resensing port " |
| 929 | "attributes"); |
| 930 | break; |
| 931 | } |
| 932 | |
| 933 | if (netif_msg_link(port)) |
| 934 | ehea_info("%s: Logical port up: %dMbps " |
| 935 | "%s Duplex", |
| 936 | port->netdev->name, |
| 937 | port->port_speed, |
| 938 | port->full_duplex == |
| 939 | 1 ? "Full" : "Half"); |
| 940 | |
| 941 | netif_carrier_on(port->netdev); |
| 942 | netif_wake_queue(port->netdev); |
| 943 | } |
| 944 | } else |
| 945 | if (netif_carrier_ok(port->netdev)) { |
| 946 | if (netif_msg_link(port)) |
| 947 | ehea_info("%s: Logical port down", |
| 948 | port->netdev->name); |
| 949 | netif_carrier_off(port->netdev); |
| 950 | netif_stop_queue(port->netdev); |
| 951 | } |
| 952 | |
| 953 | if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) { |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 954 | port->phy_link = EHEA_PHY_LINK_UP; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 955 | if (netif_msg_link(port)) |
| 956 | ehea_info("%s: Physical port up", |
| 957 | port->netdev->name); |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 958 | if (prop_carrier_state) |
| 959 | netif_carrier_on(port->netdev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 960 | } else { |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 961 | port->phy_link = EHEA_PHY_LINK_DOWN; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 962 | if (netif_msg_link(port)) |
| 963 | ehea_info("%s: Physical port down", |
| 964 | port->netdev->name); |
Jan-Bernd Themann | 8759cf7 | 2007-09-07 12:30:17 +0200 | [diff] [blame] | 965 | if (prop_carrier_state) |
| 966 | netif_carrier_off(port->netdev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe)) |
| 970 | ehea_info("External switch port is primary port"); |
| 971 | else |
| 972 | ehea_info("External switch port is backup port"); |
| 973 | |
| 974 | break; |
| 975 | case EHEA_EC_ADAPTER_MALFUNC: |
| 976 | ehea_error("Adapter malfunction"); |
| 977 | break; |
| 978 | case EHEA_EC_PORT_MALFUNC: |
| 979 | ehea_info("Port malfunction: Device: %s", port->netdev->name); |
| 980 | netif_carrier_off(port->netdev); |
| 981 | netif_stop_queue(port->netdev); |
| 982 | break; |
| 983 | default: |
Jan-Bernd Themann | bff0a55 | 2006-10-05 16:53:14 +0200 | [diff] [blame] | 984 | ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 985 | break; |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | static void ehea_neq_tasklet(unsigned long data) |
| 990 | { |
| 991 | struct ehea_adapter *adapter = (struct ehea_adapter*)data; |
| 992 | struct ehea_eqe *eqe; |
| 993 | u64 event_mask; |
| 994 | |
| 995 | eqe = ehea_poll_eq(adapter->neq); |
| 996 | ehea_debug("eqe=%p", eqe); |
| 997 | |
| 998 | while (eqe) { |
| 999 | ehea_debug("*eqe=%lx", eqe->entry); |
| 1000 | ehea_parse_eqe(adapter, eqe->entry); |
| 1001 | eqe = ehea_poll_eq(adapter->neq); |
| 1002 | ehea_debug("next eqe=%p", eqe); |
| 1003 | } |
| 1004 | |
| 1005 | event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1) |
| 1006 | | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1) |
| 1007 | | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1); |
| 1008 | |
| 1009 | ehea_h_reset_events(adapter->handle, |
| 1010 | adapter->neq->fw_handle, event_mask); |
| 1011 | } |
| 1012 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1013 | static irqreturn_t ehea_interrupt_neq(int irq, void *param) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1014 | { |
| 1015 | struct ehea_adapter *adapter = param; |
| 1016 | tasklet_hi_schedule(&adapter->neq_tasklet); |
| 1017 | return IRQ_HANDLED; |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | static int ehea_fill_port_res(struct ehea_port_res *pr) |
| 1022 | { |
| 1023 | int ret; |
| 1024 | struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr; |
| 1025 | |
| 1026 | ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1 |
| 1027 | - init_attr->act_nr_rwqes_rq2 |
| 1028 | - init_attr->act_nr_rwqes_rq3 - 1); |
| 1029 | |
| 1030 | ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1); |
| 1031 | |
| 1032 | ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1); |
| 1033 | |
| 1034 | return ret; |
| 1035 | } |
| 1036 | |
| 1037 | static int ehea_reg_interrupts(struct net_device *dev) |
| 1038 | { |
| 1039 | struct ehea_port *port = netdev_priv(dev); |
| 1040 | struct ehea_port_res *pr; |
| 1041 | int i, ret; |
| 1042 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1043 | |
| 1044 | snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff", |
| 1045 | dev->name); |
| 1046 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1047 | ret = ibmebus_request_irq(port->qp_eq->attr.ist1, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1048 | ehea_qp_aff_irq_handler, |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 1049 | IRQF_DISABLED, port->int_aff_name, port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1050 | if (ret) { |
| 1051 | ehea_error("failed registering irq for qp_aff_irq_handler:" |
| 1052 | "ist=%X", port->qp_eq->attr.ist1); |
| 1053 | goto out_free_qpeq; |
| 1054 | } |
| 1055 | |
| 1056 | if (netif_msg_ifup(port)) |
| 1057 | ehea_info("irq_handle 0x%X for function qp_aff_irq_handler " |
| 1058 | "registered", port->qp_eq->attr.ist1); |
| 1059 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1060 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1061 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
| 1062 | pr = &port->port_res[i]; |
| 1063 | snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1064 | "%s-queue%d", dev->name, i); |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1065 | ret = ibmebus_request_irq(pr->eq->attr.ist1, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1066 | ehea_recv_irq_handler, |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 1067 | IRQF_DISABLED, pr->int_send_name, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1068 | pr); |
| 1069 | if (ret) { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1070 | ehea_error("failed registering irq for ehea_queue " |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1071 | "port_res_nr:%d, ist=%X", i, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1072 | pr->eq->attr.ist1); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1073 | goto out_free_req; |
| 1074 | } |
| 1075 | if (netif_msg_ifup(port)) |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1076 | ehea_info("irq_handle 0x%X for function ehea_queue_int " |
| 1077 | "%d registered", pr->eq->attr.ist1, i); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1078 | } |
| 1079 | out: |
| 1080 | return ret; |
| 1081 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1082 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1083 | out_free_req: |
| 1084 | while (--i >= 0) { |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1085 | u32 ist = port->port_res[i].eq->attr.ist1; |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1086 | ibmebus_free_irq(ist, &port->port_res[i]); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1087 | } |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1088 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1089 | out_free_qpeq: |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1090 | ibmebus_free_irq(port->qp_eq->attr.ist1, port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1091 | i = port->num_def_qps; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1092 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1093 | goto out; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1094 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | static void ehea_free_interrupts(struct net_device *dev) |
| 1098 | { |
| 1099 | struct ehea_port *port = netdev_priv(dev); |
| 1100 | struct ehea_port_res *pr; |
| 1101 | int i; |
| 1102 | |
| 1103 | /* send */ |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1104 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1105 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
| 1106 | pr = &port->port_res[i]; |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1107 | ibmebus_free_irq(pr->eq->attr.ist1, pr); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1108 | if (netif_msg_intr(port)) |
| 1109 | ehea_info("free send irq for res %d with handle 0x%X", |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1110 | i, pr->eq->attr.ist1); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | /* associated events */ |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 1114 | ibmebus_free_irq(port->qp_eq->attr.ist1, port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1115 | if (netif_msg_intr(port)) |
| 1116 | ehea_info("associated event interrupt for handle 0x%X freed", |
| 1117 | port->qp_eq->attr.ist1); |
| 1118 | } |
| 1119 | |
| 1120 | static int ehea_configure_port(struct ehea_port *port) |
| 1121 | { |
| 1122 | int ret, i; |
| 1123 | u64 hret, mask; |
| 1124 | struct hcp_ehea_port_cb0 *cb0; |
| 1125 | |
| 1126 | ret = -ENOMEM; |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 1127 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1128 | if (!cb0) |
| 1129 | goto out; |
| 1130 | |
| 1131 | cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1) |
| 1132 | | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1) |
| 1133 | | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1) |
| 1134 | | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1) |
| 1135 | | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER, |
| 1136 | PXLY_RC_VLAN_FILTER) |
| 1137 | | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1); |
| 1138 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1139 | for (i = 0; i < port->num_mcs; i++) |
| 1140 | if (use_mcs) |
| 1141 | cb0->default_qpn_arr[i] = |
| 1142 | port->port_res[i].qp->init_attr.qp_nr; |
| 1143 | else |
| 1144 | cb0->default_qpn_arr[i] = |
| 1145 | port->port_res[0].qp->init_attr.qp_nr; |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1146 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1147 | if (netif_msg_ifup(port)) |
| 1148 | ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port"); |
| 1149 | |
| 1150 | mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1) |
| 1151 | | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1); |
| 1152 | |
| 1153 | hret = ehea_h_modify_ehea_port(port->adapter->handle, |
| 1154 | port->logical_port_id, |
| 1155 | H_PORT_CB0, mask, cb0); |
| 1156 | ret = -EIO; |
| 1157 | if (hret != H_SUCCESS) |
| 1158 | goto out_free; |
| 1159 | |
| 1160 | ret = 0; |
| 1161 | |
| 1162 | out_free: |
| 1163 | kfree(cb0); |
| 1164 | out: |
| 1165 | return ret; |
| 1166 | } |
| 1167 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1168 | int ehea_gen_smrs(struct ehea_port_res *pr) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1169 | { |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1170 | int ret; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1171 | struct ehea_adapter *adapter = pr->port->adapter; |
| 1172 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1173 | ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr); |
| 1174 | if (ret) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1175 | goto out; |
| 1176 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1177 | ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr); |
| 1178 | if (ret) |
| 1179 | goto out_free; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1180 | |
| 1181 | return 0; |
| 1182 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1183 | out_free: |
| 1184 | ehea_rem_mr(&pr->send_mr); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1185 | out: |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1186 | ehea_error("Generating SMRS failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1187 | return -EIO; |
| 1188 | } |
| 1189 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1190 | int ehea_rem_smrs(struct ehea_port_res *pr) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1191 | { |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 1192 | if ((ehea_rem_mr(&pr->send_mr)) |
| 1193 | || (ehea_rem_mr(&pr->recv_mr))) |
| 1194 | return -EIO; |
| 1195 | else |
| 1196 | return 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries) |
| 1200 | { |
| 1201 | int arr_size = sizeof(void*) * max_q_entries; |
| 1202 | |
| 1203 | q_skba->arr = vmalloc(arr_size); |
| 1204 | if (!q_skba->arr) |
| 1205 | return -ENOMEM; |
| 1206 | |
| 1207 | memset(q_skba->arr, 0, arr_size); |
| 1208 | |
| 1209 | q_skba->len = max_q_entries; |
| 1210 | q_skba->index = 0; |
| 1211 | q_skba->os_skbs = 0; |
| 1212 | |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr, |
| 1217 | struct port_res_cfg *pr_cfg, int queue_token) |
| 1218 | { |
| 1219 | struct ehea_adapter *adapter = port->adapter; |
| 1220 | enum ehea_eq_type eq_type = EHEA_EQ; |
| 1221 | struct ehea_qp_init_attr *init_attr = NULL; |
| 1222 | int ret = -EIO; |
| 1223 | |
| 1224 | memset(pr, 0, sizeof(struct ehea_port_res)); |
| 1225 | |
| 1226 | pr->port = port; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1227 | spin_lock_init(&pr->xmit_lock); |
| 1228 | spin_lock_init(&pr->netif_queue); |
| 1229 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1230 | pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0); |
| 1231 | if (!pr->eq) { |
| 1232 | ehea_error("create_eq failed (eq)"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1233 | goto out_free; |
| 1234 | } |
| 1235 | |
| 1236 | pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1237 | pr->eq->fw_handle, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1238 | port->logical_port_id); |
| 1239 | if (!pr->recv_cq) { |
| 1240 | ehea_error("create_cq failed (cq_recv)"); |
| 1241 | goto out_free; |
| 1242 | } |
| 1243 | |
| 1244 | pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq, |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1245 | pr->eq->fw_handle, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1246 | port->logical_port_id); |
| 1247 | if (!pr->send_cq) { |
| 1248 | ehea_error("create_cq failed (cq_send)"); |
| 1249 | goto out_free; |
| 1250 | } |
| 1251 | |
| 1252 | if (netif_msg_ifup(port)) |
| 1253 | ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d", |
| 1254 | pr->send_cq->attr.act_nr_of_cqes, |
| 1255 | pr->recv_cq->attr.act_nr_of_cqes); |
| 1256 | |
| 1257 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); |
| 1258 | if (!init_attr) { |
| 1259 | ret = -ENOMEM; |
| 1260 | ehea_error("no mem for ehea_qp_init_attr"); |
| 1261 | goto out_free; |
| 1262 | } |
| 1263 | |
| 1264 | init_attr->low_lat_rq1 = 1; |
| 1265 | init_attr->signalingtype = 1; /* generate CQE if specified in WQE */ |
| 1266 | init_attr->rq_count = 3; |
| 1267 | init_attr->qp_token = queue_token; |
| 1268 | init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq; |
| 1269 | init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1; |
| 1270 | init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2; |
| 1271 | init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3; |
| 1272 | init_attr->wqe_size_enc_sq = EHEA_SG_SQ; |
| 1273 | init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1; |
| 1274 | init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2; |
| 1275 | init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3; |
| 1276 | init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD; |
| 1277 | init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD; |
| 1278 | init_attr->port_nr = port->logical_port_id; |
| 1279 | init_attr->send_cq_handle = pr->send_cq->fw_handle; |
| 1280 | init_attr->recv_cq_handle = pr->recv_cq->fw_handle; |
| 1281 | init_attr->aff_eq_handle = port->qp_eq->fw_handle; |
| 1282 | |
| 1283 | pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr); |
| 1284 | if (!pr->qp) { |
| 1285 | ehea_error("create_qp failed"); |
| 1286 | ret = -EIO; |
| 1287 | goto out_free; |
| 1288 | } |
| 1289 | |
| 1290 | if (netif_msg_ifup(port)) |
| 1291 | ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n " |
| 1292 | "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr, |
| 1293 | init_attr->act_nr_send_wqes, |
| 1294 | init_attr->act_nr_rwqes_rq1, |
| 1295 | init_attr->act_nr_rwqes_rq2, |
| 1296 | init_attr->act_nr_rwqes_rq3); |
| 1297 | |
| 1298 | ret = ehea_init_q_skba(&pr->sq_skba, init_attr->act_nr_send_wqes + 1); |
| 1299 | ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1); |
| 1300 | ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1); |
| 1301 | ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1); |
| 1302 | if (ret) |
| 1303 | goto out_free; |
| 1304 | |
| 1305 | pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10; |
| 1306 | if (ehea_gen_smrs(pr) != 0) { |
| 1307 | ret = -EIO; |
| 1308 | goto out_free; |
| 1309 | } |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1310 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1311 | atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1); |
| 1312 | |
| 1313 | kfree(init_attr); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1314 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1315 | netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1316 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 1317 | pr->lro_mgr.max_aggr = pr->port->lro_max_aggr; |
| 1318 | pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS; |
| 1319 | pr->lro_mgr.lro_arr = pr->lro_desc; |
| 1320 | pr->lro_mgr.get_skb_header = get_skb_hdr; |
| 1321 | pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID; |
| 1322 | pr->lro_mgr.dev = port->netdev; |
| 1323 | pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY; |
| 1324 | pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY; |
| 1325 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1326 | ret = 0; |
| 1327 | goto out; |
| 1328 | |
| 1329 | out_free: |
| 1330 | kfree(init_attr); |
| 1331 | vfree(pr->sq_skba.arr); |
| 1332 | vfree(pr->rq1_skba.arr); |
| 1333 | vfree(pr->rq2_skba.arr); |
| 1334 | vfree(pr->rq3_skba.arr); |
| 1335 | ehea_destroy_qp(pr->qp); |
| 1336 | ehea_destroy_cq(pr->send_cq); |
| 1337 | ehea_destroy_cq(pr->recv_cq); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1338 | ehea_destroy_eq(pr->eq); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1339 | out: |
| 1340 | return ret; |
| 1341 | } |
| 1342 | |
| 1343 | static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr) |
| 1344 | { |
| 1345 | int ret, i; |
| 1346 | |
| 1347 | ret = ehea_destroy_qp(pr->qp); |
| 1348 | |
| 1349 | if (!ret) { |
| 1350 | ehea_destroy_cq(pr->send_cq); |
| 1351 | ehea_destroy_cq(pr->recv_cq); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1352 | ehea_destroy_eq(pr->eq); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1353 | |
| 1354 | for (i = 0; i < pr->rq1_skba.len; i++) |
| 1355 | if (pr->rq1_skba.arr[i]) |
| 1356 | dev_kfree_skb(pr->rq1_skba.arr[i]); |
| 1357 | |
| 1358 | for (i = 0; i < pr->rq2_skba.len; i++) |
| 1359 | if (pr->rq2_skba.arr[i]) |
| 1360 | dev_kfree_skb(pr->rq2_skba.arr[i]); |
| 1361 | |
| 1362 | for (i = 0; i < pr->rq3_skba.len; i++) |
| 1363 | if (pr->rq3_skba.arr[i]) |
| 1364 | dev_kfree_skb(pr->rq3_skba.arr[i]); |
| 1365 | |
| 1366 | for (i = 0; i < pr->sq_skba.len; i++) |
| 1367 | if (pr->sq_skba.arr[i]) |
| 1368 | dev_kfree_skb(pr->sq_skba.arr[i]); |
| 1369 | |
| 1370 | vfree(pr->rq1_skba.arr); |
| 1371 | vfree(pr->rq2_skba.arr); |
| 1372 | vfree(pr->rq3_skba.arr); |
| 1373 | vfree(pr->sq_skba.arr); |
| 1374 | ret = ehea_rem_smrs(pr); |
| 1375 | } |
| 1376 | return ret; |
| 1377 | } |
| 1378 | |
| 1379 | /* |
| 1380 | * The write_* functions store information in swqe which is used by |
| 1381 | * the hardware to calculate the ip/tcp/udp checksum |
| 1382 | */ |
| 1383 | |
| 1384 | static inline void write_ip_start_end(struct ehea_swqe *swqe, |
| 1385 | const struct sk_buff *skb) |
| 1386 | { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1387 | swqe->ip_start = skb_network_offset(skb); |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 1388 | swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | static inline void write_tcp_offset_end(struct ehea_swqe *swqe, |
| 1392 | const struct sk_buff *skb) |
| 1393 | { |
| 1394 | swqe->tcp_offset = |
| 1395 | (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check)); |
| 1396 | |
| 1397 | swqe->tcp_end = (u16)skb->len - 1; |
| 1398 | } |
| 1399 | |
| 1400 | static inline void write_udp_offset_end(struct ehea_swqe *swqe, |
| 1401 | const struct sk_buff *skb) |
| 1402 | { |
| 1403 | swqe->tcp_offset = |
| 1404 | (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check)); |
| 1405 | |
| 1406 | swqe->tcp_end = (u16)skb->len - 1; |
| 1407 | } |
| 1408 | |
| 1409 | |
| 1410 | static void write_swqe2_TSO(struct sk_buff *skb, |
| 1411 | struct ehea_swqe *swqe, u32 lkey) |
| 1412 | { |
| 1413 | struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry; |
| 1414 | u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0]; |
| 1415 | int skb_data_size = skb->len - skb->data_len; |
| 1416 | int headersize; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1417 | |
| 1418 | /* Packet is TCP with TSO enabled */ |
| 1419 | swqe->tx_control |= EHEA_SWQE_TSO; |
| 1420 | swqe->mss = skb_shinfo(skb)->gso_size; |
| 1421 | /* copy only eth/ip/tcp headers to immediate data and |
| 1422 | * the rest of skb->data to sg1entry |
| 1423 | */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 1424 | headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1425 | |
| 1426 | skb_data_size = skb->len - skb->data_len; |
| 1427 | |
| 1428 | if (skb_data_size >= headersize) { |
| 1429 | /* copy immediate data */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1430 | skb_copy_from_linear_data(skb, imm_data, headersize); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1431 | swqe->immediate_data_length = headersize; |
| 1432 | |
| 1433 | if (skb_data_size > headersize) { |
| 1434 | /* set sg1entry data */ |
| 1435 | sg1entry->l_key = lkey; |
| 1436 | sg1entry->len = skb_data_size - headersize; |
Thomas Klein | 44a5b3d | 2007-08-06 13:55:44 +0200 | [diff] [blame] | 1437 | sg1entry->vaddr = |
| 1438 | ehea_map_vaddr(skb->data + headersize); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1439 | swqe->descriptors++; |
| 1440 | } |
| 1441 | } else |
| 1442 | ehea_error("cannot handle fragmented headers"); |
| 1443 | } |
| 1444 | |
| 1445 | static void write_swqe2_nonTSO(struct sk_buff *skb, |
| 1446 | struct ehea_swqe *swqe, u32 lkey) |
| 1447 | { |
| 1448 | int skb_data_size = skb->len - skb->data_len; |
| 1449 | u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0]; |
| 1450 | struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1451 | |
| 1452 | /* Packet is any nonTSO type |
| 1453 | * |
| 1454 | * Copy as much as possible skb->data to immediate data and |
| 1455 | * the rest to sg1entry |
| 1456 | */ |
| 1457 | if (skb_data_size >= SWQE2_MAX_IMM) { |
| 1458 | /* copy immediate data */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1459 | skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1460 | |
| 1461 | swqe->immediate_data_length = SWQE2_MAX_IMM; |
| 1462 | |
| 1463 | if (skb_data_size > SWQE2_MAX_IMM) { |
| 1464 | /* copy sg1entry data */ |
| 1465 | sg1entry->l_key = lkey; |
| 1466 | sg1entry->len = skb_data_size - SWQE2_MAX_IMM; |
Thomas Klein | 44a5b3d | 2007-08-06 13:55:44 +0200 | [diff] [blame] | 1467 | sg1entry->vaddr = |
| 1468 | ehea_map_vaddr(skb->data + SWQE2_MAX_IMM); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1469 | swqe->descriptors++; |
| 1470 | } |
| 1471 | } else { |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1472 | skb_copy_from_linear_data(skb, imm_data, skb_data_size); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1473 | swqe->immediate_data_length = skb_data_size; |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev, |
| 1478 | struct ehea_swqe *swqe, u32 lkey) |
| 1479 | { |
| 1480 | struct ehea_vsgentry *sg_list, *sg1entry, *sgentry; |
| 1481 | skb_frag_t *frag; |
| 1482 | int nfrags, sg1entry_contains_frag_data, i; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1483 | |
| 1484 | nfrags = skb_shinfo(skb)->nr_frags; |
| 1485 | sg1entry = &swqe->u.immdata_desc.sg_entry; |
| 1486 | sg_list = (struct ehea_vsgentry*)&swqe->u.immdata_desc.sg_list; |
| 1487 | swqe->descriptors = 0; |
| 1488 | sg1entry_contains_frag_data = 0; |
| 1489 | |
| 1490 | if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size) |
| 1491 | write_swqe2_TSO(skb, swqe, lkey); |
| 1492 | else |
| 1493 | write_swqe2_nonTSO(skb, swqe, lkey); |
| 1494 | |
| 1495 | /* write descriptors */ |
| 1496 | if (nfrags > 0) { |
| 1497 | if (swqe->descriptors == 0) { |
| 1498 | /* sg1entry not yet used */ |
| 1499 | frag = &skb_shinfo(skb)->frags[0]; |
| 1500 | |
| 1501 | /* copy sg1entry data */ |
| 1502 | sg1entry->l_key = lkey; |
| 1503 | sg1entry->len = frag->size; |
Thomas Klein | 44a5b3d | 2007-08-06 13:55:44 +0200 | [diff] [blame] | 1504 | sg1entry->vaddr = |
| 1505 | ehea_map_vaddr(page_address(frag->page) |
| 1506 | + frag->page_offset); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1507 | swqe->descriptors++; |
| 1508 | sg1entry_contains_frag_data = 1; |
| 1509 | } |
| 1510 | |
| 1511 | for (i = sg1entry_contains_frag_data; i < nfrags; i++) { |
| 1512 | |
| 1513 | frag = &skb_shinfo(skb)->frags[i]; |
| 1514 | sgentry = &sg_list[i - sg1entry_contains_frag_data]; |
| 1515 | |
| 1516 | sgentry->l_key = lkey; |
| 1517 | sgentry->len = frag->size; |
Thomas Klein | 44a5b3d | 2007-08-06 13:55:44 +0200 | [diff] [blame] | 1518 | sgentry->vaddr = |
| 1519 | ehea_map_vaddr(page_address(frag->page) |
| 1520 | + frag->page_offset); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1521 | swqe->descriptors++; |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid) |
| 1527 | { |
| 1528 | int ret = 0; |
| 1529 | u64 hret; |
| 1530 | u8 reg_type; |
| 1531 | |
| 1532 | /* De/Register untagged packets */ |
| 1533 | reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED; |
| 1534 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, |
| 1535 | port->logical_port_id, |
| 1536 | reg_type, port->mac_addr, 0, hcallid); |
| 1537 | if (hret != H_SUCCESS) { |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 1538 | ehea_error("%sregistering bc address failed (tagged)", |
| 1539 | hcallid == H_REG_BCMC ? "" : "de"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1540 | ret = -EIO; |
| 1541 | goto out_herr; |
| 1542 | } |
| 1543 | |
| 1544 | /* De/Register VLAN packets */ |
| 1545 | reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL; |
| 1546 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, |
| 1547 | port->logical_port_id, |
| 1548 | reg_type, port->mac_addr, 0, hcallid); |
| 1549 | if (hret != H_SUCCESS) { |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 1550 | ehea_error("%sregistering bc address failed (vlan)", |
| 1551 | hcallid == H_REG_BCMC ? "" : "de"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1552 | ret = -EIO; |
| 1553 | } |
| 1554 | out_herr: |
| 1555 | return ret; |
| 1556 | } |
| 1557 | |
| 1558 | static int ehea_set_mac_addr(struct net_device *dev, void *sa) |
| 1559 | { |
| 1560 | struct ehea_port *port = netdev_priv(dev); |
| 1561 | struct sockaddr *mac_addr = sa; |
| 1562 | struct hcp_ehea_port_cb0 *cb0; |
| 1563 | int ret; |
| 1564 | u64 hret; |
| 1565 | |
| 1566 | if (!is_valid_ether_addr(mac_addr->sa_data)) { |
| 1567 | ret = -EADDRNOTAVAIL; |
| 1568 | goto out; |
| 1569 | } |
| 1570 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 1571 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1572 | if (!cb0) { |
| 1573 | ehea_error("no mem for cb0"); |
| 1574 | ret = -ENOMEM; |
| 1575 | goto out; |
| 1576 | } |
| 1577 | |
| 1578 | memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN); |
| 1579 | |
| 1580 | cb0->port_mac_addr = cb0->port_mac_addr >> 16; |
| 1581 | |
| 1582 | hret = ehea_h_modify_ehea_port(port->adapter->handle, |
| 1583 | port->logical_port_id, H_PORT_CB0, |
| 1584 | EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0); |
| 1585 | if (hret != H_SUCCESS) { |
| 1586 | ret = -EIO; |
| 1587 | goto out_free; |
| 1588 | } |
| 1589 | |
| 1590 | memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len); |
| 1591 | |
| 1592 | /* Deregister old MAC in pHYP */ |
| 1593 | ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC); |
| 1594 | if (ret) |
| 1595 | goto out_free; |
| 1596 | |
| 1597 | port->mac_addr = cb0->port_mac_addr << 16; |
| 1598 | |
| 1599 | /* Register new MAC in pHYP */ |
| 1600 | ret = ehea_broadcast_reg_helper(port, H_REG_BCMC); |
| 1601 | if (ret) |
| 1602 | goto out_free; |
| 1603 | |
| 1604 | ret = 0; |
| 1605 | out_free: |
| 1606 | kfree(cb0); |
| 1607 | out: |
| 1608 | return ret; |
| 1609 | } |
| 1610 | |
| 1611 | static void ehea_promiscuous_error(u64 hret, int enable) |
| 1612 | { |
Thomas Klein | 7674a58 | 2007-01-22 12:54:20 +0100 | [diff] [blame] | 1613 | if (hret == H_AUTHORITY) |
| 1614 | ehea_info("Hypervisor denied %sabling promiscuous mode", |
| 1615 | enable == 1 ? "en" : "dis"); |
| 1616 | else |
| 1617 | ehea_error("failed %sabling promiscuous mode", |
| 1618 | enable == 1 ? "en" : "dis"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | static void ehea_promiscuous(struct net_device *dev, int enable) |
| 1622 | { |
| 1623 | struct ehea_port *port = netdev_priv(dev); |
| 1624 | struct hcp_ehea_port_cb7 *cb7; |
| 1625 | u64 hret; |
| 1626 | |
| 1627 | if ((enable && port->promisc) || (!enable && !port->promisc)) |
| 1628 | return; |
| 1629 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 1630 | cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1631 | if (!cb7) { |
| 1632 | ehea_error("no mem for cb7"); |
| 1633 | goto out; |
| 1634 | } |
| 1635 | |
| 1636 | /* Modify Pxs_DUCQPN in CB7 */ |
| 1637 | cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0; |
| 1638 | |
| 1639 | hret = ehea_h_modify_ehea_port(port->adapter->handle, |
| 1640 | port->logical_port_id, |
| 1641 | H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7); |
| 1642 | if (hret) { |
| 1643 | ehea_promiscuous_error(hret, enable); |
| 1644 | goto out; |
| 1645 | } |
| 1646 | |
| 1647 | port->promisc = enable; |
| 1648 | out: |
| 1649 | kfree(cb7); |
| 1650 | return; |
| 1651 | } |
| 1652 | |
| 1653 | static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr, |
| 1654 | u32 hcallid) |
| 1655 | { |
| 1656 | u64 hret; |
| 1657 | u8 reg_type; |
| 1658 | |
| 1659 | reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST |
| 1660 | | EHEA_BCMC_UNTAGGED; |
| 1661 | |
| 1662 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, |
| 1663 | port->logical_port_id, |
| 1664 | reg_type, mc_mac_addr, 0, hcallid); |
| 1665 | if (hret) |
| 1666 | goto out; |
| 1667 | |
| 1668 | reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST |
| 1669 | | EHEA_BCMC_VLANID_ALL; |
| 1670 | |
| 1671 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, |
| 1672 | port->logical_port_id, |
| 1673 | reg_type, mc_mac_addr, 0, hcallid); |
| 1674 | out: |
| 1675 | return hret; |
| 1676 | } |
| 1677 | |
| 1678 | static int ehea_drop_multicast_list(struct net_device *dev) |
| 1679 | { |
| 1680 | struct ehea_port *port = netdev_priv(dev); |
| 1681 | struct ehea_mc_list *mc_entry = port->mc_list; |
| 1682 | struct list_head *pos; |
| 1683 | struct list_head *temp; |
| 1684 | int ret = 0; |
| 1685 | u64 hret; |
| 1686 | |
| 1687 | list_for_each_safe(pos, temp, &(port->mc_list->list)) { |
| 1688 | mc_entry = list_entry(pos, struct ehea_mc_list, list); |
| 1689 | |
| 1690 | hret = ehea_multicast_reg_helper(port, mc_entry->macaddr, |
| 1691 | H_DEREG_BCMC); |
| 1692 | if (hret) { |
| 1693 | ehea_error("failed deregistering mcast MAC"); |
| 1694 | ret = -EIO; |
| 1695 | } |
| 1696 | |
| 1697 | list_del(pos); |
| 1698 | kfree(mc_entry); |
| 1699 | } |
| 1700 | return ret; |
| 1701 | } |
| 1702 | |
| 1703 | static void ehea_allmulti(struct net_device *dev, int enable) |
| 1704 | { |
| 1705 | struct ehea_port *port = netdev_priv(dev); |
| 1706 | u64 hret; |
| 1707 | |
| 1708 | if (!port->allmulti) { |
| 1709 | if (enable) { |
| 1710 | /* Enable ALLMULTI */ |
| 1711 | ehea_drop_multicast_list(dev); |
| 1712 | hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC); |
| 1713 | if (!hret) |
| 1714 | port->allmulti = 1; |
| 1715 | else |
| 1716 | ehea_error("failed enabling IFF_ALLMULTI"); |
| 1717 | } |
| 1718 | } else |
| 1719 | if (!enable) { |
| 1720 | /* Disable ALLMULTI */ |
| 1721 | hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC); |
| 1722 | if (!hret) |
| 1723 | port->allmulti = 0; |
| 1724 | else |
| 1725 | ehea_error("failed disabling IFF_ALLMULTI"); |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | static void ehea_add_multicast_entry(struct ehea_port* port, u8* mc_mac_addr) |
| 1730 | { |
| 1731 | struct ehea_mc_list *ehea_mcl_entry; |
| 1732 | u64 hret; |
| 1733 | |
Jan-Bernd Themann | 1e1675c | 2006-10-25 13:11:42 +0200 | [diff] [blame] | 1734 | ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1735 | if (!ehea_mcl_entry) { |
| 1736 | ehea_error("no mem for mcl_entry"); |
| 1737 | return; |
| 1738 | } |
| 1739 | |
| 1740 | INIT_LIST_HEAD(&ehea_mcl_entry->list); |
| 1741 | |
| 1742 | memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN); |
| 1743 | |
| 1744 | hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr, |
| 1745 | H_REG_BCMC); |
| 1746 | if (!hret) |
| 1747 | list_add(&ehea_mcl_entry->list, &port->mc_list->list); |
| 1748 | else { |
| 1749 | ehea_error("failed registering mcast MAC"); |
| 1750 | kfree(ehea_mcl_entry); |
| 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | static void ehea_set_multicast_list(struct net_device *dev) |
| 1755 | { |
| 1756 | struct ehea_port *port = netdev_priv(dev); |
| 1757 | struct dev_mc_list *k_mcl_entry; |
| 1758 | int ret, i; |
| 1759 | |
| 1760 | if (dev->flags & IFF_PROMISC) { |
| 1761 | ehea_promiscuous(dev, 1); |
| 1762 | return; |
| 1763 | } |
| 1764 | ehea_promiscuous(dev, 0); |
| 1765 | |
| 1766 | if (dev->flags & IFF_ALLMULTI) { |
| 1767 | ehea_allmulti(dev, 1); |
| 1768 | return; |
| 1769 | } |
| 1770 | ehea_allmulti(dev, 0); |
| 1771 | |
| 1772 | if (dev->mc_count) { |
| 1773 | ret = ehea_drop_multicast_list(dev); |
| 1774 | if (ret) { |
| 1775 | /* Dropping the current multicast list failed. |
| 1776 | * Enabling ALL_MULTI is the best we can do. |
| 1777 | */ |
| 1778 | ehea_allmulti(dev, 1); |
| 1779 | } |
| 1780 | |
| 1781 | if (dev->mc_count > port->adapter->max_mc_mac) { |
| 1782 | ehea_info("Mcast registration limit reached (0x%lx). " |
| 1783 | "Use ALLMULTI!", |
| 1784 | port->adapter->max_mc_mac); |
| 1785 | goto out; |
| 1786 | } |
| 1787 | |
| 1788 | for (i = 0, k_mcl_entry = dev->mc_list; |
| 1789 | i < dev->mc_count; |
| 1790 | i++, k_mcl_entry = k_mcl_entry->next) { |
| 1791 | ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr); |
| 1792 | } |
| 1793 | } |
| 1794 | out: |
| 1795 | return; |
| 1796 | } |
| 1797 | |
| 1798 | static int ehea_change_mtu(struct net_device *dev, int new_mtu) |
| 1799 | { |
| 1800 | if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE)) |
| 1801 | return -EINVAL; |
| 1802 | dev->mtu = new_mtu; |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
| 1806 | static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev, |
| 1807 | struct ehea_swqe *swqe, u32 lkey) |
| 1808 | { |
| 1809 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1810 | const struct iphdr *iph = ip_hdr(skb); |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 1811 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1812 | /* IPv4 */ |
| 1813 | swqe->tx_control |= EHEA_SWQE_CRC |
| 1814 | | EHEA_SWQE_IP_CHECKSUM |
| 1815 | | EHEA_SWQE_TCP_CHECKSUM |
| 1816 | | EHEA_SWQE_IMM_DATA_PRESENT |
| 1817 | | EHEA_SWQE_DESCRIPTORS_PRESENT; |
| 1818 | |
| 1819 | write_ip_start_end(swqe, skb); |
| 1820 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1821 | if (iph->protocol == IPPROTO_UDP) { |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 1822 | if ((iph->frag_off & IP_MF) |
| 1823 | || (iph->frag_off & IP_OFFSET)) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1824 | /* IP fragment, so don't change cs */ |
| 1825 | swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM; |
| 1826 | else |
| 1827 | write_udp_offset_end(swqe, skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1828 | } else if (iph->protocol == IPPROTO_TCP) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1829 | write_tcp_offset_end(swqe, skb); |
| 1830 | } |
| 1831 | |
| 1832 | /* icmp (big data) and ip segmentation packets (all other ip |
| 1833 | packets) do not require any special handling */ |
| 1834 | |
| 1835 | } else { |
| 1836 | /* Other Ethernet Protocol */ |
| 1837 | swqe->tx_control |= EHEA_SWQE_CRC |
| 1838 | | EHEA_SWQE_IMM_DATA_PRESENT |
| 1839 | | EHEA_SWQE_DESCRIPTORS_PRESENT; |
| 1840 | } |
| 1841 | |
| 1842 | write_swqe2_data(skb, dev, swqe, lkey); |
| 1843 | } |
| 1844 | |
| 1845 | static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev, |
| 1846 | struct ehea_swqe *swqe) |
| 1847 | { |
| 1848 | int nfrags = skb_shinfo(skb)->nr_frags; |
| 1849 | u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0]; |
| 1850 | skb_frag_t *frag; |
| 1851 | int i; |
| 1852 | |
| 1853 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1854 | const struct iphdr *iph = ip_hdr(skb); |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 1855 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1856 | /* IPv4 */ |
| 1857 | write_ip_start_end(swqe, skb); |
| 1858 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1859 | if (iph->protocol == IPPROTO_TCP) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1860 | swqe->tx_control |= EHEA_SWQE_CRC |
| 1861 | | EHEA_SWQE_IP_CHECKSUM |
| 1862 | | EHEA_SWQE_TCP_CHECKSUM |
| 1863 | | EHEA_SWQE_IMM_DATA_PRESENT; |
| 1864 | |
| 1865 | write_tcp_offset_end(swqe, skb); |
| 1866 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1867 | } else if (iph->protocol == IPPROTO_UDP) { |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 1868 | if ((iph->frag_off & IP_MF) |
| 1869 | || (iph->frag_off & IP_OFFSET)) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1870 | /* IP fragment, so don't change cs */ |
| 1871 | swqe->tx_control |= EHEA_SWQE_CRC |
| 1872 | | EHEA_SWQE_IMM_DATA_PRESENT; |
| 1873 | else { |
| 1874 | swqe->tx_control |= EHEA_SWQE_CRC |
| 1875 | | EHEA_SWQE_IP_CHECKSUM |
| 1876 | | EHEA_SWQE_TCP_CHECKSUM |
| 1877 | | EHEA_SWQE_IMM_DATA_PRESENT; |
| 1878 | |
| 1879 | write_udp_offset_end(swqe, skb); |
| 1880 | } |
| 1881 | } else { |
| 1882 | /* icmp (big data) and |
| 1883 | ip segmentation packets (all other ip packets) */ |
| 1884 | swqe->tx_control |= EHEA_SWQE_CRC |
| 1885 | | EHEA_SWQE_IP_CHECKSUM |
| 1886 | | EHEA_SWQE_IMM_DATA_PRESENT; |
| 1887 | } |
| 1888 | } else { |
| 1889 | /* Other Ethernet Protocol */ |
| 1890 | swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT; |
| 1891 | } |
| 1892 | /* copy (immediate) data */ |
| 1893 | if (nfrags == 0) { |
| 1894 | /* data is in a single piece */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1895 | skb_copy_from_linear_data(skb, imm_data, skb->len); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1896 | } else { |
| 1897 | /* first copy data from the skb->data buffer ... */ |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 1898 | skb_copy_from_linear_data(skb, imm_data, |
| 1899 | skb->len - skb->data_len); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1900 | imm_data += skb->len - skb->data_len; |
| 1901 | |
| 1902 | /* ... then copy data from the fragments */ |
| 1903 | for (i = 0; i < nfrags; i++) { |
| 1904 | frag = &skb_shinfo(skb)->frags[i]; |
| 1905 | memcpy(imm_data, |
| 1906 | page_address(frag->page) + frag->page_offset, |
| 1907 | frag->size); |
| 1908 | imm_data += frag->size; |
| 1909 | } |
| 1910 | } |
| 1911 | swqe->immediate_data_length = skb->len; |
| 1912 | dev_kfree_skb(skb); |
| 1913 | } |
| 1914 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1915 | static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps) |
| 1916 | { |
| 1917 | struct tcphdr *tcp; |
| 1918 | u32 tmp; |
| 1919 | |
| 1920 | if ((skb->protocol == htons(ETH_P_IP)) && |
Thomas Klein | 88ca2d0 | 2007-05-02 16:07:05 +0200 | [diff] [blame] | 1921 | (ip_hdr(skb)->protocol == IPPROTO_TCP)) { |
| 1922 | tcp = (struct tcphdr*)(skb_network_header(skb) + (ip_hdr(skb)->ihl * 4)); |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1923 | tmp = (tcp->source + (tcp->dest << 16)) % 31; |
Thomas Klein | 88ca2d0 | 2007-05-02 16:07:05 +0200 | [diff] [blame] | 1924 | tmp += ip_hdr(skb)->daddr % 31; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1925 | return tmp % num_qps; |
| 1926 | } |
| 1927 | else |
| 1928 | return 0; |
| 1929 | } |
| 1930 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1931 | static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1932 | { |
| 1933 | struct ehea_port *port = netdev_priv(dev); |
| 1934 | struct ehea_swqe *swqe; |
| 1935 | unsigned long flags; |
| 1936 | u32 lkey; |
| 1937 | int swqe_index; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1938 | struct ehea_port_res *pr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1939 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1940 | pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)]; |
| 1941 | |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 1942 | if (!spin_trylock(&pr->xmit_lock)) |
| 1943 | return NETDEV_TX_BUSY; |
| 1944 | |
| 1945 | if (pr->queue_stopped) { |
| 1946 | spin_unlock(&pr->xmit_lock); |
| 1947 | return NETDEV_TX_BUSY; |
| 1948 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1949 | |
| 1950 | swqe = ehea_get_swqe(pr->qp, &swqe_index); |
| 1951 | memset(swqe, 0, SWQE_HEADER_SIZE); |
| 1952 | atomic_dec(&pr->swqe_avail); |
| 1953 | |
| 1954 | if (skb->len <= SWQE3_MAX_IMM) { |
| 1955 | u32 sig_iv = port->sig_comp_iv; |
| 1956 | u32 swqe_num = pr->swqe_id_counter; |
| 1957 | ehea_xmit3(skb, dev, swqe); |
| 1958 | swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE) |
| 1959 | | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num); |
| 1960 | if (pr->swqe_ll_count >= (sig_iv - 1)) { |
| 1961 | swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL, |
| 1962 | sig_iv); |
| 1963 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; |
| 1964 | pr->swqe_ll_count = 0; |
| 1965 | } else |
| 1966 | pr->swqe_ll_count += 1; |
| 1967 | } else { |
| 1968 | swqe->wr_id = |
| 1969 | EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE) |
| 1970 | | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter) |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 1971 | | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1972 | | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index); |
| 1973 | pr->sq_skba.arr[pr->sq_skba.index] = skb; |
| 1974 | |
| 1975 | pr->sq_skba.index++; |
| 1976 | pr->sq_skba.index &= (pr->sq_skba.len - 1); |
| 1977 | |
| 1978 | lkey = pr->send_mr.lkey; |
| 1979 | ehea_xmit2(skb, dev, swqe, lkey); |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 1980 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1981 | } |
| 1982 | pr->swqe_id_counter += 1; |
| 1983 | |
| 1984 | if (port->vgrp && vlan_tx_tag_present(skb)) { |
| 1985 | swqe->tx_control |= EHEA_SWQE_VLAN_INSERT; |
| 1986 | swqe->vlan_tag = vlan_tx_tag_get(skb); |
| 1987 | } |
| 1988 | |
| 1989 | if (netif_msg_tx_queued(port)) { |
| 1990 | ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr); |
Jan-Bernd Themann | bff0a55 | 2006-10-05 16:53:14 +0200 | [diff] [blame] | 1991 | ehea_dump(swqe, 512, "swqe"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1992 | } |
| 1993 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 1994 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { |
| 1995 | netif_stop_queue(dev); |
| 1996 | swqe->tx_control |= EHEA_SWQE_PURGE; |
| 1997 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 1998 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 1999 | ehea_post_swqe(pr->qp, swqe); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2000 | |
| 2001 | if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { |
| 2002 | spin_lock_irqsave(&pr->netif_queue, flags); |
| 2003 | if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { |
Jan-Bernd Themann | acbddb5 | 2007-03-23 17:18:53 +0100 | [diff] [blame] | 2004 | pr->p_stats.queue_stopped++; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2005 | netif_stop_queue(dev); |
| 2006 | pr->queue_stopped = 1; |
| 2007 | } |
| 2008 | spin_unlock_irqrestore(&pr->netif_queue, flags); |
| 2009 | } |
| 2010 | dev->trans_start = jiffies; |
| 2011 | spin_unlock(&pr->xmit_lock); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2012 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2013 | return NETDEV_TX_OK; |
| 2014 | } |
| 2015 | |
| 2016 | static void ehea_vlan_rx_register(struct net_device *dev, |
| 2017 | struct vlan_group *grp) |
| 2018 | { |
| 2019 | struct ehea_port *port = netdev_priv(dev); |
| 2020 | struct ehea_adapter *adapter = port->adapter; |
| 2021 | struct hcp_ehea_port_cb1 *cb1; |
| 2022 | u64 hret; |
| 2023 | |
| 2024 | port->vgrp = grp; |
| 2025 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2026 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2027 | if (!cb1) { |
| 2028 | ehea_error("no mem for cb1"); |
| 2029 | goto out; |
| 2030 | } |
| 2031 | |
Thomas Klein | dec590c | 2007-06-06 20:53:16 +0200 | [diff] [blame] | 2032 | memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter)); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2033 | |
| 2034 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, |
| 2035 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2036 | if (hret != H_SUCCESS) |
| 2037 | ehea_error("modify_ehea_port failed"); |
| 2038 | |
| 2039 | kfree(cb1); |
| 2040 | out: |
| 2041 | return; |
| 2042 | } |
| 2043 | |
| 2044 | static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) |
| 2045 | { |
| 2046 | struct ehea_port *port = netdev_priv(dev); |
| 2047 | struct ehea_adapter *adapter = port->adapter; |
| 2048 | struct hcp_ehea_port_cb1 *cb1; |
| 2049 | int index; |
| 2050 | u64 hret; |
| 2051 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2052 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2053 | if (!cb1) { |
| 2054 | ehea_error("no mem for cb1"); |
| 2055 | goto out; |
| 2056 | } |
| 2057 | |
| 2058 | hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id, |
| 2059 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2060 | if (hret != H_SUCCESS) { |
| 2061 | ehea_error("query_ehea_port failed"); |
| 2062 | goto out; |
| 2063 | } |
| 2064 | |
| 2065 | index = (vid / 64); |
Thomas Klein | dec590c | 2007-06-06 20:53:16 +0200 | [diff] [blame] | 2066 | cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F))); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2067 | |
| 2068 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, |
| 2069 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2070 | if (hret != H_SUCCESS) |
| 2071 | ehea_error("modify_ehea_port failed"); |
| 2072 | out: |
| 2073 | kfree(cb1); |
| 2074 | return; |
| 2075 | } |
| 2076 | |
| 2077 | static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
| 2078 | { |
| 2079 | struct ehea_port *port = netdev_priv(dev); |
| 2080 | struct ehea_adapter *adapter = port->adapter; |
| 2081 | struct hcp_ehea_port_cb1 *cb1; |
| 2082 | int index; |
| 2083 | u64 hret; |
| 2084 | |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 2085 | vlan_group_set_device(port->vgrp, vid, NULL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2086 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2087 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2088 | if (!cb1) { |
| 2089 | ehea_error("no mem for cb1"); |
| 2090 | goto out; |
| 2091 | } |
| 2092 | |
| 2093 | hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id, |
| 2094 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2095 | if (hret != H_SUCCESS) { |
| 2096 | ehea_error("query_ehea_port failed"); |
| 2097 | goto out; |
| 2098 | } |
| 2099 | |
| 2100 | index = (vid / 64); |
Thomas Klein | dec590c | 2007-06-06 20:53:16 +0200 | [diff] [blame] | 2101 | cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F))); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2102 | |
| 2103 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, |
| 2104 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); |
| 2105 | if (hret != H_SUCCESS) |
| 2106 | ehea_error("modify_ehea_port failed"); |
| 2107 | out: |
| 2108 | kfree(cb1); |
| 2109 | return; |
| 2110 | } |
| 2111 | |
| 2112 | int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp) |
| 2113 | { |
| 2114 | int ret = -EIO; |
| 2115 | u64 hret; |
| 2116 | u16 dummy16 = 0; |
| 2117 | u64 dummy64 = 0; |
| 2118 | struct hcp_modify_qp_cb0* cb0; |
| 2119 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2120 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2121 | if (!cb0) { |
| 2122 | ret = -ENOMEM; |
| 2123 | goto out; |
| 2124 | } |
| 2125 | |
| 2126 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2127 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); |
| 2128 | if (hret != H_SUCCESS) { |
| 2129 | ehea_error("query_ehea_qp failed (1)"); |
| 2130 | goto out; |
| 2131 | } |
| 2132 | |
| 2133 | cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED; |
| 2134 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2135 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, |
| 2136 | &dummy64, &dummy64, &dummy16, &dummy16); |
| 2137 | if (hret != H_SUCCESS) { |
| 2138 | ehea_error("modify_ehea_qp failed (1)"); |
| 2139 | goto out; |
| 2140 | } |
| 2141 | |
| 2142 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2143 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); |
| 2144 | if (hret != H_SUCCESS) { |
| 2145 | ehea_error("query_ehea_qp failed (2)"); |
| 2146 | goto out; |
| 2147 | } |
| 2148 | |
| 2149 | cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED; |
| 2150 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2151 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, |
| 2152 | &dummy64, &dummy64, &dummy16, &dummy16); |
| 2153 | if (hret != H_SUCCESS) { |
| 2154 | ehea_error("modify_ehea_qp failed (2)"); |
| 2155 | goto out; |
| 2156 | } |
| 2157 | |
| 2158 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2159 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); |
| 2160 | if (hret != H_SUCCESS) { |
| 2161 | ehea_error("query_ehea_qp failed (3)"); |
| 2162 | goto out; |
| 2163 | } |
| 2164 | |
| 2165 | cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND; |
| 2166 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2167 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, |
| 2168 | &dummy64, &dummy64, &dummy16, &dummy16); |
| 2169 | if (hret != H_SUCCESS) { |
| 2170 | ehea_error("modify_ehea_qp failed (3)"); |
| 2171 | goto out; |
| 2172 | } |
| 2173 | |
| 2174 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2175 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); |
| 2176 | if (hret != H_SUCCESS) { |
| 2177 | ehea_error("query_ehea_qp failed (4)"); |
| 2178 | goto out; |
| 2179 | } |
| 2180 | |
| 2181 | ret = 0; |
| 2182 | out: |
| 2183 | kfree(cb0); |
| 2184 | return ret; |
| 2185 | } |
| 2186 | |
| 2187 | static int ehea_port_res_setup(struct ehea_port *port, int def_qps, |
| 2188 | int add_tx_qps) |
| 2189 | { |
| 2190 | int ret, i; |
| 2191 | struct port_res_cfg pr_cfg, pr_cfg_small_rx; |
| 2192 | enum ehea_eq_type eq_type = EHEA_EQ; |
| 2193 | |
| 2194 | port->qp_eq = ehea_create_eq(port->adapter, eq_type, |
| 2195 | EHEA_MAX_ENTRIES_EQ, 1); |
| 2196 | if (!port->qp_eq) { |
| 2197 | ret = -EINVAL; |
| 2198 | ehea_error("ehea_create_eq failed (qp_eq)"); |
| 2199 | goto out_kill_eq; |
| 2200 | } |
| 2201 | |
| 2202 | pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries; |
Jan-Bernd Themann | 18604c5 | 2007-02-28 18:34:10 +0100 | [diff] [blame] | 2203 | pr_cfg.max_entries_scq = sq_entries * 2; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2204 | pr_cfg.max_entries_sq = sq_entries; |
| 2205 | pr_cfg.max_entries_rq1 = rq1_entries; |
| 2206 | pr_cfg.max_entries_rq2 = rq2_entries; |
| 2207 | pr_cfg.max_entries_rq3 = rq3_entries; |
| 2208 | |
| 2209 | pr_cfg_small_rx.max_entries_rcq = 1; |
| 2210 | pr_cfg_small_rx.max_entries_scq = sq_entries; |
| 2211 | pr_cfg_small_rx.max_entries_sq = sq_entries; |
| 2212 | pr_cfg_small_rx.max_entries_rq1 = 1; |
| 2213 | pr_cfg_small_rx.max_entries_rq2 = 1; |
| 2214 | pr_cfg_small_rx.max_entries_rq3 = 1; |
| 2215 | |
| 2216 | for (i = 0; i < def_qps; i++) { |
| 2217 | ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i); |
| 2218 | if (ret) |
| 2219 | goto out_clean_pr; |
| 2220 | } |
| 2221 | for (i = def_qps; i < def_qps + add_tx_qps; i++) { |
| 2222 | ret = ehea_init_port_res(port, &port->port_res[i], |
| 2223 | &pr_cfg_small_rx, i); |
| 2224 | if (ret) |
| 2225 | goto out_clean_pr; |
| 2226 | } |
| 2227 | |
| 2228 | return 0; |
| 2229 | |
| 2230 | out_clean_pr: |
| 2231 | while (--i >= 0) |
| 2232 | ehea_clean_portres(port, &port->port_res[i]); |
| 2233 | |
| 2234 | out_kill_eq: |
| 2235 | ehea_destroy_eq(port->qp_eq); |
| 2236 | return ret; |
| 2237 | } |
| 2238 | |
| 2239 | static int ehea_clean_all_portres(struct ehea_port *port) |
| 2240 | { |
| 2241 | int ret = 0; |
| 2242 | int i; |
| 2243 | |
| 2244 | for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) |
| 2245 | ret |= ehea_clean_portres(port, &port->port_res[i]); |
| 2246 | |
| 2247 | ret |= ehea_destroy_eq(port->qp_eq); |
| 2248 | |
| 2249 | return ret; |
| 2250 | } |
| 2251 | |
Thomas Klein | 35cf2e2 | 2007-08-06 13:55:14 +0200 | [diff] [blame] | 2252 | static void ehea_remove_adapter_mr(struct ehea_adapter *adapter) |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 2253 | { |
Thomas Klein | 35cf2e2 | 2007-08-06 13:55:14 +0200 | [diff] [blame] | 2254 | if (adapter->active_ports) |
| 2255 | return; |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 2256 | |
| 2257 | ehea_rem_mr(&adapter->mr); |
| 2258 | } |
| 2259 | |
Thomas Klein | 35cf2e2 | 2007-08-06 13:55:14 +0200 | [diff] [blame] | 2260 | static int ehea_add_adapter_mr(struct ehea_adapter *adapter) |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 2261 | { |
Thomas Klein | 35cf2e2 | 2007-08-06 13:55:14 +0200 | [diff] [blame] | 2262 | if (adapter->active_ports) |
| 2263 | return 0; |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 2264 | |
| 2265 | return ehea_reg_kernel_mr(adapter, &adapter->mr); |
| 2266 | } |
| 2267 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2268 | static int ehea_up(struct net_device *dev) |
| 2269 | { |
| 2270 | int ret, i; |
| 2271 | struct ehea_port *port = netdev_priv(dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2272 | |
| 2273 | if (port->state == EHEA_PORT_UP) |
| 2274 | return 0; |
| 2275 | |
| 2276 | ret = ehea_port_res_setup(port, port->num_def_qps, |
| 2277 | port->num_add_tx_qps); |
| 2278 | if (ret) { |
| 2279 | ehea_error("port_res_failed"); |
| 2280 | goto out; |
| 2281 | } |
| 2282 | |
| 2283 | /* Set default QP for this port */ |
| 2284 | ret = ehea_configure_port(port); |
| 2285 | if (ret) { |
| 2286 | ehea_error("ehea_configure_port failed. ret:%d", ret); |
| 2287 | goto out_clean_pr; |
| 2288 | } |
| 2289 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2290 | ret = ehea_reg_interrupts(dev); |
| 2291 | if (ret) { |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 2292 | ehea_error("reg_interrupts failed. ret:%d", ret); |
| 2293 | goto out_clean_pr; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
| 2297 | ret = ehea_activate_qp(port->adapter, port->port_res[i].qp); |
| 2298 | if (ret) { |
| 2299 | ehea_error("activate_qp failed"); |
| 2300 | goto out_free_irqs; |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | for(i = 0; i < port->num_def_qps; i++) { |
| 2305 | ret = ehea_fill_port_res(&port->port_res[i]); |
| 2306 | if (ret) { |
| 2307 | ehea_error("out_free_irqs"); |
| 2308 | goto out_free_irqs; |
| 2309 | } |
| 2310 | } |
| 2311 | |
| 2312 | ret = 0; |
| 2313 | port->state = EHEA_PORT_UP; |
| 2314 | goto out; |
| 2315 | |
| 2316 | out_free_irqs: |
| 2317 | ehea_free_interrupts(dev); |
| 2318 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2319 | out_clean_pr: |
| 2320 | ehea_clean_all_portres(port); |
| 2321 | out: |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2322 | if (ret) |
| 2323 | ehea_info("Failed starting %s. ret=%i", dev->name, ret); |
| 2324 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2325 | return ret; |
| 2326 | } |
| 2327 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2328 | static void port_napi_disable(struct ehea_port *port) |
| 2329 | { |
| 2330 | int i; |
| 2331 | |
| 2332 | for (i = 0; i < port->num_def_qps; i++) |
| 2333 | napi_disable(&port->port_res[i].napi); |
| 2334 | } |
| 2335 | |
| 2336 | static void port_napi_enable(struct ehea_port *port) |
| 2337 | { |
| 2338 | int i; |
| 2339 | |
| 2340 | for (i = 0; i < port->num_def_qps; i++) |
| 2341 | napi_enable(&port->port_res[i].napi); |
| 2342 | } |
| 2343 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2344 | static int ehea_open(struct net_device *dev) |
| 2345 | { |
| 2346 | int ret; |
| 2347 | struct ehea_port *port = netdev_priv(dev); |
| 2348 | |
| 2349 | down(&port->port_lock); |
| 2350 | |
| 2351 | if (netif_msg_ifup(port)) |
| 2352 | ehea_info("enabling port %s", dev->name); |
| 2353 | |
| 2354 | ret = ehea_up(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2355 | if (!ret) { |
| 2356 | port_napi_enable(port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2357 | netif_start_queue(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2358 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2359 | |
| 2360 | up(&port->port_lock); |
| 2361 | |
| 2362 | return ret; |
| 2363 | } |
| 2364 | |
| 2365 | static int ehea_down(struct net_device *dev) |
| 2366 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2367 | int ret; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2368 | struct ehea_port *port = netdev_priv(dev); |
| 2369 | |
| 2370 | if (port->state == EHEA_PORT_DOWN) |
| 2371 | return 0; |
| 2372 | |
| 2373 | ehea_drop_multicast_list(dev); |
| 2374 | ehea_free_interrupts(dev); |
| 2375 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2376 | port_napi_disable(port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2377 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2378 | port->state = EHEA_PORT_DOWN; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2379 | |
| 2380 | ret = ehea_clean_all_portres(port); |
| 2381 | if (ret) |
| 2382 | ehea_info("Failed freeing resources for %s. ret=%i", |
| 2383 | dev->name, ret); |
| 2384 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2385 | return ret; |
| 2386 | } |
| 2387 | |
| 2388 | static int ehea_stop(struct net_device *dev) |
| 2389 | { |
| 2390 | int ret; |
| 2391 | struct ehea_port *port = netdev_priv(dev); |
| 2392 | |
| 2393 | if (netif_msg_ifdown(port)) |
| 2394 | ehea_info("disabling port %s", dev->name); |
| 2395 | |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 2396 | flush_scheduled_work(); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2397 | down(&port->port_lock); |
| 2398 | netif_stop_queue(dev); |
| 2399 | ret = ehea_down(dev); |
| 2400 | up(&port->port_lock); |
| 2401 | return ret; |
| 2402 | } |
| 2403 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2404 | void ehea_purge_sq(struct ehea_qp *orig_qp) |
| 2405 | { |
| 2406 | struct ehea_qp qp = *orig_qp; |
| 2407 | struct ehea_qp_init_attr *init_attr = &qp.init_attr; |
| 2408 | struct ehea_swqe *swqe; |
| 2409 | int wqe_index; |
| 2410 | int i; |
| 2411 | |
| 2412 | for (i = 0; i < init_attr->act_nr_send_wqes; i++) { |
| 2413 | swqe = ehea_get_swqe(&qp, &wqe_index); |
| 2414 | swqe->tx_control |= EHEA_SWQE_PURGE; |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | int ehea_stop_qps(struct net_device *dev) |
| 2419 | { |
| 2420 | struct ehea_port *port = netdev_priv(dev); |
| 2421 | struct ehea_adapter *adapter = port->adapter; |
| 2422 | struct hcp_modify_qp_cb0* cb0; |
| 2423 | int ret = -EIO; |
| 2424 | int dret; |
| 2425 | int i; |
| 2426 | u64 hret; |
| 2427 | u64 dummy64 = 0; |
| 2428 | u16 dummy16 = 0; |
| 2429 | |
| 2430 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 2431 | if (!cb0) { |
| 2432 | ret = -ENOMEM; |
| 2433 | goto out; |
| 2434 | } |
| 2435 | |
| 2436 | for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) { |
| 2437 | struct ehea_port_res *pr = &port->port_res[i]; |
| 2438 | struct ehea_qp *qp = pr->qp; |
| 2439 | |
| 2440 | /* Purge send queue */ |
| 2441 | ehea_purge_sq(qp); |
| 2442 | |
| 2443 | /* Disable queue pair */ |
| 2444 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2445 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), |
| 2446 | cb0); |
| 2447 | if (hret != H_SUCCESS) { |
| 2448 | ehea_error("query_ehea_qp failed (1)"); |
| 2449 | goto out; |
| 2450 | } |
| 2451 | |
| 2452 | cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8; |
| 2453 | cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED; |
| 2454 | |
| 2455 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2456 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, |
| 2457 | 1), cb0, &dummy64, |
| 2458 | &dummy64, &dummy16, &dummy16); |
| 2459 | if (hret != H_SUCCESS) { |
| 2460 | ehea_error("modify_ehea_qp failed (1)"); |
| 2461 | goto out; |
| 2462 | } |
| 2463 | |
| 2464 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2465 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), |
| 2466 | cb0); |
| 2467 | if (hret != H_SUCCESS) { |
| 2468 | ehea_error("query_ehea_qp failed (2)"); |
| 2469 | goto out; |
| 2470 | } |
| 2471 | |
| 2472 | /* deregister shared memory regions */ |
| 2473 | dret = ehea_rem_smrs(pr); |
| 2474 | if (dret) { |
| 2475 | ehea_error("unreg shared memory region failed"); |
| 2476 | goto out; |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | ret = 0; |
| 2481 | out: |
| 2482 | kfree(cb0); |
| 2483 | |
| 2484 | return ret; |
| 2485 | } |
| 2486 | |
| 2487 | void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res * pr) |
| 2488 | { |
| 2489 | struct ehea_qp qp = *orig_qp; |
| 2490 | struct ehea_qp_init_attr *init_attr = &qp.init_attr; |
| 2491 | struct ehea_rwqe *rwqe; |
| 2492 | struct sk_buff **skba_rq2 = pr->rq2_skba.arr; |
| 2493 | struct sk_buff **skba_rq3 = pr->rq3_skba.arr; |
| 2494 | struct sk_buff *skb; |
| 2495 | u32 lkey = pr->recv_mr.lkey; |
| 2496 | |
| 2497 | |
| 2498 | int i; |
| 2499 | int index; |
| 2500 | |
| 2501 | for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) { |
| 2502 | rwqe = ehea_get_next_rwqe(&qp, 2); |
| 2503 | rwqe->sg_list[0].l_key = lkey; |
| 2504 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id); |
| 2505 | skb = skba_rq2[index]; |
| 2506 | if (skb) |
| 2507 | rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data); |
| 2508 | } |
| 2509 | |
| 2510 | for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) { |
| 2511 | rwqe = ehea_get_next_rwqe(&qp, 3); |
| 2512 | rwqe->sg_list[0].l_key = lkey; |
| 2513 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id); |
| 2514 | skb = skba_rq3[index]; |
| 2515 | if (skb) |
| 2516 | rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data); |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | int ehea_restart_qps(struct net_device *dev) |
| 2521 | { |
| 2522 | struct ehea_port *port = netdev_priv(dev); |
| 2523 | struct ehea_adapter *adapter = port->adapter; |
| 2524 | int ret = 0; |
| 2525 | int i; |
| 2526 | |
| 2527 | struct hcp_modify_qp_cb0* cb0; |
| 2528 | u64 hret; |
| 2529 | u64 dummy64 = 0; |
| 2530 | u16 dummy16 = 0; |
| 2531 | |
| 2532 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 2533 | if (!cb0) { |
| 2534 | ret = -ENOMEM; |
| 2535 | goto out; |
| 2536 | } |
| 2537 | |
| 2538 | for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) { |
| 2539 | struct ehea_port_res *pr = &port->port_res[i]; |
| 2540 | struct ehea_qp *qp = pr->qp; |
| 2541 | |
| 2542 | ret = ehea_gen_smrs(pr); |
| 2543 | if (ret) { |
| 2544 | ehea_error("creation of shared memory regions failed"); |
| 2545 | goto out; |
| 2546 | } |
| 2547 | |
| 2548 | ehea_update_rqs(qp, pr); |
| 2549 | |
| 2550 | /* Enable queue pair */ |
| 2551 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2552 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), |
| 2553 | cb0); |
| 2554 | if (hret != H_SUCCESS) { |
| 2555 | ehea_error("query_ehea_qp failed (1)"); |
| 2556 | goto out; |
| 2557 | } |
| 2558 | |
| 2559 | cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8; |
| 2560 | cb0->qp_ctl_reg |= H_QP_CR_ENABLED; |
| 2561 | |
| 2562 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2563 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, |
| 2564 | 1), cb0, &dummy64, |
| 2565 | &dummy64, &dummy16, &dummy16); |
| 2566 | if (hret != H_SUCCESS) { |
| 2567 | ehea_error("modify_ehea_qp failed (1)"); |
| 2568 | goto out; |
| 2569 | } |
| 2570 | |
| 2571 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, |
| 2572 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), |
| 2573 | cb0); |
| 2574 | if (hret != H_SUCCESS) { |
| 2575 | ehea_error("query_ehea_qp failed (2)"); |
| 2576 | goto out; |
| 2577 | } |
| 2578 | |
| 2579 | /* refill entire queue */ |
| 2580 | ehea_refill_rq1(pr, pr->rq1_skba.index, 0); |
| 2581 | ehea_refill_rq2(pr, 0); |
| 2582 | ehea_refill_rq3(pr, 0); |
| 2583 | } |
| 2584 | out: |
| 2585 | kfree(cb0); |
| 2586 | |
| 2587 | return ret; |
| 2588 | } |
| 2589 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2590 | static void ehea_reset_port(struct work_struct *work) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2591 | { |
| 2592 | int ret; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2593 | struct ehea_port *port = |
| 2594 | container_of(work, struct ehea_port, reset_task); |
| 2595 | struct net_device *dev = port->netdev; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2596 | |
| 2597 | port->resets++; |
| 2598 | down(&port->port_lock); |
| 2599 | netif_stop_queue(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2600 | |
| 2601 | port_napi_disable(port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2602 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2603 | ehea_down(dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2604 | |
| 2605 | ret = ehea_up(dev); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2606 | if (ret) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2607 | goto out; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2608 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2609 | ehea_set_multicast_list(dev); |
| 2610 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2611 | if (netif_msg_timer(port)) |
| 2612 | ehea_info("Device %s resetted successfully", dev->name); |
| 2613 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2614 | port_napi_enable(port); |
| 2615 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2616 | netif_wake_queue(dev); |
| 2617 | out: |
| 2618 | up(&port->port_lock); |
| 2619 | return; |
| 2620 | } |
| 2621 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2622 | static void ehea_rereg_mrs(struct work_struct *work) |
| 2623 | { |
| 2624 | int ret, i; |
| 2625 | struct ehea_adapter *adapter; |
| 2626 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2627 | down(&dlpar_mem_lock); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2628 | ehea_info("LPAR memory enlarged - re-initializing driver"); |
| 2629 | |
| 2630 | list_for_each_entry(adapter, &adapter_list, list) |
| 2631 | if (adapter->active_ports) { |
| 2632 | /* Shutdown all ports */ |
| 2633 | for (i = 0; i < EHEA_MAX_PORTS; i++) { |
| 2634 | struct ehea_port *port = adapter->port[i]; |
| 2635 | |
| 2636 | if (port) { |
| 2637 | struct net_device *dev = port->netdev; |
| 2638 | |
| 2639 | if (dev->flags & IFF_UP) { |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2640 | down(&port->port_lock); |
| 2641 | netif_stop_queue(dev); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2642 | ret = ehea_stop_qps(dev); |
| 2643 | if (ret) { |
| 2644 | up(&port->port_lock); |
| 2645 | goto out; |
| 2646 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2647 | port_napi_disable(port); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2648 | up(&port->port_lock); |
| 2649 | } |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | /* Unregister old memory region */ |
| 2654 | ret = ehea_rem_mr(&adapter->mr); |
| 2655 | if (ret) { |
| 2656 | ehea_error("unregister MR failed - driver" |
| 2657 | " inoperable!"); |
| 2658 | goto out; |
| 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | ehea_destroy_busmap(); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2663 | ret = ehea_create_busmap(); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2664 | if (ret) { |
| 2665 | ehea_error("creating ehea busmap failed"); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2666 | goto out; |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2667 | } |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2668 | |
| 2669 | clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags); |
| 2670 | |
| 2671 | list_for_each_entry(adapter, &adapter_list, list) |
| 2672 | if (adapter->active_ports) { |
| 2673 | /* Register new memory region */ |
| 2674 | ret = ehea_reg_kernel_mr(adapter, &adapter->mr); |
| 2675 | if (ret) { |
| 2676 | ehea_error("register MR failed - driver" |
| 2677 | " inoperable!"); |
| 2678 | goto out; |
| 2679 | } |
| 2680 | |
| 2681 | /* Restart all ports */ |
| 2682 | for (i = 0; i < EHEA_MAX_PORTS; i++) { |
| 2683 | struct ehea_port *port = adapter->port[i]; |
| 2684 | |
| 2685 | if (port) { |
| 2686 | struct net_device *dev = port->netdev; |
| 2687 | |
| 2688 | if (dev->flags & IFF_UP) { |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2689 | down(&port->port_lock); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2690 | port_napi_enable(port); |
| 2691 | ret = ehea_restart_qps(dev); |
| 2692 | if (!ret) |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2693 | netif_wake_queue(dev); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2694 | up(&port->port_lock); |
| 2695 | } |
| 2696 | } |
| 2697 | } |
| 2698 | } |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2699 | up(&dlpar_mem_lock); |
| 2700 | ehea_info("re-initializing driver complete"); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2701 | out: |
| 2702 | return; |
| 2703 | } |
| 2704 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2705 | static void ehea_tx_watchdog(struct net_device *dev) |
| 2706 | { |
| 2707 | struct ehea_port *port = netdev_priv(dev); |
| 2708 | |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 2709 | if (netif_carrier_ok(dev) && |
| 2710 | !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags)) |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 2711 | schedule_work(&port->reset_task); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | int ehea_sense_adapter_attr(struct ehea_adapter *adapter) |
| 2715 | { |
| 2716 | struct hcp_query_ehea *cb; |
| 2717 | u64 hret; |
| 2718 | int ret; |
| 2719 | |
Thomas Klein | a1d261c | 2006-11-03 17:48:23 +0100 | [diff] [blame] | 2720 | cb = kzalloc(PAGE_SIZE, GFP_KERNEL); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2721 | if (!cb) { |
| 2722 | ret = -ENOMEM; |
| 2723 | goto out; |
| 2724 | } |
| 2725 | |
| 2726 | hret = ehea_h_query_ehea(adapter->handle, cb); |
| 2727 | |
| 2728 | if (hret != H_SUCCESS) { |
| 2729 | ret = -EIO; |
| 2730 | goto out_herr; |
| 2731 | } |
| 2732 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2733 | adapter->max_mc_mac = cb->max_mc_mac - 1; |
| 2734 | ret = 0; |
| 2735 | |
| 2736 | out_herr: |
| 2737 | kfree(cb); |
| 2738 | out: |
| 2739 | return ret; |
| 2740 | } |
| 2741 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2742 | int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo) |
| 2743 | { |
| 2744 | struct hcp_ehea_port_cb4 *cb4; |
| 2745 | u64 hret; |
| 2746 | int ret = 0; |
| 2747 | |
| 2748 | *jumbo = 0; |
| 2749 | |
| 2750 | /* (Try to) enable *jumbo frames */ |
| 2751 | cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 2752 | if (!cb4) { |
| 2753 | ehea_error("no mem for cb4"); |
| 2754 | ret = -ENOMEM; |
| 2755 | goto out; |
| 2756 | } else { |
| 2757 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
| 2758 | port->logical_port_id, |
| 2759 | H_PORT_CB4, |
| 2760 | H_PORT_CB4_JUMBO, cb4); |
| 2761 | if (hret == H_SUCCESS) { |
| 2762 | if (cb4->jumbo_frame) |
| 2763 | *jumbo = 1; |
| 2764 | else { |
| 2765 | cb4->jumbo_frame = 1; |
| 2766 | hret = ehea_h_modify_ehea_port(port->adapter-> |
| 2767 | handle, |
| 2768 | port-> |
| 2769 | logical_port_id, |
| 2770 | H_PORT_CB4, |
| 2771 | H_PORT_CB4_JUMBO, |
| 2772 | cb4); |
| 2773 | if (hret == H_SUCCESS) |
| 2774 | *jumbo = 1; |
| 2775 | } |
| 2776 | } else |
| 2777 | ret = -EINVAL; |
| 2778 | |
| 2779 | kfree(cb4); |
| 2780 | } |
| 2781 | out: |
| 2782 | return ret; |
| 2783 | } |
| 2784 | |
| 2785 | static ssize_t ehea_show_port_id(struct device *dev, |
| 2786 | struct device_attribute *attr, char *buf) |
| 2787 | { |
| 2788 | struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev); |
Jan-Bernd Themann | a8e34fd | 2007-08-22 16:20:58 +0200 | [diff] [blame] | 2789 | return sprintf(buf, "%d", port->logical_port_id); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id, |
| 2793 | NULL); |
| 2794 | |
| 2795 | static void __devinit logical_port_release(struct device *dev) |
| 2796 | { |
| 2797 | struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev); |
| 2798 | of_node_put(port->ofdev.node); |
| 2799 | } |
| 2800 | |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 2801 | static int ehea_driver_sysfs_add(struct device *dev, |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 2802 | struct device_driver *driver) |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 2803 | { |
| 2804 | int ret; |
| 2805 | |
| 2806 | ret = sysfs_create_link(&driver->kobj, &dev->kobj, |
| 2807 | kobject_name(&dev->kobj)); |
| 2808 | if (ret == 0) { |
| 2809 | ret = sysfs_create_link(&dev->kobj, &driver->kobj, |
| 2810 | "driver"); |
| 2811 | if (ret) |
| 2812 | sysfs_remove_link(&driver->kobj, |
| 2813 | kobject_name(&dev->kobj)); |
| 2814 | } |
| 2815 | return ret; |
| 2816 | } |
| 2817 | |
| 2818 | static void ehea_driver_sysfs_remove(struct device *dev, |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 2819 | struct device_driver *driver) |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 2820 | { |
| 2821 | struct device_driver *drv = driver; |
| 2822 | |
| 2823 | if (drv) { |
| 2824 | sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj)); |
| 2825 | sysfs_remove_link(&dev->kobj, "driver"); |
| 2826 | } |
| 2827 | } |
| 2828 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2829 | static struct device *ehea_register_port(struct ehea_port *port, |
| 2830 | struct device_node *dn) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2831 | { |
| 2832 | int ret; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2833 | |
| 2834 | port->ofdev.node = of_node_get(dn); |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 2835 | port->ofdev.dev.parent = &port->adapter->ofdev->dev; |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 2836 | port->ofdev.dev.bus = &ibmebus_bus_type; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2837 | |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 2838 | sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2839 | port->ofdev.dev.release = logical_port_release; |
| 2840 | |
| 2841 | ret = of_device_register(&port->ofdev); |
| 2842 | if (ret) { |
| 2843 | ehea_error("failed to register device. ret=%d", ret); |
| 2844 | goto out; |
| 2845 | } |
| 2846 | |
| 2847 | ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id); |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 2848 | if (ret) { |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2849 | ehea_error("failed to register attributes, ret=%d", ret); |
| 2850 | goto out_unreg_of_dev; |
| 2851 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 2852 | |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 2853 | ret = ehea_driver_sysfs_add(&port->ofdev.dev, &ehea_driver.driver); |
| 2854 | if (ret) { |
| 2855 | ehea_error("failed to register sysfs driver link"); |
| 2856 | goto out_rem_dev_file; |
| 2857 | } |
| 2858 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2859 | return &port->ofdev.dev; |
| 2860 | |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 2861 | out_rem_dev_file: |
| 2862 | device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2863 | out_unreg_of_dev: |
| 2864 | of_device_unregister(&port->ofdev); |
| 2865 | out: |
| 2866 | return NULL; |
| 2867 | } |
| 2868 | |
| 2869 | static void ehea_unregister_port(struct ehea_port *port) |
| 2870 | { |
Thomas Klein | d1dea38 | 2007-04-26 11:56:13 +0200 | [diff] [blame] | 2871 | ehea_driver_sysfs_remove(&port->ofdev.dev, &ehea_driver.driver); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2872 | device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id); |
| 2873 | of_device_unregister(&port->ofdev); |
| 2874 | } |
| 2875 | |
| 2876 | struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter, |
| 2877 | u32 logical_port_id, |
| 2878 | struct device_node *dn) |
| 2879 | { |
| 2880 | int ret; |
| 2881 | struct net_device *dev; |
| 2882 | struct ehea_port *port; |
| 2883 | struct device *port_dev; |
| 2884 | int jumbo; |
| 2885 | |
| 2886 | /* allocate memory for the port structures */ |
| 2887 | dev = alloc_etherdev(sizeof(struct ehea_port)); |
| 2888 | |
| 2889 | if (!dev) { |
| 2890 | ehea_error("no mem for net_device"); |
| 2891 | ret = -ENOMEM; |
| 2892 | goto out_err; |
| 2893 | } |
| 2894 | |
| 2895 | port = netdev_priv(dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2896 | |
| 2897 | sema_init(&port->port_lock, 1); |
| 2898 | port->state = EHEA_PORT_DOWN; |
| 2899 | port->sig_comp_iv = sq_entries / 10; |
| 2900 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2901 | port->adapter = adapter; |
| 2902 | port->netdev = dev; |
| 2903 | port->logical_port_id = logical_port_id; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2904 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2905 | port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2906 | |
| 2907 | port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL); |
| 2908 | if (!port->mc_list) { |
| 2909 | ret = -ENOMEM; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2910 | goto out_free_ethdev; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | INIT_LIST_HEAD(&port->mc_list->list); |
| 2914 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2915 | ret = ehea_sense_port_attr(port); |
| 2916 | if (ret) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2917 | goto out_free_mc_list; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2918 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2919 | port_dev = ehea_register_port(port, dn); |
| 2920 | if (!port_dev) |
| 2921 | goto out_free_mc_list; |
Thomas Klein | 9c750b7 | 2007-01-29 18:44:01 +0100 | [diff] [blame] | 2922 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2923 | SET_NETDEV_DEV(dev, port_dev); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2924 | |
| 2925 | /* initialize net_device structure */ |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2926 | memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN); |
| 2927 | |
| 2928 | dev->open = ehea_open; |
Jan-Bernd Themann | 8d22c97 | 2007-07-23 16:05:03 +0200 | [diff] [blame] | 2929 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2930 | dev->poll_controller = ehea_netpoll; |
| 2931 | #endif |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2932 | dev->stop = ehea_stop; |
| 2933 | dev->hard_start_xmit = ehea_start_xmit; |
| 2934 | dev->get_stats = ehea_get_stats; |
| 2935 | dev->set_multicast_list = ehea_set_multicast_list; |
| 2936 | dev->set_mac_address = ehea_set_mac_addr; |
| 2937 | dev->change_mtu = ehea_change_mtu; |
| 2938 | dev->vlan_rx_register = ehea_vlan_rx_register; |
| 2939 | dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid; |
| 2940 | dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid; |
| 2941 | dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO |
| 2942 | | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX |
| 2943 | | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER |
| 2944 | | NETIF_F_LLTX; |
| 2945 | dev->tx_timeout = &ehea_tx_watchdog; |
| 2946 | dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT; |
| 2947 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2948 | INIT_WORK(&port->reset_task, ehea_reset_port); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2949 | |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 2950 | ret = ehea_broadcast_reg_helper(port, H_REG_BCMC); |
| 2951 | if (ret) { |
| 2952 | ret = -EIO; |
| 2953 | goto out_unreg_port; |
| 2954 | } |
| 2955 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2956 | ehea_set_ethtool_ops(dev); |
| 2957 | |
| 2958 | ret = register_netdev(dev); |
| 2959 | if (ret) { |
| 2960 | ehea_error("register_netdev failed. ret=%d", ret); |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 2961 | goto out_dereg_bc; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2962 | } |
| 2963 | |
Jan-Bernd Themann | d4dc4ec | 2007-09-25 16:16:34 -0700 | [diff] [blame] | 2964 | port->lro_max_aggr = lro_max_aggr; |
| 2965 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2966 | ret = ehea_get_jumboframe_status(port, &jumbo); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 2967 | if (ret) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2968 | ehea_error("failed determining jumbo frame status for %s", |
| 2969 | port->netdev->name); |
| 2970 | |
Thomas Klein | 9c750b7 | 2007-01-29 18:44:01 +0100 | [diff] [blame] | 2971 | ehea_info("%s: Jumbo frames are %sabled", dev->name, |
| 2972 | jumbo == 1 ? "en" : "dis"); |
| 2973 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 2974 | adapter->active_ports++; |
| 2975 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2976 | return port; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2977 | |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 2978 | out_dereg_bc: |
| 2979 | ehea_broadcast_reg_helper(port, H_DEREG_BCMC); |
| 2980 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2981 | out_unreg_port: |
| 2982 | ehea_unregister_port(port); |
| 2983 | |
| 2984 | out_free_mc_list: |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 2985 | kfree(port->mc_list); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 2986 | |
| 2987 | out_free_ethdev: |
| 2988 | free_netdev(dev); |
| 2989 | |
| 2990 | out_err: |
| 2991 | ehea_error("setting up logical port with id=%d failed, ret=%d", |
| 2992 | logical_port_id, ret); |
| 2993 | return NULL; |
| 2994 | } |
| 2995 | |
| 2996 | static void ehea_shutdown_single_port(struct ehea_port *port) |
| 2997 | { |
| 2998 | unregister_netdev(port->netdev); |
| 2999 | ehea_unregister_port(port); |
Thomas Klein | f9e2922 | 2007-07-18 17:34:09 +0200 | [diff] [blame] | 3000 | ehea_broadcast_reg_helper(port, H_DEREG_BCMC); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3001 | kfree(port->mc_list); |
| 3002 | free_netdev(port->netdev); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3003 | port->adapter->active_ports--; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | static int ehea_setup_ports(struct ehea_adapter *adapter) |
| 3007 | { |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3008 | struct device_node *lhea_dn; |
| 3009 | struct device_node *eth_dn = NULL; |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3010 | |
Stephen Rothwell | 9f9a3b8 | 2007-05-01 13:51:32 +1000 | [diff] [blame] | 3011 | const u32 *dn_log_port_id; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3012 | int i = 0; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3013 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3014 | lhea_dn = adapter->ofdev->node; |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3015 | while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3016 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 3017 | dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no", |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3018 | NULL); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3019 | if (!dn_log_port_id) { |
| 3020 | ehea_error("bad device node: eth_dn name=%s", |
| 3021 | eth_dn->full_name); |
| 3022 | continue; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3023 | } |
| 3024 | |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3025 | if (ehea_add_adapter_mr(adapter)) { |
| 3026 | ehea_error("creating MR failed"); |
| 3027 | of_node_put(eth_dn); |
| 3028 | return -EIO; |
| 3029 | } |
| 3030 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3031 | adapter->port[i] = ehea_setup_single_port(adapter, |
| 3032 | *dn_log_port_id, |
| 3033 | eth_dn); |
| 3034 | if (adapter->port[i]) |
| 3035 | ehea_info("%s -> logical port id #%d", |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3036 | adapter->port[i]->netdev->name, |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3037 | *dn_log_port_id); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3038 | else |
| 3039 | ehea_remove_adapter_mr(adapter); |
| 3040 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3041 | i++; |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3042 | }; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3043 | |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3044 | return 0; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3045 | } |
| 3046 | |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3047 | static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter, |
| 3048 | u32 logical_port_id) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3049 | { |
| 3050 | struct device_node *lhea_dn; |
| 3051 | struct device_node *eth_dn = NULL; |
Stephen Rothwell | 9f9a3b8 | 2007-05-01 13:51:32 +1000 | [diff] [blame] | 3052 | const u32 *dn_log_port_id; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3053 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3054 | lhea_dn = adapter->ofdev->node; |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3055 | while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3056 | |
Stephen Rothwell | 40cd3a4 | 2007-05-01 13:54:02 +1000 | [diff] [blame] | 3057 | dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no", |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3058 | NULL); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3059 | if (dn_log_port_id) |
| 3060 | if (*dn_log_port_id == logical_port_id) |
| 3061 | return eth_dn; |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3062 | }; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3063 | |
| 3064 | return NULL; |
| 3065 | } |
| 3066 | |
| 3067 | static ssize_t ehea_probe_port(struct device *dev, |
| 3068 | struct device_attribute *attr, |
| 3069 | const char *buf, size_t count) |
| 3070 | { |
| 3071 | struct ehea_adapter *adapter = dev->driver_data; |
| 3072 | struct ehea_port *port; |
| 3073 | struct device_node *eth_dn = NULL; |
| 3074 | int i; |
| 3075 | |
| 3076 | u32 logical_port_id; |
| 3077 | |
Jan-Bernd Themann | a8e34fd | 2007-08-22 16:20:58 +0200 | [diff] [blame] | 3078 | sscanf(buf, "%d", &logical_port_id); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3079 | |
| 3080 | port = ehea_get_port(adapter, logical_port_id); |
| 3081 | |
| 3082 | if (port) { |
| 3083 | ehea_info("adding port with logical port id=%d failed. port " |
| 3084 | "already configured as %s.", logical_port_id, |
| 3085 | port->netdev->name); |
| 3086 | return -EINVAL; |
| 3087 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3088 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3089 | eth_dn = ehea_get_eth_dn(adapter, logical_port_id); |
| 3090 | |
| 3091 | if (!eth_dn) { |
| 3092 | ehea_info("no logical port with id %d found", logical_port_id); |
| 3093 | return -EINVAL; |
| 3094 | } |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3095 | |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3096 | if (ehea_add_adapter_mr(adapter)) { |
| 3097 | ehea_error("creating MR failed"); |
| 3098 | return -EIO; |
| 3099 | } |
| 3100 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3101 | port = ehea_setup_single_port(adapter, logical_port_id, eth_dn); |
| 3102 | |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3103 | of_node_put(eth_dn); |
| 3104 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3105 | if (port) { |
| 3106 | for (i=0; i < EHEA_MAX_PORTS; i++) |
| 3107 | if (!adapter->port[i]) { |
| 3108 | adapter->port[i] = port; |
| 3109 | break; |
| 3110 | } |
| 3111 | |
| 3112 | ehea_info("added %s (logical port id=%d)", port->netdev->name, |
| 3113 | logical_port_id); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3114 | } else { |
| 3115 | ehea_remove_adapter_mr(adapter); |
Jan-Bernd Themann | e542aa6 | 2007-03-22 17:50:24 +0100 | [diff] [blame] | 3116 | return -EIO; |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3117 | } |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3118 | |
| 3119 | return (ssize_t) count; |
| 3120 | } |
| 3121 | |
| 3122 | static ssize_t ehea_remove_port(struct device *dev, |
| 3123 | struct device_attribute *attr, |
| 3124 | const char *buf, size_t count) |
| 3125 | { |
| 3126 | struct ehea_adapter *adapter = dev->driver_data; |
| 3127 | struct ehea_port *port; |
| 3128 | int i; |
| 3129 | u32 logical_port_id; |
| 3130 | |
Jan-Bernd Themann | a8e34fd | 2007-08-22 16:20:58 +0200 | [diff] [blame] | 3131 | sscanf(buf, "%d", &logical_port_id); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3132 | |
| 3133 | port = ehea_get_port(adapter, logical_port_id); |
| 3134 | |
| 3135 | if (port) { |
| 3136 | ehea_info("removed %s (logical port id=%d)", port->netdev->name, |
| 3137 | logical_port_id); |
| 3138 | |
| 3139 | ehea_shutdown_single_port(port); |
| 3140 | |
| 3141 | for (i=0; i < EHEA_MAX_PORTS; i++) |
| 3142 | if (adapter->port[i] == port) { |
| 3143 | adapter->port[i] = NULL; |
| 3144 | break; |
| 3145 | } |
| 3146 | } else { |
| 3147 | ehea_error("removing port with logical port id=%d failed. port " |
| 3148 | "not configured.", logical_port_id); |
| 3149 | return -EINVAL; |
| 3150 | } |
| 3151 | |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3152 | ehea_remove_adapter_mr(adapter); |
| 3153 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3154 | return (ssize_t) count; |
| 3155 | } |
| 3156 | |
| 3157 | static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port); |
| 3158 | static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port); |
| 3159 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3160 | int ehea_create_device_sysfs(struct of_device *dev) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3161 | { |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3162 | int ret = device_create_file(&dev->dev, &dev_attr_probe_port); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3163 | if (ret) |
| 3164 | goto out; |
| 3165 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3166 | ret = device_create_file(&dev->dev, &dev_attr_remove_port); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3167 | out: |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3168 | return ret; |
| 3169 | } |
| 3170 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3171 | void ehea_remove_device_sysfs(struct of_device *dev) |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3172 | { |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3173 | device_remove_file(&dev->dev, &dev_attr_probe_port); |
| 3174 | device_remove_file(&dev->dev, &dev_attr_remove_port); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3175 | } |
| 3176 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3177 | static int __devinit ehea_probe_adapter(struct of_device *dev, |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3178 | const struct of_device_id *id) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3179 | { |
| 3180 | struct ehea_adapter *adapter; |
Stephen Rothwell | 9f9a3b8 | 2007-05-01 13:51:32 +1000 | [diff] [blame] | 3181 | const u64 *adapter_handle; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3182 | int ret; |
| 3183 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3184 | if (!dev || !dev->node) { |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3185 | ehea_error("Invalid ibmebus device probed"); |
| 3186 | return -EINVAL; |
| 3187 | } |
| 3188 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3189 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); |
| 3190 | if (!adapter) { |
| 3191 | ret = -ENOMEM; |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3192 | dev_err(&dev->dev, "no mem for ehea_adapter\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3193 | goto out; |
| 3194 | } |
| 3195 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3196 | list_add(&adapter->list, &adapter_list); |
| 3197 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3198 | adapter->ofdev = dev; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3199 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3200 | adapter_handle = of_get_property(dev->node, "ibm,hea-handle", |
Jan-Bernd Themann | d1d25aa | 2007-07-02 13:00:46 +0200 | [diff] [blame] | 3201 | NULL); |
Thomas Klein | 061bf3c | 2007-01-22 12:52:20 +0100 | [diff] [blame] | 3202 | if (adapter_handle) |
| 3203 | adapter->handle = *adapter_handle; |
| 3204 | |
| 3205 | if (!adapter->handle) { |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3206 | dev_err(&dev->dev, "failed getting handle for adapter" |
| 3207 | " '%s'\n", dev->node->full_name); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3208 | ret = -ENODEV; |
| 3209 | goto out_free_ad; |
| 3210 | } |
| 3211 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3212 | adapter->pd = EHEA_PD_ID; |
| 3213 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3214 | dev->dev.driver_data = adapter; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3215 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3216 | |
| 3217 | /* initialize adapter and ports */ |
| 3218 | /* get adapter properties */ |
| 3219 | ret = ehea_sense_adapter_attr(adapter); |
| 3220 | if (ret) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame^] | 3221 | dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3222 | goto out_free_ad; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3223 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3224 | |
| 3225 | adapter->neq = ehea_create_eq(adapter, |
| 3226 | EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1); |
| 3227 | if (!adapter->neq) { |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3228 | ret = -EIO; |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame^] | 3229 | dev_err(&dev->dev, "NEQ creation failed\n"); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3230 | goto out_free_ad; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet, |
| 3234 | (unsigned long)adapter); |
| 3235 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3236 | ret = ibmebus_request_irq(adapter->neq->attr.ist1, |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 3237 | ehea_interrupt_neq, IRQF_DISABLED, |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3238 | "ehea_neq", adapter); |
| 3239 | if (ret) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame^] | 3240 | dev_err(&dev->dev, "requesting NEQ IRQ failed\n"); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3241 | goto out_kill_eq; |
| 3242 | } |
| 3243 | |
Jan-Bernd Themann | 1eef4e0 | 2007-03-22 17:49:42 +0100 | [diff] [blame] | 3244 | ret = ehea_create_device_sysfs(dev); |
| 3245 | if (ret) |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 3246 | goto out_free_irq; |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3247 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3248 | ret = ehea_setup_ports(adapter); |
| 3249 | if (ret) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame^] | 3250 | dev_err(&dev->dev, "setup_ports failed\n"); |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3251 | goto out_rem_dev_sysfs; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | ret = 0; |
| 3255 | goto out; |
| 3256 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3257 | out_rem_dev_sysfs: |
| 3258 | ehea_remove_device_sysfs(dev); |
| 3259 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3260 | out_free_irq: |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3261 | ibmebus_free_irq(adapter->neq->attr.ist1, adapter); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3262 | |
| 3263 | out_kill_eq: |
| 3264 | ehea_destroy_eq(adapter->neq); |
| 3265 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3266 | out_free_ad: |
| 3267 | kfree(adapter); |
| 3268 | out: |
| 3269 | return ret; |
| 3270 | } |
| 3271 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3272 | static int __devexit ehea_remove(struct of_device *dev) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3273 | { |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3274 | struct ehea_adapter *adapter = dev->dev.driver_data; |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3275 | int i; |
| 3276 | |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3277 | for (i = 0; i < EHEA_MAX_PORTS; i++) |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3278 | if (adapter->port[i]) { |
| 3279 | ehea_shutdown_single_port(adapter->port[i]); |
| 3280 | adapter->port[i] = NULL; |
| 3281 | } |
Jan-Bernd Themann | 1acf231 | 2007-02-28 18:34:02 +0100 | [diff] [blame] | 3282 | |
| 3283 | ehea_remove_device_sysfs(dev); |
| 3284 | |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 3285 | flush_scheduled_work(); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3286 | |
Joachim Fenkes | 6b08f3a | 2007-09-26 19:45:51 +1000 | [diff] [blame] | 3287 | ibmebus_free_irq(adapter->neq->attr.ist1, adapter); |
Thomas Klein | d4150a2 | 2007-01-29 18:44:41 +0100 | [diff] [blame] | 3288 | tasklet_kill(&adapter->neq_tasklet); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3289 | |
| 3290 | ehea_destroy_eq(adapter->neq); |
Thomas Klein | 1211bb6 | 2007-04-26 11:56:43 +0200 | [diff] [blame] | 3291 | ehea_remove_adapter_mr(adapter); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3292 | list_del(&adapter->list); |
| 3293 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3294 | kfree(adapter); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3295 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3296 | return 0; |
| 3297 | } |
| 3298 | |
| 3299 | static int check_module_parm(void) |
| 3300 | { |
| 3301 | int ret = 0; |
| 3302 | |
| 3303 | if ((rq1_entries < EHEA_MIN_ENTRIES_QP) || |
| 3304 | (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) { |
| 3305 | ehea_info("Bad parameter: rq1_entries"); |
| 3306 | ret = -EINVAL; |
| 3307 | } |
| 3308 | if ((rq2_entries < EHEA_MIN_ENTRIES_QP) || |
| 3309 | (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) { |
| 3310 | ehea_info("Bad parameter: rq2_entries"); |
| 3311 | ret = -EINVAL; |
| 3312 | } |
| 3313 | if ((rq3_entries < EHEA_MIN_ENTRIES_QP) || |
| 3314 | (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) { |
| 3315 | ehea_info("Bad parameter: rq3_entries"); |
| 3316 | ret = -EINVAL; |
| 3317 | } |
| 3318 | if ((sq_entries < EHEA_MIN_ENTRIES_QP) || |
| 3319 | (sq_entries > EHEA_MAX_ENTRIES_SQ)) { |
| 3320 | ehea_info("Bad parameter: sq_entries"); |
| 3321 | ret = -EINVAL; |
| 3322 | } |
| 3323 | |
| 3324 | return ret; |
| 3325 | } |
| 3326 | |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3327 | static ssize_t ehea_show_capabilities(struct device_driver *drv, |
| 3328 | char *buf) |
| 3329 | { |
| 3330 | return sprintf(buf, "%d", EHEA_CAPABILITIES); |
| 3331 | } |
| 3332 | |
| 3333 | static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH, |
| 3334 | ehea_show_capabilities, NULL); |
| 3335 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3336 | int __init ehea_module_init(void) |
| 3337 | { |
| 3338 | int ret; |
| 3339 | |
| 3340 | printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n", |
| 3341 | DRV_VERSION); |
| 3342 | |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3343 | |
| 3344 | INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs); |
Jan-Bernd Themann | 2c69448 | 2007-10-01 16:33:18 +0200 | [diff] [blame] | 3345 | sema_init(&dlpar_mem_lock, 1); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3346 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3347 | ret = check_module_parm(); |
| 3348 | if (ret) |
| 3349 | goto out; |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3350 | |
| 3351 | ret = ehea_create_busmap(); |
| 3352 | if (ret) |
| 3353 | goto out; |
| 3354 | |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3355 | ret = ibmebus_register_driver(&ehea_driver); |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3356 | if (ret) { |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3357 | ehea_error("failed registering eHEA device driver on ebus"); |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3358 | goto out; |
| 3359 | } |
| 3360 | |
| 3361 | ret = driver_create_file(&ehea_driver.driver, |
| 3362 | &driver_attr_capabilities); |
| 3363 | if (ret) { |
| 3364 | ehea_error("failed to register capabilities attribute, ret=%d", |
| 3365 | ret); |
| 3366 | ibmebus_unregister_driver(&ehea_driver); |
| 3367 | goto out; |
| 3368 | } |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3369 | |
| 3370 | out: |
| 3371 | return ret; |
| 3372 | } |
| 3373 | |
| 3374 | static void __exit ehea_module_exit(void) |
| 3375 | { |
Jan-Bernd Themann | 3bf76b8 | 2007-10-08 16:01:33 +0200 | [diff] [blame] | 3376 | flush_scheduled_work(); |
Jan-Bernd Themann | 4c3ca4d | 2007-07-05 09:26:25 +0200 | [diff] [blame] | 3377 | driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3378 | ibmebus_unregister_driver(&ehea_driver); |
Thomas Klein | 44c8215 | 2007-07-11 16:32:00 +0200 | [diff] [blame] | 3379 | ehea_destroy_busmap(); |
Jan-Bernd Themann | 7a29108 | 2006-09-13 17:44:31 +0200 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | module_init(ehea_module_init); |
| 3383 | module_exit(ehea_module_exit); |