blob: c35d1e3631d12ca9805c70cc68f377820b766b78 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020036#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020037#include <linux/notifier.h>
38#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020039#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010040#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070041#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020042
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020043#include <net/ip.h>
44
45#include "ehea.h"
46#include "ehea_qmr.h"
47#include "ehea_phyp.h"
48
49
50MODULE_LICENSE("GPL");
51MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
52MODULE_DESCRIPTION("IBM eServer HEA Driver");
53MODULE_VERSION(DRV_VERSION);
54
55
56static int msg_level = -1;
57static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
58static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
59static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
60static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060061static int use_mcs;
62static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070063static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010064static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066
67module_param(msg_level, int, 0);
68module_param(rq1_entries, int, 0);
69module_param(rq2_entries, int, 0);
70module_param(rq3_entries, int, 0);
71module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020072module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070074module_param(use_lro, int, 0);
75module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010076module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020077
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010078MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020079MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020080MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
81 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020082MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
83 "[2^x - 1], x = [6..14]. Default = "
84 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
85MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
88MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
91MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
92 "[2^x - 1], x = [6..14]. Default = "
93 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020094MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020095
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070096MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
97 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
98MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
99 "Default = 0");
100
Doug Maxey508d2b52008-01-31 20:20:49 -0600101static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200102static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800103static unsigned long ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200104struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700105static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100106struct ehea_fw_handle_array ehea_fw_handles;
107struct ehea_bcmc_reg_array ehea_bcmc_regs;
108
Thomas Kleind1dea382007-04-26 11:56:13 +0200109
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000110static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200111 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200112
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000113static int __devexit ehea_remove(struct of_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
115static struct of_device_id ehea_device_table[] = {
116 {
117 .name = "lhea",
118 .compatible = "IBM,lhea",
119 },
120 {},
121};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100122MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200123
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000124static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200125 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000126 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200127 .probe = ehea_probe_adapter,
128 .remove = ehea_remove,
129};
130
Doug Maxey508d2b52008-01-31 20:20:49 -0600131void ehea_dump(void *adr, int len, char *msg)
132{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200133 int x;
134 unsigned char *deb = adr;
135 for (x = 0; x < len; x += 16) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000136 printk(DRV_NAME " %s adr=%p ofs=%04x %016llx %016llx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600137 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200138 deb += 16;
139 }
140}
141
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100142void ehea_schedule_port_reset(struct ehea_port *port)
143{
144 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
145 schedule_work(&port->reset_task);
146}
147
Thomas Klein21eee2d2008-02-13 16:18:33 +0100148static void ehea_update_firmware_handles(void)
149{
150 struct ehea_fw_handle_entry *arr = NULL;
151 struct ehea_adapter *adapter;
152 int num_adapters = 0;
153 int num_ports = 0;
154 int num_portres = 0;
155 int i = 0;
156 int num_fw_handles, k, l;
157
158 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700159 mutex_lock(&ehea_fw_handles.lock);
160
Thomas Klein21eee2d2008-02-13 16:18:33 +0100161 list_for_each_entry(adapter, &adapter_list, list) {
162 num_adapters++;
163
164 for (k = 0; k < EHEA_MAX_PORTS; k++) {
165 struct ehea_port *port = adapter->port[k];
166
167 if (!port || (port->state != EHEA_PORT_UP))
168 continue;
169
170 num_ports++;
171 num_portres += port->num_def_qps + port->num_add_tx_qps;
172 }
173 }
174
175 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
176 num_ports * EHEA_NUM_PORT_FW_HANDLES +
177 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
178
179 if (num_fw_handles) {
180 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
181 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700182 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100183 } else
184 goto out_update;
185
186 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700187 if (num_adapters == 0)
188 break;
189
Thomas Klein21eee2d2008-02-13 16:18:33 +0100190 for (k = 0; k < EHEA_MAX_PORTS; k++) {
191 struct ehea_port *port = adapter->port[k];
192
Joe Perches8e95a202009-12-03 07:58:21 +0000193 if (!port || (port->state != EHEA_PORT_UP) ||
194 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100195 continue;
196
197 for (l = 0;
198 l < port->num_def_qps + port->num_add_tx_qps;
199 l++) {
200 struct ehea_port_res *pr = &port->port_res[l];
201
202 arr[i].adh = adapter->handle;
203 arr[i++].fwh = pr->qp->fw_handle;
204 arr[i].adh = adapter->handle;
205 arr[i++].fwh = pr->send_cq->fw_handle;
206 arr[i].adh = adapter->handle;
207 arr[i++].fwh = pr->recv_cq->fw_handle;
208 arr[i].adh = adapter->handle;
209 arr[i++].fwh = pr->eq->fw_handle;
210 arr[i].adh = adapter->handle;
211 arr[i++].fwh = pr->send_mr.handle;
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = pr->recv_mr.handle;
214 }
215 arr[i].adh = adapter->handle;
216 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700217 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100218 }
219
220 arr[i].adh = adapter->handle;
221 arr[i++].fwh = adapter->neq->fw_handle;
222
223 if (adapter->mr.handle) {
224 arr[i].adh = adapter->handle;
225 arr[i++].fwh = adapter->mr.handle;
226 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700227 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100228 }
229
230out_update:
231 kfree(ehea_fw_handles.arr);
232 ehea_fw_handles.arr = arr;
233 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700234out:
235 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100236}
237
238static void ehea_update_bcmc_registrations(void)
239{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700240 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100241 struct ehea_bcmc_reg_entry *arr = NULL;
242 struct ehea_adapter *adapter;
243 struct ehea_mc_list *mc_entry;
244 int num_registrations = 0;
245 int i = 0;
246 int k;
247
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700248 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
249
Thomas Klein21eee2d2008-02-13 16:18:33 +0100250 /* Determine number of registrations */
251 list_for_each_entry(adapter, &adapter_list, list)
252 for (k = 0; k < EHEA_MAX_PORTS; k++) {
253 struct ehea_port *port = adapter->port[k];
254
255 if (!port || (port->state != EHEA_PORT_UP))
256 continue;
257
258 num_registrations += 2; /* Broadcast registrations */
259
260 list_for_each_entry(mc_entry, &port->mc_list->list,list)
261 num_registrations += 2;
262 }
263
264 if (num_registrations) {
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +0100265 arr = kzalloc(num_registrations * sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100266 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700267 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100268 } else
269 goto out_update;
270
271 list_for_each_entry(adapter, &adapter_list, list) {
272 for (k = 0; k < EHEA_MAX_PORTS; k++) {
273 struct ehea_port *port = adapter->port[k];
274
275 if (!port || (port->state != EHEA_PORT_UP))
276 continue;
277
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700278 if (num_registrations == 0)
279 goto out_update;
280
Thomas Klein21eee2d2008-02-13 16:18:33 +0100281 arr[i].adh = adapter->handle;
282 arr[i].port_id = port->logical_port_id;
283 arr[i].reg_type = EHEA_BCMC_BROADCAST |
284 EHEA_BCMC_UNTAGGED;
285 arr[i++].macaddr = port->mac_addr;
286
287 arr[i].adh = adapter->handle;
288 arr[i].port_id = port->logical_port_id;
289 arr[i].reg_type = EHEA_BCMC_BROADCAST |
290 EHEA_BCMC_VLANID_ALL;
291 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700292 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100293
294 list_for_each_entry(mc_entry,
295 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700296 if (num_registrations == 0)
297 goto out_update;
298
Thomas Klein21eee2d2008-02-13 16:18:33 +0100299 arr[i].adh = adapter->handle;
300 arr[i].port_id = port->logical_port_id;
301 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
302 EHEA_BCMC_MULTICAST |
303 EHEA_BCMC_UNTAGGED;
304 arr[i++].macaddr = mc_entry->macaddr;
305
306 arr[i].adh = adapter->handle;
307 arr[i].port_id = port->logical_port_id;
308 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
309 EHEA_BCMC_MULTICAST |
310 EHEA_BCMC_VLANID_ALL;
311 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700312 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100313 }
314 }
315 }
316
317out_update:
318 kfree(ehea_bcmc_regs.arr);
319 ehea_bcmc_regs.arr = arr;
320 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700321out:
322 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100323}
324
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200325static struct net_device_stats *ehea_get_stats(struct net_device *dev)
326{
327 struct ehea_port *port = netdev_priv(dev);
328 struct net_device_stats *stats = &port->stats;
329 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100330 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200331 int i;
332
333 memset(stats, 0, sizeof(*stats));
334
Thomas Klein3faf2692009-01-21 14:45:33 -0800335 cb2 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200336 if (!cb2) {
337 ehea_error("no mem for cb2");
338 goto out;
339 }
340
341 hret = ehea_h_query_ehea_port(port->adapter->handle,
342 port->logical_port_id,
343 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
344 if (hret != H_SUCCESS) {
345 ehea_error("query_ehea_port failed");
346 goto out_herr;
347 }
348
349 if (netif_msg_hw(port))
350 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
351
352 rx_packets = 0;
353 for (i = 0; i < port->num_def_qps; i++)
354 rx_packets += port->port_res[i].rx_packets;
355
Thomas Klein7393b872007-11-21 17:37:58 +0100356 tx_packets = 0;
357 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
358 tx_packets += port->port_res[i].tx_packets;
359
360 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200361 stats->multicast = cb2->rxmcp;
362 stats->rx_errors = cb2->rxuerr;
363 stats->rx_bytes = cb2->rxo;
364 stats->tx_bytes = cb2->txo;
365 stats->rx_packets = rx_packets;
366
367out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800368 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200369out:
370 return stats;
371}
372
373static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
374{
375 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
376 struct net_device *dev = pr->port->netdev;
377 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200378 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
379 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200380 int i;
381
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200382 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200383
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200384 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200385 if (nr_of_wqes > 0)
386 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 pr->rq1_skba.os_skbs = fill_wqes;
388 return;
389 }
390
391 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200392 if (!skb_arr_rq1[index]) {
393 skb_arr_rq1[index] = netdev_alloc_skb(dev,
394 EHEA_L_PKT_SIZE);
395 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200396 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200397 break;
398 }
399 }
400 index--;
401 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200402 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200403 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200404
405 if (adder == 0)
406 return;
407
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200408 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200409 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200410}
411
Thomas Kleine2878802009-01-21 14:45:57 -0800412static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200414 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
415 struct net_device *dev = pr->port->netdev;
416 int i;
417
418 for (i = 0; i < pr->rq1_skba.len; i++) {
419 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Thomas Kleine2878802009-01-21 14:45:57 -0800420 if (!skb_arr_rq1[i])
421 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422 }
423 /* Ring doorbell */
424 ehea_update_rq1a(pr->qp, nr_rq1a);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200425}
426
427static int ehea_refill_rq_def(struct ehea_port_res *pr,
428 struct ehea_q_skb_arr *q_skba, int rq_nr,
429 int num_wqes, int wqe_type, int packet_size)
430{
431 struct net_device *dev = pr->port->netdev;
432 struct ehea_qp *qp = pr->qp;
433 struct sk_buff **skb_arr = q_skba->arr;
434 struct ehea_rwqe *rwqe;
435 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200436 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200437 int ret = 0;
438
439 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200440 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200441
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200442 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
443 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200444 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200445 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200446
447 index = q_skba->index;
448 max_index_mask = q_skba->len - 1;
449 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200450 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000451 struct sk_buff *skb;
452
453 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200454 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200455 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800456 if (q_skba->os_skbs == q_skba->len - 2) {
457 ehea_info("%s: rq%i ran dry - no mem for skb",
458 pr->port->netdev->name, rq_nr);
459 ret = -ENOMEM;
460 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200461 break;
462 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200463
464 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200465 tmp_addr = ehea_map_vaddr(skb->data);
466 if (tmp_addr == -1) {
467 dev_kfree_skb(skb);
468 q_skba->os_skbs = fill_wqes - i;
469 ret = 0;
470 break;
471 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200472
473 rwqe = ehea_get_next_rwqe(qp, rq_nr);
474 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200475 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200476 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200477 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200478 rwqe->sg_list[0].len = packet_size;
479 rwqe->data_segments = 1;
480
481 index++;
482 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200483 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200484 }
Thomas Klein44c82152007-07-11 16:32:00 +0200485
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200486 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200487 if (adder == 0)
488 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200489
490 /* Ring doorbell */
491 iosync();
492 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200493 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200494 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200495 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200496out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200497 return ret;
498}
499
500
501static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
502{
503 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
504 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000505 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200506}
507
508
509static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
510{
511 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
512 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000513 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200514}
515
516static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
517{
518 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
519 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
520 return 0;
521 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
522 (cqe->header_length == 0))
523 return 0;
524 return -EINVAL;
525}
526
527static inline void ehea_fill_skb(struct net_device *dev,
528 struct sk_buff *skb, struct ehea_cqe *cqe)
529{
530 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
531
532 skb_put(skb, length);
533 skb->ip_summed = CHECKSUM_UNNECESSARY;
534 skb->protocol = eth_type_trans(skb, dev);
535}
536
537static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
538 int arr_len,
539 struct ehea_cqe *cqe)
540{
541 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
542 struct sk_buff *skb;
543 void *pref;
544 int x;
545
546 x = skb_index + 1;
547 x &= (arr_len - 1);
548
549 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700550 if (pref) {
551 prefetchw(pref);
552 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200553
Hannes Hering0b2febf2009-05-04 11:06:37 -0700554 pref = (skb_array[x]->data);
555 prefetch(pref);
556 prefetch(pref + EHEA_CACHE_LINE);
557 prefetch(pref + EHEA_CACHE_LINE * 2);
558 prefetch(pref + EHEA_CACHE_LINE * 3);
559 }
560
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200561 skb = skb_array[skb_index];
562 skb_array[skb_index] = NULL;
563 return skb;
564}
565
566static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
567 int arr_len, int wqe_index)
568{
569 struct sk_buff *skb;
570 void *pref;
571 int x;
572
573 x = wqe_index + 1;
574 x &= (arr_len - 1);
575
576 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700577 if (pref) {
578 prefetchw(pref);
579 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200580
Hannes Hering0b2febf2009-05-04 11:06:37 -0700581 pref = (skb_array[x]->data);
582 prefetchw(pref);
583 prefetchw(pref + EHEA_CACHE_LINE);
584 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200585
586 skb = skb_array[wqe_index];
587 skb_array[wqe_index] = NULL;
588 return skb;
589}
590
591static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
592 struct ehea_cqe *cqe, int *processed_rq2,
593 int *processed_rq3)
594{
595 struct sk_buff *skb;
596
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100597 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
598 pr->p_stats.err_tcp_cksum++;
599 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
600 pr->p_stats.err_ip_cksum++;
601 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
602 pr->p_stats.err_frame_crc++;
603
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200604 if (rq == 2) {
605 *processed_rq2 += 1;
606 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
607 dev_kfree_skb(skb);
608 } else if (rq == 3) {
609 *processed_rq3 += 1;
610 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
611 dev_kfree_skb(skb);
612 }
613
614 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100615 if (netif_msg_rx_err(pr->port)) {
616 ehea_error("Critical receive error for QP %d. "
617 "Resetting port.", pr->qp->init_attr.qp_nr);
618 ehea_dump(cqe, sizeof(*cqe), "CQE");
619 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100620 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200621 return 1;
622 }
623
624 return 0;
625}
626
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700627static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
628 void **tcph, u64 *hdr_flags, void *priv)
629{
630 struct ehea_cqe *cqe = priv;
631 unsigned int ip_len;
632 struct iphdr *iph;
633
634 /* non tcp/udp packets */
635 if (!cqe->header_length)
636 return -1;
637
638 /* non tcp packet */
639 skb_reset_network_header(skb);
640 iph = ip_hdr(skb);
641 if (iph->protocol != IPPROTO_TCP)
642 return -1;
643
644 ip_len = ip_hdrlen(skb);
645 skb_set_transport_header(skb, ip_len);
646 *tcph = tcp_hdr(skb);
647
648 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700649 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700650 return -1;
651
652 *hdr_flags = LRO_IPV4 | LRO_TCP;
653 *iphdr = iph;
654
655 return 0;
656}
657
658static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
659 struct sk_buff *skb)
660{
Joe Perches8e95a202009-12-03 07:58:21 +0000661 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
662 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700663
664 if (use_lro) {
665 if (vlan_extracted)
666 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
667 pr->port->vgrp,
668 cqe->vlan_tag,
669 cqe);
670 else
671 lro_receive_skb(&pr->lro_mgr, skb, cqe);
672 } else {
673 if (vlan_extracted)
674 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
675 cqe->vlan_tag);
676 else
677 netif_receive_skb(skb);
678 }
679}
680
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700681static int ehea_proc_rwqes(struct net_device *dev,
682 struct ehea_port_res *pr,
683 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200684{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100685 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200686 struct ehea_qp *qp = pr->qp;
687 struct ehea_cqe *cqe;
688 struct sk_buff *skb;
689 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
690 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
691 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
692 int skb_arr_rq1_len = pr->rq1_skba.len;
693 int skb_arr_rq2_len = pr->rq2_skba.len;
694 int skb_arr_rq3_len = pr->rq3_skba.len;
695 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700696 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200697
698 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
699 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200700
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200701 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700702 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200703 ehea_inc_rq1(qp);
704 processed_rq1++;
705 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200706 if (netif_msg_rx_status(port))
707 ehea_dump(cqe, sizeof(*cqe), "CQE");
708
709 last_wqe_index = wqe_index;
710 rmb();
711 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600712 if (rq == 1) {
713 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200714 skb = get_skb_by_index_ll(skb_arr_rq1,
715 skb_arr_rq1_len,
716 wqe_index);
717 if (unlikely(!skb)) {
718 if (netif_msg_rx_err(port))
719 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100720
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700721 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200722 EHEA_L_PKT_SIZE);
723 if (!skb)
724 break;
725 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600726 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200727 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700728 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600729 } else if (rq == 2) {
730 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200731 skb = get_skb_by_index(skb_arr_rq2,
732 skb_arr_rq2_len, cqe);
733 if (unlikely(!skb)) {
734 if (netif_msg_rx_err(port))
735 ehea_error("rq2: skb=NULL");
736 break;
737 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700738 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200739 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600740 } else {
741 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200742 skb = get_skb_by_index(skb_arr_rq3,
743 skb_arr_rq3_len, cqe);
744 if (unlikely(!skb)) {
745 if (netif_msg_rx_err(port))
746 ehea_error("rq3: skb=NULL");
747 break;
748 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700749 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200750 processed_rq3++;
751 }
752
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700753 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100754 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100755 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200756 port_reset = ehea_treat_poll_error(pr, rq, cqe,
757 &processed_rq2,
758 &processed_rq3);
759 if (port_reset)
760 break;
761 }
762 cqe = ehea_poll_rq1(qp, &wqe_index);
763 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700764 if (use_lro)
765 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200766
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200767 pr->rx_packets += processed;
768
769 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
770 ehea_refill_rq2(pr, processed_rq2);
771 ehea_refill_rq3(pr, processed_rq3);
772
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700773 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200774}
775
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100776static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200777{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100778 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200779 struct ehea_cq *send_cq = pr->send_cq;
780 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100781 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200782 int cqe_counter = 0;
783 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100784 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200785 unsigned long flags;
786
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100787 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600788 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100789 ehea_inc_cq(send_cq);
790
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200791 cqe_counter++;
792 rmb();
793 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Thomas Kleinea96cea2010-04-20 23:10:55 +0000794 ehea_error("Bad send completion status=0x%04X",
795 cqe->status);
796
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200797 if (netif_msg_tx_err(pr->port))
798 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000799
800 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
801 ehea_error("Resetting port");
802 ehea_schedule_port_reset(pr->port);
803 break;
804 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200805 }
806
807 if (netif_msg_tx_done(pr->port))
808 ehea_dump(cqe, sizeof(*cqe), "CQE");
809
810 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100811 == EHEA_SWQE2_TYPE)) {
812
813 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
814 skb = pr->sq_skba.arr[index];
815 dev_kfree_skb(skb);
816 pr->sq_skba.arr[index] = NULL;
817 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200818
819 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
820 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100821
822 cqe = ehea_poll_cq(send_cq);
823 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200824
825 ehea_update_feca(send_cq, cqe_counter);
826 atomic_add(swqe_av, &pr->swqe_avail);
827
828 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100829
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200830 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
831 >= pr->swqe_refill_th)) {
832 netif_wake_queue(pr->port->netdev);
833 pr->queue_stopped = 0;
834 }
835 spin_unlock_irqrestore(&pr->netif_queue, flags);
836
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100837 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200838}
839
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100840#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700841#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100842
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700843static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200844{
Doug Maxey508d2b52008-01-31 20:20:49 -0600845 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
846 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700847 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100848 struct ehea_cqe *cqe;
849 struct ehea_cqe *cqe_skb = NULL;
850 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700851 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100852
853 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700854 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100855
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700856 if (!force_irq)
857 rx += ehea_proc_rwqes(dev, pr, budget - rx);
858
859 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100860 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700861 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800862 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100863 ehea_reset_cq_ep(pr->recv_cq);
864 ehea_reset_cq_ep(pr->send_cq);
865 ehea_reset_cq_n1(pr->recv_cq);
866 ehea_reset_cq_n1(pr->send_cq);
867 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
868 cqe_skb = ehea_poll_cq(pr->send_cq);
869
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100870 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700871 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100872
Ben Hutchings288379f2009-01-19 16:43:59 -0800873 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700874 return rx;
875
876 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
877 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100878 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100879
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700880 pr->poll_counter++;
881 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200882}
883
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200884#ifdef CONFIG_NET_POLL_CONTROLLER
885static void ehea_netpoll(struct net_device *dev)
886{
887 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700888 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200889
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700890 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800891 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200892}
893#endif
894
David Howells7d12e782006-10-05 14:55:46 +0100895static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200896{
897 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100898
Ben Hutchings288379f2009-01-19 16:43:59 -0800899 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100900
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200901 return IRQ_HANDLED;
902}
903
David Howells7d12e782006-10-05 14:55:46 +0100904static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200905{
906 struct ehea_port *port = param;
907 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100908 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200909 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000910 u64 resource_type, aer, aerr;
911 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200912
913 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100914
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200915 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200916 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000917 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100918 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100919
920 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000921
922 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
923 &aer, &aerr);
924
925 if (resource_type == EHEA_AER_RESTYPE_QP) {
926 if ((aer & EHEA_AER_RESET_MASK) ||
927 (aerr & EHEA_AERR_RESET_MASK))
928 reset_port = 1;
929 } else
930 reset_port = 1; /* Reset in case of CQ or EQ error */
931
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100932 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200933 }
934
Thomas Kleinea96cea2010-04-20 23:10:55 +0000935 if (reset_port) {
936 ehea_error("Resetting port");
937 ehea_schedule_port_reset(port);
938 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100939
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200940 return IRQ_HANDLED;
941}
942
943static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
944 int logical_port)
945{
946 int i;
947
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100948 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100949 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200950 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100951 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200952 return NULL;
953}
954
955int ehea_sense_port_attr(struct ehea_port *port)
956{
957 int ret;
958 u64 hret;
959 struct hcp_ehea_port_cb0 *cb0;
960
Doug Maxey508d2b52008-01-31 20:20:49 -0600961 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800962 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600963 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200964 ehea_error("no mem for cb0");
965 ret = -ENOMEM;
966 goto out;
967 }
968
969 hret = ehea_h_query_ehea_port(port->adapter->handle,
970 port->logical_port_id, H_PORT_CB0,
971 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
972 cb0);
973 if (hret != H_SUCCESS) {
974 ret = -EIO;
975 goto out_free;
976 }
977
978 /* MAC address */
979 port->mac_addr = cb0->port_mac_addr << 16;
980
Doug Maxey508d2b52008-01-31 20:20:49 -0600981 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200982 ret = -EADDRNOTAVAIL;
983 goto out_free;
984 }
985
986 /* Port speed */
987 switch (cb0->port_speed) {
988 case H_SPEED_10M_H:
989 port->port_speed = EHEA_SPEED_10M;
990 port->full_duplex = 0;
991 break;
992 case H_SPEED_10M_F:
993 port->port_speed = EHEA_SPEED_10M;
994 port->full_duplex = 1;
995 break;
996 case H_SPEED_100M_H:
997 port->port_speed = EHEA_SPEED_100M;
998 port->full_duplex = 0;
999 break;
1000 case H_SPEED_100M_F:
1001 port->port_speed = EHEA_SPEED_100M;
1002 port->full_duplex = 1;
1003 break;
1004 case H_SPEED_1G_F:
1005 port->port_speed = EHEA_SPEED_1G;
1006 port->full_duplex = 1;
1007 break;
1008 case H_SPEED_10G_F:
1009 port->port_speed = EHEA_SPEED_10G;
1010 port->full_duplex = 1;
1011 break;
1012 default:
1013 port->port_speed = 0;
1014 port->full_duplex = 0;
1015 break;
1016 }
1017
Thomas Kleine919b592007-01-22 12:53:20 +01001018 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001019 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001020
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001021 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001022 if (use_mcs)
1023 port->num_def_qps = cb0->num_default_qps;
1024 else
1025 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001026
1027 if (!port->num_def_qps) {
1028 ret = -EINVAL;
1029 goto out_free;
1030 }
1031
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001032 port->num_tx_qps = num_tx_qps;
1033
1034 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001035 port->num_add_tx_qps = 0;
1036 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001037 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001038
1039 ret = 0;
1040out_free:
1041 if (ret || netif_msg_probe(port))
1042 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001043 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001044out:
1045 return ret;
1046}
1047
1048int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1049{
1050 struct hcp_ehea_port_cb4 *cb4;
1051 u64 hret;
1052 int ret = 0;
1053
Thomas Klein3faf2692009-01-21 14:45:33 -08001054 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001055 if (!cb4) {
1056 ehea_error("no mem for cb4");
1057 ret = -ENOMEM;
1058 goto out;
1059 }
1060
1061 cb4->port_speed = port_speed;
1062
1063 netif_carrier_off(port->netdev);
1064
1065 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1066 port->logical_port_id,
1067 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1068 if (hret == H_SUCCESS) {
1069 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1070
1071 hret = ehea_h_query_ehea_port(port->adapter->handle,
1072 port->logical_port_id,
1073 H_PORT_CB4, H_PORT_CB4_SPEED,
1074 cb4);
1075 if (hret == H_SUCCESS) {
1076 switch (cb4->port_speed) {
1077 case H_SPEED_10M_H:
1078 port->port_speed = EHEA_SPEED_10M;
1079 port->full_duplex = 0;
1080 break;
1081 case H_SPEED_10M_F:
1082 port->port_speed = EHEA_SPEED_10M;
1083 port->full_duplex = 1;
1084 break;
1085 case H_SPEED_100M_H:
1086 port->port_speed = EHEA_SPEED_100M;
1087 port->full_duplex = 0;
1088 break;
1089 case H_SPEED_100M_F:
1090 port->port_speed = EHEA_SPEED_100M;
1091 port->full_duplex = 1;
1092 break;
1093 case H_SPEED_1G_F:
1094 port->port_speed = EHEA_SPEED_1G;
1095 port->full_duplex = 1;
1096 break;
1097 case H_SPEED_10G_F:
1098 port->port_speed = EHEA_SPEED_10G;
1099 port->full_duplex = 1;
1100 break;
1101 default:
1102 port->port_speed = 0;
1103 port->full_duplex = 0;
1104 break;
1105 }
1106 } else {
1107 ehea_error("Failed sensing port speed");
1108 ret = -EIO;
1109 }
1110 } else {
1111 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001112 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001113 ret = -EPERM;
1114 } else {
1115 ret = -EIO;
1116 ehea_error("Failed setting port speed");
1117 }
1118 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001119 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1120 netif_carrier_on(port->netdev);
1121
Thomas Klein3faf2692009-01-21 14:45:33 -08001122 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001123out:
1124 return ret;
1125}
1126
1127static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1128{
1129 int ret;
1130 u8 ec;
1131 u8 portnum;
1132 struct ehea_port *port;
1133
1134 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1135 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1136 port = ehea_get_port(adapter, portnum);
1137
1138 switch (ec) {
1139 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1140
1141 if (!port) {
1142 ehea_error("unknown portnum %x", portnum);
1143 break;
1144 }
1145
1146 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1147 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001148 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001149 if (ret) {
1150 ehea_error("failed resensing port "
1151 "attributes");
1152 break;
1153 }
1154
1155 if (netif_msg_link(port))
1156 ehea_info("%s: Logical port up: %dMbps "
1157 "%s Duplex",
1158 port->netdev->name,
1159 port->port_speed,
1160 port->full_duplex ==
1161 1 ? "Full" : "Half");
1162
1163 netif_carrier_on(port->netdev);
1164 netif_wake_queue(port->netdev);
1165 }
1166 } else
1167 if (netif_carrier_ok(port->netdev)) {
1168 if (netif_msg_link(port))
1169 ehea_info("%s: Logical port down",
1170 port->netdev->name);
1171 netif_carrier_off(port->netdev);
1172 netif_stop_queue(port->netdev);
1173 }
1174
1175 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001176 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001177 if (netif_msg_link(port))
1178 ehea_info("%s: Physical port up",
1179 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001180 if (prop_carrier_state)
1181 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001182 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001183 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001184 if (netif_msg_link(port))
1185 ehea_info("%s: Physical port down",
1186 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001187 if (prop_carrier_state)
1188 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001189 }
1190
1191 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1192 ehea_info("External switch port is primary port");
1193 else
1194 ehea_info("External switch port is backup port");
1195
1196 break;
1197 case EHEA_EC_ADAPTER_MALFUNC:
1198 ehea_error("Adapter malfunction");
1199 break;
1200 case EHEA_EC_PORT_MALFUNC:
1201 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1202 netif_carrier_off(port->netdev);
1203 netif_stop_queue(port->netdev);
1204 break;
1205 default:
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001206 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001207 break;
1208 }
1209}
1210
1211static void ehea_neq_tasklet(unsigned long data)
1212{
Doug Maxey508d2b52008-01-31 20:20:49 -06001213 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001214 struct ehea_eqe *eqe;
1215 u64 event_mask;
1216
1217 eqe = ehea_poll_eq(adapter->neq);
1218 ehea_debug("eqe=%p", eqe);
1219
1220 while (eqe) {
1221 ehea_debug("*eqe=%lx", eqe->entry);
1222 ehea_parse_eqe(adapter, eqe->entry);
1223 eqe = ehea_poll_eq(adapter->neq);
1224 ehea_debug("next eqe=%p", eqe);
1225 }
1226
1227 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1228 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1229 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1230
1231 ehea_h_reset_events(adapter->handle,
1232 adapter->neq->fw_handle, event_mask);
1233}
1234
David Howells7d12e782006-10-05 14:55:46 +01001235static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001236{
1237 struct ehea_adapter *adapter = param;
1238 tasklet_hi_schedule(&adapter->neq_tasklet);
1239 return IRQ_HANDLED;
1240}
1241
1242
1243static int ehea_fill_port_res(struct ehea_port_res *pr)
1244{
1245 int ret;
1246 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1247
Thomas Kleine2878802009-01-21 14:45:57 -08001248 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1249 - init_attr->act_nr_rwqes_rq2
1250 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001251
Thomas Kleine2878802009-01-21 14:45:57 -08001252 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001253
1254 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1255
1256 return ret;
1257}
1258
1259static int ehea_reg_interrupts(struct net_device *dev)
1260{
1261 struct ehea_port *port = netdev_priv(dev);
1262 struct ehea_port_res *pr;
1263 int i, ret;
1264
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001265
1266 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1267 dev->name);
1268
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001269 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001270 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001271 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001272 if (ret) {
1273 ehea_error("failed registering irq for qp_aff_irq_handler:"
1274 "ist=%X", port->qp_eq->attr.ist1);
1275 goto out_free_qpeq;
1276 }
1277
1278 if (netif_msg_ifup(port))
1279 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1280 "registered", port->qp_eq->attr.ist1);
1281
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001282
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1284 pr = &port->port_res[i];
1285 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001286 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001287 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001288 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001289 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001290 pr);
1291 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001292 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001293 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001294 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001295 goto out_free_req;
1296 }
1297 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001298 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1299 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001300 }
1301out:
1302 return ret;
1303
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001304
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001305out_free_req:
1306 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001307 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001308 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001309 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001310
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001311out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001312 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001313 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001314
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001315 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001316
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001317}
1318
1319static void ehea_free_interrupts(struct net_device *dev)
1320{
1321 struct ehea_port *port = netdev_priv(dev);
1322 struct ehea_port_res *pr;
1323 int i;
1324
1325 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001326
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001327 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1328 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001329 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001330 if (netif_msg_intr(port))
1331 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001332 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001333 }
1334
1335 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001336 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337 if (netif_msg_intr(port))
1338 ehea_info("associated event interrupt for handle 0x%X freed",
1339 port->qp_eq->attr.ist1);
1340}
1341
1342static int ehea_configure_port(struct ehea_port *port)
1343{
1344 int ret, i;
1345 u64 hret, mask;
1346 struct hcp_ehea_port_cb0 *cb0;
1347
1348 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001349 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350 if (!cb0)
1351 goto out;
1352
1353 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1354 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1355 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1356 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1357 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1358 PXLY_RC_VLAN_FILTER)
1359 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1360
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001361 for (i = 0; i < port->num_mcs; i++)
1362 if (use_mcs)
1363 cb0->default_qpn_arr[i] =
1364 port->port_res[i].qp->init_attr.qp_nr;
1365 else
1366 cb0->default_qpn_arr[i] =
1367 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001368
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001369 if (netif_msg_ifup(port))
1370 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1371
1372 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1373 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1374
1375 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1376 port->logical_port_id,
1377 H_PORT_CB0, mask, cb0);
1378 ret = -EIO;
1379 if (hret != H_SUCCESS)
1380 goto out_free;
1381
1382 ret = 0;
1383
1384out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001385 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001386out:
1387 return ret;
1388}
1389
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001390int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001391{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001392 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001393 struct ehea_adapter *adapter = pr->port->adapter;
1394
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001395 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1396 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001397 goto out;
1398
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001399 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1400 if (ret)
1401 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001402
1403 return 0;
1404
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001405out_free:
1406 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001407out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001408 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001409 return -EIO;
1410}
1411
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001412int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001413{
Joe Perches8e95a202009-12-03 07:58:21 +00001414 if ((ehea_rem_mr(&pr->send_mr)) ||
1415 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001416 return -EIO;
1417 else
1418 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001419}
1420
1421static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1422{
Doug Maxey508d2b52008-01-31 20:20:49 -06001423 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001424
1425 q_skba->arr = vmalloc(arr_size);
1426 if (!q_skba->arr)
1427 return -ENOMEM;
1428
1429 memset(q_skba->arr, 0, arr_size);
1430
1431 q_skba->len = max_q_entries;
1432 q_skba->index = 0;
1433 q_skba->os_skbs = 0;
1434
1435 return 0;
1436}
1437
1438static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1439 struct port_res_cfg *pr_cfg, int queue_token)
1440{
1441 struct ehea_adapter *adapter = port->adapter;
1442 enum ehea_eq_type eq_type = EHEA_EQ;
1443 struct ehea_qp_init_attr *init_attr = NULL;
1444 int ret = -EIO;
1445
1446 memset(pr, 0, sizeof(struct ehea_port_res));
1447
1448 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001449 spin_lock_init(&pr->xmit_lock);
1450 spin_lock_init(&pr->netif_queue);
1451
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001452 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1453 if (!pr->eq) {
1454 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001455 goto out_free;
1456 }
1457
1458 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001459 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001460 port->logical_port_id);
1461 if (!pr->recv_cq) {
1462 ehea_error("create_cq failed (cq_recv)");
1463 goto out_free;
1464 }
1465
1466 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001467 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001468 port->logical_port_id);
1469 if (!pr->send_cq) {
1470 ehea_error("create_cq failed (cq_send)");
1471 goto out_free;
1472 }
1473
1474 if (netif_msg_ifup(port))
1475 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1476 pr->send_cq->attr.act_nr_of_cqes,
1477 pr->recv_cq->attr.act_nr_of_cqes);
1478
1479 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1480 if (!init_attr) {
1481 ret = -ENOMEM;
1482 ehea_error("no mem for ehea_qp_init_attr");
1483 goto out_free;
1484 }
1485
1486 init_attr->low_lat_rq1 = 1;
1487 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1488 init_attr->rq_count = 3;
1489 init_attr->qp_token = queue_token;
1490 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1491 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1492 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1493 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1494 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1495 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1496 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1497 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1498 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1499 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1500 init_attr->port_nr = port->logical_port_id;
1501 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1502 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1503 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1504
1505 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1506 if (!pr->qp) {
1507 ehea_error("create_qp failed");
1508 ret = -EIO;
1509 goto out_free;
1510 }
1511
1512 if (netif_msg_ifup(port))
1513 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1514 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1515 init_attr->act_nr_send_wqes,
1516 init_attr->act_nr_rwqes_rq1,
1517 init_attr->act_nr_rwqes_rq2,
1518 init_attr->act_nr_rwqes_rq3);
1519
Thomas Klein44fb3122008-04-04 15:04:53 +02001520 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1521
1522 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001523 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1524 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1525 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1526 if (ret)
1527 goto out_free;
1528
1529 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1530 if (ehea_gen_smrs(pr) != 0) {
1531 ret = -EIO;
1532 goto out_free;
1533 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001534
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001535 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1536
1537 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001538
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001539 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001540
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001541 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1542 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1543 pr->lro_mgr.lro_arr = pr->lro_desc;
1544 pr->lro_mgr.get_skb_header = get_skb_hdr;
1545 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1546 pr->lro_mgr.dev = port->netdev;
1547 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1548 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1549
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001550 ret = 0;
1551 goto out;
1552
1553out_free:
1554 kfree(init_attr);
1555 vfree(pr->sq_skba.arr);
1556 vfree(pr->rq1_skba.arr);
1557 vfree(pr->rq2_skba.arr);
1558 vfree(pr->rq3_skba.arr);
1559 ehea_destroy_qp(pr->qp);
1560 ehea_destroy_cq(pr->send_cq);
1561 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001562 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563out:
1564 return ret;
1565}
1566
1567static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1568{
1569 int ret, i;
1570
Hannes Hering357eb462009-08-04 11:48:39 -07001571 if (pr->qp)
1572 netif_napi_del(&pr->napi);
1573
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001574 ret = ehea_destroy_qp(pr->qp);
1575
1576 if (!ret) {
1577 ehea_destroy_cq(pr->send_cq);
1578 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001579 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001580
1581 for (i = 0; i < pr->rq1_skba.len; i++)
1582 if (pr->rq1_skba.arr[i])
1583 dev_kfree_skb(pr->rq1_skba.arr[i]);
1584
1585 for (i = 0; i < pr->rq2_skba.len; i++)
1586 if (pr->rq2_skba.arr[i])
1587 dev_kfree_skb(pr->rq2_skba.arr[i]);
1588
1589 for (i = 0; i < pr->rq3_skba.len; i++)
1590 if (pr->rq3_skba.arr[i])
1591 dev_kfree_skb(pr->rq3_skba.arr[i]);
1592
1593 for (i = 0; i < pr->sq_skba.len; i++)
1594 if (pr->sq_skba.arr[i])
1595 dev_kfree_skb(pr->sq_skba.arr[i]);
1596
1597 vfree(pr->rq1_skba.arr);
1598 vfree(pr->rq2_skba.arr);
1599 vfree(pr->rq3_skba.arr);
1600 vfree(pr->sq_skba.arr);
1601 ret = ehea_rem_smrs(pr);
1602 }
1603 return ret;
1604}
1605
1606/*
1607 * The write_* functions store information in swqe which is used by
1608 * the hardware to calculate the ip/tcp/udp checksum
1609 */
1610
1611static inline void write_ip_start_end(struct ehea_swqe *swqe,
1612 const struct sk_buff *skb)
1613{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001614 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001615 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001616}
1617
1618static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1619 const struct sk_buff *skb)
1620{
1621 swqe->tcp_offset =
1622 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1623
1624 swqe->tcp_end = (u16)skb->len - 1;
1625}
1626
1627static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1628 const struct sk_buff *skb)
1629{
1630 swqe->tcp_offset =
1631 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1632
1633 swqe->tcp_end = (u16)skb->len - 1;
1634}
1635
1636
1637static void write_swqe2_TSO(struct sk_buff *skb,
1638 struct ehea_swqe *swqe, u32 lkey)
1639{
1640 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1641 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001642 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001643 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001644
1645 /* Packet is TCP with TSO enabled */
1646 swqe->tx_control |= EHEA_SWQE_TSO;
1647 swqe->mss = skb_shinfo(skb)->gso_size;
1648 /* copy only eth/ip/tcp headers to immediate data and
1649 * the rest of skb->data to sg1entry
1650 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001651 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001652
Eric Dumazete743d312010-04-14 15:59:40 -07001653 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001654
1655 if (skb_data_size >= headersize) {
1656 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001657 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001658 swqe->immediate_data_length = headersize;
1659
1660 if (skb_data_size > headersize) {
1661 /* set sg1entry data */
1662 sg1entry->l_key = lkey;
1663 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001664 sg1entry->vaddr =
1665 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001666 swqe->descriptors++;
1667 }
1668 } else
1669 ehea_error("cannot handle fragmented headers");
1670}
1671
1672static void write_swqe2_nonTSO(struct sk_buff *skb,
1673 struct ehea_swqe *swqe, u32 lkey)
1674{
Eric Dumazete743d312010-04-14 15:59:40 -07001675 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001676 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1677 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001678
1679 /* Packet is any nonTSO type
1680 *
1681 * Copy as much as possible skb->data to immediate data and
1682 * the rest to sg1entry
1683 */
1684 if (skb_data_size >= SWQE2_MAX_IMM) {
1685 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001686 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001687
1688 swqe->immediate_data_length = SWQE2_MAX_IMM;
1689
1690 if (skb_data_size > SWQE2_MAX_IMM) {
1691 /* copy sg1entry data */
1692 sg1entry->l_key = lkey;
1693 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001694 sg1entry->vaddr =
1695 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001696 swqe->descriptors++;
1697 }
1698 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001699 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001700 swqe->immediate_data_length = skb_data_size;
1701 }
1702}
1703
1704static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1705 struct ehea_swqe *swqe, u32 lkey)
1706{
1707 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1708 skb_frag_t *frag;
1709 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001710
1711 nfrags = skb_shinfo(skb)->nr_frags;
1712 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001713 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001714 swqe->descriptors = 0;
1715 sg1entry_contains_frag_data = 0;
1716
1717 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1718 write_swqe2_TSO(skb, swqe, lkey);
1719 else
1720 write_swqe2_nonTSO(skb, swqe, lkey);
1721
1722 /* write descriptors */
1723 if (nfrags > 0) {
1724 if (swqe->descriptors == 0) {
1725 /* sg1entry not yet used */
1726 frag = &skb_shinfo(skb)->frags[0];
1727
1728 /* copy sg1entry data */
1729 sg1entry->l_key = lkey;
1730 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001731 sg1entry->vaddr =
1732 ehea_map_vaddr(page_address(frag->page)
1733 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001734 swqe->descriptors++;
1735 sg1entry_contains_frag_data = 1;
1736 }
1737
1738 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1739
1740 frag = &skb_shinfo(skb)->frags[i];
1741 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1742
1743 sgentry->l_key = lkey;
1744 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001745 sgentry->vaddr =
1746 ehea_map_vaddr(page_address(frag->page)
1747 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001748 swqe->descriptors++;
1749 }
1750 }
1751}
1752
1753static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1754{
1755 int ret = 0;
1756 u64 hret;
1757 u8 reg_type;
1758
1759 /* De/Register untagged packets */
1760 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1761 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1762 port->logical_port_id,
1763 reg_type, port->mac_addr, 0, hcallid);
1764 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001765 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001766 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001767 ret = -EIO;
1768 goto out_herr;
1769 }
1770
1771 /* De/Register VLAN packets */
1772 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1773 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1774 port->logical_port_id,
1775 reg_type, port->mac_addr, 0, hcallid);
1776 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001777 ehea_error("%sregistering bc address failed (vlan)",
1778 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001779 ret = -EIO;
1780 }
1781out_herr:
1782 return ret;
1783}
1784
1785static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1786{
1787 struct ehea_port *port = netdev_priv(dev);
1788 struct sockaddr *mac_addr = sa;
1789 struct hcp_ehea_port_cb0 *cb0;
1790 int ret;
1791 u64 hret;
1792
1793 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1794 ret = -EADDRNOTAVAIL;
1795 goto out;
1796 }
1797
Thomas Klein3faf2692009-01-21 14:45:33 -08001798 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001799 if (!cb0) {
1800 ehea_error("no mem for cb0");
1801 ret = -ENOMEM;
1802 goto out;
1803 }
1804
1805 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1806
1807 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1808
1809 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1810 port->logical_port_id, H_PORT_CB0,
1811 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1812 if (hret != H_SUCCESS) {
1813 ret = -EIO;
1814 goto out_free;
1815 }
1816
1817 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1818
1819 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001820 if (port->state == EHEA_PORT_UP) {
1821 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1822 if (ret)
1823 goto out_upregs;
1824 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001825
1826 port->mac_addr = cb0->port_mac_addr << 16;
1827
1828 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001829 if (port->state == EHEA_PORT_UP) {
1830 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1831 if (ret)
1832 goto out_upregs;
1833 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001834
1835 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001836
1837out_upregs:
1838 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001839out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001840 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001841out:
1842 return ret;
1843}
1844
1845static void ehea_promiscuous_error(u64 hret, int enable)
1846{
Thomas Klein7674a582007-01-22 12:54:20 +01001847 if (hret == H_AUTHORITY)
1848 ehea_info("Hypervisor denied %sabling promiscuous mode",
1849 enable == 1 ? "en" : "dis");
1850 else
1851 ehea_error("failed %sabling promiscuous mode",
1852 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001853}
1854
1855static void ehea_promiscuous(struct net_device *dev, int enable)
1856{
1857 struct ehea_port *port = netdev_priv(dev);
1858 struct hcp_ehea_port_cb7 *cb7;
1859 u64 hret;
1860
1861 if ((enable && port->promisc) || (!enable && !port->promisc))
1862 return;
1863
Thomas Klein3faf2692009-01-21 14:45:33 -08001864 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001865 if (!cb7) {
1866 ehea_error("no mem for cb7");
1867 goto out;
1868 }
1869
1870 /* Modify Pxs_DUCQPN in CB7 */
1871 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1872
1873 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1874 port->logical_port_id,
1875 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1876 if (hret) {
1877 ehea_promiscuous_error(hret, enable);
1878 goto out;
1879 }
1880
1881 port->promisc = enable;
1882out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001883 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001884 return;
1885}
1886
1887static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1888 u32 hcallid)
1889{
1890 u64 hret;
1891 u8 reg_type;
1892
1893 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1894 | EHEA_BCMC_UNTAGGED;
1895
1896 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1897 port->logical_port_id,
1898 reg_type, mc_mac_addr, 0, hcallid);
1899 if (hret)
1900 goto out;
1901
1902 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1903 | EHEA_BCMC_VLANID_ALL;
1904
1905 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1906 port->logical_port_id,
1907 reg_type, mc_mac_addr, 0, hcallid);
1908out:
1909 return hret;
1910}
1911
1912static int ehea_drop_multicast_list(struct net_device *dev)
1913{
1914 struct ehea_port *port = netdev_priv(dev);
1915 struct ehea_mc_list *mc_entry = port->mc_list;
1916 struct list_head *pos;
1917 struct list_head *temp;
1918 int ret = 0;
1919 u64 hret;
1920
1921 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1922 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1923
1924 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1925 H_DEREG_BCMC);
1926 if (hret) {
1927 ehea_error("failed deregistering mcast MAC");
1928 ret = -EIO;
1929 }
1930
1931 list_del(pos);
1932 kfree(mc_entry);
1933 }
1934 return ret;
1935}
1936
1937static void ehea_allmulti(struct net_device *dev, int enable)
1938{
1939 struct ehea_port *port = netdev_priv(dev);
1940 u64 hret;
1941
1942 if (!port->allmulti) {
1943 if (enable) {
1944 /* Enable ALLMULTI */
1945 ehea_drop_multicast_list(dev);
1946 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1947 if (!hret)
1948 port->allmulti = 1;
1949 else
1950 ehea_error("failed enabling IFF_ALLMULTI");
1951 }
1952 } else
1953 if (!enable) {
1954 /* Disable ALLMULTI */
1955 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1956 if (!hret)
1957 port->allmulti = 0;
1958 else
1959 ehea_error("failed disabling IFF_ALLMULTI");
1960 }
1961}
1962
Doug Maxey508d2b52008-01-31 20:20:49 -06001963static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001964{
1965 struct ehea_mc_list *ehea_mcl_entry;
1966 u64 hret;
1967
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001968 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001969 if (!ehea_mcl_entry) {
1970 ehea_error("no mem for mcl_entry");
1971 return;
1972 }
1973
1974 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1975
1976 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1977
1978 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1979 H_REG_BCMC);
1980 if (!hret)
1981 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1982 else {
1983 ehea_error("failed registering mcast MAC");
1984 kfree(ehea_mcl_entry);
1985 }
1986}
1987
1988static void ehea_set_multicast_list(struct net_device *dev)
1989{
1990 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001991 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001992 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001993
1994 if (dev->flags & IFF_PROMISC) {
1995 ehea_promiscuous(dev, 1);
1996 return;
1997 }
1998 ehea_promiscuous(dev, 0);
1999
2000 if (dev->flags & IFF_ALLMULTI) {
2001 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002002 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002003 }
2004 ehea_allmulti(dev, 0);
2005
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002006 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002007 ret = ehea_drop_multicast_list(dev);
2008 if (ret) {
2009 /* Dropping the current multicast list failed.
2010 * Enabling ALL_MULTI is the best we can do.
2011 */
2012 ehea_allmulti(dev, 1);
2013 }
2014
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002015 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +00002016 ehea_info("Mcast registration limit reached (0x%llx). "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002017 "Use ALLMULTI!",
2018 port->adapter->max_mc_mac);
2019 goto out;
2020 }
2021
Jiri Pirko22bedad32010-04-01 21:22:57 +00002022 netdev_for_each_mc_addr(ha, dev)
2023 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002024
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002025 }
2026out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002027 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002028 return;
2029}
2030
2031static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2032{
2033 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2034 return -EINVAL;
2035 dev->mtu = new_mtu;
2036 return 0;
2037}
2038
2039static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2040 struct ehea_swqe *swqe, u32 lkey)
2041{
2042 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002043 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002044
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002045 /* IPv4 */
2046 swqe->tx_control |= EHEA_SWQE_CRC
2047 | EHEA_SWQE_IP_CHECKSUM
2048 | EHEA_SWQE_TCP_CHECKSUM
2049 | EHEA_SWQE_IMM_DATA_PRESENT
2050 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2051
2052 write_ip_start_end(swqe, skb);
2053
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002054 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002055 if ((iph->frag_off & IP_MF) ||
2056 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002057 /* IP fragment, so don't change cs */
2058 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2059 else
2060 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002061 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002062 write_tcp_offset_end(swqe, skb);
2063 }
2064
2065 /* icmp (big data) and ip segmentation packets (all other ip
2066 packets) do not require any special handling */
2067
2068 } else {
2069 /* Other Ethernet Protocol */
2070 swqe->tx_control |= EHEA_SWQE_CRC
2071 | EHEA_SWQE_IMM_DATA_PRESENT
2072 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2073 }
2074
2075 write_swqe2_data(skb, dev, swqe, lkey);
2076}
2077
2078static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2079 struct ehea_swqe *swqe)
2080{
2081 int nfrags = skb_shinfo(skb)->nr_frags;
2082 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2083 skb_frag_t *frag;
2084 int i;
2085
2086 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002087 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002088
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002089 /* IPv4 */
2090 write_ip_start_end(swqe, skb);
2091
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002092 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002093 swqe->tx_control |= EHEA_SWQE_CRC
2094 | EHEA_SWQE_IP_CHECKSUM
2095 | EHEA_SWQE_TCP_CHECKSUM
2096 | EHEA_SWQE_IMM_DATA_PRESENT;
2097
2098 write_tcp_offset_end(swqe, skb);
2099
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002100 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002101 if ((iph->frag_off & IP_MF) ||
2102 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002103 /* IP fragment, so don't change cs */
2104 swqe->tx_control |= EHEA_SWQE_CRC
2105 | EHEA_SWQE_IMM_DATA_PRESENT;
2106 else {
2107 swqe->tx_control |= EHEA_SWQE_CRC
2108 | EHEA_SWQE_IP_CHECKSUM
2109 | EHEA_SWQE_TCP_CHECKSUM
2110 | EHEA_SWQE_IMM_DATA_PRESENT;
2111
2112 write_udp_offset_end(swqe, skb);
2113 }
2114 } else {
2115 /* icmp (big data) and
2116 ip segmentation packets (all other ip packets) */
2117 swqe->tx_control |= EHEA_SWQE_CRC
2118 | EHEA_SWQE_IP_CHECKSUM
2119 | EHEA_SWQE_IMM_DATA_PRESENT;
2120 }
2121 } else {
2122 /* Other Ethernet Protocol */
2123 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2124 }
2125 /* copy (immediate) data */
2126 if (nfrags == 0) {
2127 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002128 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002129 } else {
2130 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002131 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002132 skb_headlen(skb));
2133 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002134
2135 /* ... then copy data from the fragments */
2136 for (i = 0; i < nfrags; i++) {
2137 frag = &skb_shinfo(skb)->frags[i];
2138 memcpy(imm_data,
2139 page_address(frag->page) + frag->page_offset,
2140 frag->size);
2141 imm_data += frag->size;
2142 }
2143 }
2144 swqe->immediate_data_length = skb->len;
2145 dev_kfree_skb(skb);
2146}
2147
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002148static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2149{
2150 struct tcphdr *tcp;
2151 u32 tmp;
2152
2153 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002154 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002155 tcp = (struct tcphdr *)(skb_network_header(skb) +
2156 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002157 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002158 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002159 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002160 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002161 return 0;
2162}
2163
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002164static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2165{
2166 struct ehea_port *port = netdev_priv(dev);
2167 struct ehea_swqe *swqe;
2168 unsigned long flags;
2169 u32 lkey;
2170 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002171 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002172
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002173 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2174
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002175 if (!spin_trylock(&pr->xmit_lock))
2176 return NETDEV_TX_BUSY;
2177
2178 if (pr->queue_stopped) {
2179 spin_unlock(&pr->xmit_lock);
2180 return NETDEV_TX_BUSY;
2181 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002182
2183 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2184 memset(swqe, 0, SWQE_HEADER_SIZE);
2185 atomic_dec(&pr->swqe_avail);
2186
2187 if (skb->len <= SWQE3_MAX_IMM) {
2188 u32 sig_iv = port->sig_comp_iv;
2189 u32 swqe_num = pr->swqe_id_counter;
2190 ehea_xmit3(skb, dev, swqe);
2191 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2192 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2193 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2194 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2195 sig_iv);
2196 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2197 pr->swqe_ll_count = 0;
2198 } else
2199 pr->swqe_ll_count += 1;
2200 } else {
2201 swqe->wr_id =
2202 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2203 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002204 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002205 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2206 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2207
2208 pr->sq_skba.index++;
2209 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2210
2211 lkey = pr->send_mr.lkey;
2212 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002213 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002214 }
2215 pr->swqe_id_counter += 1;
2216
2217 if (port->vgrp && vlan_tx_tag_present(skb)) {
2218 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2219 swqe->vlan_tag = vlan_tx_tag_get(skb);
2220 }
2221
2222 if (netif_msg_tx_queued(port)) {
2223 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002224 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002225 }
2226
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002227 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2228 netif_stop_queue(dev);
2229 swqe->tx_control |= EHEA_SWQE_PURGE;
2230 }
Thomas Klein44c82152007-07-11 16:32:00 +02002231
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002232 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002233 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002234
2235 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2236 spin_lock_irqsave(&pr->netif_queue, flags);
2237 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002238 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002239 netif_stop_queue(dev);
2240 pr->queue_stopped = 1;
2241 }
2242 spin_unlock_irqrestore(&pr->netif_queue, flags);
2243 }
2244 dev->trans_start = jiffies;
2245 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002246
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002247 return NETDEV_TX_OK;
2248}
2249
2250static void ehea_vlan_rx_register(struct net_device *dev,
2251 struct vlan_group *grp)
2252{
2253 struct ehea_port *port = netdev_priv(dev);
2254 struct ehea_adapter *adapter = port->adapter;
2255 struct hcp_ehea_port_cb1 *cb1;
2256 u64 hret;
2257
2258 port->vgrp = grp;
2259
Thomas Klein3faf2692009-01-21 14:45:33 -08002260 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002261 if (!cb1) {
2262 ehea_error("no mem for cb1");
2263 goto out;
2264 }
2265
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002266 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2267 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2268 if (hret != H_SUCCESS)
2269 ehea_error("modify_ehea_port failed");
2270
Thomas Klein3faf2692009-01-21 14:45:33 -08002271 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002272out:
2273 return;
2274}
2275
2276static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2277{
2278 struct ehea_port *port = netdev_priv(dev);
2279 struct ehea_adapter *adapter = port->adapter;
2280 struct hcp_ehea_port_cb1 *cb1;
2281 int index;
2282 u64 hret;
2283
Thomas Klein3faf2692009-01-21 14:45:33 -08002284 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285 if (!cb1) {
2286 ehea_error("no mem for cb1");
2287 goto out;
2288 }
2289
2290 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2291 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2292 if (hret != H_SUCCESS) {
2293 ehea_error("query_ehea_port failed");
2294 goto out;
2295 }
2296
2297 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002298 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002299
2300 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2301 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2302 if (hret != H_SUCCESS)
2303 ehea_error("modify_ehea_port failed");
2304out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002305 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002306 return;
2307}
2308
2309static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2310{
2311 struct ehea_port *port = netdev_priv(dev);
2312 struct ehea_adapter *adapter = port->adapter;
2313 struct hcp_ehea_port_cb1 *cb1;
2314 int index;
2315 u64 hret;
2316
Dan Aloni5c15bde2007-03-02 20:44:51 -08002317 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002318
Thomas Klein3faf2692009-01-21 14:45:33 -08002319 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002320 if (!cb1) {
2321 ehea_error("no mem for cb1");
2322 goto out;
2323 }
2324
2325 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2326 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2327 if (hret != H_SUCCESS) {
2328 ehea_error("query_ehea_port failed");
2329 goto out;
2330 }
2331
2332 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002333 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002334
2335 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2336 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2337 if (hret != H_SUCCESS)
2338 ehea_error("modify_ehea_port failed");
2339out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002340 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002341 return;
2342}
2343
2344int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2345{
2346 int ret = -EIO;
2347 u64 hret;
2348 u16 dummy16 = 0;
2349 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002350 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002351
Thomas Klein3faf2692009-01-21 14:45:33 -08002352 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002353 if (!cb0) {
2354 ret = -ENOMEM;
2355 goto out;
2356 }
2357
2358 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2359 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2360 if (hret != H_SUCCESS) {
2361 ehea_error("query_ehea_qp failed (1)");
2362 goto out;
2363 }
2364
2365 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2366 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2367 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2368 &dummy64, &dummy64, &dummy16, &dummy16);
2369 if (hret != H_SUCCESS) {
2370 ehea_error("modify_ehea_qp failed (1)");
2371 goto out;
2372 }
2373
2374 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2375 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2376 if (hret != H_SUCCESS) {
2377 ehea_error("query_ehea_qp failed (2)");
2378 goto out;
2379 }
2380
2381 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2382 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2383 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2384 &dummy64, &dummy64, &dummy16, &dummy16);
2385 if (hret != H_SUCCESS) {
2386 ehea_error("modify_ehea_qp failed (2)");
2387 goto out;
2388 }
2389
2390 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2391 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2392 if (hret != H_SUCCESS) {
2393 ehea_error("query_ehea_qp failed (3)");
2394 goto out;
2395 }
2396
2397 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2398 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2399 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2400 &dummy64, &dummy64, &dummy16, &dummy16);
2401 if (hret != H_SUCCESS) {
2402 ehea_error("modify_ehea_qp failed (3)");
2403 goto out;
2404 }
2405
2406 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2407 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2408 if (hret != H_SUCCESS) {
2409 ehea_error("query_ehea_qp failed (4)");
2410 goto out;
2411 }
2412
2413 ret = 0;
2414out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002415 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002416 return ret;
2417}
2418
2419static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2420 int add_tx_qps)
2421{
2422 int ret, i;
2423 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2424 enum ehea_eq_type eq_type = EHEA_EQ;
2425
2426 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2427 EHEA_MAX_ENTRIES_EQ, 1);
2428 if (!port->qp_eq) {
2429 ret = -EINVAL;
2430 ehea_error("ehea_create_eq failed (qp_eq)");
2431 goto out_kill_eq;
2432 }
2433
2434 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002435 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002436 pr_cfg.max_entries_sq = sq_entries;
2437 pr_cfg.max_entries_rq1 = rq1_entries;
2438 pr_cfg.max_entries_rq2 = rq2_entries;
2439 pr_cfg.max_entries_rq3 = rq3_entries;
2440
2441 pr_cfg_small_rx.max_entries_rcq = 1;
2442 pr_cfg_small_rx.max_entries_scq = sq_entries;
2443 pr_cfg_small_rx.max_entries_sq = sq_entries;
2444 pr_cfg_small_rx.max_entries_rq1 = 1;
2445 pr_cfg_small_rx.max_entries_rq2 = 1;
2446 pr_cfg_small_rx.max_entries_rq3 = 1;
2447
2448 for (i = 0; i < def_qps; i++) {
2449 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2450 if (ret)
2451 goto out_clean_pr;
2452 }
2453 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2454 ret = ehea_init_port_res(port, &port->port_res[i],
2455 &pr_cfg_small_rx, i);
2456 if (ret)
2457 goto out_clean_pr;
2458 }
2459
2460 return 0;
2461
2462out_clean_pr:
2463 while (--i >= 0)
2464 ehea_clean_portres(port, &port->port_res[i]);
2465
2466out_kill_eq:
2467 ehea_destroy_eq(port->qp_eq);
2468 return ret;
2469}
2470
2471static int ehea_clean_all_portres(struct ehea_port *port)
2472{
2473 int ret = 0;
2474 int i;
2475
Doug Maxey508d2b52008-01-31 20:20:49 -06002476 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002477 ret |= ehea_clean_portres(port, &port->port_res[i]);
2478
2479 ret |= ehea_destroy_eq(port->qp_eq);
2480
2481 return ret;
2482}
2483
Thomas Klein35cf2e22007-08-06 13:55:14 +02002484static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002485{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002486 if (adapter->active_ports)
2487 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002488
2489 ehea_rem_mr(&adapter->mr);
2490}
2491
Thomas Klein35cf2e22007-08-06 13:55:14 +02002492static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002493{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002494 if (adapter->active_ports)
2495 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002496
2497 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2498}
2499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002500static int ehea_up(struct net_device *dev)
2501{
2502 int ret, i;
2503 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002504
2505 if (port->state == EHEA_PORT_UP)
2506 return 0;
2507
2508 ret = ehea_port_res_setup(port, port->num_def_qps,
2509 port->num_add_tx_qps);
2510 if (ret) {
2511 ehea_error("port_res_failed");
2512 goto out;
2513 }
2514
2515 /* Set default QP for this port */
2516 ret = ehea_configure_port(port);
2517 if (ret) {
2518 ehea_error("ehea_configure_port failed. ret:%d", ret);
2519 goto out_clean_pr;
2520 }
2521
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002522 ret = ehea_reg_interrupts(dev);
2523 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002524 ehea_error("reg_interrupts failed. ret:%d", ret);
2525 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002526 }
2527
Doug Maxey508d2b52008-01-31 20:20:49 -06002528 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002529 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2530 if (ret) {
2531 ehea_error("activate_qp failed");
2532 goto out_free_irqs;
2533 }
2534 }
2535
Doug Maxey508d2b52008-01-31 20:20:49 -06002536 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002537 ret = ehea_fill_port_res(&port->port_res[i]);
2538 if (ret) {
2539 ehea_error("out_free_irqs");
2540 goto out_free_irqs;
2541 }
2542 }
2543
Thomas Klein21eee2d2008-02-13 16:18:33 +01002544 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2545 if (ret) {
2546 ret = -EIO;
2547 goto out_free_irqs;
2548 }
2549
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002550 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002551
2552 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002553 goto out;
2554
2555out_free_irqs:
2556 ehea_free_interrupts(dev);
2557
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002558out_clean_pr:
2559 ehea_clean_all_portres(port);
2560out:
Thomas Klein44c82152007-07-11 16:32:00 +02002561 if (ret)
2562 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2563
Thomas Klein21eee2d2008-02-13 16:18:33 +01002564 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002565 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002566
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002567 return ret;
2568}
2569
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002570static void port_napi_disable(struct ehea_port *port)
2571{
2572 int i;
2573
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002574 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002575 napi_disable(&port->port_res[i].napi);
2576}
2577
2578static void port_napi_enable(struct ehea_port *port)
2579{
2580 int i;
2581
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002582 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002583 napi_enable(&port->port_res[i].napi);
2584}
2585
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002586static int ehea_open(struct net_device *dev)
2587{
2588 int ret;
2589 struct ehea_port *port = netdev_priv(dev);
2590
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002591 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002592
2593 if (netif_msg_ifup(port))
2594 ehea_info("enabling port %s", dev->name);
2595
2596 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002597 if (!ret) {
2598 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002599 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002600 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002601
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002602 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002603
2604 return ret;
2605}
2606
2607static int ehea_down(struct net_device *dev)
2608{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002609 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002610 struct ehea_port *port = netdev_priv(dev);
2611
2612 if (port->state == EHEA_PORT_DOWN)
2613 return 0;
2614
2615 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002616 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2617
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002618 ehea_free_interrupts(dev);
2619
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002620 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002621
Thomas Klein21eee2d2008-02-13 16:18:33 +01002622 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002623
Thomas Klein44c82152007-07-11 16:32:00 +02002624 ret = ehea_clean_all_portres(port);
2625 if (ret)
2626 ehea_info("Failed freeing resources for %s. ret=%i",
2627 dev->name, ret);
2628
Thomas Klein21eee2d2008-02-13 16:18:33 +01002629 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002630
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002631 return ret;
2632}
2633
2634static int ehea_stop(struct net_device *dev)
2635{
2636 int ret;
2637 struct ehea_port *port = netdev_priv(dev);
2638
2639 if (netif_msg_ifdown(port))
2640 ehea_info("disabling port %s", dev->name);
2641
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002642 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002643 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002644 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002645 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002646 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002647 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002648 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002649 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002650 return ret;
2651}
2652
Andrew Morton22559c52008-04-18 13:50:39 -07002653static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002654{
2655 struct ehea_qp qp = *orig_qp;
2656 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2657 struct ehea_swqe *swqe;
2658 int wqe_index;
2659 int i;
2660
2661 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2662 swqe = ehea_get_swqe(&qp, &wqe_index);
2663 swqe->tx_control |= EHEA_SWQE_PURGE;
2664 }
2665}
2666
Andrew Morton22559c52008-04-18 13:50:39 -07002667static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002668{
2669 int i;
2670
2671 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2672 struct ehea_port_res *pr = &port->port_res[i];
2673 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2674 int k = 0;
2675 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2676 msleep(5);
2677 if (++k == 20)
2678 break;
2679 }
2680 }
2681}
2682
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002683int ehea_stop_qps(struct net_device *dev)
2684{
2685 struct ehea_port *port = netdev_priv(dev);
2686 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002687 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002688 int ret = -EIO;
2689 int dret;
2690 int i;
2691 u64 hret;
2692 u64 dummy64 = 0;
2693 u16 dummy16 = 0;
2694
Thomas Klein3faf2692009-01-21 14:45:33 -08002695 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002696 if (!cb0) {
2697 ret = -ENOMEM;
2698 goto out;
2699 }
2700
2701 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2702 struct ehea_port_res *pr = &port->port_res[i];
2703 struct ehea_qp *qp = pr->qp;
2704
2705 /* Purge send queue */
2706 ehea_purge_sq(qp);
2707
2708 /* Disable queue pair */
2709 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2710 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2711 cb0);
2712 if (hret != H_SUCCESS) {
2713 ehea_error("query_ehea_qp failed (1)");
2714 goto out;
2715 }
2716
2717 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2718 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2719
2720 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2721 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2722 1), cb0, &dummy64,
2723 &dummy64, &dummy16, &dummy16);
2724 if (hret != H_SUCCESS) {
2725 ehea_error("modify_ehea_qp failed (1)");
2726 goto out;
2727 }
2728
2729 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2730 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2731 cb0);
2732 if (hret != H_SUCCESS) {
2733 ehea_error("query_ehea_qp failed (2)");
2734 goto out;
2735 }
2736
2737 /* deregister shared memory regions */
2738 dret = ehea_rem_smrs(pr);
2739 if (dret) {
2740 ehea_error("unreg shared memory region failed");
2741 goto out;
2742 }
2743 }
2744
2745 ret = 0;
2746out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002747 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002748
2749 return ret;
2750}
2751
Doug Maxey508d2b52008-01-31 20:20:49 -06002752void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002753{
2754 struct ehea_qp qp = *orig_qp;
2755 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2756 struct ehea_rwqe *rwqe;
2757 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2758 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2759 struct sk_buff *skb;
2760 u32 lkey = pr->recv_mr.lkey;
2761
2762
2763 int i;
2764 int index;
2765
2766 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2767 rwqe = ehea_get_next_rwqe(&qp, 2);
2768 rwqe->sg_list[0].l_key = lkey;
2769 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2770 skb = skba_rq2[index];
2771 if (skb)
2772 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2773 }
2774
2775 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2776 rwqe = ehea_get_next_rwqe(&qp, 3);
2777 rwqe->sg_list[0].l_key = lkey;
2778 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2779 skb = skba_rq3[index];
2780 if (skb)
2781 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2782 }
2783}
2784
2785int ehea_restart_qps(struct net_device *dev)
2786{
2787 struct ehea_port *port = netdev_priv(dev);
2788 struct ehea_adapter *adapter = port->adapter;
2789 int ret = 0;
2790 int i;
2791
Doug Maxey508d2b52008-01-31 20:20:49 -06002792 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002793 u64 hret;
2794 u64 dummy64 = 0;
2795 u16 dummy16 = 0;
2796
Thomas Klein3faf2692009-01-21 14:45:33 -08002797 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002798 if (!cb0) {
2799 ret = -ENOMEM;
2800 goto out;
2801 }
2802
2803 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2804 struct ehea_port_res *pr = &port->port_res[i];
2805 struct ehea_qp *qp = pr->qp;
2806
2807 ret = ehea_gen_smrs(pr);
2808 if (ret) {
2809 ehea_error("creation of shared memory regions failed");
2810 goto out;
2811 }
2812
2813 ehea_update_rqs(qp, pr);
2814
2815 /* Enable queue pair */
2816 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2817 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2818 cb0);
2819 if (hret != H_SUCCESS) {
2820 ehea_error("query_ehea_qp failed (1)");
2821 goto out;
2822 }
2823
2824 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2825 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2826
2827 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2828 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2829 1), cb0, &dummy64,
2830 &dummy64, &dummy16, &dummy16);
2831 if (hret != H_SUCCESS) {
2832 ehea_error("modify_ehea_qp failed (1)");
2833 goto out;
2834 }
2835
2836 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2837 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2838 cb0);
2839 if (hret != H_SUCCESS) {
2840 ehea_error("query_ehea_qp failed (2)");
2841 goto out;
2842 }
2843
2844 /* refill entire queue */
2845 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2846 ehea_refill_rq2(pr, 0);
2847 ehea_refill_rq3(pr, 0);
2848 }
2849out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002850 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002851
2852 return ret;
2853}
2854
David Howellsc4028952006-11-22 14:57:56 +00002855static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002856{
2857 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002858 struct ehea_port *port =
2859 container_of(work, struct ehea_port, reset_task);
2860 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002861
2862 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002863 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002864 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002865
2866 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002867
Thomas Klein44c82152007-07-11 16:32:00 +02002868 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002869
2870 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002871 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002872 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002873
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002874 ehea_set_multicast_list(dev);
2875
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002876 if (netif_msg_timer(port))
2877 ehea_info("Device %s resetted successfully", dev->name);
2878
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002879 port_napi_enable(port);
2880
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002881 netif_wake_queue(dev);
2882out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002883 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002884 return;
2885}
2886
Thomas Klein44c82152007-07-11 16:32:00 +02002887static void ehea_rereg_mrs(struct work_struct *work)
2888{
2889 int ret, i;
2890 struct ehea_adapter *adapter;
2891
Daniel Walker06f89ed2008-03-28 14:41:26 -07002892 mutex_lock(&dlpar_mem_lock);
Hannes Heringd4f12da2008-10-16 11:36:42 +02002893 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002894
2895 list_for_each_entry(adapter, &adapter_list, list)
2896 if (adapter->active_ports) {
2897 /* Shutdown all ports */
2898 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2899 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002900 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002901
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002902 if (!port)
2903 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002904
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002905 dev = port->netdev;
2906
2907 if (dev->flags & IFF_UP) {
2908 mutex_lock(&port->port_lock);
2909 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002910 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002911 ret = ehea_stop_qps(dev);
2912 if (ret) {
2913 mutex_unlock(&port->port_lock);
2914 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002915 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002916 port_napi_disable(port);
2917 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002918 }
2919 }
2920
2921 /* Unregister old memory region */
2922 ret = ehea_rem_mr(&adapter->mr);
2923 if (ret) {
2924 ehea_error("unregister MR failed - driver"
2925 " inoperable!");
2926 goto out;
2927 }
2928 }
2929
Thomas Klein44c82152007-07-11 16:32:00 +02002930 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2931
2932 list_for_each_entry(adapter, &adapter_list, list)
2933 if (adapter->active_ports) {
2934 /* Register new memory region */
2935 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2936 if (ret) {
2937 ehea_error("register MR failed - driver"
2938 " inoperable!");
2939 goto out;
2940 }
2941
2942 /* Restart all ports */
2943 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2944 struct ehea_port *port = adapter->port[i];
2945
2946 if (port) {
2947 struct net_device *dev = port->netdev;
2948
2949 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002950 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002951 port_napi_enable(port);
2952 ret = ehea_restart_qps(dev);
2953 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002954 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002955 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002956 }
2957 }
2958 }
2959 }
Julia Lawall68905eb2008-07-21 09:57:26 +02002960 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002961out:
Julia Lawall68905eb2008-07-21 09:57:26 +02002962 mutex_unlock(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002963 return;
2964}
2965
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002966static void ehea_tx_watchdog(struct net_device *dev)
2967{
2968 struct ehea_port *port = netdev_priv(dev);
2969
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002970 if (netif_carrier_ok(dev) &&
2971 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002972 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002973}
2974
2975int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2976{
2977 struct hcp_query_ehea *cb;
2978 u64 hret;
2979 int ret;
2980
Thomas Klein3faf2692009-01-21 14:45:33 -08002981 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002982 if (!cb) {
2983 ret = -ENOMEM;
2984 goto out;
2985 }
2986
2987 hret = ehea_h_query_ehea(adapter->handle, cb);
2988
2989 if (hret != H_SUCCESS) {
2990 ret = -EIO;
2991 goto out_herr;
2992 }
2993
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002994 adapter->max_mc_mac = cb->max_mc_mac - 1;
2995 ret = 0;
2996
2997out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002998 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002999out:
3000 return ret;
3001}
3002
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003003int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3004{
3005 struct hcp_ehea_port_cb4 *cb4;
3006 u64 hret;
3007 int ret = 0;
3008
3009 *jumbo = 0;
3010
3011 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003012 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003013 if (!cb4) {
3014 ehea_error("no mem for cb4");
3015 ret = -ENOMEM;
3016 goto out;
3017 } else {
3018 hret = ehea_h_query_ehea_port(port->adapter->handle,
3019 port->logical_port_id,
3020 H_PORT_CB4,
3021 H_PORT_CB4_JUMBO, cb4);
3022 if (hret == H_SUCCESS) {
3023 if (cb4->jumbo_frame)
3024 *jumbo = 1;
3025 else {
3026 cb4->jumbo_frame = 1;
3027 hret = ehea_h_modify_ehea_port(port->adapter->
3028 handle,
3029 port->
3030 logical_port_id,
3031 H_PORT_CB4,
3032 H_PORT_CB4_JUMBO,
3033 cb4);
3034 if (hret == H_SUCCESS)
3035 *jumbo = 1;
3036 }
3037 } else
3038 ret = -EINVAL;
3039
Thomas Klein3faf2692009-01-21 14:45:33 -08003040 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003041 }
3042out:
3043 return ret;
3044}
3045
3046static ssize_t ehea_show_port_id(struct device *dev,
3047 struct device_attribute *attr, char *buf)
3048{
3049 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003050 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003051}
3052
3053static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3054 NULL);
3055
3056static void __devinit logical_port_release(struct device *dev)
3057{
3058 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3059 of_node_put(port->ofdev.node);
3060}
3061
3062static struct device *ehea_register_port(struct ehea_port *port,
3063 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003064{
3065 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003066
3067 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003068 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003069 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003070
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003071 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003072 port->ofdev.dev.release = logical_port_release;
3073
3074 ret = of_device_register(&port->ofdev);
3075 if (ret) {
3076 ehea_error("failed to register device. ret=%d", ret);
3077 goto out;
3078 }
3079
3080 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003081 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003082 ehea_error("failed to register attributes, ret=%d", ret);
3083 goto out_unreg_of_dev;
3084 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003085
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003086 return &port->ofdev.dev;
3087
3088out_unreg_of_dev:
3089 of_device_unregister(&port->ofdev);
3090out:
3091 return NULL;
3092}
3093
3094static void ehea_unregister_port(struct ehea_port *port)
3095{
3096 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3097 of_device_unregister(&port->ofdev);
3098}
3099
Thomas Klein086c1b22009-01-21 14:43:59 -08003100static const struct net_device_ops ehea_netdev_ops = {
3101 .ndo_open = ehea_open,
3102 .ndo_stop = ehea_stop,
3103 .ndo_start_xmit = ehea_start_xmit,
3104#ifdef CONFIG_NET_POLL_CONTROLLER
3105 .ndo_poll_controller = ehea_netpoll,
3106#endif
3107 .ndo_get_stats = ehea_get_stats,
3108 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003109 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003110 .ndo_set_multicast_list = ehea_set_multicast_list,
3111 .ndo_change_mtu = ehea_change_mtu,
3112 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3113 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003114 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3115 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003116};
3117
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003118struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3119 u32 logical_port_id,
3120 struct device_node *dn)
3121{
3122 int ret;
3123 struct net_device *dev;
3124 struct ehea_port *port;
3125 struct device *port_dev;
3126 int jumbo;
3127
3128 /* allocate memory for the port structures */
3129 dev = alloc_etherdev(sizeof(struct ehea_port));
3130
3131 if (!dev) {
3132 ehea_error("no mem for net_device");
3133 ret = -ENOMEM;
3134 goto out_err;
3135 }
3136
3137 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003138
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003139 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003140 port->state = EHEA_PORT_DOWN;
3141 port->sig_comp_iv = sq_entries / 10;
3142
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003143 port->adapter = adapter;
3144 port->netdev = dev;
3145 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003146
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003147 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003148
3149 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3150 if (!port->mc_list) {
3151 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003152 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003153 }
3154
3155 INIT_LIST_HEAD(&port->mc_list->list);
3156
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003157 ret = ehea_sense_port_attr(port);
3158 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003159 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003160
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003161 port_dev = ehea_register_port(port, dn);
3162 if (!port_dev)
3163 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003164
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003166
3167 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003168 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3169
Thomas Klein086c1b22009-01-21 14:43:59 -08003170 dev->netdev_ops = &ehea_netdev_ops;
3171 ehea_set_ethtool_ops(dev);
3172
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003173 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003174 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003175 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3176 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003177 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3178
David Howellsc4028952006-11-22 14:57:56 +00003179 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003180
3181 ret = register_netdev(dev);
3182 if (ret) {
3183 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003184 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003185 }
3186
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003187 port->lro_max_aggr = lro_max_aggr;
3188
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003189 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003190 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003191 ehea_error("failed determining jumbo frame status for %s",
3192 port->netdev->name);
3193
Thomas Klein9c750b72007-01-29 18:44:01 +01003194 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3195 jumbo == 1 ? "en" : "dis");
3196
Thomas Klein44c82152007-07-11 16:32:00 +02003197 adapter->active_ports++;
3198
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003199 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003200
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003201out_unreg_port:
3202 ehea_unregister_port(port);
3203
3204out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003205 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003206
3207out_free_ethdev:
3208 free_netdev(dev);
3209
3210out_err:
3211 ehea_error("setting up logical port with id=%d failed, ret=%d",
3212 logical_port_id, ret);
3213 return NULL;
3214}
3215
3216static void ehea_shutdown_single_port(struct ehea_port *port)
3217{
Brian King7fb1c2a2008-05-14 09:48:25 -05003218 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003219 unregister_netdev(port->netdev);
3220 ehea_unregister_port(port);
3221 kfree(port->mc_list);
3222 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003223 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003224}
3225
3226static int ehea_setup_ports(struct ehea_adapter *adapter)
3227{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003228 struct device_node *lhea_dn;
3229 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003230
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003231 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003232 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003233
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003234 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003235 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003236
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003237 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003238 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003239 if (!dn_log_port_id) {
3240 ehea_error("bad device node: eth_dn name=%s",
3241 eth_dn->full_name);
3242 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003243 }
3244
Thomas Klein1211bb62007-04-26 11:56:43 +02003245 if (ehea_add_adapter_mr(adapter)) {
3246 ehea_error("creating MR failed");
3247 of_node_put(eth_dn);
3248 return -EIO;
3249 }
3250
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251 adapter->port[i] = ehea_setup_single_port(adapter,
3252 *dn_log_port_id,
3253 eth_dn);
3254 if (adapter->port[i])
3255 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003256 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003257 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003258 else
3259 ehea_remove_adapter_mr(adapter);
3260
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003261 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003262 };
Thomas Klein1211bb62007-04-26 11:56:43 +02003263 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003264}
3265
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003266static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3267 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003268{
3269 struct device_node *lhea_dn;
3270 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003271 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003272
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003273 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003274 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003275
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003276 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003277 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003278 if (dn_log_port_id)
3279 if (*dn_log_port_id == logical_port_id)
3280 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003281 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003282
3283 return NULL;
3284}
3285
3286static ssize_t ehea_probe_port(struct device *dev,
3287 struct device_attribute *attr,
3288 const char *buf, size_t count)
3289{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003290 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003291 struct ehea_port *port;
3292 struct device_node *eth_dn = NULL;
3293 int i;
3294
3295 u32 logical_port_id;
3296
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003297 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003298
3299 port = ehea_get_port(adapter, logical_port_id);
3300
3301 if (port) {
3302 ehea_info("adding port with logical port id=%d failed. port "
3303 "already configured as %s.", logical_port_id,
3304 port->netdev->name);
3305 return -EINVAL;
3306 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003307
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003308 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3309
3310 if (!eth_dn) {
3311 ehea_info("no logical port with id %d found", logical_port_id);
3312 return -EINVAL;
3313 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003314
Thomas Klein1211bb62007-04-26 11:56:43 +02003315 if (ehea_add_adapter_mr(adapter)) {
3316 ehea_error("creating MR failed");
3317 return -EIO;
3318 }
3319
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003320 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3321
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003322 of_node_put(eth_dn);
3323
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003324 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003325 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003326 if (!adapter->port[i]) {
3327 adapter->port[i] = port;
3328 break;
3329 }
3330
3331 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3332 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003333 } else {
3334 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003335 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003336 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003337
3338 return (ssize_t) count;
3339}
3340
3341static ssize_t ehea_remove_port(struct device *dev,
3342 struct device_attribute *attr,
3343 const char *buf, size_t count)
3344{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003345 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003346 struct ehea_port *port;
3347 int i;
3348 u32 logical_port_id;
3349
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003350 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003351
3352 port = ehea_get_port(adapter, logical_port_id);
3353
3354 if (port) {
3355 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3356 logical_port_id);
3357
3358 ehea_shutdown_single_port(port);
3359
Doug Maxey508d2b52008-01-31 20:20:49 -06003360 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003361 if (adapter->port[i] == port) {
3362 adapter->port[i] = NULL;
3363 break;
3364 }
3365 } else {
3366 ehea_error("removing port with logical port id=%d failed. port "
3367 "not configured.", logical_port_id);
3368 return -EINVAL;
3369 }
3370
Thomas Klein1211bb62007-04-26 11:56:43 +02003371 ehea_remove_adapter_mr(adapter);
3372
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003373 return (ssize_t) count;
3374}
3375
3376static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3377static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3378
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003379int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003380{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003381 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003382 if (ret)
3383 goto out;
3384
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003385 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003386out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003387 return ret;
3388}
3389
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003390void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003391{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003392 device_remove_file(&dev->dev, &dev_attr_probe_port);
3393 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003394}
3395
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003396static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003397 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003398{
3399 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003400 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003401 int ret;
3402
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003403 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003404 ehea_error("Invalid ibmebus device probed");
3405 return -EINVAL;
3406 }
3407
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003408 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3409 if (!adapter) {
3410 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003411 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003412 goto out;
3413 }
3414
Thomas Klein44c82152007-07-11 16:32:00 +02003415 list_add(&adapter->list, &adapter_list);
3416
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003417 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003418
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003419 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003420 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003421 if (adapter_handle)
3422 adapter->handle = *adapter_handle;
3423
3424 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003425 dev_err(&dev->dev, "failed getting handle for adapter"
3426 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003427 ret = -ENODEV;
3428 goto out_free_ad;
3429 }
3430
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003431 adapter->pd = EHEA_PD_ID;
3432
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003433 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003434
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003435
3436 /* initialize adapter and ports */
3437 /* get adapter properties */
3438 ret = ehea_sense_adapter_attr(adapter);
3439 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003440 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003441 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003442 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003443
3444 adapter->neq = ehea_create_eq(adapter,
3445 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3446 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003447 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003448 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003449 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003450 }
3451
3452 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3453 (unsigned long)adapter);
3454
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003455 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003456 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003457 "ehea_neq", adapter);
3458 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003459 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003460 goto out_kill_eq;
3461 }
3462
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003463 ret = ehea_create_device_sysfs(dev);
3464 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003465 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003466
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003467 ret = ehea_setup_ports(adapter);
3468 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003469 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003470 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003471 }
3472
3473 ret = 0;
3474 goto out;
3475
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003476out_rem_dev_sysfs:
3477 ehea_remove_device_sysfs(dev);
3478
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003479out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003480 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003481
3482out_kill_eq:
3483 ehea_destroy_eq(adapter->neq);
3484
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003485out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003486 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003487 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003488
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003489out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003490 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003491
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003492 return ret;
3493}
3494
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003495static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003496{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003497 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003498 int i;
3499
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003500 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003501 if (adapter->port[i]) {
3502 ehea_shutdown_single_port(adapter->port[i]);
3503 adapter->port[i] = NULL;
3504 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003505
3506 ehea_remove_device_sysfs(dev);
3507
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003508 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003509
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003510 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003511 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003512
3513 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003514 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003515 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003516 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003517
Thomas Klein21eee2d2008-02-13 16:18:33 +01003518 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003519
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003520 return 0;
3521}
3522
Thomas Klein21eee2d2008-02-13 16:18:33 +01003523void ehea_crash_handler(void)
3524{
3525 int i;
3526
3527 if (ehea_fw_handles.arr)
3528 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3529 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3530 ehea_fw_handles.arr[i].fwh,
3531 FORCE_FREE);
3532
3533 if (ehea_bcmc_regs.arr)
3534 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3535 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3536 ehea_bcmc_regs.arr[i].port_id,
3537 ehea_bcmc_regs.arr[i].reg_type,
3538 ehea_bcmc_regs.arr[i].macaddr,
3539 0, H_DEREG_BCMC);
3540}
3541
Hannes Hering48cfb142008-05-07 14:43:36 +02003542static int ehea_mem_notifier(struct notifier_block *nb,
3543 unsigned long action, void *data)
3544{
Hannes Heringd4f12da2008-10-16 11:36:42 +02003545 struct memory_notify *arg = data;
Hannes Hering48cfb142008-05-07 14:43:36 +02003546 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003547 case MEM_CANCEL_OFFLINE:
3548 ehea_info("memory offlining canceled");
3549 /* Readd canceled memory block */
3550 case MEM_ONLINE:
3551 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003552 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003553 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
3554 return NOTIFY_BAD;
3555 ehea_rereg_mrs(NULL);
3556 break;
3557 case MEM_GOING_OFFLINE:
3558 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003559 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003560 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
3561 return NOTIFY_BAD;
Hannes Hering48cfb142008-05-07 14:43:36 +02003562 ehea_rereg_mrs(NULL);
3563 break;
3564 default:
3565 break;
3566 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003567
3568 ehea_update_firmware_handles();
3569
Hannes Hering48cfb142008-05-07 14:43:36 +02003570 return NOTIFY_OK;
3571}
3572
3573static struct notifier_block ehea_mem_nb = {
3574 .notifier_call = ehea_mem_notifier,
3575};
3576
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003577static int ehea_reboot_notifier(struct notifier_block *nb,
3578 unsigned long action, void *unused)
3579{
3580 if (action == SYS_RESTART) {
3581 ehea_info("Reboot: freeing all eHEA resources");
3582 ibmebus_unregister_driver(&ehea_driver);
3583 }
3584 return NOTIFY_DONE;
3585}
3586
3587static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003588 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003589};
3590
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003591static int check_module_parm(void)
3592{
3593 int ret = 0;
3594
3595 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3596 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3597 ehea_info("Bad parameter: rq1_entries");
3598 ret = -EINVAL;
3599 }
3600 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3601 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3602 ehea_info("Bad parameter: rq2_entries");
3603 ret = -EINVAL;
3604 }
3605 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3606 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3607 ehea_info("Bad parameter: rq3_entries");
3608 ret = -EINVAL;
3609 }
3610 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3611 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3612 ehea_info("Bad parameter: sq_entries");
3613 ret = -EINVAL;
3614 }
3615
3616 return ret;
3617}
3618
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003619static ssize_t ehea_show_capabilities(struct device_driver *drv,
3620 char *buf)
3621{
3622 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3623}
3624
3625static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3626 ehea_show_capabilities, NULL);
3627
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003628int __init ehea_module_init(void)
3629{
3630 int ret;
3631
3632 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3633 DRV_VERSION);
3634
Thomas Klein44c82152007-07-11 16:32:00 +02003635
3636 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003637 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3638 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3639
Daniel Walker9f71a562008-03-28 14:41:26 -07003640 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003641 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003642
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003643 ret = check_module_parm();
3644 if (ret)
3645 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003646
3647 ret = ehea_create_busmap();
3648 if (ret)
3649 goto out;
3650
Thomas Klein21eee2d2008-02-13 16:18:33 +01003651 ret = register_reboot_notifier(&ehea_reboot_nb);
3652 if (ret)
3653 ehea_info("failed registering reboot notifier");
3654
Hannes Hering48cfb142008-05-07 14:43:36 +02003655 ret = register_memory_notifier(&ehea_mem_nb);
3656 if (ret)
3657 ehea_info("failed registering memory remove notifier");
3658
Thomas Klein21eee2d2008-02-13 16:18:33 +01003659 ret = crash_shutdown_register(&ehea_crash_handler);
3660 if (ret)
3661 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003662
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003663 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003664 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003665 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003666 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003667 }
3668
3669 ret = driver_create_file(&ehea_driver.driver,
3670 &driver_attr_capabilities);
3671 if (ret) {
3672 ehea_error("failed to register capabilities attribute, ret=%d",
3673 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003674 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003675 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003676
Thomas Klein21eee2d2008-02-13 16:18:33 +01003677 return ret;
3678
3679out3:
3680 ibmebus_unregister_driver(&ehea_driver);
3681out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003682 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003683 unregister_reboot_notifier(&ehea_reboot_nb);
3684 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003685out:
3686 return ret;
3687}
3688
3689static void __exit ehea_module_exit(void)
3690{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003691 int ret;
3692
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003693 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003694 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003695 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003696 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003697 ret = crash_shutdown_unregister(&ehea_crash_handler);
3698 if (ret)
3699 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003700 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003701 kfree(ehea_fw_handles.arr);
3702 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003703 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003704}
3705
3706module_init(ehea_module_init);
3707module_exit(ehea_module_exit);