blob: f0319f1e8e052e99adfde7ca658cfaf7074b1ac1 [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
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>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020036#include <linux/notifier.h>
37#include <linux/reboot.h>
38
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020039#include <net/ip.h>
40
41#include "ehea.h"
42#include "ehea_qmr.h"
43#include "ehea_phyp.h"
44
45
46MODULE_LICENSE("GPL");
47MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
48MODULE_DESCRIPTION("IBM eServer HEA Driver");
49MODULE_VERSION(DRV_VERSION);
50
51
52static int msg_level = -1;
53static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
54static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
55static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
56static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010057static int use_mcs = 0;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070058static int use_lro = 0;
59static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010060static int num_tx_qps = EHEA_NUM_TX_QP;
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020061static int prop_carrier_state = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020062
63module_param(msg_level, int, 0);
64module_param(rq1_entries, int, 0);
65module_param(rq2_entries, int, 0);
66module_param(rq3_entries, int, 0);
67module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020068module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010069module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070070module_param(use_lro, int, 0);
71module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010072module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020073
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010074MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020075MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020076MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
81MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
84MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
87MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020090MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020091
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070092MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
93 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
94MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
95 "Default = 0");
96
Thomas Kleind1dea382007-04-26 11:56:13 +020097static int port_name_cnt = 0;
Thomas Klein44c82152007-07-11 16:32:00 +020098static LIST_HEAD(adapter_list);
99u64 ehea_driver_flags = 0;
Thomas Klein44c82152007-07-11 16:32:00 +0200100struct work_struct ehea_rereg_mr_task;
101
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200102struct semaphore dlpar_mem_lock;
Thomas Kleind1dea382007-04-26 11:56:13 +0200103
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000104static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200105 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200106
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000107static int __devexit ehea_remove(struct of_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200108
109static struct of_device_id ehea_device_table[] = {
110 {
111 .name = "lhea",
112 .compatible = "IBM,lhea",
113 },
114 {},
115};
116
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000117static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200118 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000119 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200120 .probe = ehea_probe_adapter,
121 .remove = ehea_remove,
122};
123
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200124void ehea_dump(void *adr, int len, char *msg) {
125 int x;
126 unsigned char *deb = adr;
127 for (x = 0; x < len; x += 16) {
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100128 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200129 deb, x, *((u64*)&deb[0]), *((u64*)&deb[8]));
130 deb += 16;
131 }
132}
133
134static struct net_device_stats *ehea_get_stats(struct net_device *dev)
135{
136 struct ehea_port *port = netdev_priv(dev);
137 struct net_device_stats *stats = &port->stats;
138 struct hcp_ehea_port_cb2 *cb2;
139 u64 hret, rx_packets;
140 int i;
141
142 memset(stats, 0, sizeof(*stats));
143
Thomas Kleina1d261c2006-11-03 17:48:23 +0100144 cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200145 if (!cb2) {
146 ehea_error("no mem for cb2");
147 goto out;
148 }
149
150 hret = ehea_h_query_ehea_port(port->adapter->handle,
151 port->logical_port_id,
152 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
153 if (hret != H_SUCCESS) {
154 ehea_error("query_ehea_port failed");
155 goto out_herr;
156 }
157
158 if (netif_msg_hw(port))
159 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
160
161 rx_packets = 0;
162 for (i = 0; i < port->num_def_qps; i++)
163 rx_packets += port->port_res[i].rx_packets;
164
165 stats->tx_packets = cb2->txucp + cb2->txmcp + cb2->txbcp;
166 stats->multicast = cb2->rxmcp;
167 stats->rx_errors = cb2->rxuerr;
168 stats->rx_bytes = cb2->rxo;
169 stats->tx_bytes = cb2->txo;
170 stats->rx_packets = rx_packets;
171
172out_herr:
173 kfree(cb2);
174out:
175 return stats;
176}
177
178static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
179{
180 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
181 struct net_device *dev = pr->port->netdev;
182 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200183 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
184 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200185 int i;
186
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200187 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200188
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200189 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
190 pr->rq1_skba.index = index;
191 pr->rq1_skba.os_skbs = fill_wqes;
192 return;
193 }
194
195 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200196 if (!skb_arr_rq1[index]) {
197 skb_arr_rq1[index] = netdev_alloc_skb(dev,
198 EHEA_L_PKT_SIZE);
199 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200200 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200201 ehea_error("%s: no mem for skb/%d wqes filled",
202 dev->name, i);
203 break;
204 }
205 }
206 index--;
207 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200208 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200209 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200210
211 if (adder == 0)
212 return;
213
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200214 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200215 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200216}
217
218static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
219{
220 int ret = 0;
221 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
222 struct net_device *dev = pr->port->netdev;
223 int i;
224
225 for (i = 0; i < pr->rq1_skba.len; i++) {
226 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
227 if (!skb_arr_rq1[i]) {
228 ehea_error("%s: no mem for skb/%d wqes filled",
229 dev->name, i);
230 ret = -ENOMEM;
231 goto out;
232 }
233 }
234 /* Ring doorbell */
235 ehea_update_rq1a(pr->qp, nr_rq1a);
236out:
237 return ret;
238}
239
240static int ehea_refill_rq_def(struct ehea_port_res *pr,
241 struct ehea_q_skb_arr *q_skba, int rq_nr,
242 int num_wqes, int wqe_type, int packet_size)
243{
244 struct net_device *dev = pr->port->netdev;
245 struct ehea_qp *qp = pr->qp;
246 struct sk_buff **skb_arr = q_skba->arr;
247 struct ehea_rwqe *rwqe;
248 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200249 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200250 int ret = 0;
251
252 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200253 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200254
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200255 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
256 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200257 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200258 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200259
260 index = q_skba->index;
261 max_index_mask = q_skba->len - 1;
262 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200263 u64 tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200264 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
265 if (!skb) {
266 ehea_error("%s: no mem for skb/%d wqes filled",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100267 pr->port->netdev->name, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200268 q_skba->os_skbs = fill_wqes - i;
269 ret = -ENOMEM;
270 break;
271 }
272 skb_reserve(skb, NET_IP_ALIGN);
273
274 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200275 tmp_addr = ehea_map_vaddr(skb->data);
276 if (tmp_addr == -1) {
277 dev_kfree_skb(skb);
278 q_skba->os_skbs = fill_wqes - i;
279 ret = 0;
280 break;
281 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200282
283 rwqe = ehea_get_next_rwqe(qp, rq_nr);
284 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200285 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200286 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200287 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200288 rwqe->sg_list[0].len = packet_size;
289 rwqe->data_segments = 1;
290
291 index++;
292 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200293 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200294 }
Thomas Klein44c82152007-07-11 16:32:00 +0200295
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200296 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200297 if (adder == 0)
298 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200299
300 /* Ring doorbell */
301 iosync();
302 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200303 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200304 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200305 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200306out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200307 return ret;
308}
309
310
311static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
312{
313 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
314 nr_of_wqes, EHEA_RWQE2_TYPE,
315 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
316}
317
318
319static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
320{
321 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
322 nr_of_wqes, EHEA_RWQE3_TYPE,
323 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
324}
325
326static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
327{
328 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
329 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
330 return 0;
331 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
332 (cqe->header_length == 0))
333 return 0;
334 return -EINVAL;
335}
336
337static inline void ehea_fill_skb(struct net_device *dev,
338 struct sk_buff *skb, struct ehea_cqe *cqe)
339{
340 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
341
342 skb_put(skb, length);
343 skb->ip_summed = CHECKSUM_UNNECESSARY;
344 skb->protocol = eth_type_trans(skb, dev);
345}
346
347static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
348 int arr_len,
349 struct ehea_cqe *cqe)
350{
351 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
352 struct sk_buff *skb;
353 void *pref;
354 int x;
355
356 x = skb_index + 1;
357 x &= (arr_len - 1);
358
359 pref = skb_array[x];
360 prefetchw(pref);
361 prefetchw(pref + EHEA_CACHE_LINE);
362
363 pref = (skb_array[x]->data);
364 prefetch(pref);
365 prefetch(pref + EHEA_CACHE_LINE);
366 prefetch(pref + EHEA_CACHE_LINE * 2);
367 prefetch(pref + EHEA_CACHE_LINE * 3);
368 skb = skb_array[skb_index];
369 skb_array[skb_index] = NULL;
370 return skb;
371}
372
373static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
374 int arr_len, int wqe_index)
375{
376 struct sk_buff *skb;
377 void *pref;
378 int x;
379
380 x = wqe_index + 1;
381 x &= (arr_len - 1);
382
383 pref = skb_array[x];
384 prefetchw(pref);
385 prefetchw(pref + EHEA_CACHE_LINE);
386
387 pref = (skb_array[x]->data);
388 prefetchw(pref);
389 prefetchw(pref + EHEA_CACHE_LINE);
390
391 skb = skb_array[wqe_index];
392 skb_array[wqe_index] = NULL;
393 return skb;
394}
395
396static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
397 struct ehea_cqe *cqe, int *processed_rq2,
398 int *processed_rq3)
399{
400 struct sk_buff *skb;
401
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100402 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
403 pr->p_stats.err_tcp_cksum++;
404 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
405 pr->p_stats.err_ip_cksum++;
406 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
407 pr->p_stats.err_frame_crc++;
408
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200409 if (netif_msg_rx_err(pr->port)) {
410 ehea_error("CQE Error for QP %d", pr->qp->init_attr.qp_nr);
411 ehea_dump(cqe, sizeof(*cqe), "CQE");
412 }
413
414 if (rq == 2) {
415 *processed_rq2 += 1;
416 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
417 dev_kfree_skb(skb);
418 } else if (rq == 3) {
419 *processed_rq3 += 1;
420 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
421 dev_kfree_skb(skb);
422 }
423
424 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
425 ehea_error("Critical receive error. Resetting port.");
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200426 schedule_work(&pr->port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200427 return 1;
428 }
429
430 return 0;
431}
432
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700433static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
434 void **tcph, u64 *hdr_flags, void *priv)
435{
436 struct ehea_cqe *cqe = priv;
437 unsigned int ip_len;
438 struct iphdr *iph;
439
440 /* non tcp/udp packets */
441 if (!cqe->header_length)
442 return -1;
443
444 /* non tcp packet */
445 skb_reset_network_header(skb);
446 iph = ip_hdr(skb);
447 if (iph->protocol != IPPROTO_TCP)
448 return -1;
449
450 ip_len = ip_hdrlen(skb);
451 skb_set_transport_header(skb, ip_len);
452 *tcph = tcp_hdr(skb);
453
454 /* check if ip header and tcp header are complete */
455 if (iph->tot_len < ip_len + tcp_hdrlen(skb))
456 return -1;
457
458 *hdr_flags = LRO_IPV4 | LRO_TCP;
459 *iphdr = iph;
460
461 return 0;
462}
463
464static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
465 struct sk_buff *skb)
466{
467 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
468 && pr->port->vgrp;
469
470 if (use_lro) {
471 if (vlan_extracted)
472 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
473 pr->port->vgrp,
474 cqe->vlan_tag,
475 cqe);
476 else
477 lro_receive_skb(&pr->lro_mgr, skb, cqe);
478 } else {
479 if (vlan_extracted)
480 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
481 cqe->vlan_tag);
482 else
483 netif_receive_skb(skb);
484 }
485}
486
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700487static int ehea_proc_rwqes(struct net_device *dev,
488 struct ehea_port_res *pr,
489 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200490{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100491 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200492 struct ehea_qp *qp = pr->qp;
493 struct ehea_cqe *cqe;
494 struct sk_buff *skb;
495 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
496 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
497 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
498 int skb_arr_rq1_len = pr->rq1_skba.len;
499 int skb_arr_rq2_len = pr->rq2_skba.len;
500 int skb_arr_rq3_len = pr->rq3_skba.len;
501 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700502 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200503
504 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
505 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200506
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200507 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700508 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200509 ehea_inc_rq1(qp);
510 processed_rq1++;
511 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 if (netif_msg_rx_status(port))
513 ehea_dump(cqe, sizeof(*cqe), "CQE");
514
515 last_wqe_index = wqe_index;
516 rmb();
517 if (!ehea_check_cqe(cqe, &rq)) {
518 if (rq == 1) { /* LL RQ1 */
519 skb = get_skb_by_index_ll(skb_arr_rq1,
520 skb_arr_rq1_len,
521 wqe_index);
522 if (unlikely(!skb)) {
523 if (netif_msg_rx_err(port))
524 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100525
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700526 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200527 EHEA_L_PKT_SIZE);
528 if (!skb)
529 break;
530 }
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300531 skb_copy_to_linear_data(skb, ((char*)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200532 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700533 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200534 } else if (rq == 2) { /* RQ2 */
535 skb = get_skb_by_index(skb_arr_rq2,
536 skb_arr_rq2_len, cqe);
537 if (unlikely(!skb)) {
538 if (netif_msg_rx_err(port))
539 ehea_error("rq2: skb=NULL");
540 break;
541 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700542 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200543 processed_rq2++;
544 } else { /* RQ3 */
545 skb = get_skb_by_index(skb_arr_rq3,
546 skb_arr_rq3_len, cqe);
547 if (unlikely(!skb)) {
548 if (netif_msg_rx_err(port))
549 ehea_error("rq3: skb=NULL");
550 break;
551 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700552 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200553 processed_rq3++;
554 }
555
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700556 ehea_proc_skb(pr, cqe, skb);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700557 dev->last_rx = jiffies;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100558 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100559 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200560 port_reset = ehea_treat_poll_error(pr, rq, cqe,
561 &processed_rq2,
562 &processed_rq3);
563 if (port_reset)
564 break;
565 }
566 cqe = ehea_poll_rq1(qp, &wqe_index);
567 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700568 if (use_lro)
569 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200570
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200571 pr->rx_packets += processed;
572
573 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
574 ehea_refill_rq2(pr, processed_rq2);
575 ehea_refill_rq3(pr, processed_rq3);
576
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700577 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200578}
579
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100580static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200581{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100582 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200583 struct ehea_cq *send_cq = pr->send_cq;
584 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100585 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200586 int cqe_counter = 0;
587 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100588 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200589 unsigned long flags;
590
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100591 cqe = ehea_poll_cq(send_cq);
592 while(cqe && (quota > 0)) {
593 ehea_inc_cq(send_cq);
594
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200595 cqe_counter++;
596 rmb();
597 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
598 ehea_error("Send Completion Error: Resetting port");
599 if (netif_msg_tx_err(pr->port))
600 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200601 schedule_work(&pr->port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200602 break;
603 }
604
605 if (netif_msg_tx_done(pr->port))
606 ehea_dump(cqe, sizeof(*cqe), "CQE");
607
608 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100609 == EHEA_SWQE2_TYPE)) {
610
611 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
612 skb = pr->sq_skba.arr[index];
613 dev_kfree_skb(skb);
614 pr->sq_skba.arr[index] = NULL;
615 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200616
617 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
618 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100619
620 cqe = ehea_poll_cq(send_cq);
621 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200622
623 ehea_update_feca(send_cq, cqe_counter);
624 atomic_add(swqe_av, &pr->swqe_avail);
625
626 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100627
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200628 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
629 >= pr->swqe_refill_th)) {
630 netif_wake_queue(pr->port->netdev);
631 pr->queue_stopped = 0;
632 }
633 spin_unlock_irqrestore(&pr->netif_queue, flags);
634
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100635 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200636}
637
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100638#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700639#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100640
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700641static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200642{
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700643 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res, napi);
644 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100645 struct ehea_cqe *cqe;
646 struct ehea_cqe *cqe_skb = NULL;
647 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700648 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100649
650 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700651 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100652
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700653 if (!force_irq)
654 rx += ehea_proc_rwqes(dev, pr, budget - rx);
655
656 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100657 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700658 force_irq = 0;
659 netif_rx_complete(dev, napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100660 ehea_reset_cq_ep(pr->recv_cq);
661 ehea_reset_cq_ep(pr->send_cq);
662 ehea_reset_cq_n1(pr->recv_cq);
663 ehea_reset_cq_n1(pr->send_cq);
664 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
665 cqe_skb = ehea_poll_cq(pr->send_cq);
666
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100667 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700668 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100669
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700670 if (!netif_rx_reschedule(dev, napi))
671 return rx;
672
673 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
674 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100675 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100676
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700677 pr->poll_counter++;
678 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200679}
680
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200681#ifdef CONFIG_NET_POLL_CONTROLLER
682static void ehea_netpoll(struct net_device *dev)
683{
684 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700685 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200686
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700687 for (i = 0; i < port->num_def_qps; i++)
688 netif_rx_schedule(dev, &port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200689}
690#endif
691
David Howells7d12e782006-10-05 14:55:46 +0100692static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200693{
694 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100695
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700696 netif_rx_schedule(pr->port->netdev, &pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100697
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200698 return IRQ_HANDLED;
699}
700
David Howells7d12e782006-10-05 14:55:46 +0100701static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200702{
703 struct ehea_port *port = param;
704 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100705 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200706 u32 qp_token;
707
708 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100709
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200710 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200711 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100712 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
713 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100714
715 qp = port->port_res[qp_token].qp;
716 ehea_error_data(port->adapter, qp->fw_handle);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100717 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200718 }
719
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200720 schedule_work(&port->reset_task);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100721
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200722 return IRQ_HANDLED;
723}
724
725static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
726 int logical_port)
727{
728 int i;
729
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100730 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100731 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200732 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100733 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200734 return NULL;
735}
736
737int ehea_sense_port_attr(struct ehea_port *port)
738{
739 int ret;
740 u64 hret;
741 struct hcp_ehea_port_cb0 *cb0;
742
Thomas Kleina1d261c2006-11-03 17:48:23 +0100743 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC); /* May be called via */
744 if (!cb0) { /* ehea_neq_tasklet() */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745 ehea_error("no mem for cb0");
746 ret = -ENOMEM;
747 goto out;
748 }
749
750 hret = ehea_h_query_ehea_port(port->adapter->handle,
751 port->logical_port_id, H_PORT_CB0,
752 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
753 cb0);
754 if (hret != H_SUCCESS) {
755 ret = -EIO;
756 goto out_free;
757 }
758
759 /* MAC address */
760 port->mac_addr = cb0->port_mac_addr << 16;
761
762 if (!is_valid_ether_addr((u8*)&port->mac_addr)) {
763 ret = -EADDRNOTAVAIL;
764 goto out_free;
765 }
766
767 /* Port speed */
768 switch (cb0->port_speed) {
769 case H_SPEED_10M_H:
770 port->port_speed = EHEA_SPEED_10M;
771 port->full_duplex = 0;
772 break;
773 case H_SPEED_10M_F:
774 port->port_speed = EHEA_SPEED_10M;
775 port->full_duplex = 1;
776 break;
777 case H_SPEED_100M_H:
778 port->port_speed = EHEA_SPEED_100M;
779 port->full_duplex = 0;
780 break;
781 case H_SPEED_100M_F:
782 port->port_speed = EHEA_SPEED_100M;
783 port->full_duplex = 1;
784 break;
785 case H_SPEED_1G_F:
786 port->port_speed = EHEA_SPEED_1G;
787 port->full_duplex = 1;
788 break;
789 case H_SPEED_10G_F:
790 port->port_speed = EHEA_SPEED_10G;
791 port->full_duplex = 1;
792 break;
793 default:
794 port->port_speed = 0;
795 port->full_duplex = 0;
796 break;
797 }
798
Thomas Kleine919b592007-01-22 12:53:20 +0100799 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100800 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +0100801
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200802 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100803 if (use_mcs)
804 port->num_def_qps = cb0->num_default_qps;
805 else
806 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200807
808 if (!port->num_def_qps) {
809 ret = -EINVAL;
810 goto out_free;
811 }
812
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100813 port->num_tx_qps = num_tx_qps;
814
815 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200816 port->num_add_tx_qps = 0;
817 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100818 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200819
820 ret = 0;
821out_free:
822 if (ret || netif_msg_probe(port))
823 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
824 kfree(cb0);
825out:
826 return ret;
827}
828
829int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
830{
831 struct hcp_ehea_port_cb4 *cb4;
832 u64 hret;
833 int ret = 0;
834
Thomas Kleina1d261c2006-11-03 17:48:23 +0100835 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200836 if (!cb4) {
837 ehea_error("no mem for cb4");
838 ret = -ENOMEM;
839 goto out;
840 }
841
842 cb4->port_speed = port_speed;
843
844 netif_carrier_off(port->netdev);
845
846 hret = ehea_h_modify_ehea_port(port->adapter->handle,
847 port->logical_port_id,
848 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
849 if (hret == H_SUCCESS) {
850 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
851
852 hret = ehea_h_query_ehea_port(port->adapter->handle,
853 port->logical_port_id,
854 H_PORT_CB4, H_PORT_CB4_SPEED,
855 cb4);
856 if (hret == H_SUCCESS) {
857 switch (cb4->port_speed) {
858 case H_SPEED_10M_H:
859 port->port_speed = EHEA_SPEED_10M;
860 port->full_duplex = 0;
861 break;
862 case H_SPEED_10M_F:
863 port->port_speed = EHEA_SPEED_10M;
864 port->full_duplex = 1;
865 break;
866 case H_SPEED_100M_H:
867 port->port_speed = EHEA_SPEED_100M;
868 port->full_duplex = 0;
869 break;
870 case H_SPEED_100M_F:
871 port->port_speed = EHEA_SPEED_100M;
872 port->full_duplex = 1;
873 break;
874 case H_SPEED_1G_F:
875 port->port_speed = EHEA_SPEED_1G;
876 port->full_duplex = 1;
877 break;
878 case H_SPEED_10G_F:
879 port->port_speed = EHEA_SPEED_10G;
880 port->full_duplex = 1;
881 break;
882 default:
883 port->port_speed = 0;
884 port->full_duplex = 0;
885 break;
886 }
887 } else {
888 ehea_error("Failed sensing port speed");
889 ret = -EIO;
890 }
891 } else {
892 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +0100893 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200894 ret = -EPERM;
895 } else {
896 ret = -EIO;
897 ehea_error("Failed setting port speed");
898 }
899 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +0200900 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
901 netif_carrier_on(port->netdev);
902
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200903 kfree(cb4);
904out:
905 return ret;
906}
907
908static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
909{
910 int ret;
911 u8 ec;
912 u8 portnum;
913 struct ehea_port *port;
914
915 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
916 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
917 port = ehea_get_port(adapter, portnum);
918
919 switch (ec) {
920 case EHEA_EC_PORTSTATE_CHG: /* port state change */
921
922 if (!port) {
923 ehea_error("unknown portnum %x", portnum);
924 break;
925 }
926
927 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
928 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +0200929 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200930 if (ret) {
931 ehea_error("failed resensing port "
932 "attributes");
933 break;
934 }
935
936 if (netif_msg_link(port))
937 ehea_info("%s: Logical port up: %dMbps "
938 "%s Duplex",
939 port->netdev->name,
940 port->port_speed,
941 port->full_duplex ==
942 1 ? "Full" : "Half");
943
944 netif_carrier_on(port->netdev);
945 netif_wake_queue(port->netdev);
946 }
947 } else
948 if (netif_carrier_ok(port->netdev)) {
949 if (netif_msg_link(port))
950 ehea_info("%s: Logical port down",
951 port->netdev->name);
952 netif_carrier_off(port->netdev);
953 netif_stop_queue(port->netdev);
954 }
955
956 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +0200957 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200958 if (netif_msg_link(port))
959 ehea_info("%s: Physical port up",
960 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +0200961 if (prop_carrier_state)
962 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200963 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +0200964 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200965 if (netif_msg_link(port))
966 ehea_info("%s: Physical port down",
967 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +0200968 if (prop_carrier_state)
969 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200970 }
971
972 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
973 ehea_info("External switch port is primary port");
974 else
975 ehea_info("External switch port is backup port");
976
977 break;
978 case EHEA_EC_ADAPTER_MALFUNC:
979 ehea_error("Adapter malfunction");
980 break;
981 case EHEA_EC_PORT_MALFUNC:
982 ehea_info("Port malfunction: Device: %s", port->netdev->name);
983 netif_carrier_off(port->netdev);
984 netif_stop_queue(port->netdev);
985 break;
986 default:
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +0200987 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200988 break;
989 }
990}
991
992static void ehea_neq_tasklet(unsigned long data)
993{
994 struct ehea_adapter *adapter = (struct ehea_adapter*)data;
995 struct ehea_eqe *eqe;
996 u64 event_mask;
997
998 eqe = ehea_poll_eq(adapter->neq);
999 ehea_debug("eqe=%p", eqe);
1000
1001 while (eqe) {
1002 ehea_debug("*eqe=%lx", eqe->entry);
1003 ehea_parse_eqe(adapter, eqe->entry);
1004 eqe = ehea_poll_eq(adapter->neq);
1005 ehea_debug("next eqe=%p", eqe);
1006 }
1007
1008 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1009 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1010 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1011
1012 ehea_h_reset_events(adapter->handle,
1013 adapter->neq->fw_handle, event_mask);
1014}
1015
David Howells7d12e782006-10-05 14:55:46 +01001016static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001017{
1018 struct ehea_adapter *adapter = param;
1019 tasklet_hi_schedule(&adapter->neq_tasklet);
1020 return IRQ_HANDLED;
1021}
1022
1023
1024static int ehea_fill_port_res(struct ehea_port_res *pr)
1025{
1026 int ret;
1027 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1028
1029 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1030 - init_attr->act_nr_rwqes_rq2
1031 - init_attr->act_nr_rwqes_rq3 - 1);
1032
1033 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
1034
1035 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1036
1037 return ret;
1038}
1039
1040static int ehea_reg_interrupts(struct net_device *dev)
1041{
1042 struct ehea_port *port = netdev_priv(dev);
1043 struct ehea_port_res *pr;
1044 int i, ret;
1045
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001046
1047 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1048 dev->name);
1049
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001050 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001051 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001052 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001053 if (ret) {
1054 ehea_error("failed registering irq for qp_aff_irq_handler:"
1055 "ist=%X", port->qp_eq->attr.ist1);
1056 goto out_free_qpeq;
1057 }
1058
1059 if (netif_msg_ifup(port))
1060 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1061 "registered", port->qp_eq->attr.ist1);
1062
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001063
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001064 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1065 pr = &port->port_res[i];
1066 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001067 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001068 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001069 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001070 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001071 pr);
1072 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001073 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001074 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001075 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001076 goto out_free_req;
1077 }
1078 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001079 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1080 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001081 }
1082out:
1083 return ret;
1084
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001085
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001086out_free_req:
1087 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001088 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001089 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001090 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001091
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001092out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001093 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001094 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001095
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001096 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001097
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001098}
1099
1100static void ehea_free_interrupts(struct net_device *dev)
1101{
1102 struct ehea_port *port = netdev_priv(dev);
1103 struct ehea_port_res *pr;
1104 int i;
1105
1106 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001107
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001108 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1109 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001110 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001111 if (netif_msg_intr(port))
1112 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001113 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001114 }
1115
1116 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001117 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001118 if (netif_msg_intr(port))
1119 ehea_info("associated event interrupt for handle 0x%X freed",
1120 port->qp_eq->attr.ist1);
1121}
1122
1123static int ehea_configure_port(struct ehea_port *port)
1124{
1125 int ret, i;
1126 u64 hret, mask;
1127 struct hcp_ehea_port_cb0 *cb0;
1128
1129 ret = -ENOMEM;
Thomas Kleina1d261c2006-11-03 17:48:23 +01001130 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001131 if (!cb0)
1132 goto out;
1133
1134 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1135 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1136 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1137 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1138 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1139 PXLY_RC_VLAN_FILTER)
1140 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1141
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001142 for (i = 0; i < port->num_mcs; i++)
1143 if (use_mcs)
1144 cb0->default_qpn_arr[i] =
1145 port->port_res[i].qp->init_attr.qp_nr;
1146 else
1147 cb0->default_qpn_arr[i] =
1148 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001149
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001150 if (netif_msg_ifup(port))
1151 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1152
1153 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1154 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1155
1156 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1157 port->logical_port_id,
1158 H_PORT_CB0, mask, cb0);
1159 ret = -EIO;
1160 if (hret != H_SUCCESS)
1161 goto out_free;
1162
1163 ret = 0;
1164
1165out_free:
1166 kfree(cb0);
1167out:
1168 return ret;
1169}
1170
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001171int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001172{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001173 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001174 struct ehea_adapter *adapter = pr->port->adapter;
1175
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001176 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1177 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001178 goto out;
1179
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001180 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1181 if (ret)
1182 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001183
1184 return 0;
1185
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001186out_free:
1187 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001188out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001189 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001190 return -EIO;
1191}
1192
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001193int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001194{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001195 if ((ehea_rem_mr(&pr->send_mr))
1196 || (ehea_rem_mr(&pr->recv_mr)))
1197 return -EIO;
1198 else
1199 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001200}
1201
1202static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1203{
1204 int arr_size = sizeof(void*) * max_q_entries;
1205
1206 q_skba->arr = vmalloc(arr_size);
1207 if (!q_skba->arr)
1208 return -ENOMEM;
1209
1210 memset(q_skba->arr, 0, arr_size);
1211
1212 q_skba->len = max_q_entries;
1213 q_skba->index = 0;
1214 q_skba->os_skbs = 0;
1215
1216 return 0;
1217}
1218
1219static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1220 struct port_res_cfg *pr_cfg, int queue_token)
1221{
1222 struct ehea_adapter *adapter = port->adapter;
1223 enum ehea_eq_type eq_type = EHEA_EQ;
1224 struct ehea_qp_init_attr *init_attr = NULL;
1225 int ret = -EIO;
1226
1227 memset(pr, 0, sizeof(struct ehea_port_res));
1228
1229 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001230 spin_lock_init(&pr->xmit_lock);
1231 spin_lock_init(&pr->netif_queue);
1232
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001233 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1234 if (!pr->eq) {
1235 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001236 goto out_free;
1237 }
1238
1239 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001240 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001241 port->logical_port_id);
1242 if (!pr->recv_cq) {
1243 ehea_error("create_cq failed (cq_recv)");
1244 goto out_free;
1245 }
1246
1247 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001248 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001249 port->logical_port_id);
1250 if (!pr->send_cq) {
1251 ehea_error("create_cq failed (cq_send)");
1252 goto out_free;
1253 }
1254
1255 if (netif_msg_ifup(port))
1256 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1257 pr->send_cq->attr.act_nr_of_cqes,
1258 pr->recv_cq->attr.act_nr_of_cqes);
1259
1260 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1261 if (!init_attr) {
1262 ret = -ENOMEM;
1263 ehea_error("no mem for ehea_qp_init_attr");
1264 goto out_free;
1265 }
1266
1267 init_attr->low_lat_rq1 = 1;
1268 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1269 init_attr->rq_count = 3;
1270 init_attr->qp_token = queue_token;
1271 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1272 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1273 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1274 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1275 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1276 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1277 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1278 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1279 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1280 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1281 init_attr->port_nr = port->logical_port_id;
1282 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1283 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1284 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1285
1286 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1287 if (!pr->qp) {
1288 ehea_error("create_qp failed");
1289 ret = -EIO;
1290 goto out_free;
1291 }
1292
1293 if (netif_msg_ifup(port))
1294 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1295 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1296 init_attr->act_nr_send_wqes,
1297 init_attr->act_nr_rwqes_rq1,
1298 init_attr->act_nr_rwqes_rq2,
1299 init_attr->act_nr_rwqes_rq3);
1300
1301 ret = ehea_init_q_skba(&pr->sq_skba, init_attr->act_nr_send_wqes + 1);
1302 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1303 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1304 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1305 if (ret)
1306 goto out_free;
1307
1308 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1309 if (ehea_gen_smrs(pr) != 0) {
1310 ret = -EIO;
1311 goto out_free;
1312 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001313
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001314 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1315
1316 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001317
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001318 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001319
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001320 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1321 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1322 pr->lro_mgr.lro_arr = pr->lro_desc;
1323 pr->lro_mgr.get_skb_header = get_skb_hdr;
1324 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1325 pr->lro_mgr.dev = port->netdev;
1326 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1327 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1328
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001329 ret = 0;
1330 goto out;
1331
1332out_free:
1333 kfree(init_attr);
1334 vfree(pr->sq_skba.arr);
1335 vfree(pr->rq1_skba.arr);
1336 vfree(pr->rq2_skba.arr);
1337 vfree(pr->rq3_skba.arr);
1338 ehea_destroy_qp(pr->qp);
1339 ehea_destroy_cq(pr->send_cq);
1340 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001341 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001342out:
1343 return ret;
1344}
1345
1346static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1347{
1348 int ret, i;
1349
1350 ret = ehea_destroy_qp(pr->qp);
1351
1352 if (!ret) {
1353 ehea_destroy_cq(pr->send_cq);
1354 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001355 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001356
1357 for (i = 0; i < pr->rq1_skba.len; i++)
1358 if (pr->rq1_skba.arr[i])
1359 dev_kfree_skb(pr->rq1_skba.arr[i]);
1360
1361 for (i = 0; i < pr->rq2_skba.len; i++)
1362 if (pr->rq2_skba.arr[i])
1363 dev_kfree_skb(pr->rq2_skba.arr[i]);
1364
1365 for (i = 0; i < pr->rq3_skba.len; i++)
1366 if (pr->rq3_skba.arr[i])
1367 dev_kfree_skb(pr->rq3_skba.arr[i]);
1368
1369 for (i = 0; i < pr->sq_skba.len; i++)
1370 if (pr->sq_skba.arr[i])
1371 dev_kfree_skb(pr->sq_skba.arr[i]);
1372
1373 vfree(pr->rq1_skba.arr);
1374 vfree(pr->rq2_skba.arr);
1375 vfree(pr->rq3_skba.arr);
1376 vfree(pr->sq_skba.arr);
1377 ret = ehea_rem_smrs(pr);
1378 }
1379 return ret;
1380}
1381
1382/*
1383 * The write_* functions store information in swqe which is used by
1384 * the hardware to calculate the ip/tcp/udp checksum
1385 */
1386
1387static inline void write_ip_start_end(struct ehea_swqe *swqe,
1388 const struct sk_buff *skb)
1389{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001390 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001391 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001392}
1393
1394static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1395 const struct sk_buff *skb)
1396{
1397 swqe->tcp_offset =
1398 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1399
1400 swqe->tcp_end = (u16)skb->len - 1;
1401}
1402
1403static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1404 const struct sk_buff *skb)
1405{
1406 swqe->tcp_offset =
1407 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1408
1409 swqe->tcp_end = (u16)skb->len - 1;
1410}
1411
1412
1413static void write_swqe2_TSO(struct sk_buff *skb,
1414 struct ehea_swqe *swqe, u32 lkey)
1415{
1416 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1417 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1418 int skb_data_size = skb->len - skb->data_len;
1419 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001420
1421 /* Packet is TCP with TSO enabled */
1422 swqe->tx_control |= EHEA_SWQE_TSO;
1423 swqe->mss = skb_shinfo(skb)->gso_size;
1424 /* copy only eth/ip/tcp headers to immediate data and
1425 * the rest of skb->data to sg1entry
1426 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001427 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001428
1429 skb_data_size = skb->len - skb->data_len;
1430
1431 if (skb_data_size >= headersize) {
1432 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001433 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001434 swqe->immediate_data_length = headersize;
1435
1436 if (skb_data_size > headersize) {
1437 /* set sg1entry data */
1438 sg1entry->l_key = lkey;
1439 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001440 sg1entry->vaddr =
1441 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001442 swqe->descriptors++;
1443 }
1444 } else
1445 ehea_error("cannot handle fragmented headers");
1446}
1447
1448static void write_swqe2_nonTSO(struct sk_buff *skb,
1449 struct ehea_swqe *swqe, u32 lkey)
1450{
1451 int skb_data_size = skb->len - skb->data_len;
1452 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1453 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001454
1455 /* Packet is any nonTSO type
1456 *
1457 * Copy as much as possible skb->data to immediate data and
1458 * the rest to sg1entry
1459 */
1460 if (skb_data_size >= SWQE2_MAX_IMM) {
1461 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001462 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001463
1464 swqe->immediate_data_length = SWQE2_MAX_IMM;
1465
1466 if (skb_data_size > SWQE2_MAX_IMM) {
1467 /* copy sg1entry data */
1468 sg1entry->l_key = lkey;
1469 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001470 sg1entry->vaddr =
1471 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001472 swqe->descriptors++;
1473 }
1474 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001475 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476 swqe->immediate_data_length = skb_data_size;
1477 }
1478}
1479
1480static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1481 struct ehea_swqe *swqe, u32 lkey)
1482{
1483 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1484 skb_frag_t *frag;
1485 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001486
1487 nfrags = skb_shinfo(skb)->nr_frags;
1488 sg1entry = &swqe->u.immdata_desc.sg_entry;
1489 sg_list = (struct ehea_vsgentry*)&swqe->u.immdata_desc.sg_list;
1490 swqe->descriptors = 0;
1491 sg1entry_contains_frag_data = 0;
1492
1493 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1494 write_swqe2_TSO(skb, swqe, lkey);
1495 else
1496 write_swqe2_nonTSO(skb, swqe, lkey);
1497
1498 /* write descriptors */
1499 if (nfrags > 0) {
1500 if (swqe->descriptors == 0) {
1501 /* sg1entry not yet used */
1502 frag = &skb_shinfo(skb)->frags[0];
1503
1504 /* copy sg1entry data */
1505 sg1entry->l_key = lkey;
1506 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001507 sg1entry->vaddr =
1508 ehea_map_vaddr(page_address(frag->page)
1509 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001510 swqe->descriptors++;
1511 sg1entry_contains_frag_data = 1;
1512 }
1513
1514 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1515
1516 frag = &skb_shinfo(skb)->frags[i];
1517 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1518
1519 sgentry->l_key = lkey;
1520 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001521 sgentry->vaddr =
1522 ehea_map_vaddr(page_address(frag->page)
1523 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001524 swqe->descriptors++;
1525 }
1526 }
1527}
1528
1529static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1530{
1531 int ret = 0;
1532 u64 hret;
1533 u8 reg_type;
1534
1535 /* De/Register untagged packets */
1536 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1537 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1538 port->logical_port_id,
1539 reg_type, port->mac_addr, 0, hcallid);
1540 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001541 ehea_error("%sregistering bc address failed (tagged)",
1542 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543 ret = -EIO;
1544 goto out_herr;
1545 }
1546
1547 /* De/Register VLAN packets */
1548 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1549 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1550 port->logical_port_id,
1551 reg_type, port->mac_addr, 0, hcallid);
1552 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001553 ehea_error("%sregistering bc address failed (vlan)",
1554 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001555 ret = -EIO;
1556 }
1557out_herr:
1558 return ret;
1559}
1560
1561static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1562{
1563 struct ehea_port *port = netdev_priv(dev);
1564 struct sockaddr *mac_addr = sa;
1565 struct hcp_ehea_port_cb0 *cb0;
1566 int ret;
1567 u64 hret;
1568
1569 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1570 ret = -EADDRNOTAVAIL;
1571 goto out;
1572 }
1573
Thomas Kleina1d261c2006-11-03 17:48:23 +01001574 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001575 if (!cb0) {
1576 ehea_error("no mem for cb0");
1577 ret = -ENOMEM;
1578 goto out;
1579 }
1580
1581 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1582
1583 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1584
1585 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1586 port->logical_port_id, H_PORT_CB0,
1587 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1588 if (hret != H_SUCCESS) {
1589 ret = -EIO;
1590 goto out_free;
1591 }
1592
1593 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1594
1595 /* Deregister old MAC in pHYP */
1596 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1597 if (ret)
1598 goto out_free;
1599
1600 port->mac_addr = cb0->port_mac_addr << 16;
1601
1602 /* Register new MAC in pHYP */
1603 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1604 if (ret)
1605 goto out_free;
1606
1607 ret = 0;
1608out_free:
1609 kfree(cb0);
1610out:
1611 return ret;
1612}
1613
1614static void ehea_promiscuous_error(u64 hret, int enable)
1615{
Thomas Klein7674a582007-01-22 12:54:20 +01001616 if (hret == H_AUTHORITY)
1617 ehea_info("Hypervisor denied %sabling promiscuous mode",
1618 enable == 1 ? "en" : "dis");
1619 else
1620 ehea_error("failed %sabling promiscuous mode",
1621 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001622}
1623
1624static void ehea_promiscuous(struct net_device *dev, int enable)
1625{
1626 struct ehea_port *port = netdev_priv(dev);
1627 struct hcp_ehea_port_cb7 *cb7;
1628 u64 hret;
1629
1630 if ((enable && port->promisc) || (!enable && !port->promisc))
1631 return;
1632
Thomas Kleina1d261c2006-11-03 17:48:23 +01001633 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001634 if (!cb7) {
1635 ehea_error("no mem for cb7");
1636 goto out;
1637 }
1638
1639 /* Modify Pxs_DUCQPN in CB7 */
1640 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1641
1642 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1643 port->logical_port_id,
1644 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1645 if (hret) {
1646 ehea_promiscuous_error(hret, enable);
1647 goto out;
1648 }
1649
1650 port->promisc = enable;
1651out:
1652 kfree(cb7);
1653 return;
1654}
1655
1656static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1657 u32 hcallid)
1658{
1659 u64 hret;
1660 u8 reg_type;
1661
1662 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1663 | EHEA_BCMC_UNTAGGED;
1664
1665 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1666 port->logical_port_id,
1667 reg_type, mc_mac_addr, 0, hcallid);
1668 if (hret)
1669 goto out;
1670
1671 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1672 | EHEA_BCMC_VLANID_ALL;
1673
1674 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1675 port->logical_port_id,
1676 reg_type, mc_mac_addr, 0, hcallid);
1677out:
1678 return hret;
1679}
1680
1681static int ehea_drop_multicast_list(struct net_device *dev)
1682{
1683 struct ehea_port *port = netdev_priv(dev);
1684 struct ehea_mc_list *mc_entry = port->mc_list;
1685 struct list_head *pos;
1686 struct list_head *temp;
1687 int ret = 0;
1688 u64 hret;
1689
1690 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1691 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1692
1693 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1694 H_DEREG_BCMC);
1695 if (hret) {
1696 ehea_error("failed deregistering mcast MAC");
1697 ret = -EIO;
1698 }
1699
1700 list_del(pos);
1701 kfree(mc_entry);
1702 }
1703 return ret;
1704}
1705
1706static void ehea_allmulti(struct net_device *dev, int enable)
1707{
1708 struct ehea_port *port = netdev_priv(dev);
1709 u64 hret;
1710
1711 if (!port->allmulti) {
1712 if (enable) {
1713 /* Enable ALLMULTI */
1714 ehea_drop_multicast_list(dev);
1715 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1716 if (!hret)
1717 port->allmulti = 1;
1718 else
1719 ehea_error("failed enabling IFF_ALLMULTI");
1720 }
1721 } else
1722 if (!enable) {
1723 /* Disable ALLMULTI */
1724 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1725 if (!hret)
1726 port->allmulti = 0;
1727 else
1728 ehea_error("failed disabling IFF_ALLMULTI");
1729 }
1730}
1731
1732static void ehea_add_multicast_entry(struct ehea_port* port, u8* mc_mac_addr)
1733{
1734 struct ehea_mc_list *ehea_mcl_entry;
1735 u64 hret;
1736
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001737 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001738 if (!ehea_mcl_entry) {
1739 ehea_error("no mem for mcl_entry");
1740 return;
1741 }
1742
1743 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1744
1745 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1746
1747 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1748 H_REG_BCMC);
1749 if (!hret)
1750 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1751 else {
1752 ehea_error("failed registering mcast MAC");
1753 kfree(ehea_mcl_entry);
1754 }
1755}
1756
1757static void ehea_set_multicast_list(struct net_device *dev)
1758{
1759 struct ehea_port *port = netdev_priv(dev);
1760 struct dev_mc_list *k_mcl_entry;
1761 int ret, i;
1762
1763 if (dev->flags & IFF_PROMISC) {
1764 ehea_promiscuous(dev, 1);
1765 return;
1766 }
1767 ehea_promiscuous(dev, 0);
1768
1769 if (dev->flags & IFF_ALLMULTI) {
1770 ehea_allmulti(dev, 1);
1771 return;
1772 }
1773 ehea_allmulti(dev, 0);
1774
1775 if (dev->mc_count) {
1776 ret = ehea_drop_multicast_list(dev);
1777 if (ret) {
1778 /* Dropping the current multicast list failed.
1779 * Enabling ALL_MULTI is the best we can do.
1780 */
1781 ehea_allmulti(dev, 1);
1782 }
1783
1784 if (dev->mc_count > port->adapter->max_mc_mac) {
1785 ehea_info("Mcast registration limit reached (0x%lx). "
1786 "Use ALLMULTI!",
1787 port->adapter->max_mc_mac);
1788 goto out;
1789 }
1790
1791 for (i = 0, k_mcl_entry = dev->mc_list;
1792 i < dev->mc_count;
1793 i++, k_mcl_entry = k_mcl_entry->next) {
1794 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
1795 }
1796 }
1797out:
1798 return;
1799}
1800
1801static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1802{
1803 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1804 return -EINVAL;
1805 dev->mtu = new_mtu;
1806 return 0;
1807}
1808
1809static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1810 struct ehea_swqe *swqe, u32 lkey)
1811{
1812 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001813 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001814
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001815 /* IPv4 */
1816 swqe->tx_control |= EHEA_SWQE_CRC
1817 | EHEA_SWQE_IP_CHECKSUM
1818 | EHEA_SWQE_TCP_CHECKSUM
1819 | EHEA_SWQE_IMM_DATA_PRESENT
1820 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1821
1822 write_ip_start_end(swqe, skb);
1823
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001824 if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001825 if ((iph->frag_off & IP_MF)
1826 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001827 /* IP fragment, so don't change cs */
1828 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
1829 else
1830 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001831 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001832 write_tcp_offset_end(swqe, skb);
1833 }
1834
1835 /* icmp (big data) and ip segmentation packets (all other ip
1836 packets) do not require any special handling */
1837
1838 } else {
1839 /* Other Ethernet Protocol */
1840 swqe->tx_control |= EHEA_SWQE_CRC
1841 | EHEA_SWQE_IMM_DATA_PRESENT
1842 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1843 }
1844
1845 write_swqe2_data(skb, dev, swqe, lkey);
1846}
1847
1848static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
1849 struct ehea_swqe *swqe)
1850{
1851 int nfrags = skb_shinfo(skb)->nr_frags;
1852 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
1853 skb_frag_t *frag;
1854 int i;
1855
1856 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001857 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001858
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001859 /* IPv4 */
1860 write_ip_start_end(swqe, skb);
1861
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001862 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001863 swqe->tx_control |= EHEA_SWQE_CRC
1864 | EHEA_SWQE_IP_CHECKSUM
1865 | EHEA_SWQE_TCP_CHECKSUM
1866 | EHEA_SWQE_IMM_DATA_PRESENT;
1867
1868 write_tcp_offset_end(swqe, skb);
1869
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001870 } else if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001871 if ((iph->frag_off & IP_MF)
1872 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001873 /* IP fragment, so don't change cs */
1874 swqe->tx_control |= EHEA_SWQE_CRC
1875 | EHEA_SWQE_IMM_DATA_PRESENT;
1876 else {
1877 swqe->tx_control |= EHEA_SWQE_CRC
1878 | EHEA_SWQE_IP_CHECKSUM
1879 | EHEA_SWQE_TCP_CHECKSUM
1880 | EHEA_SWQE_IMM_DATA_PRESENT;
1881
1882 write_udp_offset_end(swqe, skb);
1883 }
1884 } else {
1885 /* icmp (big data) and
1886 ip segmentation packets (all other ip packets) */
1887 swqe->tx_control |= EHEA_SWQE_CRC
1888 | EHEA_SWQE_IP_CHECKSUM
1889 | EHEA_SWQE_IMM_DATA_PRESENT;
1890 }
1891 } else {
1892 /* Other Ethernet Protocol */
1893 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
1894 }
1895 /* copy (immediate) data */
1896 if (nfrags == 0) {
1897 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001898 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001899 } else {
1900 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001901 skb_copy_from_linear_data(skb, imm_data,
1902 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001903 imm_data += skb->len - skb->data_len;
1904
1905 /* ... then copy data from the fragments */
1906 for (i = 0; i < nfrags; i++) {
1907 frag = &skb_shinfo(skb)->frags[i];
1908 memcpy(imm_data,
1909 page_address(frag->page) + frag->page_offset,
1910 frag->size);
1911 imm_data += frag->size;
1912 }
1913 }
1914 swqe->immediate_data_length = skb->len;
1915 dev_kfree_skb(skb);
1916}
1917
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001918static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
1919{
1920 struct tcphdr *tcp;
1921 u32 tmp;
1922
1923 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02001924 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
1925 tcp = (struct tcphdr*)(skb_network_header(skb) + (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001926 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02001927 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001928 return tmp % num_qps;
1929 }
1930 else
1931 return 0;
1932}
1933
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001934static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
1935{
1936 struct ehea_port *port = netdev_priv(dev);
1937 struct ehea_swqe *swqe;
1938 unsigned long flags;
1939 u32 lkey;
1940 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001941 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001942
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001943 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
1944
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001945 if (!spin_trylock(&pr->xmit_lock))
1946 return NETDEV_TX_BUSY;
1947
1948 if (pr->queue_stopped) {
1949 spin_unlock(&pr->xmit_lock);
1950 return NETDEV_TX_BUSY;
1951 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001952
1953 swqe = ehea_get_swqe(pr->qp, &swqe_index);
1954 memset(swqe, 0, SWQE_HEADER_SIZE);
1955 atomic_dec(&pr->swqe_avail);
1956
1957 if (skb->len <= SWQE3_MAX_IMM) {
1958 u32 sig_iv = port->sig_comp_iv;
1959 u32 swqe_num = pr->swqe_id_counter;
1960 ehea_xmit3(skb, dev, swqe);
1961 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
1962 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
1963 if (pr->swqe_ll_count >= (sig_iv - 1)) {
1964 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
1965 sig_iv);
1966 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
1967 pr->swqe_ll_count = 0;
1968 } else
1969 pr->swqe_ll_count += 1;
1970 } else {
1971 swqe->wr_id =
1972 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
1973 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01001974 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001975 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
1976 pr->sq_skba.arr[pr->sq_skba.index] = skb;
1977
1978 pr->sq_skba.index++;
1979 pr->sq_skba.index &= (pr->sq_skba.len - 1);
1980
1981 lkey = pr->send_mr.lkey;
1982 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01001983 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001984 }
1985 pr->swqe_id_counter += 1;
1986
1987 if (port->vgrp && vlan_tx_tag_present(skb)) {
1988 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
1989 swqe->vlan_tag = vlan_tx_tag_get(skb);
1990 }
1991
1992 if (netif_msg_tx_queued(port)) {
1993 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02001994 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001995 }
1996
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02001997 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
1998 netif_stop_queue(dev);
1999 swqe->tx_control |= EHEA_SWQE_PURGE;
2000 }
Thomas Klein44c82152007-07-11 16:32:00 +02002001
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002002 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002003
2004 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2005 spin_lock_irqsave(&pr->netif_queue, flags);
2006 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002007 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002008 netif_stop_queue(dev);
2009 pr->queue_stopped = 1;
2010 }
2011 spin_unlock_irqrestore(&pr->netif_queue, flags);
2012 }
2013 dev->trans_start = jiffies;
2014 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002015
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002016 return NETDEV_TX_OK;
2017}
2018
2019static void ehea_vlan_rx_register(struct net_device *dev,
2020 struct vlan_group *grp)
2021{
2022 struct ehea_port *port = netdev_priv(dev);
2023 struct ehea_adapter *adapter = port->adapter;
2024 struct hcp_ehea_port_cb1 *cb1;
2025 u64 hret;
2026
2027 port->vgrp = grp;
2028
Thomas Kleina1d261c2006-11-03 17:48:23 +01002029 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002030 if (!cb1) {
2031 ehea_error("no mem for cb1");
2032 goto out;
2033 }
2034
Thomas Kleindec590c2007-06-06 20:53:16 +02002035 memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002036
2037 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2038 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2039 if (hret != H_SUCCESS)
2040 ehea_error("modify_ehea_port failed");
2041
2042 kfree(cb1);
2043out:
2044 return;
2045}
2046
2047static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2048{
2049 struct ehea_port *port = netdev_priv(dev);
2050 struct ehea_adapter *adapter = port->adapter;
2051 struct hcp_ehea_port_cb1 *cb1;
2052 int index;
2053 u64 hret;
2054
Thomas Kleina1d261c2006-11-03 17:48:23 +01002055 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002056 if (!cb1) {
2057 ehea_error("no mem for cb1");
2058 goto out;
2059 }
2060
2061 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2062 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2063 if (hret != H_SUCCESS) {
2064 ehea_error("query_ehea_port failed");
2065 goto out;
2066 }
2067
2068 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002069 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002070
2071 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2072 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2073 if (hret != H_SUCCESS)
2074 ehea_error("modify_ehea_port failed");
2075out:
2076 kfree(cb1);
2077 return;
2078}
2079
2080static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2081{
2082 struct ehea_port *port = netdev_priv(dev);
2083 struct ehea_adapter *adapter = port->adapter;
2084 struct hcp_ehea_port_cb1 *cb1;
2085 int index;
2086 u64 hret;
2087
Dan Aloni5c15bde2007-03-02 20:44:51 -08002088 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002089
Thomas Kleina1d261c2006-11-03 17:48:23 +01002090 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002091 if (!cb1) {
2092 ehea_error("no mem for cb1");
2093 goto out;
2094 }
2095
2096 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2097 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2098 if (hret != H_SUCCESS) {
2099 ehea_error("query_ehea_port failed");
2100 goto out;
2101 }
2102
2103 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002104 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002105
2106 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2107 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2108 if (hret != H_SUCCESS)
2109 ehea_error("modify_ehea_port failed");
2110out:
2111 kfree(cb1);
2112 return;
2113}
2114
2115int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2116{
2117 int ret = -EIO;
2118 u64 hret;
2119 u16 dummy16 = 0;
2120 u64 dummy64 = 0;
2121 struct hcp_modify_qp_cb0* cb0;
2122
Thomas Kleina1d261c2006-11-03 17:48:23 +01002123 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002124 if (!cb0) {
2125 ret = -ENOMEM;
2126 goto out;
2127 }
2128
2129 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2130 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2131 if (hret != H_SUCCESS) {
2132 ehea_error("query_ehea_qp failed (1)");
2133 goto out;
2134 }
2135
2136 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2137 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2138 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2139 &dummy64, &dummy64, &dummy16, &dummy16);
2140 if (hret != H_SUCCESS) {
2141 ehea_error("modify_ehea_qp failed (1)");
2142 goto out;
2143 }
2144
2145 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2146 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2147 if (hret != H_SUCCESS) {
2148 ehea_error("query_ehea_qp failed (2)");
2149 goto out;
2150 }
2151
2152 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2153 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2154 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2155 &dummy64, &dummy64, &dummy16, &dummy16);
2156 if (hret != H_SUCCESS) {
2157 ehea_error("modify_ehea_qp failed (2)");
2158 goto out;
2159 }
2160
2161 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2162 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2163 if (hret != H_SUCCESS) {
2164 ehea_error("query_ehea_qp failed (3)");
2165 goto out;
2166 }
2167
2168 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2169 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2170 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2171 &dummy64, &dummy64, &dummy16, &dummy16);
2172 if (hret != H_SUCCESS) {
2173 ehea_error("modify_ehea_qp failed (3)");
2174 goto out;
2175 }
2176
2177 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2178 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2179 if (hret != H_SUCCESS) {
2180 ehea_error("query_ehea_qp failed (4)");
2181 goto out;
2182 }
2183
2184 ret = 0;
2185out:
2186 kfree(cb0);
2187 return ret;
2188}
2189
2190static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2191 int add_tx_qps)
2192{
2193 int ret, i;
2194 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2195 enum ehea_eq_type eq_type = EHEA_EQ;
2196
2197 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2198 EHEA_MAX_ENTRIES_EQ, 1);
2199 if (!port->qp_eq) {
2200 ret = -EINVAL;
2201 ehea_error("ehea_create_eq failed (qp_eq)");
2202 goto out_kill_eq;
2203 }
2204
2205 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002206 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002207 pr_cfg.max_entries_sq = sq_entries;
2208 pr_cfg.max_entries_rq1 = rq1_entries;
2209 pr_cfg.max_entries_rq2 = rq2_entries;
2210 pr_cfg.max_entries_rq3 = rq3_entries;
2211
2212 pr_cfg_small_rx.max_entries_rcq = 1;
2213 pr_cfg_small_rx.max_entries_scq = sq_entries;
2214 pr_cfg_small_rx.max_entries_sq = sq_entries;
2215 pr_cfg_small_rx.max_entries_rq1 = 1;
2216 pr_cfg_small_rx.max_entries_rq2 = 1;
2217 pr_cfg_small_rx.max_entries_rq3 = 1;
2218
2219 for (i = 0; i < def_qps; i++) {
2220 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2221 if (ret)
2222 goto out_clean_pr;
2223 }
2224 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2225 ret = ehea_init_port_res(port, &port->port_res[i],
2226 &pr_cfg_small_rx, i);
2227 if (ret)
2228 goto out_clean_pr;
2229 }
2230
2231 return 0;
2232
2233out_clean_pr:
2234 while (--i >= 0)
2235 ehea_clean_portres(port, &port->port_res[i]);
2236
2237out_kill_eq:
2238 ehea_destroy_eq(port->qp_eq);
2239 return ret;
2240}
2241
2242static int ehea_clean_all_portres(struct ehea_port *port)
2243{
2244 int ret = 0;
2245 int i;
2246
2247 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
2248 ret |= ehea_clean_portres(port, &port->port_res[i]);
2249
2250 ret |= ehea_destroy_eq(port->qp_eq);
2251
2252 return ret;
2253}
2254
Thomas Klein35cf2e22007-08-06 13:55:14 +02002255static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002256{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002257 if (adapter->active_ports)
2258 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002259
2260 ehea_rem_mr(&adapter->mr);
2261}
2262
Thomas Klein35cf2e22007-08-06 13:55:14 +02002263static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002264{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002265 if (adapter->active_ports)
2266 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002267
2268 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2269}
2270
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002271static int ehea_up(struct net_device *dev)
2272{
2273 int ret, i;
2274 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002275
2276 if (port->state == EHEA_PORT_UP)
2277 return 0;
2278
2279 ret = ehea_port_res_setup(port, port->num_def_qps,
2280 port->num_add_tx_qps);
2281 if (ret) {
2282 ehea_error("port_res_failed");
2283 goto out;
2284 }
2285
2286 /* Set default QP for this port */
2287 ret = ehea_configure_port(port);
2288 if (ret) {
2289 ehea_error("ehea_configure_port failed. ret:%d", ret);
2290 goto out_clean_pr;
2291 }
2292
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002293 ret = ehea_reg_interrupts(dev);
2294 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002295 ehea_error("reg_interrupts failed. ret:%d", ret);
2296 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002297 }
2298
2299 for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2300 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2301 if (ret) {
2302 ehea_error("activate_qp failed");
2303 goto out_free_irqs;
2304 }
2305 }
2306
2307 for(i = 0; i < port->num_def_qps; i++) {
2308 ret = ehea_fill_port_res(&port->port_res[i]);
2309 if (ret) {
2310 ehea_error("out_free_irqs");
2311 goto out_free_irqs;
2312 }
2313 }
2314
2315 ret = 0;
2316 port->state = EHEA_PORT_UP;
2317 goto out;
2318
2319out_free_irqs:
2320 ehea_free_interrupts(dev);
2321
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002322out_clean_pr:
2323 ehea_clean_all_portres(port);
2324out:
Thomas Klein44c82152007-07-11 16:32:00 +02002325 if (ret)
2326 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002328 return ret;
2329}
2330
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002331static void port_napi_disable(struct ehea_port *port)
2332{
2333 int i;
2334
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002335 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002336 napi_disable(&port->port_res[i].napi);
2337}
2338
2339static void port_napi_enable(struct ehea_port *port)
2340{
2341 int i;
2342
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002343 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002344 napi_enable(&port->port_res[i].napi);
2345}
2346
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002347static int ehea_open(struct net_device *dev)
2348{
2349 int ret;
2350 struct ehea_port *port = netdev_priv(dev);
2351
2352 down(&port->port_lock);
2353
2354 if (netif_msg_ifup(port))
2355 ehea_info("enabling port %s", dev->name);
2356
2357 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002358 if (!ret) {
2359 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002360 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002361 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002362
2363 up(&port->port_lock);
2364
2365 return ret;
2366}
2367
2368static int ehea_down(struct net_device *dev)
2369{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002370 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002371 struct ehea_port *port = netdev_priv(dev);
2372
2373 if (port->state == EHEA_PORT_DOWN)
2374 return 0;
2375
2376 ehea_drop_multicast_list(dev);
2377 ehea_free_interrupts(dev);
2378
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002379 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002380
2381 ret = ehea_clean_all_portres(port);
2382 if (ret)
2383 ehea_info("Failed freeing resources for %s. ret=%i",
2384 dev->name, ret);
2385
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002386 return ret;
2387}
2388
2389static int ehea_stop(struct net_device *dev)
2390{
2391 int ret;
2392 struct ehea_port *port = netdev_priv(dev);
2393
2394 if (netif_msg_ifdown(port))
2395 ehea_info("disabling port %s", dev->name);
2396
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002397 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002398 down(&port->port_lock);
2399 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002400 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002401 ret = ehea_down(dev);
2402 up(&port->port_lock);
2403 return ret;
2404}
2405
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002406void ehea_purge_sq(struct ehea_qp *orig_qp)
2407{
2408 struct ehea_qp qp = *orig_qp;
2409 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2410 struct ehea_swqe *swqe;
2411 int wqe_index;
2412 int i;
2413
2414 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2415 swqe = ehea_get_swqe(&qp, &wqe_index);
2416 swqe->tx_control |= EHEA_SWQE_PURGE;
2417 }
2418}
2419
2420int ehea_stop_qps(struct net_device *dev)
2421{
2422 struct ehea_port *port = netdev_priv(dev);
2423 struct ehea_adapter *adapter = port->adapter;
2424 struct hcp_modify_qp_cb0* cb0;
2425 int ret = -EIO;
2426 int dret;
2427 int i;
2428 u64 hret;
2429 u64 dummy64 = 0;
2430 u16 dummy16 = 0;
2431
2432 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2433 if (!cb0) {
2434 ret = -ENOMEM;
2435 goto out;
2436 }
2437
2438 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2439 struct ehea_port_res *pr = &port->port_res[i];
2440 struct ehea_qp *qp = pr->qp;
2441
2442 /* Purge send queue */
2443 ehea_purge_sq(qp);
2444
2445 /* Disable queue pair */
2446 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2447 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2448 cb0);
2449 if (hret != H_SUCCESS) {
2450 ehea_error("query_ehea_qp failed (1)");
2451 goto out;
2452 }
2453
2454 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2455 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2456
2457 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2458 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2459 1), cb0, &dummy64,
2460 &dummy64, &dummy16, &dummy16);
2461 if (hret != H_SUCCESS) {
2462 ehea_error("modify_ehea_qp failed (1)");
2463 goto out;
2464 }
2465
2466 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2467 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2468 cb0);
2469 if (hret != H_SUCCESS) {
2470 ehea_error("query_ehea_qp failed (2)");
2471 goto out;
2472 }
2473
2474 /* deregister shared memory regions */
2475 dret = ehea_rem_smrs(pr);
2476 if (dret) {
2477 ehea_error("unreg shared memory region failed");
2478 goto out;
2479 }
2480 }
2481
2482 ret = 0;
2483out:
2484 kfree(cb0);
2485
2486 return ret;
2487}
2488
2489void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res * pr)
2490{
2491 struct ehea_qp qp = *orig_qp;
2492 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2493 struct ehea_rwqe *rwqe;
2494 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2495 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2496 struct sk_buff *skb;
2497 u32 lkey = pr->recv_mr.lkey;
2498
2499
2500 int i;
2501 int index;
2502
2503 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2504 rwqe = ehea_get_next_rwqe(&qp, 2);
2505 rwqe->sg_list[0].l_key = lkey;
2506 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2507 skb = skba_rq2[index];
2508 if (skb)
2509 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2510 }
2511
2512 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2513 rwqe = ehea_get_next_rwqe(&qp, 3);
2514 rwqe->sg_list[0].l_key = lkey;
2515 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2516 skb = skba_rq3[index];
2517 if (skb)
2518 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2519 }
2520}
2521
2522int ehea_restart_qps(struct net_device *dev)
2523{
2524 struct ehea_port *port = netdev_priv(dev);
2525 struct ehea_adapter *adapter = port->adapter;
2526 int ret = 0;
2527 int i;
2528
2529 struct hcp_modify_qp_cb0* cb0;
2530 u64 hret;
2531 u64 dummy64 = 0;
2532 u16 dummy16 = 0;
2533
2534 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2535 if (!cb0) {
2536 ret = -ENOMEM;
2537 goto out;
2538 }
2539
2540 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2541 struct ehea_port_res *pr = &port->port_res[i];
2542 struct ehea_qp *qp = pr->qp;
2543
2544 ret = ehea_gen_smrs(pr);
2545 if (ret) {
2546 ehea_error("creation of shared memory regions failed");
2547 goto out;
2548 }
2549
2550 ehea_update_rqs(qp, pr);
2551
2552 /* Enable queue pair */
2553 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2554 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2555 cb0);
2556 if (hret != H_SUCCESS) {
2557 ehea_error("query_ehea_qp failed (1)");
2558 goto out;
2559 }
2560
2561 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2562 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2563
2564 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2565 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2566 1), cb0, &dummy64,
2567 &dummy64, &dummy16, &dummy16);
2568 if (hret != H_SUCCESS) {
2569 ehea_error("modify_ehea_qp failed (1)");
2570 goto out;
2571 }
2572
2573 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2574 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2575 cb0);
2576 if (hret != H_SUCCESS) {
2577 ehea_error("query_ehea_qp failed (2)");
2578 goto out;
2579 }
2580
2581 /* refill entire queue */
2582 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2583 ehea_refill_rq2(pr, 0);
2584 ehea_refill_rq3(pr, 0);
2585 }
2586out:
2587 kfree(cb0);
2588
2589 return ret;
2590}
2591
David Howellsc4028952006-11-22 14:57:56 +00002592static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002593{
2594 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002595 struct ehea_port *port =
2596 container_of(work, struct ehea_port, reset_task);
2597 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002598
2599 port->resets++;
2600 down(&port->port_lock);
2601 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002602
2603 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002604
Thomas Klein44c82152007-07-11 16:32:00 +02002605 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002606
2607 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002608 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002609 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002610
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002611 ehea_set_multicast_list(dev);
2612
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002613 if (netif_msg_timer(port))
2614 ehea_info("Device %s resetted successfully", dev->name);
2615
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002616 port_napi_enable(port);
2617
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002618 netif_wake_queue(dev);
2619out:
2620 up(&port->port_lock);
2621 return;
2622}
2623
Thomas Klein44c82152007-07-11 16:32:00 +02002624static void ehea_rereg_mrs(struct work_struct *work)
2625{
2626 int ret, i;
2627 struct ehea_adapter *adapter;
2628
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002629 down(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002630 ehea_info("LPAR memory enlarged - re-initializing driver");
2631
2632 list_for_each_entry(adapter, &adapter_list, list)
2633 if (adapter->active_ports) {
2634 /* Shutdown all ports */
2635 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2636 struct ehea_port *port = adapter->port[i];
2637
2638 if (port) {
2639 struct net_device *dev = port->netdev;
2640
2641 if (dev->flags & IFF_UP) {
Thomas Klein44c82152007-07-11 16:32:00 +02002642 down(&port->port_lock);
2643 netif_stop_queue(dev);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002644 ret = ehea_stop_qps(dev);
2645 if (ret) {
2646 up(&port->port_lock);
2647 goto out;
2648 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002649 port_napi_disable(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002650 up(&port->port_lock);
2651 }
2652 }
2653 }
2654
2655 /* Unregister old memory region */
2656 ret = ehea_rem_mr(&adapter->mr);
2657 if (ret) {
2658 ehea_error("unregister MR failed - driver"
2659 " inoperable!");
2660 goto out;
2661 }
2662 }
2663
2664 ehea_destroy_busmap();
Thomas Klein44c82152007-07-11 16:32:00 +02002665 ret = ehea_create_busmap();
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002666 if (ret) {
2667 ehea_error("creating ehea busmap failed");
Thomas Klein44c82152007-07-11 16:32:00 +02002668 goto out;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002669 }
Thomas Klein44c82152007-07-11 16:32:00 +02002670
2671 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2672
2673 list_for_each_entry(adapter, &adapter_list, list)
2674 if (adapter->active_ports) {
2675 /* Register new memory region */
2676 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2677 if (ret) {
2678 ehea_error("register MR failed - driver"
2679 " inoperable!");
2680 goto out;
2681 }
2682
2683 /* Restart all ports */
2684 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2685 struct ehea_port *port = adapter->port[i];
2686
2687 if (port) {
2688 struct net_device *dev = port->netdev;
2689
2690 if (dev->flags & IFF_UP) {
Thomas Klein44c82152007-07-11 16:32:00 +02002691 down(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002692 port_napi_enable(port);
2693 ret = ehea_restart_qps(dev);
2694 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002695 netif_wake_queue(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002696 up(&port->port_lock);
2697 }
2698 }
2699 }
2700 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002701 up(&dlpar_mem_lock);
2702 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002703out:
2704 return;
2705}
2706
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002707static void ehea_tx_watchdog(struct net_device *dev)
2708{
2709 struct ehea_port *port = netdev_priv(dev);
2710
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002711 if (netif_carrier_ok(dev) &&
2712 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002713 schedule_work(&port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002714}
2715
2716int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2717{
2718 struct hcp_query_ehea *cb;
2719 u64 hret;
2720 int ret;
2721
Thomas Kleina1d261c2006-11-03 17:48:23 +01002722 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002723 if (!cb) {
2724 ret = -ENOMEM;
2725 goto out;
2726 }
2727
2728 hret = ehea_h_query_ehea(adapter->handle, cb);
2729
2730 if (hret != H_SUCCESS) {
2731 ret = -EIO;
2732 goto out_herr;
2733 }
2734
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002735 adapter->max_mc_mac = cb->max_mc_mac - 1;
2736 ret = 0;
2737
2738out_herr:
2739 kfree(cb);
2740out:
2741 return ret;
2742}
2743
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002744int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2745{
2746 struct hcp_ehea_port_cb4 *cb4;
2747 u64 hret;
2748 int ret = 0;
2749
2750 *jumbo = 0;
2751
2752 /* (Try to) enable *jumbo frames */
2753 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2754 if (!cb4) {
2755 ehea_error("no mem for cb4");
2756 ret = -ENOMEM;
2757 goto out;
2758 } else {
2759 hret = ehea_h_query_ehea_port(port->adapter->handle,
2760 port->logical_port_id,
2761 H_PORT_CB4,
2762 H_PORT_CB4_JUMBO, cb4);
2763 if (hret == H_SUCCESS) {
2764 if (cb4->jumbo_frame)
2765 *jumbo = 1;
2766 else {
2767 cb4->jumbo_frame = 1;
2768 hret = ehea_h_modify_ehea_port(port->adapter->
2769 handle,
2770 port->
2771 logical_port_id,
2772 H_PORT_CB4,
2773 H_PORT_CB4_JUMBO,
2774 cb4);
2775 if (hret == H_SUCCESS)
2776 *jumbo = 1;
2777 }
2778 } else
2779 ret = -EINVAL;
2780
2781 kfree(cb4);
2782 }
2783out:
2784 return ret;
2785}
2786
2787static ssize_t ehea_show_port_id(struct device *dev,
2788 struct device_attribute *attr, char *buf)
2789{
2790 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002791 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002792}
2793
2794static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2795 NULL);
2796
2797static void __devinit logical_port_release(struct device *dev)
2798{
2799 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
2800 of_node_put(port->ofdev.node);
2801}
2802
Thomas Kleind1dea382007-04-26 11:56:13 +02002803static int ehea_driver_sysfs_add(struct device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002804 struct device_driver *driver)
Thomas Kleind1dea382007-04-26 11:56:13 +02002805{
2806 int ret;
2807
2808 ret = sysfs_create_link(&driver->kobj, &dev->kobj,
2809 kobject_name(&dev->kobj));
2810 if (ret == 0) {
2811 ret = sysfs_create_link(&dev->kobj, &driver->kobj,
2812 "driver");
2813 if (ret)
2814 sysfs_remove_link(&driver->kobj,
2815 kobject_name(&dev->kobj));
2816 }
2817 return ret;
2818}
2819
2820static void ehea_driver_sysfs_remove(struct device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002821 struct device_driver *driver)
Thomas Kleind1dea382007-04-26 11:56:13 +02002822{
2823 struct device_driver *drv = driver;
2824
2825 if (drv) {
2826 sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
2827 sysfs_remove_link(&dev->kobj, "driver");
2828 }
2829}
2830
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002831static struct device *ehea_register_port(struct ehea_port *port,
2832 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002833{
2834 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002835
2836 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002837 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002838 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002839
Thomas Kleind1dea382007-04-26 11:56:13 +02002840 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002841 port->ofdev.dev.release = logical_port_release;
2842
2843 ret = of_device_register(&port->ofdev);
2844 if (ret) {
2845 ehea_error("failed to register device. ret=%d", ret);
2846 goto out;
2847 }
2848
2849 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002850 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002851 ehea_error("failed to register attributes, ret=%d", ret);
2852 goto out_unreg_of_dev;
2853 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002854
Thomas Kleind1dea382007-04-26 11:56:13 +02002855 ret = ehea_driver_sysfs_add(&port->ofdev.dev, &ehea_driver.driver);
2856 if (ret) {
2857 ehea_error("failed to register sysfs driver link");
2858 goto out_rem_dev_file;
2859 }
2860
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002861 return &port->ofdev.dev;
2862
Thomas Kleind1dea382007-04-26 11:56:13 +02002863out_rem_dev_file:
2864 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002865out_unreg_of_dev:
2866 of_device_unregister(&port->ofdev);
2867out:
2868 return NULL;
2869}
2870
2871static void ehea_unregister_port(struct ehea_port *port)
2872{
Thomas Kleind1dea382007-04-26 11:56:13 +02002873 ehea_driver_sysfs_remove(&port->ofdev.dev, &ehea_driver.driver);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002874 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2875 of_device_unregister(&port->ofdev);
2876}
2877
2878struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
2879 u32 logical_port_id,
2880 struct device_node *dn)
2881{
2882 int ret;
2883 struct net_device *dev;
2884 struct ehea_port *port;
2885 struct device *port_dev;
2886 int jumbo;
2887
2888 /* allocate memory for the port structures */
2889 dev = alloc_etherdev(sizeof(struct ehea_port));
2890
2891 if (!dev) {
2892 ehea_error("no mem for net_device");
2893 ret = -ENOMEM;
2894 goto out_err;
2895 }
2896
2897 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002898
2899 sema_init(&port->port_lock, 1);
2900 port->state = EHEA_PORT_DOWN;
2901 port->sig_comp_iv = sq_entries / 10;
2902
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002903 port->adapter = adapter;
2904 port->netdev = dev;
2905 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002906
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002907 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002908
2909 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
2910 if (!port->mc_list) {
2911 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002912 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002913 }
2914
2915 INIT_LIST_HEAD(&port->mc_list->list);
2916
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002917 ret = ehea_sense_port_attr(port);
2918 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002919 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002920
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002921 port_dev = ehea_register_port(port, dn);
2922 if (!port_dev)
2923 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01002924
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002925 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002926
2927 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002928 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
2929
2930 dev->open = ehea_open;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +02002931#ifdef CONFIG_NET_POLL_CONTROLLER
2932 dev->poll_controller = ehea_netpoll;
2933#endif
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002934 dev->stop = ehea_stop;
2935 dev->hard_start_xmit = ehea_start_xmit;
2936 dev->get_stats = ehea_get_stats;
2937 dev->set_multicast_list = ehea_set_multicast_list;
2938 dev->set_mac_address = ehea_set_mac_addr;
2939 dev->change_mtu = ehea_change_mtu;
2940 dev->vlan_rx_register = ehea_vlan_rx_register;
2941 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
2942 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
2943 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
2944 | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX
2945 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
2946 | NETIF_F_LLTX;
2947 dev->tx_timeout = &ehea_tx_watchdog;
2948 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
2949
David Howellsc4028952006-11-22 14:57:56 +00002950 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002951
Thomas Kleinf9e29222007-07-18 17:34:09 +02002952 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2953 if (ret) {
2954 ret = -EIO;
2955 goto out_unreg_port;
2956 }
2957
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002958 ehea_set_ethtool_ops(dev);
2959
2960 ret = register_netdev(dev);
2961 if (ret) {
2962 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002963 goto out_dereg_bc;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002964 }
2965
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07002966 port->lro_max_aggr = lro_max_aggr;
2967
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002968 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002969 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002970 ehea_error("failed determining jumbo frame status for %s",
2971 port->netdev->name);
2972
Thomas Klein9c750b72007-01-29 18:44:01 +01002973 ehea_info("%s: Jumbo frames are %sabled", dev->name,
2974 jumbo == 1 ? "en" : "dis");
2975
Thomas Klein44c82152007-07-11 16:32:00 +02002976 adapter->active_ports++;
2977
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002978 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002979
Thomas Kleinf9e29222007-07-18 17:34:09 +02002980out_dereg_bc:
2981 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2982
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002983out_unreg_port:
2984 ehea_unregister_port(port);
2985
2986out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002987 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002988
2989out_free_ethdev:
2990 free_netdev(dev);
2991
2992out_err:
2993 ehea_error("setting up logical port with id=%d failed, ret=%d",
2994 logical_port_id, ret);
2995 return NULL;
2996}
2997
2998static void ehea_shutdown_single_port(struct ehea_port *port)
2999{
3000 unregister_netdev(port->netdev);
3001 ehea_unregister_port(port);
Thomas Kleinf9e29222007-07-18 17:34:09 +02003002 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003003 kfree(port->mc_list);
3004 free_netdev(port->netdev);
Thomas Klein44c82152007-07-11 16:32:00 +02003005 port->adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003006}
3007
3008static int ehea_setup_ports(struct ehea_adapter *adapter)
3009{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003010 struct device_node *lhea_dn;
3011 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003012
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003013 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003014 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003015
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003016 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003017 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003018
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003019 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003020 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003021 if (!dn_log_port_id) {
3022 ehea_error("bad device node: eth_dn name=%s",
3023 eth_dn->full_name);
3024 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003025 }
3026
Thomas Klein1211bb62007-04-26 11:56:43 +02003027 if (ehea_add_adapter_mr(adapter)) {
3028 ehea_error("creating MR failed");
3029 of_node_put(eth_dn);
3030 return -EIO;
3031 }
3032
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003033 adapter->port[i] = ehea_setup_single_port(adapter,
3034 *dn_log_port_id,
3035 eth_dn);
3036 if (adapter->port[i])
3037 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003038 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003039 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003040 else
3041 ehea_remove_adapter_mr(adapter);
3042
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003043 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003044 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003045
Thomas Klein1211bb62007-04-26 11:56:43 +02003046 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003047}
3048
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003049static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3050 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003051{
3052 struct device_node *lhea_dn;
3053 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003054 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003055
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003056 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003057 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003058
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003059 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003060 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003061 if (dn_log_port_id)
3062 if (*dn_log_port_id == logical_port_id)
3063 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003064 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003065
3066 return NULL;
3067}
3068
3069static ssize_t ehea_probe_port(struct device *dev,
3070 struct device_attribute *attr,
3071 const char *buf, size_t count)
3072{
3073 struct ehea_adapter *adapter = dev->driver_data;
3074 struct ehea_port *port;
3075 struct device_node *eth_dn = NULL;
3076 int i;
3077
3078 u32 logical_port_id;
3079
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003080 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003081
3082 port = ehea_get_port(adapter, logical_port_id);
3083
3084 if (port) {
3085 ehea_info("adding port with logical port id=%d failed. port "
3086 "already configured as %s.", logical_port_id,
3087 port->netdev->name);
3088 return -EINVAL;
3089 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003090
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003091 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3092
3093 if (!eth_dn) {
3094 ehea_info("no logical port with id %d found", logical_port_id);
3095 return -EINVAL;
3096 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003097
Thomas Klein1211bb62007-04-26 11:56:43 +02003098 if (ehea_add_adapter_mr(adapter)) {
3099 ehea_error("creating MR failed");
3100 return -EIO;
3101 }
3102
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3104
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003105 of_node_put(eth_dn);
3106
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003107 if (port) {
3108 for (i=0; i < EHEA_MAX_PORTS; i++)
3109 if (!adapter->port[i]) {
3110 adapter->port[i] = port;
3111 break;
3112 }
3113
3114 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3115 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003116 } else {
3117 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003118 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003119 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003120
3121 return (ssize_t) count;
3122}
3123
3124static ssize_t ehea_remove_port(struct device *dev,
3125 struct device_attribute *attr,
3126 const char *buf, size_t count)
3127{
3128 struct ehea_adapter *adapter = dev->driver_data;
3129 struct ehea_port *port;
3130 int i;
3131 u32 logical_port_id;
3132
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003133 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003134
3135 port = ehea_get_port(adapter, logical_port_id);
3136
3137 if (port) {
3138 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3139 logical_port_id);
3140
3141 ehea_shutdown_single_port(port);
3142
3143 for (i=0; i < EHEA_MAX_PORTS; i++)
3144 if (adapter->port[i] == port) {
3145 adapter->port[i] = NULL;
3146 break;
3147 }
3148 } else {
3149 ehea_error("removing port with logical port id=%d failed. port "
3150 "not configured.", logical_port_id);
3151 return -EINVAL;
3152 }
3153
Thomas Klein1211bb62007-04-26 11:56:43 +02003154 ehea_remove_adapter_mr(adapter);
3155
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003156 return (ssize_t) count;
3157}
3158
3159static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3160static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3161
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003162int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003163{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003164 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165 if (ret)
3166 goto out;
3167
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003168 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003169out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003170 return ret;
3171}
3172
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003173void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003174{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003175 device_remove_file(&dev->dev, &dev_attr_probe_port);
3176 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003177}
3178
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003179static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003180 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003181{
3182 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003183 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003184 int ret;
3185
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003186 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003187 ehea_error("Invalid ibmebus device probed");
3188 return -EINVAL;
3189 }
3190
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003191 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3192 if (!adapter) {
3193 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003194 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003195 goto out;
3196 }
3197
Thomas Klein44c82152007-07-11 16:32:00 +02003198 list_add(&adapter->list, &adapter_list);
3199
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003200 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003201
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003202 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003203 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003204 if (adapter_handle)
3205 adapter->handle = *adapter_handle;
3206
3207 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003208 dev_err(&dev->dev, "failed getting handle for adapter"
3209 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003210 ret = -ENODEV;
3211 goto out_free_ad;
3212 }
3213
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003214 adapter->pd = EHEA_PD_ID;
3215
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003216 dev->dev.driver_data = adapter;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003217
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003218
3219 /* initialize adapter and ports */
3220 /* get adapter properties */
3221 ret = ehea_sense_adapter_attr(adapter);
3222 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003223 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003224 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003225 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003226
3227 adapter->neq = ehea_create_eq(adapter,
3228 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3229 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003230 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003231 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003232 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003233 }
3234
3235 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3236 (unsigned long)adapter);
3237
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003238 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003239 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003240 "ehea_neq", adapter);
3241 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003242 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003243 goto out_kill_eq;
3244 }
3245
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003246 ret = ehea_create_device_sysfs(dev);
3247 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003248 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003249
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003250 ret = ehea_setup_ports(adapter);
3251 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003252 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003253 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003254 }
3255
3256 ret = 0;
3257 goto out;
3258
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003259out_rem_dev_sysfs:
3260 ehea_remove_device_sysfs(dev);
3261
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003262out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003263 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003264
3265out_kill_eq:
3266 ehea_destroy_eq(adapter->neq);
3267
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003268out_free_ad:
3269 kfree(adapter);
3270out:
3271 return ret;
3272}
3273
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003274static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003275{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003276 struct ehea_adapter *adapter = dev->dev.driver_data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003277 int i;
3278
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003279 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003280 if (adapter->port[i]) {
3281 ehea_shutdown_single_port(adapter->port[i]);
3282 adapter->port[i] = NULL;
3283 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003284
3285 ehea_remove_device_sysfs(dev);
3286
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003287 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003288
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003289 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003290 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003291
3292 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003293 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003294 list_del(&adapter->list);
3295
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003296 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003297
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003298 return 0;
3299}
3300
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003301static int ehea_reboot_notifier(struct notifier_block *nb,
3302 unsigned long action, void *unused)
3303{
3304 if (action == SYS_RESTART) {
3305 ehea_info("Reboot: freeing all eHEA resources");
3306 ibmebus_unregister_driver(&ehea_driver);
3307 }
3308 return NOTIFY_DONE;
3309}
3310
3311static struct notifier_block ehea_reboot_nb = {
3312 .notifier_call = ehea_reboot_notifier,
3313};
3314
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003315static int check_module_parm(void)
3316{
3317 int ret = 0;
3318
3319 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3320 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3321 ehea_info("Bad parameter: rq1_entries");
3322 ret = -EINVAL;
3323 }
3324 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3325 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3326 ehea_info("Bad parameter: rq2_entries");
3327 ret = -EINVAL;
3328 }
3329 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3330 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3331 ehea_info("Bad parameter: rq3_entries");
3332 ret = -EINVAL;
3333 }
3334 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3335 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3336 ehea_info("Bad parameter: sq_entries");
3337 ret = -EINVAL;
3338 }
3339
3340 return ret;
3341}
3342
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003343static ssize_t ehea_show_capabilities(struct device_driver *drv,
3344 char *buf)
3345{
3346 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3347}
3348
3349static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3350 ehea_show_capabilities, NULL);
3351
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003352int __init ehea_module_init(void)
3353{
3354 int ret;
3355
3356 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3357 DRV_VERSION);
3358
Thomas Klein44c82152007-07-11 16:32:00 +02003359
3360 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003361 sema_init(&dlpar_mem_lock, 1);
Thomas Klein44c82152007-07-11 16:32:00 +02003362
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003363 ret = check_module_parm();
3364 if (ret)
3365 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003366
3367 ret = ehea_create_busmap();
3368 if (ret)
3369 goto out;
3370
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003371 register_reboot_notifier(&ehea_reboot_nb);
3372
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003373 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003374 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003375 ehea_error("failed registering eHEA device driver on ebus");
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003376 goto out;
3377 }
3378
3379 ret = driver_create_file(&ehea_driver.driver,
3380 &driver_attr_capabilities);
3381 if (ret) {
3382 ehea_error("failed to register capabilities attribute, ret=%d",
3383 ret);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003384 unregister_reboot_notifier(&ehea_reboot_nb);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003385 ibmebus_unregister_driver(&ehea_driver);
3386 goto out;
3387 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003388
3389out:
3390 return ret;
3391}
3392
3393static void __exit ehea_module_exit(void)
3394{
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003395 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003396 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003397 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003398 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein44c82152007-07-11 16:32:00 +02003399 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003400}
3401
3402module_init(ehea_module_init);
3403module_exit(ehea_module_exit);