Commit | Line | Data |
---|---|---|
7a291083 JBT |
1 | /* |
2 | * linux/drivers/net/ehea/ehea_main.c | |
3 | * | |
4 | * eHEA ethernet device driver for IBM eServer System p | |
5 | * | |
6 | * (C) Copyright IBM Corp. 2006 | |
7 | * | |
8 | * Authors: | |
9 | * Christoph Raisch <raisch@de.ibm.com> | |
10 | * Jan-Bernd Themann <themann@de.ibm.com> | |
11 | * Thomas Klein <tklein@de.ibm.com> | |
12 | * | |
13 | * | |
14 | * This program is free software; you can redistribute it and/or modify | |
15 | * it under the terms of the GNU General Public License as published by | |
16 | * the Free Software Foundation; either version 2, or (at your option) | |
17 | * any later version. | |
18 | * | |
19 | * This program is distributed in the hope that it will be useful, | |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | * GNU General Public License for more details. | |
23 | * | |
24 | * You should have received a copy of the GNU General Public License | |
25 | * along with this program; if not, write to the Free Software | |
26 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
27 | */ | |
28 | ||
29 | #include <linux/in.h> | |
30 | #include <linux/ip.h> | |
31 | #include <linux/tcp.h> | |
32 | #include <linux/udp.h> | |
33 | #include <linux/if.h> | |
34 | #include <linux/list.h> | |
35 | #include <linux/if_ether.h> | |
36 | #include <net/ip.h> | |
37 | ||
38 | #include "ehea.h" | |
39 | #include "ehea_qmr.h" | |
40 | #include "ehea_phyp.h" | |
41 | ||
42 | ||
43 | MODULE_LICENSE("GPL"); | |
44 | MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); | |
45 | MODULE_DESCRIPTION("IBM eServer HEA Driver"); | |
46 | MODULE_VERSION(DRV_VERSION); | |
47 | ||
48 | ||
49 | static int msg_level = -1; | |
50 | static int rq1_entries = EHEA_DEF_ENTRIES_RQ1; | |
51 | static int rq2_entries = EHEA_DEF_ENTRIES_RQ2; | |
52 | static int rq3_entries = EHEA_DEF_ENTRIES_RQ3; | |
53 | static int sq_entries = EHEA_DEF_ENTRIES_SQ; | |
18604c54 | 54 | static int use_mcs = 0; |
d4dc4ec9 JBT |
55 | static int use_lro = 0; |
56 | static int lro_max_aggr = EHEA_LRO_MAX_AGGR; | |
18604c54 | 57 | static int num_tx_qps = EHEA_NUM_TX_QP; |
8759cf76 | 58 | static int prop_carrier_state = 0; |
7a291083 JBT |
59 | |
60 | module_param(msg_level, int, 0); | |
61 | module_param(rq1_entries, int, 0); | |
62 | module_param(rq2_entries, int, 0); | |
63 | module_param(rq3_entries, int, 0); | |
64 | module_param(sq_entries, int, 0); | |
8759cf76 | 65 | module_param(prop_carrier_state, int, 0); |
18604c54 | 66 | module_param(use_mcs, int, 0); |
d4dc4ec9 JBT |
67 | module_param(use_lro, int, 0); |
68 | module_param(lro_max_aggr, int, 0); | |
18604c54 | 69 | module_param(num_tx_qps, int, 0); |
7a291083 | 70 | |
18604c54 | 71 | MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS"); |
7a291083 | 72 | MODULE_PARM_DESC(msg_level, "msg_level"); |
8759cf76 JBT |
73 | MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical " |
74 | "port to stack. 1:yes, 0:no. Default = 0 "); | |
7a291083 JBT |
75 | MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 " |
76 | "[2^x - 1], x = [6..14]. Default = " | |
77 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")"); | |
78 | MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 " | |
79 | "[2^x - 1], x = [6..14]. Default = " | |
80 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")"); | |
81 | MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 " | |
82 | "[2^x - 1], x = [6..14]. Default = " | |
83 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")"); | |
84 | MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue " | |
85 | "[2^x - 1], x = [6..14]. Default = " | |
86 | __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")"); | |
18072a5b | 87 | MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 "); |
7a291083 | 88 | |
d4dc4ec9 JBT |
89 | MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = " |
90 | __MODULE_STRING(EHEA_LRO_MAX_AGGR)); | |
91 | MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, " | |
92 | "Default = 0"); | |
93 | ||
d1dea38d | 94 | static int port_name_cnt = 0; |
44c82152 TK |
95 | static LIST_HEAD(adapter_list); |
96 | u64 ehea_driver_flags = 0; | |
97 | struct workqueue_struct *ehea_driver_wq; | |
98 | struct work_struct ehea_rereg_mr_task; | |
99 | ||
d1dea38d TK |
100 | |
101 | static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev, | |
d1d25aab | 102 | const struct of_device_id *id); |
d1dea38d TK |
103 | |
104 | static int __devexit ehea_remove(struct ibmebus_dev *dev); | |
105 | ||
106 | static struct of_device_id ehea_device_table[] = { | |
107 | { | |
108 | .name = "lhea", | |
109 | .compatible = "IBM,lhea", | |
110 | }, | |
111 | {}, | |
112 | }; | |
113 | ||
114 | static struct ibmebus_driver ehea_driver = { | |
115 | .name = "ehea", | |
116 | .id_table = ehea_device_table, | |
117 | .probe = ehea_probe_adapter, | |
118 | .remove = ehea_remove, | |
119 | }; | |
120 | ||
7a291083 JBT |
121 | void ehea_dump(void *adr, int len, char *msg) { |
122 | int x; | |
123 | unsigned char *deb = adr; | |
124 | for (x = 0; x < len; x += 16) { | |
d2db9eea | 125 | printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg, |
7a291083 JBT |
126 | deb, x, *((u64*)&deb[0]), *((u64*)&deb[8])); |
127 | deb += 16; | |
128 | } | |
129 | } | |
130 | ||
131 | static struct net_device_stats *ehea_get_stats(struct net_device *dev) | |
132 | { | |
133 | struct ehea_port *port = netdev_priv(dev); | |
134 | struct net_device_stats *stats = &port->stats; | |
135 | struct hcp_ehea_port_cb2 *cb2; | |
136 | u64 hret, rx_packets; | |
137 | int i; | |
138 | ||
139 | memset(stats, 0, sizeof(*stats)); | |
140 | ||
a1d261c5 | 141 | cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
142 | if (!cb2) { |
143 | ehea_error("no mem for cb2"); | |
144 | goto out; | |
145 | } | |
146 | ||
147 | hret = ehea_h_query_ehea_port(port->adapter->handle, | |
148 | port->logical_port_id, | |
149 | H_PORT_CB2, H_PORT_CB2_ALL, cb2); | |
150 | if (hret != H_SUCCESS) { | |
151 | ehea_error("query_ehea_port failed"); | |
152 | goto out_herr; | |
153 | } | |
154 | ||
155 | if (netif_msg_hw(port)) | |
156 | ehea_dump(cb2, sizeof(*cb2), "net_device_stats"); | |
157 | ||
158 | rx_packets = 0; | |
159 | for (i = 0; i < port->num_def_qps; i++) | |
160 | rx_packets += port->port_res[i].rx_packets; | |
161 | ||
162 | stats->tx_packets = cb2->txucp + cb2->txmcp + cb2->txbcp; | |
163 | stats->multicast = cb2->rxmcp; | |
164 | stats->rx_errors = cb2->rxuerr; | |
165 | stats->rx_bytes = cb2->rxo; | |
166 | stats->tx_bytes = cb2->txo; | |
167 | stats->rx_packets = rx_packets; | |
168 | ||
169 | out_herr: | |
170 | kfree(cb2); | |
171 | out: | |
172 | return stats; | |
173 | } | |
174 | ||
175 | static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes) | |
176 | { | |
177 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; | |
178 | struct net_device *dev = pr->port->netdev; | |
179 | int max_index_mask = pr->rq1_skba.len - 1; | |
180 | int i; | |
181 | ||
182 | if (!nr_of_wqes) | |
183 | return; | |
184 | ||
185 | for (i = 0; i < nr_of_wqes; i++) { | |
186 | if (!skb_arr_rq1[index]) { | |
187 | skb_arr_rq1[index] = netdev_alloc_skb(dev, | |
188 | EHEA_L_PKT_SIZE); | |
189 | if (!skb_arr_rq1[index]) { | |
190 | ehea_error("%s: no mem for skb/%d wqes filled", | |
191 | dev->name, i); | |
192 | break; | |
193 | } | |
194 | } | |
195 | index--; | |
196 | index &= max_index_mask; | |
197 | } | |
198 | /* Ring doorbell */ | |
199 | ehea_update_rq1a(pr->qp, i); | |
200 | } | |
201 | ||
202 | static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a) | |
203 | { | |
204 | int ret = 0; | |
205 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; | |
206 | struct net_device *dev = pr->port->netdev; | |
207 | int i; | |
208 | ||
209 | for (i = 0; i < pr->rq1_skba.len; i++) { | |
210 | skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE); | |
211 | if (!skb_arr_rq1[i]) { | |
212 | ehea_error("%s: no mem for skb/%d wqes filled", | |
213 | dev->name, i); | |
214 | ret = -ENOMEM; | |
215 | goto out; | |
216 | } | |
217 | } | |
218 | /* Ring doorbell */ | |
219 | ehea_update_rq1a(pr->qp, nr_rq1a); | |
220 | out: | |
221 | return ret; | |
222 | } | |
223 | ||
224 | static int ehea_refill_rq_def(struct ehea_port_res *pr, | |
225 | struct ehea_q_skb_arr *q_skba, int rq_nr, | |
226 | int num_wqes, int wqe_type, int packet_size) | |
227 | { | |
228 | struct net_device *dev = pr->port->netdev; | |
229 | struct ehea_qp *qp = pr->qp; | |
230 | struct sk_buff **skb_arr = q_skba->arr; | |
231 | struct ehea_rwqe *rwqe; | |
232 | int i, index, max_index_mask, fill_wqes; | |
233 | int ret = 0; | |
234 | ||
235 | fill_wqes = q_skba->os_skbs + num_wqes; | |
236 | ||
237 | if (!fill_wqes) | |
238 | return ret; | |
239 | ||
240 | index = q_skba->index; | |
241 | max_index_mask = q_skba->len - 1; | |
242 | for (i = 0; i < fill_wqes; i++) { | |
243 | struct sk_buff *skb = netdev_alloc_skb(dev, packet_size); | |
244 | if (!skb) { | |
245 | ehea_error("%s: no mem for skb/%d wqes filled", | |
18604c54 | 246 | pr->port->netdev->name, i); |
7a291083 JBT |
247 | q_skba->os_skbs = fill_wqes - i; |
248 | ret = -ENOMEM; | |
249 | break; | |
250 | } | |
251 | skb_reserve(skb, NET_IP_ALIGN); | |
252 | ||
253 | skb_arr[index] = skb; | |
254 | ||
255 | rwqe = ehea_get_next_rwqe(qp, rq_nr); | |
256 | rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type) | |
d1d25aab | 257 | | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index); |
7a291083 | 258 | rwqe->sg_list[0].l_key = pr->recv_mr.lkey; |
44c82152 | 259 | rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data); |
7a291083 JBT |
260 | rwqe->sg_list[0].len = packet_size; |
261 | rwqe->data_segments = 1; | |
262 | ||
263 | index++; | |
264 | index &= max_index_mask; | |
44c82152 TK |
265 | |
266 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) | |
267 | goto out; | |
7a291083 | 268 | } |
44c82152 | 269 | |
7a291083 JBT |
270 | q_skba->index = index; |
271 | ||
272 | /* Ring doorbell */ | |
273 | iosync(); | |
274 | if (rq_nr == 2) | |
275 | ehea_update_rq2a(pr->qp, i); | |
276 | else | |
277 | ehea_update_rq3a(pr->qp, i); | |
44c82152 | 278 | out: |
7a291083 JBT |
279 | return ret; |
280 | } | |
281 | ||
282 | ||
283 | static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes) | |
284 | { | |
285 | return ehea_refill_rq_def(pr, &pr->rq2_skba, 2, | |
286 | nr_of_wqes, EHEA_RWQE2_TYPE, | |
287 | EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN); | |
288 | } | |
289 | ||
290 | ||
291 | static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes) | |
292 | { | |
293 | return ehea_refill_rq_def(pr, &pr->rq3_skba, 3, | |
294 | nr_of_wqes, EHEA_RWQE3_TYPE, | |
295 | EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN); | |
296 | } | |
297 | ||
298 | static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num) | |
299 | { | |
300 | *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5; | |
301 | if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0) | |
302 | return 0; | |
303 | if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) && | |
304 | (cqe->header_length == 0)) | |
305 | return 0; | |
306 | return -EINVAL; | |
307 | } | |
308 | ||
309 | static inline void ehea_fill_skb(struct net_device *dev, | |
310 | struct sk_buff *skb, struct ehea_cqe *cqe) | |
311 | { | |
312 | int length = cqe->num_bytes_transfered - 4; /*remove CRC */ | |
313 | ||
314 | skb_put(skb, length); | |
315 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
316 | skb->protocol = eth_type_trans(skb, dev); | |
317 | } | |
318 | ||
319 | static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array, | |
320 | int arr_len, | |
321 | struct ehea_cqe *cqe) | |
322 | { | |
323 | int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id); | |
324 | struct sk_buff *skb; | |
325 | void *pref; | |
326 | int x; | |
327 | ||
328 | x = skb_index + 1; | |
329 | x &= (arr_len - 1); | |
330 | ||
331 | pref = skb_array[x]; | |
332 | prefetchw(pref); | |
333 | prefetchw(pref + EHEA_CACHE_LINE); | |
334 | ||
335 | pref = (skb_array[x]->data); | |
336 | prefetch(pref); | |
337 | prefetch(pref + EHEA_CACHE_LINE); | |
338 | prefetch(pref + EHEA_CACHE_LINE * 2); | |
339 | prefetch(pref + EHEA_CACHE_LINE * 3); | |
340 | skb = skb_array[skb_index]; | |
341 | skb_array[skb_index] = NULL; | |
342 | return skb; | |
343 | } | |
344 | ||
345 | static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array, | |
346 | int arr_len, int wqe_index) | |
347 | { | |
348 | struct sk_buff *skb; | |
349 | void *pref; | |
350 | int x; | |
351 | ||
352 | x = wqe_index + 1; | |
353 | x &= (arr_len - 1); | |
354 | ||
355 | pref = skb_array[x]; | |
356 | prefetchw(pref); | |
357 | prefetchw(pref + EHEA_CACHE_LINE); | |
358 | ||
359 | pref = (skb_array[x]->data); | |
360 | prefetchw(pref); | |
361 | prefetchw(pref + EHEA_CACHE_LINE); | |
362 | ||
363 | skb = skb_array[wqe_index]; | |
364 | skb_array[wqe_index] = NULL; | |
365 | return skb; | |
366 | } | |
367 | ||
368 | static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq, | |
369 | struct ehea_cqe *cqe, int *processed_rq2, | |
370 | int *processed_rq3) | |
371 | { | |
372 | struct sk_buff *skb; | |
373 | ||
acbddb59 JBT |
374 | if (cqe->status & EHEA_CQE_STAT_ERR_TCP) |
375 | pr->p_stats.err_tcp_cksum++; | |
376 | if (cqe->status & EHEA_CQE_STAT_ERR_IP) | |
377 | pr->p_stats.err_ip_cksum++; | |
378 | if (cqe->status & EHEA_CQE_STAT_ERR_CRC) | |
379 | pr->p_stats.err_frame_crc++; | |
380 | ||
7a291083 JBT |
381 | if (netif_msg_rx_err(pr->port)) { |
382 | ehea_error("CQE Error for QP %d", pr->qp->init_attr.qp_nr); | |
383 | ehea_dump(cqe, sizeof(*cqe), "CQE"); | |
384 | } | |
385 | ||
386 | if (rq == 2) { | |
387 | *processed_rq2 += 1; | |
388 | skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe); | |
389 | dev_kfree_skb(skb); | |
390 | } else if (rq == 3) { | |
391 | *processed_rq3 += 1; | |
392 | skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe); | |
393 | dev_kfree_skb(skb); | |
394 | } | |
395 | ||
396 | if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) { | |
397 | ehea_error("Critical receive error. Resetting port."); | |
398 | queue_work(pr->port->adapter->ehea_wq, &pr->port->reset_task); | |
399 | return 1; | |
400 | } | |
401 | ||
402 | return 0; | |
403 | } | |
404 | ||
d4dc4ec9 JBT |
405 | static int get_skb_hdr(struct sk_buff *skb, void **iphdr, |
406 | void **tcph, u64 *hdr_flags, void *priv) | |
407 | { | |
408 | struct ehea_cqe *cqe = priv; | |
409 | unsigned int ip_len; | |
410 | struct iphdr *iph; | |
411 | ||
412 | /* non tcp/udp packets */ | |
413 | if (!cqe->header_length) | |
414 | return -1; | |
415 | ||
416 | /* non tcp packet */ | |
417 | skb_reset_network_header(skb); | |
418 | iph = ip_hdr(skb); | |
419 | if (iph->protocol != IPPROTO_TCP) | |
420 | return -1; | |
421 | ||
422 | ip_len = ip_hdrlen(skb); | |
423 | skb_set_transport_header(skb, ip_len); | |
424 | *tcph = tcp_hdr(skb); | |
425 | ||
426 | /* check if ip header and tcp header are complete */ | |
427 | if (iph->tot_len < ip_len + tcp_hdrlen(skb)) | |
428 | return -1; | |
429 | ||
430 | *hdr_flags = LRO_IPV4 | LRO_TCP; | |
431 | *iphdr = iph; | |
432 | ||
433 | return 0; | |
434 | } | |
435 | ||
436 | static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe, | |
437 | struct sk_buff *skb) | |
438 | { | |
439 | int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) | |
440 | && pr->port->vgrp; | |
441 | ||
442 | if (use_lro) { | |
443 | if (vlan_extracted) | |
444 | lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb, | |
445 | pr->port->vgrp, | |
446 | cqe->vlan_tag, | |
447 | cqe); | |
448 | else | |
449 | lro_receive_skb(&pr->lro_mgr, skb, cqe); | |
450 | } else { | |
451 | if (vlan_extracted) | |
452 | vlan_hwaccel_receive_skb(skb, pr->port->vgrp, | |
453 | cqe->vlan_tag); | |
454 | else | |
455 | netif_receive_skb(skb); | |
456 | } | |
457 | } | |
458 | ||
bea3348e SH |
459 | static int ehea_proc_rwqes(struct net_device *dev, |
460 | struct ehea_port_res *pr, | |
461 | int budget) | |
7a291083 | 462 | { |
18604c54 | 463 | struct ehea_port *port = pr->port; |
7a291083 JBT |
464 | struct ehea_qp *qp = pr->qp; |
465 | struct ehea_cqe *cqe; | |
466 | struct sk_buff *skb; | |
467 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; | |
468 | struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr; | |
469 | struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr; | |
470 | int skb_arr_rq1_len = pr->rq1_skba.len; | |
471 | int skb_arr_rq2_len = pr->rq2_skba.len; | |
472 | int skb_arr_rq3_len = pr->rq3_skba.len; | |
473 | int processed, processed_rq1, processed_rq2, processed_rq3; | |
bea3348e | 474 | int wqe_index, last_wqe_index, rq, port_reset; |
7a291083 JBT |
475 | |
476 | processed = processed_rq1 = processed_rq2 = processed_rq3 = 0; | |
477 | last_wqe_index = 0; | |
7a291083 | 478 | |
7a291083 | 479 | cqe = ehea_poll_rq1(qp, &wqe_index); |
bea3348e | 480 | while ((processed < budget) && cqe) { |
7a291083 JBT |
481 | ehea_inc_rq1(qp); |
482 | processed_rq1++; | |
483 | processed++; | |
7a291083 JBT |
484 | if (netif_msg_rx_status(port)) |
485 | ehea_dump(cqe, sizeof(*cqe), "CQE"); | |
486 | ||
487 | last_wqe_index = wqe_index; | |
488 | rmb(); | |
489 | if (!ehea_check_cqe(cqe, &rq)) { | |
490 | if (rq == 1) { /* LL RQ1 */ | |
491 | skb = get_skb_by_index_ll(skb_arr_rq1, | |
492 | skb_arr_rq1_len, | |
493 | wqe_index); | |
494 | if (unlikely(!skb)) { | |
495 | if (netif_msg_rx_err(port)) | |
496 | ehea_error("LL rq1: skb=NULL"); | |
18604c54 | 497 | |
bea3348e | 498 | skb = netdev_alloc_skb(dev, |
7a291083 JBT |
499 | EHEA_L_PKT_SIZE); |
500 | if (!skb) | |
501 | break; | |
502 | } | |
27d7ff46 | 503 | skb_copy_to_linear_data(skb, ((char*)cqe) + 64, |
d1d25aab | 504 | cqe->num_bytes_transfered - 4); |
bea3348e | 505 | ehea_fill_skb(dev, skb, cqe); |
7a291083 JBT |
506 | } else if (rq == 2) { /* RQ2 */ |
507 | skb = get_skb_by_index(skb_arr_rq2, | |
508 | skb_arr_rq2_len, cqe); | |
509 | if (unlikely(!skb)) { | |
510 | if (netif_msg_rx_err(port)) | |
511 | ehea_error("rq2: skb=NULL"); | |
512 | break; | |
513 | } | |
bea3348e | 514 | ehea_fill_skb(dev, skb, cqe); |
7a291083 JBT |
515 | processed_rq2++; |
516 | } else { /* RQ3 */ | |
517 | skb = get_skb_by_index(skb_arr_rq3, | |
518 | skb_arr_rq3_len, cqe); | |
519 | if (unlikely(!skb)) { | |
520 | if (netif_msg_rx_err(port)) | |
521 | ehea_error("rq3: skb=NULL"); | |
522 | break; | |
523 | } | |
bea3348e | 524 | ehea_fill_skb(dev, skb, cqe); |
7a291083 JBT |
525 | processed_rq3++; |
526 | } | |
527 | ||
d4dc4ec9 | 528 | ehea_proc_skb(pr, cqe, skb); |
bea3348e | 529 | dev->last_rx = jiffies; |
18604c54 | 530 | } else { |
acbddb59 | 531 | pr->p_stats.poll_receive_errors++; |
7a291083 JBT |
532 | port_reset = ehea_treat_poll_error(pr, rq, cqe, |
533 | &processed_rq2, | |
534 | &processed_rq3); | |
535 | if (port_reset) | |
536 | break; | |
537 | } | |
538 | cqe = ehea_poll_rq1(qp, &wqe_index); | |
539 | } | |
d4dc4ec9 JBT |
540 | if (use_lro) |
541 | lro_flush_all(&pr->lro_mgr); | |
7a291083 | 542 | |
7a291083 JBT |
543 | pr->rx_packets += processed; |
544 | ||
545 | ehea_refill_rq1(pr, last_wqe_index, processed_rq1); | |
546 | ehea_refill_rq2(pr, processed_rq2); | |
547 | ehea_refill_rq3(pr, processed_rq3); | |
548 | ||
bea3348e | 549 | return processed; |
7a291083 JBT |
550 | } |
551 | ||
18604c54 | 552 | static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota) |
7a291083 | 553 | { |
acbddb59 | 554 | struct sk_buff *skb; |
7a291083 JBT |
555 | struct ehea_cq *send_cq = pr->send_cq; |
556 | struct ehea_cqe *cqe; | |
18604c54 | 557 | int quota = my_quota; |
7a291083 JBT |
558 | int cqe_counter = 0; |
559 | int swqe_av = 0; | |
acbddb59 | 560 | int index; |
7a291083 JBT |
561 | unsigned long flags; |
562 | ||
18604c54 JBT |
563 | cqe = ehea_poll_cq(send_cq); |
564 | while(cqe && (quota > 0)) { | |
565 | ehea_inc_cq(send_cq); | |
566 | ||
7a291083 JBT |
567 | cqe_counter++; |
568 | rmb(); | |
569 | if (cqe->status & EHEA_CQE_STAT_ERR_MASK) { | |
570 | ehea_error("Send Completion Error: Resetting port"); | |
571 | if (netif_msg_tx_err(pr->port)) | |
572 | ehea_dump(cqe, sizeof(*cqe), "Send CQE"); | |
573 | queue_work(pr->port->adapter->ehea_wq, | |
574 | &pr->port->reset_task); | |
575 | break; | |
576 | } | |
577 | ||
578 | if (netif_msg_tx_done(pr->port)) | |
579 | ehea_dump(cqe, sizeof(*cqe), "CQE"); | |
580 | ||
581 | if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id) | |
acbddb59 JBT |
582 | == EHEA_SWQE2_TYPE)) { |
583 | ||
584 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id); | |
585 | skb = pr->sq_skba.arr[index]; | |
586 | dev_kfree_skb(skb); | |
587 | pr->sq_skba.arr[index] = NULL; | |
588 | } | |
7a291083 JBT |
589 | |
590 | swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id); | |
591 | quota--; | |
18604c54 JBT |
592 | |
593 | cqe = ehea_poll_cq(send_cq); | |
594 | }; | |
7a291083 JBT |
595 | |
596 | ehea_update_feca(send_cq, cqe_counter); | |
597 | atomic_add(swqe_av, &pr->swqe_avail); | |
598 | ||
599 | spin_lock_irqsave(&pr->netif_queue, flags); | |
18604c54 | 600 | |
7a291083 JBT |
601 | if (pr->queue_stopped && (atomic_read(&pr->swqe_avail) |
602 | >= pr->swqe_refill_th)) { | |
603 | netif_wake_queue(pr->port->netdev); | |
604 | pr->queue_stopped = 0; | |
605 | } | |
606 | spin_unlock_irqrestore(&pr->netif_queue, flags); | |
607 | ||
18604c54 | 608 | return cqe; |
7a291083 JBT |
609 | } |
610 | ||
18604c54 | 611 | #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16 |
bea3348e | 612 | #define EHEA_POLL_MAX_CQES 65535 |
18604c54 | 613 | |
bea3348e | 614 | static int ehea_poll(struct napi_struct *napi, int budget) |
7a291083 | 615 | { |
bea3348e SH |
616 | struct ehea_port_res *pr = container_of(napi, struct ehea_port_res, napi); |
617 | struct net_device *dev = pr->port->netdev; | |
18604c54 JBT |
618 | struct ehea_cqe *cqe; |
619 | struct ehea_cqe *cqe_skb = NULL; | |
620 | int force_irq, wqe_index; | |
bea3348e | 621 | int rx = 0; |
18604c54 JBT |
622 | |
623 | force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ); | |
bea3348e SH |
624 | cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES); |
625 | ||
626 | if (!force_irq) | |
627 | rx += ehea_proc_rwqes(dev, pr, budget - rx); | |
18604c54 | 628 | |
bea3348e | 629 | while ((rx != budget) || force_irq) { |
18604c54 | 630 | pr->poll_counter = 0; |
bea3348e SH |
631 | force_irq = 0; |
632 | netif_rx_complete(dev, napi); | |
18604c54 JBT |
633 | ehea_reset_cq_ep(pr->recv_cq); |
634 | ehea_reset_cq_ep(pr->send_cq); | |
635 | ehea_reset_cq_n1(pr->recv_cq); | |
636 | ehea_reset_cq_n1(pr->send_cq); | |
637 | cqe = ehea_poll_rq1(pr->qp, &wqe_index); | |
638 | cqe_skb = ehea_poll_cq(pr->send_cq); | |
639 | ||
e542aa6b | 640 | if (!cqe && !cqe_skb) |
bea3348e | 641 | return rx; |
18604c54 | 642 | |
bea3348e SH |
643 | if (!netif_rx_reschedule(dev, napi)) |
644 | return rx; | |
18604c54 | 645 | |
bea3348e SH |
646 | cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES); |
647 | rx += ehea_proc_rwqes(dev, pr, budget - rx); | |
648 | } | |
e542aa6b | 649 | |
bea3348e SH |
650 | pr->poll_counter++; |
651 | return rx; | |
7a291083 JBT |
652 | } |
653 | ||
8d22c971 JBT |
654 | #ifdef CONFIG_NET_POLL_CONTROLLER |
655 | static void ehea_netpoll(struct net_device *dev) | |
656 | { | |
657 | struct ehea_port *port = netdev_priv(dev); | |
bea3348e | 658 | int i; |
8d22c971 | 659 | |
bea3348e SH |
660 | for (i = 0; i < port->num_def_qps; i++) |
661 | netif_rx_schedule(dev, &port->port_res[i].napi); | |
8d22c971 JBT |
662 | } |
663 | #endif | |
664 | ||
7d12e780 | 665 | static irqreturn_t ehea_recv_irq_handler(int irq, void *param) |
7a291083 JBT |
666 | { |
667 | struct ehea_port_res *pr = param; | |
18604c54 | 668 | |
bea3348e | 669 | netif_rx_schedule(pr->port->netdev, &pr->napi); |
18604c54 | 670 | |
7a291083 JBT |
671 | return IRQ_HANDLED; |
672 | } | |
673 | ||
7d12e780 | 674 | static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param) |
7a291083 JBT |
675 | { |
676 | struct ehea_port *port = param; | |
677 | struct ehea_eqe *eqe; | |
d2db9eea | 678 | struct ehea_qp *qp; |
7a291083 JBT |
679 | u32 qp_token; |
680 | ||
681 | eqe = ehea_poll_eq(port->qp_eq); | |
bb3a6449 | 682 | |
7a291083 | 683 | while (eqe) { |
7a291083 | 684 | qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry); |
bb3a6449 TK |
685 | ehea_error("QP aff_err: entry=0x%lx, token=0x%x", |
686 | eqe->entry, qp_token); | |
d2db9eea JBT |
687 | |
688 | qp = port->port_res[qp_token].qp; | |
689 | ehea_error_data(port->adapter, qp->fw_handle); | |
bb3a6449 | 690 | eqe = ehea_poll_eq(port->qp_eq); |
7a291083 JBT |
691 | } |
692 | ||
d2db9eea JBT |
693 | queue_work(port->adapter->ehea_wq, &port->reset_task); |
694 | ||
7a291083 JBT |
695 | return IRQ_HANDLED; |
696 | } | |
697 | ||
698 | static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter, | |
699 | int logical_port) | |
700 | { | |
701 | int i; | |
702 | ||
1acf2318 | 703 | for (i = 0; i < EHEA_MAX_PORTS; i++) |
41b69c70 | 704 | if (adapter->port[i]) |
d1d25aab | 705 | if (adapter->port[i]->logical_port_id == logical_port) |
41b69c70 | 706 | return adapter->port[i]; |
7a291083 JBT |
707 | return NULL; |
708 | } | |
709 | ||
710 | int ehea_sense_port_attr(struct ehea_port *port) | |
711 | { | |
712 | int ret; | |
713 | u64 hret; | |
714 | struct hcp_ehea_port_cb0 *cb0; | |
715 | ||
a1d261c5 TK |
716 | cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC); /* May be called via */ |
717 | if (!cb0) { /* ehea_neq_tasklet() */ | |
7a291083 JBT |
718 | ehea_error("no mem for cb0"); |
719 | ret = -ENOMEM; | |
720 | goto out; | |
721 | } | |
722 | ||
723 | hret = ehea_h_query_ehea_port(port->adapter->handle, | |
724 | port->logical_port_id, H_PORT_CB0, | |
725 | EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF), | |
726 | cb0); | |
727 | if (hret != H_SUCCESS) { | |
728 | ret = -EIO; | |
729 | goto out_free; | |
730 | } | |
731 | ||
732 | /* MAC address */ | |
733 | port->mac_addr = cb0->port_mac_addr << 16; | |
734 | ||
735 | if (!is_valid_ether_addr((u8*)&port->mac_addr)) { | |
736 | ret = -EADDRNOTAVAIL; | |
737 | goto out_free; | |
738 | } | |
739 | ||
740 | /* Port speed */ | |
741 | switch (cb0->port_speed) { | |
742 | case H_SPEED_10M_H: | |
743 | port->port_speed = EHEA_SPEED_10M; | |
744 | port->full_duplex = 0; | |
745 | break; | |
746 | case H_SPEED_10M_F: | |
747 | port->port_speed = EHEA_SPEED_10M; | |
748 | port->full_duplex = 1; | |
749 | break; | |
750 | case H_SPEED_100M_H: | |
751 | port->port_speed = EHEA_SPEED_100M; | |
752 | port->full_duplex = 0; | |
753 | break; | |
754 | case H_SPEED_100M_F: | |
755 | port->port_speed = EHEA_SPEED_100M; | |
756 | port->full_duplex = 1; | |
757 | break; | |
758 | case H_SPEED_1G_F: | |
759 | port->port_speed = EHEA_SPEED_1G; | |
760 | port->full_duplex = 1; | |
761 | break; | |
762 | case H_SPEED_10G_F: | |
763 | port->port_speed = EHEA_SPEED_10G; | |
764 | port->full_duplex = 1; | |
765 | break; | |
766 | default: | |
767 | port->port_speed = 0; | |
768 | port->full_duplex = 0; | |
769 | break; | |
770 | } | |
771 | ||
e919b593 | 772 | port->autoneg = 1; |
18604c54 | 773 | port->num_mcs = cb0->num_default_qps; |
e919b593 | 774 | |
7a291083 | 775 | /* Number of default QPs */ |
18604c54 JBT |
776 | if (use_mcs) |
777 | port->num_def_qps = cb0->num_default_qps; | |
778 | else | |
779 | port->num_def_qps = 1; | |
7a291083 JBT |
780 | |
781 | if (!port->num_def_qps) { | |
782 | ret = -EINVAL; | |
783 | goto out_free; | |
784 | } | |
785 | ||
18604c54 JBT |
786 | port->num_tx_qps = num_tx_qps; |
787 | ||
788 | if (port->num_def_qps >= port->num_tx_qps) | |
7a291083 JBT |
789 | port->num_add_tx_qps = 0; |
790 | else | |
18604c54 | 791 | port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps; |
7a291083 JBT |
792 | |
793 | ret = 0; | |
794 | out_free: | |
795 | if (ret || netif_msg_probe(port)) | |
796 | ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr"); | |
797 | kfree(cb0); | |
798 | out: | |
799 | return ret; | |
800 | } | |
801 | ||
802 | int ehea_set_portspeed(struct ehea_port *port, u32 port_speed) | |
803 | { | |
804 | struct hcp_ehea_port_cb4 *cb4; | |
805 | u64 hret; | |
806 | int ret = 0; | |
807 | ||
a1d261c5 | 808 | cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
809 | if (!cb4) { |
810 | ehea_error("no mem for cb4"); | |
811 | ret = -ENOMEM; | |
812 | goto out; | |
813 | } | |
814 | ||
815 | cb4->port_speed = port_speed; | |
816 | ||
817 | netif_carrier_off(port->netdev); | |
818 | ||
819 | hret = ehea_h_modify_ehea_port(port->adapter->handle, | |
820 | port->logical_port_id, | |
821 | H_PORT_CB4, H_PORT_CB4_SPEED, cb4); | |
822 | if (hret == H_SUCCESS) { | |
823 | port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0; | |
824 | ||
825 | hret = ehea_h_query_ehea_port(port->adapter->handle, | |
826 | port->logical_port_id, | |
827 | H_PORT_CB4, H_PORT_CB4_SPEED, | |
828 | cb4); | |
829 | if (hret == H_SUCCESS) { | |
830 | switch (cb4->port_speed) { | |
831 | case H_SPEED_10M_H: | |
832 | port->port_speed = EHEA_SPEED_10M; | |
833 | port->full_duplex = 0; | |
834 | break; | |
835 | case H_SPEED_10M_F: | |
836 | port->port_speed = EHEA_SPEED_10M; | |
837 | port->full_duplex = 1; | |
838 | break; | |
839 | case H_SPEED_100M_H: | |
840 | port->port_speed = EHEA_SPEED_100M; | |
841 | port->full_duplex = 0; | |
842 | break; | |
843 | case H_SPEED_100M_F: | |
844 | port->port_speed = EHEA_SPEED_100M; | |
845 | port->full_duplex = 1; | |
846 | break; | |
847 | case H_SPEED_1G_F: | |
848 | port->port_speed = EHEA_SPEED_1G; | |
849 | port->full_duplex = 1; | |
850 | break; | |
851 | case H_SPEED_10G_F: | |
852 | port->port_speed = EHEA_SPEED_10G; | |
853 | port->full_duplex = 1; | |
854 | break; | |
855 | default: | |
856 | port->port_speed = 0; | |
857 | port->full_duplex = 0; | |
858 | break; | |
859 | } | |
860 | } else { | |
861 | ehea_error("Failed sensing port speed"); | |
862 | ret = -EIO; | |
863 | } | |
864 | } else { | |
865 | if (hret == H_AUTHORITY) { | |
7674a588 | 866 | ehea_info("Hypervisor denied setting port speed"); |
7a291083 JBT |
867 | ret = -EPERM; |
868 | } else { | |
869 | ret = -EIO; | |
870 | ehea_error("Failed setting port speed"); | |
871 | } | |
872 | } | |
8759cf76 JBT |
873 | if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP)) |
874 | netif_carrier_on(port->netdev); | |
875 | ||
7a291083 JBT |
876 | kfree(cb4); |
877 | out: | |
878 | return ret; | |
879 | } | |
880 | ||
881 | static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe) | |
882 | { | |
883 | int ret; | |
884 | u8 ec; | |
885 | u8 portnum; | |
886 | struct ehea_port *port; | |
887 | ||
888 | ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe); | |
889 | portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe); | |
890 | port = ehea_get_port(adapter, portnum); | |
891 | ||
892 | switch (ec) { | |
893 | case EHEA_EC_PORTSTATE_CHG: /* port state change */ | |
894 | ||
895 | if (!port) { | |
896 | ehea_error("unknown portnum %x", portnum); | |
897 | break; | |
898 | } | |
899 | ||
900 | if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) { | |
901 | if (!netif_carrier_ok(port->netdev)) { | |
1e1675cc | 902 | ret = ehea_sense_port_attr(port); |
7a291083 JBT |
903 | if (ret) { |
904 | ehea_error("failed resensing port " | |
905 | "attributes"); | |
906 | break; | |
907 | } | |
908 | ||
909 | if (netif_msg_link(port)) | |
910 | ehea_info("%s: Logical port up: %dMbps " | |
911 | "%s Duplex", | |
912 | port->netdev->name, | |
913 | port->port_speed, | |
914 | port->full_duplex == | |
915 | 1 ? "Full" : "Half"); | |
916 | ||
917 | netif_carrier_on(port->netdev); | |
918 | netif_wake_queue(port->netdev); | |
919 | } | |
920 | } else | |
921 | if (netif_carrier_ok(port->netdev)) { | |
922 | if (netif_msg_link(port)) | |
923 | ehea_info("%s: Logical port down", | |
924 | port->netdev->name); | |
925 | netif_carrier_off(port->netdev); | |
926 | netif_stop_queue(port->netdev); | |
927 | } | |
928 | ||
929 | if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) { | |
8759cf76 | 930 | port->phy_link = EHEA_PHY_LINK_UP; |
7a291083 JBT |
931 | if (netif_msg_link(port)) |
932 | ehea_info("%s: Physical port up", | |
933 | port->netdev->name); | |
8759cf76 JBT |
934 | if (prop_carrier_state) |
935 | netif_carrier_on(port->netdev); | |
7a291083 | 936 | } else { |
8759cf76 | 937 | port->phy_link = EHEA_PHY_LINK_DOWN; |
7a291083 JBT |
938 | if (netif_msg_link(port)) |
939 | ehea_info("%s: Physical port down", | |
940 | port->netdev->name); | |
8759cf76 JBT |
941 | if (prop_carrier_state) |
942 | netif_carrier_off(port->netdev); | |
7a291083 JBT |
943 | } |
944 | ||
945 | if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe)) | |
946 | ehea_info("External switch port is primary port"); | |
947 | else | |
948 | ehea_info("External switch port is backup port"); | |
949 | ||
950 | break; | |
951 | case EHEA_EC_ADAPTER_MALFUNC: | |
952 | ehea_error("Adapter malfunction"); | |
953 | break; | |
954 | case EHEA_EC_PORT_MALFUNC: | |
955 | ehea_info("Port malfunction: Device: %s", port->netdev->name); | |
956 | netif_carrier_off(port->netdev); | |
957 | netif_stop_queue(port->netdev); | |
958 | break; | |
959 | default: | |
bff0a55f | 960 | ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe); |
7a291083 JBT |
961 | break; |
962 | } | |
963 | } | |
964 | ||
965 | static void ehea_neq_tasklet(unsigned long data) | |
966 | { | |
967 | struct ehea_adapter *adapter = (struct ehea_adapter*)data; | |
968 | struct ehea_eqe *eqe; | |
969 | u64 event_mask; | |
970 | ||
971 | eqe = ehea_poll_eq(adapter->neq); | |
972 | ehea_debug("eqe=%p", eqe); | |
973 | ||
974 | while (eqe) { | |
975 | ehea_debug("*eqe=%lx", eqe->entry); | |
976 | ehea_parse_eqe(adapter, eqe->entry); | |
977 | eqe = ehea_poll_eq(adapter->neq); | |
978 | ehea_debug("next eqe=%p", eqe); | |
979 | } | |
980 | ||
981 | event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1) | |
982 | | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1) | |
983 | | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1); | |
984 | ||
985 | ehea_h_reset_events(adapter->handle, | |
986 | adapter->neq->fw_handle, event_mask); | |
987 | } | |
988 | ||
7d12e780 | 989 | static irqreturn_t ehea_interrupt_neq(int irq, void *param) |
7a291083 JBT |
990 | { |
991 | struct ehea_adapter *adapter = param; | |
992 | tasklet_hi_schedule(&adapter->neq_tasklet); | |
993 | return IRQ_HANDLED; | |
994 | } | |
995 | ||
996 | ||
997 | static int ehea_fill_port_res(struct ehea_port_res *pr) | |
998 | { | |
999 | int ret; | |
1000 | struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr; | |
1001 | ||
1002 | ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1 | |
1003 | - init_attr->act_nr_rwqes_rq2 | |
1004 | - init_attr->act_nr_rwqes_rq3 - 1); | |
1005 | ||
1006 | ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1); | |
1007 | ||
1008 | ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1); | |
1009 | ||
1010 | return ret; | |
1011 | } | |
1012 | ||
1013 | static int ehea_reg_interrupts(struct net_device *dev) | |
1014 | { | |
1015 | struct ehea_port *port = netdev_priv(dev); | |
1016 | struct ehea_port_res *pr; | |
1017 | int i, ret; | |
1018 | ||
7a291083 JBT |
1019 | |
1020 | snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff", | |
1021 | dev->name); | |
1022 | ||
1023 | ret = ibmebus_request_irq(NULL, port->qp_eq->attr.ist1, | |
1024 | ehea_qp_aff_irq_handler, | |
38515e90 | 1025 | IRQF_DISABLED, port->int_aff_name, port); |
7a291083 JBT |
1026 | if (ret) { |
1027 | ehea_error("failed registering irq for qp_aff_irq_handler:" | |
1028 | "ist=%X", port->qp_eq->attr.ist1); | |
1029 | goto out_free_qpeq; | |
1030 | } | |
1031 | ||
1032 | if (netif_msg_ifup(port)) | |
1033 | ehea_info("irq_handle 0x%X for function qp_aff_irq_handler " | |
1034 | "registered", port->qp_eq->attr.ist1); | |
1035 | ||
18604c54 | 1036 | |
7a291083 JBT |
1037 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
1038 | pr = &port->port_res[i]; | |
1039 | snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1, | |
18604c54 JBT |
1040 | "%s-queue%d", dev->name, i); |
1041 | ret = ibmebus_request_irq(NULL, pr->eq->attr.ist1, | |
1042 | ehea_recv_irq_handler, | |
38515e90 | 1043 | IRQF_DISABLED, pr->int_send_name, |
7a291083 JBT |
1044 | pr); |
1045 | if (ret) { | |
18604c54 | 1046 | ehea_error("failed registering irq for ehea_queue " |
7a291083 | 1047 | "port_res_nr:%d, ist=%X", i, |
18604c54 | 1048 | pr->eq->attr.ist1); |
7a291083 JBT |
1049 | goto out_free_req; |
1050 | } | |
1051 | if (netif_msg_ifup(port)) | |
18604c54 JBT |
1052 | ehea_info("irq_handle 0x%X for function ehea_queue_int " |
1053 | "%d registered", pr->eq->attr.ist1, i); | |
7a291083 JBT |
1054 | } |
1055 | out: | |
1056 | return ret; | |
1057 | ||
18604c54 | 1058 | |
7a291083 JBT |
1059 | out_free_req: |
1060 | while (--i >= 0) { | |
18604c54 | 1061 | u32 ist = port->port_res[i].eq->attr.ist1; |
7a291083 JBT |
1062 | ibmebus_free_irq(NULL, ist, &port->port_res[i]); |
1063 | } | |
18604c54 | 1064 | |
7a291083 JBT |
1065 | out_free_qpeq: |
1066 | ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port); | |
1067 | i = port->num_def_qps; | |
18604c54 | 1068 | |
7a291083 | 1069 | goto out; |
18604c54 | 1070 | |
7a291083 JBT |
1071 | } |
1072 | ||
1073 | static void ehea_free_interrupts(struct net_device *dev) | |
1074 | { | |
1075 | struct ehea_port *port = netdev_priv(dev); | |
1076 | struct ehea_port_res *pr; | |
1077 | int i; | |
1078 | ||
1079 | /* send */ | |
18604c54 | 1080 | |
7a291083 JBT |
1081 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { |
1082 | pr = &port->port_res[i]; | |
18604c54 | 1083 | ibmebus_free_irq(NULL, pr->eq->attr.ist1, pr); |
7a291083 JBT |
1084 | if (netif_msg_intr(port)) |
1085 | ehea_info("free send irq for res %d with handle 0x%X", | |
18604c54 | 1086 | i, pr->eq->attr.ist1); |
7a291083 JBT |
1087 | } |
1088 | ||
1089 | /* associated events */ | |
1090 | ibmebus_free_irq(NULL, port->qp_eq->attr.ist1, port); | |
1091 | if (netif_msg_intr(port)) | |
1092 | ehea_info("associated event interrupt for handle 0x%X freed", | |
1093 | port->qp_eq->attr.ist1); | |
1094 | } | |
1095 | ||
1096 | static int ehea_configure_port(struct ehea_port *port) | |
1097 | { | |
1098 | int ret, i; | |
1099 | u64 hret, mask; | |
1100 | struct hcp_ehea_port_cb0 *cb0; | |
1101 | ||
1102 | ret = -ENOMEM; | |
a1d261c5 | 1103 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
1104 | if (!cb0) |
1105 | goto out; | |
1106 | ||
1107 | cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1) | |
1108 | | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1) | |
1109 | | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1) | |
1110 | | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1) | |
1111 | | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER, | |
1112 | PXLY_RC_VLAN_FILTER) | |
1113 | | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1); | |
1114 | ||
18604c54 JBT |
1115 | for (i = 0; i < port->num_mcs; i++) |
1116 | if (use_mcs) | |
1117 | cb0->default_qpn_arr[i] = | |
1118 | port->port_res[i].qp->init_attr.qp_nr; | |
1119 | else | |
1120 | cb0->default_qpn_arr[i] = | |
1121 | port->port_res[0].qp->init_attr.qp_nr; | |
e542aa6b | 1122 | |
7a291083 JBT |
1123 | if (netif_msg_ifup(port)) |
1124 | ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port"); | |
1125 | ||
1126 | mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1) | |
1127 | | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1); | |
1128 | ||
1129 | hret = ehea_h_modify_ehea_port(port->adapter->handle, | |
1130 | port->logical_port_id, | |
1131 | H_PORT_CB0, mask, cb0); | |
1132 | ret = -EIO; | |
1133 | if (hret != H_SUCCESS) | |
1134 | goto out_free; | |
1135 | ||
1136 | ret = 0; | |
1137 | ||
1138 | out_free: | |
1139 | kfree(cb0); | |
1140 | out: | |
1141 | return ret; | |
1142 | } | |
1143 | ||
e542aa6b | 1144 | int ehea_gen_smrs(struct ehea_port_res *pr) |
7a291083 | 1145 | { |
e542aa6b | 1146 | int ret; |
7a291083 JBT |
1147 | struct ehea_adapter *adapter = pr->port->adapter; |
1148 | ||
e542aa6b JBT |
1149 | ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr); |
1150 | if (ret) | |
7a291083 JBT |
1151 | goto out; |
1152 | ||
e542aa6b JBT |
1153 | ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr); |
1154 | if (ret) | |
1155 | goto out_free; | |
7a291083 JBT |
1156 | |
1157 | return 0; | |
1158 | ||
e542aa6b JBT |
1159 | out_free: |
1160 | ehea_rem_mr(&pr->send_mr); | |
7a291083 | 1161 | out: |
e542aa6b | 1162 | ehea_error("Generating SMRS failed\n"); |
7a291083 JBT |
1163 | return -EIO; |
1164 | } | |
1165 | ||
e542aa6b | 1166 | int ehea_rem_smrs(struct ehea_port_res *pr) |
7a291083 | 1167 | { |
e542aa6b JBT |
1168 | if ((ehea_rem_mr(&pr->send_mr)) |
1169 | || (ehea_rem_mr(&pr->recv_mr))) | |
1170 | return -EIO; | |
1171 | else | |
1172 | return 0; | |
7a291083 JBT |
1173 | } |
1174 | ||
1175 | static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries) | |
1176 | { | |
1177 | int arr_size = sizeof(void*) * max_q_entries; | |
1178 | ||
1179 | q_skba->arr = vmalloc(arr_size); | |
1180 | if (!q_skba->arr) | |
1181 | return -ENOMEM; | |
1182 | ||
1183 | memset(q_skba->arr, 0, arr_size); | |
1184 | ||
1185 | q_skba->len = max_q_entries; | |
1186 | q_skba->index = 0; | |
1187 | q_skba->os_skbs = 0; | |
1188 | ||
1189 | return 0; | |
1190 | } | |
1191 | ||
1192 | static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr, | |
1193 | struct port_res_cfg *pr_cfg, int queue_token) | |
1194 | { | |
1195 | struct ehea_adapter *adapter = port->adapter; | |
1196 | enum ehea_eq_type eq_type = EHEA_EQ; | |
1197 | struct ehea_qp_init_attr *init_attr = NULL; | |
1198 | int ret = -EIO; | |
1199 | ||
1200 | memset(pr, 0, sizeof(struct ehea_port_res)); | |
1201 | ||
1202 | pr->port = port; | |
7a291083 JBT |
1203 | spin_lock_init(&pr->xmit_lock); |
1204 | spin_lock_init(&pr->netif_queue); | |
1205 | ||
18604c54 JBT |
1206 | pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0); |
1207 | if (!pr->eq) { | |
1208 | ehea_error("create_eq failed (eq)"); | |
7a291083 JBT |
1209 | goto out_free; |
1210 | } | |
1211 | ||
1212 | pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq, | |
18604c54 | 1213 | pr->eq->fw_handle, |
7a291083 JBT |
1214 | port->logical_port_id); |
1215 | if (!pr->recv_cq) { | |
1216 | ehea_error("create_cq failed (cq_recv)"); | |
1217 | goto out_free; | |
1218 | } | |
1219 | ||
1220 | pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq, | |
18604c54 | 1221 | pr->eq->fw_handle, |
7a291083 JBT |
1222 | port->logical_port_id); |
1223 | if (!pr->send_cq) { | |
1224 | ehea_error("create_cq failed (cq_send)"); | |
1225 | goto out_free; | |
1226 | } | |
1227 | ||
1228 | if (netif_msg_ifup(port)) | |
1229 | ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d", | |
1230 | pr->send_cq->attr.act_nr_of_cqes, | |
1231 | pr->recv_cq->attr.act_nr_of_cqes); | |
1232 | ||
1233 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); | |
1234 | if (!init_attr) { | |
1235 | ret = -ENOMEM; | |
1236 | ehea_error("no mem for ehea_qp_init_attr"); | |
1237 | goto out_free; | |
1238 | } | |
1239 | ||
1240 | init_attr->low_lat_rq1 = 1; | |
1241 | init_attr->signalingtype = 1; /* generate CQE if specified in WQE */ | |
1242 | init_attr->rq_count = 3; | |
1243 | init_attr->qp_token = queue_token; | |
1244 | init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq; | |
1245 | init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1; | |
1246 | init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2; | |
1247 | init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3; | |
1248 | init_attr->wqe_size_enc_sq = EHEA_SG_SQ; | |
1249 | init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1; | |
1250 | init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2; | |
1251 | init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3; | |
1252 | init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD; | |
1253 | init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD; | |
1254 | init_attr->port_nr = port->logical_port_id; | |
1255 | init_attr->send_cq_handle = pr->send_cq->fw_handle; | |
1256 | init_attr->recv_cq_handle = pr->recv_cq->fw_handle; | |
1257 | init_attr->aff_eq_handle = port->qp_eq->fw_handle; | |
1258 | ||
1259 | pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr); | |
1260 | if (!pr->qp) { | |
1261 | ehea_error("create_qp failed"); | |
1262 | ret = -EIO; | |
1263 | goto out_free; | |
1264 | } | |
1265 | ||
1266 | if (netif_msg_ifup(port)) | |
1267 | ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n " | |
1268 | "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr, | |
1269 | init_attr->act_nr_send_wqes, | |
1270 | init_attr->act_nr_rwqes_rq1, | |
1271 | init_attr->act_nr_rwqes_rq2, | |
1272 | init_attr->act_nr_rwqes_rq3); | |
1273 | ||
1274 | ret = ehea_init_q_skba(&pr->sq_skba, init_attr->act_nr_send_wqes + 1); | |
1275 | ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1); | |
1276 | ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1); | |
1277 | ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1); | |
1278 | if (ret) | |
1279 | goto out_free; | |
1280 | ||
1281 | pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10; | |
1282 | if (ehea_gen_smrs(pr) != 0) { | |
1283 | ret = -EIO; | |
1284 | goto out_free; | |
1285 | } | |
18604c54 | 1286 | |
7a291083 JBT |
1287 | atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1); |
1288 | ||
1289 | kfree(init_attr); | |
18604c54 | 1290 | |
bea3348e | 1291 | netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64); |
18604c54 | 1292 | |
d4dc4ec9 JBT |
1293 | pr->lro_mgr.max_aggr = pr->port->lro_max_aggr; |
1294 | pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS; | |
1295 | pr->lro_mgr.lro_arr = pr->lro_desc; | |
1296 | pr->lro_mgr.get_skb_header = get_skb_hdr; | |
1297 | pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID; | |
1298 | pr->lro_mgr.dev = port->netdev; | |
1299 | pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY; | |
1300 | pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY; | |
1301 | ||
7a291083 JBT |
1302 | ret = 0; |
1303 | goto out; | |
1304 | ||
1305 | out_free: | |
1306 | kfree(init_attr); | |
1307 | vfree(pr->sq_skba.arr); | |
1308 | vfree(pr->rq1_skba.arr); | |
1309 | vfree(pr->rq2_skba.arr); | |
1310 | vfree(pr->rq3_skba.arr); | |
1311 | ehea_destroy_qp(pr->qp); | |
1312 | ehea_destroy_cq(pr->send_cq); | |
1313 | ehea_destroy_cq(pr->recv_cq); | |
18604c54 | 1314 | ehea_destroy_eq(pr->eq); |
7a291083 JBT |
1315 | out: |
1316 | return ret; | |
1317 | } | |
1318 | ||
1319 | static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr) | |
1320 | { | |
1321 | int ret, i; | |
1322 | ||
1323 | ret = ehea_destroy_qp(pr->qp); | |
1324 | ||
1325 | if (!ret) { | |
1326 | ehea_destroy_cq(pr->send_cq); | |
1327 | ehea_destroy_cq(pr->recv_cq); | |
18604c54 | 1328 | ehea_destroy_eq(pr->eq); |
7a291083 JBT |
1329 | |
1330 | for (i = 0; i < pr->rq1_skba.len; i++) | |
1331 | if (pr->rq1_skba.arr[i]) | |
1332 | dev_kfree_skb(pr->rq1_skba.arr[i]); | |
1333 | ||
1334 | for (i = 0; i < pr->rq2_skba.len; i++) | |
1335 | if (pr->rq2_skba.arr[i]) | |
1336 | dev_kfree_skb(pr->rq2_skba.arr[i]); | |
1337 | ||
1338 | for (i = 0; i < pr->rq3_skba.len; i++) | |
1339 | if (pr->rq3_skba.arr[i]) | |
1340 | dev_kfree_skb(pr->rq3_skba.arr[i]); | |
1341 | ||
1342 | for (i = 0; i < pr->sq_skba.len; i++) | |
1343 | if (pr->sq_skba.arr[i]) | |
1344 | dev_kfree_skb(pr->sq_skba.arr[i]); | |
1345 | ||
1346 | vfree(pr->rq1_skba.arr); | |
1347 | vfree(pr->rq2_skba.arr); | |
1348 | vfree(pr->rq3_skba.arr); | |
1349 | vfree(pr->sq_skba.arr); | |
1350 | ret = ehea_rem_smrs(pr); | |
1351 | } | |
1352 | return ret; | |
1353 | } | |
1354 | ||
1355 | /* | |
1356 | * The write_* functions store information in swqe which is used by | |
1357 | * the hardware to calculate the ip/tcp/udp checksum | |
1358 | */ | |
1359 | ||
1360 | static inline void write_ip_start_end(struct ehea_swqe *swqe, | |
1361 | const struct sk_buff *skb) | |
1362 | { | |
eddc9ec5 | 1363 | swqe->ip_start = skb_network_offset(skb); |
c9bdd4b5 | 1364 | swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1); |
7a291083 JBT |
1365 | } |
1366 | ||
1367 | static inline void write_tcp_offset_end(struct ehea_swqe *swqe, | |
1368 | const struct sk_buff *skb) | |
1369 | { | |
1370 | swqe->tcp_offset = | |
1371 | (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check)); | |
1372 | ||
1373 | swqe->tcp_end = (u16)skb->len - 1; | |
1374 | } | |
1375 | ||
1376 | static inline void write_udp_offset_end(struct ehea_swqe *swqe, | |
1377 | const struct sk_buff *skb) | |
1378 | { | |
1379 | swqe->tcp_offset = | |
1380 | (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check)); | |
1381 | ||
1382 | swqe->tcp_end = (u16)skb->len - 1; | |
1383 | } | |
1384 | ||
1385 | ||
1386 | static void write_swqe2_TSO(struct sk_buff *skb, | |
1387 | struct ehea_swqe *swqe, u32 lkey) | |
1388 | { | |
1389 | struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry; | |
1390 | u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0]; | |
1391 | int skb_data_size = skb->len - skb->data_len; | |
1392 | int headersize; | |
7a291083 JBT |
1393 | |
1394 | /* Packet is TCP with TSO enabled */ | |
1395 | swqe->tx_control |= EHEA_SWQE_TSO; | |
1396 | swqe->mss = skb_shinfo(skb)->gso_size; | |
1397 | /* copy only eth/ip/tcp headers to immediate data and | |
1398 | * the rest of skb->data to sg1entry | |
1399 | */ | |
ab6a5bb6 | 1400 | headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb); |
7a291083 JBT |
1401 | |
1402 | skb_data_size = skb->len - skb->data_len; | |
1403 | ||
1404 | if (skb_data_size >= headersize) { | |
1405 | /* copy immediate data */ | |
d626f62b | 1406 | skb_copy_from_linear_data(skb, imm_data, headersize); |
7a291083 JBT |
1407 | swqe->immediate_data_length = headersize; |
1408 | ||
1409 | if (skb_data_size > headersize) { | |
1410 | /* set sg1entry data */ | |
1411 | sg1entry->l_key = lkey; | |
1412 | sg1entry->len = skb_data_size - headersize; | |
44a5b3d5 TK |
1413 | sg1entry->vaddr = |
1414 | ehea_map_vaddr(skb->data + headersize); | |
7a291083 JBT |
1415 | swqe->descriptors++; |
1416 | } | |
1417 | } else | |
1418 | ehea_error("cannot handle fragmented headers"); | |
1419 | } | |
1420 | ||
1421 | static void write_swqe2_nonTSO(struct sk_buff *skb, | |
1422 | struct ehea_swqe *swqe, u32 lkey) | |
1423 | { | |
1424 | int skb_data_size = skb->len - skb->data_len; | |
1425 | u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0]; | |
1426 | struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry; | |
7a291083 JBT |
1427 | |
1428 | /* Packet is any nonTSO type | |
1429 | * | |
1430 | * Copy as much as possible skb->data to immediate data and | |
1431 | * the rest to sg1entry | |
1432 | */ | |
1433 | if (skb_data_size >= SWQE2_MAX_IMM) { | |
1434 | /* copy immediate data */ | |
d626f62b | 1435 | skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM); |
7a291083 JBT |
1436 | |
1437 | swqe->immediate_data_length = SWQE2_MAX_IMM; | |
1438 | ||
1439 | if (skb_data_size > SWQE2_MAX_IMM) { | |
1440 | /* copy sg1entry data */ | |
1441 | sg1entry->l_key = lkey; | |
1442 | sg1entry->len = skb_data_size - SWQE2_MAX_IMM; | |
44a5b3d5 TK |
1443 | sg1entry->vaddr = |
1444 | ehea_map_vaddr(skb->data + SWQE2_MAX_IMM); | |
7a291083 JBT |
1445 | swqe->descriptors++; |
1446 | } | |
1447 | } else { | |
d626f62b | 1448 | skb_copy_from_linear_data(skb, imm_data, skb_data_size); |
7a291083 JBT |
1449 | swqe->immediate_data_length = skb_data_size; |
1450 | } | |
1451 | } | |
1452 | ||
1453 | static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev, | |
1454 | struct ehea_swqe *swqe, u32 lkey) | |
1455 | { | |
1456 | struct ehea_vsgentry *sg_list, *sg1entry, *sgentry; | |
1457 | skb_frag_t *frag; | |
1458 | int nfrags, sg1entry_contains_frag_data, i; | |
7a291083 JBT |
1459 | |
1460 | nfrags = skb_shinfo(skb)->nr_frags; | |
1461 | sg1entry = &swqe->u.immdata_desc.sg_entry; | |
1462 | sg_list = (struct ehea_vsgentry*)&swqe->u.immdata_desc.sg_list; | |
1463 | swqe->descriptors = 0; | |
1464 | sg1entry_contains_frag_data = 0; | |
1465 | ||
1466 | if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size) | |
1467 | write_swqe2_TSO(skb, swqe, lkey); | |
1468 | else | |
1469 | write_swqe2_nonTSO(skb, swqe, lkey); | |
1470 | ||
1471 | /* write descriptors */ | |
1472 | if (nfrags > 0) { | |
1473 | if (swqe->descriptors == 0) { | |
1474 | /* sg1entry not yet used */ | |
1475 | frag = &skb_shinfo(skb)->frags[0]; | |
1476 | ||
1477 | /* copy sg1entry data */ | |
1478 | sg1entry->l_key = lkey; | |
1479 | sg1entry->len = frag->size; | |
44a5b3d5 TK |
1480 | sg1entry->vaddr = |
1481 | ehea_map_vaddr(page_address(frag->page) | |
1482 | + frag->page_offset); | |
7a291083 JBT |
1483 | swqe->descriptors++; |
1484 | sg1entry_contains_frag_data = 1; | |
1485 | } | |
1486 | ||
1487 | for (i = sg1entry_contains_frag_data; i < nfrags; i++) { | |
1488 | ||
1489 | frag = &skb_shinfo(skb)->frags[i]; | |
1490 | sgentry = &sg_list[i - sg1entry_contains_frag_data]; | |
1491 | ||
1492 | sgentry->l_key = lkey; | |
1493 | sgentry->len = frag->size; | |
44a5b3d5 TK |
1494 | sgentry->vaddr = |
1495 | ehea_map_vaddr(page_address(frag->page) | |
1496 | + frag->page_offset); | |
7a291083 JBT |
1497 | swqe->descriptors++; |
1498 | } | |
1499 | } | |
1500 | } | |
1501 | ||
1502 | static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid) | |
1503 | { | |
1504 | int ret = 0; | |
1505 | u64 hret; | |
1506 | u8 reg_type; | |
1507 | ||
1508 | /* De/Register untagged packets */ | |
1509 | reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED; | |
1510 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, | |
1511 | port->logical_port_id, | |
1512 | reg_type, port->mac_addr, 0, hcallid); | |
1513 | if (hret != H_SUCCESS) { | |
f9e29228 TK |
1514 | ehea_error("%sregistering bc address failed (tagged)", |
1515 | hcallid == H_REG_BCMC ? "" : "de"); | |
7a291083 JBT |
1516 | ret = -EIO; |
1517 | goto out_herr; | |
1518 | } | |
1519 | ||
1520 | /* De/Register VLAN packets */ | |
1521 | reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL; | |
1522 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, | |
1523 | port->logical_port_id, | |
1524 | reg_type, port->mac_addr, 0, hcallid); | |
1525 | if (hret != H_SUCCESS) { | |
f9e29228 TK |
1526 | ehea_error("%sregistering bc address failed (vlan)", |
1527 | hcallid == H_REG_BCMC ? "" : "de"); | |
7a291083 JBT |
1528 | ret = -EIO; |
1529 | } | |
1530 | out_herr: | |
1531 | return ret; | |
1532 | } | |
1533 | ||
1534 | static int ehea_set_mac_addr(struct net_device *dev, void *sa) | |
1535 | { | |
1536 | struct ehea_port *port = netdev_priv(dev); | |
1537 | struct sockaddr *mac_addr = sa; | |
1538 | struct hcp_ehea_port_cb0 *cb0; | |
1539 | int ret; | |
1540 | u64 hret; | |
1541 | ||
1542 | if (!is_valid_ether_addr(mac_addr->sa_data)) { | |
1543 | ret = -EADDRNOTAVAIL; | |
1544 | goto out; | |
1545 | } | |
1546 | ||
a1d261c5 | 1547 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
1548 | if (!cb0) { |
1549 | ehea_error("no mem for cb0"); | |
1550 | ret = -ENOMEM; | |
1551 | goto out; | |
1552 | } | |
1553 | ||
1554 | memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN); | |
1555 | ||
1556 | cb0->port_mac_addr = cb0->port_mac_addr >> 16; | |
1557 | ||
1558 | hret = ehea_h_modify_ehea_port(port->adapter->handle, | |
1559 | port->logical_port_id, H_PORT_CB0, | |
1560 | EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0); | |
1561 | if (hret != H_SUCCESS) { | |
1562 | ret = -EIO; | |
1563 | goto out_free; | |
1564 | } | |
1565 | ||
1566 | memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len); | |
1567 | ||
1568 | /* Deregister old MAC in pHYP */ | |
1569 | ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC); | |
1570 | if (ret) | |
1571 | goto out_free; | |
1572 | ||
1573 | port->mac_addr = cb0->port_mac_addr << 16; | |
1574 | ||
1575 | /* Register new MAC in pHYP */ | |
1576 | ret = ehea_broadcast_reg_helper(port, H_REG_BCMC); | |
1577 | if (ret) | |
1578 | goto out_free; | |
1579 | ||
1580 | ret = 0; | |
1581 | out_free: | |
1582 | kfree(cb0); | |
1583 | out: | |
1584 | return ret; | |
1585 | } | |
1586 | ||
1587 | static void ehea_promiscuous_error(u64 hret, int enable) | |
1588 | { | |
7674a588 TK |
1589 | if (hret == H_AUTHORITY) |
1590 | ehea_info("Hypervisor denied %sabling promiscuous mode", | |
1591 | enable == 1 ? "en" : "dis"); | |
1592 | else | |
1593 | ehea_error("failed %sabling promiscuous mode", | |
1594 | enable == 1 ? "en" : "dis"); | |
7a291083 JBT |
1595 | } |
1596 | ||
1597 | static void ehea_promiscuous(struct net_device *dev, int enable) | |
1598 | { | |
1599 | struct ehea_port *port = netdev_priv(dev); | |
1600 | struct hcp_ehea_port_cb7 *cb7; | |
1601 | u64 hret; | |
1602 | ||
1603 | if ((enable && port->promisc) || (!enable && !port->promisc)) | |
1604 | return; | |
1605 | ||
a1d261c5 | 1606 | cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC); |
7a291083 JBT |
1607 | if (!cb7) { |
1608 | ehea_error("no mem for cb7"); | |
1609 | goto out; | |
1610 | } | |
1611 | ||
1612 | /* Modify Pxs_DUCQPN in CB7 */ | |
1613 | cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0; | |
1614 | ||
1615 | hret = ehea_h_modify_ehea_port(port->adapter->handle, | |
1616 | port->logical_port_id, | |
1617 | H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7); | |
1618 | if (hret) { | |
1619 | ehea_promiscuous_error(hret, enable); | |
1620 | goto out; | |
1621 | } | |
1622 | ||
1623 | port->promisc = enable; | |
1624 | out: | |
1625 | kfree(cb7); | |
1626 | return; | |
1627 | } | |
1628 | ||
1629 | static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr, | |
1630 | u32 hcallid) | |
1631 | { | |
1632 | u64 hret; | |
1633 | u8 reg_type; | |
1634 | ||
1635 | reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST | |
1636 | | EHEA_BCMC_UNTAGGED; | |
1637 | ||
1638 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, | |
1639 | port->logical_port_id, | |
1640 | reg_type, mc_mac_addr, 0, hcallid); | |
1641 | if (hret) | |
1642 | goto out; | |
1643 | ||
1644 | reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST | |
1645 | | EHEA_BCMC_VLANID_ALL; | |
1646 | ||
1647 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, | |
1648 | port->logical_port_id, | |
1649 | reg_type, mc_mac_addr, 0, hcallid); | |
1650 | out: | |
1651 | return hret; | |
1652 | } | |
1653 | ||
1654 | static int ehea_drop_multicast_list(struct net_device *dev) | |
1655 | { | |
1656 | struct ehea_port *port = netdev_priv(dev); | |
1657 | struct ehea_mc_list *mc_entry = port->mc_list; | |
1658 | struct list_head *pos; | |
1659 | struct list_head *temp; | |
1660 | int ret = 0; | |
1661 | u64 hret; | |
1662 | ||
1663 | list_for_each_safe(pos, temp, &(port->mc_list->list)) { | |
1664 | mc_entry = list_entry(pos, struct ehea_mc_list, list); | |
1665 | ||
1666 | hret = ehea_multicast_reg_helper(port, mc_entry->macaddr, | |
1667 | H_DEREG_BCMC); | |
1668 | if (hret) { | |
1669 | ehea_error("failed deregistering mcast MAC"); | |
1670 | ret = -EIO; | |
1671 | } | |
1672 | ||
1673 | list_del(pos); | |
1674 | kfree(mc_entry); | |
1675 | } | |
1676 | return ret; | |
1677 | } | |
1678 | ||
1679 | static void ehea_allmulti(struct net_device *dev, int enable) | |
1680 | { | |
1681 | struct ehea_port *port = netdev_priv(dev); | |
1682 | u64 hret; | |
1683 | ||
1684 | if (!port->allmulti) { | |
1685 | if (enable) { | |
1686 | /* Enable ALLMULTI */ | |
1687 | ehea_drop_multicast_list(dev); | |
1688 | hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC); | |
1689 | if (!hret) | |
1690 | port->allmulti = 1; | |
1691 | else | |
1692 | ehea_error("failed enabling IFF_ALLMULTI"); | |
1693 | } | |
1694 | } else | |
1695 | if (!enable) { | |
1696 | /* Disable ALLMULTI */ | |
1697 | hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC); | |
1698 | if (!hret) | |
1699 | port->allmulti = 0; | |
1700 | else | |
1701 | ehea_error("failed disabling IFF_ALLMULTI"); | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | static void ehea_add_multicast_entry(struct ehea_port* port, u8* mc_mac_addr) | |
1706 | { | |
1707 | struct ehea_mc_list *ehea_mcl_entry; | |
1708 | u64 hret; | |
1709 | ||
1e1675cc | 1710 | ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC); |
7a291083 JBT |
1711 | if (!ehea_mcl_entry) { |
1712 | ehea_error("no mem for mcl_entry"); | |
1713 | return; | |
1714 | } | |
1715 | ||
1716 | INIT_LIST_HEAD(&ehea_mcl_entry->list); | |
1717 | ||
1718 | memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN); | |
1719 | ||
1720 | hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr, | |
1721 | H_REG_BCMC); | |
1722 | if (!hret) | |
1723 | list_add(&ehea_mcl_entry->list, &port->mc_list->list); | |
1724 | else { | |
1725 | ehea_error("failed registering mcast MAC"); | |
1726 | kfree(ehea_mcl_entry); | |
1727 | } | |
1728 | } | |
1729 | ||
1730 | static void ehea_set_multicast_list(struct net_device *dev) | |
1731 | { | |
1732 | struct ehea_port *port = netdev_priv(dev); | |
1733 | struct dev_mc_list *k_mcl_entry; | |
1734 | int ret, i; | |
1735 | ||
1736 | if (dev->flags & IFF_PROMISC) { | |
1737 | ehea_promiscuous(dev, 1); | |
1738 | return; | |
1739 | } | |
1740 | ehea_promiscuous(dev, 0); | |
1741 | ||
1742 | if (dev->flags & IFF_ALLMULTI) { | |
1743 | ehea_allmulti(dev, 1); | |
1744 | return; | |
1745 | } | |
1746 | ehea_allmulti(dev, 0); | |
1747 | ||
1748 | if (dev->mc_count) { | |
1749 | ret = ehea_drop_multicast_list(dev); | |
1750 | if (ret) { | |
1751 | /* Dropping the current multicast list failed. | |
1752 | * Enabling ALL_MULTI is the best we can do. | |
1753 | */ | |
1754 | ehea_allmulti(dev, 1); | |
1755 | } | |
1756 | ||
1757 | if (dev->mc_count > port->adapter->max_mc_mac) { | |
1758 | ehea_info("Mcast registration limit reached (0x%lx). " | |
1759 | "Use ALLMULTI!", | |
1760 | port->adapter->max_mc_mac); | |
1761 | goto out; | |
1762 | } | |
1763 | ||
1764 | for (i = 0, k_mcl_entry = dev->mc_list; | |
1765 | i < dev->mc_count; | |
1766 | i++, k_mcl_entry = k_mcl_entry->next) { | |
1767 | ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr); | |
1768 | } | |
1769 | } | |
1770 | out: | |
1771 | return; | |
1772 | } | |
1773 | ||
1774 | static int ehea_change_mtu(struct net_device *dev, int new_mtu) | |
1775 | { | |
1776 | if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE)) | |
1777 | return -EINVAL; | |
1778 | dev->mtu = new_mtu; | |
1779 | return 0; | |
1780 | } | |
1781 | ||
1782 | static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev, | |
1783 | struct ehea_swqe *swqe, u32 lkey) | |
1784 | { | |
1785 | if (skb->protocol == htons(ETH_P_IP)) { | |
eddc9ec5 | 1786 | const struct iphdr *iph = ip_hdr(skb); |
d1d25aab | 1787 | |
7a291083 JBT |
1788 | /* IPv4 */ |
1789 | swqe->tx_control |= EHEA_SWQE_CRC | |
1790 | | EHEA_SWQE_IP_CHECKSUM | |
1791 | | EHEA_SWQE_TCP_CHECKSUM | |
1792 | | EHEA_SWQE_IMM_DATA_PRESENT | |
1793 | | EHEA_SWQE_DESCRIPTORS_PRESENT; | |
1794 | ||
1795 | write_ip_start_end(swqe, skb); | |
1796 | ||
eddc9ec5 | 1797 | if (iph->protocol == IPPROTO_UDP) { |
d1d25aab JBT |
1798 | if ((iph->frag_off & IP_MF) |
1799 | || (iph->frag_off & IP_OFFSET)) | |
7a291083 JBT |
1800 | /* IP fragment, so don't change cs */ |
1801 | swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM; | |
1802 | else | |
1803 | write_udp_offset_end(swqe, skb); | |
eddc9ec5 | 1804 | } else if (iph->protocol == IPPROTO_TCP) { |
7a291083 JBT |
1805 | write_tcp_offset_end(swqe, skb); |
1806 | } | |
1807 | ||
1808 | /* icmp (big data) and ip segmentation packets (all other ip | |
1809 | packets) do not require any special handling */ | |
1810 | ||
1811 | } else { | |
1812 | /* Other Ethernet Protocol */ | |
1813 | swqe->tx_control |= EHEA_SWQE_CRC | |
1814 | | EHEA_SWQE_IMM_DATA_PRESENT | |
1815 | | EHEA_SWQE_DESCRIPTORS_PRESENT; | |
1816 | } | |
1817 | ||
1818 | write_swqe2_data(skb, dev, swqe, lkey); | |
1819 | } | |
1820 | ||
1821 | static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev, | |
1822 | struct ehea_swqe *swqe) | |
1823 | { | |
1824 | int nfrags = skb_shinfo(skb)->nr_frags; | |
1825 | u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0]; | |
1826 | skb_frag_t *frag; | |
1827 | int i; | |
1828 | ||
1829 | if (skb->protocol == htons(ETH_P_IP)) { | |
eddc9ec5 | 1830 | const struct iphdr *iph = ip_hdr(skb); |
d1d25aab | 1831 | |
7a291083 JBT |
1832 | /* IPv4 */ |
1833 | write_ip_start_end(swqe, skb); | |
1834 | ||
eddc9ec5 | 1835 | if (iph->protocol == IPPROTO_TCP) { |
7a291083 JBT |
1836 | swqe->tx_control |= EHEA_SWQE_CRC |
1837 | | EHEA_SWQE_IP_CHECKSUM | |
1838 | | EHEA_SWQE_TCP_CHECKSUM | |
1839 | | EHEA_SWQE_IMM_DATA_PRESENT; | |
1840 | ||
1841 | write_tcp_offset_end(swqe, skb); | |
1842 | ||
eddc9ec5 | 1843 | } else if (iph->protocol == IPPROTO_UDP) { |
d1d25aab JBT |
1844 | if ((iph->frag_off & IP_MF) |
1845 | || (iph->frag_off & IP_OFFSET)) | |
7a291083 JBT |
1846 | /* IP fragment, so don't change cs */ |
1847 | swqe->tx_control |= EHEA_SWQE_CRC | |
1848 | | EHEA_SWQE_IMM_DATA_PRESENT; | |
1849 | else { | |
1850 | swqe->tx_control |= EHEA_SWQE_CRC | |
1851 | | EHEA_SWQE_IP_CHECKSUM | |
1852 | | EHEA_SWQE_TCP_CHECKSUM | |
1853 | | EHEA_SWQE_IMM_DATA_PRESENT; | |
1854 | ||
1855 | write_udp_offset_end(swqe, skb); | |
1856 | } | |
1857 | } else { | |
1858 | /* icmp (big data) and | |
1859 | ip segmentation packets (all other ip packets) */ | |
1860 | swqe->tx_control |= EHEA_SWQE_CRC | |
1861 | | EHEA_SWQE_IP_CHECKSUM | |
1862 | | EHEA_SWQE_IMM_DATA_PRESENT; | |
1863 | } | |
1864 | } else { | |
1865 | /* Other Ethernet Protocol */ | |
1866 | swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT; | |
1867 | } | |
1868 | /* copy (immediate) data */ | |
1869 | if (nfrags == 0) { | |
1870 | /* data is in a single piece */ | |
d626f62b | 1871 | skb_copy_from_linear_data(skb, imm_data, skb->len); |
7a291083 JBT |
1872 | } else { |
1873 | /* first copy data from the skb->data buffer ... */ | |
d626f62b ACM |
1874 | skb_copy_from_linear_data(skb, imm_data, |
1875 | skb->len - skb->data_len); | |
7a291083 JBT |
1876 | imm_data += skb->len - skb->data_len; |
1877 | ||
1878 | /* ... then copy data from the fragments */ | |
1879 | for (i = 0; i < nfrags; i++) { | |
1880 | frag = &skb_shinfo(skb)->frags[i]; | |
1881 | memcpy(imm_data, | |
1882 | page_address(frag->page) + frag->page_offset, | |
1883 | frag->size); | |
1884 | imm_data += frag->size; | |
1885 | } | |
1886 | } | |
1887 | swqe->immediate_data_length = skb->len; | |
1888 | dev_kfree_skb(skb); | |
1889 | } | |
1890 | ||
18604c54 JBT |
1891 | static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps) |
1892 | { | |
1893 | struct tcphdr *tcp; | |
1894 | u32 tmp; | |
1895 | ||
1896 | if ((skb->protocol == htons(ETH_P_IP)) && | |
88ca2d07 TK |
1897 | (ip_hdr(skb)->protocol == IPPROTO_TCP)) { |
1898 | tcp = (struct tcphdr*)(skb_network_header(skb) + (ip_hdr(skb)->ihl * 4)); | |
18604c54 | 1899 | tmp = (tcp->source + (tcp->dest << 16)) % 31; |
88ca2d07 | 1900 | tmp += ip_hdr(skb)->daddr % 31; |
18604c54 JBT |
1901 | return tmp % num_qps; |
1902 | } | |
1903 | else | |
1904 | return 0; | |
1905 | } | |
1906 | ||
7a291083 JBT |
1907 | static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev) |
1908 | { | |
1909 | struct ehea_port *port = netdev_priv(dev); | |
1910 | struct ehea_swqe *swqe; | |
1911 | unsigned long flags; | |
1912 | u32 lkey; | |
1913 | int swqe_index; | |
18604c54 JBT |
1914 | struct ehea_port_res *pr; |
1915 | ||
1916 | pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)]; | |
1917 | ||
18604c54 JBT |
1918 | if (!spin_trylock(&pr->xmit_lock)) |
1919 | return NETDEV_TX_BUSY; | |
1920 | ||
1921 | if (pr->queue_stopped) { | |
1922 | spin_unlock(&pr->xmit_lock); | |
1923 | return NETDEV_TX_BUSY; | |
1924 | } | |
7a291083 JBT |
1925 | |
1926 | swqe = ehea_get_swqe(pr->qp, &swqe_index); | |
1927 | memset(swqe, 0, SWQE_HEADER_SIZE); | |
1928 | atomic_dec(&pr->swqe_avail); | |
1929 | ||
1930 | if (skb->len <= SWQE3_MAX_IMM) { | |
1931 | u32 sig_iv = port->sig_comp_iv; | |
1932 | u32 swqe_num = pr->swqe_id_counter; | |
1933 | ehea_xmit3(skb, dev, swqe); | |
1934 | swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE) | |
1935 | | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num); | |
1936 | if (pr->swqe_ll_count >= (sig_iv - 1)) { | |
1937 | swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL, | |
1938 | sig_iv); | |
1939 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; | |
1940 | pr->swqe_ll_count = 0; | |
1941 | } else | |
1942 | pr->swqe_ll_count += 1; | |
1943 | } else { | |
1944 | swqe->wr_id = | |
1945 | EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE) | |
1946 | | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter) | |
acbddb59 | 1947 | | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1) |
7a291083 JBT |
1948 | | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index); |
1949 | pr->sq_skba.arr[pr->sq_skba.index] = skb; | |
1950 | ||
1951 | pr->sq_skba.index++; | |
1952 | pr->sq_skba.index &= (pr->sq_skba.len - 1); | |
1953 | ||
1954 | lkey = pr->send_mr.lkey; | |
1955 | ehea_xmit2(skb, dev, swqe, lkey); | |
acbddb59 | 1956 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; |
7a291083 JBT |
1957 | } |
1958 | pr->swqe_id_counter += 1; | |
1959 | ||
1960 | if (port->vgrp && vlan_tx_tag_present(skb)) { | |
1961 | swqe->tx_control |= EHEA_SWQE_VLAN_INSERT; | |
1962 | swqe->vlan_tag = vlan_tx_tag_get(skb); | |
1963 | } | |
1964 | ||
1965 | if (netif_msg_tx_queued(port)) { | |
1966 | ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr); | |
bff0a55f | 1967 | ehea_dump(swqe, 512, "swqe"); |
7a291083 JBT |
1968 | } |
1969 | ||
44c82152 TK |
1970 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) |
1971 | goto out; | |
1972 | ||
7a291083 JBT |
1973 | ehea_post_swqe(pr->qp, swqe); |
1974 | pr->tx_packets++; | |
1975 | ||
1976 | if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { | |
1977 | spin_lock_irqsave(&pr->netif_queue, flags); | |
1978 | if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { | |
acbddb59 | 1979 | pr->p_stats.queue_stopped++; |
7a291083 JBT |
1980 | netif_stop_queue(dev); |
1981 | pr->queue_stopped = 1; | |
1982 | } | |
1983 | spin_unlock_irqrestore(&pr->netif_queue, flags); | |
1984 | } | |
1985 | dev->trans_start = jiffies; | |
1986 | spin_unlock(&pr->xmit_lock); | |
44c82152 | 1987 | out: |
7a291083 JBT |
1988 | return NETDEV_TX_OK; |
1989 | } | |
1990 | ||
1991 | static void ehea_vlan_rx_register(struct net_device *dev, | |
1992 | struct vlan_group *grp) | |
1993 | { | |
1994 | struct ehea_port *port = netdev_priv(dev); | |
1995 | struct ehea_adapter *adapter = port->adapter; | |
1996 | struct hcp_ehea_port_cb1 *cb1; | |
1997 | u64 hret; | |
1998 | ||
1999 | port->vgrp = grp; | |
2000 | ||
a1d261c5 | 2001 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
2002 | if (!cb1) { |
2003 | ehea_error("no mem for cb1"); | |
2004 | goto out; | |
2005 | } | |
2006 | ||
dec590c1 | 2007 | memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter)); |
7a291083 JBT |
2008 | |
2009 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, | |
2010 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | |
2011 | if (hret != H_SUCCESS) | |
2012 | ehea_error("modify_ehea_port failed"); | |
2013 | ||
2014 | kfree(cb1); | |
2015 | out: | |
2016 | return; | |
2017 | } | |
2018 | ||
2019 | static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) | |
2020 | { | |
2021 | struct ehea_port *port = netdev_priv(dev); | |
2022 | struct ehea_adapter *adapter = port->adapter; | |
2023 | struct hcp_ehea_port_cb1 *cb1; | |
2024 | int index; | |
2025 | u64 hret; | |
2026 | ||
a1d261c5 | 2027 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
2028 | if (!cb1) { |
2029 | ehea_error("no mem for cb1"); | |
2030 | goto out; | |
2031 | } | |
2032 | ||
2033 | hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id, | |
2034 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | |
2035 | if (hret != H_SUCCESS) { | |
2036 | ehea_error("query_ehea_port failed"); | |
2037 | goto out; | |
2038 | } | |
2039 | ||
2040 | index = (vid / 64); | |
dec590c1 | 2041 | cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F))); |
7a291083 JBT |
2042 | |
2043 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, | |
2044 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | |
2045 | if (hret != H_SUCCESS) | |
2046 | ehea_error("modify_ehea_port failed"); | |
2047 | out: | |
2048 | kfree(cb1); | |
2049 | return; | |
2050 | } | |
2051 | ||
2052 | static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) | |
2053 | { | |
2054 | struct ehea_port *port = netdev_priv(dev); | |
2055 | struct ehea_adapter *adapter = port->adapter; | |
2056 | struct hcp_ehea_port_cb1 *cb1; | |
2057 | int index; | |
2058 | u64 hret; | |
2059 | ||
5c15bdec | 2060 | vlan_group_set_device(port->vgrp, vid, NULL); |
7a291083 | 2061 | |
a1d261c5 | 2062 | cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
2063 | if (!cb1) { |
2064 | ehea_error("no mem for cb1"); | |
2065 | goto out; | |
2066 | } | |
2067 | ||
2068 | hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id, | |
2069 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | |
2070 | if (hret != H_SUCCESS) { | |
2071 | ehea_error("query_ehea_port failed"); | |
2072 | goto out; | |
2073 | } | |
2074 | ||
2075 | index = (vid / 64); | |
dec590c1 | 2076 | cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F))); |
7a291083 JBT |
2077 | |
2078 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, | |
2079 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | |
2080 | if (hret != H_SUCCESS) | |
2081 | ehea_error("modify_ehea_port failed"); | |
2082 | out: | |
2083 | kfree(cb1); | |
2084 | return; | |
2085 | } | |
2086 | ||
2087 | int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp) | |
2088 | { | |
2089 | int ret = -EIO; | |
2090 | u64 hret; | |
2091 | u16 dummy16 = 0; | |
2092 | u64 dummy64 = 0; | |
2093 | struct hcp_modify_qp_cb0* cb0; | |
2094 | ||
a1d261c5 | 2095 | cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
2096 | if (!cb0) { |
2097 | ret = -ENOMEM; | |
2098 | goto out; | |
2099 | } | |
2100 | ||
2101 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | |
2102 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); | |
2103 | if (hret != H_SUCCESS) { | |
2104 | ehea_error("query_ehea_qp failed (1)"); | |
2105 | goto out; | |
2106 | } | |
2107 | ||
2108 | cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED; | |
2109 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, | |
2110 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, | |
2111 | &dummy64, &dummy64, &dummy16, &dummy16); | |
2112 | if (hret != H_SUCCESS) { | |
2113 | ehea_error("modify_ehea_qp failed (1)"); | |
2114 | goto out; | |
2115 | } | |
2116 | ||
2117 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | |
2118 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); | |
2119 | if (hret != H_SUCCESS) { | |
2120 | ehea_error("query_ehea_qp failed (2)"); | |
2121 | goto out; | |
2122 | } | |
2123 | ||
2124 | cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED; | |
2125 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, | |
2126 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, | |
2127 | &dummy64, &dummy64, &dummy16, &dummy16); | |
2128 | if (hret != H_SUCCESS) { | |
2129 | ehea_error("modify_ehea_qp failed (2)"); | |
2130 | goto out; | |
2131 | } | |
2132 | ||
2133 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | |
2134 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); | |
2135 | if (hret != H_SUCCESS) { | |
2136 | ehea_error("query_ehea_qp failed (3)"); | |
2137 | goto out; | |
2138 | } | |
2139 | ||
2140 | cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND; | |
2141 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, | |
2142 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, | |
2143 | &dummy64, &dummy64, &dummy16, &dummy16); | |
2144 | if (hret != H_SUCCESS) { | |
2145 | ehea_error("modify_ehea_qp failed (3)"); | |
2146 | goto out; | |
2147 | } | |
2148 | ||
2149 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | |
2150 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); | |
2151 | if (hret != H_SUCCESS) { | |
2152 | ehea_error("query_ehea_qp failed (4)"); | |
2153 | goto out; | |
2154 | } | |
2155 | ||
2156 | ret = 0; | |
2157 | out: | |
2158 | kfree(cb0); | |
2159 | return ret; | |
2160 | } | |
2161 | ||
2162 | static int ehea_port_res_setup(struct ehea_port *port, int def_qps, | |
2163 | int add_tx_qps) | |
2164 | { | |
2165 | int ret, i; | |
2166 | struct port_res_cfg pr_cfg, pr_cfg_small_rx; | |
2167 | enum ehea_eq_type eq_type = EHEA_EQ; | |
2168 | ||
2169 | port->qp_eq = ehea_create_eq(port->adapter, eq_type, | |
2170 | EHEA_MAX_ENTRIES_EQ, 1); | |
2171 | if (!port->qp_eq) { | |
2172 | ret = -EINVAL; | |
2173 | ehea_error("ehea_create_eq failed (qp_eq)"); | |
2174 | goto out_kill_eq; | |
2175 | } | |
2176 | ||
2177 | pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries; | |
18604c54 | 2178 | pr_cfg.max_entries_scq = sq_entries * 2; |
7a291083 JBT |
2179 | pr_cfg.max_entries_sq = sq_entries; |
2180 | pr_cfg.max_entries_rq1 = rq1_entries; | |
2181 | pr_cfg.max_entries_rq2 = rq2_entries; | |
2182 | pr_cfg.max_entries_rq3 = rq3_entries; | |
2183 | ||
2184 | pr_cfg_small_rx.max_entries_rcq = 1; | |
2185 | pr_cfg_small_rx.max_entries_scq = sq_entries; | |
2186 | pr_cfg_small_rx.max_entries_sq = sq_entries; | |
2187 | pr_cfg_small_rx.max_entries_rq1 = 1; | |
2188 | pr_cfg_small_rx.max_entries_rq2 = 1; | |
2189 | pr_cfg_small_rx.max_entries_rq3 = 1; | |
2190 | ||
2191 | for (i = 0; i < def_qps; i++) { | |
2192 | ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i); | |
2193 | if (ret) | |
2194 | goto out_clean_pr; | |
2195 | } | |
2196 | for (i = def_qps; i < def_qps + add_tx_qps; i++) { | |
2197 | ret = ehea_init_port_res(port, &port->port_res[i], | |
2198 | &pr_cfg_small_rx, i); | |
2199 | if (ret) | |
2200 | goto out_clean_pr; | |
2201 | } | |
2202 | ||
2203 | return 0; | |
2204 | ||
2205 | out_clean_pr: | |
2206 | while (--i >= 0) | |
2207 | ehea_clean_portres(port, &port->port_res[i]); | |
2208 | ||
2209 | out_kill_eq: | |
2210 | ehea_destroy_eq(port->qp_eq); | |
2211 | return ret; | |
2212 | } | |
2213 | ||
2214 | static int ehea_clean_all_portres(struct ehea_port *port) | |
2215 | { | |
2216 | int ret = 0; | |
2217 | int i; | |
2218 | ||
2219 | for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) | |
2220 | ret |= ehea_clean_portres(port, &port->port_res[i]); | |
2221 | ||
2222 | ret |= ehea_destroy_eq(port->qp_eq); | |
2223 | ||
2224 | return ret; | |
2225 | } | |
2226 | ||
35cf2e2e | 2227 | static void ehea_remove_adapter_mr(struct ehea_adapter *adapter) |
1211bb6d | 2228 | { |
35cf2e2e TK |
2229 | if (adapter->active_ports) |
2230 | return; | |
1211bb6d TK |
2231 | |
2232 | ehea_rem_mr(&adapter->mr); | |
2233 | } | |
2234 | ||
35cf2e2e | 2235 | static int ehea_add_adapter_mr(struct ehea_adapter *adapter) |
1211bb6d | 2236 | { |
35cf2e2e TK |
2237 | if (adapter->active_ports) |
2238 | return 0; | |
1211bb6d TK |
2239 | |
2240 | return ehea_reg_kernel_mr(adapter, &adapter->mr); | |
2241 | } | |
2242 | ||
7a291083 JBT |
2243 | static int ehea_up(struct net_device *dev) |
2244 | { | |
2245 | int ret, i; | |
2246 | struct ehea_port *port = netdev_priv(dev); | |
7a291083 JBT |
2247 | |
2248 | if (port->state == EHEA_PORT_UP) | |
2249 | return 0; | |
2250 | ||
2251 | ret = ehea_port_res_setup(port, port->num_def_qps, | |
2252 | port->num_add_tx_qps); | |
2253 | if (ret) { | |
2254 | ehea_error("port_res_failed"); | |
2255 | goto out; | |
2256 | } | |
2257 | ||
2258 | /* Set default QP for this port */ | |
2259 | ret = ehea_configure_port(port); | |
2260 | if (ret) { | |
2261 | ehea_error("ehea_configure_port failed. ret:%d", ret); | |
2262 | goto out_clean_pr; | |
2263 | } | |
2264 | ||
7a291083 JBT |
2265 | ret = ehea_reg_interrupts(dev); |
2266 | if (ret) { | |
f9e29228 TK |
2267 | ehea_error("reg_interrupts failed. ret:%d", ret); |
2268 | goto out_clean_pr; | |
7a291083 JBT |
2269 | } |
2270 | ||
2271 | for(i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { | |
2272 | ret = ehea_activate_qp(port->adapter, port->port_res[i].qp); | |
2273 | if (ret) { | |
2274 | ehea_error("activate_qp failed"); | |
2275 | goto out_free_irqs; | |
2276 | } | |
2277 | } | |
2278 | ||
2279 | for(i = 0; i < port->num_def_qps; i++) { | |
2280 | ret = ehea_fill_port_res(&port->port_res[i]); | |
2281 | if (ret) { | |
2282 | ehea_error("out_free_irqs"); | |
2283 | goto out_free_irqs; | |
2284 | } | |
2285 | } | |
2286 | ||
2287 | ret = 0; | |
2288 | port->state = EHEA_PORT_UP; | |
2289 | goto out; | |
2290 | ||
2291 | out_free_irqs: | |
2292 | ehea_free_interrupts(dev); | |
2293 | ||
7a291083 JBT |
2294 | out_clean_pr: |
2295 | ehea_clean_all_portres(port); | |
2296 | out: | |
44c82152 TK |
2297 | if (ret) |
2298 | ehea_info("Failed starting %s. ret=%i", dev->name, ret); | |
2299 | ||
7a291083 JBT |
2300 | return ret; |
2301 | } | |
2302 | ||
bea3348e SH |
2303 | static void port_napi_disable(struct ehea_port *port) |
2304 | { | |
2305 | int i; | |
2306 | ||
2307 | for (i = 0; i < port->num_def_qps; i++) | |
2308 | napi_disable(&port->port_res[i].napi); | |
2309 | } | |
2310 | ||
2311 | static void port_napi_enable(struct ehea_port *port) | |
2312 | { | |
2313 | int i; | |
2314 | ||
2315 | for (i = 0; i < port->num_def_qps; i++) | |
2316 | napi_enable(&port->port_res[i].napi); | |
2317 | } | |
2318 | ||
7a291083 JBT |
2319 | static int ehea_open(struct net_device *dev) |
2320 | { | |
2321 | int ret; | |
2322 | struct ehea_port *port = netdev_priv(dev); | |
2323 | ||
2324 | down(&port->port_lock); | |
2325 | ||
2326 | if (netif_msg_ifup(port)) | |
2327 | ehea_info("enabling port %s", dev->name); | |
2328 | ||
2329 | ret = ehea_up(dev); | |
bea3348e SH |
2330 | if (!ret) { |
2331 | port_napi_enable(port); | |
7a291083 | 2332 | netif_start_queue(dev); |
bea3348e | 2333 | } |
7a291083 JBT |
2334 | |
2335 | up(&port->port_lock); | |
2336 | ||
2337 | return ret; | |
2338 | } | |
2339 | ||
2340 | static int ehea_down(struct net_device *dev) | |
2341 | { | |
bea3348e | 2342 | int ret; |
7a291083 JBT |
2343 | struct ehea_port *port = netdev_priv(dev); |
2344 | ||
2345 | if (port->state == EHEA_PORT_DOWN) | |
2346 | return 0; | |
2347 | ||
2348 | ehea_drop_multicast_list(dev); | |
2349 | ehea_free_interrupts(dev); | |
2350 | ||
bea3348e | 2351 | port_napi_disable(port); |
7a291083 | 2352 | |
7a291083 | 2353 | port->state = EHEA_PORT_DOWN; |
44c82152 TK |
2354 | |
2355 | ret = ehea_clean_all_portres(port); | |
2356 | if (ret) | |
2357 | ehea_info("Failed freeing resources for %s. ret=%i", | |
2358 | dev->name, ret); | |
2359 | ||
7a291083 JBT |
2360 | return ret; |
2361 | } | |
2362 | ||
2363 | static int ehea_stop(struct net_device *dev) | |
2364 | { | |
2365 | int ret; | |
2366 | struct ehea_port *port = netdev_priv(dev); | |
2367 | ||
2368 | if (netif_msg_ifdown(port)) | |
2369 | ehea_info("disabling port %s", dev->name); | |
2370 | ||
2371 | flush_workqueue(port->adapter->ehea_wq); | |
2372 | down(&port->port_lock); | |
2373 | netif_stop_queue(dev); | |
2374 | ret = ehea_down(dev); | |
2375 | up(&port->port_lock); | |
2376 | return ret; | |
2377 | } | |
2378 | ||
c4028958 | 2379 | static void ehea_reset_port(struct work_struct *work) |
7a291083 JBT |
2380 | { |
2381 | int ret; | |
c4028958 DH |
2382 | struct ehea_port *port = |
2383 | container_of(work, struct ehea_port, reset_task); | |
2384 | struct net_device *dev = port->netdev; | |
7a291083 JBT |
2385 | |
2386 | port->resets++; | |
2387 | down(&port->port_lock); | |
2388 | netif_stop_queue(dev); | |
bea3348e SH |
2389 | |
2390 | port_napi_disable(port); | |
7a291083 | 2391 | |
44c82152 | 2392 | ehea_down(dev); |
7a291083 JBT |
2393 | |
2394 | ret = ehea_up(dev); | |
44c82152 | 2395 | if (ret) |
7a291083 | 2396 | goto out; |
7a291083 JBT |
2397 | |
2398 | if (netif_msg_timer(port)) | |
2399 | ehea_info("Device %s resetted successfully", dev->name); | |
2400 | ||
bea3348e SH |
2401 | port_napi_enable(port); |
2402 | ||
7a291083 JBT |
2403 | netif_wake_queue(dev); |
2404 | out: | |
2405 | up(&port->port_lock); | |
2406 | return; | |
2407 | } | |
2408 | ||
44c82152 TK |
2409 | static void ehea_rereg_mrs(struct work_struct *work) |
2410 | { | |
2411 | int ret, i; | |
2412 | struct ehea_adapter *adapter; | |
2413 | ||
2414 | ehea_info("LPAR memory enlarged - re-initializing driver"); | |
2415 | ||
2416 | list_for_each_entry(adapter, &adapter_list, list) | |
2417 | if (adapter->active_ports) { | |
2418 | /* Shutdown all ports */ | |
2419 | for (i = 0; i < EHEA_MAX_PORTS; i++) { | |
2420 | struct ehea_port *port = adapter->port[i]; | |
2421 | ||
2422 | if (port) { | |
2423 | struct net_device *dev = port->netdev; | |
2424 | ||
2425 | if (dev->flags & IFF_UP) { | |
2426 | ehea_info("stopping %s", | |
2427 | dev->name); | |
2428 | down(&port->port_lock); | |
2429 | netif_stop_queue(dev); | |
bea3348e SH |
2430 | |
2431 | port_napi_disable(port); | |
2432 | ||
44c82152 TK |
2433 | ehea_down(dev); |
2434 | up(&port->port_lock); | |
2435 | } | |
2436 | } | |
2437 | } | |
2438 | ||
2439 | /* Unregister old memory region */ | |
2440 | ret = ehea_rem_mr(&adapter->mr); | |
2441 | if (ret) { | |
2442 | ehea_error("unregister MR failed - driver" | |
2443 | " inoperable!"); | |
2444 | goto out; | |
2445 | } | |
2446 | } | |
2447 | ||
2448 | ehea_destroy_busmap(); | |
2449 | ||
2450 | ret = ehea_create_busmap(); | |
2451 | if (ret) | |
2452 | goto out; | |
2453 | ||
2454 | clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags); | |
2455 | ||
2456 | list_for_each_entry(adapter, &adapter_list, list) | |
2457 | if (adapter->active_ports) { | |
2458 | /* Register new memory region */ | |
2459 | ret = ehea_reg_kernel_mr(adapter, &adapter->mr); | |
2460 | if (ret) { | |
2461 | ehea_error("register MR failed - driver" | |
2462 | " inoperable!"); | |
2463 | goto out; | |
2464 | } | |
2465 | ||
2466 | /* Restart all ports */ | |
2467 | for (i = 0; i < EHEA_MAX_PORTS; i++) { | |
2468 | struct ehea_port *port = adapter->port[i]; | |
2469 | ||
2470 | if (port) { | |
2471 | struct net_device *dev = port->netdev; | |
2472 | ||
2473 | if (dev->flags & IFF_UP) { | |
2474 | ehea_info("restarting %s", | |
2475 | dev->name); | |
2476 | down(&port->port_lock); | |
2477 | ||
2478 | ret = ehea_up(dev); | |
2479 | if (!ret) { | |
bea3348e | 2480 | port_napi_enable(port); |
44c82152 TK |
2481 | netif_wake_queue(dev); |
2482 | } | |
2483 | ||
2484 | up(&port->port_lock); | |
2485 | } | |
2486 | } | |
2487 | } | |
2488 | } | |
2489 | out: | |
2490 | return; | |
2491 | } | |
2492 | ||
7a291083 JBT |
2493 | static void ehea_tx_watchdog(struct net_device *dev) |
2494 | { | |
2495 | struct ehea_port *port = netdev_priv(dev); | |
2496 | ||
2497 | if (netif_carrier_ok(dev)) | |
2498 | queue_work(port->adapter->ehea_wq, &port->reset_task); | |
2499 | } | |
2500 | ||
2501 | int ehea_sense_adapter_attr(struct ehea_adapter *adapter) | |
2502 | { | |
2503 | struct hcp_query_ehea *cb; | |
2504 | u64 hret; | |
2505 | int ret; | |
2506 | ||
a1d261c5 | 2507 | cb = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
2508 | if (!cb) { |
2509 | ret = -ENOMEM; | |
2510 | goto out; | |
2511 | } | |
2512 | ||
2513 | hret = ehea_h_query_ehea(adapter->handle, cb); | |
2514 | ||
2515 | if (hret != H_SUCCESS) { | |
2516 | ret = -EIO; | |
2517 | goto out_herr; | |
2518 | } | |
2519 | ||
7a291083 JBT |
2520 | adapter->max_mc_mac = cb->max_mc_mac - 1; |
2521 | ret = 0; | |
2522 | ||
2523 | out_herr: | |
2524 | kfree(cb); | |
2525 | out: | |
2526 | return ret; | |
2527 | } | |
2528 | ||
1acf2318 | 2529 | int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo) |
7a291083 | 2530 | { |
7a291083 | 2531 | struct hcp_ehea_port_cb4 *cb4; |
1acf2318 JBT |
2532 | u64 hret; |
2533 | int ret = 0; | |
7a291083 | 2534 | |
1acf2318 | 2535 | *jumbo = 0; |
7a291083 | 2536 | |
1acf2318 | 2537 | /* (Try to) enable *jumbo frames */ |
a1d261c5 | 2538 | cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL); |
7a291083 JBT |
2539 | if (!cb4) { |
2540 | ehea_error("no mem for cb4"); | |
1acf2318 JBT |
2541 | ret = -ENOMEM; |
2542 | goto out; | |
7a291083 | 2543 | } else { |
1acf2318 | 2544 | hret = ehea_h_query_ehea_port(port->adapter->handle, |
9c750b7d TK |
2545 | port->logical_port_id, |
2546 | H_PORT_CB4, | |
2547 | H_PORT_CB4_JUMBO, cb4); | |
9c750b7d TK |
2548 | if (hret == H_SUCCESS) { |
2549 | if (cb4->jumbo_frame) | |
1acf2318 | 2550 | *jumbo = 1; |
9c750b7d TK |
2551 | else { |
2552 | cb4->jumbo_frame = 1; | |
1acf2318 JBT |
2553 | hret = ehea_h_modify_ehea_port(port->adapter-> |
2554 | handle, | |
9c750b7d | 2555 | port-> |
1acf2318 | 2556 | logical_port_id, |
9c750b7d TK |
2557 | H_PORT_CB4, |
2558 | H_PORT_CB4_JUMBO, | |
2559 | cb4); | |
2560 | if (hret == H_SUCCESS) | |
1acf2318 | 2561 | *jumbo = 1; |
9c750b7d | 2562 | } |
1acf2318 JBT |
2563 | } else |
2564 | ret = -EINVAL; | |
2565 | ||
7a291083 JBT |
2566 | kfree(cb4); |
2567 | } | |
1acf2318 JBT |
2568 | out: |
2569 | return ret; | |
2570 | } | |
2571 | ||
2572 | static ssize_t ehea_show_port_id(struct device *dev, | |
2573 | struct device_attribute *attr, char *buf) | |
2574 | { | |
2575 | struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev); | |
a8e34fda | 2576 | return sprintf(buf, "%d", port->logical_port_id); |
1acf2318 JBT |
2577 | } |
2578 | ||
2579 | static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id, | |
2580 | NULL); | |
2581 | ||
2582 | static void __devinit logical_port_release(struct device *dev) | |
2583 | { | |
2584 | struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev); | |
2585 | of_node_put(port->ofdev.node); | |
2586 | } | |
2587 | ||
d1dea38d | 2588 | static int ehea_driver_sysfs_add(struct device *dev, |
d1d25aab | 2589 | struct device_driver *driver) |
d1dea38d TK |
2590 | { |
2591 | int ret; | |
2592 | ||
2593 | ret = sysfs_create_link(&driver->kobj, &dev->kobj, | |
2594 | kobject_name(&dev->kobj)); | |
2595 | if (ret == 0) { | |
2596 | ret = sysfs_create_link(&dev->kobj, &driver->kobj, | |
2597 | "driver"); | |
2598 | if (ret) | |
2599 | sysfs_remove_link(&driver->kobj, | |
2600 | kobject_name(&dev->kobj)); | |
2601 | } | |
2602 | return ret; | |
2603 | } | |
2604 | ||
2605 | static void ehea_driver_sysfs_remove(struct device *dev, | |
d1d25aab | 2606 | struct device_driver *driver) |
d1dea38d TK |
2607 | { |
2608 | struct device_driver *drv = driver; | |
2609 | ||
2610 | if (drv) { | |
2611 | sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj)); | |
2612 | sysfs_remove_link(&dev->kobj, "driver"); | |
2613 | } | |
2614 | } | |
2615 | ||
1acf2318 JBT |
2616 | static struct device *ehea_register_port(struct ehea_port *port, |
2617 | struct device_node *dn) | |
2618 | { | |
2619 | int ret; | |
2620 | ||
2621 | port->ofdev.node = of_node_get(dn); | |
2622 | port->ofdev.dev.parent = &port->adapter->ebus_dev->ofdev.dev; | |
d1dea38d | 2623 | port->ofdev.dev.bus = &ibmebus_bus_type; |
1acf2318 | 2624 | |
d1dea38d | 2625 | sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++); |
1acf2318 JBT |
2626 | port->ofdev.dev.release = logical_port_release; |
2627 | ||
2628 | ret = of_device_register(&port->ofdev); | |
2629 | if (ret) { | |
2630 | ehea_error("failed to register device. ret=%d", ret); | |
2631 | goto out; | |
2632 | } | |
2633 | ||
2634 | ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id); | |
d1d25aab | 2635 | if (ret) { |
1acf2318 JBT |
2636 | ehea_error("failed to register attributes, ret=%d", ret); |
2637 | goto out_unreg_of_dev; | |
2638 | } | |
e542aa6b | 2639 | |
d1dea38d TK |
2640 | ret = ehea_driver_sysfs_add(&port->ofdev.dev, &ehea_driver.driver); |
2641 | if (ret) { | |
2642 | ehea_error("failed to register sysfs driver link"); | |
2643 | goto out_rem_dev_file; | |
2644 | } | |
2645 | ||
1acf2318 JBT |
2646 | return &port->ofdev.dev; |
2647 | ||
d1dea38d TK |
2648 | out_rem_dev_file: |
2649 | device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id); | |
1acf2318 JBT |
2650 | out_unreg_of_dev: |
2651 | of_device_unregister(&port->ofdev); | |
2652 | out: | |
2653 | return NULL; | |
2654 | } | |
2655 | ||
2656 | static void ehea_unregister_port(struct ehea_port *port) | |
2657 | { | |
d1dea38d | 2658 | ehea_driver_sysfs_remove(&port->ofdev.dev, &ehea_driver.driver); |
1acf2318 JBT |
2659 | device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id); |
2660 | of_device_unregister(&port->ofdev); | |
2661 | } | |
2662 | ||
2663 | struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter, | |
2664 | u32 logical_port_id, | |
2665 | struct device_node *dn) | |
2666 | { | |
2667 | int ret; | |
2668 | struct net_device *dev; | |
2669 | struct ehea_port *port; | |
2670 | struct device *port_dev; | |
2671 | int jumbo; | |
2672 | ||
2673 | /* allocate memory for the port structures */ | |
2674 | dev = alloc_etherdev(sizeof(struct ehea_port)); | |
2675 | ||
2676 | if (!dev) { | |
2677 | ehea_error("no mem for net_device"); | |
2678 | ret = -ENOMEM; | |
2679 | goto out_err; | |
2680 | } | |
2681 | ||
2682 | port = netdev_priv(dev); | |
2683 | ||
2684 | sema_init(&port->port_lock, 1); | |
2685 | port->state = EHEA_PORT_DOWN; | |
2686 | port->sig_comp_iv = sq_entries / 10; | |
2687 | ||
2688 | port->adapter = adapter; | |
2689 | port->netdev = dev; | |
2690 | port->logical_port_id = logical_port_id; | |
2691 | ||
2692 | port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT); | |
2693 | ||
2694 | port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL); | |
2695 | if (!port->mc_list) { | |
2696 | ret = -ENOMEM; | |
2697 | goto out_free_ethdev; | |
2698 | } | |
2699 | ||
2700 | INIT_LIST_HEAD(&port->mc_list->list); | |
2701 | ||
2702 | ret = ehea_sense_port_attr(port); | |
2703 | if (ret) | |
2704 | goto out_free_mc_list; | |
2705 | ||
2706 | port_dev = ehea_register_port(port, dn); | |
2707 | if (!port_dev) | |
2708 | goto out_free_mc_list; | |
2709 | ||
2710 | SET_NETDEV_DEV(dev, port_dev); | |
7a291083 JBT |
2711 | |
2712 | /* initialize net_device structure */ | |
7a291083 JBT |
2713 | memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN); |
2714 | ||
2715 | dev->open = ehea_open; | |
8d22c971 JBT |
2716 | #ifdef CONFIG_NET_POLL_CONTROLLER |
2717 | dev->poll_controller = ehea_netpoll; | |
2718 | #endif | |
7a291083 JBT |
2719 | dev->stop = ehea_stop; |
2720 | dev->hard_start_xmit = ehea_start_xmit; | |
2721 | dev->get_stats = ehea_get_stats; | |
2722 | dev->set_multicast_list = ehea_set_multicast_list; | |
2723 | dev->set_mac_address = ehea_set_mac_addr; | |
2724 | dev->change_mtu = ehea_change_mtu; | |
2725 | dev->vlan_rx_register = ehea_vlan_rx_register; | |
2726 | dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid; | |
2727 | dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid; | |
2728 | dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO | |
2729 | | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_TX | |
2730 | | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER | |
2731 | | NETIF_F_LLTX; | |
2732 | dev->tx_timeout = &ehea_tx_watchdog; | |
2733 | dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT; | |
2734 | ||
c4028958 | 2735 | INIT_WORK(&port->reset_task, ehea_reset_port); |
7a291083 | 2736 | |
f9e29228 TK |
2737 | ret = ehea_broadcast_reg_helper(port, H_REG_BCMC); |
2738 | if (ret) { | |
2739 | ret = -EIO; | |
2740 | goto out_unreg_port; | |
2741 | } | |
2742 | ||
7a291083 JBT |
2743 | ehea_set_ethtool_ops(dev); |
2744 | ||
2745 | ret = register_netdev(dev); | |
2746 | if (ret) { | |
2747 | ehea_error("register_netdev failed. ret=%d", ret); | |
f9e29228 | 2748 | goto out_dereg_bc; |
7a291083 JBT |
2749 | } |
2750 | ||
d4dc4ec9 JBT |
2751 | port->lro_max_aggr = lro_max_aggr; |
2752 | ||
1acf2318 | 2753 | ret = ehea_get_jumboframe_status(port, &jumbo); |
e542aa6b | 2754 | if (ret) |
1acf2318 JBT |
2755 | ehea_error("failed determining jumbo frame status for %s", |
2756 | port->netdev->name); | |
2757 | ||
9c750b7d TK |
2758 | ehea_info("%s: Jumbo frames are %sabled", dev->name, |
2759 | jumbo == 1 ? "en" : "dis"); | |
2760 | ||
44c82152 TK |
2761 | adapter->active_ports++; |
2762 | ||
1acf2318 | 2763 | return port; |
7a291083 | 2764 | |
f9e29228 TK |
2765 | out_dereg_bc: |
2766 | ehea_broadcast_reg_helper(port, H_DEREG_BCMC); | |
2767 | ||
1acf2318 JBT |
2768 | out_unreg_port: |
2769 | ehea_unregister_port(port); | |
2770 | ||
2771 | out_free_mc_list: | |
7a291083 | 2772 | kfree(port->mc_list); |
1acf2318 JBT |
2773 | |
2774 | out_free_ethdev: | |
2775 | free_netdev(dev); | |
2776 | ||
2777 | out_err: | |
2778 | ehea_error("setting up logical port with id=%d failed, ret=%d", | |
2779 | logical_port_id, ret); | |
2780 | return NULL; | |
2781 | } | |
2782 | ||
2783 | static void ehea_shutdown_single_port(struct ehea_port *port) | |
2784 | { | |
2785 | unregister_netdev(port->netdev); | |
2786 | ehea_unregister_port(port); | |
f9e29228 | 2787 | ehea_broadcast_reg_helper(port, H_DEREG_BCMC); |
1acf2318 JBT |
2788 | kfree(port->mc_list); |
2789 | free_netdev(port->netdev); | |
44c82152 | 2790 | port->adapter->active_ports--; |
7a291083 JBT |
2791 | } |
2792 | ||
2793 | static int ehea_setup_ports(struct ehea_adapter *adapter) | |
2794 | { | |
1acf2318 JBT |
2795 | struct device_node *lhea_dn; |
2796 | struct device_node *eth_dn = NULL; | |
d1d25aab | 2797 | |
9f9a3b8a | 2798 | const u32 *dn_log_port_id; |
1acf2318 JBT |
2799 | int i = 0; |
2800 | ||
2801 | lhea_dn = adapter->ebus_dev->ofdev.node; | |
1eef4e04 | 2802 | while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { |
e542aa6b | 2803 | |
40cd3a45 | 2804 | dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no", |
d1d25aab | 2805 | NULL); |
1acf2318 JBT |
2806 | if (!dn_log_port_id) { |
2807 | ehea_error("bad device node: eth_dn name=%s", | |
2808 | eth_dn->full_name); | |
2809 | continue; | |
2810 | } | |
7a291083 | 2811 | |
1211bb6d TK |
2812 | if (ehea_add_adapter_mr(adapter)) { |
2813 | ehea_error("creating MR failed"); | |
2814 | of_node_put(eth_dn); | |
2815 | return -EIO; | |
2816 | } | |
2817 | ||
1acf2318 JBT |
2818 | adapter->port[i] = ehea_setup_single_port(adapter, |
2819 | *dn_log_port_id, | |
2820 | eth_dn); | |
7a291083 | 2821 | if (adapter->port[i]) |
1acf2318 | 2822 | ehea_info("%s -> logical port id #%d", |
e542aa6b | 2823 | adapter->port[i]->netdev->name, |
1acf2318 | 2824 | *dn_log_port_id); |
1211bb6d TK |
2825 | else |
2826 | ehea_remove_adapter_mr(adapter); | |
2827 | ||
1acf2318 | 2828 | i++; |
1eef4e04 | 2829 | }; |
7a291083 | 2830 | |
1211bb6d | 2831 | return 0; |
1acf2318 JBT |
2832 | } |
2833 | ||
e542aa6b JBT |
2834 | static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter, |
2835 | u32 logical_port_id) | |
1acf2318 JBT |
2836 | { |
2837 | struct device_node *lhea_dn; | |
2838 | struct device_node *eth_dn = NULL; | |
9f9a3b8a | 2839 | const u32 *dn_log_port_id; |
1acf2318 JBT |
2840 | |
2841 | lhea_dn = adapter->ebus_dev->ofdev.node; | |
1eef4e04 | 2842 | while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { |
e542aa6b | 2843 | |
40cd3a45 | 2844 | dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no", |
d1d25aab | 2845 | NULL); |
1acf2318 JBT |
2846 | if (dn_log_port_id) |
2847 | if (*dn_log_port_id == logical_port_id) | |
2848 | return eth_dn; | |
1eef4e04 | 2849 | }; |
1acf2318 JBT |
2850 | |
2851 | return NULL; | |
2852 | } | |
2853 | ||
2854 | static ssize_t ehea_probe_port(struct device *dev, | |
2855 | struct device_attribute *attr, | |
2856 | const char *buf, size_t count) | |
2857 | { | |
2858 | struct ehea_adapter *adapter = dev->driver_data; | |
2859 | struct ehea_port *port; | |
2860 | struct device_node *eth_dn = NULL; | |
2861 | int i; | |
2862 | ||
2863 | u32 logical_port_id; | |
2864 | ||
a8e34fda | 2865 | sscanf(buf, "%d", &logical_port_id); |
1acf2318 JBT |
2866 | |
2867 | port = ehea_get_port(adapter, logical_port_id); | |
2868 | ||
2869 | if (port) { | |
2870 | ehea_info("adding port with logical port id=%d failed. port " | |
2871 | "already configured as %s.", logical_port_id, | |
2872 | port->netdev->name); | |
2873 | return -EINVAL; | |
7a291083 | 2874 | } |
e542aa6b | 2875 | |
1acf2318 | 2876 | eth_dn = ehea_get_eth_dn(adapter, logical_port_id); |
7a291083 | 2877 | |
1acf2318 JBT |
2878 | if (!eth_dn) { |
2879 | ehea_info("no logical port with id %d found", logical_port_id); | |
2880 | return -EINVAL; | |
2881 | } | |
e542aa6b | 2882 | |
1211bb6d TK |
2883 | if (ehea_add_adapter_mr(adapter)) { |
2884 | ehea_error("creating MR failed"); | |
2885 | return -EIO; | |
2886 | } | |
2887 | ||
1acf2318 | 2888 | port = ehea_setup_single_port(adapter, logical_port_id, eth_dn); |
7a291083 | 2889 | |
1eef4e04 JBT |
2890 | of_node_put(eth_dn); |
2891 | ||
1acf2318 JBT |
2892 | if (port) { |
2893 | for (i=0; i < EHEA_MAX_PORTS; i++) | |
2894 | if (!adapter->port[i]) { | |
2895 | adapter->port[i] = port; | |
2896 | break; | |
2897 | } | |
7a291083 | 2898 | |
1acf2318 JBT |
2899 | ehea_info("added %s (logical port id=%d)", port->netdev->name, |
2900 | logical_port_id); | |
1211bb6d TK |
2901 | } else { |
2902 | ehea_remove_adapter_mr(adapter); | |
e542aa6b | 2903 | return -EIO; |
1211bb6d | 2904 | } |
7a291083 | 2905 | |
1acf2318 JBT |
2906 | return (ssize_t) count; |
2907 | } | |
2908 | ||
2909 | static ssize_t ehea_remove_port(struct device *dev, | |
2910 | struct device_attribute *attr, | |
2911 | const char *buf, size_t count) | |
2912 | { | |
2913 | struct ehea_adapter *adapter = dev->driver_data; | |
2914 | struct ehea_port *port; | |
2915 | int i; | |
2916 | u32 logical_port_id; | |
2917 | ||
a8e34fda | 2918 | sscanf(buf, "%d", &logical_port_id); |
1acf2318 JBT |
2919 | |
2920 | port = ehea_get_port(adapter, logical_port_id); | |
2921 | ||
2922 | if (port) { | |
2923 | ehea_info("removed %s (logical port id=%d)", port->netdev->name, | |
2924 | logical_port_id); | |
2925 | ||
2926 | ehea_shutdown_single_port(port); | |
2927 | ||
2928 | for (i=0; i < EHEA_MAX_PORTS; i++) | |
2929 | if (adapter->port[i] == port) { | |
2930 | adapter->port[i] = NULL; | |
2931 | break; | |
2932 | } | |
2933 | } else { | |
2934 | ehea_error("removing port with logical port id=%d failed. port " | |
2935 | "not configured.", logical_port_id); | |
2936 | return -EINVAL; | |
2937 | } | |
2938 | ||
1211bb6d TK |
2939 | ehea_remove_adapter_mr(adapter); |
2940 | ||
1acf2318 JBT |
2941 | return (ssize_t) count; |
2942 | } | |
2943 | ||
2944 | static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port); | |
2945 | static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port); | |
2946 | ||
2947 | int ehea_create_device_sysfs(struct ibmebus_dev *dev) | |
2948 | { | |
2949 | int ret = device_create_file(&dev->ofdev.dev, &dev_attr_probe_port); | |
2950 | if (ret) | |
2951 | goto out; | |
2952 | ||
2953 | ret = device_create_file(&dev->ofdev.dev, &dev_attr_remove_port); | |
2954 | out: | |
7a291083 JBT |
2955 | return ret; |
2956 | } | |
2957 | ||
1acf2318 JBT |
2958 | void ehea_remove_device_sysfs(struct ibmebus_dev *dev) |
2959 | { | |
2960 | device_remove_file(&dev->ofdev.dev, &dev_attr_probe_port); | |
2961 | device_remove_file(&dev->ofdev.dev, &dev_attr_remove_port); | |
2962 | } | |
2963 | ||
2964 | static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev, | |
2965 | const struct of_device_id *id) | |
7a291083 JBT |
2966 | { |
2967 | struct ehea_adapter *adapter; | |
9f9a3b8a | 2968 | const u64 *adapter_handle; |
7a291083 JBT |
2969 | int ret; |
2970 | ||
1eef4e04 JBT |
2971 | if (!dev || !dev->ofdev.node) { |
2972 | ehea_error("Invalid ibmebus device probed"); | |
2973 | return -EINVAL; | |
2974 | } | |
2975 | ||
7a291083 JBT |
2976 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); |
2977 | if (!adapter) { | |
2978 | ret = -ENOMEM; | |
2979 | dev_err(&dev->ofdev.dev, "no mem for ehea_adapter\n"); | |
2980 | goto out; | |
2981 | } | |
2982 | ||
44c82152 TK |
2983 | list_add(&adapter->list, &adapter_list); |
2984 | ||
1acf2318 JBT |
2985 | adapter->ebus_dev = dev; |
2986 | ||
40cd3a45 | 2987 | adapter_handle = of_get_property(dev->ofdev.node, "ibm,hea-handle", |
d1d25aab | 2988 | NULL); |
061bf3cd TK |
2989 | if (adapter_handle) |
2990 | adapter->handle = *adapter_handle; | |
2991 | ||
2992 | if (!adapter->handle) { | |
7a291083 JBT |
2993 | dev_err(&dev->ofdev.dev, "failed getting handle for adapter" |
2994 | " '%s'\n", dev->ofdev.node->full_name); | |
2995 | ret = -ENODEV; | |
2996 | goto out_free_ad; | |
2997 | } | |
2998 | ||
7a291083 JBT |
2999 | adapter->pd = EHEA_PD_ID; |
3000 | ||
3001 | dev->ofdev.dev.driver_data = adapter; | |
3002 | ||
7a291083 JBT |
3003 | |
3004 | /* initialize adapter and ports */ | |
3005 | /* get adapter properties */ | |
3006 | ret = ehea_sense_adapter_attr(adapter); | |
3007 | if (ret) { | |
3008 | dev_err(&dev->ofdev.dev, "sense_adapter_attr failed: %d", ret); | |
1211bb6d | 3009 | goto out_free_ad; |
7a291083 | 3010 | } |
7a291083 JBT |
3011 | |
3012 | adapter->neq = ehea_create_eq(adapter, | |
3013 | EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1); | |
3014 | if (!adapter->neq) { | |
1eef4e04 | 3015 | ret = -EIO; |
7a291083 | 3016 | dev_err(&dev->ofdev.dev, "NEQ creation failed"); |
1211bb6d | 3017 | goto out_free_ad; |
7a291083 JBT |
3018 | } |
3019 | ||
3020 | tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet, | |
3021 | (unsigned long)adapter); | |
3022 | ||
3023 | ret = ibmebus_request_irq(NULL, adapter->neq->attr.ist1, | |
38515e90 | 3024 | ehea_interrupt_neq, IRQF_DISABLED, |
7a291083 JBT |
3025 | "ehea_neq", adapter); |
3026 | if (ret) { | |
3027 | dev_err(&dev->ofdev.dev, "requesting NEQ IRQ failed"); | |
3028 | goto out_kill_eq; | |
3029 | } | |
3030 | ||
3031 | adapter->ehea_wq = create_workqueue("ehea_wq"); | |
1eef4e04 JBT |
3032 | if (!adapter->ehea_wq) { |
3033 | ret = -EIO; | |
7a291083 | 3034 | goto out_free_irq; |
1eef4e04 | 3035 | } |
7a291083 | 3036 | |
1eef4e04 JBT |
3037 | ret = ehea_create_device_sysfs(dev); |
3038 | if (ret) | |
1acf2318 JBT |
3039 | goto out_kill_wq; |
3040 | ||
7a291083 JBT |
3041 | ret = ehea_setup_ports(adapter); |
3042 | if (ret) { | |
3043 | dev_err(&dev->ofdev.dev, "setup_ports failed"); | |
1acf2318 | 3044 | goto out_rem_dev_sysfs; |
7a291083 JBT |
3045 | } |
3046 | ||
3047 | ret = 0; | |
3048 | goto out; | |
3049 | ||
1acf2318 JBT |
3050 | out_rem_dev_sysfs: |
3051 | ehea_remove_device_sysfs(dev); | |
3052 | ||
7a291083 JBT |
3053 | out_kill_wq: |
3054 | destroy_workqueue(adapter->ehea_wq); | |
3055 | ||
3056 | out_free_irq: | |
3057 | ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter); | |
3058 | ||
3059 | out_kill_eq: | |
3060 | ehea_destroy_eq(adapter->neq); | |
3061 | ||
7a291083 JBT |
3062 | out_free_ad: |
3063 | kfree(adapter); | |
3064 | out: | |
3065 | return ret; | |
3066 | } | |
3067 | ||
7a291083 JBT |
3068 | static int __devexit ehea_remove(struct ibmebus_dev *dev) |
3069 | { | |
3070 | struct ehea_adapter *adapter = dev->ofdev.dev.driver_data; | |
7a291083 JBT |
3071 | int i; |
3072 | ||
1acf2318 | 3073 | for (i = 0; i < EHEA_MAX_PORTS; i++) |
7a291083 JBT |
3074 | if (adapter->port[i]) { |
3075 | ehea_shutdown_single_port(adapter->port[i]); | |
3076 | adapter->port[i] = NULL; | |
3077 | } | |
1acf2318 JBT |
3078 | |
3079 | ehea_remove_device_sysfs(dev); | |
3080 | ||
7a291083 JBT |
3081 | destroy_workqueue(adapter->ehea_wq); |
3082 | ||
3083 | ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter); | |
d4150a27 | 3084 | tasklet_kill(&adapter->neq_tasklet); |
7a291083 JBT |
3085 | |
3086 | ehea_destroy_eq(adapter->neq); | |
1211bb6d | 3087 | ehea_remove_adapter_mr(adapter); |
44c82152 TK |
3088 | list_del(&adapter->list); |
3089 | ||
7a291083 | 3090 | kfree(adapter); |
44c82152 | 3091 | |
7a291083 JBT |
3092 | return 0; |
3093 | } | |
3094 | ||
3095 | static int check_module_parm(void) | |
3096 | { | |
3097 | int ret = 0; | |
3098 | ||
3099 | if ((rq1_entries < EHEA_MIN_ENTRIES_QP) || | |
3100 | (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) { | |
3101 | ehea_info("Bad parameter: rq1_entries"); | |
3102 | ret = -EINVAL; | |
3103 | } | |
3104 | if ((rq2_entries < EHEA_MIN_ENTRIES_QP) || | |
3105 | (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) { | |
3106 | ehea_info("Bad parameter: rq2_entries"); | |
3107 | ret = -EINVAL; | |
3108 | } | |
3109 | if ((rq3_entries < EHEA_MIN_ENTRIES_QP) || | |
3110 | (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) { | |
3111 | ehea_info("Bad parameter: rq3_entries"); | |
3112 | ret = -EINVAL; | |
3113 | } | |
3114 | if ((sq_entries < EHEA_MIN_ENTRIES_QP) || | |
3115 | (sq_entries > EHEA_MAX_ENTRIES_SQ)) { | |
3116 | ehea_info("Bad parameter: sq_entries"); | |
3117 | ret = -EINVAL; | |
3118 | } | |
3119 | ||
3120 | return ret; | |
3121 | } | |
3122 | ||
4c3ca4da JBT |
3123 | static ssize_t ehea_show_capabilities(struct device_driver *drv, |
3124 | char *buf) | |
3125 | { | |
3126 | return sprintf(buf, "%d", EHEA_CAPABILITIES); | |
3127 | } | |
3128 | ||
3129 | static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH, | |
3130 | ehea_show_capabilities, NULL); | |
3131 | ||
7a291083 JBT |
3132 | int __init ehea_module_init(void) |
3133 | { | |
3134 | int ret; | |
3135 | ||
3136 | printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n", | |
3137 | DRV_VERSION); | |
3138 | ||
44c82152 TK |
3139 | ehea_driver_wq = create_workqueue("ehea_driver_wq"); |
3140 | ||
3141 | INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs); | |
3142 | ||
7a291083 JBT |
3143 | ret = check_module_parm(); |
3144 | if (ret) | |
3145 | goto out; | |
44c82152 TK |
3146 | |
3147 | ret = ehea_create_busmap(); | |
3148 | if (ret) | |
3149 | goto out; | |
3150 | ||
7a291083 | 3151 | ret = ibmebus_register_driver(&ehea_driver); |
4c3ca4da | 3152 | if (ret) { |
7a291083 | 3153 | ehea_error("failed registering eHEA device driver on ebus"); |
4c3ca4da JBT |
3154 | goto out; |
3155 | } | |
3156 | ||
3157 | ret = driver_create_file(&ehea_driver.driver, | |
3158 | &driver_attr_capabilities); | |
3159 | if (ret) { | |
3160 | ehea_error("failed to register capabilities attribute, ret=%d", | |
3161 | ret); | |
3162 | ibmebus_unregister_driver(&ehea_driver); | |
3163 | goto out; | |
3164 | } | |
7a291083 JBT |
3165 | |
3166 | out: | |
3167 | return ret; | |
3168 | } | |
3169 | ||
3170 | static void __exit ehea_module_exit(void) | |
3171 | { | |
f46f6ba9 | 3172 | destroy_workqueue(ehea_driver_wq); |
4c3ca4da | 3173 | driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities); |
7a291083 | 3174 | ibmebus_unregister_driver(&ehea_driver); |
44c82152 | 3175 | ehea_destroy_busmap(); |
7a291083 JBT |
3176 | } |
3177 | ||
3178 | module_init(ehea_module_init); | |
3179 | module_exit(ehea_module_exit); |