blob: 977c3d358279378086f2e82ee03ed21f31221dc7 [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:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
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>
Hannes Hering48cfb142008-05-07 14:43:36 +020038#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010039#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070040#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020041
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020042#include <net/ip.h>
43
44#include "ehea.h"
45#include "ehea_qmr.h"
46#include "ehea_phyp.h"
47
48
49MODULE_LICENSE("GPL");
50MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
51MODULE_DESCRIPTION("IBM eServer HEA Driver");
52MODULE_VERSION(DRV_VERSION);
53
54
55static int msg_level = -1;
56static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
57static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
58static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
59static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060060static int use_mcs;
61static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070062static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010063static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060064static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020065
66module_param(msg_level, int, 0);
67module_param(rq1_entries, int, 0);
68module_param(rq2_entries, int, 0);
69module_param(rq3_entries, int, 0);
70module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020071module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010072module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070073module_param(use_lro, int, 0);
74module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010075module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020076
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010077MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020079MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
80 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020081MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
84MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
87MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
90MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
91 "[2^x - 1], x = [6..14]. Default = "
92 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020093MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020094
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070095MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
96 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
97MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
98 "Default = 0");
99
Doug Maxey508d2b52008-01-31 20:20:49 -0600100static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200101static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800102static unsigned long ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200103struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700104static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100105struct ehea_fw_handle_array ehea_fw_handles;
106struct ehea_bcmc_reg_array ehea_bcmc_regs;
107
Thomas Kleind1dea382007-04-26 11:56:13 +0200108
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000109static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200110 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200111
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000112static int __devexit ehea_remove(struct of_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200113
114static struct of_device_id ehea_device_table[] = {
115 {
116 .name = "lhea",
117 .compatible = "IBM,lhea",
118 },
119 {},
120};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100121MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200122
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000123static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200124 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000125 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200126 .probe = ehea_probe_adapter,
127 .remove = ehea_remove,
128};
129
Doug Maxey508d2b52008-01-31 20:20:49 -0600130void ehea_dump(void *adr, int len, char *msg)
131{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 int x;
133 unsigned char *deb = adr;
134 for (x = 0; x < len; x += 16) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000135 printk(DRV_NAME " %s adr=%p ofs=%04x %016llx %016llx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600136 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200137 deb += 16;
138 }
139}
140
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100141void ehea_schedule_port_reset(struct ehea_port *port)
142{
143 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
144 schedule_work(&port->reset_task);
145}
146
Thomas Klein21eee2d2008-02-13 16:18:33 +0100147static void ehea_update_firmware_handles(void)
148{
149 struct ehea_fw_handle_entry *arr = NULL;
150 struct ehea_adapter *adapter;
151 int num_adapters = 0;
152 int num_ports = 0;
153 int num_portres = 0;
154 int i = 0;
155 int num_fw_handles, k, l;
156
157 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700158 mutex_lock(&ehea_fw_handles.lock);
159
Thomas Klein21eee2d2008-02-13 16:18:33 +0100160 list_for_each_entry(adapter, &adapter_list, list) {
161 num_adapters++;
162
163 for (k = 0; k < EHEA_MAX_PORTS; k++) {
164 struct ehea_port *port = adapter->port[k];
165
166 if (!port || (port->state != EHEA_PORT_UP))
167 continue;
168
169 num_ports++;
170 num_portres += port->num_def_qps + port->num_add_tx_qps;
171 }
172 }
173
174 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
175 num_ports * EHEA_NUM_PORT_FW_HANDLES +
176 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
177
178 if (num_fw_handles) {
179 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
180 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700181 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100182 } else
183 goto out_update;
184
185 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700186 if (num_adapters == 0)
187 break;
188
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 for (k = 0; k < EHEA_MAX_PORTS; k++) {
190 struct ehea_port *port = adapter->port[k];
191
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700192 if (!port || (port->state != EHEA_PORT_UP)
193 || (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100194 continue;
195
196 for (l = 0;
197 l < port->num_def_qps + port->num_add_tx_qps;
198 l++) {
199 struct ehea_port_res *pr = &port->port_res[l];
200
201 arr[i].adh = adapter->handle;
202 arr[i++].fwh = pr->qp->fw_handle;
203 arr[i].adh = adapter->handle;
204 arr[i++].fwh = pr->send_cq->fw_handle;
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = pr->recv_cq->fw_handle;
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = pr->eq->fw_handle;
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = pr->send_mr.handle;
211 arr[i].adh = adapter->handle;
212 arr[i++].fwh = pr->recv_mr.handle;
213 }
214 arr[i].adh = adapter->handle;
215 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700216 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100217 }
218
219 arr[i].adh = adapter->handle;
220 arr[i++].fwh = adapter->neq->fw_handle;
221
222 if (adapter->mr.handle) {
223 arr[i].adh = adapter->handle;
224 arr[i++].fwh = adapter->mr.handle;
225 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700226 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100227 }
228
229out_update:
230 kfree(ehea_fw_handles.arr);
231 ehea_fw_handles.arr = arr;
232 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700233out:
234 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100235}
236
237static void ehea_update_bcmc_registrations(void)
238{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700239 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100240 struct ehea_bcmc_reg_entry *arr = NULL;
241 struct ehea_adapter *adapter;
242 struct ehea_mc_list *mc_entry;
243 int num_registrations = 0;
244 int i = 0;
245 int k;
246
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700247 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
248
Thomas Klein21eee2d2008-02-13 16:18:33 +0100249 /* Determine number of registrations */
250 list_for_each_entry(adapter, &adapter_list, list)
251 for (k = 0; k < EHEA_MAX_PORTS; k++) {
252 struct ehea_port *port = adapter->port[k];
253
254 if (!port || (port->state != EHEA_PORT_UP))
255 continue;
256
257 num_registrations += 2; /* Broadcast registrations */
258
259 list_for_each_entry(mc_entry, &port->mc_list->list,list)
260 num_registrations += 2;
261 }
262
263 if (num_registrations) {
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +0100264 arr = kzalloc(num_registrations * sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100265 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700266 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100267 } else
268 goto out_update;
269
270 list_for_each_entry(adapter, &adapter_list, list) {
271 for (k = 0; k < EHEA_MAX_PORTS; k++) {
272 struct ehea_port *port = adapter->port[k];
273
274 if (!port || (port->state != EHEA_PORT_UP))
275 continue;
276
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700277 if (num_registrations == 0)
278 goto out_update;
279
Thomas Klein21eee2d2008-02-13 16:18:33 +0100280 arr[i].adh = adapter->handle;
281 arr[i].port_id = port->logical_port_id;
282 arr[i].reg_type = EHEA_BCMC_BROADCAST |
283 EHEA_BCMC_UNTAGGED;
284 arr[i++].macaddr = port->mac_addr;
285
286 arr[i].adh = adapter->handle;
287 arr[i].port_id = port->logical_port_id;
288 arr[i].reg_type = EHEA_BCMC_BROADCAST |
289 EHEA_BCMC_VLANID_ALL;
290 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700291 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100292
293 list_for_each_entry(mc_entry,
294 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700295 if (num_registrations == 0)
296 goto out_update;
297
Thomas Klein21eee2d2008-02-13 16:18:33 +0100298 arr[i].adh = adapter->handle;
299 arr[i].port_id = port->logical_port_id;
300 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
301 EHEA_BCMC_MULTICAST |
302 EHEA_BCMC_UNTAGGED;
303 arr[i++].macaddr = mc_entry->macaddr;
304
305 arr[i].adh = adapter->handle;
306 arr[i].port_id = port->logical_port_id;
307 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
308 EHEA_BCMC_MULTICAST |
309 EHEA_BCMC_VLANID_ALL;
310 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700311 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100312 }
313 }
314 }
315
316out_update:
317 kfree(ehea_bcmc_regs.arr);
318 ehea_bcmc_regs.arr = arr;
319 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700320out:
321 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100322}
323
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200324static struct net_device_stats *ehea_get_stats(struct net_device *dev)
325{
326 struct ehea_port *port = netdev_priv(dev);
327 struct net_device_stats *stats = &port->stats;
328 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100329 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200330 int i;
331
332 memset(stats, 0, sizeof(*stats));
333
Thomas Klein3faf2692009-01-21 14:45:33 -0800334 cb2 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200335 if (!cb2) {
336 ehea_error("no mem for cb2");
337 goto out;
338 }
339
340 hret = ehea_h_query_ehea_port(port->adapter->handle,
341 port->logical_port_id,
342 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
343 if (hret != H_SUCCESS) {
344 ehea_error("query_ehea_port failed");
345 goto out_herr;
346 }
347
348 if (netif_msg_hw(port))
349 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
350
351 rx_packets = 0;
352 for (i = 0; i < port->num_def_qps; i++)
353 rx_packets += port->port_res[i].rx_packets;
354
Thomas Klein7393b872007-11-21 17:37:58 +0100355 tx_packets = 0;
356 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
357 tx_packets += port->port_res[i].tx_packets;
358
359 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200360 stats->multicast = cb2->rxmcp;
361 stats->rx_errors = cb2->rxuerr;
362 stats->rx_bytes = cb2->rxo;
363 stats->tx_bytes = cb2->txo;
364 stats->rx_packets = rx_packets;
365
366out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800367 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200368out:
369 return stats;
370}
371
372static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
373{
374 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
375 struct net_device *dev = pr->port->netdev;
376 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200377 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
378 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200379 int i;
380
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200381 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200382
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200383 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200384 if (nr_of_wqes > 0)
385 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200386 pr->rq1_skba.os_skbs = fill_wqes;
387 return;
388 }
389
390 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200391 if (!skb_arr_rq1[index]) {
392 skb_arr_rq1[index] = netdev_alloc_skb(dev,
393 EHEA_L_PKT_SIZE);
394 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200395 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200396 break;
397 }
398 }
399 index--;
400 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200401 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200402 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200403
404 if (adder == 0)
405 return;
406
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200407 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200408 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200409}
410
Thomas Kleine2878802009-01-21 14:45:57 -0800411static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200412{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
414 struct net_device *dev = pr->port->netdev;
415 int i;
416
417 for (i = 0; i < pr->rq1_skba.len; i++) {
418 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Thomas Kleine2878802009-01-21 14:45:57 -0800419 if (!skb_arr_rq1[i])
420 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200421 }
422 /* Ring doorbell */
423 ehea_update_rq1a(pr->qp, nr_rq1a);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200424}
425
426static int ehea_refill_rq_def(struct ehea_port_res *pr,
427 struct ehea_q_skb_arr *q_skba, int rq_nr,
428 int num_wqes, int wqe_type, int packet_size)
429{
430 struct net_device *dev = pr->port->netdev;
431 struct ehea_qp *qp = pr->qp;
432 struct sk_buff **skb_arr = q_skba->arr;
433 struct ehea_rwqe *rwqe;
434 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200435 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200436 int ret = 0;
437
438 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200439 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200440
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200441 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
442 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200443 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200444 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200445
446 index = q_skba->index;
447 max_index_mask = q_skba->len - 1;
448 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200449 u64 tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200450 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
451 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200452 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800453 if (q_skba->os_skbs == q_skba->len - 2) {
454 ehea_info("%s: rq%i ran dry - no mem for skb",
455 pr->port->netdev->name, rq_nr);
456 ret = -ENOMEM;
457 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458 break;
459 }
460 skb_reserve(skb, NET_IP_ALIGN);
461
462 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200463 tmp_addr = ehea_map_vaddr(skb->data);
464 if (tmp_addr == -1) {
465 dev_kfree_skb(skb);
466 q_skba->os_skbs = fill_wqes - i;
467 ret = 0;
468 break;
469 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470
471 rwqe = ehea_get_next_rwqe(qp, rq_nr);
472 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200473 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200474 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200475 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200476 rwqe->sg_list[0].len = packet_size;
477 rwqe->data_segments = 1;
478
479 index++;
480 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200481 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200482 }
Thomas Klein44c82152007-07-11 16:32:00 +0200483
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200484 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200485 if (adder == 0)
486 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200487
488 /* Ring doorbell */
489 iosync();
490 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200491 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200492 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200493 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200494out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200495 return ret;
496}
497
498
499static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
500{
501 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
502 nr_of_wqes, EHEA_RWQE2_TYPE,
503 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
504}
505
506
507static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
508{
509 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
510 nr_of_wqes, EHEA_RWQE3_TYPE,
511 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
512}
513
514static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
515{
516 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
517 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
518 return 0;
519 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
520 (cqe->header_length == 0))
521 return 0;
522 return -EINVAL;
523}
524
525static inline void ehea_fill_skb(struct net_device *dev,
526 struct sk_buff *skb, struct ehea_cqe *cqe)
527{
528 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
529
530 skb_put(skb, length);
531 skb->ip_summed = CHECKSUM_UNNECESSARY;
532 skb->protocol = eth_type_trans(skb, dev);
533}
534
535static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
536 int arr_len,
537 struct ehea_cqe *cqe)
538{
539 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
540 struct sk_buff *skb;
541 void *pref;
542 int x;
543
544 x = skb_index + 1;
545 x &= (arr_len - 1);
546
547 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700548 if (pref) {
549 prefetchw(pref);
550 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200551
Hannes Hering0b2febf2009-05-04 11:06:37 -0700552 pref = (skb_array[x]->data);
553 prefetch(pref);
554 prefetch(pref + EHEA_CACHE_LINE);
555 prefetch(pref + EHEA_CACHE_LINE * 2);
556 prefetch(pref + EHEA_CACHE_LINE * 3);
557 }
558
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200559 skb = skb_array[skb_index];
560 skb_array[skb_index] = NULL;
561 return skb;
562}
563
564static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
565 int arr_len, int wqe_index)
566{
567 struct sk_buff *skb;
568 void *pref;
569 int x;
570
571 x = wqe_index + 1;
572 x &= (arr_len - 1);
573
574 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700575 if (pref) {
576 prefetchw(pref);
577 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200578
Hannes Hering0b2febf2009-05-04 11:06:37 -0700579 pref = (skb_array[x]->data);
580 prefetchw(pref);
581 prefetchw(pref + EHEA_CACHE_LINE);
582 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200583
584 skb = skb_array[wqe_index];
585 skb_array[wqe_index] = NULL;
586 return skb;
587}
588
589static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
590 struct ehea_cqe *cqe, int *processed_rq2,
591 int *processed_rq3)
592{
593 struct sk_buff *skb;
594
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100595 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
596 pr->p_stats.err_tcp_cksum++;
597 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
598 pr->p_stats.err_ip_cksum++;
599 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
600 pr->p_stats.err_frame_crc++;
601
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200602 if (rq == 2) {
603 *processed_rq2 += 1;
604 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
605 dev_kfree_skb(skb);
606 } else if (rq == 3) {
607 *processed_rq3 += 1;
608 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
609 dev_kfree_skb(skb);
610 }
611
612 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100613 if (netif_msg_rx_err(pr->port)) {
614 ehea_error("Critical receive error for QP %d. "
615 "Resetting port.", pr->qp->init_attr.qp_nr);
616 ehea_dump(cqe, sizeof(*cqe), "CQE");
617 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100618 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200619 return 1;
620 }
621
622 return 0;
623}
624
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700625static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
626 void **tcph, u64 *hdr_flags, void *priv)
627{
628 struct ehea_cqe *cqe = priv;
629 unsigned int ip_len;
630 struct iphdr *iph;
631
632 /* non tcp/udp packets */
633 if (!cqe->header_length)
634 return -1;
635
636 /* non tcp packet */
637 skb_reset_network_header(skb);
638 iph = ip_hdr(skb);
639 if (iph->protocol != IPPROTO_TCP)
640 return -1;
641
642 ip_len = ip_hdrlen(skb);
643 skb_set_transport_header(skb, ip_len);
644 *tcph = tcp_hdr(skb);
645
646 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700647 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700648 return -1;
649
650 *hdr_flags = LRO_IPV4 | LRO_TCP;
651 *iphdr = iph;
652
653 return 0;
654}
655
656static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
657 struct sk_buff *skb)
658{
659 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
660 && pr->port->vgrp;
661
662 if (use_lro) {
663 if (vlan_extracted)
664 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
665 pr->port->vgrp,
666 cqe->vlan_tag,
667 cqe);
668 else
669 lro_receive_skb(&pr->lro_mgr, skb, cqe);
670 } else {
671 if (vlan_extracted)
672 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
673 cqe->vlan_tag);
674 else
675 netif_receive_skb(skb);
676 }
677}
678
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700679static int ehea_proc_rwqes(struct net_device *dev,
680 struct ehea_port_res *pr,
681 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200682{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100683 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200684 struct ehea_qp *qp = pr->qp;
685 struct ehea_cqe *cqe;
686 struct sk_buff *skb;
687 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
688 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
689 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
690 int skb_arr_rq1_len = pr->rq1_skba.len;
691 int skb_arr_rq2_len = pr->rq2_skba.len;
692 int skb_arr_rq3_len = pr->rq3_skba.len;
693 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700694 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200695
696 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
697 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200698
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200699 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700700 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200701 ehea_inc_rq1(qp);
702 processed_rq1++;
703 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200704 if (netif_msg_rx_status(port))
705 ehea_dump(cqe, sizeof(*cqe), "CQE");
706
707 last_wqe_index = wqe_index;
708 rmb();
709 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600710 if (rq == 1) {
711 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200712 skb = get_skb_by_index_ll(skb_arr_rq1,
713 skb_arr_rq1_len,
714 wqe_index);
715 if (unlikely(!skb)) {
716 if (netif_msg_rx_err(port))
717 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100718
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700719 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200720 EHEA_L_PKT_SIZE);
721 if (!skb)
722 break;
723 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600724 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200725 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700726 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600727 } else if (rq == 2) {
728 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200729 skb = get_skb_by_index(skb_arr_rq2,
730 skb_arr_rq2_len, cqe);
731 if (unlikely(!skb)) {
732 if (netif_msg_rx_err(port))
733 ehea_error("rq2: skb=NULL");
734 break;
735 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700736 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200737 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600738 } else {
739 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200740 skb = get_skb_by_index(skb_arr_rq3,
741 skb_arr_rq3_len, cqe);
742 if (unlikely(!skb)) {
743 if (netif_msg_rx_err(port))
744 ehea_error("rq3: skb=NULL");
745 break;
746 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700747 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200748 processed_rq3++;
749 }
750
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700751 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100752 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100753 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200754 port_reset = ehea_treat_poll_error(pr, rq, cqe,
755 &processed_rq2,
756 &processed_rq3);
757 if (port_reset)
758 break;
759 }
760 cqe = ehea_poll_rq1(qp, &wqe_index);
761 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700762 if (use_lro)
763 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200764
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200765 pr->rx_packets += processed;
766
767 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
768 ehea_refill_rq2(pr, processed_rq2);
769 ehea_refill_rq3(pr, processed_rq3);
770
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700771 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200772}
773
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100774static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200775{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100776 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200777 struct ehea_cq *send_cq = pr->send_cq;
778 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100779 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200780 int cqe_counter = 0;
781 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100782 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200783 unsigned long flags;
784
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100785 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600786 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100787 ehea_inc_cq(send_cq);
788
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200789 cqe_counter++;
790 rmb();
791 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
792 ehea_error("Send Completion Error: Resetting port");
793 if (netif_msg_tx_err(pr->port))
794 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100795 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200796 break;
797 }
798
799 if (netif_msg_tx_done(pr->port))
800 ehea_dump(cqe, sizeof(*cqe), "CQE");
801
802 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100803 == EHEA_SWQE2_TYPE)) {
804
805 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
806 skb = pr->sq_skba.arr[index];
807 dev_kfree_skb(skb);
808 pr->sq_skba.arr[index] = NULL;
809 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200810
811 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
812 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100813
814 cqe = ehea_poll_cq(send_cq);
815 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200816
817 ehea_update_feca(send_cq, cqe_counter);
818 atomic_add(swqe_av, &pr->swqe_avail);
819
820 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100821
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200822 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
823 >= pr->swqe_refill_th)) {
824 netif_wake_queue(pr->port->netdev);
825 pr->queue_stopped = 0;
826 }
827 spin_unlock_irqrestore(&pr->netif_queue, flags);
828
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100829 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200830}
831
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100832#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700833#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100834
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700835static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200836{
Doug Maxey508d2b52008-01-31 20:20:49 -0600837 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
838 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700839 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100840 struct ehea_cqe *cqe;
841 struct ehea_cqe *cqe_skb = NULL;
842 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700843 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100844
845 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700846 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100847
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700848 if (!force_irq)
849 rx += ehea_proc_rwqes(dev, pr, budget - rx);
850
851 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100852 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700853 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800854 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100855 ehea_reset_cq_ep(pr->recv_cq);
856 ehea_reset_cq_ep(pr->send_cq);
857 ehea_reset_cq_n1(pr->recv_cq);
858 ehea_reset_cq_n1(pr->send_cq);
859 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
860 cqe_skb = ehea_poll_cq(pr->send_cq);
861
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100862 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700863 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100864
Ben Hutchings288379f2009-01-19 16:43:59 -0800865 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700866 return rx;
867
868 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
869 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100870 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100871
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700872 pr->poll_counter++;
873 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200874}
875
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200876#ifdef CONFIG_NET_POLL_CONTROLLER
877static void ehea_netpoll(struct net_device *dev)
878{
879 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700880 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200881
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700882 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800883 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200884}
885#endif
886
David Howells7d12e782006-10-05 14:55:46 +0100887static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200888{
889 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100890
Ben Hutchings288379f2009-01-19 16:43:59 -0800891 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100892
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200893 return IRQ_HANDLED;
894}
895
David Howells7d12e782006-10-05 14:55:46 +0100896static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200897{
898 struct ehea_port *port = param;
899 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100900 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200901 u32 qp_token;
902
903 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100904
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200905 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200906 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000907 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100908 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100909
910 qp = port->port_res[qp_token].qp;
911 ehea_error_data(port->adapter, qp->fw_handle);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100912 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200913 }
914
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100915 ehea_schedule_port_reset(port);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100916
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200917 return IRQ_HANDLED;
918}
919
920static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
921 int logical_port)
922{
923 int i;
924
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100925 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100926 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200927 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100928 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200929 return NULL;
930}
931
932int ehea_sense_port_attr(struct ehea_port *port)
933{
934 int ret;
935 u64 hret;
936 struct hcp_ehea_port_cb0 *cb0;
937
Doug Maxey508d2b52008-01-31 20:20:49 -0600938 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800939 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600940 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200941 ehea_error("no mem for cb0");
942 ret = -ENOMEM;
943 goto out;
944 }
945
946 hret = ehea_h_query_ehea_port(port->adapter->handle,
947 port->logical_port_id, H_PORT_CB0,
948 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
949 cb0);
950 if (hret != H_SUCCESS) {
951 ret = -EIO;
952 goto out_free;
953 }
954
955 /* MAC address */
956 port->mac_addr = cb0->port_mac_addr << 16;
957
Doug Maxey508d2b52008-01-31 20:20:49 -0600958 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200959 ret = -EADDRNOTAVAIL;
960 goto out_free;
961 }
962
963 /* Port speed */
964 switch (cb0->port_speed) {
965 case H_SPEED_10M_H:
966 port->port_speed = EHEA_SPEED_10M;
967 port->full_duplex = 0;
968 break;
969 case H_SPEED_10M_F:
970 port->port_speed = EHEA_SPEED_10M;
971 port->full_duplex = 1;
972 break;
973 case H_SPEED_100M_H:
974 port->port_speed = EHEA_SPEED_100M;
975 port->full_duplex = 0;
976 break;
977 case H_SPEED_100M_F:
978 port->port_speed = EHEA_SPEED_100M;
979 port->full_duplex = 1;
980 break;
981 case H_SPEED_1G_F:
982 port->port_speed = EHEA_SPEED_1G;
983 port->full_duplex = 1;
984 break;
985 case H_SPEED_10G_F:
986 port->port_speed = EHEA_SPEED_10G;
987 port->full_duplex = 1;
988 break;
989 default:
990 port->port_speed = 0;
991 port->full_duplex = 0;
992 break;
993 }
994
Thomas Kleine919b592007-01-22 12:53:20 +0100995 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100996 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +0100997
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200998 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100999 if (use_mcs)
1000 port->num_def_qps = cb0->num_default_qps;
1001 else
1002 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001003
1004 if (!port->num_def_qps) {
1005 ret = -EINVAL;
1006 goto out_free;
1007 }
1008
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001009 port->num_tx_qps = num_tx_qps;
1010
1011 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001012 port->num_add_tx_qps = 0;
1013 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001014 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001015
1016 ret = 0;
1017out_free:
1018 if (ret || netif_msg_probe(port))
1019 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001020 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001021out:
1022 return ret;
1023}
1024
1025int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1026{
1027 struct hcp_ehea_port_cb4 *cb4;
1028 u64 hret;
1029 int ret = 0;
1030
Thomas Klein3faf2692009-01-21 14:45:33 -08001031 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001032 if (!cb4) {
1033 ehea_error("no mem for cb4");
1034 ret = -ENOMEM;
1035 goto out;
1036 }
1037
1038 cb4->port_speed = port_speed;
1039
1040 netif_carrier_off(port->netdev);
1041
1042 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1043 port->logical_port_id,
1044 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1045 if (hret == H_SUCCESS) {
1046 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1047
1048 hret = ehea_h_query_ehea_port(port->adapter->handle,
1049 port->logical_port_id,
1050 H_PORT_CB4, H_PORT_CB4_SPEED,
1051 cb4);
1052 if (hret == H_SUCCESS) {
1053 switch (cb4->port_speed) {
1054 case H_SPEED_10M_H:
1055 port->port_speed = EHEA_SPEED_10M;
1056 port->full_duplex = 0;
1057 break;
1058 case H_SPEED_10M_F:
1059 port->port_speed = EHEA_SPEED_10M;
1060 port->full_duplex = 1;
1061 break;
1062 case H_SPEED_100M_H:
1063 port->port_speed = EHEA_SPEED_100M;
1064 port->full_duplex = 0;
1065 break;
1066 case H_SPEED_100M_F:
1067 port->port_speed = EHEA_SPEED_100M;
1068 port->full_duplex = 1;
1069 break;
1070 case H_SPEED_1G_F:
1071 port->port_speed = EHEA_SPEED_1G;
1072 port->full_duplex = 1;
1073 break;
1074 case H_SPEED_10G_F:
1075 port->port_speed = EHEA_SPEED_10G;
1076 port->full_duplex = 1;
1077 break;
1078 default:
1079 port->port_speed = 0;
1080 port->full_duplex = 0;
1081 break;
1082 }
1083 } else {
1084 ehea_error("Failed sensing port speed");
1085 ret = -EIO;
1086 }
1087 } else {
1088 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001089 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001090 ret = -EPERM;
1091 } else {
1092 ret = -EIO;
1093 ehea_error("Failed setting port speed");
1094 }
1095 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001096 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1097 netif_carrier_on(port->netdev);
1098
Thomas Klein3faf2692009-01-21 14:45:33 -08001099 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001100out:
1101 return ret;
1102}
1103
1104static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1105{
1106 int ret;
1107 u8 ec;
1108 u8 portnum;
1109 struct ehea_port *port;
1110
1111 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1112 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1113 port = ehea_get_port(adapter, portnum);
1114
1115 switch (ec) {
1116 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1117
1118 if (!port) {
1119 ehea_error("unknown portnum %x", portnum);
1120 break;
1121 }
1122
1123 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1124 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001125 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001126 if (ret) {
1127 ehea_error("failed resensing port "
1128 "attributes");
1129 break;
1130 }
1131
1132 if (netif_msg_link(port))
1133 ehea_info("%s: Logical port up: %dMbps "
1134 "%s Duplex",
1135 port->netdev->name,
1136 port->port_speed,
1137 port->full_duplex ==
1138 1 ? "Full" : "Half");
1139
1140 netif_carrier_on(port->netdev);
1141 netif_wake_queue(port->netdev);
1142 }
1143 } else
1144 if (netif_carrier_ok(port->netdev)) {
1145 if (netif_msg_link(port))
1146 ehea_info("%s: Logical port down",
1147 port->netdev->name);
1148 netif_carrier_off(port->netdev);
1149 netif_stop_queue(port->netdev);
1150 }
1151
1152 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001153 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001154 if (netif_msg_link(port))
1155 ehea_info("%s: Physical port up",
1156 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001157 if (prop_carrier_state)
1158 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001159 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001160 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001161 if (netif_msg_link(port))
1162 ehea_info("%s: Physical port down",
1163 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001164 if (prop_carrier_state)
1165 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001166 }
1167
1168 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1169 ehea_info("External switch port is primary port");
1170 else
1171 ehea_info("External switch port is backup port");
1172
1173 break;
1174 case EHEA_EC_ADAPTER_MALFUNC:
1175 ehea_error("Adapter malfunction");
1176 break;
1177 case EHEA_EC_PORT_MALFUNC:
1178 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1179 netif_carrier_off(port->netdev);
1180 netif_stop_queue(port->netdev);
1181 break;
1182 default:
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001183 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001184 break;
1185 }
1186}
1187
1188static void ehea_neq_tasklet(unsigned long data)
1189{
Doug Maxey508d2b52008-01-31 20:20:49 -06001190 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001191 struct ehea_eqe *eqe;
1192 u64 event_mask;
1193
1194 eqe = ehea_poll_eq(adapter->neq);
1195 ehea_debug("eqe=%p", eqe);
1196
1197 while (eqe) {
1198 ehea_debug("*eqe=%lx", eqe->entry);
1199 ehea_parse_eqe(adapter, eqe->entry);
1200 eqe = ehea_poll_eq(adapter->neq);
1201 ehea_debug("next eqe=%p", eqe);
1202 }
1203
1204 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1205 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1206 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1207
1208 ehea_h_reset_events(adapter->handle,
1209 adapter->neq->fw_handle, event_mask);
1210}
1211
David Howells7d12e782006-10-05 14:55:46 +01001212static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001213{
1214 struct ehea_adapter *adapter = param;
1215 tasklet_hi_schedule(&adapter->neq_tasklet);
1216 return IRQ_HANDLED;
1217}
1218
1219
1220static int ehea_fill_port_res(struct ehea_port_res *pr)
1221{
1222 int ret;
1223 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1224
Thomas Kleine2878802009-01-21 14:45:57 -08001225 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1226 - init_attr->act_nr_rwqes_rq2
1227 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001228
Thomas Kleine2878802009-01-21 14:45:57 -08001229 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001230
1231 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1232
1233 return ret;
1234}
1235
1236static int ehea_reg_interrupts(struct net_device *dev)
1237{
1238 struct ehea_port *port = netdev_priv(dev);
1239 struct ehea_port_res *pr;
1240 int i, ret;
1241
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001242
1243 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1244 dev->name);
1245
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001246 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001247 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001248 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001249 if (ret) {
1250 ehea_error("failed registering irq for qp_aff_irq_handler:"
1251 "ist=%X", port->qp_eq->attr.ist1);
1252 goto out_free_qpeq;
1253 }
1254
1255 if (netif_msg_ifup(port))
1256 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1257 "registered", port->qp_eq->attr.ist1);
1258
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001259
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001260 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1261 pr = &port->port_res[i];
1262 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001263 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001264 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001265 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001266 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001267 pr);
1268 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001269 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001270 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001271 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001272 goto out_free_req;
1273 }
1274 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001275 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1276 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001277 }
1278out:
1279 return ret;
1280
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001281
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001282out_free_req:
1283 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001284 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001285 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001286 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001287
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001289 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001290 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001291
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001292 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001293
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001294}
1295
1296static void ehea_free_interrupts(struct net_device *dev)
1297{
1298 struct ehea_port *port = netdev_priv(dev);
1299 struct ehea_port_res *pr;
1300 int i;
1301
1302 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001303
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001304 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1305 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001306 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001307 if (netif_msg_intr(port))
1308 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001309 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001310 }
1311
1312 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001313 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001314 if (netif_msg_intr(port))
1315 ehea_info("associated event interrupt for handle 0x%X freed",
1316 port->qp_eq->attr.ist1);
1317}
1318
1319static int ehea_configure_port(struct ehea_port *port)
1320{
1321 int ret, i;
1322 u64 hret, mask;
1323 struct hcp_ehea_port_cb0 *cb0;
1324
1325 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001326 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001327 if (!cb0)
1328 goto out;
1329
1330 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1331 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1332 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1333 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1334 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1335 PXLY_RC_VLAN_FILTER)
1336 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1337
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001338 for (i = 0; i < port->num_mcs; i++)
1339 if (use_mcs)
1340 cb0->default_qpn_arr[i] =
1341 port->port_res[i].qp->init_attr.qp_nr;
1342 else
1343 cb0->default_qpn_arr[i] =
1344 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001345
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001346 if (netif_msg_ifup(port))
1347 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1348
1349 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1350 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1351
1352 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1353 port->logical_port_id,
1354 H_PORT_CB0, mask, cb0);
1355 ret = -EIO;
1356 if (hret != H_SUCCESS)
1357 goto out_free;
1358
1359 ret = 0;
1360
1361out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001362 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001363out:
1364 return ret;
1365}
1366
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001367int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001368{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001369 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001370 struct ehea_adapter *adapter = pr->port->adapter;
1371
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001372 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1373 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374 goto out;
1375
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001376 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1377 if (ret)
1378 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001379
1380 return 0;
1381
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001382out_free:
1383 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001384out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001385 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001386 return -EIO;
1387}
1388
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001389int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001390{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001391 if ((ehea_rem_mr(&pr->send_mr))
1392 || (ehea_rem_mr(&pr->recv_mr)))
1393 return -EIO;
1394 else
1395 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001396}
1397
1398static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1399{
Doug Maxey508d2b52008-01-31 20:20:49 -06001400 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001401
1402 q_skba->arr = vmalloc(arr_size);
1403 if (!q_skba->arr)
1404 return -ENOMEM;
1405
1406 memset(q_skba->arr, 0, arr_size);
1407
1408 q_skba->len = max_q_entries;
1409 q_skba->index = 0;
1410 q_skba->os_skbs = 0;
1411
1412 return 0;
1413}
1414
1415static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1416 struct port_res_cfg *pr_cfg, int queue_token)
1417{
1418 struct ehea_adapter *adapter = port->adapter;
1419 enum ehea_eq_type eq_type = EHEA_EQ;
1420 struct ehea_qp_init_attr *init_attr = NULL;
1421 int ret = -EIO;
1422
1423 memset(pr, 0, sizeof(struct ehea_port_res));
1424
1425 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001426 spin_lock_init(&pr->xmit_lock);
1427 spin_lock_init(&pr->netif_queue);
1428
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001429 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1430 if (!pr->eq) {
1431 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001432 goto out_free;
1433 }
1434
1435 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001436 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001437 port->logical_port_id);
1438 if (!pr->recv_cq) {
1439 ehea_error("create_cq failed (cq_recv)");
1440 goto out_free;
1441 }
1442
1443 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001444 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001445 port->logical_port_id);
1446 if (!pr->send_cq) {
1447 ehea_error("create_cq failed (cq_send)");
1448 goto out_free;
1449 }
1450
1451 if (netif_msg_ifup(port))
1452 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1453 pr->send_cq->attr.act_nr_of_cqes,
1454 pr->recv_cq->attr.act_nr_of_cqes);
1455
1456 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1457 if (!init_attr) {
1458 ret = -ENOMEM;
1459 ehea_error("no mem for ehea_qp_init_attr");
1460 goto out_free;
1461 }
1462
1463 init_attr->low_lat_rq1 = 1;
1464 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1465 init_attr->rq_count = 3;
1466 init_attr->qp_token = queue_token;
1467 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1468 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1469 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1470 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1471 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1472 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1473 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1474 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1475 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1476 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1477 init_attr->port_nr = port->logical_port_id;
1478 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1479 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1480 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1481
1482 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1483 if (!pr->qp) {
1484 ehea_error("create_qp failed");
1485 ret = -EIO;
1486 goto out_free;
1487 }
1488
1489 if (netif_msg_ifup(port))
1490 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1491 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1492 init_attr->act_nr_send_wqes,
1493 init_attr->act_nr_rwqes_rq1,
1494 init_attr->act_nr_rwqes_rq2,
1495 init_attr->act_nr_rwqes_rq3);
1496
Thomas Klein44fb3122008-04-04 15:04:53 +02001497 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1498
1499 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001500 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1501 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1502 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1503 if (ret)
1504 goto out_free;
1505
1506 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1507 if (ehea_gen_smrs(pr) != 0) {
1508 ret = -EIO;
1509 goto out_free;
1510 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001511
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001512 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1513
1514 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001515
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001516 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001517
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001518 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1519 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1520 pr->lro_mgr.lro_arr = pr->lro_desc;
1521 pr->lro_mgr.get_skb_header = get_skb_hdr;
1522 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1523 pr->lro_mgr.dev = port->netdev;
1524 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1525 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1526
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001527 ret = 0;
1528 goto out;
1529
1530out_free:
1531 kfree(init_attr);
1532 vfree(pr->sq_skba.arr);
1533 vfree(pr->rq1_skba.arr);
1534 vfree(pr->rq2_skba.arr);
1535 vfree(pr->rq3_skba.arr);
1536 ehea_destroy_qp(pr->qp);
1537 ehea_destroy_cq(pr->send_cq);
1538 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001539 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001540out:
1541 return ret;
1542}
1543
1544static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1545{
1546 int ret, i;
1547
Hannes Hering357eb462009-08-04 11:48:39 -07001548 if (pr->qp)
1549 netif_napi_del(&pr->napi);
1550
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001551 ret = ehea_destroy_qp(pr->qp);
1552
1553 if (!ret) {
1554 ehea_destroy_cq(pr->send_cq);
1555 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001556 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001557
1558 for (i = 0; i < pr->rq1_skba.len; i++)
1559 if (pr->rq1_skba.arr[i])
1560 dev_kfree_skb(pr->rq1_skba.arr[i]);
1561
1562 for (i = 0; i < pr->rq2_skba.len; i++)
1563 if (pr->rq2_skba.arr[i])
1564 dev_kfree_skb(pr->rq2_skba.arr[i]);
1565
1566 for (i = 0; i < pr->rq3_skba.len; i++)
1567 if (pr->rq3_skba.arr[i])
1568 dev_kfree_skb(pr->rq3_skba.arr[i]);
1569
1570 for (i = 0; i < pr->sq_skba.len; i++)
1571 if (pr->sq_skba.arr[i])
1572 dev_kfree_skb(pr->sq_skba.arr[i]);
1573
1574 vfree(pr->rq1_skba.arr);
1575 vfree(pr->rq2_skba.arr);
1576 vfree(pr->rq3_skba.arr);
1577 vfree(pr->sq_skba.arr);
1578 ret = ehea_rem_smrs(pr);
1579 }
1580 return ret;
1581}
1582
1583/*
1584 * The write_* functions store information in swqe which is used by
1585 * the hardware to calculate the ip/tcp/udp checksum
1586 */
1587
1588static inline void write_ip_start_end(struct ehea_swqe *swqe,
1589 const struct sk_buff *skb)
1590{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001591 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001592 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001593}
1594
1595static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1596 const struct sk_buff *skb)
1597{
1598 swqe->tcp_offset =
1599 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1600
1601 swqe->tcp_end = (u16)skb->len - 1;
1602}
1603
1604static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1605 const struct sk_buff *skb)
1606{
1607 swqe->tcp_offset =
1608 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1609
1610 swqe->tcp_end = (u16)skb->len - 1;
1611}
1612
1613
1614static void write_swqe2_TSO(struct sk_buff *skb,
1615 struct ehea_swqe *swqe, u32 lkey)
1616{
1617 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1618 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1619 int skb_data_size = skb->len - skb->data_len;
1620 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001621
1622 /* Packet is TCP with TSO enabled */
1623 swqe->tx_control |= EHEA_SWQE_TSO;
1624 swqe->mss = skb_shinfo(skb)->gso_size;
1625 /* copy only eth/ip/tcp headers to immediate data and
1626 * the rest of skb->data to sg1entry
1627 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001628 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001629
1630 skb_data_size = skb->len - skb->data_len;
1631
1632 if (skb_data_size >= headersize) {
1633 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001634 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001635 swqe->immediate_data_length = headersize;
1636
1637 if (skb_data_size > headersize) {
1638 /* set sg1entry data */
1639 sg1entry->l_key = lkey;
1640 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001641 sg1entry->vaddr =
1642 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001643 swqe->descriptors++;
1644 }
1645 } else
1646 ehea_error("cannot handle fragmented headers");
1647}
1648
1649static void write_swqe2_nonTSO(struct sk_buff *skb,
1650 struct ehea_swqe *swqe, u32 lkey)
1651{
1652 int skb_data_size = skb->len - skb->data_len;
1653 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1654 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001655
1656 /* Packet is any nonTSO type
1657 *
1658 * Copy as much as possible skb->data to immediate data and
1659 * the rest to sg1entry
1660 */
1661 if (skb_data_size >= SWQE2_MAX_IMM) {
1662 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001663 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001664
1665 swqe->immediate_data_length = SWQE2_MAX_IMM;
1666
1667 if (skb_data_size > SWQE2_MAX_IMM) {
1668 /* copy sg1entry data */
1669 sg1entry->l_key = lkey;
1670 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001671 sg1entry->vaddr =
1672 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001673 swqe->descriptors++;
1674 }
1675 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001676 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001677 swqe->immediate_data_length = skb_data_size;
1678 }
1679}
1680
1681static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1682 struct ehea_swqe *swqe, u32 lkey)
1683{
1684 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1685 skb_frag_t *frag;
1686 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001687
1688 nfrags = skb_shinfo(skb)->nr_frags;
1689 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001690 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001691 swqe->descriptors = 0;
1692 sg1entry_contains_frag_data = 0;
1693
1694 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1695 write_swqe2_TSO(skb, swqe, lkey);
1696 else
1697 write_swqe2_nonTSO(skb, swqe, lkey);
1698
1699 /* write descriptors */
1700 if (nfrags > 0) {
1701 if (swqe->descriptors == 0) {
1702 /* sg1entry not yet used */
1703 frag = &skb_shinfo(skb)->frags[0];
1704
1705 /* copy sg1entry data */
1706 sg1entry->l_key = lkey;
1707 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001708 sg1entry->vaddr =
1709 ehea_map_vaddr(page_address(frag->page)
1710 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001711 swqe->descriptors++;
1712 sg1entry_contains_frag_data = 1;
1713 }
1714
1715 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1716
1717 frag = &skb_shinfo(skb)->frags[i];
1718 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1719
1720 sgentry->l_key = lkey;
1721 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001722 sgentry->vaddr =
1723 ehea_map_vaddr(page_address(frag->page)
1724 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001725 swqe->descriptors++;
1726 }
1727 }
1728}
1729
1730static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1731{
1732 int ret = 0;
1733 u64 hret;
1734 u8 reg_type;
1735
1736 /* De/Register untagged packets */
1737 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1738 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1739 port->logical_port_id,
1740 reg_type, port->mac_addr, 0, hcallid);
1741 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001742 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001743 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001744 ret = -EIO;
1745 goto out_herr;
1746 }
1747
1748 /* De/Register VLAN packets */
1749 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1750 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1751 port->logical_port_id,
1752 reg_type, port->mac_addr, 0, hcallid);
1753 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001754 ehea_error("%sregistering bc address failed (vlan)",
1755 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001756 ret = -EIO;
1757 }
1758out_herr:
1759 return ret;
1760}
1761
1762static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1763{
1764 struct ehea_port *port = netdev_priv(dev);
1765 struct sockaddr *mac_addr = sa;
1766 struct hcp_ehea_port_cb0 *cb0;
1767 int ret;
1768 u64 hret;
1769
1770 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1771 ret = -EADDRNOTAVAIL;
1772 goto out;
1773 }
1774
Thomas Klein3faf2692009-01-21 14:45:33 -08001775 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001776 if (!cb0) {
1777 ehea_error("no mem for cb0");
1778 ret = -ENOMEM;
1779 goto out;
1780 }
1781
1782 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1783
1784 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1785
1786 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1787 port->logical_port_id, H_PORT_CB0,
1788 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1789 if (hret != H_SUCCESS) {
1790 ret = -EIO;
1791 goto out_free;
1792 }
1793
1794 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1795
1796 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001797 if (port->state == EHEA_PORT_UP) {
1798 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1799 if (ret)
1800 goto out_upregs;
1801 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001802
1803 port->mac_addr = cb0->port_mac_addr << 16;
1804
1805 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001806 if (port->state == EHEA_PORT_UP) {
1807 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1808 if (ret)
1809 goto out_upregs;
1810 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001811
1812 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001813
1814out_upregs:
1815 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001816out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001817 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001818out:
1819 return ret;
1820}
1821
1822static void ehea_promiscuous_error(u64 hret, int enable)
1823{
Thomas Klein7674a582007-01-22 12:54:20 +01001824 if (hret == H_AUTHORITY)
1825 ehea_info("Hypervisor denied %sabling promiscuous mode",
1826 enable == 1 ? "en" : "dis");
1827 else
1828 ehea_error("failed %sabling promiscuous mode",
1829 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001830}
1831
1832static void ehea_promiscuous(struct net_device *dev, int enable)
1833{
1834 struct ehea_port *port = netdev_priv(dev);
1835 struct hcp_ehea_port_cb7 *cb7;
1836 u64 hret;
1837
1838 if ((enable && port->promisc) || (!enable && !port->promisc))
1839 return;
1840
Thomas Klein3faf2692009-01-21 14:45:33 -08001841 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001842 if (!cb7) {
1843 ehea_error("no mem for cb7");
1844 goto out;
1845 }
1846
1847 /* Modify Pxs_DUCQPN in CB7 */
1848 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1849
1850 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1851 port->logical_port_id,
1852 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1853 if (hret) {
1854 ehea_promiscuous_error(hret, enable);
1855 goto out;
1856 }
1857
1858 port->promisc = enable;
1859out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001860 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001861 return;
1862}
1863
1864static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1865 u32 hcallid)
1866{
1867 u64 hret;
1868 u8 reg_type;
1869
1870 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1871 | EHEA_BCMC_UNTAGGED;
1872
1873 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1874 port->logical_port_id,
1875 reg_type, mc_mac_addr, 0, hcallid);
1876 if (hret)
1877 goto out;
1878
1879 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1880 | EHEA_BCMC_VLANID_ALL;
1881
1882 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1883 port->logical_port_id,
1884 reg_type, mc_mac_addr, 0, hcallid);
1885out:
1886 return hret;
1887}
1888
1889static int ehea_drop_multicast_list(struct net_device *dev)
1890{
1891 struct ehea_port *port = netdev_priv(dev);
1892 struct ehea_mc_list *mc_entry = port->mc_list;
1893 struct list_head *pos;
1894 struct list_head *temp;
1895 int ret = 0;
1896 u64 hret;
1897
1898 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1899 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1900
1901 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1902 H_DEREG_BCMC);
1903 if (hret) {
1904 ehea_error("failed deregistering mcast MAC");
1905 ret = -EIO;
1906 }
1907
1908 list_del(pos);
1909 kfree(mc_entry);
1910 }
1911 return ret;
1912}
1913
1914static void ehea_allmulti(struct net_device *dev, int enable)
1915{
1916 struct ehea_port *port = netdev_priv(dev);
1917 u64 hret;
1918
1919 if (!port->allmulti) {
1920 if (enable) {
1921 /* Enable ALLMULTI */
1922 ehea_drop_multicast_list(dev);
1923 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1924 if (!hret)
1925 port->allmulti = 1;
1926 else
1927 ehea_error("failed enabling IFF_ALLMULTI");
1928 }
1929 } else
1930 if (!enable) {
1931 /* Disable ALLMULTI */
1932 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1933 if (!hret)
1934 port->allmulti = 0;
1935 else
1936 ehea_error("failed disabling IFF_ALLMULTI");
1937 }
1938}
1939
Doug Maxey508d2b52008-01-31 20:20:49 -06001940static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001941{
1942 struct ehea_mc_list *ehea_mcl_entry;
1943 u64 hret;
1944
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001945 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001946 if (!ehea_mcl_entry) {
1947 ehea_error("no mem for mcl_entry");
1948 return;
1949 }
1950
1951 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1952
1953 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1954
1955 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1956 H_REG_BCMC);
1957 if (!hret)
1958 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1959 else {
1960 ehea_error("failed registering mcast MAC");
1961 kfree(ehea_mcl_entry);
1962 }
1963}
1964
1965static void ehea_set_multicast_list(struct net_device *dev)
1966{
1967 struct ehea_port *port = netdev_priv(dev);
1968 struct dev_mc_list *k_mcl_entry;
1969 int ret, i;
1970
1971 if (dev->flags & IFF_PROMISC) {
1972 ehea_promiscuous(dev, 1);
1973 return;
1974 }
1975 ehea_promiscuous(dev, 0);
1976
1977 if (dev->flags & IFF_ALLMULTI) {
1978 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001979 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001980 }
1981 ehea_allmulti(dev, 0);
1982
1983 if (dev->mc_count) {
1984 ret = ehea_drop_multicast_list(dev);
1985 if (ret) {
1986 /* Dropping the current multicast list failed.
1987 * Enabling ALL_MULTI is the best we can do.
1988 */
1989 ehea_allmulti(dev, 1);
1990 }
1991
1992 if (dev->mc_count > port->adapter->max_mc_mac) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001993 ehea_info("Mcast registration limit reached (0x%llx). "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001994 "Use ALLMULTI!",
1995 port->adapter->max_mc_mac);
1996 goto out;
1997 }
1998
Doug Maxey508d2b52008-01-31 20:20:49 -06001999 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
2000 k_mcl_entry = k_mcl_entry->next)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002001 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002002
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002003 }
2004out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002005 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002006 return;
2007}
2008
2009static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2010{
2011 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2012 return -EINVAL;
2013 dev->mtu = new_mtu;
2014 return 0;
2015}
2016
2017static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2018 struct ehea_swqe *swqe, u32 lkey)
2019{
2020 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002021 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002022
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002023 /* IPv4 */
2024 swqe->tx_control |= EHEA_SWQE_CRC
2025 | EHEA_SWQE_IP_CHECKSUM
2026 | EHEA_SWQE_TCP_CHECKSUM
2027 | EHEA_SWQE_IMM_DATA_PRESENT
2028 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2029
2030 write_ip_start_end(swqe, skb);
2031
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002032 if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002033 if ((iph->frag_off & IP_MF)
2034 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002035 /* IP fragment, so don't change cs */
2036 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2037 else
2038 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002039 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002040 write_tcp_offset_end(swqe, skb);
2041 }
2042
2043 /* icmp (big data) and ip segmentation packets (all other ip
2044 packets) do not require any special handling */
2045
2046 } else {
2047 /* Other Ethernet Protocol */
2048 swqe->tx_control |= EHEA_SWQE_CRC
2049 | EHEA_SWQE_IMM_DATA_PRESENT
2050 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2051 }
2052
2053 write_swqe2_data(skb, dev, swqe, lkey);
2054}
2055
2056static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2057 struct ehea_swqe *swqe)
2058{
2059 int nfrags = skb_shinfo(skb)->nr_frags;
2060 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2061 skb_frag_t *frag;
2062 int i;
2063
2064 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002065 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002066
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002067 /* IPv4 */
2068 write_ip_start_end(swqe, skb);
2069
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002070 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002071 swqe->tx_control |= EHEA_SWQE_CRC
2072 | EHEA_SWQE_IP_CHECKSUM
2073 | EHEA_SWQE_TCP_CHECKSUM
2074 | EHEA_SWQE_IMM_DATA_PRESENT;
2075
2076 write_tcp_offset_end(swqe, skb);
2077
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002078 } else if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002079 if ((iph->frag_off & IP_MF)
2080 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002081 /* IP fragment, so don't change cs */
2082 swqe->tx_control |= EHEA_SWQE_CRC
2083 | EHEA_SWQE_IMM_DATA_PRESENT;
2084 else {
2085 swqe->tx_control |= EHEA_SWQE_CRC
2086 | EHEA_SWQE_IP_CHECKSUM
2087 | EHEA_SWQE_TCP_CHECKSUM
2088 | EHEA_SWQE_IMM_DATA_PRESENT;
2089
2090 write_udp_offset_end(swqe, skb);
2091 }
2092 } else {
2093 /* icmp (big data) and
2094 ip segmentation packets (all other ip packets) */
2095 swqe->tx_control |= EHEA_SWQE_CRC
2096 | EHEA_SWQE_IP_CHECKSUM
2097 | EHEA_SWQE_IMM_DATA_PRESENT;
2098 }
2099 } else {
2100 /* Other Ethernet Protocol */
2101 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2102 }
2103 /* copy (immediate) data */
2104 if (nfrags == 0) {
2105 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002106 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002107 } else {
2108 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002109 skb_copy_from_linear_data(skb, imm_data,
2110 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111 imm_data += skb->len - skb->data_len;
2112
2113 /* ... then copy data from the fragments */
2114 for (i = 0; i < nfrags; i++) {
2115 frag = &skb_shinfo(skb)->frags[i];
2116 memcpy(imm_data,
2117 page_address(frag->page) + frag->page_offset,
2118 frag->size);
2119 imm_data += frag->size;
2120 }
2121 }
2122 swqe->immediate_data_length = skb->len;
2123 dev_kfree_skb(skb);
2124}
2125
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002126static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2127{
2128 struct tcphdr *tcp;
2129 u32 tmp;
2130
2131 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002132 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002133 tcp = (struct tcphdr *)(skb_network_header(skb) +
2134 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002135 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002136 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002137 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002138 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002139 return 0;
2140}
2141
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002142static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2143{
2144 struct ehea_port *port = netdev_priv(dev);
2145 struct ehea_swqe *swqe;
2146 unsigned long flags;
2147 u32 lkey;
2148 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002149 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002150
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002151 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2152
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002153 if (!spin_trylock(&pr->xmit_lock))
2154 return NETDEV_TX_BUSY;
2155
2156 if (pr->queue_stopped) {
2157 spin_unlock(&pr->xmit_lock);
2158 return NETDEV_TX_BUSY;
2159 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002160
2161 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2162 memset(swqe, 0, SWQE_HEADER_SIZE);
2163 atomic_dec(&pr->swqe_avail);
2164
2165 if (skb->len <= SWQE3_MAX_IMM) {
2166 u32 sig_iv = port->sig_comp_iv;
2167 u32 swqe_num = pr->swqe_id_counter;
2168 ehea_xmit3(skb, dev, swqe);
2169 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2170 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2171 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2172 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2173 sig_iv);
2174 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2175 pr->swqe_ll_count = 0;
2176 } else
2177 pr->swqe_ll_count += 1;
2178 } else {
2179 swqe->wr_id =
2180 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2181 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002182 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002183 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2184 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2185
2186 pr->sq_skba.index++;
2187 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2188
2189 lkey = pr->send_mr.lkey;
2190 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002191 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002192 }
2193 pr->swqe_id_counter += 1;
2194
2195 if (port->vgrp && vlan_tx_tag_present(skb)) {
2196 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2197 swqe->vlan_tag = vlan_tx_tag_get(skb);
2198 }
2199
2200 if (netif_msg_tx_queued(port)) {
2201 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002202 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002203 }
2204
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002205 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2206 netif_stop_queue(dev);
2207 swqe->tx_control |= EHEA_SWQE_PURGE;
2208 }
Thomas Klein44c82152007-07-11 16:32:00 +02002209
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002210 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002211 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002212
2213 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2214 spin_lock_irqsave(&pr->netif_queue, flags);
2215 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002216 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002217 netif_stop_queue(dev);
2218 pr->queue_stopped = 1;
2219 }
2220 spin_unlock_irqrestore(&pr->netif_queue, flags);
2221 }
2222 dev->trans_start = jiffies;
2223 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002224
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002225 return NETDEV_TX_OK;
2226}
2227
2228static void ehea_vlan_rx_register(struct net_device *dev,
2229 struct vlan_group *grp)
2230{
2231 struct ehea_port *port = netdev_priv(dev);
2232 struct ehea_adapter *adapter = port->adapter;
2233 struct hcp_ehea_port_cb1 *cb1;
2234 u64 hret;
2235
2236 port->vgrp = grp;
2237
Thomas Klein3faf2692009-01-21 14:45:33 -08002238 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002239 if (!cb1) {
2240 ehea_error("no mem for cb1");
2241 goto out;
2242 }
2243
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002244 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2245 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2246 if (hret != H_SUCCESS)
2247 ehea_error("modify_ehea_port failed");
2248
Thomas Klein3faf2692009-01-21 14:45:33 -08002249 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002250out:
2251 return;
2252}
2253
2254static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2255{
2256 struct ehea_port *port = netdev_priv(dev);
2257 struct ehea_adapter *adapter = port->adapter;
2258 struct hcp_ehea_port_cb1 *cb1;
2259 int index;
2260 u64 hret;
2261
Thomas Klein3faf2692009-01-21 14:45:33 -08002262 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002263 if (!cb1) {
2264 ehea_error("no mem for cb1");
2265 goto out;
2266 }
2267
2268 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2269 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2270 if (hret != H_SUCCESS) {
2271 ehea_error("query_ehea_port failed");
2272 goto out;
2273 }
2274
2275 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002276 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002277
2278 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2279 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2280 if (hret != H_SUCCESS)
2281 ehea_error("modify_ehea_port failed");
2282out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002283 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002284 return;
2285}
2286
2287static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2288{
2289 struct ehea_port *port = netdev_priv(dev);
2290 struct ehea_adapter *adapter = port->adapter;
2291 struct hcp_ehea_port_cb1 *cb1;
2292 int index;
2293 u64 hret;
2294
Dan Aloni5c15bde2007-03-02 20:44:51 -08002295 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002296
Thomas Klein3faf2692009-01-21 14:45:33 -08002297 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002298 if (!cb1) {
2299 ehea_error("no mem for cb1");
2300 goto out;
2301 }
2302
2303 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2304 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2305 if (hret != H_SUCCESS) {
2306 ehea_error("query_ehea_port failed");
2307 goto out;
2308 }
2309
2310 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002311 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002312
2313 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2314 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2315 if (hret != H_SUCCESS)
2316 ehea_error("modify_ehea_port failed");
2317out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002318 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002319 return;
2320}
2321
2322int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2323{
2324 int ret = -EIO;
2325 u64 hret;
2326 u16 dummy16 = 0;
2327 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002328 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002329
Thomas Klein3faf2692009-01-21 14:45:33 -08002330 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331 if (!cb0) {
2332 ret = -ENOMEM;
2333 goto out;
2334 }
2335
2336 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2337 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2338 if (hret != H_SUCCESS) {
2339 ehea_error("query_ehea_qp failed (1)");
2340 goto out;
2341 }
2342
2343 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2344 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2345 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2346 &dummy64, &dummy64, &dummy16, &dummy16);
2347 if (hret != H_SUCCESS) {
2348 ehea_error("modify_ehea_qp failed (1)");
2349 goto out;
2350 }
2351
2352 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2353 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2354 if (hret != H_SUCCESS) {
2355 ehea_error("query_ehea_qp failed (2)");
2356 goto out;
2357 }
2358
2359 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2360 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2361 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2362 &dummy64, &dummy64, &dummy16, &dummy16);
2363 if (hret != H_SUCCESS) {
2364 ehea_error("modify_ehea_qp failed (2)");
2365 goto out;
2366 }
2367
2368 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2369 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2370 if (hret != H_SUCCESS) {
2371 ehea_error("query_ehea_qp failed (3)");
2372 goto out;
2373 }
2374
2375 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2376 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2377 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2378 &dummy64, &dummy64, &dummy16, &dummy16);
2379 if (hret != H_SUCCESS) {
2380 ehea_error("modify_ehea_qp failed (3)");
2381 goto out;
2382 }
2383
2384 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2385 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2386 if (hret != H_SUCCESS) {
2387 ehea_error("query_ehea_qp failed (4)");
2388 goto out;
2389 }
2390
2391 ret = 0;
2392out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002393 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002394 return ret;
2395}
2396
2397static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2398 int add_tx_qps)
2399{
2400 int ret, i;
2401 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2402 enum ehea_eq_type eq_type = EHEA_EQ;
2403
2404 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2405 EHEA_MAX_ENTRIES_EQ, 1);
2406 if (!port->qp_eq) {
2407 ret = -EINVAL;
2408 ehea_error("ehea_create_eq failed (qp_eq)");
2409 goto out_kill_eq;
2410 }
2411
2412 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002413 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002414 pr_cfg.max_entries_sq = sq_entries;
2415 pr_cfg.max_entries_rq1 = rq1_entries;
2416 pr_cfg.max_entries_rq2 = rq2_entries;
2417 pr_cfg.max_entries_rq3 = rq3_entries;
2418
2419 pr_cfg_small_rx.max_entries_rcq = 1;
2420 pr_cfg_small_rx.max_entries_scq = sq_entries;
2421 pr_cfg_small_rx.max_entries_sq = sq_entries;
2422 pr_cfg_small_rx.max_entries_rq1 = 1;
2423 pr_cfg_small_rx.max_entries_rq2 = 1;
2424 pr_cfg_small_rx.max_entries_rq3 = 1;
2425
2426 for (i = 0; i < def_qps; i++) {
2427 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2428 if (ret)
2429 goto out_clean_pr;
2430 }
2431 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2432 ret = ehea_init_port_res(port, &port->port_res[i],
2433 &pr_cfg_small_rx, i);
2434 if (ret)
2435 goto out_clean_pr;
2436 }
2437
2438 return 0;
2439
2440out_clean_pr:
2441 while (--i >= 0)
2442 ehea_clean_portres(port, &port->port_res[i]);
2443
2444out_kill_eq:
2445 ehea_destroy_eq(port->qp_eq);
2446 return ret;
2447}
2448
2449static int ehea_clean_all_portres(struct ehea_port *port)
2450{
2451 int ret = 0;
2452 int i;
2453
Doug Maxey508d2b52008-01-31 20:20:49 -06002454 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002455 ret |= ehea_clean_portres(port, &port->port_res[i]);
2456
2457 ret |= ehea_destroy_eq(port->qp_eq);
2458
2459 return ret;
2460}
2461
Thomas Klein35cf2e22007-08-06 13:55:14 +02002462static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002463{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002464 if (adapter->active_ports)
2465 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002466
2467 ehea_rem_mr(&adapter->mr);
2468}
2469
Thomas Klein35cf2e22007-08-06 13:55:14 +02002470static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002471{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002472 if (adapter->active_ports)
2473 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002474
2475 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2476}
2477
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002478static int ehea_up(struct net_device *dev)
2479{
2480 int ret, i;
2481 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002482
2483 if (port->state == EHEA_PORT_UP)
2484 return 0;
2485
2486 ret = ehea_port_res_setup(port, port->num_def_qps,
2487 port->num_add_tx_qps);
2488 if (ret) {
2489 ehea_error("port_res_failed");
2490 goto out;
2491 }
2492
2493 /* Set default QP for this port */
2494 ret = ehea_configure_port(port);
2495 if (ret) {
2496 ehea_error("ehea_configure_port failed. ret:%d", ret);
2497 goto out_clean_pr;
2498 }
2499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002500 ret = ehea_reg_interrupts(dev);
2501 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002502 ehea_error("reg_interrupts failed. ret:%d", ret);
2503 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002504 }
2505
Doug Maxey508d2b52008-01-31 20:20:49 -06002506 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002507 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2508 if (ret) {
2509 ehea_error("activate_qp failed");
2510 goto out_free_irqs;
2511 }
2512 }
2513
Doug Maxey508d2b52008-01-31 20:20:49 -06002514 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002515 ret = ehea_fill_port_res(&port->port_res[i]);
2516 if (ret) {
2517 ehea_error("out_free_irqs");
2518 goto out_free_irqs;
2519 }
2520 }
2521
Thomas Klein21eee2d2008-02-13 16:18:33 +01002522 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2523 if (ret) {
2524 ret = -EIO;
2525 goto out_free_irqs;
2526 }
2527
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002528 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002529
2530 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002531 goto out;
2532
2533out_free_irqs:
2534 ehea_free_interrupts(dev);
2535
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002536out_clean_pr:
2537 ehea_clean_all_portres(port);
2538out:
Thomas Klein44c82152007-07-11 16:32:00 +02002539 if (ret)
2540 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2541
Thomas Klein21eee2d2008-02-13 16:18:33 +01002542 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002543 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002544
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002545 return ret;
2546}
2547
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002548static void port_napi_disable(struct ehea_port *port)
2549{
2550 int i;
2551
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002552 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002553 napi_disable(&port->port_res[i].napi);
2554}
2555
2556static void port_napi_enable(struct ehea_port *port)
2557{
2558 int i;
2559
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002560 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002561 napi_enable(&port->port_res[i].napi);
2562}
2563
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002564static int ehea_open(struct net_device *dev)
2565{
2566 int ret;
2567 struct ehea_port *port = netdev_priv(dev);
2568
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002569 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002570
2571 if (netif_msg_ifup(port))
2572 ehea_info("enabling port %s", dev->name);
2573
2574 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002575 if (!ret) {
2576 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002577 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002578 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002579
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002580 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002581
2582 return ret;
2583}
2584
2585static int ehea_down(struct net_device *dev)
2586{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002587 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002588 struct ehea_port *port = netdev_priv(dev);
2589
2590 if (port->state == EHEA_PORT_DOWN)
2591 return 0;
2592
2593 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002594 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2595
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002596 ehea_free_interrupts(dev);
2597
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002598 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002599
Thomas Klein21eee2d2008-02-13 16:18:33 +01002600 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002601
Thomas Klein44c82152007-07-11 16:32:00 +02002602 ret = ehea_clean_all_portres(port);
2603 if (ret)
2604 ehea_info("Failed freeing resources for %s. ret=%i",
2605 dev->name, ret);
2606
Thomas Klein21eee2d2008-02-13 16:18:33 +01002607 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002608
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002609 return ret;
2610}
2611
2612static int ehea_stop(struct net_device *dev)
2613{
2614 int ret;
2615 struct ehea_port *port = netdev_priv(dev);
2616
2617 if (netif_msg_ifdown(port))
2618 ehea_info("disabling port %s", dev->name);
2619
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002620 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002621 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002622 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002623 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002624 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002625 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002626 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002627 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002628 return ret;
2629}
2630
Andrew Morton22559c52008-04-18 13:50:39 -07002631static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002632{
2633 struct ehea_qp qp = *orig_qp;
2634 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2635 struct ehea_swqe *swqe;
2636 int wqe_index;
2637 int i;
2638
2639 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2640 swqe = ehea_get_swqe(&qp, &wqe_index);
2641 swqe->tx_control |= EHEA_SWQE_PURGE;
2642 }
2643}
2644
Andrew Morton22559c52008-04-18 13:50:39 -07002645static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002646{
2647 int i;
2648
2649 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2650 struct ehea_port_res *pr = &port->port_res[i];
2651 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2652 int k = 0;
2653 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2654 msleep(5);
2655 if (++k == 20)
2656 break;
2657 }
2658 }
2659}
2660
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002661int ehea_stop_qps(struct net_device *dev)
2662{
2663 struct ehea_port *port = netdev_priv(dev);
2664 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002665 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002666 int ret = -EIO;
2667 int dret;
2668 int i;
2669 u64 hret;
2670 u64 dummy64 = 0;
2671 u16 dummy16 = 0;
2672
Thomas Klein3faf2692009-01-21 14:45:33 -08002673 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002674 if (!cb0) {
2675 ret = -ENOMEM;
2676 goto out;
2677 }
2678
2679 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2680 struct ehea_port_res *pr = &port->port_res[i];
2681 struct ehea_qp *qp = pr->qp;
2682
2683 /* Purge send queue */
2684 ehea_purge_sq(qp);
2685
2686 /* Disable queue pair */
2687 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2688 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2689 cb0);
2690 if (hret != H_SUCCESS) {
2691 ehea_error("query_ehea_qp failed (1)");
2692 goto out;
2693 }
2694
2695 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2696 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2697
2698 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2699 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2700 1), cb0, &dummy64,
2701 &dummy64, &dummy16, &dummy16);
2702 if (hret != H_SUCCESS) {
2703 ehea_error("modify_ehea_qp failed (1)");
2704 goto out;
2705 }
2706
2707 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2708 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2709 cb0);
2710 if (hret != H_SUCCESS) {
2711 ehea_error("query_ehea_qp failed (2)");
2712 goto out;
2713 }
2714
2715 /* deregister shared memory regions */
2716 dret = ehea_rem_smrs(pr);
2717 if (dret) {
2718 ehea_error("unreg shared memory region failed");
2719 goto out;
2720 }
2721 }
2722
2723 ret = 0;
2724out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002725 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002726
2727 return ret;
2728}
2729
Doug Maxey508d2b52008-01-31 20:20:49 -06002730void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002731{
2732 struct ehea_qp qp = *orig_qp;
2733 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2734 struct ehea_rwqe *rwqe;
2735 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2736 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2737 struct sk_buff *skb;
2738 u32 lkey = pr->recv_mr.lkey;
2739
2740
2741 int i;
2742 int index;
2743
2744 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2745 rwqe = ehea_get_next_rwqe(&qp, 2);
2746 rwqe->sg_list[0].l_key = lkey;
2747 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2748 skb = skba_rq2[index];
2749 if (skb)
2750 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2751 }
2752
2753 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2754 rwqe = ehea_get_next_rwqe(&qp, 3);
2755 rwqe->sg_list[0].l_key = lkey;
2756 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2757 skb = skba_rq3[index];
2758 if (skb)
2759 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2760 }
2761}
2762
2763int ehea_restart_qps(struct net_device *dev)
2764{
2765 struct ehea_port *port = netdev_priv(dev);
2766 struct ehea_adapter *adapter = port->adapter;
2767 int ret = 0;
2768 int i;
2769
Doug Maxey508d2b52008-01-31 20:20:49 -06002770 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002771 u64 hret;
2772 u64 dummy64 = 0;
2773 u16 dummy16 = 0;
2774
Thomas Klein3faf2692009-01-21 14:45:33 -08002775 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002776 if (!cb0) {
2777 ret = -ENOMEM;
2778 goto out;
2779 }
2780
2781 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2782 struct ehea_port_res *pr = &port->port_res[i];
2783 struct ehea_qp *qp = pr->qp;
2784
2785 ret = ehea_gen_smrs(pr);
2786 if (ret) {
2787 ehea_error("creation of shared memory regions failed");
2788 goto out;
2789 }
2790
2791 ehea_update_rqs(qp, pr);
2792
2793 /* Enable queue pair */
2794 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2795 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2796 cb0);
2797 if (hret != H_SUCCESS) {
2798 ehea_error("query_ehea_qp failed (1)");
2799 goto out;
2800 }
2801
2802 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2803 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2804
2805 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2806 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2807 1), cb0, &dummy64,
2808 &dummy64, &dummy16, &dummy16);
2809 if (hret != H_SUCCESS) {
2810 ehea_error("modify_ehea_qp failed (1)");
2811 goto out;
2812 }
2813
2814 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2815 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2816 cb0);
2817 if (hret != H_SUCCESS) {
2818 ehea_error("query_ehea_qp failed (2)");
2819 goto out;
2820 }
2821
2822 /* refill entire queue */
2823 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2824 ehea_refill_rq2(pr, 0);
2825 ehea_refill_rq3(pr, 0);
2826 }
2827out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002828 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002829
2830 return ret;
2831}
2832
David Howellsc4028952006-11-22 14:57:56 +00002833static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002834{
2835 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002836 struct ehea_port *port =
2837 container_of(work, struct ehea_port, reset_task);
2838 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002839
2840 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002841 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002842 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002843
2844 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002845
Thomas Klein44c82152007-07-11 16:32:00 +02002846 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002847
2848 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002849 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002850 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002851
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002852 ehea_set_multicast_list(dev);
2853
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002854 if (netif_msg_timer(port))
2855 ehea_info("Device %s resetted successfully", dev->name);
2856
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002857 port_napi_enable(port);
2858
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002859 netif_wake_queue(dev);
2860out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002861 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002862 return;
2863}
2864
Thomas Klein44c82152007-07-11 16:32:00 +02002865static void ehea_rereg_mrs(struct work_struct *work)
2866{
2867 int ret, i;
2868 struct ehea_adapter *adapter;
2869
Daniel Walker06f89ed2008-03-28 14:41:26 -07002870 mutex_lock(&dlpar_mem_lock);
Hannes Heringd4f12da2008-10-16 11:36:42 +02002871 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002872
2873 list_for_each_entry(adapter, &adapter_list, list)
2874 if (adapter->active_ports) {
2875 /* Shutdown all ports */
2876 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2877 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002878 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002879
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002880 if (!port)
2881 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002882
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002883 dev = port->netdev;
2884
2885 if (dev->flags & IFF_UP) {
2886 mutex_lock(&port->port_lock);
2887 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002888 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002889 ret = ehea_stop_qps(dev);
2890 if (ret) {
2891 mutex_unlock(&port->port_lock);
2892 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002893 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002894 port_napi_disable(port);
2895 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002896 }
2897 }
2898
2899 /* Unregister old memory region */
2900 ret = ehea_rem_mr(&adapter->mr);
2901 if (ret) {
2902 ehea_error("unregister MR failed - driver"
2903 " inoperable!");
2904 goto out;
2905 }
2906 }
2907
Thomas Klein44c82152007-07-11 16:32:00 +02002908 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2909
2910 list_for_each_entry(adapter, &adapter_list, list)
2911 if (adapter->active_ports) {
2912 /* Register new memory region */
2913 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2914 if (ret) {
2915 ehea_error("register MR failed - driver"
2916 " inoperable!");
2917 goto out;
2918 }
2919
2920 /* Restart all ports */
2921 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2922 struct ehea_port *port = adapter->port[i];
2923
2924 if (port) {
2925 struct net_device *dev = port->netdev;
2926
2927 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002928 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002929 port_napi_enable(port);
2930 ret = ehea_restart_qps(dev);
2931 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002932 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002933 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002934 }
2935 }
2936 }
2937 }
Julia Lawall68905eb2008-07-21 09:57:26 +02002938 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002939out:
Julia Lawall68905eb2008-07-21 09:57:26 +02002940 mutex_unlock(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002941 return;
2942}
2943
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002944static void ehea_tx_watchdog(struct net_device *dev)
2945{
2946 struct ehea_port *port = netdev_priv(dev);
2947
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002948 if (netif_carrier_ok(dev) &&
2949 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002950 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002951}
2952
2953int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2954{
2955 struct hcp_query_ehea *cb;
2956 u64 hret;
2957 int ret;
2958
Thomas Klein3faf2692009-01-21 14:45:33 -08002959 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002960 if (!cb) {
2961 ret = -ENOMEM;
2962 goto out;
2963 }
2964
2965 hret = ehea_h_query_ehea(adapter->handle, cb);
2966
2967 if (hret != H_SUCCESS) {
2968 ret = -EIO;
2969 goto out_herr;
2970 }
2971
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002972 adapter->max_mc_mac = cb->max_mc_mac - 1;
2973 ret = 0;
2974
2975out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002976 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002977out:
2978 return ret;
2979}
2980
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002981int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2982{
2983 struct hcp_ehea_port_cb4 *cb4;
2984 u64 hret;
2985 int ret = 0;
2986
2987 *jumbo = 0;
2988
2989 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002990 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002991 if (!cb4) {
2992 ehea_error("no mem for cb4");
2993 ret = -ENOMEM;
2994 goto out;
2995 } else {
2996 hret = ehea_h_query_ehea_port(port->adapter->handle,
2997 port->logical_port_id,
2998 H_PORT_CB4,
2999 H_PORT_CB4_JUMBO, cb4);
3000 if (hret == H_SUCCESS) {
3001 if (cb4->jumbo_frame)
3002 *jumbo = 1;
3003 else {
3004 cb4->jumbo_frame = 1;
3005 hret = ehea_h_modify_ehea_port(port->adapter->
3006 handle,
3007 port->
3008 logical_port_id,
3009 H_PORT_CB4,
3010 H_PORT_CB4_JUMBO,
3011 cb4);
3012 if (hret == H_SUCCESS)
3013 *jumbo = 1;
3014 }
3015 } else
3016 ret = -EINVAL;
3017
Thomas Klein3faf2692009-01-21 14:45:33 -08003018 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003019 }
3020out:
3021 return ret;
3022}
3023
3024static ssize_t ehea_show_port_id(struct device *dev,
3025 struct device_attribute *attr, char *buf)
3026{
3027 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003028 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003029}
3030
3031static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3032 NULL);
3033
3034static void __devinit logical_port_release(struct device *dev)
3035{
3036 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3037 of_node_put(port->ofdev.node);
3038}
3039
3040static struct device *ehea_register_port(struct ehea_port *port,
3041 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003042{
3043 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003044
3045 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003046 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003047 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003048
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003049 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003050 port->ofdev.dev.release = logical_port_release;
3051
3052 ret = of_device_register(&port->ofdev);
3053 if (ret) {
3054 ehea_error("failed to register device. ret=%d", ret);
3055 goto out;
3056 }
3057
3058 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003059 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003060 ehea_error("failed to register attributes, ret=%d", ret);
3061 goto out_unreg_of_dev;
3062 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003063
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003064 return &port->ofdev.dev;
3065
3066out_unreg_of_dev:
3067 of_device_unregister(&port->ofdev);
3068out:
3069 return NULL;
3070}
3071
3072static void ehea_unregister_port(struct ehea_port *port)
3073{
3074 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3075 of_device_unregister(&port->ofdev);
3076}
3077
Thomas Klein086c1b22009-01-21 14:43:59 -08003078static const struct net_device_ops ehea_netdev_ops = {
3079 .ndo_open = ehea_open,
3080 .ndo_stop = ehea_stop,
3081 .ndo_start_xmit = ehea_start_xmit,
3082#ifdef CONFIG_NET_POLL_CONTROLLER
3083 .ndo_poll_controller = ehea_netpoll,
3084#endif
3085 .ndo_get_stats = ehea_get_stats,
Ben Hutchings635ecaa2009-07-09 17:59:01 +00003086 .ndo_change_mtu = eth_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08003087 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003088 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003089 .ndo_set_multicast_list = ehea_set_multicast_list,
3090 .ndo_change_mtu = ehea_change_mtu,
3091 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3092 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003093 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3094 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003095};
3096
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003097struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3098 u32 logical_port_id,
3099 struct device_node *dn)
3100{
3101 int ret;
3102 struct net_device *dev;
3103 struct ehea_port *port;
3104 struct device *port_dev;
3105 int jumbo;
3106
3107 /* allocate memory for the port structures */
3108 dev = alloc_etherdev(sizeof(struct ehea_port));
3109
3110 if (!dev) {
3111 ehea_error("no mem for net_device");
3112 ret = -ENOMEM;
3113 goto out_err;
3114 }
3115
3116 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003117
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003118 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003119 port->state = EHEA_PORT_DOWN;
3120 port->sig_comp_iv = sq_entries / 10;
3121
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003122 port->adapter = adapter;
3123 port->netdev = dev;
3124 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003125
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003127
3128 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3129 if (!port->mc_list) {
3130 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003132 }
3133
3134 INIT_LIST_HEAD(&port->mc_list->list);
3135
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003136 ret = ehea_sense_port_attr(port);
3137 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003138 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003139
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003140 port_dev = ehea_register_port(port, dn);
3141 if (!port_dev)
3142 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003143
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003144 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003145
3146 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003147 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3148
Thomas Klein086c1b22009-01-21 14:43:59 -08003149 dev->netdev_ops = &ehea_netdev_ops;
3150 ehea_set_ethtool_ops(dev);
3151
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003152 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003153 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003154 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3155 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003156 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3157
David Howellsc4028952006-11-22 14:57:56 +00003158 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003159
3160 ret = register_netdev(dev);
3161 if (ret) {
3162 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003163 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003164 }
3165
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003166 port->lro_max_aggr = lro_max_aggr;
3167
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003169 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003170 ehea_error("failed determining jumbo frame status for %s",
3171 port->netdev->name);
3172
Thomas Klein9c750b72007-01-29 18:44:01 +01003173 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3174 jumbo == 1 ? "en" : "dis");
3175
Thomas Klein44c82152007-07-11 16:32:00 +02003176 adapter->active_ports++;
3177
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003178 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003179
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003180out_unreg_port:
3181 ehea_unregister_port(port);
3182
3183out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003184 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003185
3186out_free_ethdev:
3187 free_netdev(dev);
3188
3189out_err:
3190 ehea_error("setting up logical port with id=%d failed, ret=%d",
3191 logical_port_id, ret);
3192 return NULL;
3193}
3194
3195static void ehea_shutdown_single_port(struct ehea_port *port)
3196{
Brian King7fb1c2a2008-05-14 09:48:25 -05003197 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003198 unregister_netdev(port->netdev);
3199 ehea_unregister_port(port);
3200 kfree(port->mc_list);
3201 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003202 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003203}
3204
3205static int ehea_setup_ports(struct ehea_adapter *adapter)
3206{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003207 struct device_node *lhea_dn;
3208 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003209
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003210 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003211 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003212
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003213 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003214 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003215
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003216 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003217 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003218 if (!dn_log_port_id) {
3219 ehea_error("bad device node: eth_dn name=%s",
3220 eth_dn->full_name);
3221 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003222 }
3223
Thomas Klein1211bb62007-04-26 11:56:43 +02003224 if (ehea_add_adapter_mr(adapter)) {
3225 ehea_error("creating MR failed");
3226 of_node_put(eth_dn);
3227 return -EIO;
3228 }
3229
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230 adapter->port[i] = ehea_setup_single_port(adapter,
3231 *dn_log_port_id,
3232 eth_dn);
3233 if (adapter->port[i])
3234 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003235 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003236 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003237 else
3238 ehea_remove_adapter_mr(adapter);
3239
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003240 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003241 };
Thomas Klein1211bb62007-04-26 11:56:43 +02003242 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003243}
3244
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003245static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3246 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003247{
3248 struct device_node *lhea_dn;
3249 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003250 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003252 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003253 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003254
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003255 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003256 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003257 if (dn_log_port_id)
3258 if (*dn_log_port_id == logical_port_id)
3259 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003260 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003261
3262 return NULL;
3263}
3264
3265static ssize_t ehea_probe_port(struct device *dev,
3266 struct device_attribute *attr,
3267 const char *buf, size_t count)
3268{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003269 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003270 struct ehea_port *port;
3271 struct device_node *eth_dn = NULL;
3272 int i;
3273
3274 u32 logical_port_id;
3275
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003276 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003277
3278 port = ehea_get_port(adapter, logical_port_id);
3279
3280 if (port) {
3281 ehea_info("adding port with logical port id=%d failed. port "
3282 "already configured as %s.", logical_port_id,
3283 port->netdev->name);
3284 return -EINVAL;
3285 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003286
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003287 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3288
3289 if (!eth_dn) {
3290 ehea_info("no logical port with id %d found", logical_port_id);
3291 return -EINVAL;
3292 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003293
Thomas Klein1211bb62007-04-26 11:56:43 +02003294 if (ehea_add_adapter_mr(adapter)) {
3295 ehea_error("creating MR failed");
3296 return -EIO;
3297 }
3298
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003299 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3300
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003301 of_node_put(eth_dn);
3302
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003303 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003304 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003305 if (!adapter->port[i]) {
3306 adapter->port[i] = port;
3307 break;
3308 }
3309
3310 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3311 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003312 } else {
3313 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003314 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003315 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003316
3317 return (ssize_t) count;
3318}
3319
3320static ssize_t ehea_remove_port(struct device *dev,
3321 struct device_attribute *attr,
3322 const char *buf, size_t count)
3323{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003324 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325 struct ehea_port *port;
3326 int i;
3327 u32 logical_port_id;
3328
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003329 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003330
3331 port = ehea_get_port(adapter, logical_port_id);
3332
3333 if (port) {
3334 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3335 logical_port_id);
3336
3337 ehea_shutdown_single_port(port);
3338
Doug Maxey508d2b52008-01-31 20:20:49 -06003339 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003340 if (adapter->port[i] == port) {
3341 adapter->port[i] = NULL;
3342 break;
3343 }
3344 } else {
3345 ehea_error("removing port with logical port id=%d failed. port "
3346 "not configured.", logical_port_id);
3347 return -EINVAL;
3348 }
3349
Thomas Klein1211bb62007-04-26 11:56:43 +02003350 ehea_remove_adapter_mr(adapter);
3351
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003352 return (ssize_t) count;
3353}
3354
3355static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3356static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3357
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003358int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003359{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003360 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003361 if (ret)
3362 goto out;
3363
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003364 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003366 return ret;
3367}
3368
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003369void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003370{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003371 device_remove_file(&dev->dev, &dev_attr_probe_port);
3372 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003373}
3374
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003375static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003376 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003377{
3378 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003379 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003380 int ret;
3381
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003382 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003383 ehea_error("Invalid ibmebus device probed");
3384 return -EINVAL;
3385 }
3386
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003387 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3388 if (!adapter) {
3389 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003390 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003391 goto out;
3392 }
3393
Thomas Klein44c82152007-07-11 16:32:00 +02003394 list_add(&adapter->list, &adapter_list);
3395
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003396 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003397
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003398 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003399 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003400 if (adapter_handle)
3401 adapter->handle = *adapter_handle;
3402
3403 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003404 dev_err(&dev->dev, "failed getting handle for adapter"
3405 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003406 ret = -ENODEV;
3407 goto out_free_ad;
3408 }
3409
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003410 adapter->pd = EHEA_PD_ID;
3411
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003412 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003413
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003414
3415 /* initialize adapter and ports */
3416 /* get adapter properties */
3417 ret = ehea_sense_adapter_attr(adapter);
3418 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003419 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003420 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003421 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003422
3423 adapter->neq = ehea_create_eq(adapter,
3424 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3425 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003426 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003427 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003428 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003429 }
3430
3431 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3432 (unsigned long)adapter);
3433
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003434 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003435 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003436 "ehea_neq", adapter);
3437 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003438 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003439 goto out_kill_eq;
3440 }
3441
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003442 ret = ehea_create_device_sysfs(dev);
3443 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003444 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003445
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003446 ret = ehea_setup_ports(adapter);
3447 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003448 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003449 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003450 }
3451
3452 ret = 0;
3453 goto out;
3454
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003455out_rem_dev_sysfs:
3456 ehea_remove_device_sysfs(dev);
3457
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003458out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003459 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003460
3461out_kill_eq:
3462 ehea_destroy_eq(adapter->neq);
3463
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003464out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003465 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003466 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003468out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003469 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003470
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003471 return ret;
3472}
3473
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003474static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003475{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003476 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003477 int i;
3478
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003479 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003480 if (adapter->port[i]) {
3481 ehea_shutdown_single_port(adapter->port[i]);
3482 adapter->port[i] = NULL;
3483 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003484
3485 ehea_remove_device_sysfs(dev);
3486
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003487 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003488
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003489 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003490 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003491
3492 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003493 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003494 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003495 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003496
Thomas Klein21eee2d2008-02-13 16:18:33 +01003497 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003498
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003499 return 0;
3500}
3501
Thomas Klein21eee2d2008-02-13 16:18:33 +01003502void ehea_crash_handler(void)
3503{
3504 int i;
3505
3506 if (ehea_fw_handles.arr)
3507 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3508 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3509 ehea_fw_handles.arr[i].fwh,
3510 FORCE_FREE);
3511
3512 if (ehea_bcmc_regs.arr)
3513 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3514 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3515 ehea_bcmc_regs.arr[i].port_id,
3516 ehea_bcmc_regs.arr[i].reg_type,
3517 ehea_bcmc_regs.arr[i].macaddr,
3518 0, H_DEREG_BCMC);
3519}
3520
Hannes Hering48cfb142008-05-07 14:43:36 +02003521static int ehea_mem_notifier(struct notifier_block *nb,
3522 unsigned long action, void *data)
3523{
Hannes Heringd4f12da2008-10-16 11:36:42 +02003524 struct memory_notify *arg = data;
Hannes Hering48cfb142008-05-07 14:43:36 +02003525 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003526 case MEM_CANCEL_OFFLINE:
3527 ehea_info("memory offlining canceled");
3528 /* Readd canceled memory block */
3529 case MEM_ONLINE:
3530 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003531 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003532 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
3533 return NOTIFY_BAD;
3534 ehea_rereg_mrs(NULL);
3535 break;
3536 case MEM_GOING_OFFLINE:
3537 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003538 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003539 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
3540 return NOTIFY_BAD;
Hannes Hering48cfb142008-05-07 14:43:36 +02003541 ehea_rereg_mrs(NULL);
3542 break;
3543 default:
3544 break;
3545 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003546
3547 ehea_update_firmware_handles();
3548
Hannes Hering48cfb142008-05-07 14:43:36 +02003549 return NOTIFY_OK;
3550}
3551
3552static struct notifier_block ehea_mem_nb = {
3553 .notifier_call = ehea_mem_notifier,
3554};
3555
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003556static int ehea_reboot_notifier(struct notifier_block *nb,
3557 unsigned long action, void *unused)
3558{
3559 if (action == SYS_RESTART) {
3560 ehea_info("Reboot: freeing all eHEA resources");
3561 ibmebus_unregister_driver(&ehea_driver);
3562 }
3563 return NOTIFY_DONE;
3564}
3565
3566static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003567 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003568};
3569
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570static int check_module_parm(void)
3571{
3572 int ret = 0;
3573
3574 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3575 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3576 ehea_info("Bad parameter: rq1_entries");
3577 ret = -EINVAL;
3578 }
3579 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3580 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3581 ehea_info("Bad parameter: rq2_entries");
3582 ret = -EINVAL;
3583 }
3584 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3585 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3586 ehea_info("Bad parameter: rq3_entries");
3587 ret = -EINVAL;
3588 }
3589 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3590 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3591 ehea_info("Bad parameter: sq_entries");
3592 ret = -EINVAL;
3593 }
3594
3595 return ret;
3596}
3597
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003598static ssize_t ehea_show_capabilities(struct device_driver *drv,
3599 char *buf)
3600{
3601 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3602}
3603
3604static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3605 ehea_show_capabilities, NULL);
3606
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003607int __init ehea_module_init(void)
3608{
3609 int ret;
3610
3611 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3612 DRV_VERSION);
3613
Thomas Klein44c82152007-07-11 16:32:00 +02003614
3615 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003616 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3617 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3618
Daniel Walker9f71a562008-03-28 14:41:26 -07003619 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003620 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003621
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003622 ret = check_module_parm();
3623 if (ret)
3624 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003625
3626 ret = ehea_create_busmap();
3627 if (ret)
3628 goto out;
3629
Thomas Klein21eee2d2008-02-13 16:18:33 +01003630 ret = register_reboot_notifier(&ehea_reboot_nb);
3631 if (ret)
3632 ehea_info("failed registering reboot notifier");
3633
Hannes Hering48cfb142008-05-07 14:43:36 +02003634 ret = register_memory_notifier(&ehea_mem_nb);
3635 if (ret)
3636 ehea_info("failed registering memory remove notifier");
3637
Thomas Klein21eee2d2008-02-13 16:18:33 +01003638 ret = crash_shutdown_register(&ehea_crash_handler);
3639 if (ret)
3640 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003642 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003643 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003644 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003645 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003646 }
3647
3648 ret = driver_create_file(&ehea_driver.driver,
3649 &driver_attr_capabilities);
3650 if (ret) {
3651 ehea_error("failed to register capabilities attribute, ret=%d",
3652 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003653 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003654 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003655
Thomas Klein21eee2d2008-02-13 16:18:33 +01003656 return ret;
3657
3658out3:
3659 ibmebus_unregister_driver(&ehea_driver);
3660out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003661 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003662 unregister_reboot_notifier(&ehea_reboot_nb);
3663 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003664out:
3665 return ret;
3666}
3667
3668static void __exit ehea_module_exit(void)
3669{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003670 int ret;
3671
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003672 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003673 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003674 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003675 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003676 ret = crash_shutdown_unregister(&ehea_crash_handler);
3677 if (ret)
3678 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003679 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003680 kfree(ehea_fw_handles.arr);
3681 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003682 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003683}
3684
3685module_init(ehea_module_init);
3686module_exit(ehea_module_exit);