blob: 3554414eb5e289287e3a9ab174320c7e9fa1bf30 [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
Joe Perches8c4877a2010-12-13 10:05:14 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020031#include <linux/in.h>
32#include <linux/ip.h>
33#include <linux/tcp.h>
34#include <linux/udp.h>
35#include <linux/if.h>
36#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020038#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020039#include <linux/notifier.h>
40#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020041#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010042#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070043#include <linux/mutex.h>
Linus Torvalds268bb0c2011-05-20 12:50:29 -070044#include <linux/prefetch.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020045
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020046#include <net/ip.h>
47
48#include "ehea.h"
49#include "ehea_qmr.h"
50#include "ehea_phyp.h"
51
52
53MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
55MODULE_DESCRIPTION("IBM eServer HEA Driver");
56MODULE_VERSION(DRV_VERSION);
57
58
59static int msg_level = -1;
60static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
61static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
62static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
63static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Anton Blanchardb9564462011-10-14 05:30:59 +000064static int use_mcs = 1;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066
67module_param(msg_level, int, 0);
68module_param(rq1_entries, int, 0);
69module_param(rq2_entries, int, 0);
70module_param(rq3_entries, int, 0);
71module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020072module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(use_mcs, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020074
75MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020076MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
81MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
84MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
87MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Anton Blanchardb9564462011-10-14 05:30:59 +000090MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
91 "Default = 1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020092
Doug Maxey508d2b52008-01-31 20:20:49 -060093static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +020094static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -080095static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -070096static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +010097struct ehea_fw_handle_array ehea_fw_handles;
98struct ehea_bcmc_reg_array ehea_bcmc_regs;
99
Thomas Kleind1dea382007-04-26 11:56:13 +0200100
Grant Likely2dc11582010-08-06 09:25:50 -0600101static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200102 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200103
Grant Likely2dc11582010-08-06 09:25:50 -0600104static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200105
106static struct of_device_id ehea_device_table[] = {
107 {
108 .name = "lhea",
109 .compatible = "IBM,lhea",
110 },
111 {},
112};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100113MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000115static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700116 .driver = {
117 .name = "ehea",
118 .owner = THIS_MODULE,
119 .of_match_table = ehea_device_table,
120 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200121 .probe = ehea_probe_adapter,
122 .remove = ehea_remove,
123};
124
Doug Maxey508d2b52008-01-31 20:20:49 -0600125void ehea_dump(void *adr, int len, char *msg)
126{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200127 int x;
128 unsigned char *deb = adr;
129 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800130 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
131 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 deb += 16;
133 }
134}
135
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100136void ehea_schedule_port_reset(struct ehea_port *port)
137{
138 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
139 schedule_work(&port->reset_task);
140}
141
Thomas Klein21eee2d2008-02-13 16:18:33 +0100142static void ehea_update_firmware_handles(void)
143{
144 struct ehea_fw_handle_entry *arr = NULL;
145 struct ehea_adapter *adapter;
146 int num_adapters = 0;
147 int num_ports = 0;
148 int num_portres = 0;
149 int i = 0;
150 int num_fw_handles, k, l;
151
152 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700153 mutex_lock(&ehea_fw_handles.lock);
154
Thomas Klein21eee2d2008-02-13 16:18:33 +0100155 list_for_each_entry(adapter, &adapter_list, list) {
156 num_adapters++;
157
158 for (k = 0; k < EHEA_MAX_PORTS; k++) {
159 struct ehea_port *port = adapter->port[k];
160
161 if (!port || (port->state != EHEA_PORT_UP))
162 continue;
163
164 num_ports++;
Anton Blanchard723f28e2011-10-14 05:31:01 +0000165 num_portres += port->num_def_qps;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100166 }
167 }
168
169 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
170 num_ports * EHEA_NUM_PORT_FW_HANDLES +
171 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
172
173 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000174 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100175 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700176 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100177 } else
178 goto out_update;
179
180 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700181 if (num_adapters == 0)
182 break;
183
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 for (k = 0; k < EHEA_MAX_PORTS; k++) {
185 struct ehea_port *port = adapter->port[k];
186
Joe Perches8e95a202009-12-03 07:58:21 +0000187 if (!port || (port->state != EHEA_PORT_UP) ||
188 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 continue;
190
Anton Blanchard723f28e2011-10-14 05:31:01 +0000191 for (l = 0; l < port->num_def_qps; l++) {
Thomas Klein21eee2d2008-02-13 16:18:33 +0100192 struct ehea_port_res *pr = &port->port_res[l];
193
194 arr[i].adh = adapter->handle;
195 arr[i++].fwh = pr->qp->fw_handle;
196 arr[i].adh = adapter->handle;
197 arr[i++].fwh = pr->send_cq->fw_handle;
198 arr[i].adh = adapter->handle;
199 arr[i++].fwh = pr->recv_cq->fw_handle;
200 arr[i].adh = adapter->handle;
201 arr[i++].fwh = pr->eq->fw_handle;
202 arr[i].adh = adapter->handle;
203 arr[i++].fwh = pr->send_mr.handle;
204 arr[i].adh = adapter->handle;
205 arr[i++].fwh = pr->recv_mr.handle;
206 }
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700209 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100210 }
211
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = adapter->neq->fw_handle;
214
215 if (adapter->mr.handle) {
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = adapter->mr.handle;
218 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700219 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100220 }
221
222out_update:
223 kfree(ehea_fw_handles.arr);
224 ehea_fw_handles.arr = arr;
225 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700226out:
227 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100228}
229
230static void ehea_update_bcmc_registrations(void)
231{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700232 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100233 struct ehea_bcmc_reg_entry *arr = NULL;
234 struct ehea_adapter *adapter;
235 struct ehea_mc_list *mc_entry;
236 int num_registrations = 0;
237 int i = 0;
238 int k;
239
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700240 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
241
Thomas Klein21eee2d2008-02-13 16:18:33 +0100242 /* Determine number of registrations */
243 list_for_each_entry(adapter, &adapter_list, list)
244 for (k = 0; k < EHEA_MAX_PORTS; k++) {
245 struct ehea_port *port = adapter->port[k];
246
247 if (!port || (port->state != EHEA_PORT_UP))
248 continue;
249
250 num_registrations += 2; /* Broadcast registrations */
251
252 list_for_each_entry(mc_entry, &port->mc_list->list,list)
253 num_registrations += 2;
254 }
255
256 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000257 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100258 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700259 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100260 } else
261 goto out_update;
262
263 list_for_each_entry(adapter, &adapter_list, list) {
264 for (k = 0; k < EHEA_MAX_PORTS; k++) {
265 struct ehea_port *port = adapter->port[k];
266
267 if (!port || (port->state != EHEA_PORT_UP))
268 continue;
269
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700270 if (num_registrations == 0)
271 goto out_update;
272
Thomas Klein21eee2d2008-02-13 16:18:33 +0100273 arr[i].adh = adapter->handle;
274 arr[i].port_id = port->logical_port_id;
275 arr[i].reg_type = EHEA_BCMC_BROADCAST |
276 EHEA_BCMC_UNTAGGED;
277 arr[i++].macaddr = port->mac_addr;
278
279 arr[i].adh = adapter->handle;
280 arr[i].port_id = port->logical_port_id;
281 arr[i].reg_type = EHEA_BCMC_BROADCAST |
282 EHEA_BCMC_VLANID_ALL;
283 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700284 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100285
286 list_for_each_entry(mc_entry,
287 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700288 if (num_registrations == 0)
289 goto out_update;
290
Thomas Klein21eee2d2008-02-13 16:18:33 +0100291 arr[i].adh = adapter->handle;
292 arr[i].port_id = port->logical_port_id;
293 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
294 EHEA_BCMC_MULTICAST |
295 EHEA_BCMC_UNTAGGED;
296 arr[i++].macaddr = mc_entry->macaddr;
297
298 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_VLANID_ALL;
303 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700304 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100305 }
306 }
307 }
308
309out_update:
310 kfree(ehea_bcmc_regs.arr);
311 ehea_bcmc_regs.arr = arr;
312 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700313out:
314 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100315}
316
Anton Blanchard239c5622011-10-14 05:31:09 +0000317static struct rtnl_link_stats64 *ehea_get_stats64(struct net_device *dev,
318 struct rtnl_link_stats64 *stats)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200319{
320 struct ehea_port *port = netdev_priv(dev);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000321 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200322 int i;
323
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000324 for (i = 0; i < port->num_def_qps; i++) {
325 rx_packets += port->port_res[i].rx_packets;
326 rx_bytes += port->port_res[i].rx_bytes;
327 }
328
Anton Blanchard723f28e2011-10-14 05:31:01 +0000329 for (i = 0; i < port->num_def_qps; i++) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000330 tx_packets += port->port_res[i].tx_packets;
331 tx_bytes += port->port_res[i].tx_bytes;
332 }
333
334 stats->tx_packets = tx_packets;
335 stats->rx_bytes = rx_bytes;
336 stats->tx_bytes = tx_bytes;
337 stats->rx_packets = rx_packets;
338
339 return &port->stats;
340}
341
342static void ehea_update_stats(struct work_struct *work)
343{
344 struct ehea_port *port =
345 container_of(work, struct ehea_port, stats_work.work);
346 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000347 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000348 struct hcp_ehea_port_cb2 *cb2;
349 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200350
Brian King3d8009c2010-06-30 11:59:12 +0000351 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200352 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000353 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
354 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200355 }
356
357 hret = ehea_h_query_ehea_port(port->adapter->handle,
358 port->logical_port_id,
359 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
360 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800361 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200362 goto out_herr;
363 }
364
365 if (netif_msg_hw(port))
366 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
367
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200368 stats->multicast = cb2->rxmcp;
369 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200370
371out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800372 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000373resched:
Anton Blanchard67c170a2011-11-23 00:13:54 +0000374 schedule_delayed_work(&port->stats_work,
375 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200376}
377
378static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
379{
380 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
381 struct net_device *dev = pr->port->netdev;
382 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200383 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
384 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200385 int i;
386
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200388
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200389 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200390 if (nr_of_wqes > 0)
391 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200392 pr->rq1_skba.os_skbs = fill_wqes;
393 return;
394 }
395
396 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200397 if (!skb_arr_rq1[index]) {
398 skb_arr_rq1[index] = netdev_alloc_skb(dev,
399 EHEA_L_PKT_SIZE);
400 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800401 netdev_info(dev, "Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200402 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200403 break;
404 }
405 }
406 index--;
407 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200408 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200409 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200410
411 if (adder == 0)
412 return;
413
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200414 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200415 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200416}
417
Thomas Kleine2878802009-01-21 14:45:57 -0800418static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200419{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
421 struct net_device *dev = pr->port->netdev;
422 int i;
423
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000424 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800425 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000426 return;
427 }
428
429 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200430 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000431 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800432 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800433 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000434 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200435 }
436 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000437 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200438}
439
440static int ehea_refill_rq_def(struct ehea_port_res *pr,
441 struct ehea_q_skb_arr *q_skba, int rq_nr,
442 int num_wqes, int wqe_type, int packet_size)
443{
444 struct net_device *dev = pr->port->netdev;
445 struct ehea_qp *qp = pr->qp;
446 struct sk_buff **skb_arr = q_skba->arr;
447 struct ehea_rwqe *rwqe;
448 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200449 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200450 int ret = 0;
451
452 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200453 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200454
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200455 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
456 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200457 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200458 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200459
460 index = q_skba->index;
461 max_index_mask = q_skba->len - 1;
462 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200463 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000464 struct sk_buff *skb;
465
466 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200467 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200468 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800469 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800470 netdev_info(pr->port->netdev,
471 "rq%i ran dry - no mem for skb\n",
472 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800473 ret = -ENOMEM;
474 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200475 break;
476 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200477
478 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200479 tmp_addr = ehea_map_vaddr(skb->data);
480 if (tmp_addr == -1) {
481 dev_kfree_skb(skb);
482 q_skba->os_skbs = fill_wqes - i;
483 ret = 0;
484 break;
485 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200486
487 rwqe = ehea_get_next_rwqe(qp, rq_nr);
488 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200489 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200490 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200491 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200492 rwqe->sg_list[0].len = packet_size;
493 rwqe->data_segments = 1;
494
495 index++;
496 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200497 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200498 }
Thomas Klein44c82152007-07-11 16:32:00 +0200499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200500 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200501 if (adder == 0)
502 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200503
504 /* Ring doorbell */
505 iosync();
506 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200507 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200508 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200509 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200510out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200511 return ret;
512}
513
514
515static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
516{
517 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
518 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000519 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200520}
521
522
523static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
524{
525 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
526 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000527 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200528}
529
530static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
531{
532 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
533 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
534 return 0;
535 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
536 (cqe->header_length == 0))
537 return 0;
538 return -EINVAL;
539}
540
541static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000542 struct sk_buff *skb, struct ehea_cqe *cqe,
543 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200544{
545 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
546
547 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200548 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000549
550 /* The packet was not an IPV4 packet so a complemented checksum was
551 calculated. The value is found in the Internet Checksum field. */
552 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
553 skb->ip_summed = CHECKSUM_COMPLETE;
554 skb->csum = csum_unfold(~cqe->inet_checksum_value);
555 } else
556 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000557
558 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200559}
560
561static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
562 int arr_len,
563 struct ehea_cqe *cqe)
564{
565 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
566 struct sk_buff *skb;
567 void *pref;
568 int x;
569
570 x = skb_index + 1;
571 x &= (arr_len - 1);
572
573 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700574 if (pref) {
575 prefetchw(pref);
576 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200577
Hannes Hering0b2febf2009-05-04 11:06:37 -0700578 pref = (skb_array[x]->data);
579 prefetch(pref);
580 prefetch(pref + EHEA_CACHE_LINE);
581 prefetch(pref + EHEA_CACHE_LINE * 2);
582 prefetch(pref + EHEA_CACHE_LINE * 3);
583 }
584
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200585 skb = skb_array[skb_index];
586 skb_array[skb_index] = NULL;
587 return skb;
588}
589
590static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
591 int arr_len, int wqe_index)
592{
593 struct sk_buff *skb;
594 void *pref;
595 int x;
596
597 x = wqe_index + 1;
598 x &= (arr_len - 1);
599
600 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700601 if (pref) {
602 prefetchw(pref);
603 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200604
Hannes Hering0b2febf2009-05-04 11:06:37 -0700605 pref = (skb_array[x]->data);
606 prefetchw(pref);
607 prefetchw(pref + EHEA_CACHE_LINE);
608 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200609
610 skb = skb_array[wqe_index];
611 skb_array[wqe_index] = NULL;
612 return skb;
613}
614
615static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
616 struct ehea_cqe *cqe, int *processed_rq2,
617 int *processed_rq3)
618{
619 struct sk_buff *skb;
620
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100621 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
622 pr->p_stats.err_tcp_cksum++;
623 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
624 pr->p_stats.err_ip_cksum++;
625 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
626 pr->p_stats.err_frame_crc++;
627
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200628 if (rq == 2) {
629 *processed_rq2 += 1;
630 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
631 dev_kfree_skb(skb);
632 } else if (rq == 3) {
633 *processed_rq3 += 1;
634 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
635 dev_kfree_skb(skb);
636 }
637
638 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100639 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800640 pr_err("Critical receive error for QP %d. Resetting port.\n",
641 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100642 ehea_dump(cqe, sizeof(*cqe), "CQE");
643 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100644 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200645 return 1;
646 }
647
648 return 0;
649}
650
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700651static int ehea_proc_rwqes(struct net_device *dev,
652 struct ehea_port_res *pr,
653 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200654{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100655 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200656 struct ehea_qp *qp = pr->qp;
657 struct ehea_cqe *cqe;
658 struct sk_buff *skb;
659 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
660 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
661 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
662 int skb_arr_rq1_len = pr->rq1_skba.len;
663 int skb_arr_rq2_len = pr->rq2_skba.len;
664 int skb_arr_rq3_len = pr->rq3_skba.len;
665 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000666 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700667 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200668
669 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
670 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200671
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200672 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700673 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200674 ehea_inc_rq1(qp);
675 processed_rq1++;
676 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200677 if (netif_msg_rx_status(port))
678 ehea_dump(cqe, sizeof(*cqe), "CQE");
679
680 last_wqe_index = wqe_index;
681 rmb();
682 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600683 if (rq == 1) {
684 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200685 skb = get_skb_by_index_ll(skb_arr_rq1,
686 skb_arr_rq1_len,
687 wqe_index);
688 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800689 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800690 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100691
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700692 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200693 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000694 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800695 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200696 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000697 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200698 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600699 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200700 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000701 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600702 } else if (rq == 2) {
703 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200704 skb = get_skb_by_index(skb_arr_rq2,
705 skb_arr_rq2_len, cqe);
706 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800707 netif_err(port, rx_err, dev,
708 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200709 break;
710 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000711 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200712 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600713 } else {
714 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200715 skb = get_skb_by_index(skb_arr_rq3,
716 skb_arr_rq3_len, cqe);
717 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800718 netif_err(port, rx_err, dev,
719 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200720 break;
721 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000722 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200723 processed_rq3++;
724 }
725
Breno Leitaoce45b872010-10-27 08:45:14 +0000726 processed_bytes += skb->len;
Anton Blanchard34284142011-10-14 05:31:11 +0000727
728 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
729 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
730
731 napi_gro_receive(&pr->napi, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100732 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100733 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200734 port_reset = ehea_treat_poll_error(pr, rq, cqe,
735 &processed_rq2,
736 &processed_rq3);
737 if (port_reset)
738 break;
739 }
740 cqe = ehea_poll_rq1(qp, &wqe_index);
741 }
742
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200743 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000744 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745
746 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
747 ehea_refill_rq2(pr, processed_rq2);
748 ehea_refill_rq3(pr, processed_rq3);
749
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700750 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200751}
752
Andre Detsch2928db42010-08-17 05:49:12 +0000753#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
754
755static void reset_sq_restart_flag(struct ehea_port *port)
756{
757 int i;
758
Anton Blanchard723f28e2011-10-14 05:31:01 +0000759 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000760 struct ehea_port_res *pr = &port->port_res[i];
761 pr->sq_restart_flag = 0;
762 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000763 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000764}
765
766static void check_sqs(struct ehea_port *port)
767{
768 struct ehea_swqe *swqe;
769 int swqe_index;
770 int i, k;
771
Anton Blanchard723f28e2011-10-14 05:31:01 +0000772 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000773 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000774 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000775 k = 0;
776 swqe = ehea_get_swqe(pr->qp, &swqe_index);
777 memset(swqe, 0, SWQE_HEADER_SIZE);
778 atomic_dec(&pr->swqe_avail);
779
780 swqe->tx_control |= EHEA_SWQE_PURGE;
781 swqe->wr_id = SWQE_RESTART_CHECK;
782 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
783 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
784 swqe->immediate_data_length = 80;
785
786 ehea_post_swqe(pr->qp, swqe);
787
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000788 ret = wait_event_timeout(port->restart_wq,
789 pr->sq_restart_flag == 0,
790 msecs_to_jiffies(100));
791
792 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800793 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000794 ehea_schedule_port_reset(pr->port);
795 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000796 }
797 }
Andre Detsch2928db42010-08-17 05:49:12 +0000798}
799
800
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100801static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200802{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100803 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200804 struct ehea_cq *send_cq = pr->send_cq;
805 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100806 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200807 int cqe_counter = 0;
808 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100809 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000810 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
811 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200812
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100813 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600814 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100815 ehea_inc_cq(send_cq);
816
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200817 cqe_counter++;
818 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000819
820 if (cqe->wr_id == SWQE_RESTART_CHECK) {
821 pr->sq_restart_flag = 1;
822 swqe_av++;
823 break;
824 }
825
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200826 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800827 pr_err("Bad send completion status=0x%04X\n",
828 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000829
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200830 if (netif_msg_tx_err(pr->port))
831 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000832
833 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800834 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000835 ehea_schedule_port_reset(pr->port);
836 break;
837 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200838 }
839
840 if (netif_msg_tx_done(pr->port))
841 ehea_dump(cqe, sizeof(*cqe), "CQE");
842
843 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100844 == EHEA_SWQE2_TYPE)) {
845
846 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
847 skb = pr->sq_skba.arr[index];
848 dev_kfree_skb(skb);
849 pr->sq_skba.arr[index] = NULL;
850 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200851
852 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
853 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100854
855 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700856 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200857
858 ehea_update_feca(send_cq, cqe_counter);
859 atomic_add(swqe_av, &pr->swqe_avail);
860
Anton Blanchardb9564462011-10-14 05:30:59 +0000861 if (unlikely(netif_tx_queue_stopped(txq) &&
862 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
863 __netif_tx_lock(txq, smp_processor_id());
864 if (netif_tx_queue_stopped(txq) &&
865 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
866 netif_tx_wake_queue(txq);
867 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200868 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000869
Breno Leitao5b27d422010-10-05 13:16:22 +0000870 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200871
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100872 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200873}
874
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700875#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100876
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700877static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200878{
Doug Maxey508d2b52008-01-31 20:20:49 -0600879 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
880 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700881 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100882 struct ehea_cqe *cqe;
883 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000884 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700885 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100886
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700887 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000888 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100889
Anton Blanchard222ca962011-10-14 05:31:00 +0000890 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800891 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100892 ehea_reset_cq_ep(pr->recv_cq);
893 ehea_reset_cq_ep(pr->send_cq);
894 ehea_reset_cq_n1(pr->recv_cq);
895 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000896 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100897 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
898 cqe_skb = ehea_poll_cq(pr->send_cq);
899
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100900 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700901 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100902
Ben Hutchings288379f2009-01-19 16:43:59 -0800903 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700904 return rx;
905
906 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
907 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100908 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100909
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700910 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200911}
912
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200913#ifdef CONFIG_NET_POLL_CONTROLLER
914static void ehea_netpoll(struct net_device *dev)
915{
916 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700917 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200918
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700919 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800920 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200921}
922#endif
923
David Howells7d12e782006-10-05 14:55:46 +0100924static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200925{
926 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100927
Ben Hutchings288379f2009-01-19 16:43:59 -0800928 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100929
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200930 return IRQ_HANDLED;
931}
932
David Howells7d12e782006-10-05 14:55:46 +0100933static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200934{
935 struct ehea_port *port = param;
936 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100937 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200938 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000939 u64 resource_type, aer, aerr;
940 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200941
942 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100943
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200944 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200945 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800946 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
947 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100948
949 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000950
951 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
952 &aer, &aerr);
953
954 if (resource_type == EHEA_AER_RESTYPE_QP) {
955 if ((aer & EHEA_AER_RESET_MASK) ||
956 (aerr & EHEA_AERR_RESET_MASK))
957 reset_port = 1;
958 } else
959 reset_port = 1; /* Reset in case of CQ or EQ error */
960
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100961 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200962 }
963
Thomas Kleinea96cea2010-04-20 23:10:55 +0000964 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800965 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000966 ehea_schedule_port_reset(port);
967 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100968
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200969 return IRQ_HANDLED;
970}
971
972static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
973 int logical_port)
974{
975 int i;
976
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100977 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100978 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200979 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100980 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200981 return NULL;
982}
983
984int ehea_sense_port_attr(struct ehea_port *port)
985{
986 int ret;
987 u64 hret;
988 struct hcp_ehea_port_cb0 *cb0;
989
Doug Maxey508d2b52008-01-31 20:20:49 -0600990 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800991 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600992 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800993 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200994 ret = -ENOMEM;
995 goto out;
996 }
997
998 hret = ehea_h_query_ehea_port(port->adapter->handle,
999 port->logical_port_id, H_PORT_CB0,
1000 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1001 cb0);
1002 if (hret != H_SUCCESS) {
1003 ret = -EIO;
1004 goto out_free;
1005 }
1006
1007 /* MAC address */
1008 port->mac_addr = cb0->port_mac_addr << 16;
1009
Doug Maxey508d2b52008-01-31 20:20:49 -06001010 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001011 ret = -EADDRNOTAVAIL;
1012 goto out_free;
1013 }
1014
1015 /* Port speed */
1016 switch (cb0->port_speed) {
1017 case H_SPEED_10M_H:
1018 port->port_speed = EHEA_SPEED_10M;
1019 port->full_duplex = 0;
1020 break;
1021 case H_SPEED_10M_F:
1022 port->port_speed = EHEA_SPEED_10M;
1023 port->full_duplex = 1;
1024 break;
1025 case H_SPEED_100M_H:
1026 port->port_speed = EHEA_SPEED_100M;
1027 port->full_duplex = 0;
1028 break;
1029 case H_SPEED_100M_F:
1030 port->port_speed = EHEA_SPEED_100M;
1031 port->full_duplex = 1;
1032 break;
1033 case H_SPEED_1G_F:
1034 port->port_speed = EHEA_SPEED_1G;
1035 port->full_duplex = 1;
1036 break;
1037 case H_SPEED_10G_F:
1038 port->port_speed = EHEA_SPEED_10G;
1039 port->full_duplex = 1;
1040 break;
1041 default:
1042 port->port_speed = 0;
1043 port->full_duplex = 0;
1044 break;
1045 }
1046
Thomas Kleine919b592007-01-22 12:53:20 +01001047 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001048 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001049
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001050 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001051 if (use_mcs)
1052 port->num_def_qps = cb0->num_default_qps;
1053 else
1054 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001055
1056 if (!port->num_def_qps) {
1057 ret = -EINVAL;
1058 goto out_free;
1059 }
1060
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001061 ret = 0;
1062out_free:
1063 if (ret || netif_msg_probe(port))
1064 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001065 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001066out:
1067 return ret;
1068}
1069
1070int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1071{
1072 struct hcp_ehea_port_cb4 *cb4;
1073 u64 hret;
1074 int ret = 0;
1075
Thomas Klein3faf2692009-01-21 14:45:33 -08001076 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001077 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001078 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001079 ret = -ENOMEM;
1080 goto out;
1081 }
1082
1083 cb4->port_speed = port_speed;
1084
1085 netif_carrier_off(port->netdev);
1086
1087 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1088 port->logical_port_id,
1089 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1090 if (hret == H_SUCCESS) {
1091 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1092
1093 hret = ehea_h_query_ehea_port(port->adapter->handle,
1094 port->logical_port_id,
1095 H_PORT_CB4, H_PORT_CB4_SPEED,
1096 cb4);
1097 if (hret == H_SUCCESS) {
1098 switch (cb4->port_speed) {
1099 case H_SPEED_10M_H:
1100 port->port_speed = EHEA_SPEED_10M;
1101 port->full_duplex = 0;
1102 break;
1103 case H_SPEED_10M_F:
1104 port->port_speed = EHEA_SPEED_10M;
1105 port->full_duplex = 1;
1106 break;
1107 case H_SPEED_100M_H:
1108 port->port_speed = EHEA_SPEED_100M;
1109 port->full_duplex = 0;
1110 break;
1111 case H_SPEED_100M_F:
1112 port->port_speed = EHEA_SPEED_100M;
1113 port->full_duplex = 1;
1114 break;
1115 case H_SPEED_1G_F:
1116 port->port_speed = EHEA_SPEED_1G;
1117 port->full_duplex = 1;
1118 break;
1119 case H_SPEED_10G_F:
1120 port->port_speed = EHEA_SPEED_10G;
1121 port->full_duplex = 1;
1122 break;
1123 default:
1124 port->port_speed = 0;
1125 port->full_duplex = 0;
1126 break;
1127 }
1128 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001129 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001130 ret = -EIO;
1131 }
1132 } else {
1133 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001134 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001135 ret = -EPERM;
1136 } else {
1137 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001138 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001139 }
1140 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001141 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1142 netif_carrier_on(port->netdev);
1143
Thomas Klein3faf2692009-01-21 14:45:33 -08001144 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001145out:
1146 return ret;
1147}
1148
1149static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1150{
1151 int ret;
1152 u8 ec;
1153 u8 portnum;
1154 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001155 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001156
1157 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1158 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1159 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001160 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001161
1162 switch (ec) {
1163 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1164
1165 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001166 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001167 break;
1168 }
1169
1170 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001171 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001172 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001173 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001174 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001175 break;
1176 }
1177
Joe Perches8c4877a2010-12-13 10:05:14 -08001178 netif_info(port, link, dev,
1179 "Logical port up: %dMbps %s Duplex\n",
1180 port->port_speed,
1181 port->full_duplex == 1 ?
1182 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001183
Joe Perches8c4877a2010-12-13 10:05:14 -08001184 netif_carrier_on(dev);
1185 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001186 }
1187 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001188 if (netif_carrier_ok(dev)) {
1189 netif_info(port, link, dev,
1190 "Logical port down\n");
1191 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001192 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001193 }
1194
1195 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001196 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001197 netif_info(port, link, dev,
1198 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001199 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001200 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001201 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001202 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001203 netif_info(port, link, dev,
1204 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001205 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001206 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001207 }
1208
1209 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001210 netdev_info(dev,
1211 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001212 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001213 netdev_info(dev,
1214 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001215
1216 break;
1217 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001218 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001219 break;
1220 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001221 netdev_info(dev, "Port malfunction\n");
1222 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001223 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001224 break;
1225 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001226 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001227 break;
1228 }
1229}
1230
1231static void ehea_neq_tasklet(unsigned long data)
1232{
Doug Maxey508d2b52008-01-31 20:20:49 -06001233 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001234 struct ehea_eqe *eqe;
1235 u64 event_mask;
1236
1237 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001238 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001239
1240 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001241 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001242 ehea_parse_eqe(adapter, eqe->entry);
1243 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001244 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001245 }
1246
1247 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1248 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1249 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1250
1251 ehea_h_reset_events(adapter->handle,
1252 adapter->neq->fw_handle, event_mask);
1253}
1254
David Howells7d12e782006-10-05 14:55:46 +01001255static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256{
1257 struct ehea_adapter *adapter = param;
1258 tasklet_hi_schedule(&adapter->neq_tasklet);
1259 return IRQ_HANDLED;
1260}
1261
1262
1263static int ehea_fill_port_res(struct ehea_port_res *pr)
1264{
1265 int ret;
1266 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1267
Breno Leitaof76957f2011-01-11 07:45:57 +00001268 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001269
Thomas Kleine2878802009-01-21 14:45:57 -08001270 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001271
1272 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1273
1274 return ret;
1275}
1276
1277static int ehea_reg_interrupts(struct net_device *dev)
1278{
1279 struct ehea_port *port = netdev_priv(dev);
1280 struct ehea_port_res *pr;
1281 int i, ret;
1282
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283
1284 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1285 dev->name);
1286
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001287 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001289 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001290 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001291 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1292 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001293 goto out_free_qpeq;
1294 }
1295
Joe Perches8c4877a2010-12-13 10:05:14 -08001296 netif_info(port, ifup, dev,
1297 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1298 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001299
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001300
Anton Blanchard723f28e2011-10-14 05:31:01 +00001301 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001302 pr = &port->port_res[i];
1303 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001304 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001305 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001306 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001307 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001308 pr);
1309 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001310 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1311 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001312 goto out_free_req;
1313 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001314 netif_info(port, ifup, dev,
1315 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1316 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001317 }
1318out:
1319 return ret;
1320
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001321
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001322out_free_req:
1323 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001324 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001325 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001326 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001328out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001329 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001330 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001331
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001333
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001334}
1335
1336static void ehea_free_interrupts(struct net_device *dev)
1337{
1338 struct ehea_port *port = netdev_priv(dev);
1339 struct ehea_port_res *pr;
1340 int i;
1341
1342 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001343
Anton Blanchard723f28e2011-10-14 05:31:01 +00001344 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001345 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001346 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001347 netif_info(port, intr, dev,
1348 "free send irq for res %d with handle 0x%X\n",
1349 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350 }
1351
1352 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001353 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001354 netif_info(port, intr, dev,
1355 "associated event interrupt for handle 0x%X freed\n",
1356 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357}
1358
1359static int ehea_configure_port(struct ehea_port *port)
1360{
1361 int ret, i;
1362 u64 hret, mask;
1363 struct hcp_ehea_port_cb0 *cb0;
1364
1365 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001366 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001367 if (!cb0)
1368 goto out;
1369
1370 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1371 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1372 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1373 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1374 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1375 PXLY_RC_VLAN_FILTER)
1376 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1377
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001378 for (i = 0; i < port->num_mcs; i++)
1379 if (use_mcs)
1380 cb0->default_qpn_arr[i] =
1381 port->port_res[i].qp->init_attr.qp_nr;
1382 else
1383 cb0->default_qpn_arr[i] =
1384 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001385
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001386 if (netif_msg_ifup(port))
1387 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1388
1389 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1390 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1391
1392 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1393 port->logical_port_id,
1394 H_PORT_CB0, mask, cb0);
1395 ret = -EIO;
1396 if (hret != H_SUCCESS)
1397 goto out_free;
1398
1399 ret = 0;
1400
1401out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001402 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001403out:
1404 return ret;
1405}
1406
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001407int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001408{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001409 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001410 struct ehea_adapter *adapter = pr->port->adapter;
1411
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001412 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1413 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414 goto out;
1415
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001416 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1417 if (ret)
1418 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001419
1420 return 0;
1421
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001422out_free:
1423 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001424out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001425 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001426 return -EIO;
1427}
1428
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001429int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001430{
Joe Perches8e95a202009-12-03 07:58:21 +00001431 if ((ehea_rem_mr(&pr->send_mr)) ||
1432 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001433 return -EIO;
1434 else
1435 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001436}
1437
1438static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1439{
Doug Maxey508d2b52008-01-31 20:20:49 -06001440 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001441
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001442 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001443 if (!q_skba->arr)
1444 return -ENOMEM;
1445
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001446 q_skba->len = max_q_entries;
1447 q_skba->index = 0;
1448 q_skba->os_skbs = 0;
1449
1450 return 0;
1451}
1452
1453static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1454 struct port_res_cfg *pr_cfg, int queue_token)
1455{
1456 struct ehea_adapter *adapter = port->adapter;
1457 enum ehea_eq_type eq_type = EHEA_EQ;
1458 struct ehea_qp_init_attr *init_attr = NULL;
1459 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001460 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1461
1462 tx_bytes = pr->tx_bytes;
1463 tx_packets = pr->tx_packets;
1464 rx_bytes = pr->rx_bytes;
1465 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001466
1467 memset(pr, 0, sizeof(struct ehea_port_res));
1468
Breno Leitaoce45b872010-10-27 08:45:14 +00001469 pr->tx_bytes = rx_bytes;
1470 pr->tx_packets = tx_packets;
1471 pr->rx_bytes = rx_bytes;
1472 pr->rx_packets = rx_packets;
1473
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001475
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001476 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1477 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001478 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001479 goto out_free;
1480 }
1481
1482 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001483 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001484 port->logical_port_id);
1485 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001486 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001487 goto out_free;
1488 }
1489
1490 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001491 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001492 port->logical_port_id);
1493 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001494 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001495 goto out_free;
1496 }
1497
1498 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001499 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1500 pr->send_cq->attr.act_nr_of_cqes,
1501 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001502
1503 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1504 if (!init_attr) {
1505 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001506 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001507 goto out_free;
1508 }
1509
1510 init_attr->low_lat_rq1 = 1;
1511 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1512 init_attr->rq_count = 3;
1513 init_attr->qp_token = queue_token;
1514 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1515 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1516 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1517 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1518 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1519 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1520 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1521 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1522 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1523 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1524 init_attr->port_nr = port->logical_port_id;
1525 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1526 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1527 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1528
1529 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1530 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001531 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001532 ret = -EIO;
1533 goto out_free;
1534 }
1535
1536 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001537 pr_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d\n",
1538 init_attr->qp_nr,
1539 init_attr->act_nr_send_wqes,
1540 init_attr->act_nr_rwqes_rq1,
1541 init_attr->act_nr_rwqes_rq2,
1542 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543
Thomas Klein44fb3122008-04-04 15:04:53 +02001544 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1545
1546 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001547 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1548 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1549 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1550 if (ret)
1551 goto out_free;
1552
1553 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1554 if (ehea_gen_smrs(pr) != 0) {
1555 ret = -EIO;
1556 goto out_free;
1557 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001558
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001559 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1560
1561 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001562
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001563 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001564
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001565 ret = 0;
1566 goto out;
1567
1568out_free:
1569 kfree(init_attr);
1570 vfree(pr->sq_skba.arr);
1571 vfree(pr->rq1_skba.arr);
1572 vfree(pr->rq2_skba.arr);
1573 vfree(pr->rq3_skba.arr);
1574 ehea_destroy_qp(pr->qp);
1575 ehea_destroy_cq(pr->send_cq);
1576 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001577 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001578out:
1579 return ret;
1580}
1581
1582static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1583{
1584 int ret, i;
1585
Hannes Hering357eb462009-08-04 11:48:39 -07001586 if (pr->qp)
1587 netif_napi_del(&pr->napi);
1588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001589 ret = ehea_destroy_qp(pr->qp);
1590
1591 if (!ret) {
1592 ehea_destroy_cq(pr->send_cq);
1593 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001594 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001595
1596 for (i = 0; i < pr->rq1_skba.len; i++)
1597 if (pr->rq1_skba.arr[i])
1598 dev_kfree_skb(pr->rq1_skba.arr[i]);
1599
1600 for (i = 0; i < pr->rq2_skba.len; i++)
1601 if (pr->rq2_skba.arr[i])
1602 dev_kfree_skb(pr->rq2_skba.arr[i]);
1603
1604 for (i = 0; i < pr->rq3_skba.len; i++)
1605 if (pr->rq3_skba.arr[i])
1606 dev_kfree_skb(pr->rq3_skba.arr[i]);
1607
1608 for (i = 0; i < pr->sq_skba.len; i++)
1609 if (pr->sq_skba.arr[i])
1610 dev_kfree_skb(pr->sq_skba.arr[i]);
1611
1612 vfree(pr->rq1_skba.arr);
1613 vfree(pr->rq2_skba.arr);
1614 vfree(pr->rq3_skba.arr);
1615 vfree(pr->sq_skba.arr);
1616 ret = ehea_rem_smrs(pr);
1617 }
1618 return ret;
1619}
1620
Anton Blanchard13946f52011-10-14 05:31:06 +00001621static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1622 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001623{
Eric Dumazete743d312010-04-14 15:59:40 -07001624 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001625 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1626 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001627 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001628
Anton Blanchard13946f52011-10-14 05:31:06 +00001629 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001630
Anton Blanchard13946f52011-10-14 05:31:06 +00001631 if (skb_is_gso(skb)) {
1632 swqe->tx_control |= EHEA_SWQE_TSO;
1633 swqe->mss = skb_shinfo(skb)->gso_size;
1634 /*
1635 * For TSO packets we only copy the headers into the
1636 * immediate area.
1637 */
1638 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1639 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001640
Anton Blanchard13946f52011-10-14 05:31:06 +00001641 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1642 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1643 swqe->immediate_data_length = immediate_len;
1644
1645 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001646 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001647 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001648 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001649 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001650 swqe->descriptors++;
1651 }
1652 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001653 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001654 swqe->immediate_data_length = skb_data_size;
1655 }
1656}
1657
1658static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1659 struct ehea_swqe *swqe, u32 lkey)
1660{
1661 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1662 skb_frag_t *frag;
1663 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001664
1665 nfrags = skb_shinfo(skb)->nr_frags;
1666 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001667 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001668 sg1entry_contains_frag_data = 0;
1669
Anton Blanchard13946f52011-10-14 05:31:06 +00001670 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001671
1672 /* write descriptors */
1673 if (nfrags > 0) {
1674 if (swqe->descriptors == 0) {
1675 /* sg1entry not yet used */
1676 frag = &skb_shinfo(skb)->frags[0];
1677
1678 /* copy sg1entry data */
1679 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001680 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001681 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001682 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001683 swqe->descriptors++;
1684 sg1entry_contains_frag_data = 1;
1685 }
1686
1687 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1688
1689 frag = &skb_shinfo(skb)->frags[i];
1690 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1691
1692 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001693 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001694 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001695 swqe->descriptors++;
1696 }
1697 }
1698}
1699
1700static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1701{
1702 int ret = 0;
1703 u64 hret;
1704 u8 reg_type;
1705
1706 /* De/Register untagged packets */
1707 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1708 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1709 port->logical_port_id,
1710 reg_type, port->mac_addr, 0, hcallid);
1711 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001712 pr_err("%sregistering bc address failed (tagged)\n",
1713 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001714 ret = -EIO;
1715 goto out_herr;
1716 }
1717
1718 /* De/Register VLAN packets */
1719 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1720 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1721 port->logical_port_id,
1722 reg_type, port->mac_addr, 0, hcallid);
1723 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001724 pr_err("%sregistering bc address failed (vlan)\n",
1725 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001726 ret = -EIO;
1727 }
1728out_herr:
1729 return ret;
1730}
1731
1732static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1733{
1734 struct ehea_port *port = netdev_priv(dev);
1735 struct sockaddr *mac_addr = sa;
1736 struct hcp_ehea_port_cb0 *cb0;
1737 int ret;
1738 u64 hret;
1739
1740 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1741 ret = -EADDRNOTAVAIL;
1742 goto out;
1743 }
1744
Thomas Klein3faf2692009-01-21 14:45:33 -08001745 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001746 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001747 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001748 ret = -ENOMEM;
1749 goto out;
1750 }
1751
1752 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1753
1754 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1755
1756 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1757 port->logical_port_id, H_PORT_CB0,
1758 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1759 if (hret != H_SUCCESS) {
1760 ret = -EIO;
1761 goto out_free;
1762 }
1763
1764 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1765
1766 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001767 if (port->state == EHEA_PORT_UP) {
1768 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1769 if (ret)
1770 goto out_upregs;
1771 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001772
1773 port->mac_addr = cb0->port_mac_addr << 16;
1774
1775 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001776 if (port->state == EHEA_PORT_UP) {
1777 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1778 if (ret)
1779 goto out_upregs;
1780 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001781
1782 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001783
1784out_upregs:
1785 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001786out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001787 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001788out:
1789 return ret;
1790}
1791
1792static void ehea_promiscuous_error(u64 hret, int enable)
1793{
Thomas Klein7674a582007-01-22 12:54:20 +01001794 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001795 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1796 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001797 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001798 pr_err("failed %sabling promiscuous mode\n",
1799 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001800}
1801
1802static void ehea_promiscuous(struct net_device *dev, int enable)
1803{
1804 struct ehea_port *port = netdev_priv(dev);
1805 struct hcp_ehea_port_cb7 *cb7;
1806 u64 hret;
1807
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001808 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001809 return;
1810
Thomas Klein3faf2692009-01-21 14:45:33 -08001811 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001812 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001813 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001814 goto out;
1815 }
1816
1817 /* Modify Pxs_DUCQPN in CB7 */
1818 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1819
1820 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1821 port->logical_port_id,
1822 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1823 if (hret) {
1824 ehea_promiscuous_error(hret, enable);
1825 goto out;
1826 }
1827
1828 port->promisc = enable;
1829out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001830 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001831}
1832
1833static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1834 u32 hcallid)
1835{
1836 u64 hret;
1837 u8 reg_type;
1838
1839 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1840 | EHEA_BCMC_UNTAGGED;
1841
1842 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1843 port->logical_port_id,
1844 reg_type, mc_mac_addr, 0, hcallid);
1845 if (hret)
1846 goto out;
1847
1848 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1849 | EHEA_BCMC_VLANID_ALL;
1850
1851 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1852 port->logical_port_id,
1853 reg_type, mc_mac_addr, 0, hcallid);
1854out:
1855 return hret;
1856}
1857
1858static int ehea_drop_multicast_list(struct net_device *dev)
1859{
1860 struct ehea_port *port = netdev_priv(dev);
1861 struct ehea_mc_list *mc_entry = port->mc_list;
1862 struct list_head *pos;
1863 struct list_head *temp;
1864 int ret = 0;
1865 u64 hret;
1866
1867 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1868 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1869
1870 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1871 H_DEREG_BCMC);
1872 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001873 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001874 ret = -EIO;
1875 }
1876
1877 list_del(pos);
1878 kfree(mc_entry);
1879 }
1880 return ret;
1881}
1882
1883static void ehea_allmulti(struct net_device *dev, int enable)
1884{
1885 struct ehea_port *port = netdev_priv(dev);
1886 u64 hret;
1887
1888 if (!port->allmulti) {
1889 if (enable) {
1890 /* Enable ALLMULTI */
1891 ehea_drop_multicast_list(dev);
1892 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1893 if (!hret)
1894 port->allmulti = 1;
1895 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001896 netdev_err(dev,
1897 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001898 }
1899 } else
1900 if (!enable) {
1901 /* Disable ALLMULTI */
1902 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1903 if (!hret)
1904 port->allmulti = 0;
1905 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001906 netdev_err(dev,
1907 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001908 }
1909}
1910
Doug Maxey508d2b52008-01-31 20:20:49 -06001911static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001912{
1913 struct ehea_mc_list *ehea_mcl_entry;
1914 u64 hret;
1915
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001916 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001917 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001918 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001919 return;
1920 }
1921
1922 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1923
1924 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1925
1926 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1927 H_REG_BCMC);
1928 if (!hret)
1929 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1930 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001931 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001932 kfree(ehea_mcl_entry);
1933 }
1934}
1935
1936static void ehea_set_multicast_list(struct net_device *dev)
1937{
1938 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad2010-04-01 21:22:57 +00001939 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001940 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001941
Breno Leitaoa4910b72011-05-23 03:36:35 +00001942 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001943 ehea_promiscuous(dev, 1);
1944 return;
1945 }
1946 ehea_promiscuous(dev, 0);
1947
1948 if (dev->flags & IFF_ALLMULTI) {
1949 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001950 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001951 }
1952 ehea_allmulti(dev, 0);
1953
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001954 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001955 ret = ehea_drop_multicast_list(dev);
1956 if (ret) {
1957 /* Dropping the current multicast list failed.
1958 * Enabling ALL_MULTI is the best we can do.
1959 */
1960 ehea_allmulti(dev, 1);
1961 }
1962
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001963 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001964 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1965 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001966 goto out;
1967 }
1968
Jiri Pirko22bedad2010-04-01 21:22:57 +00001969 netdev_for_each_mc_addr(ha, dev)
1970 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001971
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001972 }
1973out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001974 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001975}
1976
1977static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1978{
1979 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1980 return -EINVAL;
1981 dev->mtu = new_mtu;
1982 return 0;
1983}
1984
Anton Blanchardd695c332011-10-14 05:31:05 +00001985static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1986{
1987 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1988
1989 if (skb->protocol != htons(ETH_P_IP))
1990 return;
1991
1992 if (skb->ip_summed == CHECKSUM_PARTIAL)
1993 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
1994
1995 swqe->ip_start = skb_network_offset(skb);
1996 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
1997
1998 switch (ip_hdr(skb)->protocol) {
1999 case IPPROTO_UDP:
2000 if (skb->ip_summed == CHECKSUM_PARTIAL)
2001 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2002
2003 swqe->tcp_offset = swqe->ip_end + 1 +
2004 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002005 break;
2006
2007 case IPPROTO_TCP:
2008 if (skb->ip_summed == CHECKSUM_PARTIAL)
2009 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2010
2011 swqe->tcp_offset = swqe->ip_end + 1 +
2012 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002013 break;
2014 }
2015}
2016
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002017static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2018 struct ehea_swqe *swqe, u32 lkey)
2019{
Anton Blanchardd695c332011-10-14 05:31:05 +00002020 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002021
Anton Blanchardd695c332011-10-14 05:31:05 +00002022 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002023
2024 write_swqe2_data(skb, dev, swqe, lkey);
2025}
2026
2027static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2028 struct ehea_swqe *swqe)
2029{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002030 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002031
Anton Blanchardd695c332011-10-14 05:31:05 +00002032 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002033
Anton Blanchard30e2e902011-10-14 05:31:07 +00002034 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002035 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002036 else
2037 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002038
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002039 swqe->immediate_data_length = skb->len;
2040 dev_kfree_skb(skb);
2041}
2042
2043static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2044{
2045 struct ehea_port *port = netdev_priv(dev);
2046 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002047 u32 lkey;
2048 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002049 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002050 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002051
Anton Blanchardb9564462011-10-14 05:30:59 +00002052 pr = &port->port_res[skb_get_queue_mapping(skb)];
2053 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002054
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002055 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2056 memset(swqe, 0, SWQE_HEADER_SIZE);
2057 atomic_dec(&pr->swqe_avail);
2058
Eric Dumazete5ccd962010-10-26 19:21:07 +00002059 if (vlan_tx_tag_present(skb)) {
2060 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2061 swqe->vlan_tag = vlan_tx_tag_get(skb);
2062 }
2063
Breno Leitaoce45b872010-10-27 08:45:14 +00002064 pr->tx_packets++;
2065 pr->tx_bytes += skb->len;
2066
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002067 if (skb->len <= SWQE3_MAX_IMM) {
2068 u32 sig_iv = port->sig_comp_iv;
2069 u32 swqe_num = pr->swqe_id_counter;
2070 ehea_xmit3(skb, dev, swqe);
2071 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2072 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2073 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2074 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2075 sig_iv);
2076 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2077 pr->swqe_ll_count = 0;
2078 } else
2079 pr->swqe_ll_count += 1;
2080 } else {
2081 swqe->wr_id =
2082 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2083 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002084 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002085 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2086 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2087
2088 pr->sq_skba.index++;
2089 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2090
2091 lkey = pr->send_mr.lkey;
2092 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002093 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002094 }
2095 pr->swqe_id_counter += 1;
2096
Joe Perches8c4877a2010-12-13 10:05:14 -08002097 netif_info(port, tx_queued, dev,
2098 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2099 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002100 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002101
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002102 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002103 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002104 swqe->tx_control |= EHEA_SWQE_PURGE;
2105 }
Thomas Klein44c82152007-07-11 16:32:00 +02002106
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002107 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108
2109 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002110 pr->p_stats.queue_stopped++;
2111 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002112 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002113
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002114 return NETDEV_TX_OK;
2115}
2116
Jiri Pirko8e586132011-12-08 19:52:37 -05002117static int ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002118{
2119 struct ehea_port *port = netdev_priv(dev);
2120 struct ehea_adapter *adapter = port->adapter;
2121 struct hcp_ehea_port_cb1 *cb1;
2122 int index;
2123 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002124 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002125
Thomas Klein3faf2692009-01-21 14:45:33 -08002126 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002127 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002128 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002129 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002130 goto out;
2131 }
2132
2133 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2134 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2135 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002136 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002137 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002138 goto out;
2139 }
2140
2141 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002142 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002143
2144 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2145 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002146 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002147 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002148 err = -EINVAL;
2149 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002150out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002151 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002152 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002153}
2154
Jiri Pirko8e586132011-12-08 19:52:37 -05002155static int ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002156{
2157 struct ehea_port *port = netdev_priv(dev);
2158 struct ehea_adapter *adapter = port->adapter;
2159 struct hcp_ehea_port_cb1 *cb1;
2160 int index;
2161 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002162 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002163
Thomas Klein3faf2692009-01-21 14:45:33 -08002164 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002165 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002166 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002167 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002168 goto out;
2169 }
2170
2171 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2172 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2173 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002174 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002175 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002176 goto out;
2177 }
2178
2179 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002180 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002181
2182 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2183 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002184 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002185 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002186 err = -EINVAL;
2187 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002188out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002189 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002190 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002191}
2192
2193int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2194{
2195 int ret = -EIO;
2196 u64 hret;
2197 u16 dummy16 = 0;
2198 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002199 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002200
Thomas Klein3faf2692009-01-21 14:45:33 -08002201 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002202 if (!cb0) {
2203 ret = -ENOMEM;
2204 goto out;
2205 }
2206
2207 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2208 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2209 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002210 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002211 goto out;
2212 }
2213
2214 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2215 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2216 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2217 &dummy64, &dummy64, &dummy16, &dummy16);
2218 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002219 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002220 goto out;
2221 }
2222
2223 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2224 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2225 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002226 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002227 goto out;
2228 }
2229
2230 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2231 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2232 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2233 &dummy64, &dummy64, &dummy16, &dummy16);
2234 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002235 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002236 goto out;
2237 }
2238
2239 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2240 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2241 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002242 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002243 goto out;
2244 }
2245
2246 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2247 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2248 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2249 &dummy64, &dummy64, &dummy16, &dummy16);
2250 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002251 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002252 goto out;
2253 }
2254
2255 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2256 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2257 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002258 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002259 goto out;
2260 }
2261
2262 ret = 0;
2263out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002264 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002265 return ret;
2266}
2267
Anton Blanchard723f28e2011-10-14 05:31:01 +00002268static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002269{
2270 int ret, i;
2271 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2272 enum ehea_eq_type eq_type = EHEA_EQ;
2273
2274 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2275 EHEA_MAX_ENTRIES_EQ, 1);
2276 if (!port->qp_eq) {
2277 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002278 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002279 goto out_kill_eq;
2280 }
2281
2282 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002283 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002284 pr_cfg.max_entries_sq = sq_entries;
2285 pr_cfg.max_entries_rq1 = rq1_entries;
2286 pr_cfg.max_entries_rq2 = rq2_entries;
2287 pr_cfg.max_entries_rq3 = rq3_entries;
2288
2289 pr_cfg_small_rx.max_entries_rcq = 1;
2290 pr_cfg_small_rx.max_entries_scq = sq_entries;
2291 pr_cfg_small_rx.max_entries_sq = sq_entries;
2292 pr_cfg_small_rx.max_entries_rq1 = 1;
2293 pr_cfg_small_rx.max_entries_rq2 = 1;
2294 pr_cfg_small_rx.max_entries_rq3 = 1;
2295
2296 for (i = 0; i < def_qps; i++) {
2297 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2298 if (ret)
2299 goto out_clean_pr;
2300 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002301 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002302 ret = ehea_init_port_res(port, &port->port_res[i],
2303 &pr_cfg_small_rx, i);
2304 if (ret)
2305 goto out_clean_pr;
2306 }
2307
2308 return 0;
2309
2310out_clean_pr:
2311 while (--i >= 0)
2312 ehea_clean_portres(port, &port->port_res[i]);
2313
2314out_kill_eq:
2315 ehea_destroy_eq(port->qp_eq);
2316 return ret;
2317}
2318
2319static int ehea_clean_all_portres(struct ehea_port *port)
2320{
2321 int ret = 0;
2322 int i;
2323
Anton Blanchard723f28e2011-10-14 05:31:01 +00002324 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002325 ret |= ehea_clean_portres(port, &port->port_res[i]);
2326
2327 ret |= ehea_destroy_eq(port->qp_eq);
2328
2329 return ret;
2330}
2331
Thomas Klein35cf2e22007-08-06 13:55:14 +02002332static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002333{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002334 if (adapter->active_ports)
2335 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002336
2337 ehea_rem_mr(&adapter->mr);
2338}
2339
Thomas Klein35cf2e22007-08-06 13:55:14 +02002340static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002341{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002342 if (adapter->active_ports)
2343 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002344
2345 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2346}
2347
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002348static int ehea_up(struct net_device *dev)
2349{
2350 int ret, i;
2351 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002352
2353 if (port->state == EHEA_PORT_UP)
2354 return 0;
2355
Anton Blanchard723f28e2011-10-14 05:31:01 +00002356 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002357 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002358 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002359 goto out;
2360 }
2361
2362 /* Set default QP for this port */
2363 ret = ehea_configure_port(port);
2364 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002365 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002366 goto out_clean_pr;
2367 }
2368
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002369 ret = ehea_reg_interrupts(dev);
2370 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002371 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002372 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002373 }
2374
Anton Blanchard723f28e2011-10-14 05:31:01 +00002375 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002376 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2377 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002378 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002379 goto out_free_irqs;
2380 }
2381 }
2382
Doug Maxey508d2b52008-01-31 20:20:49 -06002383 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002384 ret = ehea_fill_port_res(&port->port_res[i]);
2385 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002386 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387 goto out_free_irqs;
2388 }
2389 }
2390
Thomas Klein21eee2d2008-02-13 16:18:33 +01002391 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2392 if (ret) {
2393 ret = -EIO;
2394 goto out_free_irqs;
2395 }
2396
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002397 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002398
2399 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002400 goto out;
2401
2402out_free_irqs:
2403 ehea_free_interrupts(dev);
2404
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002405out_clean_pr:
2406 ehea_clean_all_portres(port);
2407out:
Thomas Klein44c82152007-07-11 16:32:00 +02002408 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002409 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002410
Thomas Klein21eee2d2008-02-13 16:18:33 +01002411 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002412 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002413
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002414 return ret;
2415}
2416
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002417static void port_napi_disable(struct ehea_port *port)
2418{
2419 int i;
2420
Anton Blanchard723f28e2011-10-14 05:31:01 +00002421 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002422 napi_disable(&port->port_res[i].napi);
2423}
2424
2425static void port_napi_enable(struct ehea_port *port)
2426{
2427 int i;
2428
Anton Blanchard723f28e2011-10-14 05:31:01 +00002429 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002430 napi_enable(&port->port_res[i].napi);
2431}
2432
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002433static int ehea_open(struct net_device *dev)
2434{
2435 int ret;
2436 struct ehea_port *port = netdev_priv(dev);
2437
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002438 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002439
Joe Perches8c4877a2010-12-13 10:05:14 -08002440 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002441
2442 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002443 if (!ret) {
2444 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002445 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002446 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002447
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002448 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002449 schedule_delayed_work(&port->stats_work,
2450 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002451
2452 return ret;
2453}
2454
2455static int ehea_down(struct net_device *dev)
2456{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002457 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002458 struct ehea_port *port = netdev_priv(dev);
2459
2460 if (port->state == EHEA_PORT_DOWN)
2461 return 0;
2462
2463 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002464 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2465
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002466 ehea_free_interrupts(dev);
2467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002468 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002469
Thomas Klein21eee2d2008-02-13 16:18:33 +01002470 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002471
Thomas Klein44c82152007-07-11 16:32:00 +02002472 ret = ehea_clean_all_portres(port);
2473 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002474 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002475
Thomas Klein21eee2d2008-02-13 16:18:33 +01002476 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002477
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002478 return ret;
2479}
2480
2481static int ehea_stop(struct net_device *dev)
2482{
2483 int ret;
2484 struct ehea_port *port = netdev_priv(dev);
2485
Joe Perches8c4877a2010-12-13 10:05:14 -08002486 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002487
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002488 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002489 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002490 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002491 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002492 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002493 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002494 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002495 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002496 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002497 return ret;
2498}
2499
Andrew Morton22559c52008-04-18 13:50:39 -07002500static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002501{
2502 struct ehea_qp qp = *orig_qp;
2503 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2504 struct ehea_swqe *swqe;
2505 int wqe_index;
2506 int i;
2507
2508 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2509 swqe = ehea_get_swqe(&qp, &wqe_index);
2510 swqe->tx_control |= EHEA_SWQE_PURGE;
2511 }
2512}
2513
Andrew Morton22559c52008-04-18 13:50:39 -07002514static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002515{
2516 int i;
2517
Anton Blanchard723f28e2011-10-14 05:31:01 +00002518 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002519 struct ehea_port_res *pr = &port->port_res[i];
2520 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002521 int ret;
2522
2523 ret = wait_event_timeout(port->swqe_avail_wq,
2524 atomic_read(&pr->swqe_avail) >= swqe_max,
2525 msecs_to_jiffies(100));
2526
2527 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002528 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002529 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002530 }
2531 }
2532}
2533
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002534int ehea_stop_qps(struct net_device *dev)
2535{
2536 struct ehea_port *port = netdev_priv(dev);
2537 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002538 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002539 int ret = -EIO;
2540 int dret;
2541 int i;
2542 u64 hret;
2543 u64 dummy64 = 0;
2544 u16 dummy16 = 0;
2545
Thomas Klein3faf2692009-01-21 14:45:33 -08002546 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002547 if (!cb0) {
2548 ret = -ENOMEM;
2549 goto out;
2550 }
2551
Anton Blanchard723f28e2011-10-14 05:31:01 +00002552 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002553 struct ehea_port_res *pr = &port->port_res[i];
2554 struct ehea_qp *qp = pr->qp;
2555
2556 /* Purge send queue */
2557 ehea_purge_sq(qp);
2558
2559 /* Disable queue pair */
2560 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2561 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2562 cb0);
2563 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002564 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002565 goto out;
2566 }
2567
2568 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2569 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2570
2571 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2572 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2573 1), cb0, &dummy64,
2574 &dummy64, &dummy16, &dummy16);
2575 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002576 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002577 goto out;
2578 }
2579
2580 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2581 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2582 cb0);
2583 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002584 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002585 goto out;
2586 }
2587
2588 /* deregister shared memory regions */
2589 dret = ehea_rem_smrs(pr);
2590 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002591 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002592 goto out;
2593 }
2594 }
2595
2596 ret = 0;
2597out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002598 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002599
2600 return ret;
2601}
2602
Doug Maxey508d2b52008-01-31 20:20:49 -06002603void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002604{
2605 struct ehea_qp qp = *orig_qp;
2606 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2607 struct ehea_rwqe *rwqe;
2608 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2609 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2610 struct sk_buff *skb;
2611 u32 lkey = pr->recv_mr.lkey;
2612
2613
2614 int i;
2615 int index;
2616
2617 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2618 rwqe = ehea_get_next_rwqe(&qp, 2);
2619 rwqe->sg_list[0].l_key = lkey;
2620 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2621 skb = skba_rq2[index];
2622 if (skb)
2623 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2624 }
2625
2626 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2627 rwqe = ehea_get_next_rwqe(&qp, 3);
2628 rwqe->sg_list[0].l_key = lkey;
2629 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2630 skb = skba_rq3[index];
2631 if (skb)
2632 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2633 }
2634}
2635
2636int ehea_restart_qps(struct net_device *dev)
2637{
2638 struct ehea_port *port = netdev_priv(dev);
2639 struct ehea_adapter *adapter = port->adapter;
2640 int ret = 0;
2641 int i;
2642
Doug Maxey508d2b52008-01-31 20:20:49 -06002643 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002644 u64 hret;
2645 u64 dummy64 = 0;
2646 u16 dummy16 = 0;
2647
Thomas Klein3faf2692009-01-21 14:45:33 -08002648 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002649 if (!cb0) {
2650 ret = -ENOMEM;
2651 goto out;
2652 }
2653
Anton Blanchard723f28e2011-10-14 05:31:01 +00002654 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002655 struct ehea_port_res *pr = &port->port_res[i];
2656 struct ehea_qp *qp = pr->qp;
2657
2658 ret = ehea_gen_smrs(pr);
2659 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002660 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002661 goto out;
2662 }
2663
2664 ehea_update_rqs(qp, pr);
2665
2666 /* Enable queue pair */
2667 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2668 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2669 cb0);
2670 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002671 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002672 goto out;
2673 }
2674
2675 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2676 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2677
2678 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2679 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2680 1), cb0, &dummy64,
2681 &dummy64, &dummy16, &dummy16);
2682 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002683 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002684 goto out;
2685 }
2686
2687 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2688 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2689 cb0);
2690 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002691 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002692 goto out;
2693 }
2694
2695 /* refill entire queue */
2696 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2697 ehea_refill_rq2(pr, 0);
2698 ehea_refill_rq3(pr, 0);
2699 }
2700out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002701 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002702
2703 return ret;
2704}
2705
David Howellsc4028952006-11-22 14:57:56 +00002706static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002707{
2708 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002709 struct ehea_port *port =
2710 container_of(work, struct ehea_port, reset_task);
2711 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002712
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002713 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002714 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002715 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002716 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002717
2718 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002719
Thomas Klein44c82152007-07-11 16:32:00 +02002720 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002721
2722 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002723 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002724 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002725
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002726 ehea_set_multicast_list(dev);
2727
Joe Perches8c4877a2010-12-13 10:05:14 -08002728 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002729
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002730 port_napi_enable(port);
2731
Anton Blanchardb9564462011-10-14 05:30:59 +00002732 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002733out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002734 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002735 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002736}
2737
Tejun Heo3d6b8922010-12-12 16:45:14 +01002738static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002739{
2740 int ret, i;
2741 struct ehea_adapter *adapter;
2742
Joe Perches8c4877a2010-12-13 10:05:14 -08002743 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002744
2745 list_for_each_entry(adapter, &adapter_list, list)
2746 if (adapter->active_ports) {
2747 /* Shutdown all ports */
2748 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2749 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002750 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002751
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002752 if (!port)
2753 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002754
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002755 dev = port->netdev;
2756
2757 if (dev->flags & IFF_UP) {
2758 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002759 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002760 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002761 ret = ehea_stop_qps(dev);
2762 if (ret) {
2763 mutex_unlock(&port->port_lock);
2764 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002765 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002766 port_napi_disable(port);
2767 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002768 }
Andre Detsch2928db42010-08-17 05:49:12 +00002769 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002770 }
2771
2772 /* Unregister old memory region */
2773 ret = ehea_rem_mr(&adapter->mr);
2774 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002775 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002776 goto out;
2777 }
2778 }
2779
Thomas Klein44c82152007-07-11 16:32:00 +02002780 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2781
2782 list_for_each_entry(adapter, &adapter_list, list)
2783 if (adapter->active_ports) {
2784 /* Register new memory region */
2785 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2786 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002787 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002788 goto out;
2789 }
2790
2791 /* Restart all ports */
2792 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2793 struct ehea_port *port = adapter->port[i];
2794
2795 if (port) {
2796 struct net_device *dev = port->netdev;
2797
2798 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002799 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002800 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002801 if (!ret) {
2802 check_sqs(port);
2803 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002804 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002805 } else {
2806 netdev_err(dev, "Unable to restart QPS\n");
2807 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002808 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002809 }
2810 }
2811 }
2812 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002813 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002814out:
2815 return;
2816}
2817
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002818static void ehea_tx_watchdog(struct net_device *dev)
2819{
2820 struct ehea_port *port = netdev_priv(dev);
2821
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002822 if (netif_carrier_ok(dev) &&
2823 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002824 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002825}
2826
2827int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2828{
2829 struct hcp_query_ehea *cb;
2830 u64 hret;
2831 int ret;
2832
Thomas Klein3faf2692009-01-21 14:45:33 -08002833 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002834 if (!cb) {
2835 ret = -ENOMEM;
2836 goto out;
2837 }
2838
2839 hret = ehea_h_query_ehea(adapter->handle, cb);
2840
2841 if (hret != H_SUCCESS) {
2842 ret = -EIO;
2843 goto out_herr;
2844 }
2845
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002846 adapter->max_mc_mac = cb->max_mc_mac - 1;
2847 ret = 0;
2848
2849out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002850 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002851out:
2852 return ret;
2853}
2854
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002855int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2856{
2857 struct hcp_ehea_port_cb4 *cb4;
2858 u64 hret;
2859 int ret = 0;
2860
2861 *jumbo = 0;
2862
2863 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002864 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002865 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002866 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002867 ret = -ENOMEM;
2868 goto out;
2869 } else {
2870 hret = ehea_h_query_ehea_port(port->adapter->handle,
2871 port->logical_port_id,
2872 H_PORT_CB4,
2873 H_PORT_CB4_JUMBO, cb4);
2874 if (hret == H_SUCCESS) {
2875 if (cb4->jumbo_frame)
2876 *jumbo = 1;
2877 else {
2878 cb4->jumbo_frame = 1;
2879 hret = ehea_h_modify_ehea_port(port->adapter->
2880 handle,
2881 port->
2882 logical_port_id,
2883 H_PORT_CB4,
2884 H_PORT_CB4_JUMBO,
2885 cb4);
2886 if (hret == H_SUCCESS)
2887 *jumbo = 1;
2888 }
2889 } else
2890 ret = -EINVAL;
2891
Thomas Klein3faf2692009-01-21 14:45:33 -08002892 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002893 }
2894out:
2895 return ret;
2896}
2897
2898static ssize_t ehea_show_port_id(struct device *dev,
2899 struct device_attribute *attr, char *buf)
2900{
2901 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002902 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002903}
2904
2905static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2906 NULL);
2907
2908static void __devinit logical_port_release(struct device *dev)
2909{
2910 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002911 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002912}
2913
2914static struct device *ehea_register_port(struct ehea_port *port,
2915 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002916{
2917 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002918
Grant Likely61c7a082010-04-13 16:12:29 -07002919 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002920 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002921 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002922
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002923 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002924 port->ofdev.dev.release = logical_port_release;
2925
2926 ret = of_device_register(&port->ofdev);
2927 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002928 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002929 goto out;
2930 }
2931
2932 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002933 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002934 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002935 goto out_unreg_of_dev;
2936 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002937
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002938 return &port->ofdev.dev;
2939
2940out_unreg_of_dev:
2941 of_device_unregister(&port->ofdev);
2942out:
2943 return NULL;
2944}
2945
2946static void ehea_unregister_port(struct ehea_port *port)
2947{
2948 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2949 of_device_unregister(&port->ofdev);
2950}
2951
Thomas Klein086c1b22009-01-21 14:43:59 -08002952static const struct net_device_ops ehea_netdev_ops = {
2953 .ndo_open = ehea_open,
2954 .ndo_stop = ehea_stop,
2955 .ndo_start_xmit = ehea_start_xmit,
2956#ifdef CONFIG_NET_POLL_CONTROLLER
2957 .ndo_poll_controller = ehea_netpoll,
2958#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00002959 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08002960 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00002961 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002962 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08002963 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08002964 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07002965 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
2966 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08002967};
2968
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002969struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
2970 u32 logical_port_id,
2971 struct device_node *dn)
2972{
2973 int ret;
2974 struct net_device *dev;
2975 struct ehea_port *port;
2976 struct device *port_dev;
2977 int jumbo;
2978
2979 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00002980 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002981
2982 if (!dev) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002983 pr_err("no mem for net_device\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002984 ret = -ENOMEM;
2985 goto out_err;
2986 }
2987
2988 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002989
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002990 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002991 port->state = EHEA_PORT_DOWN;
2992 port->sig_comp_iv = sq_entries / 10;
2993
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002994 port->adapter = adapter;
2995 port->netdev = dev;
2996 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002997
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002998 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002999
3000 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3001 if (!port->mc_list) {
3002 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003003 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003004 }
3005
3006 INIT_LIST_HEAD(&port->mc_list->list);
3007
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003008 ret = ehea_sense_port_attr(port);
3009 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003010 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003011
Anton Blanchardb9564462011-10-14 05:30:59 +00003012 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003013 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003014
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003015 port_dev = ehea_register_port(port, dn);
3016 if (!port_dev)
3017 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003018
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003019 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003020
3021 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003022 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3023
Thomas Klein086c1b22009-01-21 14:43:59 -08003024 dev->netdev_ops = &ehea_netdev_ops;
3025 ehea_set_ethtool_ops(dev);
3026
Anton Blanchardd695c332011-10-14 05:31:05 +00003027 dev->hw_features = NETIF_F_SG | NETIF_F_TSO
Michał Mirosławf4786a92011-04-17 00:15:47 +00003028 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003029 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003030 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003031 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003032 | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003033 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3034 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003035 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3036
David Howellsc4028952006-11-22 14:57:56 +00003037 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003038 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003039
Anton Blanchard21ccc792011-05-10 16:17:10 +00003040 init_waitqueue_head(&port->swqe_avail_wq);
3041 init_waitqueue_head(&port->restart_wq);
3042
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003043 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003044 ret = register_netdev(dev);
3045 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003046 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003047 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003048 }
3049
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003050 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003051 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003052 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003053
Joe Perches8c4877a2010-12-13 10:05:14 -08003054 netdev_info(dev, "Jumbo frames are %sabled\n",
3055 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003056
Thomas Klein44c82152007-07-11 16:32:00 +02003057 adapter->active_ports++;
3058
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003059 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003060
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003061out_unreg_port:
3062 ehea_unregister_port(port);
3063
3064out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003065 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003066
3067out_free_ethdev:
3068 free_netdev(dev);
3069
3070out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003071 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3072 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003073 return NULL;
3074}
3075
3076static void ehea_shutdown_single_port(struct ehea_port *port)
3077{
Brian King7fb1c2a2008-05-14 09:48:25 -05003078 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003079
3080 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003081 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003082 unregister_netdev(port->netdev);
3083 ehea_unregister_port(port);
3084 kfree(port->mc_list);
3085 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003086 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003087}
3088
3089static int ehea_setup_ports(struct ehea_adapter *adapter)
3090{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003091 struct device_node *lhea_dn;
3092 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003093
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003094 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003095 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003096
Grant Likely61c7a082010-04-13 16:12:29 -07003097 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003098 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003099
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003100 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003101 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003102 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003103 pr_err("bad device node: eth_dn name=%s\n",
3104 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003106 }
3107
Thomas Klein1211bb62007-04-26 11:56:43 +02003108 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003109 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003110 of_node_put(eth_dn);
3111 return -EIO;
3112 }
3113
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003114 adapter->port[i] = ehea_setup_single_port(adapter,
3115 *dn_log_port_id,
3116 eth_dn);
3117 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003118 netdev_info(adapter->port[i]->netdev,
3119 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003120 else
3121 ehea_remove_adapter_mr(adapter);
3122
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003123 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003124 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003125 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003126}
3127
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003128static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3129 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003130{
3131 struct device_node *lhea_dn;
3132 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003133 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003134
Grant Likely61c7a082010-04-13 16:12:29 -07003135 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003136 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003137
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003138 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003139 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003140 if (dn_log_port_id)
3141 if (*dn_log_port_id == logical_port_id)
3142 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003143 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003144
3145 return NULL;
3146}
3147
3148static ssize_t ehea_probe_port(struct device *dev,
3149 struct device_attribute *attr,
3150 const char *buf, size_t count)
3151{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003152 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003153 struct ehea_port *port;
3154 struct device_node *eth_dn = NULL;
3155 int i;
3156
3157 u32 logical_port_id;
3158
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003159 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003160
3161 port = ehea_get_port(adapter, logical_port_id);
3162
3163 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003164 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3165 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003166 return -EINVAL;
3167 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003168
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003169 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3170
3171 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003172 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003173 return -EINVAL;
3174 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003175
Thomas Klein1211bb62007-04-26 11:56:43 +02003176 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003177 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003178 return -EIO;
3179 }
3180
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003181 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3182
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003183 of_node_put(eth_dn);
3184
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003185 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003186 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003187 if (!adapter->port[i]) {
3188 adapter->port[i] = port;
3189 break;
3190 }
3191
Joe Perches8c4877a2010-12-13 10:05:14 -08003192 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3193 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003194 } else {
3195 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003196 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003197 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003198
3199 return (ssize_t) count;
3200}
3201
3202static ssize_t ehea_remove_port(struct device *dev,
3203 struct device_attribute *attr,
3204 const char *buf, size_t count)
3205{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003206 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003207 struct ehea_port *port;
3208 int i;
3209 u32 logical_port_id;
3210
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003211 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003212
3213 port = ehea_get_port(adapter, logical_port_id);
3214
3215 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003216 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3217 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003218
3219 ehea_shutdown_single_port(port);
3220
Doug Maxey508d2b52008-01-31 20:20:49 -06003221 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003222 if (adapter->port[i] == port) {
3223 adapter->port[i] = NULL;
3224 break;
3225 }
3226 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003227 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3228 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003229 return -EINVAL;
3230 }
3231
Thomas Klein1211bb62007-04-26 11:56:43 +02003232 ehea_remove_adapter_mr(adapter);
3233
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003234 return (ssize_t) count;
3235}
3236
3237static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3238static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3239
Grant Likely2dc11582010-08-06 09:25:50 -06003240int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003241{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003242 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003243 if (ret)
3244 goto out;
3245
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003246 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003247out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003248 return ret;
3249}
3250
Grant Likely2dc11582010-08-06 09:25:50 -06003251void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003252{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003253 device_remove_file(&dev->dev, &dev_attr_probe_port);
3254 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003255}
3256
Grant Likely2dc11582010-08-06 09:25:50 -06003257static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003258 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003259{
3260 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003261 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003262 int ret;
3263
Grant Likely61c7a082010-04-13 16:12:29 -07003264 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003265 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003266 return -EINVAL;
3267 }
3268
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003269 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3270 if (!adapter) {
3271 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003272 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003273 goto out;
3274 }
3275
Thomas Klein44c82152007-07-11 16:32:00 +02003276 list_add(&adapter->list, &adapter_list);
3277
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003278 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003279
Grant Likely61c7a082010-04-13 16:12:29 -07003280 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003281 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003282 if (adapter_handle)
3283 adapter->handle = *adapter_handle;
3284
3285 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003286 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003287 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003288 ret = -ENODEV;
3289 goto out_free_ad;
3290 }
3291
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003292 adapter->pd = EHEA_PD_ID;
3293
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003294 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003295
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003296
3297 /* initialize adapter and ports */
3298 /* get adapter properties */
3299 ret = ehea_sense_adapter_attr(adapter);
3300 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003301 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003302 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003303 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003304
3305 adapter->neq = ehea_create_eq(adapter,
3306 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3307 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003308 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003309 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003310 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003311 }
3312
3313 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3314 (unsigned long)adapter);
3315
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003316 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003317 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003318 "ehea_neq", adapter);
3319 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003320 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003321 goto out_kill_eq;
3322 }
3323
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003324 ret = ehea_create_device_sysfs(dev);
3325 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003326 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003328 ret = ehea_setup_ports(adapter);
3329 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003330 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003331 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003332 }
3333
3334 ret = 0;
3335 goto out;
3336
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003337out_rem_dev_sysfs:
3338 ehea_remove_device_sysfs(dev);
3339
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003340out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003341 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003342
3343out_kill_eq:
3344 ehea_destroy_eq(adapter->neq);
3345
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003346out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003347 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003348 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003349
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003350out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003351 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003352
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003353 return ret;
3354}
3355
Grant Likely2dc11582010-08-06 09:25:50 -06003356static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003357{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003358 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003359 int i;
3360
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003361 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003362 if (adapter->port[i]) {
3363 ehea_shutdown_single_port(adapter->port[i]);
3364 adapter->port[i] = NULL;
3365 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003366
3367 ehea_remove_device_sysfs(dev);
3368
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003369 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003370 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003371
3372 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003373 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003374 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003375 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003376
Thomas Klein21eee2d2008-02-13 16:18:33 +01003377 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003378
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003379 return 0;
3380}
3381
Thomas Klein21eee2d2008-02-13 16:18:33 +01003382void ehea_crash_handler(void)
3383{
3384 int i;
3385
3386 if (ehea_fw_handles.arr)
3387 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3388 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3389 ehea_fw_handles.arr[i].fwh,
3390 FORCE_FREE);
3391
3392 if (ehea_bcmc_regs.arr)
3393 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3394 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3395 ehea_bcmc_regs.arr[i].port_id,
3396 ehea_bcmc_regs.arr[i].reg_type,
3397 ehea_bcmc_regs.arr[i].macaddr,
3398 0, H_DEREG_BCMC);
3399}
3400
Hannes Hering48cfb142008-05-07 14:43:36 +02003401static int ehea_mem_notifier(struct notifier_block *nb,
3402 unsigned long action, void *data)
3403{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003404 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003405 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003406
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003407 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003408
Hannes Hering48cfb142008-05-07 14:43:36 +02003409 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003410 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003411 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003412 /* Readd canceled memory block */
3413 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003414 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003415 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003416 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003417 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003418 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003419 break;
3420 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003421 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003422 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003423 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003424 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003425 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003426 break;
3427 default:
3428 break;
3429 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003430
3431 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003432 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003433
Thomas Kleina7c561f22010-04-20 23:11:31 +00003434out_unlock:
3435 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003436 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003437}
3438
3439static struct notifier_block ehea_mem_nb = {
3440 .notifier_call = ehea_mem_notifier,
3441};
3442
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003443static int ehea_reboot_notifier(struct notifier_block *nb,
3444 unsigned long action, void *unused)
3445{
3446 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003447 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003448 ibmebus_unregister_driver(&ehea_driver);
3449 }
3450 return NOTIFY_DONE;
3451}
3452
3453static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003454 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003455};
3456
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003457static int check_module_parm(void)
3458{
3459 int ret = 0;
3460
3461 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3462 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003463 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003464 ret = -EINVAL;
3465 }
3466 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3467 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003468 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003469 ret = -EINVAL;
3470 }
3471 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3472 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003473 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003474 ret = -EINVAL;
3475 }
3476 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3477 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003478 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003479 ret = -EINVAL;
3480 }
3481
3482 return ret;
3483}
3484
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003485static ssize_t ehea_show_capabilities(struct device_driver *drv,
3486 char *buf)
3487{
3488 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3489}
3490
3491static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3492 ehea_show_capabilities, NULL);
3493
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003494int __init ehea_module_init(void)
3495{
3496 int ret;
3497
Joe Perches8c4877a2010-12-13 10:05:14 -08003498 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003499
Thomas Klein21eee2d2008-02-13 16:18:33 +01003500 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3501 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3502
Daniel Walker9f71a562008-03-28 14:41:26 -07003503 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003504 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003505
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003506 ret = check_module_parm();
3507 if (ret)
3508 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003509
3510 ret = ehea_create_busmap();
3511 if (ret)
3512 goto out;
3513
Thomas Klein21eee2d2008-02-13 16:18:33 +01003514 ret = register_reboot_notifier(&ehea_reboot_nb);
3515 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003516 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003517
Hannes Hering48cfb142008-05-07 14:43:36 +02003518 ret = register_memory_notifier(&ehea_mem_nb);
3519 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003520 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003521
Joe Perchesc061b182010-08-23 18:20:03 +00003522 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003523 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003524 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003525
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003526 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003527 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003528 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003529 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003530 }
3531
3532 ret = driver_create_file(&ehea_driver.driver,
3533 &driver_attr_capabilities);
3534 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003535 pr_err("failed to register capabilities attribute, ret=%d\n",
3536 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003537 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003538 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539
Thomas Klein21eee2d2008-02-13 16:18:33 +01003540 return ret;
3541
3542out3:
3543 ibmebus_unregister_driver(&ehea_driver);
3544out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003545 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003546 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003547 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003548out:
3549 return ret;
3550}
3551
3552static void __exit ehea_module_exit(void)
3553{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003554 int ret;
3555
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003556 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003558 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003559 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003560 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003561 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003562 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003563 kfree(ehea_fw_handles.arr);
3564 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003565 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003566}
3567
3568module_init(ehea_module_init);
3569module_exit(ehea_module_exit);