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