blob: 7f8fcc2fa74816c0d0087f46da33f303ed5a5050 [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
2 * linux/drivers/net/ehea/ehea_main.c
3 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29#include <linux/in.h>
30#include <linux/ip.h>
31#include <linux/tcp.h>
32#include <linux/udp.h>
33#include <linux/if.h>
34#include <linux/list.h>
35#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020036#include <linux/notifier.h>
37#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020038#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010039#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070040#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020041
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020042#include <net/ip.h>
43
44#include "ehea.h"
45#include "ehea_qmr.h"
46#include "ehea_phyp.h"
47
48
49MODULE_LICENSE("GPL");
50MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
51MODULE_DESCRIPTION("IBM eServer HEA Driver");
52MODULE_VERSION(DRV_VERSION);
53
54
55static int msg_level = -1;
56static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
57static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
58static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
59static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060060static int use_mcs;
61static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070062static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010063static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060064static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020065
66module_param(msg_level, int, 0);
67module_param(rq1_entries, int, 0);
68module_param(rq2_entries, int, 0);
69module_param(rq3_entries, int, 0);
70module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020071module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010072module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070073module_param(use_lro, int, 0);
74module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010075module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020076
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010077MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020079MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
80 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020081MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
84MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
87MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
90MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
91 "[2^x - 1], x = [6..14]. Default = "
92 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020093MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020094
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070095MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
96 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
97MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
98 "Default = 0");
99
Doug Maxey508d2b52008-01-31 20:20:49 -0600100static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200101static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800102static unsigned long ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200103struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700104static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100105struct ehea_fw_handle_array ehea_fw_handles;
106struct ehea_bcmc_reg_array ehea_bcmc_regs;
107
Thomas Kleind1dea382007-04-26 11:56:13 +0200108
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000109static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200110 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200111
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000112static int __devexit ehea_remove(struct of_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200113
114static struct of_device_id ehea_device_table[] = {
115 {
116 .name = "lhea",
117 .compatible = "IBM,lhea",
118 },
119 {},
120};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100121MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200122
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000123static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200124 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000125 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200126 .probe = ehea_probe_adapter,
127 .remove = ehea_remove,
128};
129
Doug Maxey508d2b52008-01-31 20:20:49 -0600130void ehea_dump(void *adr, int len, char *msg)
131{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 int x;
133 unsigned char *deb = adr;
134 for (x = 0; x < len; x += 16) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000135 printk(DRV_NAME " %s adr=%p ofs=%04x %016llx %016llx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600136 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200137 deb += 16;
138 }
139}
140
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100141void ehea_schedule_port_reset(struct ehea_port *port)
142{
143 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
144 schedule_work(&port->reset_task);
145}
146
Thomas Klein21eee2d2008-02-13 16:18:33 +0100147static void ehea_update_firmware_handles(void)
148{
149 struct ehea_fw_handle_entry *arr = NULL;
150 struct ehea_adapter *adapter;
151 int num_adapters = 0;
152 int num_ports = 0;
153 int num_portres = 0;
154 int i = 0;
155 int num_fw_handles, k, l;
156
157 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700158 mutex_lock(&ehea_fw_handles.lock);
159
Thomas Klein21eee2d2008-02-13 16:18:33 +0100160 list_for_each_entry(adapter, &adapter_list, list) {
161 num_adapters++;
162
163 for (k = 0; k < EHEA_MAX_PORTS; k++) {
164 struct ehea_port *port = adapter->port[k];
165
166 if (!port || (port->state != EHEA_PORT_UP))
167 continue;
168
169 num_ports++;
170 num_portres += port->num_def_qps + port->num_add_tx_qps;
171 }
172 }
173
174 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
175 num_ports * EHEA_NUM_PORT_FW_HANDLES +
176 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
177
178 if (num_fw_handles) {
179 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
180 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700181 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100182 } else
183 goto out_update;
184
185 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700186 if (num_adapters == 0)
187 break;
188
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 for (k = 0; k < EHEA_MAX_PORTS; k++) {
190 struct ehea_port *port = adapter->port[k];
191
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700192 if (!port || (port->state != EHEA_PORT_UP)
193 || (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100194 continue;
195
196 for (l = 0;
197 l < port->num_def_qps + port->num_add_tx_qps;
198 l++) {
199 struct ehea_port_res *pr = &port->port_res[l];
200
201 arr[i].adh = adapter->handle;
202 arr[i++].fwh = pr->qp->fw_handle;
203 arr[i].adh = adapter->handle;
204 arr[i++].fwh = pr->send_cq->fw_handle;
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = pr->recv_cq->fw_handle;
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = pr->eq->fw_handle;
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = pr->send_mr.handle;
211 arr[i].adh = adapter->handle;
212 arr[i++].fwh = pr->recv_mr.handle;
213 }
214 arr[i].adh = adapter->handle;
215 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700216 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100217 }
218
219 arr[i].adh = adapter->handle;
220 arr[i++].fwh = adapter->neq->fw_handle;
221
222 if (adapter->mr.handle) {
223 arr[i].adh = adapter->handle;
224 arr[i++].fwh = adapter->mr.handle;
225 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700226 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100227 }
228
229out_update:
230 kfree(ehea_fw_handles.arr);
231 ehea_fw_handles.arr = arr;
232 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700233out:
234 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100235}
236
237static void ehea_update_bcmc_registrations(void)
238{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700239 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100240 struct ehea_bcmc_reg_entry *arr = NULL;
241 struct ehea_adapter *adapter;
242 struct ehea_mc_list *mc_entry;
243 int num_registrations = 0;
244 int i = 0;
245 int k;
246
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700247 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
248
Thomas Klein21eee2d2008-02-13 16:18:33 +0100249 /* Determine number of registrations */
250 list_for_each_entry(adapter, &adapter_list, list)
251 for (k = 0; k < EHEA_MAX_PORTS; k++) {
252 struct ehea_port *port = adapter->port[k];
253
254 if (!port || (port->state != EHEA_PORT_UP))
255 continue;
256
257 num_registrations += 2; /* Broadcast registrations */
258
259 list_for_each_entry(mc_entry, &port->mc_list->list,list)
260 num_registrations += 2;
261 }
262
263 if (num_registrations) {
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +0100264 arr = kzalloc(num_registrations * sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100265 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700266 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100267 } else
268 goto out_update;
269
270 list_for_each_entry(adapter, &adapter_list, list) {
271 for (k = 0; k < EHEA_MAX_PORTS; k++) {
272 struct ehea_port *port = adapter->port[k];
273
274 if (!port || (port->state != EHEA_PORT_UP))
275 continue;
276
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700277 if (num_registrations == 0)
278 goto out_update;
279
Thomas Klein21eee2d2008-02-13 16:18:33 +0100280 arr[i].adh = adapter->handle;
281 arr[i].port_id = port->logical_port_id;
282 arr[i].reg_type = EHEA_BCMC_BROADCAST |
283 EHEA_BCMC_UNTAGGED;
284 arr[i++].macaddr = port->mac_addr;
285
286 arr[i].adh = adapter->handle;
287 arr[i].port_id = port->logical_port_id;
288 arr[i].reg_type = EHEA_BCMC_BROADCAST |
289 EHEA_BCMC_VLANID_ALL;
290 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700291 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100292
293 list_for_each_entry(mc_entry,
294 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700295 if (num_registrations == 0)
296 goto out_update;
297
Thomas Klein21eee2d2008-02-13 16:18:33 +0100298 arr[i].adh = adapter->handle;
299 arr[i].port_id = port->logical_port_id;
300 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
301 EHEA_BCMC_MULTICAST |
302 EHEA_BCMC_UNTAGGED;
303 arr[i++].macaddr = mc_entry->macaddr;
304
305 arr[i].adh = adapter->handle;
306 arr[i].port_id = port->logical_port_id;
307 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
308 EHEA_BCMC_MULTICAST |
309 EHEA_BCMC_VLANID_ALL;
310 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700311 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100312 }
313 }
314 }
315
316out_update:
317 kfree(ehea_bcmc_regs.arr);
318 ehea_bcmc_regs.arr = arr;
319 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700320out:
321 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100322}
323
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200324static struct net_device_stats *ehea_get_stats(struct net_device *dev)
325{
326 struct ehea_port *port = netdev_priv(dev);
327 struct net_device_stats *stats = &port->stats;
328 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100329 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200330 int i;
331
332 memset(stats, 0, sizeof(*stats));
333
Thomas Klein3faf2692009-01-21 14:45:33 -0800334 cb2 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200335 if (!cb2) {
336 ehea_error("no mem for cb2");
337 goto out;
338 }
339
340 hret = ehea_h_query_ehea_port(port->adapter->handle,
341 port->logical_port_id,
342 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
343 if (hret != H_SUCCESS) {
344 ehea_error("query_ehea_port failed");
345 goto out_herr;
346 }
347
348 if (netif_msg_hw(port))
349 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
350
351 rx_packets = 0;
352 for (i = 0; i < port->num_def_qps; i++)
353 rx_packets += port->port_res[i].rx_packets;
354
Thomas Klein7393b872007-11-21 17:37:58 +0100355 tx_packets = 0;
356 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
357 tx_packets += port->port_res[i].tx_packets;
358
359 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200360 stats->multicast = cb2->rxmcp;
361 stats->rx_errors = cb2->rxuerr;
362 stats->rx_bytes = cb2->rxo;
363 stats->tx_bytes = cb2->txo;
364 stats->rx_packets = rx_packets;
365
366out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800367 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200368out:
369 return stats;
370}
371
372static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
373{
374 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
375 struct net_device *dev = pr->port->netdev;
376 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200377 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
378 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200379 int i;
380
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200381 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200382
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200383 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200384 if (nr_of_wqes > 0)
385 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200386 pr->rq1_skba.os_skbs = fill_wqes;
387 return;
388 }
389
390 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200391 if (!skb_arr_rq1[index]) {
392 skb_arr_rq1[index] = netdev_alloc_skb(dev,
393 EHEA_L_PKT_SIZE);
394 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200395 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200396 break;
397 }
398 }
399 index--;
400 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200401 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200402 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200403
404 if (adder == 0)
405 return;
406
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200407 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200408 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200409}
410
Thomas Kleine2878802009-01-21 14:45:57 -0800411static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200412{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
414 struct net_device *dev = pr->port->netdev;
415 int i;
416
417 for (i = 0; i < pr->rq1_skba.len; i++) {
418 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Thomas Kleine2878802009-01-21 14:45:57 -0800419 if (!skb_arr_rq1[i])
420 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200421 }
422 /* Ring doorbell */
423 ehea_update_rq1a(pr->qp, nr_rq1a);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200424}
425
426static int ehea_refill_rq_def(struct ehea_port_res *pr,
427 struct ehea_q_skb_arr *q_skba, int rq_nr,
428 int num_wqes, int wqe_type, int packet_size)
429{
430 struct net_device *dev = pr->port->netdev;
431 struct ehea_qp *qp = pr->qp;
432 struct sk_buff **skb_arr = q_skba->arr;
433 struct ehea_rwqe *rwqe;
434 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200435 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200436 int ret = 0;
437
438 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200439 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200440
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200441 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
442 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200443 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200444 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200445
446 index = q_skba->index;
447 max_index_mask = q_skba->len - 1;
448 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200449 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000450 struct sk_buff *skb;
451
452 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200453 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200454 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800455 if (q_skba->os_skbs == q_skba->len - 2) {
456 ehea_info("%s: rq%i ran dry - no mem for skb",
457 pr->port->netdev->name, rq_nr);
458 ret = -ENOMEM;
459 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200460 break;
461 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200462
463 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200464 tmp_addr = ehea_map_vaddr(skb->data);
465 if (tmp_addr == -1) {
466 dev_kfree_skb(skb);
467 q_skba->os_skbs = fill_wqes - i;
468 ret = 0;
469 break;
470 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471
472 rwqe = ehea_get_next_rwqe(qp, rq_nr);
473 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200474 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200475 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200476 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200477 rwqe->sg_list[0].len = packet_size;
478 rwqe->data_segments = 1;
479
480 index++;
481 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200482 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200483 }
Thomas Klein44c82152007-07-11 16:32:00 +0200484
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200485 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200486 if (adder == 0)
487 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200488
489 /* Ring doorbell */
490 iosync();
491 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200492 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200493 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200494 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200495out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200496 return ret;
497}
498
499
500static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
501{
502 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
503 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000504 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200505}
506
507
508static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
509{
510 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
511 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000512 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200513}
514
515static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
516{
517 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
518 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
519 return 0;
520 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
521 (cqe->header_length == 0))
522 return 0;
523 return -EINVAL;
524}
525
526static inline void ehea_fill_skb(struct net_device *dev,
527 struct sk_buff *skb, struct ehea_cqe *cqe)
528{
529 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
530
531 skb_put(skb, length);
532 skb->ip_summed = CHECKSUM_UNNECESSARY;
533 skb->protocol = eth_type_trans(skb, dev);
534}
535
536static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
537 int arr_len,
538 struct ehea_cqe *cqe)
539{
540 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
541 struct sk_buff *skb;
542 void *pref;
543 int x;
544
545 x = skb_index + 1;
546 x &= (arr_len - 1);
547
548 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700549 if (pref) {
550 prefetchw(pref);
551 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200552
Hannes Hering0b2febf2009-05-04 11:06:37 -0700553 pref = (skb_array[x]->data);
554 prefetch(pref);
555 prefetch(pref + EHEA_CACHE_LINE);
556 prefetch(pref + EHEA_CACHE_LINE * 2);
557 prefetch(pref + EHEA_CACHE_LINE * 3);
558 }
559
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200560 skb = skb_array[skb_index];
561 skb_array[skb_index] = NULL;
562 return skb;
563}
564
565static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
566 int arr_len, int wqe_index)
567{
568 struct sk_buff *skb;
569 void *pref;
570 int x;
571
572 x = wqe_index + 1;
573 x &= (arr_len - 1);
574
575 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700576 if (pref) {
577 prefetchw(pref);
578 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200579
Hannes Hering0b2febf2009-05-04 11:06:37 -0700580 pref = (skb_array[x]->data);
581 prefetchw(pref);
582 prefetchw(pref + EHEA_CACHE_LINE);
583 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200584
585 skb = skb_array[wqe_index];
586 skb_array[wqe_index] = NULL;
587 return skb;
588}
589
590static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
591 struct ehea_cqe *cqe, int *processed_rq2,
592 int *processed_rq3)
593{
594 struct sk_buff *skb;
595
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100596 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
597 pr->p_stats.err_tcp_cksum++;
598 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
599 pr->p_stats.err_ip_cksum++;
600 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
601 pr->p_stats.err_frame_crc++;
602
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200603 if (rq == 2) {
604 *processed_rq2 += 1;
605 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
606 dev_kfree_skb(skb);
607 } else if (rq == 3) {
608 *processed_rq3 += 1;
609 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
610 dev_kfree_skb(skb);
611 }
612
613 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100614 if (netif_msg_rx_err(pr->port)) {
615 ehea_error("Critical receive error for QP %d. "
616 "Resetting port.", pr->qp->init_attr.qp_nr);
617 ehea_dump(cqe, sizeof(*cqe), "CQE");
618 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100619 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200620 return 1;
621 }
622
623 return 0;
624}
625
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700626static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
627 void **tcph, u64 *hdr_flags, void *priv)
628{
629 struct ehea_cqe *cqe = priv;
630 unsigned int ip_len;
631 struct iphdr *iph;
632
633 /* non tcp/udp packets */
634 if (!cqe->header_length)
635 return -1;
636
637 /* non tcp packet */
638 skb_reset_network_header(skb);
639 iph = ip_hdr(skb);
640 if (iph->protocol != IPPROTO_TCP)
641 return -1;
642
643 ip_len = ip_hdrlen(skb);
644 skb_set_transport_header(skb, ip_len);
645 *tcph = tcp_hdr(skb);
646
647 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700648 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700649 return -1;
650
651 *hdr_flags = LRO_IPV4 | LRO_TCP;
652 *iphdr = iph;
653
654 return 0;
655}
656
657static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
658 struct sk_buff *skb)
659{
660 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
661 && pr->port->vgrp;
662
663 if (use_lro) {
664 if (vlan_extracted)
665 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
666 pr->port->vgrp,
667 cqe->vlan_tag,
668 cqe);
669 else
670 lro_receive_skb(&pr->lro_mgr, skb, cqe);
671 } else {
672 if (vlan_extracted)
673 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
674 cqe->vlan_tag);
675 else
676 netif_receive_skb(skb);
677 }
678}
679
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700680static int ehea_proc_rwqes(struct net_device *dev,
681 struct ehea_port_res *pr,
682 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200683{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100684 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200685 struct ehea_qp *qp = pr->qp;
686 struct ehea_cqe *cqe;
687 struct sk_buff *skb;
688 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
689 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
690 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
691 int skb_arr_rq1_len = pr->rq1_skba.len;
692 int skb_arr_rq2_len = pr->rq2_skba.len;
693 int skb_arr_rq3_len = pr->rq3_skba.len;
694 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700695 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200696
697 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
698 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200699
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200700 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700701 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200702 ehea_inc_rq1(qp);
703 processed_rq1++;
704 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200705 if (netif_msg_rx_status(port))
706 ehea_dump(cqe, sizeof(*cqe), "CQE");
707
708 last_wqe_index = wqe_index;
709 rmb();
710 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600711 if (rq == 1) {
712 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200713 skb = get_skb_by_index_ll(skb_arr_rq1,
714 skb_arr_rq1_len,
715 wqe_index);
716 if (unlikely(!skb)) {
717 if (netif_msg_rx_err(port))
718 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100719
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700720 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200721 EHEA_L_PKT_SIZE);
722 if (!skb)
723 break;
724 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600725 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200726 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700727 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600728 } else if (rq == 2) {
729 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200730 skb = get_skb_by_index(skb_arr_rq2,
731 skb_arr_rq2_len, cqe);
732 if (unlikely(!skb)) {
733 if (netif_msg_rx_err(port))
734 ehea_error("rq2: skb=NULL");
735 break;
736 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700737 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200738 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600739 } else {
740 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200741 skb = get_skb_by_index(skb_arr_rq3,
742 skb_arr_rq3_len, cqe);
743 if (unlikely(!skb)) {
744 if (netif_msg_rx_err(port))
745 ehea_error("rq3: skb=NULL");
746 break;
747 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700748 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749 processed_rq3++;
750 }
751
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700752 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100753 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100754 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200755 port_reset = ehea_treat_poll_error(pr, rq, cqe,
756 &processed_rq2,
757 &processed_rq3);
758 if (port_reset)
759 break;
760 }
761 cqe = ehea_poll_rq1(qp, &wqe_index);
762 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700763 if (use_lro)
764 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200765
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200766 pr->rx_packets += processed;
767
768 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
769 ehea_refill_rq2(pr, processed_rq2);
770 ehea_refill_rq3(pr, processed_rq3);
771
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700772 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200773}
774
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100775static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200776{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100777 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200778 struct ehea_cq *send_cq = pr->send_cq;
779 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100780 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200781 int cqe_counter = 0;
782 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100783 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200784 unsigned long flags;
785
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100786 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600787 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100788 ehea_inc_cq(send_cq);
789
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200790 cqe_counter++;
791 rmb();
792 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
793 ehea_error("Send Completion Error: Resetting port");
794 if (netif_msg_tx_err(pr->port))
795 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100796 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200797 break;
798 }
799
800 if (netif_msg_tx_done(pr->port))
801 ehea_dump(cqe, sizeof(*cqe), "CQE");
802
803 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100804 == EHEA_SWQE2_TYPE)) {
805
806 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
807 skb = pr->sq_skba.arr[index];
808 dev_kfree_skb(skb);
809 pr->sq_skba.arr[index] = NULL;
810 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200811
812 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
813 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100814
815 cqe = ehea_poll_cq(send_cq);
816 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200817
818 ehea_update_feca(send_cq, cqe_counter);
819 atomic_add(swqe_av, &pr->swqe_avail);
820
821 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100822
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200823 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
824 >= pr->swqe_refill_th)) {
825 netif_wake_queue(pr->port->netdev);
826 pr->queue_stopped = 0;
827 }
828 spin_unlock_irqrestore(&pr->netif_queue, flags);
829
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100830 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200831}
832
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100833#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700834#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100835
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700836static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200837{
Doug Maxey508d2b52008-01-31 20:20:49 -0600838 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
839 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700840 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100841 struct ehea_cqe *cqe;
842 struct ehea_cqe *cqe_skb = NULL;
843 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700844 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100845
846 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700847 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100848
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700849 if (!force_irq)
850 rx += ehea_proc_rwqes(dev, pr, budget - rx);
851
852 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100853 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700854 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800855 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100856 ehea_reset_cq_ep(pr->recv_cq);
857 ehea_reset_cq_ep(pr->send_cq);
858 ehea_reset_cq_n1(pr->recv_cq);
859 ehea_reset_cq_n1(pr->send_cq);
860 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
861 cqe_skb = ehea_poll_cq(pr->send_cq);
862
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100863 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700864 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100865
Ben Hutchings288379f2009-01-19 16:43:59 -0800866 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700867 return rx;
868
869 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
870 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100871 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100872
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700873 pr->poll_counter++;
874 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200875}
876
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200877#ifdef CONFIG_NET_POLL_CONTROLLER
878static void ehea_netpoll(struct net_device *dev)
879{
880 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700881 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200882
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700883 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800884 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200885}
886#endif
887
David Howells7d12e782006-10-05 14:55:46 +0100888static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200889{
890 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100891
Ben Hutchings288379f2009-01-19 16:43:59 -0800892 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100893
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200894 return IRQ_HANDLED;
895}
896
David Howells7d12e782006-10-05 14:55:46 +0100897static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200898{
899 struct ehea_port *port = param;
900 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100901 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200902 u32 qp_token;
903
904 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100905
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200906 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200907 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000908 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100909 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100910
911 qp = port->port_res[qp_token].qp;
912 ehea_error_data(port->adapter, qp->fw_handle);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100913 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200914 }
915
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100916 ehea_schedule_port_reset(port);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100917
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200918 return IRQ_HANDLED;
919}
920
921static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
922 int logical_port)
923{
924 int i;
925
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100926 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100927 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200928 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100929 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200930 return NULL;
931}
932
933int ehea_sense_port_attr(struct ehea_port *port)
934{
935 int ret;
936 u64 hret;
937 struct hcp_ehea_port_cb0 *cb0;
938
Doug Maxey508d2b52008-01-31 20:20:49 -0600939 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800940 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600941 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200942 ehea_error("no mem for cb0");
943 ret = -ENOMEM;
944 goto out;
945 }
946
947 hret = ehea_h_query_ehea_port(port->adapter->handle,
948 port->logical_port_id, H_PORT_CB0,
949 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
950 cb0);
951 if (hret != H_SUCCESS) {
952 ret = -EIO;
953 goto out_free;
954 }
955
956 /* MAC address */
957 port->mac_addr = cb0->port_mac_addr << 16;
958
Doug Maxey508d2b52008-01-31 20:20:49 -0600959 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200960 ret = -EADDRNOTAVAIL;
961 goto out_free;
962 }
963
964 /* Port speed */
965 switch (cb0->port_speed) {
966 case H_SPEED_10M_H:
967 port->port_speed = EHEA_SPEED_10M;
968 port->full_duplex = 0;
969 break;
970 case H_SPEED_10M_F:
971 port->port_speed = EHEA_SPEED_10M;
972 port->full_duplex = 1;
973 break;
974 case H_SPEED_100M_H:
975 port->port_speed = EHEA_SPEED_100M;
976 port->full_duplex = 0;
977 break;
978 case H_SPEED_100M_F:
979 port->port_speed = EHEA_SPEED_100M;
980 port->full_duplex = 1;
981 break;
982 case H_SPEED_1G_F:
983 port->port_speed = EHEA_SPEED_1G;
984 port->full_duplex = 1;
985 break;
986 case H_SPEED_10G_F:
987 port->port_speed = EHEA_SPEED_10G;
988 port->full_duplex = 1;
989 break;
990 default:
991 port->port_speed = 0;
992 port->full_duplex = 0;
993 break;
994 }
995
Thomas Kleine919b592007-01-22 12:53:20 +0100996 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100997 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +0100998
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200999 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001000 if (use_mcs)
1001 port->num_def_qps = cb0->num_default_qps;
1002 else
1003 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001004
1005 if (!port->num_def_qps) {
1006 ret = -EINVAL;
1007 goto out_free;
1008 }
1009
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001010 port->num_tx_qps = num_tx_qps;
1011
1012 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001013 port->num_add_tx_qps = 0;
1014 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001015 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001016
1017 ret = 0;
1018out_free:
1019 if (ret || netif_msg_probe(port))
1020 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001021 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001022out:
1023 return ret;
1024}
1025
1026int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1027{
1028 struct hcp_ehea_port_cb4 *cb4;
1029 u64 hret;
1030 int ret = 0;
1031
Thomas Klein3faf2692009-01-21 14:45:33 -08001032 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001033 if (!cb4) {
1034 ehea_error("no mem for cb4");
1035 ret = -ENOMEM;
1036 goto out;
1037 }
1038
1039 cb4->port_speed = port_speed;
1040
1041 netif_carrier_off(port->netdev);
1042
1043 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1044 port->logical_port_id,
1045 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1046 if (hret == H_SUCCESS) {
1047 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1048
1049 hret = ehea_h_query_ehea_port(port->adapter->handle,
1050 port->logical_port_id,
1051 H_PORT_CB4, H_PORT_CB4_SPEED,
1052 cb4);
1053 if (hret == H_SUCCESS) {
1054 switch (cb4->port_speed) {
1055 case H_SPEED_10M_H:
1056 port->port_speed = EHEA_SPEED_10M;
1057 port->full_duplex = 0;
1058 break;
1059 case H_SPEED_10M_F:
1060 port->port_speed = EHEA_SPEED_10M;
1061 port->full_duplex = 1;
1062 break;
1063 case H_SPEED_100M_H:
1064 port->port_speed = EHEA_SPEED_100M;
1065 port->full_duplex = 0;
1066 break;
1067 case H_SPEED_100M_F:
1068 port->port_speed = EHEA_SPEED_100M;
1069 port->full_duplex = 1;
1070 break;
1071 case H_SPEED_1G_F:
1072 port->port_speed = EHEA_SPEED_1G;
1073 port->full_duplex = 1;
1074 break;
1075 case H_SPEED_10G_F:
1076 port->port_speed = EHEA_SPEED_10G;
1077 port->full_duplex = 1;
1078 break;
1079 default:
1080 port->port_speed = 0;
1081 port->full_duplex = 0;
1082 break;
1083 }
1084 } else {
1085 ehea_error("Failed sensing port speed");
1086 ret = -EIO;
1087 }
1088 } else {
1089 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001090 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001091 ret = -EPERM;
1092 } else {
1093 ret = -EIO;
1094 ehea_error("Failed setting port speed");
1095 }
1096 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001097 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1098 netif_carrier_on(port->netdev);
1099
Thomas Klein3faf2692009-01-21 14:45:33 -08001100 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001101out:
1102 return ret;
1103}
1104
1105static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1106{
1107 int ret;
1108 u8 ec;
1109 u8 portnum;
1110 struct ehea_port *port;
1111
1112 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1113 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1114 port = ehea_get_port(adapter, portnum);
1115
1116 switch (ec) {
1117 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1118
1119 if (!port) {
1120 ehea_error("unknown portnum %x", portnum);
1121 break;
1122 }
1123
1124 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1125 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001126 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001127 if (ret) {
1128 ehea_error("failed resensing port "
1129 "attributes");
1130 break;
1131 }
1132
1133 if (netif_msg_link(port))
1134 ehea_info("%s: Logical port up: %dMbps "
1135 "%s Duplex",
1136 port->netdev->name,
1137 port->port_speed,
1138 port->full_duplex ==
1139 1 ? "Full" : "Half");
1140
1141 netif_carrier_on(port->netdev);
1142 netif_wake_queue(port->netdev);
1143 }
1144 } else
1145 if (netif_carrier_ok(port->netdev)) {
1146 if (netif_msg_link(port))
1147 ehea_info("%s: Logical port down",
1148 port->netdev->name);
1149 netif_carrier_off(port->netdev);
1150 netif_stop_queue(port->netdev);
1151 }
1152
1153 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001154 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001155 if (netif_msg_link(port))
1156 ehea_info("%s: Physical port up",
1157 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001158 if (prop_carrier_state)
1159 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001160 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001161 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001162 if (netif_msg_link(port))
1163 ehea_info("%s: Physical port down",
1164 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001165 if (prop_carrier_state)
1166 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001167 }
1168
1169 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1170 ehea_info("External switch port is primary port");
1171 else
1172 ehea_info("External switch port is backup port");
1173
1174 break;
1175 case EHEA_EC_ADAPTER_MALFUNC:
1176 ehea_error("Adapter malfunction");
1177 break;
1178 case EHEA_EC_PORT_MALFUNC:
1179 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1180 netif_carrier_off(port->netdev);
1181 netif_stop_queue(port->netdev);
1182 break;
1183 default:
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001184 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001185 break;
1186 }
1187}
1188
1189static void ehea_neq_tasklet(unsigned long data)
1190{
Doug Maxey508d2b52008-01-31 20:20:49 -06001191 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001192 struct ehea_eqe *eqe;
1193 u64 event_mask;
1194
1195 eqe = ehea_poll_eq(adapter->neq);
1196 ehea_debug("eqe=%p", eqe);
1197
1198 while (eqe) {
1199 ehea_debug("*eqe=%lx", eqe->entry);
1200 ehea_parse_eqe(adapter, eqe->entry);
1201 eqe = ehea_poll_eq(adapter->neq);
1202 ehea_debug("next eqe=%p", eqe);
1203 }
1204
1205 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1206 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1207 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1208
1209 ehea_h_reset_events(adapter->handle,
1210 adapter->neq->fw_handle, event_mask);
1211}
1212
David Howells7d12e782006-10-05 14:55:46 +01001213static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001214{
1215 struct ehea_adapter *adapter = param;
1216 tasklet_hi_schedule(&adapter->neq_tasklet);
1217 return IRQ_HANDLED;
1218}
1219
1220
1221static int ehea_fill_port_res(struct ehea_port_res *pr)
1222{
1223 int ret;
1224 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1225
Thomas Kleine2878802009-01-21 14:45:57 -08001226 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1227 - init_attr->act_nr_rwqes_rq2
1228 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001229
Thomas Kleine2878802009-01-21 14:45:57 -08001230 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001231
1232 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1233
1234 return ret;
1235}
1236
1237static int ehea_reg_interrupts(struct net_device *dev)
1238{
1239 struct ehea_port *port = netdev_priv(dev);
1240 struct ehea_port_res *pr;
1241 int i, ret;
1242
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001243
1244 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1245 dev->name);
1246
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001247 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001248 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001249 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001250 if (ret) {
1251 ehea_error("failed registering irq for qp_aff_irq_handler:"
1252 "ist=%X", port->qp_eq->attr.ist1);
1253 goto out_free_qpeq;
1254 }
1255
1256 if (netif_msg_ifup(port))
1257 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1258 "registered", port->qp_eq->attr.ist1);
1259
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001260
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001261 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1262 pr = &port->port_res[i];
1263 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001264 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001265 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001266 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001267 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001268 pr);
1269 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001270 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001271 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001272 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273 goto out_free_req;
1274 }
1275 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001276 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1277 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001278 }
1279out:
1280 return ret;
1281
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001282
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283out_free_req:
1284 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001285 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001286 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001287 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001288
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001289out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001290 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001291 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001292
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001293 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001294
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001295}
1296
1297static void ehea_free_interrupts(struct net_device *dev)
1298{
1299 struct ehea_port *port = netdev_priv(dev);
1300 struct ehea_port_res *pr;
1301 int i;
1302
1303 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001304
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001305 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1306 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001307 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001308 if (netif_msg_intr(port))
1309 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001310 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001311 }
1312
1313 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001314 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001315 if (netif_msg_intr(port))
1316 ehea_info("associated event interrupt for handle 0x%X freed",
1317 port->qp_eq->attr.ist1);
1318}
1319
1320static int ehea_configure_port(struct ehea_port *port)
1321{
1322 int ret, i;
1323 u64 hret, mask;
1324 struct hcp_ehea_port_cb0 *cb0;
1325
1326 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001327 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001328 if (!cb0)
1329 goto out;
1330
1331 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1332 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1333 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1334 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1335 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1336 PXLY_RC_VLAN_FILTER)
1337 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1338
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001339 for (i = 0; i < port->num_mcs; i++)
1340 if (use_mcs)
1341 cb0->default_qpn_arr[i] =
1342 port->port_res[i].qp->init_attr.qp_nr;
1343 else
1344 cb0->default_qpn_arr[i] =
1345 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001346
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001347 if (netif_msg_ifup(port))
1348 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1349
1350 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1351 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1352
1353 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1354 port->logical_port_id,
1355 H_PORT_CB0, mask, cb0);
1356 ret = -EIO;
1357 if (hret != H_SUCCESS)
1358 goto out_free;
1359
1360 ret = 0;
1361
1362out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001363 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001364out:
1365 return ret;
1366}
1367
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001368int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001369{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001370 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001371 struct ehea_adapter *adapter = pr->port->adapter;
1372
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001373 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1374 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001375 goto out;
1376
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001377 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1378 if (ret)
1379 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001380
1381 return 0;
1382
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001383out_free:
1384 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001385out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001386 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001387 return -EIO;
1388}
1389
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001390int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001391{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001392 if ((ehea_rem_mr(&pr->send_mr))
1393 || (ehea_rem_mr(&pr->recv_mr)))
1394 return -EIO;
1395 else
1396 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001397}
1398
1399static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1400{
Doug Maxey508d2b52008-01-31 20:20:49 -06001401 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001402
1403 q_skba->arr = vmalloc(arr_size);
1404 if (!q_skba->arr)
1405 return -ENOMEM;
1406
1407 memset(q_skba->arr, 0, arr_size);
1408
1409 q_skba->len = max_q_entries;
1410 q_skba->index = 0;
1411 q_skba->os_skbs = 0;
1412
1413 return 0;
1414}
1415
1416static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1417 struct port_res_cfg *pr_cfg, int queue_token)
1418{
1419 struct ehea_adapter *adapter = port->adapter;
1420 enum ehea_eq_type eq_type = EHEA_EQ;
1421 struct ehea_qp_init_attr *init_attr = NULL;
1422 int ret = -EIO;
1423
1424 memset(pr, 0, sizeof(struct ehea_port_res));
1425
1426 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001427 spin_lock_init(&pr->xmit_lock);
1428 spin_lock_init(&pr->netif_queue);
1429
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001430 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1431 if (!pr->eq) {
1432 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001433 goto out_free;
1434 }
1435
1436 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001437 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001438 port->logical_port_id);
1439 if (!pr->recv_cq) {
1440 ehea_error("create_cq failed (cq_recv)");
1441 goto out_free;
1442 }
1443
1444 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001445 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001446 port->logical_port_id);
1447 if (!pr->send_cq) {
1448 ehea_error("create_cq failed (cq_send)");
1449 goto out_free;
1450 }
1451
1452 if (netif_msg_ifup(port))
1453 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1454 pr->send_cq->attr.act_nr_of_cqes,
1455 pr->recv_cq->attr.act_nr_of_cqes);
1456
1457 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1458 if (!init_attr) {
1459 ret = -ENOMEM;
1460 ehea_error("no mem for ehea_qp_init_attr");
1461 goto out_free;
1462 }
1463
1464 init_attr->low_lat_rq1 = 1;
1465 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1466 init_attr->rq_count = 3;
1467 init_attr->qp_token = queue_token;
1468 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1469 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1470 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1471 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1472 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1473 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1474 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1475 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1476 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1477 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1478 init_attr->port_nr = port->logical_port_id;
1479 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1480 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1481 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1482
1483 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1484 if (!pr->qp) {
1485 ehea_error("create_qp failed");
1486 ret = -EIO;
1487 goto out_free;
1488 }
1489
1490 if (netif_msg_ifup(port))
1491 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1492 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1493 init_attr->act_nr_send_wqes,
1494 init_attr->act_nr_rwqes_rq1,
1495 init_attr->act_nr_rwqes_rq2,
1496 init_attr->act_nr_rwqes_rq3);
1497
Thomas Klein44fb3122008-04-04 15:04:53 +02001498 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1499
1500 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001501 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1502 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1503 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1504 if (ret)
1505 goto out_free;
1506
1507 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1508 if (ehea_gen_smrs(pr) != 0) {
1509 ret = -EIO;
1510 goto out_free;
1511 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001512
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001513 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1514
1515 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001516
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001517 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001518
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001519 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1520 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1521 pr->lro_mgr.lro_arr = pr->lro_desc;
1522 pr->lro_mgr.get_skb_header = get_skb_hdr;
1523 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1524 pr->lro_mgr.dev = port->netdev;
1525 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1526 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1527
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001528 ret = 0;
1529 goto out;
1530
1531out_free:
1532 kfree(init_attr);
1533 vfree(pr->sq_skba.arr);
1534 vfree(pr->rq1_skba.arr);
1535 vfree(pr->rq2_skba.arr);
1536 vfree(pr->rq3_skba.arr);
1537 ehea_destroy_qp(pr->qp);
1538 ehea_destroy_cq(pr->send_cq);
1539 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001540 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001541out:
1542 return ret;
1543}
1544
1545static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1546{
1547 int ret, i;
1548
Hannes Hering357eb462009-08-04 11:48:39 -07001549 if (pr->qp)
1550 netif_napi_del(&pr->napi);
1551
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001552 ret = ehea_destroy_qp(pr->qp);
1553
1554 if (!ret) {
1555 ehea_destroy_cq(pr->send_cq);
1556 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001557 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001558
1559 for (i = 0; i < pr->rq1_skba.len; i++)
1560 if (pr->rq1_skba.arr[i])
1561 dev_kfree_skb(pr->rq1_skba.arr[i]);
1562
1563 for (i = 0; i < pr->rq2_skba.len; i++)
1564 if (pr->rq2_skba.arr[i])
1565 dev_kfree_skb(pr->rq2_skba.arr[i]);
1566
1567 for (i = 0; i < pr->rq3_skba.len; i++)
1568 if (pr->rq3_skba.arr[i])
1569 dev_kfree_skb(pr->rq3_skba.arr[i]);
1570
1571 for (i = 0; i < pr->sq_skba.len; i++)
1572 if (pr->sq_skba.arr[i])
1573 dev_kfree_skb(pr->sq_skba.arr[i]);
1574
1575 vfree(pr->rq1_skba.arr);
1576 vfree(pr->rq2_skba.arr);
1577 vfree(pr->rq3_skba.arr);
1578 vfree(pr->sq_skba.arr);
1579 ret = ehea_rem_smrs(pr);
1580 }
1581 return ret;
1582}
1583
1584/*
1585 * The write_* functions store information in swqe which is used by
1586 * the hardware to calculate the ip/tcp/udp checksum
1587 */
1588
1589static inline void write_ip_start_end(struct ehea_swqe *swqe,
1590 const struct sk_buff *skb)
1591{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001592 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001593 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001594}
1595
1596static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1597 const struct sk_buff *skb)
1598{
1599 swqe->tcp_offset =
1600 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1601
1602 swqe->tcp_end = (u16)skb->len - 1;
1603}
1604
1605static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1606 const struct sk_buff *skb)
1607{
1608 swqe->tcp_offset =
1609 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1610
1611 swqe->tcp_end = (u16)skb->len - 1;
1612}
1613
1614
1615static void write_swqe2_TSO(struct sk_buff *skb,
1616 struct ehea_swqe *swqe, u32 lkey)
1617{
1618 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1619 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1620 int skb_data_size = skb->len - skb->data_len;
1621 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001622
1623 /* Packet is TCP with TSO enabled */
1624 swqe->tx_control |= EHEA_SWQE_TSO;
1625 swqe->mss = skb_shinfo(skb)->gso_size;
1626 /* copy only eth/ip/tcp headers to immediate data and
1627 * the rest of skb->data to sg1entry
1628 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001629 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001630
1631 skb_data_size = skb->len - skb->data_len;
1632
1633 if (skb_data_size >= headersize) {
1634 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001635 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001636 swqe->immediate_data_length = headersize;
1637
1638 if (skb_data_size > headersize) {
1639 /* set sg1entry data */
1640 sg1entry->l_key = lkey;
1641 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001642 sg1entry->vaddr =
1643 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001644 swqe->descriptors++;
1645 }
1646 } else
1647 ehea_error("cannot handle fragmented headers");
1648}
1649
1650static void write_swqe2_nonTSO(struct sk_buff *skb,
1651 struct ehea_swqe *swqe, u32 lkey)
1652{
1653 int skb_data_size = skb->len - skb->data_len;
1654 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1655 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001656
1657 /* Packet is any nonTSO type
1658 *
1659 * Copy as much as possible skb->data to immediate data and
1660 * the rest to sg1entry
1661 */
1662 if (skb_data_size >= SWQE2_MAX_IMM) {
1663 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001664 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001665
1666 swqe->immediate_data_length = SWQE2_MAX_IMM;
1667
1668 if (skb_data_size > SWQE2_MAX_IMM) {
1669 /* copy sg1entry data */
1670 sg1entry->l_key = lkey;
1671 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001672 sg1entry->vaddr =
1673 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001674 swqe->descriptors++;
1675 }
1676 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001677 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001678 swqe->immediate_data_length = skb_data_size;
1679 }
1680}
1681
1682static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1683 struct ehea_swqe *swqe, u32 lkey)
1684{
1685 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1686 skb_frag_t *frag;
1687 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001688
1689 nfrags = skb_shinfo(skb)->nr_frags;
1690 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001691 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001692 swqe->descriptors = 0;
1693 sg1entry_contains_frag_data = 0;
1694
1695 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1696 write_swqe2_TSO(skb, swqe, lkey);
1697 else
1698 write_swqe2_nonTSO(skb, swqe, lkey);
1699
1700 /* write descriptors */
1701 if (nfrags > 0) {
1702 if (swqe->descriptors == 0) {
1703 /* sg1entry not yet used */
1704 frag = &skb_shinfo(skb)->frags[0];
1705
1706 /* copy sg1entry data */
1707 sg1entry->l_key = lkey;
1708 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001709 sg1entry->vaddr =
1710 ehea_map_vaddr(page_address(frag->page)
1711 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001712 swqe->descriptors++;
1713 sg1entry_contains_frag_data = 1;
1714 }
1715
1716 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1717
1718 frag = &skb_shinfo(skb)->frags[i];
1719 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1720
1721 sgentry->l_key = lkey;
1722 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001723 sgentry->vaddr =
1724 ehea_map_vaddr(page_address(frag->page)
1725 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001726 swqe->descriptors++;
1727 }
1728 }
1729}
1730
1731static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1732{
1733 int ret = 0;
1734 u64 hret;
1735 u8 reg_type;
1736
1737 /* De/Register untagged packets */
1738 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1739 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1740 port->logical_port_id,
1741 reg_type, port->mac_addr, 0, hcallid);
1742 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001743 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001744 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001745 ret = -EIO;
1746 goto out_herr;
1747 }
1748
1749 /* De/Register VLAN packets */
1750 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1751 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1752 port->logical_port_id,
1753 reg_type, port->mac_addr, 0, hcallid);
1754 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001755 ehea_error("%sregistering bc address failed (vlan)",
1756 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001757 ret = -EIO;
1758 }
1759out_herr:
1760 return ret;
1761}
1762
1763static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1764{
1765 struct ehea_port *port = netdev_priv(dev);
1766 struct sockaddr *mac_addr = sa;
1767 struct hcp_ehea_port_cb0 *cb0;
1768 int ret;
1769 u64 hret;
1770
1771 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1772 ret = -EADDRNOTAVAIL;
1773 goto out;
1774 }
1775
Thomas Klein3faf2692009-01-21 14:45:33 -08001776 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001777 if (!cb0) {
1778 ehea_error("no mem for cb0");
1779 ret = -ENOMEM;
1780 goto out;
1781 }
1782
1783 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1784
1785 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1786
1787 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1788 port->logical_port_id, H_PORT_CB0,
1789 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1790 if (hret != H_SUCCESS) {
1791 ret = -EIO;
1792 goto out_free;
1793 }
1794
1795 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1796
1797 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001798 if (port->state == EHEA_PORT_UP) {
1799 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1800 if (ret)
1801 goto out_upregs;
1802 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001803
1804 port->mac_addr = cb0->port_mac_addr << 16;
1805
1806 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001807 if (port->state == EHEA_PORT_UP) {
1808 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1809 if (ret)
1810 goto out_upregs;
1811 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001812
1813 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001814
1815out_upregs:
1816 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001817out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001818 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001819out:
1820 return ret;
1821}
1822
1823static void ehea_promiscuous_error(u64 hret, int enable)
1824{
Thomas Klein7674a582007-01-22 12:54:20 +01001825 if (hret == H_AUTHORITY)
1826 ehea_info("Hypervisor denied %sabling promiscuous mode",
1827 enable == 1 ? "en" : "dis");
1828 else
1829 ehea_error("failed %sabling promiscuous mode",
1830 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001831}
1832
1833static void ehea_promiscuous(struct net_device *dev, int enable)
1834{
1835 struct ehea_port *port = netdev_priv(dev);
1836 struct hcp_ehea_port_cb7 *cb7;
1837 u64 hret;
1838
1839 if ((enable && port->promisc) || (!enable && !port->promisc))
1840 return;
1841
Thomas Klein3faf2692009-01-21 14:45:33 -08001842 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001843 if (!cb7) {
1844 ehea_error("no mem for cb7");
1845 goto out;
1846 }
1847
1848 /* Modify Pxs_DUCQPN in CB7 */
1849 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1850
1851 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1852 port->logical_port_id,
1853 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1854 if (hret) {
1855 ehea_promiscuous_error(hret, enable);
1856 goto out;
1857 }
1858
1859 port->promisc = enable;
1860out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001861 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001862 return;
1863}
1864
1865static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1866 u32 hcallid)
1867{
1868 u64 hret;
1869 u8 reg_type;
1870
1871 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1872 | EHEA_BCMC_UNTAGGED;
1873
1874 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1875 port->logical_port_id,
1876 reg_type, mc_mac_addr, 0, hcallid);
1877 if (hret)
1878 goto out;
1879
1880 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1881 | EHEA_BCMC_VLANID_ALL;
1882
1883 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1884 port->logical_port_id,
1885 reg_type, mc_mac_addr, 0, hcallid);
1886out:
1887 return hret;
1888}
1889
1890static int ehea_drop_multicast_list(struct net_device *dev)
1891{
1892 struct ehea_port *port = netdev_priv(dev);
1893 struct ehea_mc_list *mc_entry = port->mc_list;
1894 struct list_head *pos;
1895 struct list_head *temp;
1896 int ret = 0;
1897 u64 hret;
1898
1899 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1900 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1901
1902 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1903 H_DEREG_BCMC);
1904 if (hret) {
1905 ehea_error("failed deregistering mcast MAC");
1906 ret = -EIO;
1907 }
1908
1909 list_del(pos);
1910 kfree(mc_entry);
1911 }
1912 return ret;
1913}
1914
1915static void ehea_allmulti(struct net_device *dev, int enable)
1916{
1917 struct ehea_port *port = netdev_priv(dev);
1918 u64 hret;
1919
1920 if (!port->allmulti) {
1921 if (enable) {
1922 /* Enable ALLMULTI */
1923 ehea_drop_multicast_list(dev);
1924 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1925 if (!hret)
1926 port->allmulti = 1;
1927 else
1928 ehea_error("failed enabling IFF_ALLMULTI");
1929 }
1930 } else
1931 if (!enable) {
1932 /* Disable ALLMULTI */
1933 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1934 if (!hret)
1935 port->allmulti = 0;
1936 else
1937 ehea_error("failed disabling IFF_ALLMULTI");
1938 }
1939}
1940
Doug Maxey508d2b52008-01-31 20:20:49 -06001941static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001942{
1943 struct ehea_mc_list *ehea_mcl_entry;
1944 u64 hret;
1945
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001946 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001947 if (!ehea_mcl_entry) {
1948 ehea_error("no mem for mcl_entry");
1949 return;
1950 }
1951
1952 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1953
1954 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1955
1956 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1957 H_REG_BCMC);
1958 if (!hret)
1959 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1960 else {
1961 ehea_error("failed registering mcast MAC");
1962 kfree(ehea_mcl_entry);
1963 }
1964}
1965
1966static void ehea_set_multicast_list(struct net_device *dev)
1967{
1968 struct ehea_port *port = netdev_priv(dev);
1969 struct dev_mc_list *k_mcl_entry;
1970 int ret, i;
1971
1972 if (dev->flags & IFF_PROMISC) {
1973 ehea_promiscuous(dev, 1);
1974 return;
1975 }
1976 ehea_promiscuous(dev, 0);
1977
1978 if (dev->flags & IFF_ALLMULTI) {
1979 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001980 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001981 }
1982 ehea_allmulti(dev, 0);
1983
1984 if (dev->mc_count) {
1985 ret = ehea_drop_multicast_list(dev);
1986 if (ret) {
1987 /* Dropping the current multicast list failed.
1988 * Enabling ALL_MULTI is the best we can do.
1989 */
1990 ehea_allmulti(dev, 1);
1991 }
1992
1993 if (dev->mc_count > port->adapter->max_mc_mac) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001994 ehea_info("Mcast registration limit reached (0x%llx). "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001995 "Use ALLMULTI!",
1996 port->adapter->max_mc_mac);
1997 goto out;
1998 }
1999
Doug Maxey508d2b52008-01-31 20:20:49 -06002000 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
2001 k_mcl_entry = k_mcl_entry->next)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002002 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002003
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002004 }
2005out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002006 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002007 return;
2008}
2009
2010static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2011{
2012 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2013 return -EINVAL;
2014 dev->mtu = new_mtu;
2015 return 0;
2016}
2017
2018static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2019 struct ehea_swqe *swqe, u32 lkey)
2020{
2021 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002022 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002023
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002024 /* IPv4 */
2025 swqe->tx_control |= EHEA_SWQE_CRC
2026 | EHEA_SWQE_IP_CHECKSUM
2027 | EHEA_SWQE_TCP_CHECKSUM
2028 | EHEA_SWQE_IMM_DATA_PRESENT
2029 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2030
2031 write_ip_start_end(swqe, skb);
2032
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002033 if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002034 if ((iph->frag_off & IP_MF)
2035 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002036 /* IP fragment, so don't change cs */
2037 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2038 else
2039 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002040 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002041 write_tcp_offset_end(swqe, skb);
2042 }
2043
2044 /* icmp (big data) and ip segmentation packets (all other ip
2045 packets) do not require any special handling */
2046
2047 } else {
2048 /* Other Ethernet Protocol */
2049 swqe->tx_control |= EHEA_SWQE_CRC
2050 | EHEA_SWQE_IMM_DATA_PRESENT
2051 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2052 }
2053
2054 write_swqe2_data(skb, dev, swqe, lkey);
2055}
2056
2057static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2058 struct ehea_swqe *swqe)
2059{
2060 int nfrags = skb_shinfo(skb)->nr_frags;
2061 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2062 skb_frag_t *frag;
2063 int i;
2064
2065 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002066 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002067
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002068 /* IPv4 */
2069 write_ip_start_end(swqe, skb);
2070
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002071 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002072 swqe->tx_control |= EHEA_SWQE_CRC
2073 | EHEA_SWQE_IP_CHECKSUM
2074 | EHEA_SWQE_TCP_CHECKSUM
2075 | EHEA_SWQE_IMM_DATA_PRESENT;
2076
2077 write_tcp_offset_end(swqe, skb);
2078
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002079 } else if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002080 if ((iph->frag_off & IP_MF)
2081 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002082 /* IP fragment, so don't change cs */
2083 swqe->tx_control |= EHEA_SWQE_CRC
2084 | EHEA_SWQE_IMM_DATA_PRESENT;
2085 else {
2086 swqe->tx_control |= EHEA_SWQE_CRC
2087 | EHEA_SWQE_IP_CHECKSUM
2088 | EHEA_SWQE_TCP_CHECKSUM
2089 | EHEA_SWQE_IMM_DATA_PRESENT;
2090
2091 write_udp_offset_end(swqe, skb);
2092 }
2093 } else {
2094 /* icmp (big data) and
2095 ip segmentation packets (all other ip packets) */
2096 swqe->tx_control |= EHEA_SWQE_CRC
2097 | EHEA_SWQE_IP_CHECKSUM
2098 | EHEA_SWQE_IMM_DATA_PRESENT;
2099 }
2100 } else {
2101 /* Other Ethernet Protocol */
2102 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2103 }
2104 /* copy (immediate) data */
2105 if (nfrags == 0) {
2106 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002107 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108 } else {
2109 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002110 skb_copy_from_linear_data(skb, imm_data,
2111 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002112 imm_data += skb->len - skb->data_len;
2113
2114 /* ... then copy data from the fragments */
2115 for (i = 0; i < nfrags; i++) {
2116 frag = &skb_shinfo(skb)->frags[i];
2117 memcpy(imm_data,
2118 page_address(frag->page) + frag->page_offset,
2119 frag->size);
2120 imm_data += frag->size;
2121 }
2122 }
2123 swqe->immediate_data_length = skb->len;
2124 dev_kfree_skb(skb);
2125}
2126
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002127static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2128{
2129 struct tcphdr *tcp;
2130 u32 tmp;
2131
2132 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002133 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002134 tcp = (struct tcphdr *)(skb_network_header(skb) +
2135 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002136 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002137 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002138 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002139 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002140 return 0;
2141}
2142
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002143static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2144{
2145 struct ehea_port *port = netdev_priv(dev);
2146 struct ehea_swqe *swqe;
2147 unsigned long flags;
2148 u32 lkey;
2149 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002150 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002151
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002152 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2153
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002154 if (!spin_trylock(&pr->xmit_lock))
2155 return NETDEV_TX_BUSY;
2156
2157 if (pr->queue_stopped) {
2158 spin_unlock(&pr->xmit_lock);
2159 return NETDEV_TX_BUSY;
2160 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002161
2162 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2163 memset(swqe, 0, SWQE_HEADER_SIZE);
2164 atomic_dec(&pr->swqe_avail);
2165
2166 if (skb->len <= SWQE3_MAX_IMM) {
2167 u32 sig_iv = port->sig_comp_iv;
2168 u32 swqe_num = pr->swqe_id_counter;
2169 ehea_xmit3(skb, dev, swqe);
2170 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2171 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2172 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2173 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2174 sig_iv);
2175 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2176 pr->swqe_ll_count = 0;
2177 } else
2178 pr->swqe_ll_count += 1;
2179 } else {
2180 swqe->wr_id =
2181 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2182 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002183 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2185 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2186
2187 pr->sq_skba.index++;
2188 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2189
2190 lkey = pr->send_mr.lkey;
2191 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002192 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002193 }
2194 pr->swqe_id_counter += 1;
2195
2196 if (port->vgrp && vlan_tx_tag_present(skb)) {
2197 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2198 swqe->vlan_tag = vlan_tx_tag_get(skb);
2199 }
2200
2201 if (netif_msg_tx_queued(port)) {
2202 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002203 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002204 }
2205
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002206 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2207 netif_stop_queue(dev);
2208 swqe->tx_control |= EHEA_SWQE_PURGE;
2209 }
Thomas Klein44c82152007-07-11 16:32:00 +02002210
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002211 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002212 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002213
2214 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2215 spin_lock_irqsave(&pr->netif_queue, flags);
2216 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002217 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002218 netif_stop_queue(dev);
2219 pr->queue_stopped = 1;
2220 }
2221 spin_unlock_irqrestore(&pr->netif_queue, flags);
2222 }
2223 dev->trans_start = jiffies;
2224 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002225
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002226 return NETDEV_TX_OK;
2227}
2228
2229static void ehea_vlan_rx_register(struct net_device *dev,
2230 struct vlan_group *grp)
2231{
2232 struct ehea_port *port = netdev_priv(dev);
2233 struct ehea_adapter *adapter = port->adapter;
2234 struct hcp_ehea_port_cb1 *cb1;
2235 u64 hret;
2236
2237 port->vgrp = grp;
2238
Thomas Klein3faf2692009-01-21 14:45:33 -08002239 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002240 if (!cb1) {
2241 ehea_error("no mem for cb1");
2242 goto out;
2243 }
2244
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002245 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2246 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2247 if (hret != H_SUCCESS)
2248 ehea_error("modify_ehea_port failed");
2249
Thomas Klein3faf2692009-01-21 14:45:33 -08002250 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002251out:
2252 return;
2253}
2254
2255static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2256{
2257 struct ehea_port *port = netdev_priv(dev);
2258 struct ehea_adapter *adapter = port->adapter;
2259 struct hcp_ehea_port_cb1 *cb1;
2260 int index;
2261 u64 hret;
2262
Thomas Klein3faf2692009-01-21 14:45:33 -08002263 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002264 if (!cb1) {
2265 ehea_error("no mem for cb1");
2266 goto out;
2267 }
2268
2269 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2270 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2271 if (hret != H_SUCCESS) {
2272 ehea_error("query_ehea_port failed");
2273 goto out;
2274 }
2275
2276 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002277 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002278
2279 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2280 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2281 if (hret != H_SUCCESS)
2282 ehea_error("modify_ehea_port failed");
2283out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002284 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285 return;
2286}
2287
2288static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2289{
2290 struct ehea_port *port = netdev_priv(dev);
2291 struct ehea_adapter *adapter = port->adapter;
2292 struct hcp_ehea_port_cb1 *cb1;
2293 int index;
2294 u64 hret;
2295
Dan Aloni5c15bde2007-03-02 20:44:51 -08002296 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002297
Thomas Klein3faf2692009-01-21 14:45:33 -08002298 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002299 if (!cb1) {
2300 ehea_error("no mem for cb1");
2301 goto out;
2302 }
2303
2304 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2305 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2306 if (hret != H_SUCCESS) {
2307 ehea_error("query_ehea_port failed");
2308 goto out;
2309 }
2310
2311 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002312 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002313
2314 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2315 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2316 if (hret != H_SUCCESS)
2317 ehea_error("modify_ehea_port failed");
2318out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002319 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002320 return;
2321}
2322
2323int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2324{
2325 int ret = -EIO;
2326 u64 hret;
2327 u16 dummy16 = 0;
2328 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002329 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002330
Thomas Klein3faf2692009-01-21 14:45:33 -08002331 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002332 if (!cb0) {
2333 ret = -ENOMEM;
2334 goto out;
2335 }
2336
2337 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2338 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2339 if (hret != H_SUCCESS) {
2340 ehea_error("query_ehea_qp failed (1)");
2341 goto out;
2342 }
2343
2344 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2345 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2346 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2347 &dummy64, &dummy64, &dummy16, &dummy16);
2348 if (hret != H_SUCCESS) {
2349 ehea_error("modify_ehea_qp failed (1)");
2350 goto out;
2351 }
2352
2353 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2354 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2355 if (hret != H_SUCCESS) {
2356 ehea_error("query_ehea_qp failed (2)");
2357 goto out;
2358 }
2359
2360 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2361 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2362 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2363 &dummy64, &dummy64, &dummy16, &dummy16);
2364 if (hret != H_SUCCESS) {
2365 ehea_error("modify_ehea_qp failed (2)");
2366 goto out;
2367 }
2368
2369 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2370 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2371 if (hret != H_SUCCESS) {
2372 ehea_error("query_ehea_qp failed (3)");
2373 goto out;
2374 }
2375
2376 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2377 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2378 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2379 &dummy64, &dummy64, &dummy16, &dummy16);
2380 if (hret != H_SUCCESS) {
2381 ehea_error("modify_ehea_qp failed (3)");
2382 goto out;
2383 }
2384
2385 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2386 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2387 if (hret != H_SUCCESS) {
2388 ehea_error("query_ehea_qp failed (4)");
2389 goto out;
2390 }
2391
2392 ret = 0;
2393out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002394 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002395 return ret;
2396}
2397
2398static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2399 int add_tx_qps)
2400{
2401 int ret, i;
2402 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2403 enum ehea_eq_type eq_type = EHEA_EQ;
2404
2405 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2406 EHEA_MAX_ENTRIES_EQ, 1);
2407 if (!port->qp_eq) {
2408 ret = -EINVAL;
2409 ehea_error("ehea_create_eq failed (qp_eq)");
2410 goto out_kill_eq;
2411 }
2412
2413 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002414 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002415 pr_cfg.max_entries_sq = sq_entries;
2416 pr_cfg.max_entries_rq1 = rq1_entries;
2417 pr_cfg.max_entries_rq2 = rq2_entries;
2418 pr_cfg.max_entries_rq3 = rq3_entries;
2419
2420 pr_cfg_small_rx.max_entries_rcq = 1;
2421 pr_cfg_small_rx.max_entries_scq = sq_entries;
2422 pr_cfg_small_rx.max_entries_sq = sq_entries;
2423 pr_cfg_small_rx.max_entries_rq1 = 1;
2424 pr_cfg_small_rx.max_entries_rq2 = 1;
2425 pr_cfg_small_rx.max_entries_rq3 = 1;
2426
2427 for (i = 0; i < def_qps; i++) {
2428 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2429 if (ret)
2430 goto out_clean_pr;
2431 }
2432 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2433 ret = ehea_init_port_res(port, &port->port_res[i],
2434 &pr_cfg_small_rx, i);
2435 if (ret)
2436 goto out_clean_pr;
2437 }
2438
2439 return 0;
2440
2441out_clean_pr:
2442 while (--i >= 0)
2443 ehea_clean_portres(port, &port->port_res[i]);
2444
2445out_kill_eq:
2446 ehea_destroy_eq(port->qp_eq);
2447 return ret;
2448}
2449
2450static int ehea_clean_all_portres(struct ehea_port *port)
2451{
2452 int ret = 0;
2453 int i;
2454
Doug Maxey508d2b52008-01-31 20:20:49 -06002455 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002456 ret |= ehea_clean_portres(port, &port->port_res[i]);
2457
2458 ret |= ehea_destroy_eq(port->qp_eq);
2459
2460 return ret;
2461}
2462
Thomas Klein35cf2e22007-08-06 13:55:14 +02002463static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002464{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002465 if (adapter->active_ports)
2466 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002467
2468 ehea_rem_mr(&adapter->mr);
2469}
2470
Thomas Klein35cf2e22007-08-06 13:55:14 +02002471static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002472{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002473 if (adapter->active_ports)
2474 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002475
2476 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2477}
2478
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002479static int ehea_up(struct net_device *dev)
2480{
2481 int ret, i;
2482 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002483
2484 if (port->state == EHEA_PORT_UP)
2485 return 0;
2486
2487 ret = ehea_port_res_setup(port, port->num_def_qps,
2488 port->num_add_tx_qps);
2489 if (ret) {
2490 ehea_error("port_res_failed");
2491 goto out;
2492 }
2493
2494 /* Set default QP for this port */
2495 ret = ehea_configure_port(port);
2496 if (ret) {
2497 ehea_error("ehea_configure_port failed. ret:%d", ret);
2498 goto out_clean_pr;
2499 }
2500
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002501 ret = ehea_reg_interrupts(dev);
2502 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002503 ehea_error("reg_interrupts failed. ret:%d", ret);
2504 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002505 }
2506
Doug Maxey508d2b52008-01-31 20:20:49 -06002507 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002508 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2509 if (ret) {
2510 ehea_error("activate_qp failed");
2511 goto out_free_irqs;
2512 }
2513 }
2514
Doug Maxey508d2b52008-01-31 20:20:49 -06002515 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002516 ret = ehea_fill_port_res(&port->port_res[i]);
2517 if (ret) {
2518 ehea_error("out_free_irqs");
2519 goto out_free_irqs;
2520 }
2521 }
2522
Thomas Klein21eee2d2008-02-13 16:18:33 +01002523 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2524 if (ret) {
2525 ret = -EIO;
2526 goto out_free_irqs;
2527 }
2528
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002529 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002530
2531 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002532 goto out;
2533
2534out_free_irqs:
2535 ehea_free_interrupts(dev);
2536
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002537out_clean_pr:
2538 ehea_clean_all_portres(port);
2539out:
Thomas Klein44c82152007-07-11 16:32:00 +02002540 if (ret)
2541 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2542
Thomas Klein21eee2d2008-02-13 16:18:33 +01002543 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002544 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002545
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002546 return ret;
2547}
2548
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002549static void port_napi_disable(struct ehea_port *port)
2550{
2551 int i;
2552
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002553 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002554 napi_disable(&port->port_res[i].napi);
2555}
2556
2557static void port_napi_enable(struct ehea_port *port)
2558{
2559 int i;
2560
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002561 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002562 napi_enable(&port->port_res[i].napi);
2563}
2564
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002565static int ehea_open(struct net_device *dev)
2566{
2567 int ret;
2568 struct ehea_port *port = netdev_priv(dev);
2569
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002570 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002571
2572 if (netif_msg_ifup(port))
2573 ehea_info("enabling port %s", dev->name);
2574
2575 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002576 if (!ret) {
2577 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002578 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002579 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002580
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002581 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002582
2583 return ret;
2584}
2585
2586static int ehea_down(struct net_device *dev)
2587{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002588 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002589 struct ehea_port *port = netdev_priv(dev);
2590
2591 if (port->state == EHEA_PORT_DOWN)
2592 return 0;
2593
2594 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002595 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2596
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002597 ehea_free_interrupts(dev);
2598
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002599 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002600
Thomas Klein21eee2d2008-02-13 16:18:33 +01002601 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002602
Thomas Klein44c82152007-07-11 16:32:00 +02002603 ret = ehea_clean_all_portres(port);
2604 if (ret)
2605 ehea_info("Failed freeing resources for %s. ret=%i",
2606 dev->name, ret);
2607
Thomas Klein21eee2d2008-02-13 16:18:33 +01002608 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002609
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002610 return ret;
2611}
2612
2613static int ehea_stop(struct net_device *dev)
2614{
2615 int ret;
2616 struct ehea_port *port = netdev_priv(dev);
2617
2618 if (netif_msg_ifdown(port))
2619 ehea_info("disabling port %s", dev->name);
2620
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002621 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002622 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002623 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002624 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002625 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002626 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002627 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002628 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002629 return ret;
2630}
2631
Andrew Morton22559c52008-04-18 13:50:39 -07002632static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002633{
2634 struct ehea_qp qp = *orig_qp;
2635 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2636 struct ehea_swqe *swqe;
2637 int wqe_index;
2638 int i;
2639
2640 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2641 swqe = ehea_get_swqe(&qp, &wqe_index);
2642 swqe->tx_control |= EHEA_SWQE_PURGE;
2643 }
2644}
2645
Andrew Morton22559c52008-04-18 13:50:39 -07002646static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002647{
2648 int i;
2649
2650 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2651 struct ehea_port_res *pr = &port->port_res[i];
2652 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2653 int k = 0;
2654 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2655 msleep(5);
2656 if (++k == 20)
2657 break;
2658 }
2659 }
2660}
2661
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002662int ehea_stop_qps(struct net_device *dev)
2663{
2664 struct ehea_port *port = netdev_priv(dev);
2665 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002666 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002667 int ret = -EIO;
2668 int dret;
2669 int i;
2670 u64 hret;
2671 u64 dummy64 = 0;
2672 u16 dummy16 = 0;
2673
Thomas Klein3faf2692009-01-21 14:45:33 -08002674 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002675 if (!cb0) {
2676 ret = -ENOMEM;
2677 goto out;
2678 }
2679
2680 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2681 struct ehea_port_res *pr = &port->port_res[i];
2682 struct ehea_qp *qp = pr->qp;
2683
2684 /* Purge send queue */
2685 ehea_purge_sq(qp);
2686
2687 /* Disable queue pair */
2688 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2689 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2690 cb0);
2691 if (hret != H_SUCCESS) {
2692 ehea_error("query_ehea_qp failed (1)");
2693 goto out;
2694 }
2695
2696 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2697 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2698
2699 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2700 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2701 1), cb0, &dummy64,
2702 &dummy64, &dummy16, &dummy16);
2703 if (hret != H_SUCCESS) {
2704 ehea_error("modify_ehea_qp failed (1)");
2705 goto out;
2706 }
2707
2708 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2709 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2710 cb0);
2711 if (hret != H_SUCCESS) {
2712 ehea_error("query_ehea_qp failed (2)");
2713 goto out;
2714 }
2715
2716 /* deregister shared memory regions */
2717 dret = ehea_rem_smrs(pr);
2718 if (dret) {
2719 ehea_error("unreg shared memory region failed");
2720 goto out;
2721 }
2722 }
2723
2724 ret = 0;
2725out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002726 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002727
2728 return ret;
2729}
2730
Doug Maxey508d2b52008-01-31 20:20:49 -06002731void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002732{
2733 struct ehea_qp qp = *orig_qp;
2734 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2735 struct ehea_rwqe *rwqe;
2736 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2737 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2738 struct sk_buff *skb;
2739 u32 lkey = pr->recv_mr.lkey;
2740
2741
2742 int i;
2743 int index;
2744
2745 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2746 rwqe = ehea_get_next_rwqe(&qp, 2);
2747 rwqe->sg_list[0].l_key = lkey;
2748 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2749 skb = skba_rq2[index];
2750 if (skb)
2751 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2752 }
2753
2754 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2755 rwqe = ehea_get_next_rwqe(&qp, 3);
2756 rwqe->sg_list[0].l_key = lkey;
2757 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2758 skb = skba_rq3[index];
2759 if (skb)
2760 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2761 }
2762}
2763
2764int ehea_restart_qps(struct net_device *dev)
2765{
2766 struct ehea_port *port = netdev_priv(dev);
2767 struct ehea_adapter *adapter = port->adapter;
2768 int ret = 0;
2769 int i;
2770
Doug Maxey508d2b52008-01-31 20:20:49 -06002771 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002772 u64 hret;
2773 u64 dummy64 = 0;
2774 u16 dummy16 = 0;
2775
Thomas Klein3faf2692009-01-21 14:45:33 -08002776 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002777 if (!cb0) {
2778 ret = -ENOMEM;
2779 goto out;
2780 }
2781
2782 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2783 struct ehea_port_res *pr = &port->port_res[i];
2784 struct ehea_qp *qp = pr->qp;
2785
2786 ret = ehea_gen_smrs(pr);
2787 if (ret) {
2788 ehea_error("creation of shared memory regions failed");
2789 goto out;
2790 }
2791
2792 ehea_update_rqs(qp, pr);
2793
2794 /* Enable queue pair */
2795 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2796 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2797 cb0);
2798 if (hret != H_SUCCESS) {
2799 ehea_error("query_ehea_qp failed (1)");
2800 goto out;
2801 }
2802
2803 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2804 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2805
2806 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2807 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2808 1), cb0, &dummy64,
2809 &dummy64, &dummy16, &dummy16);
2810 if (hret != H_SUCCESS) {
2811 ehea_error("modify_ehea_qp failed (1)");
2812 goto out;
2813 }
2814
2815 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2816 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2817 cb0);
2818 if (hret != H_SUCCESS) {
2819 ehea_error("query_ehea_qp failed (2)");
2820 goto out;
2821 }
2822
2823 /* refill entire queue */
2824 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2825 ehea_refill_rq2(pr, 0);
2826 ehea_refill_rq3(pr, 0);
2827 }
2828out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002829 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002830
2831 return ret;
2832}
2833
David Howellsc4028952006-11-22 14:57:56 +00002834static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002835{
2836 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002837 struct ehea_port *port =
2838 container_of(work, struct ehea_port, reset_task);
2839 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002840
2841 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002842 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002843 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002844
2845 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002846
Thomas Klein44c82152007-07-11 16:32:00 +02002847 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002848
2849 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002850 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002851 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002852
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002853 ehea_set_multicast_list(dev);
2854
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002855 if (netif_msg_timer(port))
2856 ehea_info("Device %s resetted successfully", dev->name);
2857
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002858 port_napi_enable(port);
2859
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002860 netif_wake_queue(dev);
2861out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002862 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002863 return;
2864}
2865
Thomas Klein44c82152007-07-11 16:32:00 +02002866static void ehea_rereg_mrs(struct work_struct *work)
2867{
2868 int ret, i;
2869 struct ehea_adapter *adapter;
2870
Daniel Walker06f89ed2008-03-28 14:41:26 -07002871 mutex_lock(&dlpar_mem_lock);
Hannes Heringd4f12da2008-10-16 11:36:42 +02002872 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002873
2874 list_for_each_entry(adapter, &adapter_list, list)
2875 if (adapter->active_ports) {
2876 /* Shutdown all ports */
2877 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2878 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002879 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002880
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002881 if (!port)
2882 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002883
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002884 dev = port->netdev;
2885
2886 if (dev->flags & IFF_UP) {
2887 mutex_lock(&port->port_lock);
2888 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002889 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002890 ret = ehea_stop_qps(dev);
2891 if (ret) {
2892 mutex_unlock(&port->port_lock);
2893 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002894 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002895 port_napi_disable(port);
2896 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002897 }
2898 }
2899
2900 /* Unregister old memory region */
2901 ret = ehea_rem_mr(&adapter->mr);
2902 if (ret) {
2903 ehea_error("unregister MR failed - driver"
2904 " inoperable!");
2905 goto out;
2906 }
2907 }
2908
Thomas Klein44c82152007-07-11 16:32:00 +02002909 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2910
2911 list_for_each_entry(adapter, &adapter_list, list)
2912 if (adapter->active_ports) {
2913 /* Register new memory region */
2914 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2915 if (ret) {
2916 ehea_error("register MR failed - driver"
2917 " inoperable!");
2918 goto out;
2919 }
2920
2921 /* Restart all ports */
2922 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2923 struct ehea_port *port = adapter->port[i];
2924
2925 if (port) {
2926 struct net_device *dev = port->netdev;
2927
2928 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002929 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002930 port_napi_enable(port);
2931 ret = ehea_restart_qps(dev);
2932 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002933 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002934 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002935 }
2936 }
2937 }
2938 }
Julia Lawall68905eb2008-07-21 09:57:26 +02002939 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002940out:
Julia Lawall68905eb2008-07-21 09:57:26 +02002941 mutex_unlock(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002942 return;
2943}
2944
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002945static void ehea_tx_watchdog(struct net_device *dev)
2946{
2947 struct ehea_port *port = netdev_priv(dev);
2948
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002949 if (netif_carrier_ok(dev) &&
2950 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002951 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002952}
2953
2954int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2955{
2956 struct hcp_query_ehea *cb;
2957 u64 hret;
2958 int ret;
2959
Thomas Klein3faf2692009-01-21 14:45:33 -08002960 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002961 if (!cb) {
2962 ret = -ENOMEM;
2963 goto out;
2964 }
2965
2966 hret = ehea_h_query_ehea(adapter->handle, cb);
2967
2968 if (hret != H_SUCCESS) {
2969 ret = -EIO;
2970 goto out_herr;
2971 }
2972
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002973 adapter->max_mc_mac = cb->max_mc_mac - 1;
2974 ret = 0;
2975
2976out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002977 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002978out:
2979 return ret;
2980}
2981
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002982int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2983{
2984 struct hcp_ehea_port_cb4 *cb4;
2985 u64 hret;
2986 int ret = 0;
2987
2988 *jumbo = 0;
2989
2990 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002991 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002992 if (!cb4) {
2993 ehea_error("no mem for cb4");
2994 ret = -ENOMEM;
2995 goto out;
2996 } else {
2997 hret = ehea_h_query_ehea_port(port->adapter->handle,
2998 port->logical_port_id,
2999 H_PORT_CB4,
3000 H_PORT_CB4_JUMBO, cb4);
3001 if (hret == H_SUCCESS) {
3002 if (cb4->jumbo_frame)
3003 *jumbo = 1;
3004 else {
3005 cb4->jumbo_frame = 1;
3006 hret = ehea_h_modify_ehea_port(port->adapter->
3007 handle,
3008 port->
3009 logical_port_id,
3010 H_PORT_CB4,
3011 H_PORT_CB4_JUMBO,
3012 cb4);
3013 if (hret == H_SUCCESS)
3014 *jumbo = 1;
3015 }
3016 } else
3017 ret = -EINVAL;
3018
Thomas Klein3faf2692009-01-21 14:45:33 -08003019 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003020 }
3021out:
3022 return ret;
3023}
3024
3025static ssize_t ehea_show_port_id(struct device *dev,
3026 struct device_attribute *attr, char *buf)
3027{
3028 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003029 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003030}
3031
3032static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3033 NULL);
3034
3035static void __devinit logical_port_release(struct device *dev)
3036{
3037 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3038 of_node_put(port->ofdev.node);
3039}
3040
3041static struct device *ehea_register_port(struct ehea_port *port,
3042 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003043{
3044 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003045
3046 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003047 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003048 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003049
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003050 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003051 port->ofdev.dev.release = logical_port_release;
3052
3053 ret = of_device_register(&port->ofdev);
3054 if (ret) {
3055 ehea_error("failed to register device. ret=%d", ret);
3056 goto out;
3057 }
3058
3059 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003060 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003061 ehea_error("failed to register attributes, ret=%d", ret);
3062 goto out_unreg_of_dev;
3063 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003064
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003065 return &port->ofdev.dev;
3066
3067out_unreg_of_dev:
3068 of_device_unregister(&port->ofdev);
3069out:
3070 return NULL;
3071}
3072
3073static void ehea_unregister_port(struct ehea_port *port)
3074{
3075 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3076 of_device_unregister(&port->ofdev);
3077}
3078
Thomas Klein086c1b22009-01-21 14:43:59 -08003079static const struct net_device_ops ehea_netdev_ops = {
3080 .ndo_open = ehea_open,
3081 .ndo_stop = ehea_stop,
3082 .ndo_start_xmit = ehea_start_xmit,
3083#ifdef CONFIG_NET_POLL_CONTROLLER
3084 .ndo_poll_controller = ehea_netpoll,
3085#endif
3086 .ndo_get_stats = ehea_get_stats,
3087 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003088 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003089 .ndo_set_multicast_list = ehea_set_multicast_list,
3090 .ndo_change_mtu = ehea_change_mtu,
3091 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3092 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003093 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3094 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003095};
3096
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003097struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3098 u32 logical_port_id,
3099 struct device_node *dn)
3100{
3101 int ret;
3102 struct net_device *dev;
3103 struct ehea_port *port;
3104 struct device *port_dev;
3105 int jumbo;
3106
3107 /* allocate memory for the port structures */
3108 dev = alloc_etherdev(sizeof(struct ehea_port));
3109
3110 if (!dev) {
3111 ehea_error("no mem for net_device");
3112 ret = -ENOMEM;
3113 goto out_err;
3114 }
3115
3116 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003117
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003118 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003119 port->state = EHEA_PORT_DOWN;
3120 port->sig_comp_iv = sq_entries / 10;
3121
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003122 port->adapter = adapter;
3123 port->netdev = dev;
3124 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003125
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003127
3128 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3129 if (!port->mc_list) {
3130 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003132 }
3133
3134 INIT_LIST_HEAD(&port->mc_list->list);
3135
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003136 ret = ehea_sense_port_attr(port);
3137 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003138 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003139
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003140 port_dev = ehea_register_port(port, dn);
3141 if (!port_dev)
3142 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003143
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003144 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003145
3146 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003147 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3148
Thomas Klein086c1b22009-01-21 14:43:59 -08003149 dev->netdev_ops = &ehea_netdev_ops;
3150 ehea_set_ethtool_ops(dev);
3151
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003152 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003153 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003154 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3155 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003156 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3157
David Howellsc4028952006-11-22 14:57:56 +00003158 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003159
3160 ret = register_netdev(dev);
3161 if (ret) {
3162 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003163 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003164 }
3165
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003166 port->lro_max_aggr = lro_max_aggr;
3167
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003169 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003170 ehea_error("failed determining jumbo frame status for %s",
3171 port->netdev->name);
3172
Thomas Klein9c750b72007-01-29 18:44:01 +01003173 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3174 jumbo == 1 ? "en" : "dis");
3175
Thomas Klein44c82152007-07-11 16:32:00 +02003176 adapter->active_ports++;
3177
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003178 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003179
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003180out_unreg_port:
3181 ehea_unregister_port(port);
3182
3183out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003184 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003185
3186out_free_ethdev:
3187 free_netdev(dev);
3188
3189out_err:
3190 ehea_error("setting up logical port with id=%d failed, ret=%d",
3191 logical_port_id, ret);
3192 return NULL;
3193}
3194
3195static void ehea_shutdown_single_port(struct ehea_port *port)
3196{
Brian King7fb1c2a2008-05-14 09:48:25 -05003197 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003198 unregister_netdev(port->netdev);
3199 ehea_unregister_port(port);
3200 kfree(port->mc_list);
3201 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003202 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003203}
3204
3205static int ehea_setup_ports(struct ehea_adapter *adapter)
3206{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003207 struct device_node *lhea_dn;
3208 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003209
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003210 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003211 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003212
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003213 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003214 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003215
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003216 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003217 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003218 if (!dn_log_port_id) {
3219 ehea_error("bad device node: eth_dn name=%s",
3220 eth_dn->full_name);
3221 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003222 }
3223
Thomas Klein1211bb62007-04-26 11:56:43 +02003224 if (ehea_add_adapter_mr(adapter)) {
3225 ehea_error("creating MR failed");
3226 of_node_put(eth_dn);
3227 return -EIO;
3228 }
3229
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230 adapter->port[i] = ehea_setup_single_port(adapter,
3231 *dn_log_port_id,
3232 eth_dn);
3233 if (adapter->port[i])
3234 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003235 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003236 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003237 else
3238 ehea_remove_adapter_mr(adapter);
3239
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003240 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003241 };
Thomas Klein1211bb62007-04-26 11:56:43 +02003242 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003243}
3244
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003245static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3246 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003247{
3248 struct device_node *lhea_dn;
3249 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003250 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003252 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003253 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003254
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003255 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003256 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003257 if (dn_log_port_id)
3258 if (*dn_log_port_id == logical_port_id)
3259 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003260 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003261
3262 return NULL;
3263}
3264
3265static ssize_t ehea_probe_port(struct device *dev,
3266 struct device_attribute *attr,
3267 const char *buf, size_t count)
3268{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003269 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003270 struct ehea_port *port;
3271 struct device_node *eth_dn = NULL;
3272 int i;
3273
3274 u32 logical_port_id;
3275
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003276 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003277
3278 port = ehea_get_port(adapter, logical_port_id);
3279
3280 if (port) {
3281 ehea_info("adding port with logical port id=%d failed. port "
3282 "already configured as %s.", logical_port_id,
3283 port->netdev->name);
3284 return -EINVAL;
3285 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003286
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003287 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3288
3289 if (!eth_dn) {
3290 ehea_info("no logical port with id %d found", logical_port_id);
3291 return -EINVAL;
3292 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003293
Thomas Klein1211bb62007-04-26 11:56:43 +02003294 if (ehea_add_adapter_mr(adapter)) {
3295 ehea_error("creating MR failed");
3296 return -EIO;
3297 }
3298
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003299 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3300
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003301 of_node_put(eth_dn);
3302
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003303 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003304 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003305 if (!adapter->port[i]) {
3306 adapter->port[i] = port;
3307 break;
3308 }
3309
3310 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3311 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003312 } else {
3313 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003314 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003315 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003316
3317 return (ssize_t) count;
3318}
3319
3320static ssize_t ehea_remove_port(struct device *dev,
3321 struct device_attribute *attr,
3322 const char *buf, size_t count)
3323{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003324 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325 struct ehea_port *port;
3326 int i;
3327 u32 logical_port_id;
3328
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003329 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003330
3331 port = ehea_get_port(adapter, logical_port_id);
3332
3333 if (port) {
3334 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3335 logical_port_id);
3336
3337 ehea_shutdown_single_port(port);
3338
Doug Maxey508d2b52008-01-31 20:20:49 -06003339 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003340 if (adapter->port[i] == port) {
3341 adapter->port[i] = NULL;
3342 break;
3343 }
3344 } else {
3345 ehea_error("removing port with logical port id=%d failed. port "
3346 "not configured.", logical_port_id);
3347 return -EINVAL;
3348 }
3349
Thomas Klein1211bb62007-04-26 11:56:43 +02003350 ehea_remove_adapter_mr(adapter);
3351
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003352 return (ssize_t) count;
3353}
3354
3355static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3356static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3357
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003358int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003359{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003360 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003361 if (ret)
3362 goto out;
3363
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003364 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003366 return ret;
3367}
3368
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003369void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003370{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003371 device_remove_file(&dev->dev, &dev_attr_probe_port);
3372 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003373}
3374
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003375static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003376 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003377{
3378 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003379 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003380 int ret;
3381
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003382 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003383 ehea_error("Invalid ibmebus device probed");
3384 return -EINVAL;
3385 }
3386
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003387 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3388 if (!adapter) {
3389 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003390 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003391 goto out;
3392 }
3393
Thomas Klein44c82152007-07-11 16:32:00 +02003394 list_add(&adapter->list, &adapter_list);
3395
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003396 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003397
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003398 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003399 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003400 if (adapter_handle)
3401 adapter->handle = *adapter_handle;
3402
3403 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003404 dev_err(&dev->dev, "failed getting handle for adapter"
3405 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003406 ret = -ENODEV;
3407 goto out_free_ad;
3408 }
3409
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003410 adapter->pd = EHEA_PD_ID;
3411
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003412 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003413
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003414
3415 /* initialize adapter and ports */
3416 /* get adapter properties */
3417 ret = ehea_sense_adapter_attr(adapter);
3418 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003419 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003420 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003421 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003422
3423 adapter->neq = ehea_create_eq(adapter,
3424 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3425 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003426 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003427 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003428 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003429 }
3430
3431 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3432 (unsigned long)adapter);
3433
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003434 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003435 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003436 "ehea_neq", adapter);
3437 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003438 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003439 goto out_kill_eq;
3440 }
3441
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003442 ret = ehea_create_device_sysfs(dev);
3443 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003444 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003445
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003446 ret = ehea_setup_ports(adapter);
3447 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003448 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003449 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003450 }
3451
3452 ret = 0;
3453 goto out;
3454
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003455out_rem_dev_sysfs:
3456 ehea_remove_device_sysfs(dev);
3457
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003458out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003459 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003460
3461out_kill_eq:
3462 ehea_destroy_eq(adapter->neq);
3463
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003464out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003465 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003466 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003468out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003469 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003470
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003471 return ret;
3472}
3473
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003474static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003475{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003476 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003477 int i;
3478
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003479 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003480 if (adapter->port[i]) {
3481 ehea_shutdown_single_port(adapter->port[i]);
3482 adapter->port[i] = NULL;
3483 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003484
3485 ehea_remove_device_sysfs(dev);
3486
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003487 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003488
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003489 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003490 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003491
3492 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003493 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003494 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003495 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003496
Thomas Klein21eee2d2008-02-13 16:18:33 +01003497 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003498
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003499 return 0;
3500}
3501
Thomas Klein21eee2d2008-02-13 16:18:33 +01003502void ehea_crash_handler(void)
3503{
3504 int i;
3505
3506 if (ehea_fw_handles.arr)
3507 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3508 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3509 ehea_fw_handles.arr[i].fwh,
3510 FORCE_FREE);
3511
3512 if (ehea_bcmc_regs.arr)
3513 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3514 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3515 ehea_bcmc_regs.arr[i].port_id,
3516 ehea_bcmc_regs.arr[i].reg_type,
3517 ehea_bcmc_regs.arr[i].macaddr,
3518 0, H_DEREG_BCMC);
3519}
3520
Hannes Hering48cfb142008-05-07 14:43:36 +02003521static int ehea_mem_notifier(struct notifier_block *nb,
3522 unsigned long action, void *data)
3523{
Hannes Heringd4f12da2008-10-16 11:36:42 +02003524 struct memory_notify *arg = data;
Hannes Hering48cfb142008-05-07 14:43:36 +02003525 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003526 case MEM_CANCEL_OFFLINE:
3527 ehea_info("memory offlining canceled");
3528 /* Readd canceled memory block */
3529 case MEM_ONLINE:
3530 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003531 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003532 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
3533 return NOTIFY_BAD;
3534 ehea_rereg_mrs(NULL);
3535 break;
3536 case MEM_GOING_OFFLINE:
3537 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003538 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003539 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
3540 return NOTIFY_BAD;
Hannes Hering48cfb142008-05-07 14:43:36 +02003541 ehea_rereg_mrs(NULL);
3542 break;
3543 default:
3544 break;
3545 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003546
3547 ehea_update_firmware_handles();
3548
Hannes Hering48cfb142008-05-07 14:43:36 +02003549 return NOTIFY_OK;
3550}
3551
3552static struct notifier_block ehea_mem_nb = {
3553 .notifier_call = ehea_mem_notifier,
3554};
3555
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003556static int ehea_reboot_notifier(struct notifier_block *nb,
3557 unsigned long action, void *unused)
3558{
3559 if (action == SYS_RESTART) {
3560 ehea_info("Reboot: freeing all eHEA resources");
3561 ibmebus_unregister_driver(&ehea_driver);
3562 }
3563 return NOTIFY_DONE;
3564}
3565
3566static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003567 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003568};
3569
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570static int check_module_parm(void)
3571{
3572 int ret = 0;
3573
3574 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3575 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3576 ehea_info("Bad parameter: rq1_entries");
3577 ret = -EINVAL;
3578 }
3579 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3580 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3581 ehea_info("Bad parameter: rq2_entries");
3582 ret = -EINVAL;
3583 }
3584 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3585 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3586 ehea_info("Bad parameter: rq3_entries");
3587 ret = -EINVAL;
3588 }
3589 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3590 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3591 ehea_info("Bad parameter: sq_entries");
3592 ret = -EINVAL;
3593 }
3594
3595 return ret;
3596}
3597
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003598static ssize_t ehea_show_capabilities(struct device_driver *drv,
3599 char *buf)
3600{
3601 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3602}
3603
3604static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3605 ehea_show_capabilities, NULL);
3606
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003607int __init ehea_module_init(void)
3608{
3609 int ret;
3610
3611 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3612 DRV_VERSION);
3613
Thomas Klein44c82152007-07-11 16:32:00 +02003614
3615 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003616 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3617 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3618
Daniel Walker9f71a562008-03-28 14:41:26 -07003619 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003620 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003621
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003622 ret = check_module_parm();
3623 if (ret)
3624 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003625
3626 ret = ehea_create_busmap();
3627 if (ret)
3628 goto out;
3629
Thomas Klein21eee2d2008-02-13 16:18:33 +01003630 ret = register_reboot_notifier(&ehea_reboot_nb);
3631 if (ret)
3632 ehea_info("failed registering reboot notifier");
3633
Hannes Hering48cfb142008-05-07 14:43:36 +02003634 ret = register_memory_notifier(&ehea_mem_nb);
3635 if (ret)
3636 ehea_info("failed registering memory remove notifier");
3637
Thomas Klein21eee2d2008-02-13 16:18:33 +01003638 ret = crash_shutdown_register(&ehea_crash_handler);
3639 if (ret)
3640 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003642 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003643 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003644 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003645 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003646 }
3647
3648 ret = driver_create_file(&ehea_driver.driver,
3649 &driver_attr_capabilities);
3650 if (ret) {
3651 ehea_error("failed to register capabilities attribute, ret=%d",
3652 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003653 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003654 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003655
Thomas Klein21eee2d2008-02-13 16:18:33 +01003656 return ret;
3657
3658out3:
3659 ibmebus_unregister_driver(&ehea_driver);
3660out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003661 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003662 unregister_reboot_notifier(&ehea_reboot_nb);
3663 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003664out:
3665 return ret;
3666}
3667
3668static void __exit ehea_module_exit(void)
3669{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003670 int ret;
3671
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003672 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003673 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003674 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003675 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003676 ret = crash_shutdown_unregister(&ehea_crash_handler);
3677 if (ret)
3678 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003679 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003680 kfree(ehea_fw_handles.arr);
3681 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003682 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003683}
3684
3685module_init(ehea_module_init);
3686module_exit(ehea_module_exit);