diff options
author | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2011-05-13 17:29:12 -0400 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2011-08-11 05:41:59 -0400 |
commit | 9aa3283595451ca093500ff0977b106e1f465586 (patch) | |
tree | 89cd128f037b029b67f73fbff7d8cc38177c2b27 /drivers/net/ethernet/ibm | |
parent | 86387e1ac4fcaa45ff5578013a78593d1a0ba279 (diff) |
ehea/ibm*: Move the IBM drivers
Move the IBM drivers into drivers/net/ethernet/ibm/ and make the
necessary Kconfig and Makefile changes.
- Renamed ibm_new_emac to emac
- Cleaned up Makefile and Kconfig options which referred to
IBM_NEW_EMAC to IBM_EMAC
- ibmlana driver is a National Semiconductor SONIC driver so
it was not moved
CC: Christoph Raisch <raisch@de.ibm.com>
CC: Santiago Leon <santil@linux.vnet.ibm.com>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: David Gibson <dwg@au1.ibm.com>
CC: Kyle Lucke <klucke@us.ibm.com>
CC: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/ibm')
31 files changed, 18123 insertions, 0 deletions
diff --git a/drivers/net/ethernet/ibm/Kconfig b/drivers/net/ethernet/ibm/Kconfig new file mode 100644 index 000000000000..4c7ef980f1c6 --- /dev/null +++ b/drivers/net/ethernet/ibm/Kconfig | |||
@@ -0,0 +1,47 @@ | |||
1 | # | ||
2 | # IBM device configuration. | ||
3 | # | ||
4 | |||
5 | config NET_VENDOR_IBM | ||
6 | bool "IBM devices" | ||
7 | depends on MCA || PPC_PSERIES || PPC_PSERIES || PPC_DCR || \ | ||
8 | (IBMEBUS && INET && SPARSEMEM) | ||
9 | ---help--- | ||
10 | If you have a network (Ethernet) card belonging to this class, say Y | ||
11 | and read the Ethernet-HOWTO, available from | ||
12 | <http://www.tldp.org/docs.html#howto>. | ||
13 | |||
14 | Note that the answer to this question doesn't directly affect the | ||
15 | kernel: saying N will just cause the configurator to skip all | ||
16 | the questions about IBM devices. If you say Y, you will be asked for | ||
17 | your specific card in the following questions. | ||
18 | |||
19 | if NET_VENDOR_IBM | ||
20 | |||
21 | config IBMVETH | ||
22 | tristate "IBM LAN Virtual Ethernet support" | ||
23 | depends on PPC_PSERIES | ||
24 | ---help--- | ||
25 | This driver supports virtual ethernet adapters on newer IBM iSeries | ||
26 | and pSeries systems. | ||
27 | |||
28 | To compile this driver as a module, choose M here. The module will | ||
29 | be called ibmveth. | ||
30 | |||
31 | config ISERIES_VETH | ||
32 | tristate "iSeries Virtual Ethernet driver support" | ||
33 | depends on PPC_ISERIES | ||
34 | |||
35 | source "drivers/net/ethernet/ibm/emac/Kconfig" | ||
36 | |||
37 | config EHEA | ||
38 | tristate "eHEA Ethernet support" | ||
39 | depends on IBMEBUS && INET && SPARSEMEM | ||
40 | select INET_LRO | ||
41 | ---help--- | ||
42 | This driver supports the IBM pSeries eHEA ethernet adapter. | ||
43 | |||
44 | To compile the driver as a module, choose M here. The module | ||
45 | will be called ehea. | ||
46 | |||
47 | endif # NET_VENDOR_IBM | ||
diff --git a/drivers/net/ethernet/ibm/Makefile b/drivers/net/ethernet/ibm/Makefile new file mode 100644 index 000000000000..5a7d4e9ac803 --- /dev/null +++ b/drivers/net/ethernet/ibm/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # | ||
2 | # Makefile for th IBM network device drivers. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_IBMVETH) += ibmveth.o | ||
6 | obj-$(CONFIG_ISERIES_VETH) += iseries_veth.o | ||
7 | obj-$(CONFIG_IBM_EMAC) += emac/ | ||
8 | obj-$(CONFIG_EHEA) += ehea/ | ||
diff --git a/drivers/net/ethernet/ibm/ehea/Makefile b/drivers/net/ethernet/ibm/ehea/Makefile new file mode 100644 index 000000000000..775d9969b5c2 --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | # | ||
2 | # Makefile for the eHEA ethernet device driver for IBM eServer System p | ||
3 | # | ||
4 | ehea-y = ehea_main.o ehea_phyp.o ehea_qmr.o ehea_ethtool.o ehea_phyp.o | ||
5 | obj-$(CONFIG_EHEA) += ehea.o | ||
6 | |||
diff --git a/drivers/net/ethernet/ibm/ehea/ehea.h b/drivers/net/ethernet/ibm/ehea/ehea.h new file mode 100644 index 000000000000..7dd5e6a0d998 --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/ehea.h | |||
@@ -0,0 +1,504 @@ | |||
1 | /* | ||
2 | * linux/drivers/net/ehea/ehea.h | ||
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 | #ifndef __EHEA_H__ | ||
30 | #define __EHEA_H__ | ||
31 | |||
32 | #include <linux/module.h> | ||
33 | #include <linux/ethtool.h> | ||
34 | #include <linux/vmalloc.h> | ||
35 | #include <linux/if_vlan.h> | ||
36 | #include <linux/inet_lro.h> | ||
37 | |||
38 | #include <asm/ibmebus.h> | ||
39 | #include <asm/abs_addr.h> | ||
40 | #include <asm/io.h> | ||
41 | |||
42 | #define DRV_NAME "ehea" | ||
43 | #define DRV_VERSION "EHEA_0107" | ||
44 | |||
45 | /* eHEA capability flags */ | ||
46 | #define DLPAR_PORT_ADD_REM 1 | ||
47 | #define DLPAR_MEM_ADD 2 | ||
48 | #define DLPAR_MEM_REM 4 | ||
49 | #define EHEA_CAPABILITIES (DLPAR_PORT_ADD_REM | DLPAR_MEM_ADD | DLPAR_MEM_REM) | ||
50 | |||
51 | #define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \ | ||
52 | | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR) | ||
53 | |||
54 | #define EHEA_MAX_ENTRIES_RQ1 32767 | ||
55 | #define EHEA_MAX_ENTRIES_RQ2 16383 | ||
56 | #define EHEA_MAX_ENTRIES_RQ3 16383 | ||
57 | #define EHEA_MAX_ENTRIES_SQ 32767 | ||
58 | #define EHEA_MIN_ENTRIES_QP 127 | ||
59 | |||
60 | #define EHEA_SMALL_QUEUES | ||
61 | #define EHEA_NUM_TX_QP 1 | ||
62 | #define EHEA_LRO_MAX_AGGR 64 | ||
63 | |||
64 | #ifdef EHEA_SMALL_QUEUES | ||
65 | #define EHEA_MAX_CQE_COUNT 1023 | ||
66 | #define EHEA_DEF_ENTRIES_SQ 1023 | ||
67 | #define EHEA_DEF_ENTRIES_RQ1 4095 | ||
68 | #define EHEA_DEF_ENTRIES_RQ2 1023 | ||
69 | #define EHEA_DEF_ENTRIES_RQ3 1023 | ||
70 | #else | ||
71 | #define EHEA_MAX_CQE_COUNT 4080 | ||
72 | #define EHEA_DEF_ENTRIES_SQ 4080 | ||
73 | #define EHEA_DEF_ENTRIES_RQ1 8160 | ||
74 | #define EHEA_DEF_ENTRIES_RQ2 2040 | ||
75 | #define EHEA_DEF_ENTRIES_RQ3 2040 | ||
76 | #endif | ||
77 | |||
78 | #define EHEA_MAX_ENTRIES_EQ 20 | ||
79 | |||
80 | #define EHEA_SG_SQ 2 | ||
81 | #define EHEA_SG_RQ1 1 | ||
82 | #define EHEA_SG_RQ2 0 | ||
83 | #define EHEA_SG_RQ3 0 | ||
84 | |||
85 | #define EHEA_MAX_PACKET_SIZE 9022 /* for jumbo frames */ | ||
86 | #define EHEA_RQ2_PKT_SIZE 1522 | ||
87 | #define EHEA_L_PKT_SIZE 256 /* low latency */ | ||
88 | |||
89 | #define MAX_LRO_DESCRIPTORS 8 | ||
90 | |||
91 | /* Send completion signaling */ | ||
92 | |||
93 | /* Protection Domain Identifier */ | ||
94 | #define EHEA_PD_ID 0xaabcdeff | ||
95 | |||
96 | #define EHEA_RQ2_THRESHOLD 1 | ||
97 | #define EHEA_RQ3_THRESHOLD 9 /* use RQ3 threshold of 1522 bytes */ | ||
98 | |||
99 | #define EHEA_SPEED_10G 10000 | ||
100 | #define EHEA_SPEED_1G 1000 | ||
101 | #define EHEA_SPEED_100M 100 | ||
102 | #define EHEA_SPEED_10M 10 | ||
103 | #define EHEA_SPEED_AUTONEG 0 | ||
104 | |||
105 | /* Broadcast/Multicast registration types */ | ||
106 | #define EHEA_BCMC_SCOPE_ALL 0x08 | ||
107 | #define EHEA_BCMC_SCOPE_SINGLE 0x00 | ||
108 | #define EHEA_BCMC_MULTICAST 0x04 | ||
109 | #define EHEA_BCMC_BROADCAST 0x00 | ||
110 | #define EHEA_BCMC_UNTAGGED 0x02 | ||
111 | #define EHEA_BCMC_TAGGED 0x00 | ||
112 | #define EHEA_BCMC_VLANID_ALL 0x01 | ||
113 | #define EHEA_BCMC_VLANID_SINGLE 0x00 | ||
114 | |||
115 | #define EHEA_CACHE_LINE 128 | ||
116 | |||
117 | /* Memory Regions */ | ||
118 | #define EHEA_MR_ACC_CTRL 0x00800000 | ||
119 | |||
120 | #define EHEA_BUSMAP_START 0x8000000000000000ULL | ||
121 | #define EHEA_INVAL_ADDR 0xFFFFFFFFFFFFFFFFULL | ||
122 | #define EHEA_DIR_INDEX_SHIFT 13 /* 8k Entries in 64k block */ | ||
123 | #define EHEA_TOP_INDEX_SHIFT (EHEA_DIR_INDEX_SHIFT * 2) | ||
124 | #define EHEA_MAP_ENTRIES (1 << EHEA_DIR_INDEX_SHIFT) | ||
125 | #define EHEA_MAP_SIZE (0x10000) /* currently fixed map size */ | ||
126 | #define EHEA_INDEX_MASK (EHEA_MAP_ENTRIES - 1) | ||
127 | |||
128 | |||
129 | #define EHEA_WATCH_DOG_TIMEOUT 10*HZ | ||
130 | |||
131 | /* utility functions */ | ||
132 | |||
133 | void ehea_dump(void *adr, int len, char *msg); | ||
134 | |||
135 | #define EHEA_BMASK(pos, length) (((pos) << 16) + (length)) | ||
136 | |||
137 | #define EHEA_BMASK_IBM(from, to) (((63 - to) << 16) + ((to) - (from) + 1)) | ||
138 | |||
139 | #define EHEA_BMASK_SHIFTPOS(mask) (((mask) >> 16) & 0xffff) | ||
140 | |||
141 | #define EHEA_BMASK_MASK(mask) \ | ||
142 | (0xffffffffffffffffULL >> ((64 - (mask)) & 0xffff)) | ||
143 | |||
144 | #define EHEA_BMASK_SET(mask, value) \ | ||
145 | ((EHEA_BMASK_MASK(mask) & ((u64)(value))) << EHEA_BMASK_SHIFTPOS(mask)) | ||
146 | |||
147 | #define EHEA_BMASK_GET(mask, value) \ | ||
148 | (EHEA_BMASK_MASK(mask) & (((u64)(value)) >> EHEA_BMASK_SHIFTPOS(mask))) | ||
149 | |||
150 | /* | ||
151 | * Generic ehea page | ||
152 | */ | ||
153 | struct ehea_page { | ||
154 | u8 entries[PAGE_SIZE]; | ||
155 | }; | ||
156 | |||
157 | /* | ||
158 | * Generic queue in linux kernel virtual memory | ||
159 | */ | ||
160 | struct hw_queue { | ||
161 | u64 current_q_offset; /* current queue entry */ | ||
162 | struct ehea_page **queue_pages; /* array of pages belonging to queue */ | ||
163 | u32 qe_size; /* queue entry size */ | ||
164 | u32 queue_length; /* queue length allocated in bytes */ | ||
165 | u32 pagesize; | ||
166 | u32 toggle_state; /* toggle flag - per page */ | ||
167 | u32 reserved; /* 64 bit alignment */ | ||
168 | }; | ||
169 | |||
170 | /* | ||
171 | * For pSeries this is a 64bit memory address where | ||
172 | * I/O memory is mapped into CPU address space | ||
173 | */ | ||
174 | struct h_epa { | ||
175 | void __iomem *addr; | ||
176 | }; | ||
177 | |||
178 | struct h_epa_user { | ||
179 | u64 addr; | ||
180 | }; | ||
181 | |||
182 | struct h_epas { | ||
183 | struct h_epa kernel; /* kernel space accessible resource, | ||
184 | set to 0 if unused */ | ||
185 | struct h_epa_user user; /* user space accessible resource | ||
186 | set to 0 if unused */ | ||
187 | }; | ||
188 | |||
189 | /* | ||
190 | * Memory map data structures | ||
191 | */ | ||
192 | struct ehea_dir_bmap | ||
193 | { | ||
194 | u64 ent[EHEA_MAP_ENTRIES]; | ||
195 | }; | ||
196 | struct ehea_top_bmap | ||
197 | { | ||
198 | struct ehea_dir_bmap *dir[EHEA_MAP_ENTRIES]; | ||
199 | }; | ||
200 | struct ehea_bmap | ||
201 | { | ||
202 | struct ehea_top_bmap *top[EHEA_MAP_ENTRIES]; | ||
203 | }; | ||
204 | |||
205 | struct ehea_qp; | ||
206 | struct ehea_cq; | ||
207 | struct ehea_eq; | ||
208 | struct ehea_port; | ||
209 | struct ehea_av; | ||
210 | |||
211 | /* | ||
212 | * Queue attributes passed to ehea_create_qp() | ||
213 | */ | ||
214 | struct ehea_qp_init_attr { | ||
215 | /* input parameter */ | ||
216 | u32 qp_token; /* queue token */ | ||
217 | u8 low_lat_rq1; | ||
218 | u8 signalingtype; /* cqe generation flag */ | ||
219 | u8 rq_count; /* num of receive queues */ | ||
220 | u8 eqe_gen; /* eqe generation flag */ | ||
221 | u16 max_nr_send_wqes; /* max number of send wqes */ | ||
222 | u16 max_nr_rwqes_rq1; /* max number of receive wqes */ | ||
223 | u16 max_nr_rwqes_rq2; | ||
224 | u16 max_nr_rwqes_rq3; | ||
225 | u8 wqe_size_enc_sq; | ||
226 | u8 wqe_size_enc_rq1; | ||
227 | u8 wqe_size_enc_rq2; | ||
228 | u8 wqe_size_enc_rq3; | ||
229 | u8 swqe_imm_data_len; /* immediate data length for swqes */ | ||
230 | u16 port_nr; | ||
231 | u16 rq2_threshold; | ||
232 | u16 rq3_threshold; | ||
233 | u64 send_cq_handle; | ||
234 | u64 recv_cq_handle; | ||
235 | u64 aff_eq_handle; | ||
236 | |||
237 | /* output parameter */ | ||
238 | u32 qp_nr; | ||
239 | u16 act_nr_send_wqes; | ||
240 | u16 act_nr_rwqes_rq1; | ||
241 | u16 act_nr_rwqes_rq2; | ||
242 | u16 act_nr_rwqes_rq3; | ||
243 | u8 act_wqe_size_enc_sq; | ||
244 | u8 act_wqe_size_enc_rq1; | ||
245 | u8 act_wqe_size_enc_rq2; | ||
246 | u8 act_wqe_size_enc_rq3; | ||
247 | u32 nr_sq_pages; | ||
248 | u32 nr_rq1_pages; | ||
249 | u32 nr_rq2_pages; | ||
250 | u32 nr_rq3_pages; | ||
251 | u32 liobn_sq; | ||
252 | u32 liobn_rq1; | ||
253 | u32 liobn_rq2; | ||
254 | u32 liobn_rq3; | ||
255 | }; | ||
256 | |||
257 | /* | ||
258 | * Event Queue attributes, passed as parameter | ||
259 | */ | ||
260 | struct ehea_eq_attr { | ||
261 | u32 type; | ||
262 | u32 max_nr_of_eqes; | ||
263 | u8 eqe_gen; /* generate eqe flag */ | ||
264 | u64 eq_handle; | ||
265 | u32 act_nr_of_eqes; | ||
266 | u32 nr_pages; | ||
267 | u32 ist1; /* Interrupt service token */ | ||
268 | u32 ist2; | ||
269 | u32 ist3; | ||
270 | u32 ist4; | ||
271 | }; | ||
272 | |||
273 | |||
274 | /* | ||
275 | * Event Queue | ||
276 | */ | ||
277 | struct ehea_eq { | ||
278 | struct ehea_adapter *adapter; | ||
279 | struct hw_queue hw_queue; | ||
280 | u64 fw_handle; | ||
281 | struct h_epas epas; | ||
282 | spinlock_t spinlock; | ||
283 | struct ehea_eq_attr attr; | ||
284 | }; | ||
285 | |||
286 | /* | ||
287 | * HEA Queues | ||
288 | */ | ||
289 | struct ehea_qp { | ||
290 | struct ehea_adapter *adapter; | ||
291 | u64 fw_handle; /* QP handle for firmware calls */ | ||
292 | struct hw_queue hw_squeue; | ||
293 | struct hw_queue hw_rqueue1; | ||
294 | struct hw_queue hw_rqueue2; | ||
295 | struct hw_queue hw_rqueue3; | ||
296 | struct h_epas epas; | ||
297 | struct ehea_qp_init_attr init_attr; | ||
298 | }; | ||
299 | |||
300 | /* | ||
301 | * Completion Queue attributes | ||
302 | */ | ||
303 | struct ehea_cq_attr { | ||
304 | /* input parameter */ | ||
305 | u32 max_nr_of_cqes; | ||
306 | u32 cq_token; | ||
307 | u64 eq_handle; | ||
308 | |||
309 | /* output parameter */ | ||
310 | u32 act_nr_of_cqes; | ||
311 | u32 nr_pages; | ||
312 | }; | ||
313 | |||
314 | /* | ||
315 | * Completion Queue | ||
316 | */ | ||
317 | struct ehea_cq { | ||
318 | struct ehea_adapter *adapter; | ||
319 | u64 fw_handle; | ||
320 | struct hw_queue hw_queue; | ||
321 | struct h_epas epas; | ||
322 | struct ehea_cq_attr attr; | ||
323 | }; | ||
324 | |||
325 | /* | ||
326 | * Memory Region | ||
327 | */ | ||
328 | struct ehea_mr { | ||
329 | struct ehea_adapter *adapter; | ||
330 | u64 handle; | ||
331 | u64 vaddr; | ||
332 | u32 lkey; | ||
333 | }; | ||
334 | |||
335 | /* | ||
336 | * Port state information | ||
337 | */ | ||
338 | struct port_stats { | ||
339 | int poll_receive_errors; | ||
340 | int queue_stopped; | ||
341 | int err_tcp_cksum; | ||
342 | int err_ip_cksum; | ||
343 | int err_frame_crc; | ||
344 | }; | ||
345 | |||
346 | #define EHEA_IRQ_NAME_SIZE 20 | ||
347 | |||
348 | /* | ||
349 | * Queue SKB Array | ||
350 | */ | ||
351 | struct ehea_q_skb_arr { | ||
352 | struct sk_buff **arr; /* skb array for queue */ | ||
353 | int len; /* array length */ | ||
354 | int index; /* array index */ | ||
355 | int os_skbs; /* rq2/rq3 only: outstanding skbs */ | ||
356 | }; | ||
357 | |||
358 | /* | ||
359 | * Port resources | ||
360 | */ | ||
361 | struct ehea_port_res { | ||
362 | struct napi_struct napi; | ||
363 | struct port_stats p_stats; | ||
364 | struct ehea_mr send_mr; /* send memory region */ | ||
365 | struct ehea_mr recv_mr; /* receive memory region */ | ||
366 | spinlock_t xmit_lock; | ||
367 | struct ehea_port *port; | ||
368 | char int_recv_name[EHEA_IRQ_NAME_SIZE]; | ||
369 | char int_send_name[EHEA_IRQ_NAME_SIZE]; | ||
370 | struct ehea_qp *qp; | ||
371 | struct ehea_cq *send_cq; | ||
372 | struct ehea_cq *recv_cq; | ||
373 | struct ehea_eq *eq; | ||
374 | struct ehea_q_skb_arr rq1_skba; | ||
375 | struct ehea_q_skb_arr rq2_skba; | ||
376 | struct ehea_q_skb_arr rq3_skba; | ||
377 | struct ehea_q_skb_arr sq_skba; | ||
378 | int sq_skba_size; | ||
379 | spinlock_t netif_queue; | ||
380 | int queue_stopped; | ||
381 | int swqe_refill_th; | ||
382 | atomic_t swqe_avail; | ||
383 | int swqe_ll_count; | ||
384 | u32 swqe_id_counter; | ||
385 | u64 tx_packets; | ||
386 | u64 tx_bytes; | ||
387 | u64 rx_packets; | ||
388 | u64 rx_bytes; | ||
389 | u32 poll_counter; | ||
390 | struct net_lro_mgr lro_mgr; | ||
391 | struct net_lro_desc lro_desc[MAX_LRO_DESCRIPTORS]; | ||
392 | int sq_restart_flag; | ||
393 | }; | ||
394 | |||
395 | |||
396 | #define EHEA_MAX_PORTS 16 | ||
397 | |||
398 | #define EHEA_NUM_PORTRES_FW_HANDLES 6 /* QP handle, SendCQ handle, | ||
399 | RecvCQ handle, EQ handle, | ||
400 | SendMR handle, RecvMR handle */ | ||
401 | #define EHEA_NUM_PORT_FW_HANDLES 1 /* EQ handle */ | ||
402 | #define EHEA_NUM_ADAPTER_FW_HANDLES 2 /* MR handle, NEQ handle */ | ||
403 | |||
404 | struct ehea_adapter { | ||
405 | u64 handle; | ||
406 | struct platform_device *ofdev; | ||
407 | struct ehea_port *port[EHEA_MAX_PORTS]; | ||
408 | struct ehea_eq *neq; /* notification event queue */ | ||
409 | struct tasklet_struct neq_tasklet; | ||
410 | struct ehea_mr mr; | ||
411 | u32 pd; /* protection domain */ | ||
412 | u64 max_mc_mac; /* max number of multicast mac addresses */ | ||
413 | int active_ports; | ||
414 | struct list_head list; | ||
415 | }; | ||
416 | |||
417 | |||
418 | struct ehea_mc_list { | ||
419 | struct list_head list; | ||
420 | u64 macaddr; | ||
421 | }; | ||
422 | |||
423 | /* kdump support */ | ||
424 | struct ehea_fw_handle_entry { | ||
425 | u64 adh; /* Adapter Handle */ | ||
426 | u64 fwh; /* Firmware Handle */ | ||
427 | }; | ||
428 | |||
429 | struct ehea_fw_handle_array { | ||
430 | struct ehea_fw_handle_entry *arr; | ||
431 | int num_entries; | ||
432 | struct mutex lock; | ||
433 | }; | ||
434 | |||
435 | struct ehea_bcmc_reg_entry { | ||
436 | u64 adh; /* Adapter Handle */ | ||
437 | u32 port_id; /* Logical Port Id */ | ||
438 | u8 reg_type; /* Registration Type */ | ||
439 | u64 macaddr; | ||
440 | }; | ||
441 | |||
442 | struct ehea_bcmc_reg_array { | ||
443 | struct ehea_bcmc_reg_entry *arr; | ||
444 | int num_entries; | ||
445 | spinlock_t lock; | ||
446 | }; | ||
447 | |||
448 | #define EHEA_PORT_UP 1 | ||
449 | #define EHEA_PORT_DOWN 0 | ||
450 | #define EHEA_PHY_LINK_UP 1 | ||
451 | #define EHEA_PHY_LINK_DOWN 0 | ||
452 | #define EHEA_MAX_PORT_RES 16 | ||
453 | struct ehea_port { | ||
454 | struct ehea_adapter *adapter; /* adapter that owns this port */ | ||
455 | struct net_device *netdev; | ||
456 | struct net_device_stats stats; | ||
457 | struct ehea_port_res port_res[EHEA_MAX_PORT_RES]; | ||
458 | struct platform_device ofdev; /* Open Firmware Device */ | ||
459 | struct ehea_mc_list *mc_list; /* Multicast MAC addresses */ | ||
460 | struct ehea_eq *qp_eq; | ||
461 | struct work_struct reset_task; | ||
462 | struct mutex port_lock; | ||
463 | char int_aff_name[EHEA_IRQ_NAME_SIZE]; | ||
464 | int allmulti; /* Indicates IFF_ALLMULTI state */ | ||
465 | int promisc; /* Indicates IFF_PROMISC state */ | ||
466 | int num_tx_qps; | ||
467 | int num_add_tx_qps; | ||
468 | int num_mcs; | ||
469 | int resets; | ||
470 | unsigned long flags; | ||
471 | u64 mac_addr; | ||
472 | u32 logical_port_id; | ||
473 | u32 port_speed; | ||
474 | u32 msg_enable; | ||
475 | u32 sig_comp_iv; | ||
476 | u32 state; | ||
477 | u32 lro_max_aggr; | ||
478 | u8 phy_link; | ||
479 | u8 full_duplex; | ||
480 | u8 autoneg; | ||
481 | u8 num_def_qps; | ||
482 | wait_queue_head_t swqe_avail_wq; | ||
483 | wait_queue_head_t restart_wq; | ||
484 | }; | ||
485 | |||
486 | struct port_res_cfg { | ||
487 | int max_entries_rcq; | ||
488 | int max_entries_scq; | ||
489 | int max_entries_sq; | ||
490 | int max_entries_rq1; | ||
491 | int max_entries_rq2; | ||
492 | int max_entries_rq3; | ||
493 | }; | ||
494 | |||
495 | enum ehea_flag_bits { | ||
496 | __EHEA_STOP_XFER, | ||
497 | __EHEA_DISABLE_PORT_RESET | ||
498 | }; | ||
499 | |||
500 | void ehea_set_ethtool_ops(struct net_device *netdev); | ||
501 | int ehea_sense_port_attr(struct ehea_port *port); | ||
502 | int ehea_set_portspeed(struct ehea_port *port, u32 port_speed); | ||
503 | |||
504 | #endif /* __EHEA_H__ */ | ||
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_ethtool.c b/drivers/net/ethernet/ibm/ehea/ehea_ethtool.c new file mode 100644 index 000000000000..7f642aef5e82 --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/ehea_ethtool.c | |||
@@ -0,0 +1,295 @@ | |||
1 | /* | ||
2 | * linux/drivers/net/ehea/ehea_ethtool.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 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
30 | |||
31 | #include "ehea.h" | ||
32 | #include "ehea_phyp.h" | ||
33 | |||
34 | static int ehea_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
35 | { | ||
36 | struct ehea_port *port = netdev_priv(dev); | ||
37 | u32 speed; | ||
38 | int ret; | ||
39 | |||
40 | ret = ehea_sense_port_attr(port); | ||
41 | |||
42 | if (ret) | ||
43 | return ret; | ||
44 | |||
45 | if (netif_carrier_ok(dev)) { | ||
46 | switch (port->port_speed) { | ||
47 | case EHEA_SPEED_10M: | ||
48 | speed = SPEED_10; | ||
49 | break; | ||
50 | case EHEA_SPEED_100M: | ||
51 | speed = SPEED_100; | ||
52 | break; | ||
53 | case EHEA_SPEED_1G: | ||
54 | speed = SPEED_1000; | ||
55 | break; | ||
56 | case EHEA_SPEED_10G: | ||
57 | speed = SPEED_10000; | ||
58 | break; | ||
59 | default: | ||
60 | speed = -1; | ||
61 | break; /* BUG */ | ||
62 | } | ||
63 | cmd->duplex = port->full_duplex == 1 ? | ||
64 | DUPLEX_FULL : DUPLEX_HALF; | ||
65 | } else { | ||
66 | speed = ~0; | ||
67 | cmd->duplex = -1; | ||
68 | } | ||
69 | ethtool_cmd_speed_set(cmd, speed); | ||
70 | |||
71 | if (cmd->speed == SPEED_10000) { | ||
72 | cmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); | ||
73 | cmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE); | ||
74 | cmd->port = PORT_FIBRE; | ||
75 | } else { | ||
76 | cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_100baseT_Full | ||
77 | | SUPPORTED_100baseT_Half | SUPPORTED_10baseT_Full | ||
78 | | SUPPORTED_10baseT_Half | SUPPORTED_Autoneg | ||
79 | | SUPPORTED_TP); | ||
80 | cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | ||
81 | | ADVERTISED_TP); | ||
82 | cmd->port = PORT_TP; | ||
83 | } | ||
84 | |||
85 | cmd->autoneg = port->autoneg == 1 ? AUTONEG_ENABLE : AUTONEG_DISABLE; | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | static int ehea_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
91 | { | ||
92 | struct ehea_port *port = netdev_priv(dev); | ||
93 | int ret = 0; | ||
94 | u32 sp; | ||
95 | |||
96 | if (cmd->autoneg == AUTONEG_ENABLE) { | ||
97 | sp = EHEA_SPEED_AUTONEG; | ||
98 | goto doit; | ||
99 | } | ||
100 | |||
101 | switch (cmd->speed) { | ||
102 | case SPEED_10: | ||
103 | if (cmd->duplex == DUPLEX_FULL) | ||
104 | sp = H_SPEED_10M_F; | ||
105 | else | ||
106 | sp = H_SPEED_10M_H; | ||
107 | break; | ||
108 | |||
109 | case SPEED_100: | ||
110 | if (cmd->duplex == DUPLEX_FULL) | ||
111 | sp = H_SPEED_100M_F; | ||
112 | else | ||
113 | sp = H_SPEED_100M_H; | ||
114 | break; | ||
115 | |||
116 | case SPEED_1000: | ||
117 | if (cmd->duplex == DUPLEX_FULL) | ||
118 | sp = H_SPEED_1G_F; | ||
119 | else | ||
120 | ret = -EINVAL; | ||
121 | break; | ||
122 | |||
123 | case SPEED_10000: | ||
124 | if (cmd->duplex == DUPLEX_FULL) | ||
125 | sp = H_SPEED_10G_F; | ||
126 | else | ||
127 | ret = -EINVAL; | ||
128 | break; | ||
129 | |||
130 | default: | ||
131 | ret = -EINVAL; | ||
132 | break; | ||
133 | } | ||
134 | |||
135 | if (ret) | ||
136 | goto out; | ||
137 | doit: | ||
138 | ret = ehea_set_portspeed(port, sp); | ||
139 | |||
140 | if (!ret) | ||
141 | netdev_info(dev, | ||
142 | "Port speed successfully set: %dMbps %s Duplex\n", | ||
143 | port->port_speed, | ||
144 | port->full_duplex == 1 ? "Full" : "Half"); | ||
145 | out: | ||
146 | return ret; | ||
147 | } | ||
148 | |||
149 | static int ehea_nway_reset(struct net_device *dev) | ||
150 | { | ||
151 | struct ehea_port *port = netdev_priv(dev); | ||
152 | int ret; | ||
153 | |||
154 | ret = ehea_set_portspeed(port, EHEA_SPEED_AUTONEG); | ||
155 | |||
156 | if (!ret) | ||
157 | netdev_info(port->netdev, | ||
158 | "Port speed successfully set: %dMbps %s Duplex\n", | ||
159 | port->port_speed, | ||
160 | port->full_duplex == 1 ? "Full" : "Half"); | ||
161 | return ret; | ||
162 | } | ||
163 | |||
164 | static void ehea_get_drvinfo(struct net_device *dev, | ||
165 | struct ethtool_drvinfo *info) | ||
166 | { | ||
167 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); | ||
168 | strlcpy(info->version, DRV_VERSION, sizeof(info->version)); | ||
169 | } | ||
170 | |||
171 | static u32 ehea_get_msglevel(struct net_device *dev) | ||
172 | { | ||
173 | struct ehea_port *port = netdev_priv(dev); | ||
174 | return port->msg_enable; | ||
175 | } | ||
176 | |||
177 | static void ehea_set_msglevel(struct net_device *dev, u32 value) | ||
178 | { | ||
179 | struct ehea_port *port = netdev_priv(dev); | ||
180 | port->msg_enable = value; | ||
181 | } | ||
182 | |||
183 | static char ehea_ethtool_stats_keys[][ETH_GSTRING_LEN] = { | ||
184 | {"sig_comp_iv"}, | ||
185 | {"swqe_refill_th"}, | ||
186 | {"port resets"}, | ||
187 | {"Receive errors"}, | ||
188 | {"TCP cksum errors"}, | ||
189 | {"IP cksum errors"}, | ||
190 | {"Frame cksum errors"}, | ||
191 | {"num SQ stopped"}, | ||
192 | {"SQ stopped"}, | ||
193 | {"PR0 free_swqes"}, | ||
194 | {"PR1 free_swqes"}, | ||
195 | {"PR2 free_swqes"}, | ||
196 | {"PR3 free_swqes"}, | ||
197 | {"PR4 free_swqes"}, | ||
198 | {"PR5 free_swqes"}, | ||
199 | {"PR6 free_swqes"}, | ||
200 | {"PR7 free_swqes"}, | ||
201 | {"LRO aggregated"}, | ||
202 | {"LRO flushed"}, | ||
203 | {"LRO no_desc"}, | ||
204 | }; | ||
205 | |||
206 | static void ehea_get_strings(struct net_device *dev, u32 stringset, u8 *data) | ||
207 | { | ||
208 | if (stringset == ETH_SS_STATS) { | ||
209 | memcpy(data, &ehea_ethtool_stats_keys, | ||
210 | sizeof(ehea_ethtool_stats_keys)); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | static int ehea_get_sset_count(struct net_device *dev, int sset) | ||
215 | { | ||
216 | switch (sset) { | ||
217 | case ETH_SS_STATS: | ||
218 | return ARRAY_SIZE(ehea_ethtool_stats_keys); | ||
219 | default: | ||
220 | return -EOPNOTSUPP; | ||
221 | } | ||
222 | } | ||
223 | |||
224 | static void ehea_get_ethtool_stats(struct net_device *dev, | ||
225 | struct ethtool_stats *stats, u64 *data) | ||
226 | { | ||
227 | int i, k, tmp; | ||
228 | struct ehea_port *port = netdev_priv(dev); | ||
229 | |||
230 | for (i = 0; i < ehea_get_sset_count(dev, ETH_SS_STATS); i++) | ||
231 | data[i] = 0; | ||
232 | i = 0; | ||
233 | |||
234 | data[i++] = port->sig_comp_iv; | ||
235 | data[i++] = port->port_res[0].swqe_refill_th; | ||
236 | data[i++] = port->resets; | ||
237 | |||
238 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
239 | tmp += port->port_res[k].p_stats.poll_receive_errors; | ||
240 | data[i++] = tmp; | ||
241 | |||
242 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
243 | tmp += port->port_res[k].p_stats.err_tcp_cksum; | ||
244 | data[i++] = tmp; | ||
245 | |||
246 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
247 | tmp += port->port_res[k].p_stats.err_ip_cksum; | ||
248 | data[i++] = tmp; | ||
249 | |||
250 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
251 | tmp += port->port_res[k].p_stats.err_frame_crc; | ||
252 | data[i++] = tmp; | ||
253 | |||
254 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
255 | tmp += port->port_res[k].p_stats.queue_stopped; | ||
256 | data[i++] = tmp; | ||
257 | |||
258 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
259 | tmp |= port->port_res[k].queue_stopped; | ||
260 | data[i++] = tmp; | ||
261 | |||
262 | for (k = 0; k < 8; k++) | ||
263 | data[i++] = atomic_read(&port->port_res[k].swqe_avail); | ||
264 | |||
265 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
266 | tmp |= port->port_res[k].lro_mgr.stats.aggregated; | ||
267 | data[i++] = tmp; | ||
268 | |||
269 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
270 | tmp |= port->port_res[k].lro_mgr.stats.flushed; | ||
271 | data[i++] = tmp; | ||
272 | |||
273 | for (k = 0, tmp = 0; k < EHEA_MAX_PORT_RES; k++) | ||
274 | tmp |= port->port_res[k].lro_mgr.stats.no_desc; | ||
275 | data[i++] = tmp; | ||
276 | |||
277 | } | ||
278 | |||
279 | const struct ethtool_ops ehea_ethtool_ops = { | ||
280 | .get_settings = ehea_get_settings, | ||
281 | .get_drvinfo = ehea_get_drvinfo, | ||
282 | .get_msglevel = ehea_get_msglevel, | ||
283 | .set_msglevel = ehea_set_msglevel, | ||
284 | .get_link = ethtool_op_get_link, | ||
285 | .get_strings = ehea_get_strings, | ||
286 | .get_sset_count = ehea_get_sset_count, | ||
287 | .get_ethtool_stats = ehea_get_ethtool_stats, | ||
288 | .set_settings = ehea_set_settings, | ||
289 | .nway_reset = ehea_nway_reset, /* Restart autonegotiation */ | ||
290 | }; | ||
291 | |||
292 | void ehea_set_ethtool_ops(struct net_device *netdev) | ||
293 | { | ||
294 | SET_ETHTOOL_OPS(netdev, &ehea_ethtool_ops); | ||
295 | } | ||
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_hw.h b/drivers/net/ethernet/ibm/ehea/ehea_hw.h new file mode 100644 index 000000000000..567981b4b2cc --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/ehea_hw.h | |||
@@ -0,0 +1,292 @@ | |||
1 | /* | ||
2 | * linux/drivers/net/ehea/ehea_hw.h | ||
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 | #ifndef __EHEA_HW_H__ | ||
30 | #define __EHEA_HW_H__ | ||
31 | |||
32 | #define QPX_SQA_VALUE EHEA_BMASK_IBM(48, 63) | ||
33 | #define QPX_RQ1A_VALUE EHEA_BMASK_IBM(48, 63) | ||
34 | #define QPX_RQ2A_VALUE EHEA_BMASK_IBM(48, 63) | ||
35 | #define QPX_RQ3A_VALUE EHEA_BMASK_IBM(48, 63) | ||
36 | |||
37 | #define QPTEMM_OFFSET(x) offsetof(struct ehea_qptemm, x) | ||
38 | |||
39 | struct ehea_qptemm { | ||
40 | u64 qpx_hcr; | ||
41 | u64 qpx_c; | ||
42 | u64 qpx_herr; | ||
43 | u64 qpx_aer; | ||
44 | u64 qpx_sqa; | ||
45 | u64 qpx_sqc; | ||
46 | u64 qpx_rq1a; | ||
47 | u64 qpx_rq1c; | ||
48 | u64 qpx_st; | ||
49 | u64 qpx_aerr; | ||
50 | u64 qpx_tenure; | ||
51 | u64 qpx_reserved1[(0x098 - 0x058) / 8]; | ||
52 | u64 qpx_portp; | ||
53 | u64 qpx_reserved2[(0x100 - 0x0A0) / 8]; | ||
54 | u64 qpx_t; | ||
55 | u64 qpx_sqhp; | ||
56 | u64 qpx_sqptp; | ||
57 | u64 qpx_reserved3[(0x140 - 0x118) / 8]; | ||
58 | u64 qpx_sqwsize; | ||
59 | u64 qpx_reserved4[(0x170 - 0x148) / 8]; | ||
60 | u64 qpx_sqsize; | ||
61 | u64 qpx_reserved5[(0x1B0 - 0x178) / 8]; | ||
62 | u64 qpx_sigt; | ||
63 | u64 qpx_wqecnt; | ||
64 | u64 qpx_rq1hp; | ||
65 | u64 qpx_rq1ptp; | ||
66 | u64 qpx_rq1size; | ||
67 | u64 qpx_reserved6[(0x220 - 0x1D8) / 8]; | ||
68 | u64 qpx_rq1wsize; | ||
69 | u64 qpx_reserved7[(0x240 - 0x228) / 8]; | ||
70 | u64 qpx_pd; | ||
71 | u64 qpx_scqn; | ||
72 | u64 qpx_rcqn; | ||
73 | u64 qpx_aeqn; | ||
74 | u64 reserved49; | ||
75 | u64 qpx_ram; | ||
76 | u64 qpx_reserved8[(0x300 - 0x270) / 8]; | ||
77 | u64 qpx_rq2a; | ||
78 | u64 qpx_rq2c; | ||
79 | u64 qpx_rq2hp; | ||
80 | u64 qpx_rq2ptp; | ||
81 | u64 qpx_rq2size; | ||
82 | u64 qpx_rq2wsize; | ||
83 | u64 qpx_rq2th; | ||
84 | u64 qpx_rq3a; | ||
85 | u64 qpx_rq3c; | ||
86 | u64 qpx_rq3hp; | ||
87 | u64 qpx_rq3ptp; | ||
88 | u64 qpx_rq3size; | ||
89 | u64 qpx_rq3wsize; | ||
90 | u64 qpx_rq3th; | ||
91 | u64 qpx_lpn; | ||
92 | u64 qpx_reserved9[(0x400 - 0x378) / 8]; | ||
93 | u64 reserved_ext[(0x500 - 0x400) / 8]; | ||
94 | u64 reserved2[(0x1000 - 0x500) / 8]; | ||
95 | }; | ||
96 | |||
97 | #define MRx_HCR_LPARID_VALID EHEA_BMASK_IBM(0, 0) | ||
98 | |||
99 | #define MRMWMM_OFFSET(x) offsetof(struct ehea_mrmwmm, x) | ||
100 | |||
101 | struct ehea_mrmwmm { | ||
102 | u64 mrx_hcr; | ||
103 | u64 mrx_c; | ||
104 | u64 mrx_herr; | ||
105 | u64 mrx_aer; | ||
106 | u64 mrx_pp; | ||
107 | u64 reserved1; | ||
108 | u64 reserved2; | ||
109 | u64 reserved3; | ||
110 | u64 reserved4[(0x200 - 0x40) / 8]; | ||
111 | u64 mrx_ctl[64]; | ||
112 | }; | ||
113 | |||
114 | #define QPEDMM_OFFSET(x) offsetof(struct ehea_qpedmm, x) | ||
115 | |||
116 | struct ehea_qpedmm { | ||
117 | |||
118 | u64 reserved0[(0x400) / 8]; | ||
119 | u64 qpedx_phh; | ||
120 | u64 qpedx_ppsgp; | ||
121 | u64 qpedx_ppsgu; | ||
122 | u64 qpedx_ppdgp; | ||
123 | u64 qpedx_ppdgu; | ||
124 | u64 qpedx_aph; | ||
125 | u64 qpedx_apsgp; | ||
126 | u64 qpedx_apsgu; | ||
127 | u64 qpedx_apdgp; | ||
128 | u64 qpedx_apdgu; | ||
129 | u64 qpedx_apav; | ||
130 | u64 qpedx_apsav; | ||
131 | u64 qpedx_hcr; | ||
132 | u64 reserved1[4]; | ||
133 | u64 qpedx_rrl0; | ||
134 | u64 qpedx_rrrkey0; | ||
135 | u64 qpedx_rrva0; | ||
136 | u64 reserved2; | ||
137 | u64 qpedx_rrl1; | ||
138 | u64 qpedx_rrrkey1; | ||
139 | u64 qpedx_rrva1; | ||
140 | u64 reserved3; | ||
141 | u64 qpedx_rrl2; | ||
142 | u64 qpedx_rrrkey2; | ||
143 | u64 qpedx_rrva2; | ||
144 | u64 reserved4; | ||
145 | u64 qpedx_rrl3; | ||
146 | u64 qpedx_rrrkey3; | ||
147 | u64 qpedx_rrva3; | ||
148 | }; | ||
149 | |||
150 | #define CQX_FECADDER EHEA_BMASK_IBM(32, 63) | ||
151 | #define CQX_FEC_CQE_CNT EHEA_BMASK_IBM(32, 63) | ||
152 | #define CQX_N1_GENERATE_COMP_EVENT EHEA_BMASK_IBM(0, 0) | ||
153 | #define CQX_EP_EVENT_PENDING EHEA_BMASK_IBM(0, 0) | ||
154 | |||
155 | #define CQTEMM_OFFSET(x) offsetof(struct ehea_cqtemm, x) | ||
156 | |||
157 | struct ehea_cqtemm { | ||
158 | u64 cqx_hcr; | ||
159 | u64 cqx_c; | ||
160 | u64 cqx_herr; | ||
161 | u64 cqx_aer; | ||
162 | u64 cqx_ptp; | ||
163 | u64 cqx_tp; | ||
164 | u64 cqx_fec; | ||
165 | u64 cqx_feca; | ||
166 | u64 cqx_ep; | ||
167 | u64 cqx_eq; | ||
168 | u64 reserved1; | ||
169 | u64 cqx_n0; | ||
170 | u64 cqx_n1; | ||
171 | u64 reserved2[(0x1000 - 0x60) / 8]; | ||
172 | }; | ||
173 | |||
174 | #define EQTEMM_OFFSET(x) offsetof(struct ehea_eqtemm, x) | ||
175 | |||
176 | struct ehea_eqtemm { | ||
177 | u64 eqx_hcr; | ||
178 | u64 eqx_c; | ||
179 | u64 eqx_herr; | ||
180 | u64 eqx_aer; | ||
181 | u64 eqx_ptp; | ||
182 | u64 eqx_tp; | ||
183 | u64 eqx_ssba; | ||
184 | u64 eqx_psba; | ||
185 | u64 eqx_cec; | ||
186 | u64 eqx_meql; | ||
187 | u64 eqx_xisbi; | ||
188 | u64 eqx_xisc; | ||
189 | u64 eqx_it; | ||
190 | }; | ||
191 | |||
192 | /* | ||
193 | * These access functions will be changed when the dissuccsion about | ||
194 | * the new access methods for POWER has settled. | ||
195 | */ | ||
196 | |||
197 | static inline u64 epa_load(struct h_epa epa, u32 offset) | ||
198 | { | ||
199 | return __raw_readq((void __iomem *)(epa.addr + offset)); | ||
200 | } | ||
201 | |||
202 | static inline void epa_store(struct h_epa epa, u32 offset, u64 value) | ||
203 | { | ||
204 | __raw_writeq(value, (void __iomem *)(epa.addr + offset)); | ||
205 | epa_load(epa, offset); /* synchronize explicitly to eHEA */ | ||
206 | } | ||
207 | |||
208 | static inline void epa_store_acc(struct h_epa epa, u32 offset, u64 value) | ||
209 | { | ||
210 | __raw_writeq(value, (void __iomem *)(epa.addr + offset)); | ||
211 | } | ||
212 | |||
213 | #define epa_store_eq(epa, offset, value)\ | ||
214 | epa_store(epa, EQTEMM_OFFSET(offset), value) | ||
215 | #define epa_load_eq(epa, offset)\ | ||
216 | epa_load(epa, EQTEMM_OFFSET(offset)) | ||
217 | |||
218 | #define epa_store_cq(epa, offset, value)\ | ||
219 | epa_store(epa, CQTEMM_OFFSET(offset), value) | ||
220 | #define epa_load_cq(epa, offset)\ | ||
221 | epa_load(epa, CQTEMM_OFFSET(offset)) | ||
222 | |||
223 | #define epa_store_qp(epa, offset, value)\ | ||
224 | epa_store(epa, QPTEMM_OFFSET(offset), value) | ||
225 | #define epa_load_qp(epa, offset)\ | ||
226 | epa_load(epa, QPTEMM_OFFSET(offset)) | ||
227 | |||
228 | #define epa_store_qped(epa, offset, value)\ | ||
229 | epa_store(epa, QPEDMM_OFFSET(offset), value) | ||
230 | #define epa_load_qped(epa, offset)\ | ||
231 | epa_load(epa, QPEDMM_OFFSET(offset)) | ||
232 | |||
233 | #define epa_store_mrmw(epa, offset, value)\ | ||
234 | epa_store(epa, MRMWMM_OFFSET(offset), value) | ||
235 | #define epa_load_mrmw(epa, offset)\ | ||
236 | epa_load(epa, MRMWMM_OFFSET(offset)) | ||
237 | |||
238 | #define epa_store_base(epa, offset, value)\ | ||
239 | epa_store(epa, HCAGR_OFFSET(offset), value) | ||
240 | #define epa_load_base(epa, offset)\ | ||
241 | epa_load(epa, HCAGR_OFFSET(offset)) | ||
242 | |||
243 | static inline void ehea_update_sqa(struct ehea_qp *qp, u16 nr_wqes) | ||
244 | { | ||
245 | struct h_epa epa = qp->epas.kernel; | ||
246 | epa_store_acc(epa, QPTEMM_OFFSET(qpx_sqa), | ||
247 | EHEA_BMASK_SET(QPX_SQA_VALUE, nr_wqes)); | ||
248 | } | ||
249 | |||
250 | static inline void ehea_update_rq3a(struct ehea_qp *qp, u16 nr_wqes) | ||
251 | { | ||
252 | struct h_epa epa = qp->epas.kernel; | ||
253 | epa_store_acc(epa, QPTEMM_OFFSET(qpx_rq3a), | ||
254 | EHEA_BMASK_SET(QPX_RQ1A_VALUE, nr_wqes)); | ||
255 | } | ||
256 | |||
257 | static inline void ehea_update_rq2a(struct ehea_qp *qp, u16 nr_wqes) | ||
258 | { | ||
259 | struct h_epa epa = qp->epas.kernel; | ||
260 | epa_store_acc(epa, QPTEMM_OFFSET(qpx_rq2a), | ||
261 | EHEA_BMASK_SET(QPX_RQ2A_VALUE, nr_wqes)); | ||
262 | } | ||
263 | |||
264 | static inline void ehea_update_rq1a(struct ehea_qp *qp, u16 nr_wqes) | ||
265 | { | ||
266 | struct h_epa epa = qp->epas.kernel; | ||
267 | epa_store_acc(epa, QPTEMM_OFFSET(qpx_rq1a), | ||
268 | EHEA_BMASK_SET(QPX_RQ3A_VALUE, nr_wqes)); | ||
269 | } | ||
270 | |||
271 | static inline void ehea_update_feca(struct ehea_cq *cq, u32 nr_cqes) | ||
272 | { | ||
273 | struct h_epa epa = cq->epas.kernel; | ||
274 | epa_store_acc(epa, CQTEMM_OFFSET(cqx_feca), | ||
275 | EHEA_BMASK_SET(CQX_FECADDER, nr_cqes)); | ||
276 | } | ||
277 | |||
278 | static inline void ehea_reset_cq_n1(struct ehea_cq *cq) | ||
279 | { | ||
280 | struct h_epa epa = cq->epas.kernel; | ||
281 | epa_store_cq(epa, cqx_n1, | ||
282 | EHEA_BMASK_SET(CQX_N1_GENERATE_COMP_EVENT, 1)); | ||
283 | } | ||
284 | |||
285 | static inline void ehea_reset_cq_ep(struct ehea_cq *my_cq) | ||
286 | { | ||
287 | struct h_epa epa = my_cq->epas.kernel; | ||
288 | epa_store_acc(epa, CQTEMM_OFFSET(cqx_ep), | ||
289 | EHEA_BMASK_SET(CQX_EP_EVENT_PENDING, 0)); | ||
290 | } | ||
291 | |||
292 | #endif /* __EHEA_HW_H__ */ | ||
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_main.c b/drivers/net/ethernet/ibm/ehea/ehea_main.c new file mode 100644 index 000000000000..be2cb4ab8b4f --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/ehea_main.c | |||
@@ -0,0 +1,3768 @@ | |||
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 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
30 | |||
31 | #include <linux/in.h> | ||
32 | #include <linux/ip.h> | ||
33 | #include <linux/tcp.h> | ||
34 | #include <linux/udp.h> | ||
35 | #include <linux/if.h> | ||
36 | #include <linux/list.h> | ||
37 | #include <linux/slab.h> | ||
38 | #include <linux/if_ether.h> | ||
39 | #include <linux/notifier.h> | ||
40 | #include <linux/reboot.h> | ||
41 | #include <linux/memory.h> | ||
42 | #include <asm/kexec.h> | ||
43 | #include <linux/mutex.h> | ||
44 | #include <linux/prefetch.h> | ||
45 | |||
46 | #include <net/ip.h> | ||
47 | |||
48 | #include "ehea.h" | ||
49 | #include "ehea_qmr.h" | ||
50 | #include "ehea_phyp.h" | ||
51 | |||
52 | |||
53 | MODULE_LICENSE("GPL"); | ||
54 | MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); | ||
55 | MODULE_DESCRIPTION("IBM eServer HEA Driver"); | ||
56 | MODULE_VERSION(DRV_VERSION); | ||
57 | |||
58 | |||
59 | static int msg_level = -1; | ||
60 | static int rq1_entries = EHEA_DEF_ENTRIES_RQ1; | ||
61 | static int rq2_entries = EHEA_DEF_ENTRIES_RQ2; | ||
62 | static int rq3_entries = EHEA_DEF_ENTRIES_RQ3; | ||
63 | static int sq_entries = EHEA_DEF_ENTRIES_SQ; | ||
64 | static int use_mcs; | ||
65 | static int use_lro; | ||
66 | static int lro_max_aggr = EHEA_LRO_MAX_AGGR; | ||
67 | static int num_tx_qps = EHEA_NUM_TX_QP; | ||
68 | static int prop_carrier_state; | ||
69 | |||
70 | module_param(msg_level, int, 0); | ||
71 | module_param(rq1_entries, int, 0); | ||
72 | module_param(rq2_entries, int, 0); | ||
73 | module_param(rq3_entries, int, 0); | ||
74 | module_param(sq_entries, int, 0); | ||
75 | module_param(prop_carrier_state, int, 0); | ||
76 | module_param(use_mcs, int, 0); | ||
77 | module_param(use_lro, int, 0); | ||
78 | module_param(lro_max_aggr, int, 0); | ||
79 | module_param(num_tx_qps, int, 0); | ||
80 | |||
81 | MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS"); | ||
82 | MODULE_PARM_DESC(msg_level, "msg_level"); | ||
83 | MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical " | ||
84 | "port to stack. 1:yes, 0:no. Default = 0 "); | ||
85 | MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 " | ||
86 | "[2^x - 1], x = [6..14]. Default = " | ||
87 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")"); | ||
88 | MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 " | ||
89 | "[2^x - 1], x = [6..14]. Default = " | ||
90 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")"); | ||
91 | MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 " | ||
92 | "[2^x - 1], x = [6..14]. Default = " | ||
93 | __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")"); | ||
94 | MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue " | ||
95 | "[2^x - 1], x = [6..14]. Default = " | ||
96 | __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")"); | ||
97 | MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 "); | ||
98 | |||
99 | MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = " | ||
100 | __MODULE_STRING(EHEA_LRO_MAX_AGGR)); | ||
101 | MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, " | ||
102 | "Default = 0"); | ||
103 | |||
104 | static int port_name_cnt; | ||
105 | static LIST_HEAD(adapter_list); | ||
106 | static unsigned long ehea_driver_flags; | ||
107 | static DEFINE_MUTEX(dlpar_mem_lock); | ||
108 | struct ehea_fw_handle_array ehea_fw_handles; | ||
109 | struct ehea_bcmc_reg_array ehea_bcmc_regs; | ||
110 | |||
111 | |||
112 | static int __devinit ehea_probe_adapter(struct platform_device *dev, | ||
113 | const struct of_device_id *id); | ||
114 | |||
115 | static int __devexit ehea_remove(struct platform_device *dev); | ||
116 | |||
117 | static struct of_device_id ehea_device_table[] = { | ||
118 | { | ||
119 | .name = "lhea", | ||
120 | .compatible = "IBM,lhea", | ||
121 | }, | ||
122 | {}, | ||
123 | }; | ||
124 | MODULE_DEVICE_TABLE(of, ehea_device_table); | ||
125 | |||
126 | static struct of_platform_driver ehea_driver = { | ||
127 | .driver = { | ||
128 | .name = "ehea", | ||
129 | .owner = THIS_MODULE, | ||
130 | .of_match_table = ehea_device_table, | ||
131 | }, | ||
132 | .probe = ehea_probe_adapter, | ||
133 | .remove = ehea_remove, | ||
134 | }; | ||
135 | |||
136 | void ehea_dump(void *adr, int len, char *msg) | ||
137 | { | ||
138 | int x; | ||
139 | unsigned char *deb = adr; | ||
140 | for (x = 0; x < len; x += 16) { | ||
141 | pr_info("%s adr=%p ofs=%04x %016llx %016llx\n", | ||
142 | msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8])); | ||
143 | deb += 16; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | void ehea_schedule_port_reset(struct ehea_port *port) | ||
148 | { | ||
149 | if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags)) | ||
150 | schedule_work(&port->reset_task); | ||
151 | } | ||
152 | |||
153 | static void ehea_update_firmware_handles(void) | ||
154 | { | ||
155 | struct ehea_fw_handle_entry *arr = NULL; | ||
156 | struct ehea_adapter *adapter; | ||
157 | int num_adapters = 0; | ||
158 | int num_ports = 0; | ||
159 | int num_portres = 0; | ||
160 | int i = 0; | ||
161 | int num_fw_handles, k, l; | ||
162 | |||
163 | /* Determine number of handles */ | ||
164 | mutex_lock(&ehea_fw_handles.lock); | ||
165 | |||
166 | list_for_each_entry(adapter, &adapter_list, list) { | ||
167 | num_adapters++; | ||
168 | |||
169 | for (k = 0; k < EHEA_MAX_PORTS; k++) { | ||
170 | struct ehea_port *port = adapter->port[k]; | ||
171 | |||
172 | if (!port || (port->state != EHEA_PORT_UP)) | ||
173 | continue; | ||
174 | |||
175 | num_ports++; | ||
176 | num_portres += port->num_def_qps + port->num_add_tx_qps; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES + | ||
181 | num_ports * EHEA_NUM_PORT_FW_HANDLES + | ||
182 | num_portres * EHEA_NUM_PORTRES_FW_HANDLES; | ||
183 | |||
184 | if (num_fw_handles) { | ||
185 | arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL); | ||
186 | if (!arr) | ||
187 | goto out; /* Keep the existing array */ | ||
188 | } else | ||
189 | goto out_update; | ||
190 | |||
191 | list_for_each_entry(adapter, &adapter_list, list) { | ||
192 | if (num_adapters == 0) | ||
193 | break; | ||
194 | |||
195 | for (k = 0; k < EHEA_MAX_PORTS; k++) { | ||
196 | struct ehea_port *port = adapter->port[k]; | ||
197 | |||
198 | if (!port || (port->state != EHEA_PORT_UP) || | ||
199 | (num_ports == 0)) | ||
200 | continue; | ||
201 | |||
202 | for (l = 0; | ||
203 | l < port->num_def_qps + port->num_add_tx_qps; | ||
204 | l++) { | ||
205 | struct ehea_port_res *pr = &port->port_res[l]; | ||
206 | |||
207 | arr[i].adh = adapter->handle; | ||
208 | arr[i++].fwh = pr->qp->fw_handle; | ||
209 | arr[i].adh = adapter->handle; | ||
210 | arr[i++].fwh = pr->send_cq->fw_handle; | ||
211 | arr[i].adh = adapter->handle; | ||
212 | arr[i++].fwh = pr->recv_cq->fw_handle; | ||
213 | arr[i].adh = adapter->handle; | ||
214 | arr[i++].fwh = pr->eq->fw_handle; | ||
215 | arr[i].adh = adapter->handle; | ||
216 | arr[i++].fwh = pr->send_mr.handle; | ||
217 | arr[i].adh = adapter->handle; | ||
218 | arr[i++].fwh = pr->recv_mr.handle; | ||
219 | } | ||
220 | arr[i].adh = adapter->handle; | ||
221 | arr[i++].fwh = port->qp_eq->fw_handle; | ||
222 | num_ports--; | ||
223 | } | ||
224 | |||
225 | arr[i].adh = adapter->handle; | ||
226 | arr[i++].fwh = adapter->neq->fw_handle; | ||
227 | |||
228 | if (adapter->mr.handle) { | ||
229 | arr[i].adh = adapter->handle; | ||
230 | arr[i++].fwh = adapter->mr.handle; | ||
231 | } | ||
232 | num_adapters--; | ||
233 | } | ||
234 | |||
235 | out_update: | ||
236 | kfree(ehea_fw_handles.arr); | ||
237 | ehea_fw_handles.arr = arr; | ||
238 | ehea_fw_handles.num_entries = i; | ||
239 | out: | ||
240 | mutex_unlock(&ehea_fw_handles.lock); | ||
241 | } | ||
242 | |||
243 | static void ehea_update_bcmc_registrations(void) | ||
244 | { | ||
245 | unsigned long flags; | ||
246 | struct ehea_bcmc_reg_entry *arr = NULL; | ||
247 | struct ehea_adapter *adapter; | ||
248 | struct ehea_mc_list *mc_entry; | ||
249 | int num_registrations = 0; | ||
250 | int i = 0; | ||
251 | int k; | ||
252 | |||
253 | spin_lock_irqsave(&ehea_bcmc_regs.lock, flags); | ||
254 | |||
255 | /* Determine number of registrations */ | ||
256 | list_for_each_entry(adapter, &adapter_list, list) | ||
257 | for (k = 0; k < EHEA_MAX_PORTS; k++) { | ||
258 | struct ehea_port *port = adapter->port[k]; | ||
259 | |||
260 | if (!port || (port->state != EHEA_PORT_UP)) | ||
261 | continue; | ||
262 | |||
263 | num_registrations += 2; /* Broadcast registrations */ | ||
264 | |||
265 | list_for_each_entry(mc_entry, &port->mc_list->list,list) | ||
266 | num_registrations += 2; | ||
267 | } | ||
268 | |||
269 | if (num_registrations) { | ||
270 | arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC); | ||
271 | if (!arr) | ||
272 | goto out; /* Keep the existing array */ | ||
273 | } else | ||
274 | goto out_update; | ||
275 | |||
276 | list_for_each_entry(adapter, &adapter_list, list) { | ||
277 | for (k = 0; k < EHEA_MAX_PORTS; k++) { | ||
278 | struct ehea_port *port = adapter->port[k]; | ||
279 | |||
280 | if (!port || (port->state != EHEA_PORT_UP)) | ||
281 | continue; | ||
282 | |||
283 | if (num_registrations == 0) | ||
284 | goto out_update; | ||
285 | |||
286 | arr[i].adh = adapter->handle; | ||
287 | arr[i].port_id = port->logical_port_id; | ||
288 | arr[i].reg_type = EHEA_BCMC_BROADCAST | | ||
289 | EHEA_BCMC_UNTAGGED; | ||
290 | arr[i++].macaddr = port->mac_addr; | ||
291 | |||
292 | arr[i].adh = adapter->handle; | ||
293 | arr[i].port_id = port->logical_port_id; | ||
294 | arr[i].reg_type = EHEA_BCMC_BROADCAST | | ||
295 | EHEA_BCMC_VLANID_ALL; | ||
296 | arr[i++].macaddr = port->mac_addr; | ||
297 | num_registrations -= 2; | ||
298 | |||
299 | list_for_each_entry(mc_entry, | ||
300 | &port->mc_list->list, list) { | ||
301 | if (num_registrations == 0) | ||
302 | goto out_update; | ||
303 | |||
304 | arr[i].adh = adapter->handle; | ||
305 | arr[i].port_id = port->logical_port_id; | ||
306 | arr[i].reg_type = EHEA_BCMC_SCOPE_ALL | | ||
307 | EHEA_BCMC_MULTICAST | | ||
308 | EHEA_BCMC_UNTAGGED; | ||
309 | arr[i++].macaddr = mc_entry->macaddr; | ||
310 | |||
311 | arr[i].adh = adapter->handle; | ||
312 | arr[i].port_id = port->logical_port_id; | ||
313 | arr[i].reg_type = EHEA_BCMC_SCOPE_ALL | | ||
314 | EHEA_BCMC_MULTICAST | | ||
315 | EHEA_BCMC_VLANID_ALL; | ||
316 | arr[i++].macaddr = mc_entry->macaddr; | ||
317 | num_registrations -= 2; | ||
318 | } | ||
319 | } | ||
320 | } | ||
321 | |||
322 | out_update: | ||
323 | kfree(ehea_bcmc_regs.arr); | ||
324 | ehea_bcmc_regs.arr = arr; | ||
325 | ehea_bcmc_regs.num_entries = i; | ||
326 | out: | ||
327 | spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags); | ||
328 | } | ||
329 | |||
330 | static struct net_device_stats *ehea_get_stats(struct net_device *dev) | ||
331 | { | ||
332 | struct ehea_port *port = netdev_priv(dev); | ||
333 | struct net_device_stats *stats = &port->stats; | ||
334 | struct hcp_ehea_port_cb2 *cb2; | ||
335 | u64 hret, rx_packets, tx_packets, rx_bytes = 0, tx_bytes = 0; | ||
336 | int i; | ||
337 | |||
338 | memset(stats, 0, sizeof(*stats)); | ||
339 | |||
340 | cb2 = (void *)get_zeroed_page(GFP_KERNEL); | ||
341 | if (!cb2) { | ||
342 | netdev_err(dev, "no mem for cb2\n"); | ||
343 | goto out; | ||
344 | } | ||
345 | |||
346 | hret = ehea_h_query_ehea_port(port->adapter->handle, | ||
347 | port->logical_port_id, | ||
348 | H_PORT_CB2, H_PORT_CB2_ALL, cb2); | ||
349 | if (hret != H_SUCCESS) { | ||
350 | netdev_err(dev, "query_ehea_port failed\n"); | ||
351 | goto out_herr; | ||
352 | } | ||
353 | |||
354 | if (netif_msg_hw(port)) | ||
355 | ehea_dump(cb2, sizeof(*cb2), "net_device_stats"); | ||
356 | |||
357 | rx_packets = 0; | ||
358 | for (i = 0; i < port->num_def_qps; i++) { | ||
359 | rx_packets += port->port_res[i].rx_packets; | ||
360 | rx_bytes += port->port_res[i].rx_bytes; | ||
361 | } | ||
362 | |||
363 | tx_packets = 0; | ||
364 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { | ||
365 | tx_packets += port->port_res[i].tx_packets; | ||
366 | tx_bytes += port->port_res[i].tx_bytes; | ||
367 | } | ||
368 | |||
369 | stats->tx_packets = tx_packets; | ||
370 | stats->multicast = cb2->rxmcp; | ||
371 | stats->rx_errors = cb2->rxuerr; | ||
372 | stats->rx_bytes = rx_bytes; | ||
373 | stats->tx_bytes = tx_bytes; | ||
374 | stats->rx_packets = rx_packets; | ||
375 | |||
376 | out_herr: | ||
377 | free_page((unsigned long)cb2); | ||
378 | out: | ||
379 | return stats; | ||
380 | } | ||
381 | |||
382 | static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes) | ||
383 | { | ||
384 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; | ||
385 | struct net_device *dev = pr->port->netdev; | ||
386 | int max_index_mask = pr->rq1_skba.len - 1; | ||
387 | int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes; | ||
388 | int adder = 0; | ||
389 | int i; | ||
390 | |||
391 | pr->rq1_skba.os_skbs = 0; | ||
392 | |||
393 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { | ||
394 | if (nr_of_wqes > 0) | ||
395 | pr->rq1_skba.index = index; | ||
396 | pr->rq1_skba.os_skbs = fill_wqes; | ||
397 | return; | ||
398 | } | ||
399 | |||
400 | for (i = 0; i < fill_wqes; i++) { | ||
401 | if (!skb_arr_rq1[index]) { | ||
402 | skb_arr_rq1[index] = netdev_alloc_skb(dev, | ||
403 | EHEA_L_PKT_SIZE); | ||
404 | if (!skb_arr_rq1[index]) { | ||
405 | netdev_info(dev, "Unable to allocate enough skb in the array\n"); | ||
406 | pr->rq1_skba.os_skbs = fill_wqes - i; | ||
407 | break; | ||
408 | } | ||
409 | } | ||
410 | index--; | ||
411 | index &= max_index_mask; | ||
412 | adder++; | ||
413 | } | ||
414 | |||
415 | if (adder == 0) | ||
416 | return; | ||
417 | |||
418 | /* Ring doorbell */ | ||
419 | ehea_update_rq1a(pr->qp, adder); | ||
420 | } | ||
421 | |||
422 | static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a) | ||
423 | { | ||
424 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; | ||
425 | struct net_device *dev = pr->port->netdev; | ||
426 | int i; | ||
427 | |||
428 | if (nr_rq1a > pr->rq1_skba.len) { | ||
429 | netdev_err(dev, "NR_RQ1A bigger than skb array len\n"); | ||
430 | return; | ||
431 | } | ||
432 | |||
433 | for (i = 0; i < nr_rq1a; i++) { | ||
434 | skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE); | ||
435 | if (!skb_arr_rq1[i]) { | ||
436 | netdev_info(dev, "Not enough memory to allocate skb array\n"); | ||
437 | break; | ||
438 | } | ||
439 | } | ||
440 | /* Ring doorbell */ | ||
441 | ehea_update_rq1a(pr->qp, i - 1); | ||
442 | } | ||
443 | |||
444 | static int ehea_refill_rq_def(struct ehea_port_res *pr, | ||
445 | struct ehea_q_skb_arr *q_skba, int rq_nr, | ||
446 | int num_wqes, int wqe_type, int packet_size) | ||
447 | { | ||
448 | struct net_device *dev = pr->port->netdev; | ||
449 | struct ehea_qp *qp = pr->qp; | ||
450 | struct sk_buff **skb_arr = q_skba->arr; | ||
451 | struct ehea_rwqe *rwqe; | ||
452 | int i, index, max_index_mask, fill_wqes; | ||
453 | int adder = 0; | ||
454 | int ret = 0; | ||
455 | |||
456 | fill_wqes = q_skba->os_skbs + num_wqes; | ||
457 | q_skba->os_skbs = 0; | ||
458 | |||
459 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { | ||
460 | q_skba->os_skbs = fill_wqes; | ||
461 | return ret; | ||
462 | } | ||
463 | |||
464 | index = q_skba->index; | ||
465 | max_index_mask = q_skba->len - 1; | ||
466 | for (i = 0; i < fill_wqes; i++) { | ||
467 | u64 tmp_addr; | ||
468 | struct sk_buff *skb; | ||
469 | |||
470 | skb = netdev_alloc_skb_ip_align(dev, packet_size); | ||
471 | if (!skb) { | ||
472 | q_skba->os_skbs = fill_wqes - i; | ||
473 | if (q_skba->os_skbs == q_skba->len - 2) { | ||
474 | netdev_info(pr->port->netdev, | ||
475 | "rq%i ran dry - no mem for skb\n", | ||
476 | rq_nr); | ||
477 | ret = -ENOMEM; | ||
478 | } | ||
479 | break; | ||
480 | } | ||
481 | |||
482 | skb_arr[index] = skb; | ||
483 | tmp_addr = ehea_map_vaddr(skb->data); | ||
484 | if (tmp_addr == -1) { | ||
485 | dev_kfree_skb(skb); | ||
486 | q_skba->os_skbs = fill_wqes - i; | ||
487 | ret = 0; | ||
488 | break; | ||
489 | } | ||
490 | |||
491 | rwqe = ehea_get_next_rwqe(qp, rq_nr); | ||
492 | rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type) | ||
493 | | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index); | ||
494 | rwqe->sg_list[0].l_key = pr->recv_mr.lkey; | ||
495 | rwqe->sg_list[0].vaddr = tmp_addr; | ||
496 | rwqe->sg_list[0].len = packet_size; | ||
497 | rwqe->data_segments = 1; | ||
498 | |||
499 | index++; | ||
500 | index &= max_index_mask; | ||
501 | adder++; | ||
502 | } | ||
503 | |||
504 | q_skba->index = index; | ||
505 | if (adder == 0) | ||
506 | goto out; | ||
507 | |||
508 | /* Ring doorbell */ | ||
509 | iosync(); | ||
510 | if (rq_nr == 2) | ||
511 | ehea_update_rq2a(pr->qp, adder); | ||
512 | else | ||
513 | ehea_update_rq3a(pr->qp, adder); | ||
514 | out: | ||
515 | return ret; | ||
516 | } | ||
517 | |||
518 | |||
519 | static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes) | ||
520 | { | ||
521 | return ehea_refill_rq_def(pr, &pr->rq2_skba, 2, | ||
522 | nr_of_wqes, EHEA_RWQE2_TYPE, | ||
523 | EHEA_RQ2_PKT_SIZE); | ||
524 | } | ||
525 | |||
526 | |||
527 | static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes) | ||
528 | { | ||
529 | return ehea_refill_rq_def(pr, &pr->rq3_skba, 3, | ||
530 | nr_of_wqes, EHEA_RWQE3_TYPE, | ||
531 | EHEA_MAX_PACKET_SIZE); | ||
532 | } | ||
533 | |||
534 | static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num) | ||
535 | { | ||
536 | *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5; | ||
537 | if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0) | ||
538 | return 0; | ||
539 | if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) && | ||
540 | (cqe->header_length == 0)) | ||
541 | return 0; | ||
542 | return -EINVAL; | ||
543 | } | ||
544 | |||
545 | static inline void ehea_fill_skb(struct net_device *dev, | ||
546 | struct sk_buff *skb, struct ehea_cqe *cqe) | ||
547 | { | ||
548 | int length = cqe->num_bytes_transfered - 4; /*remove CRC */ | ||
549 | |||
550 | skb_put(skb, length); | ||
551 | skb->protocol = eth_type_trans(skb, dev); | ||
552 | |||
553 | /* The packet was not an IPV4 packet so a complemented checksum was | ||
554 | calculated. The value is found in the Internet Checksum field. */ | ||
555 | if (cqe->status & EHEA_CQE_BLIND_CKSUM) { | ||
556 | skb->ip_summed = CHECKSUM_COMPLETE; | ||
557 | skb->csum = csum_unfold(~cqe->inet_checksum_value); | ||
558 | } else | ||
559 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
560 | } | ||
561 | |||
562 | static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array, | ||
563 | int arr_len, | ||
564 | struct ehea_cqe *cqe) | ||
565 | { | ||
566 | int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id); | ||
567 | struct sk_buff *skb; | ||
568 | void *pref; | ||
569 | int x; | ||
570 | |||
571 | x = skb_index + 1; | ||
572 | x &= (arr_len - 1); | ||
573 | |||
574 | pref = skb_array[x]; | ||
575 | if (pref) { | ||
576 | prefetchw(pref); | ||
577 | prefetchw(pref + EHEA_CACHE_LINE); | ||
578 | |||
579 | pref = (skb_array[x]->data); | ||
580 | prefetch(pref); | ||
581 | prefetch(pref + EHEA_CACHE_LINE); | ||
582 | prefetch(pref + EHEA_CACHE_LINE * 2); | ||
583 | prefetch(pref + EHEA_CACHE_LINE * 3); | ||
584 | } | ||
585 | |||
586 | skb = skb_array[skb_index]; | ||
587 | skb_array[skb_index] = NULL; | ||
588 | return skb; | ||
589 | } | ||
590 | |||
591 | static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array, | ||
592 | int arr_len, int wqe_index) | ||
593 | { | ||
594 | struct sk_buff *skb; | ||
595 | void *pref; | ||
596 | int x; | ||
597 | |||
598 | x = wqe_index + 1; | ||
599 | x &= (arr_len - 1); | ||
600 | |||
601 | pref = skb_array[x]; | ||
602 | if (pref) { | ||
603 | prefetchw(pref); | ||
604 | prefetchw(pref + EHEA_CACHE_LINE); | ||
605 | |||
606 | pref = (skb_array[x]->data); | ||
607 | prefetchw(pref); | ||
608 | prefetchw(pref + EHEA_CACHE_LINE); | ||
609 | } | ||
610 | |||
611 | skb = skb_array[wqe_index]; | ||
612 | skb_array[wqe_index] = NULL; | ||
613 | return skb; | ||
614 | } | ||
615 | |||
616 | static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq, | ||
617 | struct ehea_cqe *cqe, int *processed_rq2, | ||
618 | int *processed_rq3) | ||
619 | { | ||
620 | struct sk_buff *skb; | ||
621 | |||
622 | if (cqe->status & EHEA_CQE_STAT_ERR_TCP) | ||
623 | pr->p_stats.err_tcp_cksum++; | ||
624 | if (cqe->status & EHEA_CQE_STAT_ERR_IP) | ||
625 | pr->p_stats.err_ip_cksum++; | ||
626 | if (cqe->status & EHEA_CQE_STAT_ERR_CRC) | ||
627 | pr->p_stats.err_frame_crc++; | ||
628 | |||
629 | if (rq == 2) { | ||
630 | *processed_rq2 += 1; | ||
631 | skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe); | ||
632 | dev_kfree_skb(skb); | ||
633 | } else if (rq == 3) { | ||
634 | *processed_rq3 += 1; | ||
635 | skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe); | ||
636 | dev_kfree_skb(skb); | ||
637 | } | ||
638 | |||
639 | if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) { | ||
640 | if (netif_msg_rx_err(pr->port)) { | ||
641 | pr_err("Critical receive error for QP %d. Resetting port.\n", | ||
642 | pr->qp->init_attr.qp_nr); | ||
643 | ehea_dump(cqe, sizeof(*cqe), "CQE"); | ||
644 | } | ||
645 | ehea_schedule_port_reset(pr->port); | ||
646 | return 1; | ||
647 | } | ||
648 | |||
649 | return 0; | ||
650 | } | ||
651 | |||
652 | static int get_skb_hdr(struct sk_buff *skb, void **iphdr, | ||
653 | void **tcph, u64 *hdr_flags, void *priv) | ||
654 | { | ||
655 | struct ehea_cqe *cqe = priv; | ||
656 | unsigned int ip_len; | ||
657 | struct iphdr *iph; | ||
658 | |||
659 | /* non tcp/udp packets */ | ||
660 | if (!cqe->header_length) | ||
661 | return -1; | ||
662 | |||
663 | /* non tcp packet */ | ||
664 | skb_reset_network_header(skb); | ||
665 | iph = ip_hdr(skb); | ||
666 | if (iph->protocol != IPPROTO_TCP) | ||
667 | return -1; | ||
668 | |||
669 | ip_len = ip_hdrlen(skb); | ||
670 | skb_set_transport_header(skb, ip_len); | ||
671 | *tcph = tcp_hdr(skb); | ||
672 | |||
673 | /* check if ip header and tcp header are complete */ | ||
674 | if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb)) | ||
675 | return -1; | ||
676 | |||
677 | *hdr_flags = LRO_IPV4 | LRO_TCP; | ||
678 | *iphdr = iph; | ||
679 | |||
680 | return 0; | ||
681 | } | ||
682 | |||
683 | static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe, | ||
684 | struct sk_buff *skb) | ||
685 | { | ||
686 | if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) | ||
687 | __vlan_hwaccel_put_tag(skb, cqe->vlan_tag); | ||
688 | |||
689 | if (skb->dev->features & NETIF_F_LRO) | ||
690 | lro_receive_skb(&pr->lro_mgr, skb, cqe); | ||
691 | else | ||
692 | netif_receive_skb(skb); | ||
693 | } | ||
694 | |||
695 | static int ehea_proc_rwqes(struct net_device *dev, | ||
696 | struct ehea_port_res *pr, | ||
697 | int budget) | ||
698 | { | ||
699 | struct ehea_port *port = pr->port; | ||
700 | struct ehea_qp *qp = pr->qp; | ||
701 | struct ehea_cqe *cqe; | ||
702 | struct sk_buff *skb; | ||
703 | struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr; | ||
704 | struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr; | ||
705 | struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr; | ||
706 | int skb_arr_rq1_len = pr->rq1_skba.len; | ||
707 | int skb_arr_rq2_len = pr->rq2_skba.len; | ||
708 | int skb_arr_rq3_len = pr->rq3_skba.len; | ||
709 | int processed, processed_rq1, processed_rq2, processed_rq3; | ||
710 | u64 processed_bytes = 0; | ||
711 | int wqe_index, last_wqe_index, rq, port_reset; | ||
712 | |||
713 | processed = processed_rq1 = processed_rq2 = processed_rq3 = 0; | ||
714 | last_wqe_index = 0; | ||
715 | |||
716 | cqe = ehea_poll_rq1(qp, &wqe_index); | ||
717 | while ((processed < budget) && cqe) { | ||
718 | ehea_inc_rq1(qp); | ||
719 | processed_rq1++; | ||
720 | processed++; | ||
721 | if (netif_msg_rx_status(port)) | ||
722 | ehea_dump(cqe, sizeof(*cqe), "CQE"); | ||
723 | |||
724 | last_wqe_index = wqe_index; | ||
725 | rmb(); | ||
726 | if (!ehea_check_cqe(cqe, &rq)) { | ||
727 | if (rq == 1) { | ||
728 | /* LL RQ1 */ | ||
729 | skb = get_skb_by_index_ll(skb_arr_rq1, | ||
730 | skb_arr_rq1_len, | ||
731 | wqe_index); | ||
732 | if (unlikely(!skb)) { | ||
733 | netif_info(port, rx_err, dev, | ||
734 | "LL rq1: skb=NULL\n"); | ||
735 | |||
736 | skb = netdev_alloc_skb(dev, | ||
737 | EHEA_L_PKT_SIZE); | ||
738 | if (!skb) { | ||
739 | netdev_err(dev, "Not enough memory to allocate skb\n"); | ||
740 | break; | ||
741 | } | ||
742 | } | ||
743 | skb_copy_to_linear_data(skb, ((char *)cqe) + 64, | ||
744 | cqe->num_bytes_transfered - 4); | ||
745 | ehea_fill_skb(dev, skb, cqe); | ||
746 | } else if (rq == 2) { | ||
747 | /* RQ2 */ | ||
748 | skb = get_skb_by_index(skb_arr_rq2, | ||
749 | skb_arr_rq2_len, cqe); | ||
750 | if (unlikely(!skb)) { | ||
751 | netif_err(port, rx_err, dev, | ||
752 | "rq2: skb=NULL\n"); | ||
753 | break; | ||
754 | } | ||
755 | ehea_fill_skb(dev, skb, cqe); | ||
756 | processed_rq2++; | ||
757 | } else { | ||
758 | /* RQ3 */ | ||
759 | skb = get_skb_by_index(skb_arr_rq3, | ||
760 | skb_arr_rq3_len, cqe); | ||
761 | if (unlikely(!skb)) { | ||
762 | netif_err(port, rx_err, dev, | ||
763 | "rq3: skb=NULL\n"); | ||
764 | break; | ||
765 | } | ||
766 | ehea_fill_skb(dev, skb, cqe); | ||
767 | processed_rq3++; | ||
768 | } | ||
769 | |||
770 | processed_bytes += skb->len; | ||
771 | ehea_proc_skb(pr, cqe, skb); | ||
772 | } else { | ||
773 | pr->p_stats.poll_receive_errors++; | ||
774 | port_reset = ehea_treat_poll_error(pr, rq, cqe, | ||
775 | &processed_rq2, | ||
776 | &processed_rq3); | ||
777 | if (port_reset) | ||
778 | break; | ||
779 | } | ||
780 | cqe = ehea_poll_rq1(qp, &wqe_index); | ||
781 | } | ||
782 | if (dev->features & NETIF_F_LRO) | ||
783 | lro_flush_all(&pr->lro_mgr); | ||
784 | |||
785 | pr->rx_packets += processed; | ||
786 | pr->rx_bytes += processed_bytes; | ||
787 | |||
788 | ehea_refill_rq1(pr, last_wqe_index, processed_rq1); | ||
789 | ehea_refill_rq2(pr, processed_rq2); | ||
790 | ehea_refill_rq3(pr, processed_rq3); | ||
791 | |||
792 | return processed; | ||
793 | } | ||
794 | |||
795 | #define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull | ||
796 | |||
797 | static void reset_sq_restart_flag(struct ehea_port *port) | ||
798 | { | ||
799 | int i; | ||
800 | |||
801 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { | ||
802 | struct ehea_port_res *pr = &port->port_res[i]; | ||
803 | pr->sq_restart_flag = 0; | ||
804 | } | ||
805 | wake_up(&port->restart_wq); | ||
806 | } | ||
807 | |||
808 | static void check_sqs(struct ehea_port *port) | ||
809 | { | ||
810 | struct ehea_swqe *swqe; | ||
811 | int swqe_index; | ||
812 | int i, k; | ||
813 | |||
814 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { | ||
815 | struct ehea_port_res *pr = &port->port_res[i]; | ||
816 | int ret; | ||
817 | k = 0; | ||
818 | swqe = ehea_get_swqe(pr->qp, &swqe_index); | ||
819 | memset(swqe, 0, SWQE_HEADER_SIZE); | ||
820 | atomic_dec(&pr->swqe_avail); | ||
821 | |||
822 | swqe->tx_control |= EHEA_SWQE_PURGE; | ||
823 | swqe->wr_id = SWQE_RESTART_CHECK; | ||
824 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; | ||
825 | swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT; | ||
826 | swqe->immediate_data_length = 80; | ||
827 | |||
828 | ehea_post_swqe(pr->qp, swqe); | ||
829 | |||
830 | ret = wait_event_timeout(port->restart_wq, | ||
831 | pr->sq_restart_flag == 0, | ||
832 | msecs_to_jiffies(100)); | ||
833 | |||
834 | if (!ret) { | ||
835 | pr_err("HW/SW queues out of sync\n"); | ||
836 | ehea_schedule_port_reset(pr->port); | ||
837 | return; | ||
838 | } | ||
839 | } | ||
840 | } | ||
841 | |||
842 | |||
843 | static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota) | ||
844 | { | ||
845 | struct sk_buff *skb; | ||
846 | struct ehea_cq *send_cq = pr->send_cq; | ||
847 | struct ehea_cqe *cqe; | ||
848 | int quota = my_quota; | ||
849 | int cqe_counter = 0; | ||
850 | int swqe_av = 0; | ||
851 | int index; | ||
852 | unsigned long flags; | ||
853 | |||
854 | cqe = ehea_poll_cq(send_cq); | ||
855 | while (cqe && (quota > 0)) { | ||
856 | ehea_inc_cq(send_cq); | ||
857 | |||
858 | cqe_counter++; | ||
859 | rmb(); | ||
860 | |||
861 | if (cqe->wr_id == SWQE_RESTART_CHECK) { | ||
862 | pr->sq_restart_flag = 1; | ||
863 | swqe_av++; | ||
864 | break; | ||
865 | } | ||
866 | |||
867 | if (cqe->status & EHEA_CQE_STAT_ERR_MASK) { | ||
868 | pr_err("Bad send completion status=0x%04X\n", | ||
869 | cqe->status); | ||
870 | |||
871 | if (netif_msg_tx_err(pr->port)) | ||
872 | ehea_dump(cqe, sizeof(*cqe), "Send CQE"); | ||
873 | |||
874 | if (cqe->status & EHEA_CQE_STAT_RESET_MASK) { | ||
875 | pr_err("Resetting port\n"); | ||
876 | ehea_schedule_port_reset(pr->port); | ||
877 | break; | ||
878 | } | ||
879 | } | ||
880 | |||
881 | if (netif_msg_tx_done(pr->port)) | ||
882 | ehea_dump(cqe, sizeof(*cqe), "CQE"); | ||
883 | |||
884 | if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id) | ||
885 | == EHEA_SWQE2_TYPE)) { | ||
886 | |||
887 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id); | ||
888 | skb = pr->sq_skba.arr[index]; | ||
889 | dev_kfree_skb(skb); | ||
890 | pr->sq_skba.arr[index] = NULL; | ||
891 | } | ||
892 | |||
893 | swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id); | ||
894 | quota--; | ||
895 | |||
896 | cqe = ehea_poll_cq(send_cq); | ||
897 | } | ||
898 | |||
899 | ehea_update_feca(send_cq, cqe_counter); | ||
900 | atomic_add(swqe_av, &pr->swqe_avail); | ||
901 | |||
902 | spin_lock_irqsave(&pr->netif_queue, flags); | ||
903 | |||
904 | if (pr->queue_stopped && (atomic_read(&pr->swqe_avail) | ||
905 | >= pr->swqe_refill_th)) { | ||
906 | netif_wake_queue(pr->port->netdev); | ||
907 | pr->queue_stopped = 0; | ||
908 | } | ||
909 | spin_unlock_irqrestore(&pr->netif_queue, flags); | ||
910 | wake_up(&pr->port->swqe_avail_wq); | ||
911 | |||
912 | return cqe; | ||
913 | } | ||
914 | |||
915 | #define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16 | ||
916 | #define EHEA_POLL_MAX_CQES 65535 | ||
917 | |||
918 | static int ehea_poll(struct napi_struct *napi, int budget) | ||
919 | { | ||
920 | struct ehea_port_res *pr = container_of(napi, struct ehea_port_res, | ||
921 | napi); | ||
922 | struct net_device *dev = pr->port->netdev; | ||
923 | struct ehea_cqe *cqe; | ||
924 | struct ehea_cqe *cqe_skb = NULL; | ||
925 | int force_irq, wqe_index; | ||
926 | int rx = 0; | ||
927 | |||
928 | force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ); | ||
929 | cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES); | ||
930 | |||
931 | if (!force_irq) | ||
932 | rx += ehea_proc_rwqes(dev, pr, budget - rx); | ||
933 | |||
934 | while ((rx != budget) || force_irq) { | ||
935 | pr->poll_counter = 0; | ||
936 | force_irq = 0; | ||
937 | napi_complete(napi); | ||
938 | ehea_reset_cq_ep(pr->recv_cq); | ||
939 | ehea_reset_cq_ep(pr->send_cq); | ||
940 | ehea_reset_cq_n1(pr->recv_cq); | ||
941 | ehea_reset_cq_n1(pr->send_cq); | ||
942 | rmb(); | ||
943 | cqe = ehea_poll_rq1(pr->qp, &wqe_index); | ||
944 | cqe_skb = ehea_poll_cq(pr->send_cq); | ||
945 | |||
946 | if (!cqe && !cqe_skb) | ||
947 | return rx; | ||
948 | |||
949 | if (!napi_reschedule(napi)) | ||
950 | return rx; | ||
951 | |||
952 | cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES); | ||
953 | rx += ehea_proc_rwqes(dev, pr, budget - rx); | ||
954 | } | ||
955 | |||
956 | pr->poll_counter++; | ||
957 | return rx; | ||
958 | } | ||
959 | |||
960 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
961 | static void ehea_netpoll(struct net_device *dev) | ||
962 | { | ||
963 | struct ehea_port *port = netdev_priv(dev); | ||
964 | int i; | ||
965 | |||
966 | for (i = 0; i < port->num_def_qps; i++) | ||
967 | napi_schedule(&port->port_res[i].napi); | ||
968 | } | ||
969 | #endif | ||
970 | |||
971 | static irqreturn_t ehea_recv_irq_handler(int irq, void *param) | ||
972 | { | ||
973 | struct ehea_port_res *pr = param; | ||
974 | |||
975 | napi_schedule(&pr->napi); | ||
976 | |||
977 | return IRQ_HANDLED; | ||
978 | } | ||
979 | |||
980 | static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param) | ||
981 | { | ||
982 | struct ehea_port *port = param; | ||
983 | struct ehea_eqe *eqe; | ||
984 | struct ehea_qp *qp; | ||
985 | u32 qp_token; | ||
986 | u64 resource_type, aer, aerr; | ||
987 | int reset_port = 0; | ||
988 | |||
989 | eqe = ehea_poll_eq(port->qp_eq); | ||
990 | |||
991 | while (eqe) { | ||
992 | qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry); | ||
993 | pr_err("QP aff_err: entry=0x%llx, token=0x%x\n", | ||
994 | eqe->entry, qp_token); | ||
995 | |||
996 | qp = port->port_res[qp_token].qp; | ||
997 | |||
998 | resource_type = ehea_error_data(port->adapter, qp->fw_handle, | ||
999 | &aer, &aerr); | ||
1000 | |||
1001 | if (resource_type == EHEA_AER_RESTYPE_QP) { | ||
1002 | if ((aer & EHEA_AER_RESET_MASK) || | ||
1003 | (aerr & EHEA_AERR_RESET_MASK)) | ||
1004 | reset_port = 1; | ||
1005 | } else | ||
1006 | reset_port = 1; /* Reset in case of CQ or EQ error */ | ||
1007 | |||
1008 | eqe = ehea_poll_eq(port->qp_eq); | ||
1009 | } | ||
1010 | |||
1011 | if (reset_port) { | ||
1012 | pr_err("Resetting port\n"); | ||
1013 | ehea_schedule_port_reset(port); | ||
1014 | } | ||
1015 | |||
1016 | return IRQ_HANDLED; | ||
1017 | } | ||
1018 | |||
1019 | static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter, | ||
1020 | int logical_port) | ||
1021 | { | ||
1022 | int i; | ||
1023 | |||
1024 | for (i = 0; i < EHEA_MAX_PORTS; i++) | ||
1025 | if (adapter->port[i]) | ||
1026 | if (adapter->port[i]->logical_port_id == logical_port) | ||
1027 | return adapter->port[i]; | ||
1028 | return NULL; | ||
1029 | } | ||
1030 | |||
1031 | int ehea_sense_port_attr(struct ehea_port *port) | ||
1032 | { | ||
1033 | int ret; | ||
1034 | u64 hret; | ||
1035 | struct hcp_ehea_port_cb0 *cb0; | ||
1036 | |||
1037 | /* may be called via ehea_neq_tasklet() */ | ||
1038 | cb0 = (void *)get_zeroed_page(GFP_ATOMIC); | ||
1039 | if (!cb0) { | ||
1040 | pr_err("no mem for cb0\n"); | ||
1041 | ret = -ENOMEM; | ||
1042 | goto out; | ||
1043 | } | ||
1044 | |||
1045 | hret = ehea_h_query_ehea_port(port->adapter->handle, | ||
1046 | port->logical_port_id, H_PORT_CB0, | ||
1047 | EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF), | ||
1048 | cb0); | ||
1049 | if (hret != H_SUCCESS) { | ||
1050 | ret = -EIO; | ||
1051 | goto out_free; | ||
1052 | } | ||
1053 | |||
1054 | /* MAC address */ | ||
1055 | port->mac_addr = cb0->port_mac_addr << 16; | ||
1056 | |||
1057 | if (!is_valid_ether_addr((u8 *)&port->mac_addr)) { | ||
1058 | ret = -EADDRNOTAVAIL; | ||
1059 | goto out_free; | ||
1060 | } | ||
1061 | |||
1062 | /* Port speed */ | ||
1063 | switch (cb0->port_speed) { | ||
1064 | case H_SPEED_10M_H: | ||
1065 | port->port_speed = EHEA_SPEED_10M; | ||
1066 | port->full_duplex = 0; | ||
1067 | break; | ||
1068 | case H_SPEED_10M_F: | ||
1069 | port->port_speed = EHEA_SPEED_10M; | ||
1070 | port->full_duplex = 1; | ||
1071 | break; | ||
1072 | case H_SPEED_100M_H: | ||
1073 | port->port_speed = EHEA_SPEED_100M; | ||
1074 | port->full_duplex = 0; | ||
1075 | break; | ||
1076 | case H_SPEED_100M_F: | ||
1077 | port->port_speed = EHEA_SPEED_100M; | ||
1078 | port->full_duplex = 1; | ||
1079 | break; | ||
1080 | case H_SPEED_1G_F: | ||
1081 | port->port_speed = EHEA_SPEED_1G; | ||
1082 | port->full_duplex = 1; | ||
1083 | break; | ||
1084 | case H_SPEED_10G_F: | ||
1085 | port->port_speed = EHEA_SPEED_10G; | ||
1086 | port->full_duplex = 1; | ||
1087 | break; | ||
1088 | default: | ||
1089 | port->port_speed = 0; | ||
1090 | port->full_duplex = 0; | ||
1091 | break; | ||
1092 | } | ||
1093 | |||
1094 | port->autoneg = 1; | ||
1095 | port->num_mcs = cb0->num_default_qps; | ||
1096 | |||
1097 | /* Number of default QPs */ | ||
1098 | if (use_mcs) | ||
1099 | port->num_def_qps = cb0->num_default_qps; | ||
1100 | else | ||
1101 | port->num_def_qps = 1; | ||
1102 | |||
1103 | if (!port->num_def_qps) { | ||
1104 | ret = -EINVAL; | ||
1105 | goto out_free; | ||
1106 | } | ||
1107 | |||
1108 | port->num_tx_qps = num_tx_qps; | ||
1109 | |||
1110 | if (port->num_def_qps >= port->num_tx_qps) | ||
1111 | port->num_add_tx_qps = 0; | ||
1112 | else | ||
1113 | port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps; | ||
1114 | |||
1115 | ret = 0; | ||
1116 | out_free: | ||
1117 | if (ret || netif_msg_probe(port)) | ||
1118 | ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr"); | ||
1119 | free_page((unsigned long)cb0); | ||
1120 | out: | ||
1121 | return ret; | ||
1122 | } | ||
1123 | |||
1124 | int ehea_set_portspeed(struct ehea_port *port, u32 port_speed) | ||
1125 | { | ||
1126 | struct hcp_ehea_port_cb4 *cb4; | ||
1127 | u64 hret; | ||
1128 | int ret = 0; | ||
1129 | |||
1130 | cb4 = (void *)get_zeroed_page(GFP_KERNEL); | ||
1131 | if (!cb4) { | ||
1132 | pr_err("no mem for cb4\n"); | ||
1133 | ret = -ENOMEM; | ||
1134 | goto out; | ||
1135 | } | ||
1136 | |||
1137 | cb4->port_speed = port_speed; | ||
1138 | |||
1139 | netif_carrier_off(port->netdev); | ||
1140 | |||
1141 | hret = ehea_h_modify_ehea_port(port->adapter->handle, | ||
1142 | port->logical_port_id, | ||
1143 | H_PORT_CB4, H_PORT_CB4_SPEED, cb4); | ||
1144 | if (hret == H_SUCCESS) { | ||
1145 | port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0; | ||
1146 | |||
1147 | hret = ehea_h_query_ehea_port(port->adapter->handle, | ||
1148 | port->logical_port_id, | ||
1149 | H_PORT_CB4, H_PORT_CB4_SPEED, | ||
1150 | cb4); | ||
1151 | if (hret == H_SUCCESS) { | ||
1152 | switch (cb4->port_speed) { | ||
1153 | case H_SPEED_10M_H: | ||
1154 | port->port_speed = EHEA_SPEED_10M; | ||
1155 | port->full_duplex = 0; | ||
1156 | break; | ||
1157 | case H_SPEED_10M_F: | ||
1158 | port->port_speed = EHEA_SPEED_10M; | ||
1159 | port->full_duplex = 1; | ||
1160 | break; | ||
1161 | case H_SPEED_100M_H: | ||
1162 | port->port_speed = EHEA_SPEED_100M; | ||
1163 | port->full_duplex = 0; | ||
1164 | break; | ||
1165 | case H_SPEED_100M_F: | ||
1166 | port->port_speed = EHEA_SPEED_100M; | ||
1167 | port->full_duplex = 1; | ||
1168 | break; | ||
1169 | case H_SPEED_1G_F: | ||
1170 | port->port_speed = EHEA_SPEED_1G; | ||
1171 | port->full_duplex = 1; | ||
1172 | break; | ||
1173 | case H_SPEED_10G_F: | ||
1174 | port->port_speed = EHEA_SPEED_10G; | ||
1175 | port->full_duplex = 1; | ||
1176 | break; | ||
1177 | default: | ||
1178 | port->port_speed = 0; | ||
1179 | port->full_duplex = 0; | ||
1180 | break; | ||
1181 | } | ||
1182 | } else { | ||
1183 | pr_err("Failed sensing port speed\n"); | ||
1184 | ret = -EIO; | ||
1185 | } | ||
1186 | } else { | ||
1187 | if (hret == H_AUTHORITY) { | ||
1188 | pr_info("Hypervisor denied setting port speed\n"); | ||
1189 | ret = -EPERM; | ||
1190 | } else { | ||
1191 | ret = -EIO; | ||
1192 | pr_err("Failed setting port speed\n"); | ||
1193 | } | ||
1194 | } | ||
1195 | if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP)) | ||
1196 | netif_carrier_on(port->netdev); | ||
1197 | |||
1198 | free_page((unsigned long)cb4); | ||
1199 | out: | ||
1200 | return ret; | ||
1201 | } | ||
1202 | |||
1203 | static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe) | ||
1204 | { | ||
1205 | int ret; | ||
1206 | u8 ec; | ||
1207 | u8 portnum; | ||
1208 | struct ehea_port *port; | ||
1209 | struct net_device *dev; | ||
1210 | |||
1211 | ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe); | ||
1212 | portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe); | ||
1213 | port = ehea_get_port(adapter, portnum); | ||
1214 | dev = port->netdev; | ||
1215 | |||
1216 | switch (ec) { | ||
1217 | case EHEA_EC_PORTSTATE_CHG: /* port state change */ | ||
1218 | |||
1219 | if (!port) { | ||
1220 | netdev_err(dev, "unknown portnum %x\n", portnum); | ||
1221 | break; | ||
1222 | } | ||
1223 | |||
1224 | if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) { | ||
1225 | if (!netif_carrier_ok(dev)) { | ||
1226 | ret = ehea_sense_port_attr(port); | ||
1227 | if (ret) { | ||
1228 | netdev_err(dev, "failed resensing port attributes\n"); | ||
1229 | break; | ||
1230 | } | ||
1231 | |||
1232 | netif_info(port, link, dev, | ||
1233 | "Logical port up: %dMbps %s Duplex\n", | ||
1234 | port->port_speed, | ||
1235 | port->full_duplex == 1 ? | ||
1236 | "Full" : "Half"); | ||
1237 | |||
1238 | netif_carrier_on(dev); | ||
1239 | netif_wake_queue(dev); | ||
1240 | } | ||
1241 | } else | ||
1242 | if (netif_carrier_ok(dev)) { | ||
1243 | netif_info(port, link, dev, | ||
1244 | "Logical port down\n"); | ||
1245 | netif_carrier_off(dev); | ||
1246 | netif_stop_queue(dev); | ||
1247 | } | ||
1248 | |||
1249 | if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) { | ||
1250 | port->phy_link = EHEA_PHY_LINK_UP; | ||
1251 | netif_info(port, link, dev, | ||
1252 | "Physical port up\n"); | ||
1253 | if (prop_carrier_state) | ||
1254 | netif_carrier_on(dev); | ||
1255 | } else { | ||
1256 | port->phy_link = EHEA_PHY_LINK_DOWN; | ||
1257 | netif_info(port, link, dev, | ||
1258 | "Physical port down\n"); | ||
1259 | if (prop_carrier_state) | ||
1260 | netif_carrier_off(dev); | ||
1261 | } | ||
1262 | |||
1263 | if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe)) | ||
1264 | netdev_info(dev, | ||
1265 | "External switch port is primary port\n"); | ||
1266 | else | ||
1267 | netdev_info(dev, | ||
1268 | "External switch port is backup port\n"); | ||
1269 | |||
1270 | break; | ||
1271 | case EHEA_EC_ADAPTER_MALFUNC: | ||
1272 | netdev_err(dev, "Adapter malfunction\n"); | ||
1273 | break; | ||
1274 | case EHEA_EC_PORT_MALFUNC: | ||
1275 | netdev_info(dev, "Port malfunction\n"); | ||
1276 | netif_carrier_off(dev); | ||
1277 | netif_stop_queue(dev); | ||
1278 | break; | ||
1279 | default: | ||
1280 | netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe); | ||
1281 | break; | ||
1282 | } | ||
1283 | } | ||
1284 | |||
1285 | static void ehea_neq_tasklet(unsigned long data) | ||
1286 | { | ||
1287 | struct ehea_adapter *adapter = (struct ehea_adapter *)data; | ||
1288 | struct ehea_eqe *eqe; | ||
1289 | u64 event_mask; | ||
1290 | |||
1291 | eqe = ehea_poll_eq(adapter->neq); | ||
1292 | pr_debug("eqe=%p\n", eqe); | ||
1293 | |||
1294 | while (eqe) { | ||
1295 | pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry); | ||
1296 | ehea_parse_eqe(adapter, eqe->entry); | ||
1297 | eqe = ehea_poll_eq(adapter->neq); | ||
1298 | pr_debug("next eqe=%p\n", eqe); | ||
1299 | } | ||
1300 | |||
1301 | event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1) | ||
1302 | | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1) | ||
1303 | | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1); | ||
1304 | |||
1305 | ehea_h_reset_events(adapter->handle, | ||
1306 | adapter->neq->fw_handle, event_mask); | ||
1307 | } | ||
1308 | |||
1309 | static irqreturn_t ehea_interrupt_neq(int irq, void *param) | ||
1310 | { | ||
1311 | struct ehea_adapter *adapter = param; | ||
1312 | tasklet_hi_schedule(&adapter->neq_tasklet); | ||
1313 | return IRQ_HANDLED; | ||
1314 | } | ||
1315 | |||
1316 | |||
1317 | static int ehea_fill_port_res(struct ehea_port_res *pr) | ||
1318 | { | ||
1319 | int ret; | ||
1320 | struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr; | ||
1321 | |||
1322 | ehea_init_fill_rq1(pr, pr->rq1_skba.len); | ||
1323 | |||
1324 | ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1); | ||
1325 | |||
1326 | ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1); | ||
1327 | |||
1328 | return ret; | ||
1329 | } | ||
1330 | |||
1331 | static int ehea_reg_interrupts(struct net_device *dev) | ||
1332 | { | ||
1333 | struct ehea_port *port = netdev_priv(dev); | ||
1334 | struct ehea_port_res *pr; | ||
1335 | int i, ret; | ||
1336 | |||
1337 | |||
1338 | snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff", | ||
1339 | dev->name); | ||
1340 | |||
1341 | ret = ibmebus_request_irq(port->qp_eq->attr.ist1, | ||
1342 | ehea_qp_aff_irq_handler, | ||
1343 | IRQF_DISABLED, port->int_aff_name, port); | ||
1344 | if (ret) { | ||
1345 | netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n", | ||
1346 | port->qp_eq->attr.ist1); | ||
1347 | goto out_free_qpeq; | ||
1348 | } | ||
1349 | |||
1350 | netif_info(port, ifup, dev, | ||
1351 | "irq_handle 0x%X for function qp_aff_irq_handler registered\n", | ||
1352 | port->qp_eq->attr.ist1); | ||
1353 | |||
1354 | |||
1355 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { | ||
1356 | pr = &port->port_res[i]; | ||
1357 | snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1, | ||
1358 | "%s-queue%d", dev->name, i); | ||
1359 | ret = ibmebus_request_irq(pr->eq->attr.ist1, | ||
1360 | ehea_recv_irq_handler, | ||
1361 | IRQF_DISABLED, pr->int_send_name, | ||
1362 | pr); | ||
1363 | if (ret) { | ||
1364 | netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n", | ||
1365 | i, pr->eq->attr.ist1); | ||
1366 | goto out_free_req; | ||
1367 | } | ||
1368 | netif_info(port, ifup, dev, | ||
1369 | "irq_handle 0x%X for function ehea_queue_int %d registered\n", | ||
1370 | pr->eq->attr.ist1, i); | ||
1371 | } | ||
1372 | out: | ||
1373 | return ret; | ||
1374 | |||
1375 | |||
1376 | out_free_req: | ||
1377 | while (--i >= 0) { | ||
1378 | u32 ist = port->port_res[i].eq->attr.ist1; | ||
1379 | ibmebus_free_irq(ist, &port->port_res[i]); | ||
1380 | } | ||
1381 | |||
1382 | out_free_qpeq: | ||
1383 | ibmebus_free_irq(port->qp_eq->attr.ist1, port); | ||
1384 | i = port->num_def_qps; | ||
1385 | |||
1386 | goto out; | ||
1387 | |||
1388 | } | ||
1389 | |||
1390 | static void ehea_free_interrupts(struct net_device *dev) | ||
1391 | { | ||
1392 | struct ehea_port *port = netdev_priv(dev); | ||
1393 | struct ehea_port_res *pr; | ||
1394 | int i; | ||
1395 | |||
1396 | /* send */ | ||
1397 | |||
1398 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { | ||
1399 | pr = &port->port_res[i]; | ||
1400 | ibmebus_free_irq(pr->eq->attr.ist1, pr); | ||
1401 | netif_info(port, intr, dev, | ||
1402 | "free send irq for res %d with handle 0x%X\n", | ||
1403 | i, pr->eq->attr.ist1); | ||
1404 | } | ||
1405 | |||
1406 | /* associated events */ | ||
1407 | ibmebus_free_irq(port->qp_eq->attr.ist1, port); | ||
1408 | netif_info(port, intr, dev, | ||
1409 | "associated event interrupt for handle 0x%X freed\n", | ||
1410 | port->qp_eq->attr.ist1); | ||
1411 | } | ||
1412 | |||
1413 | static int ehea_configure_port(struct ehea_port *port) | ||
1414 | { | ||
1415 | int ret, i; | ||
1416 | u64 hret, mask; | ||
1417 | struct hcp_ehea_port_cb0 *cb0; | ||
1418 | |||
1419 | ret = -ENOMEM; | ||
1420 | cb0 = (void *)get_zeroed_page(GFP_KERNEL); | ||
1421 | if (!cb0) | ||
1422 | goto out; | ||
1423 | |||
1424 | cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1) | ||
1425 | | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1) | ||
1426 | | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1) | ||
1427 | | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1) | ||
1428 | | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER, | ||
1429 | PXLY_RC_VLAN_FILTER) | ||
1430 | | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1); | ||
1431 | |||
1432 | for (i = 0; i < port->num_mcs; i++) | ||
1433 | if (use_mcs) | ||
1434 | cb0->default_qpn_arr[i] = | ||
1435 | port->port_res[i].qp->init_attr.qp_nr; | ||
1436 | else | ||
1437 | cb0->default_qpn_arr[i] = | ||
1438 | port->port_res[0].qp->init_attr.qp_nr; | ||
1439 | |||
1440 | if (netif_msg_ifup(port)) | ||
1441 | ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port"); | ||
1442 | |||
1443 | mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1) | ||
1444 | | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1); | ||
1445 | |||
1446 | hret = ehea_h_modify_ehea_port(port->adapter->handle, | ||
1447 | port->logical_port_id, | ||
1448 | H_PORT_CB0, mask, cb0); | ||
1449 | ret = -EIO; | ||
1450 | if (hret != H_SUCCESS) | ||
1451 | goto out_free; | ||
1452 | |||
1453 | ret = 0; | ||
1454 | |||
1455 | out_free: | ||
1456 | free_page((unsigned long)cb0); | ||
1457 | out: | ||
1458 | return ret; | ||
1459 | } | ||
1460 | |||
1461 | int ehea_gen_smrs(struct ehea_port_res *pr) | ||
1462 | { | ||
1463 | int ret; | ||
1464 | struct ehea_adapter *adapter = pr->port->adapter; | ||
1465 | |||
1466 | ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr); | ||
1467 | if (ret) | ||
1468 | goto out; | ||
1469 | |||
1470 | ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr); | ||
1471 | if (ret) | ||
1472 | goto out_free; | ||
1473 | |||
1474 | return 0; | ||
1475 | |||
1476 | out_free: | ||
1477 | ehea_rem_mr(&pr->send_mr); | ||
1478 | out: | ||
1479 | pr_err("Generating SMRS failed\n"); | ||
1480 | return -EIO; | ||
1481 | } | ||
1482 | |||
1483 | int ehea_rem_smrs(struct ehea_port_res *pr) | ||
1484 | { | ||
1485 | if ((ehea_rem_mr(&pr->send_mr)) || | ||
1486 | (ehea_rem_mr(&pr->recv_mr))) | ||
1487 | return -EIO; | ||
1488 | else | ||
1489 | return 0; | ||
1490 | } | ||
1491 | |||
1492 | static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries) | ||
1493 | { | ||
1494 | int arr_size = sizeof(void *) * max_q_entries; | ||
1495 | |||
1496 | q_skba->arr = vzalloc(arr_size); | ||
1497 | if (!q_skba->arr) | ||
1498 | return -ENOMEM; | ||
1499 | |||
1500 | q_skba->len = max_q_entries; | ||
1501 | q_skba->index = 0; | ||
1502 | q_skba->os_skbs = 0; | ||
1503 | |||
1504 | return 0; | ||
1505 | } | ||
1506 | |||
1507 | static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr, | ||
1508 | struct port_res_cfg *pr_cfg, int queue_token) | ||
1509 | { | ||
1510 | struct ehea_adapter *adapter = port->adapter; | ||
1511 | enum ehea_eq_type eq_type = EHEA_EQ; | ||
1512 | struct ehea_qp_init_attr *init_attr = NULL; | ||
1513 | int ret = -EIO; | ||
1514 | u64 tx_bytes, rx_bytes, tx_packets, rx_packets; | ||
1515 | |||
1516 | tx_bytes = pr->tx_bytes; | ||
1517 | tx_packets = pr->tx_packets; | ||
1518 | rx_bytes = pr->rx_bytes; | ||
1519 | rx_packets = pr->rx_packets; | ||
1520 | |||
1521 | memset(pr, 0, sizeof(struct ehea_port_res)); | ||
1522 | |||
1523 | pr->tx_bytes = rx_bytes; | ||
1524 | pr->tx_packets = tx_packets; | ||
1525 | pr->rx_bytes = rx_bytes; | ||
1526 | pr->rx_packets = rx_packets; | ||
1527 | |||
1528 | pr->port = port; | ||
1529 | spin_lock_init(&pr->xmit_lock); | ||
1530 | spin_lock_init(&pr->netif_queue); | ||
1531 | |||
1532 | pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0); | ||
1533 | if (!pr->eq) { | ||
1534 | pr_err("create_eq failed (eq)\n"); | ||
1535 | goto out_free; | ||
1536 | } | ||
1537 | |||
1538 | pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq, | ||
1539 | pr->eq->fw_handle, | ||
1540 | port->logical_port_id); | ||
1541 | if (!pr->recv_cq) { | ||
1542 | pr_err("create_cq failed (cq_recv)\n"); | ||
1543 | goto out_free; | ||
1544 | } | ||
1545 | |||
1546 | pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq, | ||
1547 | pr->eq->fw_handle, | ||
1548 | port->logical_port_id); | ||
1549 | if (!pr->send_cq) { | ||
1550 | pr_err("create_cq failed (cq_send)\n"); | ||
1551 | goto out_free; | ||
1552 | } | ||
1553 | |||
1554 | if (netif_msg_ifup(port)) | ||
1555 | pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n", | ||
1556 | pr->send_cq->attr.act_nr_of_cqes, | ||
1557 | pr->recv_cq->attr.act_nr_of_cqes); | ||
1558 | |||
1559 | init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL); | ||
1560 | if (!init_attr) { | ||
1561 | ret = -ENOMEM; | ||
1562 | pr_err("no mem for ehea_qp_init_attr\n"); | ||
1563 | goto out_free; | ||
1564 | } | ||
1565 | |||
1566 | init_attr->low_lat_rq1 = 1; | ||
1567 | init_attr->signalingtype = 1; /* generate CQE if specified in WQE */ | ||
1568 | init_attr->rq_count = 3; | ||
1569 | init_attr->qp_token = queue_token; | ||
1570 | init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq; | ||
1571 | init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1; | ||
1572 | init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2; | ||
1573 | init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3; | ||
1574 | init_attr->wqe_size_enc_sq = EHEA_SG_SQ; | ||
1575 | init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1; | ||
1576 | init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2; | ||
1577 | init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3; | ||
1578 | init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD; | ||
1579 | init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD; | ||
1580 | init_attr->port_nr = port->logical_port_id; | ||
1581 | init_attr->send_cq_handle = pr->send_cq->fw_handle; | ||
1582 | init_attr->recv_cq_handle = pr->recv_cq->fw_handle; | ||
1583 | init_attr->aff_eq_handle = port->qp_eq->fw_handle; | ||
1584 | |||
1585 | pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr); | ||
1586 | if (!pr->qp) { | ||
1587 | pr_err("create_qp failed\n"); | ||
1588 | ret = -EIO; | ||
1589 | goto out_free; | ||
1590 | } | ||
1591 | |||
1592 | if (netif_msg_ifup(port)) | ||
1593 | pr_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d\n", | ||
1594 | init_attr->qp_nr, | ||
1595 | init_attr->act_nr_send_wqes, | ||
1596 | init_attr->act_nr_rwqes_rq1, | ||
1597 | init_attr->act_nr_rwqes_rq2, | ||
1598 | init_attr->act_nr_rwqes_rq3); | ||
1599 | |||
1600 | pr->sq_skba_size = init_attr->act_nr_send_wqes + 1; | ||
1601 | |||
1602 | ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size); | ||
1603 | ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1); | ||
1604 | ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1); | ||
1605 | ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1); | ||
1606 | if (ret) | ||
1607 | goto out_free; | ||
1608 | |||
1609 | pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10; | ||
1610 | if (ehea_gen_smrs(pr) != 0) { | ||
1611 | ret = -EIO; | ||
1612 | goto out_free; | ||
1613 | } | ||
1614 | |||
1615 | atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1); | ||
1616 | |||
1617 | kfree(init_attr); | ||
1618 | |||
1619 | netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64); | ||
1620 | |||
1621 | pr->lro_mgr.max_aggr = pr->port->lro_max_aggr; | ||
1622 | pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS; | ||
1623 | pr->lro_mgr.lro_arr = pr->lro_desc; | ||
1624 | pr->lro_mgr.get_skb_header = get_skb_hdr; | ||
1625 | pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID; | ||
1626 | pr->lro_mgr.dev = port->netdev; | ||
1627 | pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY; | ||
1628 | pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY; | ||
1629 | |||
1630 | ret = 0; | ||
1631 | goto out; | ||
1632 | |||
1633 | out_free: | ||
1634 | kfree(init_attr); | ||
1635 | vfree(pr->sq_skba.arr); | ||
1636 | vfree(pr->rq1_skba.arr); | ||
1637 | vfree(pr->rq2_skba.arr); | ||
1638 | vfree(pr->rq3_skba.arr); | ||
1639 | ehea_destroy_qp(pr->qp); | ||
1640 | ehea_destroy_cq(pr->send_cq); | ||
1641 | ehea_destroy_cq(pr->recv_cq); | ||
1642 | ehea_destroy_eq(pr->eq); | ||
1643 | out: | ||
1644 | return ret; | ||
1645 | } | ||
1646 | |||
1647 | static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr) | ||
1648 | { | ||
1649 | int ret, i; | ||
1650 | |||
1651 | if (pr->qp) | ||
1652 | netif_napi_del(&pr->napi); | ||
1653 | |||
1654 | ret = ehea_destroy_qp(pr->qp); | ||
1655 | |||
1656 | if (!ret) { | ||
1657 | ehea_destroy_cq(pr->send_cq); | ||
1658 | ehea_destroy_cq(pr->recv_cq); | ||
1659 | ehea_destroy_eq(pr->eq); | ||
1660 | |||
1661 | for (i = 0; i < pr->rq1_skba.len; i++) | ||
1662 | if (pr->rq1_skba.arr[i]) | ||
1663 | dev_kfree_skb(pr->rq1_skba.arr[i]); | ||
1664 | |||
1665 | for (i = 0; i < pr->rq2_skba.len; i++) | ||
1666 | if (pr->rq2_skba.arr[i]) | ||
1667 | dev_kfree_skb(pr->rq2_skba.arr[i]); | ||
1668 | |||
1669 | for (i = 0; i < pr->rq3_skba.len; i++) | ||
1670 | if (pr->rq3_skba.arr[i]) | ||
1671 | dev_kfree_skb(pr->rq3_skba.arr[i]); | ||
1672 | |||
1673 | for (i = 0; i < pr->sq_skba.len; i++) | ||
1674 | if (pr->sq_skba.arr[i]) | ||
1675 | dev_kfree_skb(pr->sq_skba.arr[i]); | ||
1676 | |||
1677 | vfree(pr->rq1_skba.arr); | ||
1678 | vfree(pr->rq2_skba.arr); | ||
1679 | vfree(pr->rq3_skba.arr); | ||
1680 | vfree(pr->sq_skba.arr); | ||
1681 | ret = ehea_rem_smrs(pr); | ||
1682 | } | ||
1683 | return ret; | ||
1684 | } | ||
1685 | |||
1686 | /* | ||
1687 | * The write_* functions store information in swqe which is used by | ||
1688 | * the hardware to calculate the ip/tcp/udp checksum | ||
1689 | */ | ||
1690 | |||
1691 | static inline void write_ip_start_end(struct ehea_swqe *swqe, | ||
1692 | const struct sk_buff *skb) | ||
1693 | { | ||
1694 | swqe->ip_start = skb_network_offset(skb); | ||
1695 | swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1); | ||
1696 | } | ||
1697 | |||
1698 | static inline void write_tcp_offset_end(struct ehea_swqe *swqe, | ||
1699 | const struct sk_buff *skb) | ||
1700 | { | ||
1701 | swqe->tcp_offset = | ||
1702 | (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check)); | ||
1703 | |||
1704 | swqe->tcp_end = (u16)skb->len - 1; | ||
1705 | } | ||
1706 | |||
1707 | static inline void write_udp_offset_end(struct ehea_swqe *swqe, | ||
1708 | const struct sk_buff *skb) | ||
1709 | { | ||
1710 | swqe->tcp_offset = | ||
1711 | (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check)); | ||
1712 | |||
1713 | swqe->tcp_end = (u16)skb->len - 1; | ||
1714 | } | ||
1715 | |||
1716 | |||
1717 | static void write_swqe2_TSO(struct sk_buff *skb, | ||
1718 | struct ehea_swqe *swqe, u32 lkey) | ||
1719 | { | ||
1720 | struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry; | ||
1721 | u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0]; | ||
1722 | int skb_data_size = skb_headlen(skb); | ||
1723 | int headersize; | ||
1724 | |||
1725 | /* Packet is TCP with TSO enabled */ | ||
1726 | swqe->tx_control |= EHEA_SWQE_TSO; | ||
1727 | swqe->mss = skb_shinfo(skb)->gso_size; | ||
1728 | /* copy only eth/ip/tcp headers to immediate data and | ||
1729 | * the rest of skb->data to sg1entry | ||
1730 | */ | ||
1731 | headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb); | ||
1732 | |||
1733 | skb_data_size = skb_headlen(skb); | ||
1734 | |||
1735 | if (skb_data_size >= headersize) { | ||
1736 | /* copy immediate data */ | ||
1737 | skb_copy_from_linear_data(skb, imm_data, headersize); | ||
1738 | swqe->immediate_data_length = headersize; | ||
1739 | |||
1740 | if (skb_data_size > headersize) { | ||
1741 | /* set sg1entry data */ | ||
1742 | sg1entry->l_key = lkey; | ||
1743 | sg1entry->len = skb_data_size - headersize; | ||
1744 | sg1entry->vaddr = | ||
1745 | ehea_map_vaddr(skb->data + headersize); | ||
1746 | swqe->descriptors++; | ||
1747 | } | ||
1748 | } else | ||
1749 | pr_err("cannot handle fragmented headers\n"); | ||
1750 | } | ||
1751 | |||
1752 | static void write_swqe2_nonTSO(struct sk_buff *skb, | ||
1753 | struct ehea_swqe *swqe, u32 lkey) | ||
1754 | { | ||
1755 | int skb_data_size = skb_headlen(skb); | ||
1756 | u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0]; | ||
1757 | struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry; | ||
1758 | |||
1759 | /* Packet is any nonTSO type | ||
1760 | * | ||
1761 | * Copy as much as possible skb->data to immediate data and | ||
1762 | * the rest to sg1entry | ||
1763 | */ | ||
1764 | if (skb_data_size >= SWQE2_MAX_IMM) { | ||
1765 | /* copy immediate data */ | ||
1766 | skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM); | ||
1767 | |||
1768 | swqe->immediate_data_length = SWQE2_MAX_IMM; | ||
1769 | |||
1770 | if (skb_data_size > SWQE2_MAX_IMM) { | ||
1771 | /* copy sg1entry data */ | ||
1772 | sg1entry->l_key = lkey; | ||
1773 | sg1entry->len = skb_data_size - SWQE2_MAX_IMM; | ||
1774 | sg1entry->vaddr = | ||
1775 | ehea_map_vaddr(skb->data + SWQE2_MAX_IMM); | ||
1776 | swqe->descriptors++; | ||
1777 | } | ||
1778 | } else { | ||
1779 | skb_copy_from_linear_data(skb, imm_data, skb_data_size); | ||
1780 | swqe->immediate_data_length = skb_data_size; | ||
1781 | } | ||
1782 | } | ||
1783 | |||
1784 | static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev, | ||
1785 | struct ehea_swqe *swqe, u32 lkey) | ||
1786 | { | ||
1787 | struct ehea_vsgentry *sg_list, *sg1entry, *sgentry; | ||
1788 | skb_frag_t *frag; | ||
1789 | int nfrags, sg1entry_contains_frag_data, i; | ||
1790 | |||
1791 | nfrags = skb_shinfo(skb)->nr_frags; | ||
1792 | sg1entry = &swqe->u.immdata_desc.sg_entry; | ||
1793 | sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list; | ||
1794 | swqe->descriptors = 0; | ||
1795 | sg1entry_contains_frag_data = 0; | ||
1796 | |||
1797 | if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size) | ||
1798 | write_swqe2_TSO(skb, swqe, lkey); | ||
1799 | else | ||
1800 | write_swqe2_nonTSO(skb, swqe, lkey); | ||
1801 | |||
1802 | /* write descriptors */ | ||
1803 | if (nfrags > 0) { | ||
1804 | if (swqe->descriptors == 0) { | ||
1805 | /* sg1entry not yet used */ | ||
1806 | frag = &skb_shinfo(skb)->frags[0]; | ||
1807 | |||
1808 | /* copy sg1entry data */ | ||
1809 | sg1entry->l_key = lkey; | ||
1810 | sg1entry->len = frag->size; | ||
1811 | sg1entry->vaddr = | ||
1812 | ehea_map_vaddr(page_address(frag->page) | ||
1813 | + frag->page_offset); | ||
1814 | swqe->descriptors++; | ||
1815 | sg1entry_contains_frag_data = 1; | ||
1816 | } | ||
1817 | |||
1818 | for (i = sg1entry_contains_frag_data; i < nfrags; i++) { | ||
1819 | |||
1820 | frag = &skb_shinfo(skb)->frags[i]; | ||
1821 | sgentry = &sg_list[i - sg1entry_contains_frag_data]; | ||
1822 | |||
1823 | sgentry->l_key = lkey; | ||
1824 | sgentry->len = frag->size; | ||
1825 | sgentry->vaddr = | ||
1826 | ehea_map_vaddr(page_address(frag->page) | ||
1827 | + frag->page_offset); | ||
1828 | swqe->descriptors++; | ||
1829 | } | ||
1830 | } | ||
1831 | } | ||
1832 | |||
1833 | static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid) | ||
1834 | { | ||
1835 | int ret = 0; | ||
1836 | u64 hret; | ||
1837 | u8 reg_type; | ||
1838 | |||
1839 | /* De/Register untagged packets */ | ||
1840 | reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED; | ||
1841 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, | ||
1842 | port->logical_port_id, | ||
1843 | reg_type, port->mac_addr, 0, hcallid); | ||
1844 | if (hret != H_SUCCESS) { | ||
1845 | pr_err("%sregistering bc address failed (tagged)\n", | ||
1846 | hcallid == H_REG_BCMC ? "" : "de"); | ||
1847 | ret = -EIO; | ||
1848 | goto out_herr; | ||
1849 | } | ||
1850 | |||
1851 | /* De/Register VLAN packets */ | ||
1852 | reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL; | ||
1853 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, | ||
1854 | port->logical_port_id, | ||
1855 | reg_type, port->mac_addr, 0, hcallid); | ||
1856 | if (hret != H_SUCCESS) { | ||
1857 | pr_err("%sregistering bc address failed (vlan)\n", | ||
1858 | hcallid == H_REG_BCMC ? "" : "de"); | ||
1859 | ret = -EIO; | ||
1860 | } | ||
1861 | out_herr: | ||
1862 | return ret; | ||
1863 | } | ||
1864 | |||
1865 | static int ehea_set_mac_addr(struct net_device *dev, void *sa) | ||
1866 | { | ||
1867 | struct ehea_port *port = netdev_priv(dev); | ||
1868 | struct sockaddr *mac_addr = sa; | ||
1869 | struct hcp_ehea_port_cb0 *cb0; | ||
1870 | int ret; | ||
1871 | u64 hret; | ||
1872 | |||
1873 | if (!is_valid_ether_addr(mac_addr->sa_data)) { | ||
1874 | ret = -EADDRNOTAVAIL; | ||
1875 | goto out; | ||
1876 | } | ||
1877 | |||
1878 | cb0 = (void *)get_zeroed_page(GFP_KERNEL); | ||
1879 | if (!cb0) { | ||
1880 | pr_err("no mem for cb0\n"); | ||
1881 | ret = -ENOMEM; | ||
1882 | goto out; | ||
1883 | } | ||
1884 | |||
1885 | memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN); | ||
1886 | |||
1887 | cb0->port_mac_addr = cb0->port_mac_addr >> 16; | ||
1888 | |||
1889 | hret = ehea_h_modify_ehea_port(port->adapter->handle, | ||
1890 | port->logical_port_id, H_PORT_CB0, | ||
1891 | EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0); | ||
1892 | if (hret != H_SUCCESS) { | ||
1893 | ret = -EIO; | ||
1894 | goto out_free; | ||
1895 | } | ||
1896 | |||
1897 | memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len); | ||
1898 | |||
1899 | /* Deregister old MAC in pHYP */ | ||
1900 | if (port->state == EHEA_PORT_UP) { | ||
1901 | ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC); | ||
1902 | if (ret) | ||
1903 | goto out_upregs; | ||
1904 | } | ||
1905 | |||
1906 | port->mac_addr = cb0->port_mac_addr << 16; | ||
1907 | |||
1908 | /* Register new MAC in pHYP */ | ||
1909 | if (port->state == EHEA_PORT_UP) { | ||
1910 | ret = ehea_broadcast_reg_helper(port, H_REG_BCMC); | ||
1911 | if (ret) | ||
1912 | goto out_upregs; | ||
1913 | } | ||
1914 | |||
1915 | ret = 0; | ||
1916 | |||
1917 | out_upregs: | ||
1918 | ehea_update_bcmc_registrations(); | ||
1919 | out_free: | ||
1920 | free_page((unsigned long)cb0); | ||
1921 | out: | ||
1922 | return ret; | ||
1923 | } | ||
1924 | |||
1925 | static void ehea_promiscuous_error(u64 hret, int enable) | ||
1926 | { | ||
1927 | if (hret == H_AUTHORITY) | ||
1928 | pr_info("Hypervisor denied %sabling promiscuous mode\n", | ||
1929 | enable == 1 ? "en" : "dis"); | ||
1930 | else | ||
1931 | pr_err("failed %sabling promiscuous mode\n", | ||
1932 | enable == 1 ? "en" : "dis"); | ||
1933 | } | ||
1934 | |||
1935 | static void ehea_promiscuous(struct net_device *dev, int enable) | ||
1936 | { | ||
1937 | struct ehea_port *port = netdev_priv(dev); | ||
1938 | struct hcp_ehea_port_cb7 *cb7; | ||
1939 | u64 hret; | ||
1940 | |||
1941 | if (enable == port->promisc) | ||
1942 | return; | ||
1943 | |||
1944 | cb7 = (void *)get_zeroed_page(GFP_ATOMIC); | ||
1945 | if (!cb7) { | ||
1946 | pr_err("no mem for cb7\n"); | ||
1947 | goto out; | ||
1948 | } | ||
1949 | |||
1950 | /* Modify Pxs_DUCQPN in CB7 */ | ||
1951 | cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0; | ||
1952 | |||
1953 | hret = ehea_h_modify_ehea_port(port->adapter->handle, | ||
1954 | port->logical_port_id, | ||
1955 | H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7); | ||
1956 | if (hret) { | ||
1957 | ehea_promiscuous_error(hret, enable); | ||
1958 | goto out; | ||
1959 | } | ||
1960 | |||
1961 | port->promisc = enable; | ||
1962 | out: | ||
1963 | free_page((unsigned long)cb7); | ||
1964 | } | ||
1965 | |||
1966 | static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr, | ||
1967 | u32 hcallid) | ||
1968 | { | ||
1969 | u64 hret; | ||
1970 | u8 reg_type; | ||
1971 | |||
1972 | reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST | ||
1973 | | EHEA_BCMC_UNTAGGED; | ||
1974 | |||
1975 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, | ||
1976 | port->logical_port_id, | ||
1977 | reg_type, mc_mac_addr, 0, hcallid); | ||
1978 | if (hret) | ||
1979 | goto out; | ||
1980 | |||
1981 | reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST | ||
1982 | | EHEA_BCMC_VLANID_ALL; | ||
1983 | |||
1984 | hret = ehea_h_reg_dereg_bcmc(port->adapter->handle, | ||
1985 | port->logical_port_id, | ||
1986 | reg_type, mc_mac_addr, 0, hcallid); | ||
1987 | out: | ||
1988 | return hret; | ||
1989 | } | ||
1990 | |||
1991 | static int ehea_drop_multicast_list(struct net_device *dev) | ||
1992 | { | ||
1993 | struct ehea_port *port = netdev_priv(dev); | ||
1994 | struct ehea_mc_list *mc_entry = port->mc_list; | ||
1995 | struct list_head *pos; | ||
1996 | struct list_head *temp; | ||
1997 | int ret = 0; | ||
1998 | u64 hret; | ||
1999 | |||
2000 | list_for_each_safe(pos, temp, &(port->mc_list->list)) { | ||
2001 | mc_entry = list_entry(pos, struct ehea_mc_list, list); | ||
2002 | |||
2003 | hret = ehea_multicast_reg_helper(port, mc_entry->macaddr, | ||
2004 | H_DEREG_BCMC); | ||
2005 | if (hret) { | ||
2006 | pr_err("failed deregistering mcast MAC\n"); | ||
2007 | ret = -EIO; | ||
2008 | } | ||
2009 | |||
2010 | list_del(pos); | ||
2011 | kfree(mc_entry); | ||
2012 | } | ||
2013 | return ret; | ||
2014 | } | ||
2015 | |||
2016 | static void ehea_allmulti(struct net_device *dev, int enable) | ||
2017 | { | ||
2018 | struct ehea_port *port = netdev_priv(dev); | ||
2019 | u64 hret; | ||
2020 | |||
2021 | if (!port->allmulti) { | ||
2022 | if (enable) { | ||
2023 | /* Enable ALLMULTI */ | ||
2024 | ehea_drop_multicast_list(dev); | ||
2025 | hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC); | ||
2026 | if (!hret) | ||
2027 | port->allmulti = 1; | ||
2028 | else | ||
2029 | netdev_err(dev, | ||
2030 | "failed enabling IFF_ALLMULTI\n"); | ||
2031 | } | ||
2032 | } else | ||
2033 | if (!enable) { | ||
2034 | /* Disable ALLMULTI */ | ||
2035 | hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC); | ||
2036 | if (!hret) | ||
2037 | port->allmulti = 0; | ||
2038 | else | ||
2039 | netdev_err(dev, | ||
2040 | "failed disabling IFF_ALLMULTI\n"); | ||
2041 | } | ||
2042 | } | ||
2043 | |||
2044 | static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr) | ||
2045 | { | ||
2046 | struct ehea_mc_list *ehea_mcl_entry; | ||
2047 | u64 hret; | ||
2048 | |||
2049 | ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC); | ||
2050 | if (!ehea_mcl_entry) { | ||
2051 | pr_err("no mem for mcl_entry\n"); | ||
2052 | return; | ||
2053 | } | ||
2054 | |||
2055 | INIT_LIST_HEAD(&ehea_mcl_entry->list); | ||
2056 | |||
2057 | memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN); | ||
2058 | |||
2059 | hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr, | ||
2060 | H_REG_BCMC); | ||
2061 | if (!hret) | ||
2062 | list_add(&ehea_mcl_entry->list, &port->mc_list->list); | ||
2063 | else { | ||
2064 | pr_err("failed registering mcast MAC\n"); | ||
2065 | kfree(ehea_mcl_entry); | ||
2066 | } | ||
2067 | } | ||
2068 | |||
2069 | static void ehea_set_multicast_list(struct net_device *dev) | ||
2070 | { | ||
2071 | struct ehea_port *port = netdev_priv(dev); | ||
2072 | struct netdev_hw_addr *ha; | ||
2073 | int ret; | ||
2074 | |||
2075 | if (port->promisc) { | ||
2076 | ehea_promiscuous(dev, 1); | ||
2077 | return; | ||
2078 | } | ||
2079 | ehea_promiscuous(dev, 0); | ||
2080 | |||
2081 | if (dev->flags & IFF_ALLMULTI) { | ||
2082 | ehea_allmulti(dev, 1); | ||
2083 | goto out; | ||
2084 | } | ||
2085 | ehea_allmulti(dev, 0); | ||
2086 | |||
2087 | if (!netdev_mc_empty(dev)) { | ||
2088 | ret = ehea_drop_multicast_list(dev); | ||
2089 | if (ret) { | ||
2090 | /* Dropping the current multicast list failed. | ||
2091 | * Enabling ALL_MULTI is the best we can do. | ||
2092 | */ | ||
2093 | ehea_allmulti(dev, 1); | ||
2094 | } | ||
2095 | |||
2096 | if (netdev_mc_count(dev) > port->adapter->max_mc_mac) { | ||
2097 | pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n", | ||
2098 | port->adapter->max_mc_mac); | ||
2099 | goto out; | ||
2100 | } | ||
2101 | |||
2102 | netdev_for_each_mc_addr(ha, dev) | ||
2103 | ehea_add_multicast_entry(port, ha->addr); | ||
2104 | |||
2105 | } | ||
2106 | out: | ||
2107 | ehea_update_bcmc_registrations(); | ||
2108 | } | ||
2109 | |||
2110 | static int ehea_change_mtu(struct net_device *dev, int new_mtu) | ||
2111 | { | ||
2112 | if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE)) | ||
2113 | return -EINVAL; | ||
2114 | dev->mtu = new_mtu; | ||
2115 | return 0; | ||
2116 | } | ||
2117 | |||
2118 | static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev, | ||
2119 | struct ehea_swqe *swqe, u32 lkey) | ||
2120 | { | ||
2121 | if (skb->protocol == htons(ETH_P_IP)) { | ||
2122 | const struct iphdr *iph = ip_hdr(skb); | ||
2123 | |||
2124 | /* IPv4 */ | ||
2125 | swqe->tx_control |= EHEA_SWQE_CRC | ||
2126 | | EHEA_SWQE_IP_CHECKSUM | ||
2127 | | EHEA_SWQE_TCP_CHECKSUM | ||
2128 | | EHEA_SWQE_IMM_DATA_PRESENT | ||
2129 | | EHEA_SWQE_DESCRIPTORS_PRESENT; | ||
2130 | |||
2131 | write_ip_start_end(swqe, skb); | ||
2132 | |||
2133 | if (iph->protocol == IPPROTO_UDP) { | ||
2134 | if ((iph->frag_off & IP_MF) || | ||
2135 | (iph->frag_off & IP_OFFSET)) | ||
2136 | /* IP fragment, so don't change cs */ | ||
2137 | swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM; | ||
2138 | else | ||
2139 | write_udp_offset_end(swqe, skb); | ||
2140 | } else if (iph->protocol == IPPROTO_TCP) { | ||
2141 | write_tcp_offset_end(swqe, skb); | ||
2142 | } | ||
2143 | |||
2144 | /* icmp (big data) and ip segmentation packets (all other ip | ||
2145 | packets) do not require any special handling */ | ||
2146 | |||
2147 | } else { | ||
2148 | /* Other Ethernet Protocol */ | ||
2149 | swqe->tx_control |= EHEA_SWQE_CRC | ||
2150 | | EHEA_SWQE_IMM_DATA_PRESENT | ||
2151 | | EHEA_SWQE_DESCRIPTORS_PRESENT; | ||
2152 | } | ||
2153 | |||
2154 | write_swqe2_data(skb, dev, swqe, lkey); | ||
2155 | } | ||
2156 | |||
2157 | static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev, | ||
2158 | struct ehea_swqe *swqe) | ||
2159 | { | ||
2160 | int nfrags = skb_shinfo(skb)->nr_frags; | ||
2161 | u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0]; | ||
2162 | skb_frag_t *frag; | ||
2163 | int i; | ||
2164 | |||
2165 | if (skb->protocol == htons(ETH_P_IP)) { | ||
2166 | const struct iphdr *iph = ip_hdr(skb); | ||
2167 | |||
2168 | /* IPv4 */ | ||
2169 | write_ip_start_end(swqe, skb); | ||
2170 | |||
2171 | if (iph->protocol == IPPROTO_TCP) { | ||
2172 | swqe->tx_control |= EHEA_SWQE_CRC | ||
2173 | | EHEA_SWQE_IP_CHECKSUM | ||
2174 | | EHEA_SWQE_TCP_CHECKSUM | ||
2175 | | EHEA_SWQE_IMM_DATA_PRESENT; | ||
2176 | |||
2177 | write_tcp_offset_end(swqe, skb); | ||
2178 | |||
2179 | } else if (iph->protocol == IPPROTO_UDP) { | ||
2180 | if ((iph->frag_off & IP_MF) || | ||
2181 | (iph->frag_off & IP_OFFSET)) | ||
2182 | /* IP fragment, so don't change cs */ | ||
2183 | swqe->tx_control |= EHEA_SWQE_CRC | ||
2184 | | EHEA_SWQE_IMM_DATA_PRESENT; | ||
2185 | else { | ||
2186 | swqe->tx_control |= EHEA_SWQE_CRC | ||
2187 | | EHEA_SWQE_IP_CHECKSUM | ||
2188 | | EHEA_SWQE_TCP_CHECKSUM | ||
2189 | | EHEA_SWQE_IMM_DATA_PRESENT; | ||
2190 | |||
2191 | write_udp_offset_end(swqe, skb); | ||
2192 | } | ||
2193 | } else { | ||
2194 | /* icmp (big data) and | ||
2195 | ip segmentation packets (all other ip packets) */ | ||
2196 | swqe->tx_control |= EHEA_SWQE_CRC | ||
2197 | | EHEA_SWQE_IP_CHECKSUM | ||
2198 | | EHEA_SWQE_IMM_DATA_PRESENT; | ||
2199 | } | ||
2200 | } else { | ||
2201 | /* Other Ethernet Protocol */ | ||
2202 | swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT; | ||
2203 | } | ||
2204 | /* copy (immediate) data */ | ||
2205 | if (nfrags == 0) { | ||
2206 | /* data is in a single piece */ | ||
2207 | skb_copy_from_linear_data(skb, imm_data, skb->len); | ||
2208 | } else { | ||
2209 | /* first copy data from the skb->data buffer ... */ | ||
2210 | skb_copy_from_linear_data(skb, imm_data, | ||
2211 | skb_headlen(skb)); | ||
2212 | imm_data += skb_headlen(skb); | ||
2213 | |||
2214 | /* ... then copy data from the fragments */ | ||
2215 | for (i = 0; i < nfrags; i++) { | ||
2216 | frag = &skb_shinfo(skb)->frags[i]; | ||
2217 | memcpy(imm_data, | ||
2218 | page_address(frag->page) + frag->page_offset, | ||
2219 | frag->size); | ||
2220 | imm_data += frag->size; | ||
2221 | } | ||
2222 | } | ||
2223 | swqe->immediate_data_length = skb->len; | ||
2224 | dev_kfree_skb(skb); | ||
2225 | } | ||
2226 | |||
2227 | static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps) | ||
2228 | { | ||
2229 | struct tcphdr *tcp; | ||
2230 | u32 tmp; | ||
2231 | |||
2232 | if ((skb->protocol == htons(ETH_P_IP)) && | ||
2233 | (ip_hdr(skb)->protocol == IPPROTO_TCP)) { | ||
2234 | tcp = (struct tcphdr *)(skb_network_header(skb) + | ||
2235 | (ip_hdr(skb)->ihl * 4)); | ||
2236 | tmp = (tcp->source + (tcp->dest << 16)) % 31; | ||
2237 | tmp += ip_hdr(skb)->daddr % 31; | ||
2238 | return tmp % num_qps; | ||
2239 | } else | ||
2240 | return 0; | ||
2241 | } | ||
2242 | |||
2243 | static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev) | ||
2244 | { | ||
2245 | struct ehea_port *port = netdev_priv(dev); | ||
2246 | struct ehea_swqe *swqe; | ||
2247 | unsigned long flags; | ||
2248 | u32 lkey; | ||
2249 | int swqe_index; | ||
2250 | struct ehea_port_res *pr; | ||
2251 | |||
2252 | pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)]; | ||
2253 | |||
2254 | if (!spin_trylock(&pr->xmit_lock)) | ||
2255 | return NETDEV_TX_BUSY; | ||
2256 | |||
2257 | if (pr->queue_stopped) { | ||
2258 | spin_unlock(&pr->xmit_lock); | ||
2259 | return NETDEV_TX_BUSY; | ||
2260 | } | ||
2261 | |||
2262 | swqe = ehea_get_swqe(pr->qp, &swqe_index); | ||
2263 | memset(swqe, 0, SWQE_HEADER_SIZE); | ||
2264 | atomic_dec(&pr->swqe_avail); | ||
2265 | |||
2266 | if (vlan_tx_tag_present(skb)) { | ||
2267 | swqe->tx_control |= EHEA_SWQE_VLAN_INSERT; | ||
2268 | swqe->vlan_tag = vlan_tx_tag_get(skb); | ||
2269 | } | ||
2270 | |||
2271 | pr->tx_packets++; | ||
2272 | pr->tx_bytes += skb->len; | ||
2273 | |||
2274 | if (skb->len <= SWQE3_MAX_IMM) { | ||
2275 | u32 sig_iv = port->sig_comp_iv; | ||
2276 | u32 swqe_num = pr->swqe_id_counter; | ||
2277 | ehea_xmit3(skb, dev, swqe); | ||
2278 | swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE) | ||
2279 | | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num); | ||
2280 | if (pr->swqe_ll_count >= (sig_iv - 1)) { | ||
2281 | swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL, | ||
2282 | sig_iv); | ||
2283 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; | ||
2284 | pr->swqe_ll_count = 0; | ||
2285 | } else | ||
2286 | pr->swqe_ll_count += 1; | ||
2287 | } else { | ||
2288 | swqe->wr_id = | ||
2289 | EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE) | ||
2290 | | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter) | ||
2291 | | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1) | ||
2292 | | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index); | ||
2293 | pr->sq_skba.arr[pr->sq_skba.index] = skb; | ||
2294 | |||
2295 | pr->sq_skba.index++; | ||
2296 | pr->sq_skba.index &= (pr->sq_skba.len - 1); | ||
2297 | |||
2298 | lkey = pr->send_mr.lkey; | ||
2299 | ehea_xmit2(skb, dev, swqe, lkey); | ||
2300 | swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION; | ||
2301 | } | ||
2302 | pr->swqe_id_counter += 1; | ||
2303 | |||
2304 | netif_info(port, tx_queued, dev, | ||
2305 | "post swqe on QP %d\n", pr->qp->init_attr.qp_nr); | ||
2306 | if (netif_msg_tx_queued(port)) | ||
2307 | ehea_dump(swqe, 512, "swqe"); | ||
2308 | |||
2309 | if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) { | ||
2310 | netif_stop_queue(dev); | ||
2311 | swqe->tx_control |= EHEA_SWQE_PURGE; | ||
2312 | } | ||
2313 | |||
2314 | ehea_post_swqe(pr->qp, swqe); | ||
2315 | |||
2316 | if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { | ||
2317 | spin_lock_irqsave(&pr->netif_queue, flags); | ||
2318 | if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { | ||
2319 | pr->p_stats.queue_stopped++; | ||
2320 | netif_stop_queue(dev); | ||
2321 | pr->queue_stopped = 1; | ||
2322 | } | ||
2323 | spin_unlock_irqrestore(&pr->netif_queue, flags); | ||
2324 | } | ||
2325 | dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */ | ||
2326 | spin_unlock(&pr->xmit_lock); | ||
2327 | |||
2328 | return NETDEV_TX_OK; | ||
2329 | } | ||
2330 | |||
2331 | static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) | ||
2332 | { | ||
2333 | struct ehea_port *port = netdev_priv(dev); | ||
2334 | struct ehea_adapter *adapter = port->adapter; | ||
2335 | struct hcp_ehea_port_cb1 *cb1; | ||
2336 | int index; | ||
2337 | u64 hret; | ||
2338 | |||
2339 | cb1 = (void *)get_zeroed_page(GFP_KERNEL); | ||
2340 | if (!cb1) { | ||
2341 | pr_err("no mem for cb1\n"); | ||
2342 | goto out; | ||
2343 | } | ||
2344 | |||
2345 | hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id, | ||
2346 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | ||
2347 | if (hret != H_SUCCESS) { | ||
2348 | pr_err("query_ehea_port failed\n"); | ||
2349 | goto out; | ||
2350 | } | ||
2351 | |||
2352 | index = (vid / 64); | ||
2353 | cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F))); | ||
2354 | |||
2355 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, | ||
2356 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | ||
2357 | if (hret != H_SUCCESS) | ||
2358 | pr_err("modify_ehea_port failed\n"); | ||
2359 | out: | ||
2360 | free_page((unsigned long)cb1); | ||
2361 | return; | ||
2362 | } | ||
2363 | |||
2364 | static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) | ||
2365 | { | ||
2366 | struct ehea_port *port = netdev_priv(dev); | ||
2367 | struct ehea_adapter *adapter = port->adapter; | ||
2368 | struct hcp_ehea_port_cb1 *cb1; | ||
2369 | int index; | ||
2370 | u64 hret; | ||
2371 | |||
2372 | cb1 = (void *)get_zeroed_page(GFP_KERNEL); | ||
2373 | if (!cb1) { | ||
2374 | pr_err("no mem for cb1\n"); | ||
2375 | goto out; | ||
2376 | } | ||
2377 | |||
2378 | hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id, | ||
2379 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | ||
2380 | if (hret != H_SUCCESS) { | ||
2381 | pr_err("query_ehea_port failed\n"); | ||
2382 | goto out; | ||
2383 | } | ||
2384 | |||
2385 | index = (vid / 64); | ||
2386 | cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F))); | ||
2387 | |||
2388 | hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id, | ||
2389 | H_PORT_CB1, H_PORT_CB1_ALL, cb1); | ||
2390 | if (hret != H_SUCCESS) | ||
2391 | pr_err("modify_ehea_port failed\n"); | ||
2392 | out: | ||
2393 | free_page((unsigned long)cb1); | ||
2394 | } | ||
2395 | |||
2396 | int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp) | ||
2397 | { | ||
2398 | int ret = -EIO; | ||
2399 | u64 hret; | ||
2400 | u16 dummy16 = 0; | ||
2401 | u64 dummy64 = 0; | ||
2402 | struct hcp_modify_qp_cb0 *cb0; | ||
2403 | |||
2404 | cb0 = (void *)get_zeroed_page(GFP_KERNEL); | ||
2405 | if (!cb0) { | ||
2406 | ret = -ENOMEM; | ||
2407 | goto out; | ||
2408 | } | ||
2409 | |||
2410 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2411 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); | ||
2412 | if (hret != H_SUCCESS) { | ||
2413 | pr_err("query_ehea_qp failed (1)\n"); | ||
2414 | goto out; | ||
2415 | } | ||
2416 | |||
2417 | cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED; | ||
2418 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2419 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, | ||
2420 | &dummy64, &dummy64, &dummy16, &dummy16); | ||
2421 | if (hret != H_SUCCESS) { | ||
2422 | pr_err("modify_ehea_qp failed (1)\n"); | ||
2423 | goto out; | ||
2424 | } | ||
2425 | |||
2426 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2427 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); | ||
2428 | if (hret != H_SUCCESS) { | ||
2429 | pr_err("query_ehea_qp failed (2)\n"); | ||
2430 | goto out; | ||
2431 | } | ||
2432 | |||
2433 | cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED; | ||
2434 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2435 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, | ||
2436 | &dummy64, &dummy64, &dummy16, &dummy16); | ||
2437 | if (hret != H_SUCCESS) { | ||
2438 | pr_err("modify_ehea_qp failed (2)\n"); | ||
2439 | goto out; | ||
2440 | } | ||
2441 | |||
2442 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2443 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); | ||
2444 | if (hret != H_SUCCESS) { | ||
2445 | pr_err("query_ehea_qp failed (3)\n"); | ||
2446 | goto out; | ||
2447 | } | ||
2448 | |||
2449 | cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND; | ||
2450 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2451 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0, | ||
2452 | &dummy64, &dummy64, &dummy16, &dummy16); | ||
2453 | if (hret != H_SUCCESS) { | ||
2454 | pr_err("modify_ehea_qp failed (3)\n"); | ||
2455 | goto out; | ||
2456 | } | ||
2457 | |||
2458 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2459 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0); | ||
2460 | if (hret != H_SUCCESS) { | ||
2461 | pr_err("query_ehea_qp failed (4)\n"); | ||
2462 | goto out; | ||
2463 | } | ||
2464 | |||
2465 | ret = 0; | ||
2466 | out: | ||
2467 | free_page((unsigned long)cb0); | ||
2468 | return ret; | ||
2469 | } | ||
2470 | |||
2471 | static int ehea_port_res_setup(struct ehea_port *port, int def_qps, | ||
2472 | int add_tx_qps) | ||
2473 | { | ||
2474 | int ret, i; | ||
2475 | struct port_res_cfg pr_cfg, pr_cfg_small_rx; | ||
2476 | enum ehea_eq_type eq_type = EHEA_EQ; | ||
2477 | |||
2478 | port->qp_eq = ehea_create_eq(port->adapter, eq_type, | ||
2479 | EHEA_MAX_ENTRIES_EQ, 1); | ||
2480 | if (!port->qp_eq) { | ||
2481 | ret = -EINVAL; | ||
2482 | pr_err("ehea_create_eq failed (qp_eq)\n"); | ||
2483 | goto out_kill_eq; | ||
2484 | } | ||
2485 | |||
2486 | pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries; | ||
2487 | pr_cfg.max_entries_scq = sq_entries * 2; | ||
2488 | pr_cfg.max_entries_sq = sq_entries; | ||
2489 | pr_cfg.max_entries_rq1 = rq1_entries; | ||
2490 | pr_cfg.max_entries_rq2 = rq2_entries; | ||
2491 | pr_cfg.max_entries_rq3 = rq3_entries; | ||
2492 | |||
2493 | pr_cfg_small_rx.max_entries_rcq = 1; | ||
2494 | pr_cfg_small_rx.max_entries_scq = sq_entries; | ||
2495 | pr_cfg_small_rx.max_entries_sq = sq_entries; | ||
2496 | pr_cfg_small_rx.max_entries_rq1 = 1; | ||
2497 | pr_cfg_small_rx.max_entries_rq2 = 1; | ||
2498 | pr_cfg_small_rx.max_entries_rq3 = 1; | ||
2499 | |||
2500 | for (i = 0; i < def_qps; i++) { | ||
2501 | ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i); | ||
2502 | if (ret) | ||
2503 | goto out_clean_pr; | ||
2504 | } | ||
2505 | for (i = def_qps; i < def_qps + add_tx_qps; i++) { | ||
2506 | ret = ehea_init_port_res(port, &port->port_res[i], | ||
2507 | &pr_cfg_small_rx, i); | ||
2508 | if (ret) | ||
2509 | goto out_clean_pr; | ||
2510 | } | ||
2511 | |||
2512 | return 0; | ||
2513 | |||
2514 | out_clean_pr: | ||
2515 | while (--i >= 0) | ||
2516 | ehea_clean_portres(port, &port->port_res[i]); | ||
2517 | |||
2518 | out_kill_eq: | ||
2519 | ehea_destroy_eq(port->qp_eq); | ||
2520 | return ret; | ||
2521 | } | ||
2522 | |||
2523 | static int ehea_clean_all_portres(struct ehea_port *port) | ||
2524 | { | ||
2525 | int ret = 0; | ||
2526 | int i; | ||
2527 | |||
2528 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) | ||
2529 | ret |= ehea_clean_portres(port, &port->port_res[i]); | ||
2530 | |||
2531 | ret |= ehea_destroy_eq(port->qp_eq); | ||
2532 | |||
2533 | return ret; | ||
2534 | } | ||
2535 | |||
2536 | static void ehea_remove_adapter_mr(struct ehea_adapter *adapter) | ||
2537 | { | ||
2538 | if (adapter->active_ports) | ||
2539 | return; | ||
2540 | |||
2541 | ehea_rem_mr(&adapter->mr); | ||
2542 | } | ||
2543 | |||
2544 | static int ehea_add_adapter_mr(struct ehea_adapter *adapter) | ||
2545 | { | ||
2546 | if (adapter->active_ports) | ||
2547 | return 0; | ||
2548 | |||
2549 | return ehea_reg_kernel_mr(adapter, &adapter->mr); | ||
2550 | } | ||
2551 | |||
2552 | static int ehea_up(struct net_device *dev) | ||
2553 | { | ||
2554 | int ret, i; | ||
2555 | struct ehea_port *port = netdev_priv(dev); | ||
2556 | |||
2557 | if (port->state == EHEA_PORT_UP) | ||
2558 | return 0; | ||
2559 | |||
2560 | ret = ehea_port_res_setup(port, port->num_def_qps, | ||
2561 | port->num_add_tx_qps); | ||
2562 | if (ret) { | ||
2563 | netdev_err(dev, "port_res_failed\n"); | ||
2564 | goto out; | ||
2565 | } | ||
2566 | |||
2567 | /* Set default QP for this port */ | ||
2568 | ret = ehea_configure_port(port); | ||
2569 | if (ret) { | ||
2570 | netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret); | ||
2571 | goto out_clean_pr; | ||
2572 | } | ||
2573 | |||
2574 | ret = ehea_reg_interrupts(dev); | ||
2575 | if (ret) { | ||
2576 | netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret); | ||
2577 | goto out_clean_pr; | ||
2578 | } | ||
2579 | |||
2580 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { | ||
2581 | ret = ehea_activate_qp(port->adapter, port->port_res[i].qp); | ||
2582 | if (ret) { | ||
2583 | netdev_err(dev, "activate_qp failed\n"); | ||
2584 | goto out_free_irqs; | ||
2585 | } | ||
2586 | } | ||
2587 | |||
2588 | for (i = 0; i < port->num_def_qps; i++) { | ||
2589 | ret = ehea_fill_port_res(&port->port_res[i]); | ||
2590 | if (ret) { | ||
2591 | netdev_err(dev, "out_free_irqs\n"); | ||
2592 | goto out_free_irqs; | ||
2593 | } | ||
2594 | } | ||
2595 | |||
2596 | ret = ehea_broadcast_reg_helper(port, H_REG_BCMC); | ||
2597 | if (ret) { | ||
2598 | ret = -EIO; | ||
2599 | goto out_free_irqs; | ||
2600 | } | ||
2601 | |||
2602 | port->state = EHEA_PORT_UP; | ||
2603 | |||
2604 | ret = 0; | ||
2605 | goto out; | ||
2606 | |||
2607 | out_free_irqs: | ||
2608 | ehea_free_interrupts(dev); | ||
2609 | |||
2610 | out_clean_pr: | ||
2611 | ehea_clean_all_portres(port); | ||
2612 | out: | ||
2613 | if (ret) | ||
2614 | netdev_info(dev, "Failed starting. ret=%i\n", ret); | ||
2615 | |||
2616 | ehea_update_bcmc_registrations(); | ||
2617 | ehea_update_firmware_handles(); | ||
2618 | |||
2619 | return ret; | ||
2620 | } | ||
2621 | |||
2622 | static void port_napi_disable(struct ehea_port *port) | ||
2623 | { | ||
2624 | int i; | ||
2625 | |||
2626 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) | ||
2627 | napi_disable(&port->port_res[i].napi); | ||
2628 | } | ||
2629 | |||
2630 | static void port_napi_enable(struct ehea_port *port) | ||
2631 | { | ||
2632 | int i; | ||
2633 | |||
2634 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) | ||
2635 | napi_enable(&port->port_res[i].napi); | ||
2636 | } | ||
2637 | |||
2638 | static int ehea_open(struct net_device *dev) | ||
2639 | { | ||
2640 | int ret; | ||
2641 | struct ehea_port *port = netdev_priv(dev); | ||
2642 | |||
2643 | mutex_lock(&port->port_lock); | ||
2644 | |||
2645 | netif_info(port, ifup, dev, "enabling port\n"); | ||
2646 | |||
2647 | ret = ehea_up(dev); | ||
2648 | if (!ret) { | ||
2649 | port_napi_enable(port); | ||
2650 | netif_start_queue(dev); | ||
2651 | } | ||
2652 | |||
2653 | mutex_unlock(&port->port_lock); | ||
2654 | |||
2655 | return ret; | ||
2656 | } | ||
2657 | |||
2658 | static int ehea_down(struct net_device *dev) | ||
2659 | { | ||
2660 | int ret; | ||
2661 | struct ehea_port *port = netdev_priv(dev); | ||
2662 | |||
2663 | if (port->state == EHEA_PORT_DOWN) | ||
2664 | return 0; | ||
2665 | |||
2666 | ehea_drop_multicast_list(dev); | ||
2667 | ehea_broadcast_reg_helper(port, H_DEREG_BCMC); | ||
2668 | |||
2669 | ehea_free_interrupts(dev); | ||
2670 | |||
2671 | port->state = EHEA_PORT_DOWN; | ||
2672 | |||
2673 | ehea_update_bcmc_registrations(); | ||
2674 | |||
2675 | ret = ehea_clean_all_portres(port); | ||
2676 | if (ret) | ||
2677 | netdev_info(dev, "Failed freeing resources. ret=%i\n", ret); | ||
2678 | |||
2679 | ehea_update_firmware_handles(); | ||
2680 | |||
2681 | return ret; | ||
2682 | } | ||
2683 | |||
2684 | static int ehea_stop(struct net_device *dev) | ||
2685 | { | ||
2686 | int ret; | ||
2687 | struct ehea_port *port = netdev_priv(dev); | ||
2688 | |||
2689 | netif_info(port, ifdown, dev, "disabling port\n"); | ||
2690 | |||
2691 | set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags); | ||
2692 | cancel_work_sync(&port->reset_task); | ||
2693 | mutex_lock(&port->port_lock); | ||
2694 | netif_stop_queue(dev); | ||
2695 | port_napi_disable(port); | ||
2696 | ret = ehea_down(dev); | ||
2697 | mutex_unlock(&port->port_lock); | ||
2698 | clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags); | ||
2699 | return ret; | ||
2700 | } | ||
2701 | |||
2702 | static void ehea_purge_sq(struct ehea_qp *orig_qp) | ||
2703 | { | ||
2704 | struct ehea_qp qp = *orig_qp; | ||
2705 | struct ehea_qp_init_attr *init_attr = &qp.init_attr; | ||
2706 | struct ehea_swqe *swqe; | ||
2707 | int wqe_index; | ||
2708 | int i; | ||
2709 | |||
2710 | for (i = 0; i < init_attr->act_nr_send_wqes; i++) { | ||
2711 | swqe = ehea_get_swqe(&qp, &wqe_index); | ||
2712 | swqe->tx_control |= EHEA_SWQE_PURGE; | ||
2713 | } | ||
2714 | } | ||
2715 | |||
2716 | static void ehea_flush_sq(struct ehea_port *port) | ||
2717 | { | ||
2718 | int i; | ||
2719 | |||
2720 | for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) { | ||
2721 | struct ehea_port_res *pr = &port->port_res[i]; | ||
2722 | int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count; | ||
2723 | int ret; | ||
2724 | |||
2725 | ret = wait_event_timeout(port->swqe_avail_wq, | ||
2726 | atomic_read(&pr->swqe_avail) >= swqe_max, | ||
2727 | msecs_to_jiffies(100)); | ||
2728 | |||
2729 | if (!ret) { | ||
2730 | pr_err("WARNING: sq not flushed completely\n"); | ||
2731 | break; | ||
2732 | } | ||
2733 | } | ||
2734 | } | ||
2735 | |||
2736 | int ehea_stop_qps(struct net_device *dev) | ||
2737 | { | ||
2738 | struct ehea_port *port = netdev_priv(dev); | ||
2739 | struct ehea_adapter *adapter = port->adapter; | ||
2740 | struct hcp_modify_qp_cb0 *cb0; | ||
2741 | int ret = -EIO; | ||
2742 | int dret; | ||
2743 | int i; | ||
2744 | u64 hret; | ||
2745 | u64 dummy64 = 0; | ||
2746 | u16 dummy16 = 0; | ||
2747 | |||
2748 | cb0 = (void *)get_zeroed_page(GFP_KERNEL); | ||
2749 | if (!cb0) { | ||
2750 | ret = -ENOMEM; | ||
2751 | goto out; | ||
2752 | } | ||
2753 | |||
2754 | for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) { | ||
2755 | struct ehea_port_res *pr = &port->port_res[i]; | ||
2756 | struct ehea_qp *qp = pr->qp; | ||
2757 | |||
2758 | /* Purge send queue */ | ||
2759 | ehea_purge_sq(qp); | ||
2760 | |||
2761 | /* Disable queue pair */ | ||
2762 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2763 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), | ||
2764 | cb0); | ||
2765 | if (hret != H_SUCCESS) { | ||
2766 | pr_err("query_ehea_qp failed (1)\n"); | ||
2767 | goto out; | ||
2768 | } | ||
2769 | |||
2770 | cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8; | ||
2771 | cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED; | ||
2772 | |||
2773 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2774 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, | ||
2775 | 1), cb0, &dummy64, | ||
2776 | &dummy64, &dummy16, &dummy16); | ||
2777 | if (hret != H_SUCCESS) { | ||
2778 | pr_err("modify_ehea_qp failed (1)\n"); | ||
2779 | goto out; | ||
2780 | } | ||
2781 | |||
2782 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2783 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), | ||
2784 | cb0); | ||
2785 | if (hret != H_SUCCESS) { | ||
2786 | pr_err("query_ehea_qp failed (2)\n"); | ||
2787 | goto out; | ||
2788 | } | ||
2789 | |||
2790 | /* deregister shared memory regions */ | ||
2791 | dret = ehea_rem_smrs(pr); | ||
2792 | if (dret) { | ||
2793 | pr_err("unreg shared memory region failed\n"); | ||
2794 | goto out; | ||
2795 | } | ||
2796 | } | ||
2797 | |||
2798 | ret = 0; | ||
2799 | out: | ||
2800 | free_page((unsigned long)cb0); | ||
2801 | |||
2802 | return ret; | ||
2803 | } | ||
2804 | |||
2805 | void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr) | ||
2806 | { | ||
2807 | struct ehea_qp qp = *orig_qp; | ||
2808 | struct ehea_qp_init_attr *init_attr = &qp.init_attr; | ||
2809 | struct ehea_rwqe *rwqe; | ||
2810 | struct sk_buff **skba_rq2 = pr->rq2_skba.arr; | ||
2811 | struct sk_buff **skba_rq3 = pr->rq3_skba.arr; | ||
2812 | struct sk_buff *skb; | ||
2813 | u32 lkey = pr->recv_mr.lkey; | ||
2814 | |||
2815 | |||
2816 | int i; | ||
2817 | int index; | ||
2818 | |||
2819 | for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) { | ||
2820 | rwqe = ehea_get_next_rwqe(&qp, 2); | ||
2821 | rwqe->sg_list[0].l_key = lkey; | ||
2822 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id); | ||
2823 | skb = skba_rq2[index]; | ||
2824 | if (skb) | ||
2825 | rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data); | ||
2826 | } | ||
2827 | |||
2828 | for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) { | ||
2829 | rwqe = ehea_get_next_rwqe(&qp, 3); | ||
2830 | rwqe->sg_list[0].l_key = lkey; | ||
2831 | index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id); | ||
2832 | skb = skba_rq3[index]; | ||
2833 | if (skb) | ||
2834 | rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data); | ||
2835 | } | ||
2836 | } | ||
2837 | |||
2838 | int ehea_restart_qps(struct net_device *dev) | ||
2839 | { | ||
2840 | struct ehea_port *port = netdev_priv(dev); | ||
2841 | struct ehea_adapter *adapter = port->adapter; | ||
2842 | int ret = 0; | ||
2843 | int i; | ||
2844 | |||
2845 | struct hcp_modify_qp_cb0 *cb0; | ||
2846 | u64 hret; | ||
2847 | u64 dummy64 = 0; | ||
2848 | u16 dummy16 = 0; | ||
2849 | |||
2850 | cb0 = (void *)get_zeroed_page(GFP_KERNEL); | ||
2851 | if (!cb0) { | ||
2852 | ret = -ENOMEM; | ||
2853 | goto out; | ||
2854 | } | ||
2855 | |||
2856 | for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) { | ||
2857 | struct ehea_port_res *pr = &port->port_res[i]; | ||
2858 | struct ehea_qp *qp = pr->qp; | ||
2859 | |||
2860 | ret = ehea_gen_smrs(pr); | ||
2861 | if (ret) { | ||
2862 | netdev_err(dev, "creation of shared memory regions failed\n"); | ||
2863 | goto out; | ||
2864 | } | ||
2865 | |||
2866 | ehea_update_rqs(qp, pr); | ||
2867 | |||
2868 | /* Enable queue pair */ | ||
2869 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2870 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), | ||
2871 | cb0); | ||
2872 | if (hret != H_SUCCESS) { | ||
2873 | netdev_err(dev, "query_ehea_qp failed (1)\n"); | ||
2874 | goto out; | ||
2875 | } | ||
2876 | |||
2877 | cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8; | ||
2878 | cb0->qp_ctl_reg |= H_QP_CR_ENABLED; | ||
2879 | |||
2880 | hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2881 | EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, | ||
2882 | 1), cb0, &dummy64, | ||
2883 | &dummy64, &dummy16, &dummy16); | ||
2884 | if (hret != H_SUCCESS) { | ||
2885 | netdev_err(dev, "modify_ehea_qp failed (1)\n"); | ||
2886 | goto out; | ||
2887 | } | ||
2888 | |||
2889 | hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle, | ||
2890 | EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), | ||
2891 | cb0); | ||
2892 | if (hret != H_SUCCESS) { | ||
2893 | netdev_err(dev, "query_ehea_qp failed (2)\n"); | ||
2894 | goto out; | ||
2895 | } | ||
2896 | |||
2897 | /* refill entire queue */ | ||
2898 | ehea_refill_rq1(pr, pr->rq1_skba.index, 0); | ||
2899 | ehea_refill_rq2(pr, 0); | ||
2900 | ehea_refill_rq3(pr, 0); | ||
2901 | } | ||
2902 | out: | ||
2903 | free_page((unsigned long)cb0); | ||
2904 | |||
2905 | return ret; | ||
2906 | } | ||
2907 | |||
2908 | static void ehea_reset_port(struct work_struct *work) | ||
2909 | { | ||
2910 | int ret; | ||
2911 | struct ehea_port *port = | ||
2912 | container_of(work, struct ehea_port, reset_task); | ||
2913 | struct net_device *dev = port->netdev; | ||
2914 | |||
2915 | mutex_lock(&dlpar_mem_lock); | ||
2916 | port->resets++; | ||
2917 | mutex_lock(&port->port_lock); | ||
2918 | netif_stop_queue(dev); | ||
2919 | |||
2920 | port_napi_disable(port); | ||
2921 | |||
2922 | ehea_down(dev); | ||
2923 | |||
2924 | ret = ehea_up(dev); | ||
2925 | if (ret) | ||
2926 | goto out; | ||
2927 | |||
2928 | ehea_set_multicast_list(dev); | ||
2929 | |||
2930 | netif_info(port, timer, dev, "reset successful\n"); | ||
2931 | |||
2932 | port_napi_enable(port); | ||
2933 | |||
2934 | netif_wake_queue(dev); | ||
2935 | out: | ||
2936 | mutex_unlock(&port->port_lock); | ||
2937 | mutex_unlock(&dlpar_mem_lock); | ||
2938 | } | ||
2939 | |||
2940 | static void ehea_rereg_mrs(void) | ||
2941 | { | ||
2942 | int ret, i; | ||
2943 | struct ehea_adapter *adapter; | ||
2944 | |||
2945 | pr_info("LPAR memory changed - re-initializing driver\n"); | ||
2946 | |||
2947 | list_for_each_entry(adapter, &adapter_list, list) | ||
2948 | if (adapter->active_ports) { | ||
2949 | /* Shutdown all ports */ | ||
2950 | for (i = 0; i < EHEA_MAX_PORTS; i++) { | ||
2951 | struct ehea_port *port = adapter->port[i]; | ||
2952 | struct net_device *dev; | ||
2953 | |||
2954 | if (!port) | ||
2955 | continue; | ||
2956 | |||
2957 | dev = port->netdev; | ||
2958 | |||
2959 | if (dev->flags & IFF_UP) { | ||
2960 | mutex_lock(&port->port_lock); | ||
2961 | netif_stop_queue(dev); | ||
2962 | ehea_flush_sq(port); | ||
2963 | ret = ehea_stop_qps(dev); | ||
2964 | if (ret) { | ||
2965 | mutex_unlock(&port->port_lock); | ||
2966 | goto out; | ||
2967 | } | ||
2968 | port_napi_disable(port); | ||
2969 | mutex_unlock(&port->port_lock); | ||
2970 | } | ||
2971 | reset_sq_restart_flag(port); | ||
2972 | } | ||
2973 | |||
2974 | /* Unregister old memory region */ | ||
2975 | ret = ehea_rem_mr(&adapter->mr); | ||
2976 | if (ret) { | ||
2977 | pr_err("unregister MR failed - driver inoperable!\n"); | ||
2978 | goto out; | ||
2979 | } | ||
2980 | } | ||
2981 | |||
2982 | clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags); | ||
2983 | |||
2984 | list_for_each_entry(adapter, &adapter_list, list) | ||
2985 | if (adapter->active_ports) { | ||
2986 | /* Register new memory region */ | ||
2987 | ret = ehea_reg_kernel_mr(adapter, &adapter->mr); | ||
2988 | if (ret) { | ||
2989 | pr_err("register MR failed - driver inoperable!\n"); | ||
2990 | goto out; | ||
2991 | } | ||
2992 | |||
2993 | /* Restart all ports */ | ||
2994 | for (i = 0; i < EHEA_MAX_PORTS; i++) { | ||
2995 | struct ehea_port *port = adapter->port[i]; | ||
2996 | |||
2997 | if (port) { | ||
2998 | struct net_device *dev = port->netdev; | ||
2999 | |||
3000 | if (dev->flags & IFF_UP) { | ||
3001 | mutex_lock(&port->port_lock); | ||
3002 | ret = ehea_restart_qps(dev); | ||
3003 | if (!ret) { | ||
3004 | check_sqs(port); | ||
3005 | port_napi_enable(port); | ||
3006 | netif_wake_queue(dev); | ||
3007 | } else { | ||
3008 | netdev_err(dev, "Unable to restart QPS\n"); | ||
3009 | } | ||
3010 | mutex_unlock(&port->port_lock); | ||
3011 | } | ||
3012 | } | ||
3013 | } | ||
3014 | } | ||
3015 | pr_info("re-initializing driver complete\n"); | ||
3016 | out: | ||
3017 | return; | ||
3018 | } | ||
3019 | |||
3020 | static void ehea_tx_watchdog(struct net_device *dev) | ||
3021 | { | ||
3022 | struct ehea_port *port = netdev_priv(dev); | ||
3023 | |||
3024 | if (netif_carrier_ok(dev) && | ||
3025 | !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags)) | ||
3026 | ehea_schedule_port_reset(port); | ||
3027 | } | ||
3028 | |||
3029 | int ehea_sense_adapter_attr(struct ehea_adapter *adapter) | ||
3030 | { | ||
3031 | struct hcp_query_ehea *cb; | ||
3032 | u64 hret; | ||
3033 | int ret; | ||
3034 | |||
3035 | cb = (void *)get_zeroed_page(GFP_KERNEL); | ||
3036 | if (!cb) { | ||
3037 | ret = -ENOMEM; | ||
3038 | goto out; | ||
3039 | } | ||
3040 | |||
3041 | hret = ehea_h_query_ehea(adapter->handle, cb); | ||
3042 | |||
3043 | if (hret != H_SUCCESS) { | ||
3044 | ret = -EIO; | ||
3045 | goto out_herr; | ||
3046 | } | ||
3047 | |||
3048 | adapter->max_mc_mac = cb->max_mc_mac - 1; | ||
3049 | ret = 0; | ||
3050 | |||
3051 | out_herr: | ||
3052 | free_page((unsigned long)cb); | ||
3053 | out: | ||
3054 | return ret; | ||
3055 | } | ||
3056 | |||
3057 | int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo) | ||
3058 | { | ||
3059 | struct hcp_ehea_port_cb4 *cb4; | ||
3060 | u64 hret; | ||
3061 | int ret = 0; | ||
3062 | |||
3063 | *jumbo = 0; | ||
3064 | |||
3065 | /* (Try to) enable *jumbo frames */ | ||
3066 | cb4 = (void *)get_zeroed_page(GFP_KERNEL); | ||
3067 | if (!cb4) { | ||
3068 | pr_err("no mem for cb4\n"); | ||
3069 | ret = -ENOMEM; | ||
3070 | goto out; | ||
3071 | } else { | ||
3072 | hret = ehea_h_query_ehea_port(port->adapter->handle, | ||
3073 | port->logical_port_id, | ||
3074 | H_PORT_CB4, | ||
3075 | H_PORT_CB4_JUMBO, cb4); | ||
3076 | if (hret == H_SUCCESS) { | ||
3077 | if (cb4->jumbo_frame) | ||
3078 | *jumbo = 1; | ||
3079 | else { | ||
3080 | cb4->jumbo_frame = 1; | ||
3081 | hret = ehea_h_modify_ehea_port(port->adapter-> | ||
3082 | handle, | ||
3083 | port-> | ||
3084 | logical_port_id, | ||
3085 | H_PORT_CB4, | ||
3086 | H_PORT_CB4_JUMBO, | ||
3087 | cb4); | ||
3088 | if (hret == H_SUCCESS) | ||
3089 | *jumbo = 1; | ||
3090 | } | ||
3091 | } else | ||
3092 | ret = -EINVAL; | ||
3093 | |||
3094 | free_page((unsigned long)cb4); | ||
3095 | } | ||
3096 | out: | ||
3097 | return ret; | ||
3098 | } | ||
3099 | |||
3100 | static ssize_t ehea_show_port_id(struct device *dev, | ||
3101 | struct device_attribute *attr, char *buf) | ||
3102 | { | ||
3103 | struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev); | ||
3104 | return sprintf(buf, "%d", port->logical_port_id); | ||
3105 | } | ||
3106 | |||
3107 | static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id, | ||
3108 | NULL); | ||
3109 | |||
3110 | static void __devinit logical_port_release(struct device *dev) | ||
3111 | { | ||
3112 | struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev); | ||
3113 | of_node_put(port->ofdev.dev.of_node); | ||
3114 | } | ||
3115 | |||
3116 | static struct device *ehea_register_port(struct ehea_port *port, | ||
3117 | struct device_node *dn) | ||
3118 | { | ||
3119 | int ret; | ||
3120 | |||
3121 | port->ofdev.dev.of_node = of_node_get(dn); | ||
3122 | port->ofdev.dev.parent = &port->adapter->ofdev->dev; | ||
3123 | port->ofdev.dev.bus = &ibmebus_bus_type; | ||
3124 | |||
3125 | dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++); | ||
3126 | port->ofdev.dev.release = logical_port_release; | ||
3127 | |||
3128 | ret = of_device_register(&port->ofdev); | ||
3129 | if (ret) { | ||
3130 | pr_err("failed to register device. ret=%d\n", ret); | ||
3131 | goto out; | ||
3132 | } | ||
3133 | |||
3134 | ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id); | ||
3135 | if (ret) { | ||
3136 | pr_err("failed to register attributes, ret=%d\n", ret); | ||
3137 | goto out_unreg_of_dev; | ||
3138 | } | ||
3139 | |||
3140 | return &port->ofdev.dev; | ||
3141 | |||
3142 | out_unreg_of_dev: | ||
3143 | of_device_unregister(&port->ofdev); | ||
3144 | out: | ||
3145 | return NULL; | ||
3146 | } | ||
3147 | |||
3148 | static void ehea_unregister_port(struct ehea_port *port) | ||
3149 | { | ||
3150 | device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id); | ||
3151 | of_device_unregister(&port->ofdev); | ||
3152 | } | ||
3153 | |||
3154 | static const struct net_device_ops ehea_netdev_ops = { | ||
3155 | .ndo_open = ehea_open, | ||
3156 | .ndo_stop = ehea_stop, | ||
3157 | .ndo_start_xmit = ehea_start_xmit, | ||
3158 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
3159 | .ndo_poll_controller = ehea_netpoll, | ||
3160 | #endif | ||
3161 | .ndo_get_stats = ehea_get_stats, | ||
3162 | .ndo_set_mac_address = ehea_set_mac_addr, | ||
3163 | .ndo_validate_addr = eth_validate_addr, | ||
3164 | .ndo_set_multicast_list = ehea_set_multicast_list, | ||
3165 | .ndo_change_mtu = ehea_change_mtu, | ||
3166 | .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid, | ||
3167 | .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid, | ||
3168 | .ndo_tx_timeout = ehea_tx_watchdog, | ||
3169 | }; | ||
3170 | |||
3171 | struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter, | ||
3172 | u32 logical_port_id, | ||
3173 | struct device_node *dn) | ||
3174 | { | ||
3175 | int ret; | ||
3176 | struct net_device *dev; | ||
3177 | struct ehea_port *port; | ||
3178 | struct device *port_dev; | ||
3179 | int jumbo; | ||
3180 | |||
3181 | /* allocate memory for the port structures */ | ||
3182 | dev = alloc_etherdev(sizeof(struct ehea_port)); | ||
3183 | |||
3184 | if (!dev) { | ||
3185 | pr_err("no mem for net_device\n"); | ||
3186 | ret = -ENOMEM; | ||
3187 | goto out_err; | ||
3188 | } | ||
3189 | |||
3190 | port = netdev_priv(dev); | ||
3191 | |||
3192 | mutex_init(&port->port_lock); | ||
3193 | port->state = EHEA_PORT_DOWN; | ||
3194 | port->sig_comp_iv = sq_entries / 10; | ||
3195 | |||
3196 | port->adapter = adapter; | ||
3197 | port->netdev = dev; | ||
3198 | port->logical_port_id = logical_port_id; | ||
3199 | |||
3200 | port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT); | ||
3201 | |||
3202 | port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL); | ||
3203 | if (!port->mc_list) { | ||
3204 | ret = -ENOMEM; | ||
3205 | goto out_free_ethdev; | ||
3206 | } | ||
3207 | |||
3208 | INIT_LIST_HEAD(&port->mc_list->list); | ||
3209 | |||
3210 | ret = ehea_sense_port_attr(port); | ||
3211 | if (ret) | ||
3212 | goto out_free_mc_list; | ||
3213 | |||
3214 | port_dev = ehea_register_port(port, dn); | ||
3215 | if (!port_dev) | ||
3216 | goto out_free_mc_list; | ||
3217 | |||
3218 | SET_NETDEV_DEV(dev, port_dev); | ||
3219 | |||
3220 | /* initialize net_device structure */ | ||
3221 | memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN); | ||
3222 | |||
3223 | dev->netdev_ops = &ehea_netdev_ops; | ||
3224 | ehea_set_ethtool_ops(dev); | ||
3225 | |||
3226 | dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO | ||
3227 | | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO; | ||
3228 | dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO | ||
3229 | | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | ||
3230 | | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER | ||
3231 | | NETIF_F_LLTX | NETIF_F_RXCSUM; | ||
3232 | dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT; | ||
3233 | |||
3234 | if (use_lro) | ||
3235 | dev->features |= NETIF_F_LRO; | ||
3236 | |||
3237 | INIT_WORK(&port->reset_task, ehea_reset_port); | ||
3238 | |||
3239 | init_waitqueue_head(&port->swqe_avail_wq); | ||
3240 | init_waitqueue_head(&port->restart_wq); | ||
3241 | |||
3242 | ret = register_netdev(dev); | ||
3243 | if (ret) { | ||
3244 | pr_err("register_netdev failed. ret=%d\n", ret); | ||
3245 | goto out_unreg_port; | ||
3246 | } | ||
3247 | |||
3248 | port->lro_max_aggr = lro_max_aggr; | ||
3249 | |||
3250 | ret = ehea_get_jumboframe_status(port, &jumbo); | ||
3251 | if (ret) | ||
3252 | netdev_err(dev, "failed determining jumbo frame status\n"); | ||
3253 | |||
3254 | netdev_info(dev, "Jumbo frames are %sabled\n", | ||
3255 | jumbo == 1 ? "en" : "dis"); | ||
3256 | |||
3257 | adapter->active_ports++; | ||
3258 | |||
3259 | return port; | ||
3260 | |||
3261 | out_unreg_port: | ||
3262 | ehea_unregister_port(port); | ||
3263 | |||
3264 | out_free_mc_list: | ||
3265 | kfree(port->mc_list); | ||
3266 | |||
3267 | out_free_ethdev: | ||
3268 | free_netdev(dev); | ||
3269 | |||
3270 | out_err: | ||
3271 | pr_err("setting up logical port with id=%d failed, ret=%d\n", | ||
3272 | logical_port_id, ret); | ||
3273 | return NULL; | ||
3274 | } | ||
3275 | |||
3276 | static void ehea_shutdown_single_port(struct ehea_port *port) | ||
3277 | { | ||
3278 | struct ehea_adapter *adapter = port->adapter; | ||
3279 | |||
3280 | cancel_work_sync(&port->reset_task); | ||
3281 | unregister_netdev(port->netdev); | ||
3282 | ehea_unregister_port(port); | ||
3283 | kfree(port->mc_list); | ||
3284 | free_netdev(port->netdev); | ||
3285 | adapter->active_ports--; | ||
3286 | } | ||
3287 | |||
3288 | static int ehea_setup_ports(struct ehea_adapter *adapter) | ||
3289 | { | ||
3290 | struct device_node *lhea_dn; | ||
3291 | struct device_node *eth_dn = NULL; | ||
3292 | |||
3293 | const u32 *dn_log_port_id; | ||
3294 | int i = 0; | ||
3295 | |||
3296 | lhea_dn = adapter->ofdev->dev.of_node; | ||
3297 | while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { | ||
3298 | |||
3299 | dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no", | ||
3300 | NULL); | ||
3301 | if (!dn_log_port_id) { | ||
3302 | pr_err("bad device node: eth_dn name=%s\n", | ||
3303 | eth_dn->full_name); | ||
3304 | continue; | ||
3305 | } | ||
3306 | |||
3307 | if (ehea_add_adapter_mr(adapter)) { | ||
3308 | pr_err("creating MR failed\n"); | ||
3309 | of_node_put(eth_dn); | ||
3310 | return -EIO; | ||
3311 | } | ||
3312 | |||
3313 | adapter->port[i] = ehea_setup_single_port(adapter, | ||
3314 | *dn_log_port_id, | ||
3315 | eth_dn); | ||
3316 | if (adapter->port[i]) | ||
3317 | netdev_info(adapter->port[i]->netdev, | ||
3318 | "logical port id #%d\n", *dn_log_port_id); | ||
3319 | else | ||
3320 | ehea_remove_adapter_mr(adapter); | ||
3321 | |||
3322 | i++; | ||
3323 | } | ||
3324 | return 0; | ||
3325 | } | ||
3326 | |||
3327 | static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter, | ||
3328 | u32 logical_port_id) | ||
3329 | { | ||
3330 | struct device_node *lhea_dn; | ||
3331 | struct device_node *eth_dn = NULL; | ||
3332 | const u32 *dn_log_port_id; | ||
3333 | |||
3334 | lhea_dn = adapter->ofdev->dev.of_node; | ||
3335 | while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { | ||
3336 | |||
3337 | dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no", | ||
3338 | NULL); | ||
3339 | if (dn_log_port_id) | ||
3340 | if (*dn_log_port_id == logical_port_id) | ||
3341 | return eth_dn; | ||
3342 | } | ||
3343 | |||
3344 | return NULL; | ||
3345 | } | ||
3346 | |||
3347 | static ssize_t ehea_probe_port(struct device *dev, | ||
3348 | struct device_attribute *attr, | ||
3349 | const char *buf, size_t count) | ||
3350 | { | ||
3351 | struct ehea_adapter *adapter = dev_get_drvdata(dev); | ||
3352 | struct ehea_port *port; | ||
3353 | struct device_node *eth_dn = NULL; | ||
3354 | int i; | ||
3355 | |||
3356 | u32 logical_port_id; | ||
3357 | |||
3358 | sscanf(buf, "%d", &logical_port_id); | ||
3359 | |||
3360 | port = ehea_get_port(adapter, logical_port_id); | ||
3361 | |||
3362 | if (port) { | ||
3363 | netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n", | ||
3364 | logical_port_id); | ||
3365 | return -EINVAL; | ||
3366 | } | ||
3367 | |||
3368 | eth_dn = ehea_get_eth_dn(adapter, logical_port_id); | ||
3369 | |||
3370 | if (!eth_dn) { | ||
3371 | pr_info("no logical port with id %d found\n", logical_port_id); | ||
3372 | return -EINVAL; | ||
3373 | } | ||
3374 | |||
3375 | if (ehea_add_adapter_mr(adapter)) { | ||
3376 | pr_err("creating MR failed\n"); | ||
3377 | return -EIO; | ||
3378 | } | ||
3379 | |||
3380 | port = ehea_setup_single_port(adapter, logical_port_id, eth_dn); | ||
3381 | |||
3382 | of_node_put(eth_dn); | ||
3383 | |||
3384 | if (port) { | ||
3385 | for (i = 0; i < EHEA_MAX_PORTS; i++) | ||
3386 | if (!adapter->port[i]) { | ||
3387 | adapter->port[i] = port; | ||
3388 | break; | ||
3389 | } | ||
3390 | |||
3391 | netdev_info(port->netdev, "added: (logical port id=%d)\n", | ||
3392 | logical_port_id); | ||
3393 | } else { | ||
3394 | ehea_remove_adapter_mr(adapter); | ||
3395 | return -EIO; | ||
3396 | } | ||
3397 | |||
3398 | return (ssize_t) count; | ||
3399 | } | ||
3400 | |||
3401 | static ssize_t ehea_remove_port(struct device *dev, | ||
3402 | struct device_attribute *attr, | ||
3403 | const char *buf, size_t count) | ||
3404 | { | ||
3405 | struct ehea_adapter *adapter = dev_get_drvdata(dev); | ||
3406 | struct ehea_port *port; | ||
3407 | int i; | ||
3408 | u32 logical_port_id; | ||
3409 | |||
3410 | sscanf(buf, "%d", &logical_port_id); | ||
3411 | |||
3412 | port = ehea_get_port(adapter, logical_port_id); | ||
3413 | |||
3414 | if (port) { | ||
3415 | netdev_info(port->netdev, "removed: (logical port id=%d)\n", | ||
3416 | logical_port_id); | ||
3417 | |||
3418 | ehea_shutdown_single_port(port); | ||
3419 | |||
3420 | for (i = 0; i < EHEA_MAX_PORTS; i++) | ||
3421 | if (adapter->port[i] == port) { | ||
3422 | adapter->port[i] = NULL; | ||
3423 | break; | ||
3424 | } | ||
3425 | } else { | ||
3426 | pr_err("removing port with logical port id=%d failed. port not configured.\n", | ||
3427 | logical_port_id); | ||
3428 | return -EINVAL; | ||
3429 | } | ||
3430 | |||
3431 | ehea_remove_adapter_mr(adapter); | ||
3432 | |||
3433 | return (ssize_t) count; | ||
3434 | } | ||
3435 | |||
3436 | static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port); | ||
3437 | static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port); | ||
3438 | |||
3439 | int ehea_create_device_sysfs(struct platform_device *dev) | ||
3440 | { | ||
3441 | int ret = device_create_file(&dev->dev, &dev_attr_probe_port); | ||
3442 | if (ret) | ||
3443 | goto out; | ||
3444 | |||
3445 | ret = device_create_file(&dev->dev, &dev_attr_remove_port); | ||
3446 | out: | ||
3447 | return ret; | ||
3448 | } | ||
3449 | |||
3450 | void ehea_remove_device_sysfs(struct platform_device *dev) | ||
3451 | { | ||
3452 | device_remove_file(&dev->dev, &dev_attr_probe_port); | ||
3453 | device_remove_file(&dev->dev, &dev_attr_remove_port); | ||
3454 | } | ||
3455 | |||
3456 | static int __devinit ehea_probe_adapter(struct platform_device *dev, | ||
3457 | const struct of_device_id *id) | ||
3458 | { | ||
3459 | struct ehea_adapter *adapter; | ||
3460 | const u64 *adapter_handle; | ||
3461 | int ret; | ||
3462 | |||
3463 | if (!dev || !dev->dev.of_node) { | ||
3464 | pr_err("Invalid ibmebus device probed\n"); | ||
3465 | return -EINVAL; | ||
3466 | } | ||
3467 | |||
3468 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); | ||
3469 | if (!adapter) { | ||
3470 | ret = -ENOMEM; | ||
3471 | dev_err(&dev->dev, "no mem for ehea_adapter\n"); | ||
3472 | goto out; | ||
3473 | } | ||
3474 | |||
3475 | list_add(&adapter->list, &adapter_list); | ||
3476 | |||
3477 | adapter->ofdev = dev; | ||
3478 | |||
3479 | adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle", | ||
3480 | NULL); | ||
3481 | if (adapter_handle) | ||
3482 | adapter->handle = *adapter_handle; | ||
3483 | |||
3484 | if (!adapter->handle) { | ||
3485 | dev_err(&dev->dev, "failed getting handle for adapter" | ||
3486 | " '%s'\n", dev->dev.of_node->full_name); | ||
3487 | ret = -ENODEV; | ||
3488 | goto out_free_ad; | ||
3489 | } | ||
3490 | |||
3491 | adapter->pd = EHEA_PD_ID; | ||
3492 | |||
3493 | dev_set_drvdata(&dev->dev, adapter); | ||
3494 | |||
3495 | |||
3496 | /* initialize adapter and ports */ | ||
3497 | /* get adapter properties */ | ||
3498 | ret = ehea_sense_adapter_attr(adapter); | ||
3499 | if (ret) { | ||
3500 | dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret); | ||
3501 | goto out_free_ad; | ||
3502 | } | ||
3503 | |||
3504 | adapter->neq = ehea_create_eq(adapter, | ||
3505 | EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1); | ||
3506 | if (!adapter->neq) { | ||
3507 | ret = -EIO; | ||
3508 | dev_err(&dev->dev, "NEQ creation failed\n"); | ||
3509 | goto out_free_ad; | ||
3510 | } | ||
3511 | |||
3512 | tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet, | ||
3513 | (unsigned long)adapter); | ||
3514 | |||
3515 | ret = ibmebus_request_irq(adapter->neq->attr.ist1, | ||
3516 | ehea_interrupt_neq, IRQF_DISABLED, | ||
3517 | "ehea_neq", adapter); | ||
3518 | if (ret) { | ||
3519 | dev_err(&dev->dev, "requesting NEQ IRQ failed\n"); | ||
3520 | goto out_kill_eq; | ||
3521 | } | ||
3522 | |||
3523 | ret = ehea_create_device_sysfs(dev); | ||
3524 | if (ret) | ||
3525 | goto out_free_irq; | ||
3526 | |||
3527 | ret = ehea_setup_ports(adapter); | ||
3528 | if (ret) { | ||
3529 | dev_err(&dev->dev, "setup_ports failed\n"); | ||
3530 | goto out_rem_dev_sysfs; | ||
3531 | } | ||
3532 | |||
3533 | ret = 0; | ||
3534 | goto out; | ||
3535 | |||
3536 | out_rem_dev_sysfs: | ||
3537 | ehea_remove_device_sysfs(dev); | ||
3538 | |||
3539 | out_free_irq: | ||
3540 | ibmebus_free_irq(adapter->neq->attr.ist1, adapter); | ||
3541 | |||
3542 | out_kill_eq: | ||
3543 | ehea_destroy_eq(adapter->neq); | ||
3544 | |||
3545 | out_free_ad: | ||
3546 | list_del(&adapter->list); | ||
3547 | kfree(adapter); | ||
3548 | |||
3549 | out: | ||
3550 | ehea_update_firmware_handles(); | ||
3551 | |||
3552 | return ret; | ||
3553 | } | ||
3554 | |||
3555 | static int __devexit ehea_remove(struct platform_device *dev) | ||
3556 | { | ||
3557 | struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev); | ||
3558 | int i; | ||
3559 | |||
3560 | for (i = 0; i < EHEA_MAX_PORTS; i++) | ||
3561 | if (adapter->port[i]) { | ||
3562 | ehea_shutdown_single_port(adapter->port[i]); | ||
3563 | adapter->port[i] = NULL; | ||
3564 | } | ||
3565 | |||
3566 | ehea_remove_device_sysfs(dev); | ||
3567 | |||
3568 | ibmebus_free_irq(adapter->neq->attr.ist1, adapter); | ||
3569 | tasklet_kill(&adapter->neq_tasklet); | ||
3570 | |||
3571 | ehea_destroy_eq(adapter->neq); | ||
3572 | ehea_remove_adapter_mr(adapter); | ||
3573 | list_del(&adapter->list); | ||
3574 | kfree(adapter); | ||
3575 | |||
3576 | ehea_update_firmware_handles(); | ||
3577 | |||
3578 | return 0; | ||
3579 | } | ||
3580 | |||
3581 | void ehea_crash_handler(void) | ||
3582 | { | ||
3583 | int i; | ||
3584 | |||
3585 | if (ehea_fw_handles.arr) | ||
3586 | for (i = 0; i < ehea_fw_handles.num_entries; i++) | ||
3587 | ehea_h_free_resource(ehea_fw_handles.arr[i].adh, | ||
3588 | ehea_fw_handles.arr[i].fwh, | ||
3589 | FORCE_FREE); | ||
3590 | |||
3591 | if (ehea_bcmc_regs.arr) | ||
3592 | for (i = 0; i < ehea_bcmc_regs.num_entries; i++) | ||
3593 | ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh, | ||
3594 | ehea_bcmc_regs.arr[i].port_id, | ||
3595 | ehea_bcmc_regs.arr[i].reg_type, | ||
3596 | ehea_bcmc_regs.arr[i].macaddr, | ||
3597 | 0, H_DEREG_BCMC); | ||
3598 | } | ||
3599 | |||
3600 | static int ehea_mem_notifier(struct notifier_block *nb, | ||
3601 | unsigned long action, void *data) | ||
3602 | { | ||
3603 | int ret = NOTIFY_BAD; | ||
3604 | struct memory_notify *arg = data; | ||
3605 | |||
3606 | mutex_lock(&dlpar_mem_lock); | ||
3607 | |||
3608 | switch (action) { | ||
3609 | case MEM_CANCEL_OFFLINE: | ||
3610 | pr_info("memory offlining canceled"); | ||
3611 | /* Readd canceled memory block */ | ||
3612 | case MEM_ONLINE: | ||
3613 | pr_info("memory is going online"); | ||
3614 | set_bit(__EHEA_STOP_XFER, &ehea_driver_flags); | ||
3615 | if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages)) | ||
3616 | goto out_unlock; | ||
3617 | ehea_rereg_mrs(); | ||
3618 | break; | ||
3619 | case MEM_GOING_OFFLINE: | ||
3620 | pr_info("memory is going offline"); | ||
3621 | set_bit(__EHEA_STOP_XFER, &ehea_driver_flags); | ||
3622 | if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages)) | ||
3623 | goto out_unlock; | ||
3624 | ehea_rereg_mrs(); | ||
3625 | break; | ||
3626 | default: | ||
3627 | break; | ||
3628 | } | ||
3629 | |||
3630 | ehea_update_firmware_handles(); | ||
3631 | ret = NOTIFY_OK; | ||
3632 | |||
3633 | out_unlock: | ||
3634 | mutex_unlock(&dlpar_mem_lock); | ||
3635 | return ret; | ||
3636 | } | ||
3637 | |||
3638 | static struct notifier_block ehea_mem_nb = { | ||
3639 | .notifier_call = ehea_mem_notifier, | ||
3640 | }; | ||
3641 | |||
3642 | static int ehea_reboot_notifier(struct notifier_block *nb, | ||
3643 | unsigned long action, void *unused) | ||
3644 | { | ||
3645 | if (action == SYS_RESTART) { | ||
3646 | pr_info("Reboot: freeing all eHEA resources\n"); | ||
3647 | ibmebus_unregister_driver(&ehea_driver); | ||
3648 | } | ||
3649 | return NOTIFY_DONE; | ||
3650 | } | ||
3651 | |||
3652 | static struct notifier_block ehea_reboot_nb = { | ||
3653 | .notifier_call = ehea_reboot_notifier, | ||
3654 | }; | ||
3655 | |||
3656 | static int check_module_parm(void) | ||
3657 | { | ||
3658 | int ret = 0; | ||
3659 | |||
3660 | if ((rq1_entries < EHEA_MIN_ENTRIES_QP) || | ||
3661 | (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) { | ||
3662 | pr_info("Bad parameter: rq1_entries\n"); | ||
3663 | ret = -EINVAL; | ||
3664 | } | ||
3665 | if ((rq2_entries < EHEA_MIN_ENTRIES_QP) || | ||
3666 | (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) { | ||
3667 | pr_info("Bad parameter: rq2_entries\n"); | ||
3668 | ret = -EINVAL; | ||
3669 | } | ||
3670 | if ((rq3_entries < EHEA_MIN_ENTRIES_QP) || | ||
3671 | (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) { | ||
3672 | pr_info("Bad parameter: rq3_entries\n"); | ||
3673 | ret = -EINVAL; | ||
3674 | } | ||
3675 | if ((sq_entries < EHEA_MIN_ENTRIES_QP) || | ||
3676 | (sq_entries > EHEA_MAX_ENTRIES_SQ)) { | ||
3677 | pr_info("Bad parameter: sq_entries\n"); | ||
3678 | ret = -EINVAL; | ||
3679 | } | ||
3680 | |||
3681 | return ret; | ||
3682 | } | ||
3683 | |||
3684 | static ssize_t ehea_show_capabilities(struct device_driver *drv, | ||
3685 | char *buf) | ||
3686 | { | ||
3687 | return sprintf(buf, "%d", EHEA_CAPABILITIES); | ||
3688 | } | ||
3689 | |||
3690 | static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH, | ||
3691 | ehea_show_capabilities, NULL); | ||
3692 | |||
3693 | int __init ehea_module_init(void) | ||
3694 | { | ||
3695 | int ret; | ||
3696 | |||
3697 | pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION); | ||
3698 | |||
3699 | memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles)); | ||
3700 | memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs)); | ||
3701 | |||
3702 | mutex_init(&ehea_fw_handles.lock); | ||
3703 | spin_lock_init(&ehea_bcmc_regs.lock); | ||
3704 | |||
3705 | ret = check_module_parm(); | ||
3706 | if (ret) | ||
3707 | goto out; | ||
3708 | |||
3709 | ret = ehea_create_busmap(); | ||
3710 | if (ret) | ||
3711 | goto out; | ||
3712 | |||
3713 | ret = register_reboot_notifier(&ehea_reboot_nb); | ||
3714 | if (ret) | ||
3715 | pr_info("failed registering reboot notifier\n"); | ||
3716 | |||
3717 | ret = register_memory_notifier(&ehea_mem_nb); | ||
3718 | if (ret) | ||
3719 | pr_info("failed registering memory remove notifier\n"); | ||
3720 | |||
3721 | ret = crash_shutdown_register(ehea_crash_handler); | ||
3722 | if (ret) | ||
3723 | pr_info("failed registering crash handler\n"); | ||
3724 | |||
3725 | ret = ibmebus_register_driver(&ehea_driver); | ||
3726 | if (ret) { | ||
3727 | pr_err("failed registering eHEA device driver on ebus\n"); | ||
3728 | goto out2; | ||
3729 | } | ||
3730 | |||
3731 | ret = driver_create_file(&ehea_driver.driver, | ||
3732 | &driver_attr_capabilities); | ||
3733 | if (ret) { | ||
3734 | pr_err("failed to register capabilities attribute, ret=%d\n", | ||
3735 | ret); | ||
3736 | goto out3; | ||
3737 | } | ||
3738 | |||
3739 | return ret; | ||
3740 | |||
3741 | out3: | ||
3742 | ibmebus_unregister_driver(&ehea_driver); | ||
3743 | out2: | ||
3744 | unregister_memory_notifier(&ehea_mem_nb); | ||
3745 | unregister_reboot_notifier(&ehea_reboot_nb); | ||
3746 | crash_shutdown_unregister(ehea_crash_handler); | ||
3747 | out: | ||
3748 | return ret; | ||
3749 | } | ||
3750 | |||
3751 | static void __exit ehea_module_exit(void) | ||
3752 | { | ||
3753 | int ret; | ||
3754 | |||
3755 | driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities); | ||
3756 | ibmebus_unregister_driver(&ehea_driver); | ||
3757 | unregister_reboot_notifier(&ehea_reboot_nb); | ||
3758 | ret = crash_shutdown_unregister(ehea_crash_handler); | ||
3759 | if (ret) | ||
3760 | pr_info("failed unregistering crash handler\n"); | ||
3761 | unregister_memory_notifier(&ehea_mem_nb); | ||
3762 | kfree(ehea_fw_handles.arr); | ||
3763 | kfree(ehea_bcmc_regs.arr); | ||
3764 | ehea_destroy_busmap(); | ||
3765 | } | ||
3766 | |||
3767 | module_init(ehea_module_init); | ||
3768 | module_exit(ehea_module_exit); | ||
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_phyp.c b/drivers/net/ethernet/ibm/ehea/ehea_phyp.c new file mode 100644 index 000000000000..0506967b9044 --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/ehea_phyp.c | |||
@@ -0,0 +1,626 @@ | |||
1 | /* | ||
2 | * linux/drivers/net/ehea/ehea_phyp.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 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
30 | |||
31 | #include "ehea_phyp.h" | ||
32 | |||
33 | |||
34 | static inline u16 get_order_of_qentries(u16 queue_entries) | ||
35 | { | ||
36 | u8 ld = 1; /* logarithmus dualis */ | ||
37 | while (((1U << ld) - 1) < queue_entries) | ||
38 | ld++; | ||
39 | return ld - 1; | ||
40 | } | ||
41 | |||
42 | /* Defines for H_CALL H_ALLOC_RESOURCE */ | ||
43 | #define H_ALL_RES_TYPE_QP 1 | ||
44 | #define H_ALL_RES_TYPE_CQ 2 | ||
45 | #define H_ALL_RES_TYPE_EQ 3 | ||
46 | #define H_ALL_RES_TYPE_MR 5 | ||
47 | #define H_ALL_RES_TYPE_MW 6 | ||
48 | |||
49 | static long ehea_plpar_hcall_norets(unsigned long opcode, | ||
50 | unsigned long arg1, | ||
51 | unsigned long arg2, | ||
52 | unsigned long arg3, | ||
53 | unsigned long arg4, | ||
54 | unsigned long arg5, | ||
55 | unsigned long arg6, | ||
56 | unsigned long arg7) | ||
57 | { | ||
58 | long ret; | ||
59 | int i, sleep_msecs; | ||
60 | |||
61 | for (i = 0; i < 5; i++) { | ||
62 | ret = plpar_hcall_norets(opcode, arg1, arg2, arg3, arg4, | ||
63 | arg5, arg6, arg7); | ||
64 | |||
65 | if (H_IS_LONG_BUSY(ret)) { | ||
66 | sleep_msecs = get_longbusy_msecs(ret); | ||
67 | msleep_interruptible(sleep_msecs); | ||
68 | continue; | ||
69 | } | ||
70 | |||
71 | if (ret < H_SUCCESS) | ||
72 | pr_err("opcode=%lx ret=%lx" | ||
73 | " arg1=%lx arg2=%lx arg3=%lx arg4=%lx" | ||
74 | " arg5=%lx arg6=%lx arg7=%lx\n", | ||
75 | opcode, ret, | ||
76 | arg1, arg2, arg3, arg4, arg5, arg6, arg7); | ||
77 | |||
78 | return ret; | ||
79 | } | ||
80 | |||
81 | return H_BUSY; | ||
82 | } | ||
83 | |||
84 | static long ehea_plpar_hcall9(unsigned long opcode, | ||
85 | unsigned long *outs, /* array of 9 outputs */ | ||
86 | unsigned long arg1, | ||
87 | unsigned long arg2, | ||
88 | unsigned long arg3, | ||
89 | unsigned long arg4, | ||
90 | unsigned long arg5, | ||
91 | unsigned long arg6, | ||
92 | unsigned long arg7, | ||
93 | unsigned long arg8, | ||
94 | unsigned long arg9) | ||
95 | { | ||
96 | long ret; | ||
97 | int i, sleep_msecs; | ||
98 | u8 cb_cat; | ||
99 | |||
100 | for (i = 0; i < 5; i++) { | ||
101 | ret = plpar_hcall9(opcode, outs, | ||
102 | arg1, arg2, arg3, arg4, arg5, | ||
103 | arg6, arg7, arg8, arg9); | ||
104 | |||
105 | if (H_IS_LONG_BUSY(ret)) { | ||
106 | sleep_msecs = get_longbusy_msecs(ret); | ||
107 | msleep_interruptible(sleep_msecs); | ||
108 | continue; | ||
109 | } | ||
110 | |||
111 | cb_cat = EHEA_BMASK_GET(H_MEHEAPORT_CAT, arg2); | ||
112 | |||
113 | if ((ret < H_SUCCESS) && !(((ret == H_AUTHORITY) | ||
114 | && (opcode == H_MODIFY_HEA_PORT)) | ||
115 | && (((cb_cat == H_PORT_CB4) && ((arg3 == H_PORT_CB4_JUMBO) | ||
116 | || (arg3 == H_PORT_CB4_SPEED))) || ((cb_cat == H_PORT_CB7) | ||
117 | && (arg3 == H_PORT_CB7_DUCQPN))))) | ||
118 | pr_err("opcode=%lx ret=%lx" | ||
119 | " arg1=%lx arg2=%lx arg3=%lx arg4=%lx" | ||
120 | " arg5=%lx arg6=%lx arg7=%lx arg8=%lx" | ||
121 | " arg9=%lx" | ||
122 | " out1=%lx out2=%lx out3=%lx out4=%lx" | ||
123 | " out5=%lx out6=%lx out7=%lx out8=%lx" | ||
124 | " out9=%lx\n", | ||
125 | opcode, ret, | ||
126 | arg1, arg2, arg3, arg4, arg5, | ||
127 | arg6, arg7, arg8, arg9, | ||
128 | outs[0], outs[1], outs[2], outs[3], outs[4], | ||
129 | outs[5], outs[6], outs[7], outs[8]); | ||
130 | return ret; | ||
131 | } | ||
132 | |||
133 | return H_BUSY; | ||
134 | } | ||
135 | |||
136 | u64 ehea_h_query_ehea_qp(const u64 adapter_handle, const u8 qp_category, | ||
137 | const u64 qp_handle, const u64 sel_mask, void *cb_addr) | ||
138 | { | ||
139 | return ehea_plpar_hcall_norets(H_QUERY_HEA_QP, | ||
140 | adapter_handle, /* R4 */ | ||
141 | qp_category, /* R5 */ | ||
142 | qp_handle, /* R6 */ | ||
143 | sel_mask, /* R7 */ | ||
144 | virt_to_abs(cb_addr), /* R8 */ | ||
145 | 0, 0); | ||
146 | } | ||
147 | |||
148 | /* input param R5 */ | ||
149 | #define H_ALL_RES_QP_EQPO EHEA_BMASK_IBM(9, 11) | ||
150 | #define H_ALL_RES_QP_QPP EHEA_BMASK_IBM(12, 12) | ||
151 | #define H_ALL_RES_QP_RQR EHEA_BMASK_IBM(13, 15) | ||
152 | #define H_ALL_RES_QP_EQEG EHEA_BMASK_IBM(16, 16) | ||
153 | #define H_ALL_RES_QP_LL_QP EHEA_BMASK_IBM(17, 17) | ||
154 | #define H_ALL_RES_QP_DMA128 EHEA_BMASK_IBM(19, 19) | ||
155 | #define H_ALL_RES_QP_HSM EHEA_BMASK_IBM(20, 21) | ||
156 | #define H_ALL_RES_QP_SIGT EHEA_BMASK_IBM(22, 23) | ||
157 | #define H_ALL_RES_QP_TENURE EHEA_BMASK_IBM(48, 55) | ||
158 | #define H_ALL_RES_QP_RES_TYP EHEA_BMASK_IBM(56, 63) | ||
159 | |||
160 | /* input param R9 */ | ||
161 | #define H_ALL_RES_QP_TOKEN EHEA_BMASK_IBM(0, 31) | ||
162 | #define H_ALL_RES_QP_PD EHEA_BMASK_IBM(32, 63) | ||
163 | |||
164 | /* input param R10 */ | ||
165 | #define H_ALL_RES_QP_MAX_SWQE EHEA_BMASK_IBM(4, 7) | ||
166 | #define H_ALL_RES_QP_MAX_R1WQE EHEA_BMASK_IBM(12, 15) | ||
167 | #define H_ALL_RES_QP_MAX_R2WQE EHEA_BMASK_IBM(20, 23) | ||
168 | #define H_ALL_RES_QP_MAX_R3WQE EHEA_BMASK_IBM(28, 31) | ||
169 | /* Max Send Scatter Gather Elements */ | ||
170 | #define H_ALL_RES_QP_MAX_SSGE EHEA_BMASK_IBM(37, 39) | ||
171 | #define H_ALL_RES_QP_MAX_R1SGE EHEA_BMASK_IBM(45, 47) | ||
172 | /* Max Receive SG Elements RQ1 */ | ||
173 | #define H_ALL_RES_QP_MAX_R2SGE EHEA_BMASK_IBM(53, 55) | ||
174 | #define H_ALL_RES_QP_MAX_R3SGE EHEA_BMASK_IBM(61, 63) | ||
175 | |||
176 | /* input param R11 */ | ||
177 | #define H_ALL_RES_QP_SWQE_IDL EHEA_BMASK_IBM(0, 7) | ||
178 | /* max swqe immediate data length */ | ||
179 | #define H_ALL_RES_QP_PORT_NUM EHEA_BMASK_IBM(48, 63) | ||
180 | |||
181 | /* input param R12 */ | ||
182 | #define H_ALL_RES_QP_TH_RQ2 EHEA_BMASK_IBM(0, 15) | ||
183 | /* Threshold RQ2 */ | ||
184 | #define H_ALL_RES_QP_TH_RQ3 EHEA_BMASK_IBM(16, 31) | ||
185 | /* Threshold RQ3 */ | ||
186 | |||
187 | /* output param R6 */ | ||
188 | #define H_ALL_RES_QP_ACT_SWQE EHEA_BMASK_IBM(0, 15) | ||
189 | #define H_ALL_RES_QP_ACT_R1WQE EHEA_BMASK_IBM(16, 31) | ||
190 | #define H_ALL_RES_QP_ACT_R2WQE EHEA_BMASK_IBM(32, 47) | ||
191 | #define H_ALL_RES_QP_ACT_R3WQE EHEA_BMASK_IBM(48, 63) | ||
192 | |||
193 | /* output param, R7 */ | ||
194 | #define H_ALL_RES_QP_ACT_SSGE EHEA_BMASK_IBM(0, 7) | ||
195 | #define H_ALL_RES_QP_ACT_R1SGE EHEA_BMASK_IBM(8, 15) | ||
196 | #define H_ALL_RES_QP_ACT_R2SGE EHEA_BMASK_IBM(16, 23) | ||
197 | #define H_ALL_RES_QP_ACT_R3SGE EHEA_BMASK_IBM(24, 31) | ||
198 | #define H_ALL_RES_QP_ACT_SWQE_IDL EHEA_BMASK_IBM(32, 39) | ||
199 | |||
200 | /* output param R8,R9 */ | ||
201 | #define H_ALL_RES_QP_SIZE_SQ EHEA_BMASK_IBM(0, 31) | ||
202 | #define H_ALL_RES_QP_SIZE_RQ1 EHEA_BMASK_IBM(32, 63) | ||
203 | #define H_ALL_RES_QP_SIZE_RQ2 EHEA_BMASK_IBM(0, 31) | ||
204 | #define H_ALL_RES_QP_SIZE_RQ3 EHEA_BMASK_IBM(32, 63) | ||
205 | |||
206 | /* output param R11,R12 */ | ||
207 | #define H_ALL_RES_QP_LIOBN_SQ EHEA_BMASK_IBM(0, 31) | ||
208 | #define H_ALL_RES_QP_LIOBN_RQ1 EHEA_BMASK_IBM(32, 63) | ||
209 | #define H_ALL_RES_QP_LIOBN_RQ2 EHEA_BMASK_IBM(0, 31) | ||
210 | #define H_ALL_RES_QP_LIOBN_RQ3 EHEA_BMASK_IBM(32, 63) | ||
211 | |||
212 | u64 ehea_h_alloc_resource_qp(const u64 adapter_handle, | ||
213 | struct ehea_qp_init_attr *init_attr, const u32 pd, | ||
214 | u64 *qp_handle, struct h_epas *h_epas) | ||
215 | { | ||
216 | u64 hret; | ||
217 | unsigned long outs[PLPAR_HCALL9_BUFSIZE]; | ||
218 | |||
219 | u64 allocate_controls = | ||
220 | EHEA_BMASK_SET(H_ALL_RES_QP_EQPO, init_attr->low_lat_rq1 ? 1 : 0) | ||
221 | | EHEA_BMASK_SET(H_ALL_RES_QP_QPP, 0) | ||
222 | | EHEA_BMASK_SET(H_ALL_RES_QP_RQR, 6) /* rq1 & rq2 & rq3 */ | ||
223 | | EHEA_BMASK_SET(H_ALL_RES_QP_EQEG, 0) /* EQE gen. disabled */ | ||
224 | | EHEA_BMASK_SET(H_ALL_RES_QP_LL_QP, init_attr->low_lat_rq1) | ||
225 | | EHEA_BMASK_SET(H_ALL_RES_QP_DMA128, 0) | ||
226 | | EHEA_BMASK_SET(H_ALL_RES_QP_HSM, 0) | ||
227 | | EHEA_BMASK_SET(H_ALL_RES_QP_SIGT, init_attr->signalingtype) | ||
228 | | EHEA_BMASK_SET(H_ALL_RES_QP_RES_TYP, H_ALL_RES_TYPE_QP); | ||
229 | |||
230 | u64 r9_reg = EHEA_BMASK_SET(H_ALL_RES_QP_PD, pd) | ||
231 | | EHEA_BMASK_SET(H_ALL_RES_QP_TOKEN, init_attr->qp_token); | ||
232 | |||
233 | u64 max_r10_reg = | ||
234 | EHEA_BMASK_SET(H_ALL_RES_QP_MAX_SWQE, | ||
235 | get_order_of_qentries(init_attr->max_nr_send_wqes)) | ||
236 | | EHEA_BMASK_SET(H_ALL_RES_QP_MAX_R1WQE, | ||
237 | get_order_of_qentries(init_attr->max_nr_rwqes_rq1)) | ||
238 | | EHEA_BMASK_SET(H_ALL_RES_QP_MAX_R2WQE, | ||
239 | get_order_of_qentries(init_attr->max_nr_rwqes_rq2)) | ||
240 | | EHEA_BMASK_SET(H_ALL_RES_QP_MAX_R3WQE, | ||
241 | get_order_of_qentries(init_attr->max_nr_rwqes_rq3)) | ||
242 | | EHEA_BMASK_SET(H_ALL_RES_QP_MAX_SSGE, init_attr->wqe_size_enc_sq) | ||
243 | | EHEA_BMASK_SET(H_ALL_RES_QP_MAX_R1SGE, | ||
244 | init_attr->wqe_size_enc_rq1) | ||
245 | | EHEA_BMASK_SET(H_ALL_RES_QP_MAX_R2SGE, | ||
246 | init_attr->wqe_size_enc_rq2) | ||
247 | | EHEA_BMASK_SET(H_ALL_RES_QP_MAX_R3SGE, | ||
248 | init_attr->wqe_size_enc_rq3); | ||
249 | |||
250 | u64 r11_in = | ||
251 | EHEA_BMASK_SET(H_ALL_RES_QP_SWQE_IDL, init_attr->swqe_imm_data_len) | ||
252 | | EHEA_BMASK_SET(H_ALL_RES_QP_PORT_NUM, init_attr->port_nr); | ||
253 | u64 threshold = | ||
254 | EHEA_BMASK_SET(H_ALL_RES_QP_TH_RQ2, init_attr->rq2_threshold) | ||
255 | | EHEA_BMASK_SET(H_ALL_RES_QP_TH_RQ3, init_attr->rq3_threshold); | ||
256 | |||
257 | hret = ehea_plpar_hcall9(H_ALLOC_HEA_RESOURCE, | ||
258 | outs, | ||
259 | adapter_handle, /* R4 */ | ||
260 | allocate_controls, /* R5 */ | ||
261 | init_attr->send_cq_handle, /* R6 */ | ||
262 | init_attr->recv_cq_handle, /* R7 */ | ||
263 | init_attr->aff_eq_handle, /* R8 */ | ||
264 | r9_reg, /* R9 */ | ||
265 | max_r10_reg, /* R10 */ | ||
266 | r11_in, /* R11 */ | ||
267 | threshold); /* R12 */ | ||
268 | |||
269 | *qp_handle = outs[0]; | ||
270 | init_attr->qp_nr = (u32)outs[1]; | ||
271 | |||
272 | init_attr->act_nr_send_wqes = | ||
273 | (u16)EHEA_BMASK_GET(H_ALL_RES_QP_ACT_SWQE, outs[2]); | ||
274 | init_attr->act_nr_rwqes_rq1 = | ||
275 | (u16)EHEA_BMASK_GET(H_ALL_RES_QP_ACT_R1WQE, outs[2]); | ||
276 | init_attr->act_nr_rwqes_rq2 = | ||
277 | (u16)EHEA_BMASK_GET(H_ALL_RES_QP_ACT_R2WQE, outs[2]); | ||
278 | init_attr->act_nr_rwqes_rq3 = | ||
279 | (u16)EHEA_BMASK_GET(H_ALL_RES_QP_ACT_R3WQE, outs[2]); | ||
280 | |||
281 | init_attr->act_wqe_size_enc_sq = init_attr->wqe_size_enc_sq; | ||
282 | init_attr->act_wqe_size_enc_rq1 = init_attr->wqe_size_enc_rq1; | ||
283 | init_attr->act_wqe_size_enc_rq2 = init_attr->wqe_size_enc_rq2; | ||
284 | init_attr->act_wqe_size_enc_rq3 = init_attr->wqe_size_enc_rq3; | ||
285 | |||
286 | init_attr->nr_sq_pages = | ||
287 | (u32)EHEA_BMASK_GET(H_ALL_RES_QP_SIZE_SQ, outs[4]); | ||
288 | init_attr->nr_rq1_pages = | ||
289 | (u32)EHEA_BMASK_GET(H_ALL_RES_QP_SIZE_RQ1, outs[4]); | ||
290 | init_attr->nr_rq2_pages = | ||
291 | (u32)EHEA_BMASK_GET(H_ALL_RES_QP_SIZE_RQ2, outs[5]); | ||
292 | init_attr->nr_rq3_pages = | ||
293 | (u32)EHEA_BMASK_GET(H_ALL_RES_QP_SIZE_RQ3, outs[5]); | ||
294 | |||
295 | init_attr->liobn_sq = | ||
296 | (u32)EHEA_BMASK_GET(H_ALL_RES_QP_LIOBN_SQ, outs[7]); | ||
297 | init_attr->liobn_rq1 = | ||
298 | (u32)EHEA_BMASK_GET(H_ALL_RES_QP_LIOBN_RQ1, outs[7]); | ||
299 | init_attr->liobn_rq2 = | ||
300 | (u32)EHEA_BMASK_GET(H_ALL_RES_QP_LIOBN_RQ2, outs[8]); | ||
301 | init_attr->liobn_rq3 = | ||
302 | (u32)EHEA_BMASK_GET(H_ALL_RES_QP_LIOBN_RQ3, outs[8]); | ||
303 | |||
304 | if (!hret) | ||
305 | hcp_epas_ctor(h_epas, outs[6], outs[6]); | ||
306 | |||
307 | return hret; | ||
308 | } | ||
309 | |||
310 | u64 ehea_h_alloc_resource_cq(const u64 adapter_handle, | ||
311 | struct ehea_cq_attr *cq_attr, | ||
312 | u64 *cq_handle, struct h_epas *epas) | ||
313 | { | ||
314 | u64 hret; | ||
315 | unsigned long outs[PLPAR_HCALL9_BUFSIZE]; | ||
316 | |||
317 | hret = ehea_plpar_hcall9(H_ALLOC_HEA_RESOURCE, | ||
318 | outs, | ||
319 | adapter_handle, /* R4 */ | ||
320 | H_ALL_RES_TYPE_CQ, /* R5 */ | ||
321 | cq_attr->eq_handle, /* R6 */ | ||
322 | cq_attr->cq_token, /* R7 */ | ||
323 | cq_attr->max_nr_of_cqes, /* R8 */ | ||
324 | 0, 0, 0, 0); /* R9-R12 */ | ||
325 | |||
326 | *cq_handle = outs[0]; | ||
327 | cq_attr->act_nr_of_cqes = outs[3]; | ||
328 | cq_attr->nr_pages = outs[4]; | ||
329 | |||
330 | if (!hret) | ||
331 | hcp_epas_ctor(epas, outs[5], outs[6]); | ||
332 | |||
333 | return hret; | ||
334 | } | ||
335 | |||
336 | /* Defines for H_CALL H_ALLOC_RESOURCE */ | ||
337 | #define H_ALL_RES_TYPE_QP 1 | ||
338 | #define H_ALL_RES_TYPE_CQ 2 | ||
339 | #define H_ALL_RES_TYPE_EQ 3 | ||
340 | #define H_ALL_RES_TYPE_MR 5 | ||
341 | #define H_ALL_RES_TYPE_MW 6 | ||
342 | |||
343 | /* input param R5 */ | ||
344 | #define H_ALL_RES_EQ_NEQ EHEA_BMASK_IBM(0, 0) | ||
345 | #define H_ALL_RES_EQ_NON_NEQ_ISN EHEA_BMASK_IBM(6, 7) | ||
346 | #define H_ALL_RES_EQ_INH_EQE_GEN EHEA_BMASK_IBM(16, 16) | ||
347 | #define H_ALL_RES_EQ_RES_TYPE EHEA_BMASK_IBM(56, 63) | ||
348 | /* input param R6 */ | ||
349 | #define H_ALL_RES_EQ_MAX_EQE EHEA_BMASK_IBM(32, 63) | ||
350 | |||
351 | /* output param R6 */ | ||
352 | #define H_ALL_RES_EQ_LIOBN EHEA_BMASK_IBM(32, 63) | ||
353 | |||
354 | /* output param R7 */ | ||
355 | #define H_ALL_RES_EQ_ACT_EQE EHEA_BMASK_IBM(32, 63) | ||
356 | |||
357 | /* output param R8 */ | ||
358 | #define H_ALL_RES_EQ_ACT_PS EHEA_BMASK_IBM(32, 63) | ||
359 | |||
360 | /* output param R9 */ | ||
361 | #define H_ALL_RES_EQ_ACT_EQ_IST_C EHEA_BMASK_IBM(30, 31) | ||
362 | #define H_ALL_RES_EQ_ACT_EQ_IST_1 EHEA_BMASK_IBM(40, 63) | ||
363 | |||
364 | /* output param R10 */ | ||
365 | #define H_ALL_RES_EQ_ACT_EQ_IST_2 EHEA_BMASK_IBM(40, 63) | ||
366 | |||
367 | /* output param R11 */ | ||
368 | #define H_ALL_RES_EQ_ACT_EQ_IST_3 EHEA_BMASK_IBM(40, 63) | ||
369 | |||
370 | /* output param R12 */ | ||
371 | #define H_ALL_RES_EQ_ACT_EQ_IST_4 EHEA_BMASK_IBM(40, 63) | ||
372 | |||
373 | u64 ehea_h_alloc_resource_eq(const u64 adapter_handle, | ||
374 | struct ehea_eq_attr *eq_attr, u64 *eq_handle) | ||
375 | { | ||
376 | u64 hret, allocate_controls; | ||
377 | unsigned long outs[PLPAR_HCALL9_BUFSIZE]; | ||
378 | |||
379 | /* resource type */ | ||
380 | allocate_controls = | ||
381 | EHEA_BMASK_SET(H_ALL_RES_EQ_RES_TYPE, H_ALL_RES_TYPE_EQ) | ||
382 | | EHEA_BMASK_SET(H_ALL_RES_EQ_NEQ, eq_attr->type ? 1 : 0) | ||
383 | | EHEA_BMASK_SET(H_ALL_RES_EQ_INH_EQE_GEN, !eq_attr->eqe_gen) | ||
384 | | EHEA_BMASK_SET(H_ALL_RES_EQ_NON_NEQ_ISN, 1); | ||
385 | |||
386 | hret = ehea_plpar_hcall9(H_ALLOC_HEA_RESOURCE, | ||
387 | outs, | ||
388 | adapter_handle, /* R4 */ | ||
389 | allocate_controls, /* R5 */ | ||
390 | eq_attr->max_nr_of_eqes, /* R6 */ | ||
391 | 0, 0, 0, 0, 0, 0); /* R7-R10 */ | ||
392 | |||
393 | *eq_handle = outs[0]; | ||
394 | eq_attr->act_nr_of_eqes = outs[3]; | ||
395 | eq_attr->nr_pages = outs[4]; | ||
396 | eq_attr->ist1 = outs[5]; | ||
397 | eq_attr->ist2 = outs[6]; | ||
398 | eq_attr->ist3 = outs[7]; | ||
399 | eq_attr->ist4 = outs[8]; | ||
400 | |||
401 | return hret; | ||
402 | } | ||
403 | |||
404 | u64 ehea_h_modify_ehea_qp(const u64 adapter_handle, const u8 cat, | ||
405 | const u64 qp_handle, const u64 sel_mask, | ||
406 | void *cb_addr, u64 *inv_attr_id, u64 *proc_mask, | ||
407 | u16 *out_swr, u16 *out_rwr) | ||
408 | { | ||
409 | u64 hret; | ||
410 | unsigned long outs[PLPAR_HCALL9_BUFSIZE]; | ||
411 | |||
412 | hret = ehea_plpar_hcall9(H_MODIFY_HEA_QP, | ||
413 | outs, | ||
414 | adapter_handle, /* R4 */ | ||
415 | (u64) cat, /* R5 */ | ||
416 | qp_handle, /* R6 */ | ||
417 | sel_mask, /* R7 */ | ||
418 | virt_to_abs(cb_addr), /* R8 */ | ||
419 | 0, 0, 0, 0); /* R9-R12 */ | ||
420 | |||
421 | *inv_attr_id = outs[0]; | ||
422 | *out_swr = outs[3]; | ||
423 | *out_rwr = outs[4]; | ||
424 | *proc_mask = outs[5]; | ||
425 | |||
426 | return hret; | ||
427 | } | ||
428 | |||
429 | u64 ehea_h_register_rpage(const u64 adapter_handle, const u8 pagesize, | ||
430 | const u8 queue_type, const u64 resource_handle, | ||
431 | const u64 log_pageaddr, u64 count) | ||
432 | { | ||
433 | u64 reg_control; | ||
434 | |||
435 | reg_control = EHEA_BMASK_SET(H_REG_RPAGE_PAGE_SIZE, pagesize) | ||
436 | | EHEA_BMASK_SET(H_REG_RPAGE_QT, queue_type); | ||
437 | |||
438 | return ehea_plpar_hcall_norets(H_REGISTER_HEA_RPAGES, | ||
439 | adapter_handle, /* R4 */ | ||
440 | reg_control, /* R5 */ | ||
441 | resource_handle, /* R6 */ | ||
442 | log_pageaddr, /* R7 */ | ||
443 | count, /* R8 */ | ||
444 | 0, 0); /* R9-R10 */ | ||
445 | } | ||
446 | |||
447 | u64 ehea_h_register_smr(const u64 adapter_handle, const u64 orig_mr_handle, | ||
448 | const u64 vaddr_in, const u32 access_ctrl, const u32 pd, | ||
449 | struct ehea_mr *mr) | ||
450 | { | ||
451 | u64 hret; | ||
452 | unsigned long outs[PLPAR_HCALL9_BUFSIZE]; | ||
453 | |||
454 | hret = ehea_plpar_hcall9(H_REGISTER_SMR, | ||
455 | outs, | ||
456 | adapter_handle , /* R4 */ | ||
457 | orig_mr_handle, /* R5 */ | ||
458 | vaddr_in, /* R6 */ | ||
459 | (((u64)access_ctrl) << 32ULL), /* R7 */ | ||
460 | pd, /* R8 */ | ||
461 | 0, 0, 0, 0); /* R9-R12 */ | ||
462 | |||
463 | mr->handle = outs[0]; | ||
464 | mr->lkey = (u32)outs[2]; | ||
465 | |||
466 | return hret; | ||
467 | } | ||
468 | |||
469 | u64 ehea_h_disable_and_get_hea(const u64 adapter_handle, const u64 qp_handle) | ||
470 | { | ||
471 | unsigned long outs[PLPAR_HCALL9_BUFSIZE]; | ||
472 | |||
473 | return ehea_plpar_hcall9(H_DISABLE_AND_GET_HEA, | ||
474 | outs, | ||
475 | adapter_handle, /* R4 */ | ||
476 | H_DISABLE_GET_EHEA_WQE_P, /* R5 */ | ||
477 | qp_handle, /* R6 */ | ||
478 | 0, 0, 0, 0, 0, 0); /* R7-R12 */ | ||
479 | } | ||
480 | |||
481 | u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle, | ||
482 | u64 force_bit) | ||
483 | { | ||
484 | return ehea_plpar_hcall_norets(H_FREE_RESOURCE, | ||
485 | adapter_handle, /* R4 */ | ||
486 | res_handle, /* R5 */ | ||
487 | force_bit, | ||
488 | 0, 0, 0, 0); /* R7-R10 */ | ||
489 | } | ||
490 | |||
491 | u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr, | ||
492 | const u64 length, const u32 access_ctrl, | ||
493 | const u32 pd, u64 *mr_handle, u32 *lkey) | ||
494 | { | ||
495 | u64 hret; | ||
496 | unsigned long outs[PLPAR_HCALL9_BUFSIZE]; | ||
497 | |||
498 | hret = ehea_plpar_hcall9(H_ALLOC_HEA_RESOURCE, | ||
499 | outs, | ||
500 | adapter_handle, /* R4 */ | ||
501 | 5, /* R5 */ | ||
502 | vaddr, /* R6 */ | ||
503 | length, /* R7 */ | ||
504 | (((u64) access_ctrl) << 32ULL), /* R8 */ | ||
505 | pd, /* R9 */ | ||
506 | 0, 0, 0); /* R10-R12 */ | ||
507 | |||
508 | *mr_handle = outs[0]; | ||
509 | *lkey = (u32)outs[2]; | ||
510 | return hret; | ||
511 | } | ||
512 | |||
513 | u64 ehea_h_register_rpage_mr(const u64 adapter_handle, const u64 mr_handle, | ||
514 | const u8 pagesize, const u8 queue_type, | ||
515 | const u64 log_pageaddr, const u64 count) | ||
516 | { | ||
517 | if ((count > 1) && (log_pageaddr & ~PAGE_MASK)) { | ||
518 | pr_err("not on pageboundary\n"); | ||
519 | return H_PARAMETER; | ||
520 | } | ||
521 | |||
522 | return ehea_h_register_rpage(adapter_handle, pagesize, | ||
523 | queue_type, mr_handle, | ||
524 | log_pageaddr, count); | ||
525 | } | ||
526 | |||
527 | u64 ehea_h_query_ehea(const u64 adapter_handle, void *cb_addr) | ||
528 | { | ||
529 | u64 hret, cb_logaddr; | ||
530 | |||
531 | cb_logaddr = virt_to_abs(cb_addr); | ||
532 | |||
533 | hret = ehea_plpar_hcall_norets(H_QUERY_HEA, | ||
534 | adapter_handle, /* R4 */ | ||
535 | cb_logaddr, /* R5 */ | ||
536 | 0, 0, 0, 0, 0); /* R6-R10 */ | ||
537 | #ifdef DEBUG | ||
538 | ehea_dump(cb_addr, sizeof(struct hcp_query_ehea), "hcp_query_ehea"); | ||
539 | #endif | ||
540 | return hret; | ||
541 | } | ||
542 | |||
543 | u64 ehea_h_query_ehea_port(const u64 adapter_handle, const u16 port_num, | ||
544 | const u8 cb_cat, const u64 select_mask, | ||
545 | void *cb_addr) | ||
546 | { | ||
547 | u64 port_info; | ||
548 | u64 cb_logaddr = virt_to_abs(cb_addr); | ||
549 | u64 arr_index = 0; | ||
550 | |||
551 | port_info = EHEA_BMASK_SET(H_MEHEAPORT_CAT, cb_cat) | ||
552 | | EHEA_BMASK_SET(H_MEHEAPORT_PN, port_num); | ||
553 | |||
554 | return ehea_plpar_hcall_norets(H_QUERY_HEA_PORT, | ||
555 | adapter_handle, /* R4 */ | ||
556 | port_info, /* R5 */ | ||
557 | select_mask, /* R6 */ | ||
558 | arr_index, /* R7 */ | ||
559 | cb_logaddr, /* R8 */ | ||
560 | 0, 0); /* R9-R10 */ | ||
561 | } | ||
562 | |||
563 | u64 ehea_h_modify_ehea_port(const u64 adapter_handle, const u16 port_num, | ||
564 | const u8 cb_cat, const u64 select_mask, | ||
565 | void *cb_addr) | ||
566 | { | ||
567 | unsigned long outs[PLPAR_HCALL9_BUFSIZE]; | ||
568 | u64 port_info; | ||
569 | u64 arr_index = 0; | ||
570 | u64 cb_logaddr = virt_to_abs(cb_addr); | ||
571 | |||
572 | port_info = EHEA_BMASK_SET(H_MEHEAPORT_CAT, cb_cat) | ||
573 | | EHEA_BMASK_SET(H_MEHEAPORT_PN, port_num); | ||
574 | #ifdef DEBUG | ||
575 | ehea_dump(cb_addr, sizeof(struct hcp_ehea_port_cb0), "Before HCALL"); | ||
576 | #endif | ||
577 | return ehea_plpar_hcall9(H_MODIFY_HEA_PORT, | ||
578 | outs, | ||
579 | adapter_handle, /* R4 */ | ||
580 | port_info, /* R5 */ | ||
581 | select_mask, /* R6 */ | ||
582 | arr_index, /* R7 */ | ||
583 | cb_logaddr, /* R8 */ | ||
584 | 0, 0, 0, 0); /* R9-R12 */ | ||
585 | } | ||
586 | |||
587 | u64 ehea_h_reg_dereg_bcmc(const u64 adapter_handle, const u16 port_num, | ||
588 | const u8 reg_type, const u64 mc_mac_addr, | ||
589 | const u16 vlan_id, const u32 hcall_id) | ||
590 | { | ||
591 | u64 r5_port_num, r6_reg_type, r7_mc_mac_addr, r8_vlan_id; | ||
592 | u64 mac_addr = mc_mac_addr >> 16; | ||
593 | |||
594 | r5_port_num = EHEA_BMASK_SET(H_REGBCMC_PN, port_num); | ||
595 | r6_reg_type = EHEA_BMASK_SET(H_REGBCMC_REGTYPE, reg_type); | ||
596 | r7_mc_mac_addr = EHEA_BMASK_SET(H_REGBCMC_MACADDR, mac_addr); | ||
597 | r8_vlan_id = EHEA_BMASK_SET(H_REGBCMC_VLANID, vlan_id); | ||
598 | |||
599 | return ehea_plpar_hcall_norets(hcall_id, | ||
600 | adapter_handle, /* R4 */ | ||
601 | r5_port_num, /* R5 */ | ||
602 | r6_reg_type, /* R6 */ | ||
603 | r7_mc_mac_addr, /* R7 */ | ||
604 | r8_vlan_id, /* R8 */ | ||
605 | 0, 0); /* R9-R12 */ | ||
606 | } | ||
607 | |||
608 | u64 ehea_h_reset_events(const u64 adapter_handle, const u64 neq_handle, | ||
609 | const u64 event_mask) | ||
610 | { | ||
611 | return ehea_plpar_hcall_norets(H_RESET_EVENTS, | ||
612 | adapter_handle, /* R4 */ | ||
613 | neq_handle, /* R5 */ | ||
614 | event_mask, /* R6 */ | ||
615 | 0, 0, 0, 0); /* R7-R12 */ | ||
616 | } | ||
617 | |||
618 | u64 ehea_h_error_data(const u64 adapter_handle, const u64 ressource_handle, | ||
619 | void *rblock) | ||
620 | { | ||
621 | return ehea_plpar_hcall_norets(H_ERROR_DATA, | ||
622 | adapter_handle, /* R4 */ | ||
623 | ressource_handle, /* R5 */ | ||
624 | virt_to_abs(rblock), /* R6 */ | ||
625 | 0, 0, 0, 0); /* R7-R12 */ | ||
626 | } | ||
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_phyp.h b/drivers/net/ethernet/ibm/ehea/ehea_phyp.h new file mode 100644 index 000000000000..2f8174c248bc --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/ehea_phyp.h | |||
@@ -0,0 +1,467 @@ | |||
1 | /* | ||
2 | * linux/drivers/net/ehea/ehea_phyp.h | ||
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 | #ifndef __EHEA_PHYP_H__ | ||
30 | #define __EHEA_PHYP_H__ | ||
31 | |||
32 | #include <linux/delay.h> | ||
33 | #include <asm/hvcall.h> | ||
34 | #include "ehea.h" | ||
35 | #include "ehea_hw.h" | ||
36 | |||
37 | /* Some abbreviations used here: | ||
38 | * | ||
39 | * hcp_* - structures, variables and functions releated to Hypervisor Calls | ||
40 | */ | ||
41 | |||
42 | static inline u32 get_longbusy_msecs(int long_busy_ret_code) | ||
43 | { | ||
44 | switch (long_busy_ret_code) { | ||
45 | case H_LONG_BUSY_ORDER_1_MSEC: | ||
46 | return 1; | ||
47 | case H_LONG_BUSY_ORDER_10_MSEC: | ||
48 | return 10; | ||
49 | case H_LONG_BUSY_ORDER_100_MSEC: | ||
50 | return 100; | ||
51 | case H_LONG_BUSY_ORDER_1_SEC: | ||
52 | return 1000; | ||
53 | case H_LONG_BUSY_ORDER_10_SEC: | ||
54 | return 10000; | ||
55 | case H_LONG_BUSY_ORDER_100_SEC: | ||
56 | return 100000; | ||
57 | default: | ||
58 | return 1; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /* Number of pages which can be registered at once by H_REGISTER_HEA_RPAGES */ | ||
63 | #define EHEA_MAX_RPAGE 512 | ||
64 | |||
65 | /* Notification Event Queue (NEQ) Entry bit masks */ | ||
66 | #define NEQE_EVENT_CODE EHEA_BMASK_IBM(2, 7) | ||
67 | #define NEQE_PORTNUM EHEA_BMASK_IBM(32, 47) | ||
68 | #define NEQE_PORT_UP EHEA_BMASK_IBM(16, 16) | ||
69 | #define NEQE_EXTSWITCH_PORT_UP EHEA_BMASK_IBM(17, 17) | ||
70 | #define NEQE_EXTSWITCH_PRIMARY EHEA_BMASK_IBM(18, 18) | ||
71 | #define NEQE_PLID EHEA_BMASK_IBM(16, 47) | ||
72 | |||
73 | /* Notification Event Codes */ | ||
74 | #define EHEA_EC_PORTSTATE_CHG 0x30 | ||
75 | #define EHEA_EC_ADAPTER_MALFUNC 0x32 | ||
76 | #define EHEA_EC_PORT_MALFUNC 0x33 | ||
77 | |||
78 | /* Notification Event Log Register (NELR) bit masks */ | ||
79 | #define NELR_PORT_MALFUNC EHEA_BMASK_IBM(61, 61) | ||
80 | #define NELR_ADAPTER_MALFUNC EHEA_BMASK_IBM(62, 62) | ||
81 | #define NELR_PORTSTATE_CHG EHEA_BMASK_IBM(63, 63) | ||
82 | |||
83 | static inline void hcp_epas_ctor(struct h_epas *epas, u64 paddr_kernel, | ||
84 | u64 paddr_user) | ||
85 | { | ||
86 | /* To support 64k pages we must round to 64k page boundary */ | ||
87 | epas->kernel.addr = ioremap((paddr_kernel & PAGE_MASK), PAGE_SIZE) + | ||
88 | (paddr_kernel & ~PAGE_MASK); | ||
89 | epas->user.addr = paddr_user; | ||
90 | } | ||
91 | |||
92 | static inline void hcp_epas_dtor(struct h_epas *epas) | ||
93 | { | ||
94 | if (epas->kernel.addr) | ||
95 | iounmap((void __iomem *)((u64)epas->kernel.addr & PAGE_MASK)); | ||
96 | |||
97 | epas->user.addr = 0; | ||
98 | epas->kernel.addr = 0; | ||
99 | } | ||
100 | |||
101 | struct hcp_modify_qp_cb0 { | ||
102 | u64 qp_ctl_reg; /* 00 */ | ||
103 | u32 max_swqe; /* 02 */ | ||
104 | u32 max_rwqe; /* 03 */ | ||
105 | u32 port_nb; /* 04 */ | ||
106 | u32 reserved0; /* 05 */ | ||
107 | u64 qp_aer; /* 06 */ | ||
108 | u64 qp_tenure; /* 08 */ | ||
109 | }; | ||
110 | |||
111 | /* Hcall Query/Modify Queue Pair Control Block 0 Selection Mask Bits */ | ||
112 | #define H_QPCB0_ALL EHEA_BMASK_IBM(0, 5) | ||
113 | #define H_QPCB0_QP_CTL_REG EHEA_BMASK_IBM(0, 0) | ||
114 | #define H_QPCB0_MAX_SWQE EHEA_BMASK_IBM(1, 1) | ||
115 | #define H_QPCB0_MAX_RWQE EHEA_BMASK_IBM(2, 2) | ||
116 | #define H_QPCB0_PORT_NB EHEA_BMASK_IBM(3, 3) | ||
117 | #define H_QPCB0_QP_AER EHEA_BMASK_IBM(4, 4) | ||
118 | #define H_QPCB0_QP_TENURE EHEA_BMASK_IBM(5, 5) | ||
119 | |||
120 | /* Queue Pair Control Register Status Bits */ | ||
121 | #define H_QP_CR_ENABLED 0x8000000000000000ULL /* QP enabled */ | ||
122 | /* QP States: */ | ||
123 | #define H_QP_CR_STATE_RESET 0x0000010000000000ULL /* Reset */ | ||
124 | #define H_QP_CR_STATE_INITIALIZED 0x0000020000000000ULL /* Initialized */ | ||
125 | #define H_QP_CR_STATE_RDY2RCV 0x0000030000000000ULL /* Ready to recv */ | ||
126 | #define H_QP_CR_STATE_RDY2SND 0x0000050000000000ULL /* Ready to send */ | ||
127 | #define H_QP_CR_STATE_ERROR 0x0000800000000000ULL /* Error */ | ||
128 | #define H_QP_CR_RES_STATE 0x0000007F00000000ULL /* Resultant state */ | ||
129 | |||
130 | struct hcp_modify_qp_cb1 { | ||
131 | u32 qpn; /* 00 */ | ||
132 | u32 qp_asyn_ev_eq_nb; /* 01 */ | ||
133 | u64 sq_cq_handle; /* 02 */ | ||
134 | u64 rq_cq_handle; /* 04 */ | ||
135 | /* sgel = scatter gather element */ | ||
136 | u32 sgel_nb_sq; /* 06 */ | ||
137 | u32 sgel_nb_rq1; /* 07 */ | ||
138 | u32 sgel_nb_rq2; /* 08 */ | ||
139 | u32 sgel_nb_rq3; /* 09 */ | ||
140 | }; | ||
141 | |||
142 | /* Hcall Query/Modify Queue Pair Control Block 1 Selection Mask Bits */ | ||
143 | #define H_QPCB1_ALL EHEA_BMASK_IBM(0, 7) | ||
144 | #define H_QPCB1_QPN EHEA_BMASK_IBM(0, 0) | ||
145 | #define H_QPCB1_ASYN_EV_EQ_NB EHEA_BMASK_IBM(1, 1) | ||
146 | #define H_QPCB1_SQ_CQ_HANDLE EHEA_BMASK_IBM(2, 2) | ||
147 | #define H_QPCB1_RQ_CQ_HANDLE EHEA_BMASK_IBM(3, 3) | ||
148 | #define H_QPCB1_SGEL_NB_SQ EHEA_BMASK_IBM(4, 4) | ||
149 | #define H_QPCB1_SGEL_NB_RQ1 EHEA_BMASK_IBM(5, 5) | ||
150 | #define H_QPCB1_SGEL_NB_RQ2 EHEA_BMASK_IBM(6, 6) | ||
151 | #define H_QPCB1_SGEL_NB_RQ3 EHEA_BMASK_IBM(7, 7) | ||
152 | |||
153 | struct hcp_query_ehea { | ||
154 | u32 cur_num_qps; /* 00 */ | ||
155 | u32 cur_num_cqs; /* 01 */ | ||
156 | u32 cur_num_eqs; /* 02 */ | ||
157 | u32 cur_num_mrs; /* 03 */ | ||
158 | u32 auth_level; /* 04 */ | ||
159 | u32 max_num_qps; /* 05 */ | ||
160 | u32 max_num_cqs; /* 06 */ | ||
161 | u32 max_num_eqs; /* 07 */ | ||
162 | u32 max_num_mrs; /* 08 */ | ||
163 | u32 reserved0; /* 09 */ | ||
164 | u32 int_clock_freq; /* 10 */ | ||
165 | u32 max_num_pds; /* 11 */ | ||
166 | u32 max_num_addr_handles; /* 12 */ | ||
167 | u32 max_num_cqes; /* 13 */ | ||
168 | u32 max_num_wqes; /* 14 */ | ||
169 | u32 max_num_sgel_rq1wqe; /* 15 */ | ||
170 | u32 max_num_sgel_rq2wqe; /* 16 */ | ||
171 | u32 max_num_sgel_rq3wqe; /* 17 */ | ||
172 | u32 mr_page_size; /* 18 */ | ||
173 | u32 reserved1; /* 19 */ | ||
174 | u64 max_mr_size; /* 20 */ | ||
175 | u64 reserved2; /* 22 */ | ||
176 | u32 num_ports; /* 24 */ | ||
177 | u32 reserved3; /* 25 */ | ||
178 | u32 reserved4; /* 26 */ | ||
179 | u32 reserved5; /* 27 */ | ||
180 | u64 max_mc_mac; /* 28 */ | ||
181 | u64 ehea_cap; /* 30 */ | ||
182 | u32 max_isn_per_eq; /* 32 */ | ||
183 | u32 max_num_neq; /* 33 */ | ||
184 | u64 max_num_vlan_ids; /* 34 */ | ||
185 | u32 max_num_port_group; /* 36 */ | ||
186 | u32 max_num_phys_port; /* 37 */ | ||
187 | |||
188 | }; | ||
189 | |||
190 | /* Hcall Query/Modify Port Control Block defines */ | ||
191 | #define H_PORT_CB0 0 | ||
192 | #define H_PORT_CB1 1 | ||
193 | #define H_PORT_CB2 2 | ||
194 | #define H_PORT_CB3 3 | ||
195 | #define H_PORT_CB4 4 | ||
196 | #define H_PORT_CB5 5 | ||
197 | #define H_PORT_CB6 6 | ||
198 | #define H_PORT_CB7 7 | ||
199 | |||
200 | struct hcp_ehea_port_cb0 { | ||
201 | u64 port_mac_addr; | ||
202 | u64 port_rc; | ||
203 | u64 reserved0; | ||
204 | u32 port_op_state; | ||
205 | u32 port_speed; | ||
206 | u32 ext_swport_op_state; | ||
207 | u32 neg_tpf_prpf; | ||
208 | u32 num_default_qps; | ||
209 | u32 reserved1; | ||
210 | u64 default_qpn_arr[16]; | ||
211 | }; | ||
212 | |||
213 | /* Hcall Query/Modify Port Control Block 0 Selection Mask Bits */ | ||
214 | #define H_PORT_CB0_ALL EHEA_BMASK_IBM(0, 7) /* Set all bits */ | ||
215 | #define H_PORT_CB0_MAC EHEA_BMASK_IBM(0, 0) /* MAC address */ | ||
216 | #define H_PORT_CB0_PRC EHEA_BMASK_IBM(1, 1) /* Port Recv Control */ | ||
217 | #define H_PORT_CB0_DEFQPNARRAY EHEA_BMASK_IBM(7, 7) /* Default QPN Array */ | ||
218 | |||
219 | /* Hcall Query Port: Returned port speed values */ | ||
220 | #define H_SPEED_10M_H 1 /* 10 Mbps, Half Duplex */ | ||
221 | #define H_SPEED_10M_F 2 /* 10 Mbps, Full Duplex */ | ||
222 | #define H_SPEED_100M_H 3 /* 100 Mbps, Half Duplex */ | ||
223 | #define H_SPEED_100M_F 4 /* 100 Mbps, Full Duplex */ | ||
224 | #define H_SPEED_1G_F 6 /* 1 Gbps, Full Duplex */ | ||
225 | #define H_SPEED_10G_F 8 /* 10 Gbps, Full Duplex */ | ||
226 | |||
227 | /* Port Receive Control Status Bits */ | ||
228 | #define PXLY_RC_VALID EHEA_BMASK_IBM(49, 49) | ||
229 | #define PXLY_RC_VLAN_XTRACT EHEA_BMASK_IBM(50, 50) | ||
230 | #define PXLY_RC_TCP_6_TUPLE EHEA_BMASK_IBM(51, 51) | ||
231 | #define PXLY_RC_UDP_6_TUPLE EHEA_BMASK_IBM(52, 52) | ||
232 | #define PXLY_RC_TCP_3_TUPLE EHEA_BMASK_IBM(53, 53) | ||
233 | #define PXLY_RC_TCP_2_TUPLE EHEA_BMASK_IBM(54, 54) | ||
234 | #define PXLY_RC_LLC_SNAP EHEA_BMASK_IBM(55, 55) | ||
235 | #define PXLY_RC_JUMBO_FRAME EHEA_BMASK_IBM(56, 56) | ||
236 | #define PXLY_RC_FRAG_IP_PKT EHEA_BMASK_IBM(57, 57) | ||
237 | #define PXLY_RC_TCP_UDP_CHKSUM EHEA_BMASK_IBM(58, 58) | ||
238 | #define PXLY_RC_IP_CHKSUM EHEA_BMASK_IBM(59, 59) | ||
239 | #define PXLY_RC_MAC_FILTER EHEA_BMASK_IBM(60, 60) | ||
240 | #define PXLY_RC_UNTAG_FILTER EHEA_BMASK_IBM(61, 61) | ||
241 | #define PXLY_RC_VLAN_TAG_FILTER EHEA_BMASK_IBM(62, 63) | ||
242 | |||
243 | #define PXLY_RC_VLAN_FILTER 2 | ||
244 | #define PXLY_RC_VLAN_PERM 0 | ||
245 | |||
246 | |||
247 | #define H_PORT_CB1_ALL 0x8000000000000000ULL | ||
248 | |||
249 | struct hcp_ehea_port_cb1 { | ||
250 | u64 vlan_filter[64]; | ||
251 | }; | ||
252 | |||
253 | #define H_PORT_CB2_ALL 0xFFE0000000000000ULL | ||
254 | |||
255 | struct hcp_ehea_port_cb2 { | ||
256 | u64 rxo; | ||
257 | u64 rxucp; | ||
258 | u64 rxufd; | ||
259 | u64 rxuerr; | ||
260 | u64 rxftl; | ||
261 | u64 rxmcp; | ||
262 | u64 rxbcp; | ||
263 | u64 txo; | ||
264 | u64 txucp; | ||
265 | u64 txmcp; | ||
266 | u64 txbcp; | ||
267 | }; | ||
268 | |||
269 | struct hcp_ehea_port_cb3 { | ||
270 | u64 vlan_bc_filter[64]; | ||
271 | u64 vlan_mc_filter[64]; | ||
272 | u64 vlan_un_filter[64]; | ||
273 | u64 port_mac_hash_array[64]; | ||
274 | }; | ||
275 | |||
276 | #define H_PORT_CB4_ALL 0xF000000000000000ULL | ||
277 | #define H_PORT_CB4_JUMBO 0x1000000000000000ULL | ||
278 | #define H_PORT_CB4_SPEED 0x8000000000000000ULL | ||
279 | |||
280 | struct hcp_ehea_port_cb4 { | ||
281 | u32 port_speed; | ||
282 | u32 pause_frame; | ||
283 | u32 ens_port_op_state; | ||
284 | u32 jumbo_frame; | ||
285 | u32 ens_port_wrap; | ||
286 | }; | ||
287 | |||
288 | /* Hcall Query/Modify Port Control Block 5 Selection Mask Bits */ | ||
289 | #define H_PORT_CB5_RCU 0x0001000000000000ULL | ||
290 | #define PXS_RCU EHEA_BMASK_IBM(61, 63) | ||
291 | |||
292 | struct hcp_ehea_port_cb5 { | ||
293 | u64 prc; /* 00 */ | ||
294 | u64 uaa; /* 01 */ | ||
295 | u64 macvc; /* 02 */ | ||
296 | u64 xpcsc; /* 03 */ | ||
297 | u64 xpcsp; /* 04 */ | ||
298 | u64 pcsid; /* 05 */ | ||
299 | u64 xpcsst; /* 06 */ | ||
300 | u64 pthlb; /* 07 */ | ||
301 | u64 pthrb; /* 08 */ | ||
302 | u64 pqu; /* 09 */ | ||
303 | u64 pqd; /* 10 */ | ||
304 | u64 prt; /* 11 */ | ||
305 | u64 wsth; /* 12 */ | ||
306 | u64 rcb; /* 13 */ | ||
307 | u64 rcm; /* 14 */ | ||
308 | u64 rcu; /* 15 */ | ||
309 | u64 macc; /* 16 */ | ||
310 | u64 pc; /* 17 */ | ||
311 | u64 pst; /* 18 */ | ||
312 | u64 ducqpn; /* 19 */ | ||
313 | u64 mcqpn; /* 20 */ | ||
314 | u64 mma; /* 21 */ | ||
315 | u64 pmc0h; /* 22 */ | ||
316 | u64 pmc0l; /* 23 */ | ||
317 | u64 lbc; /* 24 */ | ||
318 | }; | ||
319 | |||
320 | #define H_PORT_CB6_ALL 0xFFFFFE7FFFFF8000ULL | ||
321 | |||
322 | struct hcp_ehea_port_cb6 { | ||
323 | u64 rxo; /* 00 */ | ||
324 | u64 rx64; /* 01 */ | ||
325 | u64 rx65; /* 02 */ | ||
326 | u64 rx128; /* 03 */ | ||
327 | u64 rx256; /* 04 */ | ||
328 | u64 rx512; /* 05 */ | ||
329 | u64 rx1024; /* 06 */ | ||
330 | u64 rxbfcs; /* 07 */ | ||
331 | u64 rxime; /* 08 */ | ||
332 | u64 rxrle; /* 09 */ | ||
333 | u64 rxorle; /* 10 */ | ||
334 | u64 rxftl; /* 11 */ | ||
335 | u64 rxjab; /* 12 */ | ||
336 | u64 rxse; /* 13 */ | ||
337 | u64 rxce; /* 14 */ | ||
338 | u64 rxrf; /* 15 */ | ||
339 | u64 rxfrag; /* 16 */ | ||
340 | u64 rxuoc; /* 17 */ | ||
341 | u64 rxcpf; /* 18 */ | ||
342 | u64 rxsb; /* 19 */ | ||
343 | u64 rxfd; /* 20 */ | ||
344 | u64 rxoerr; /* 21 */ | ||
345 | u64 rxaln; /* 22 */ | ||
346 | u64 ducqpn; /* 23 */ | ||
347 | u64 reserved0; /* 24 */ | ||
348 | u64 rxmcp; /* 25 */ | ||
349 | u64 rxbcp; /* 26 */ | ||
350 | u64 txmcp; /* 27 */ | ||
351 | u64 txbcp; /* 28 */ | ||
352 | u64 txo; /* 29 */ | ||
353 | u64 tx64; /* 30 */ | ||
354 | u64 tx65; /* 31 */ | ||
355 | u64 tx128; /* 32 */ | ||
356 | u64 tx256; /* 33 */ | ||
357 | u64 tx512; /* 34 */ | ||
358 | u64 tx1024; /* 35 */ | ||
359 | u64 txbfcs; /* 36 */ | ||
360 | u64 txcpf; /* 37 */ | ||
361 | u64 txlf; /* 38 */ | ||
362 | u64 txrf; /* 39 */ | ||
363 | u64 txime; /* 40 */ | ||
364 | u64 txsc; /* 41 */ | ||
365 | u64 txmc; /* 42 */ | ||
366 | u64 txsqe; /* 43 */ | ||
367 | u64 txdef; /* 44 */ | ||
368 | u64 txlcol; /* 45 */ | ||
369 | u64 txexcol; /* 46 */ | ||
370 | u64 txcse; /* 47 */ | ||
371 | u64 txbor; /* 48 */ | ||
372 | }; | ||
373 | |||
374 | #define H_PORT_CB7_DUCQPN 0x8000000000000000ULL | ||
375 | |||
376 | struct hcp_ehea_port_cb7 { | ||
377 | u64 def_uc_qpn; | ||
378 | }; | ||
379 | |||
380 | u64 ehea_h_query_ehea_qp(const u64 adapter_handle, | ||
381 | const u8 qp_category, | ||
382 | const u64 qp_handle, const u64 sel_mask, | ||
383 | void *cb_addr); | ||
384 | |||
385 | u64 ehea_h_modify_ehea_qp(const u64 adapter_handle, | ||
386 | const u8 cat, | ||
387 | const u64 qp_handle, | ||
388 | const u64 sel_mask, | ||
389 | void *cb_addr, | ||
390 | u64 *inv_attr_id, | ||
391 | u64 *proc_mask, u16 *out_swr, u16 *out_rwr); | ||
392 | |||
393 | u64 ehea_h_alloc_resource_eq(const u64 adapter_handle, | ||
394 | struct ehea_eq_attr *eq_attr, u64 *eq_handle); | ||
395 | |||
396 | u64 ehea_h_alloc_resource_cq(const u64 adapter_handle, | ||
397 | struct ehea_cq_attr *cq_attr, | ||
398 | u64 *cq_handle, struct h_epas *epas); | ||
399 | |||
400 | u64 ehea_h_alloc_resource_qp(const u64 adapter_handle, | ||
401 | struct ehea_qp_init_attr *init_attr, | ||
402 | const u32 pd, | ||
403 | u64 *qp_handle, struct h_epas *h_epas); | ||
404 | |||
405 | #define H_REG_RPAGE_PAGE_SIZE EHEA_BMASK_IBM(48, 55) | ||
406 | #define H_REG_RPAGE_QT EHEA_BMASK_IBM(62, 63) | ||
407 | |||
408 | u64 ehea_h_register_rpage(const u64 adapter_handle, | ||
409 | const u8 pagesize, | ||
410 | const u8 queue_type, | ||
411 | const u64 resource_handle, | ||
412 | const u64 log_pageaddr, u64 count); | ||
413 | |||
414 | #define H_DISABLE_GET_EHEA_WQE_P 1 | ||
415 | #define H_DISABLE_GET_SQ_WQE_P 2 | ||
416 | #define H_DISABLE_GET_RQC 3 | ||
417 | |||
418 | u64 ehea_h_disable_and_get_hea(const u64 adapter_handle, const u64 qp_handle); | ||
419 | |||
420 | #define FORCE_FREE 1 | ||
421 | #define NORMAL_FREE 0 | ||
422 | |||
423 | u64 ehea_h_free_resource(const u64 adapter_handle, const u64 res_handle, | ||
424 | u64 force_bit); | ||
425 | |||
426 | u64 ehea_h_alloc_resource_mr(const u64 adapter_handle, const u64 vaddr, | ||
427 | const u64 length, const u32 access_ctrl, | ||
428 | const u32 pd, u64 *mr_handle, u32 *lkey); | ||
429 | |||
430 | u64 ehea_h_register_rpage_mr(const u64 adapter_handle, const u64 mr_handle, | ||
431 | const u8 pagesize, const u8 queue_type, | ||
432 | const u64 log_pageaddr, const u64 count); | ||
433 | |||
434 | u64 ehea_h_register_smr(const u64 adapter_handle, const u64 orig_mr_handle, | ||
435 | const u64 vaddr_in, const u32 access_ctrl, const u32 pd, | ||
436 | struct ehea_mr *mr); | ||
437 | |||
438 | u64 ehea_h_query_ehea(const u64 adapter_handle, void *cb_addr); | ||
439 | |||
440 | /* output param R5 */ | ||
441 | #define H_MEHEAPORT_CAT EHEA_BMASK_IBM(40, 47) | ||
442 | #define H_MEHEAPORT_PN EHEA_BMASK_IBM(48, 63) | ||
443 | |||
444 | u64 ehea_h_query_ehea_port(const u64 adapter_handle, const u16 port_num, | ||
445 | const u8 cb_cat, const u64 select_mask, | ||
446 | void *cb_addr); | ||
447 | |||
448 | u64 ehea_h_modify_ehea_port(const u64 adapter_handle, const u16 port_num, | ||
449 | const u8 cb_cat, const u64 select_mask, | ||
450 | void *cb_addr); | ||
451 | |||
452 | #define H_REGBCMC_PN EHEA_BMASK_IBM(48, 63) | ||
453 | #define H_REGBCMC_REGTYPE EHEA_BMASK_IBM(61, 63) | ||
454 | #define H_REGBCMC_MACADDR EHEA_BMASK_IBM(16, 63) | ||
455 | #define H_REGBCMC_VLANID EHEA_BMASK_IBM(52, 63) | ||
456 | |||
457 | u64 ehea_h_reg_dereg_bcmc(const u64 adapter_handle, const u16 port_num, | ||
458 | const u8 reg_type, const u64 mc_mac_addr, | ||
459 | const u16 vlan_id, const u32 hcall_id); | ||
460 | |||
461 | u64 ehea_h_reset_events(const u64 adapter_handle, const u64 neq_handle, | ||
462 | const u64 event_mask); | ||
463 | |||
464 | u64 ehea_h_error_data(const u64 adapter_handle, const u64 ressource_handle, | ||
465 | void *rblock); | ||
466 | |||
467 | #endif /* __EHEA_PHYP_H__ */ | ||
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_qmr.c b/drivers/net/ethernet/ibm/ehea/ehea_qmr.c new file mode 100644 index 000000000000..95b9f4fa811e --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/ehea_qmr.c | |||
@@ -0,0 +1,1031 @@ | |||
1 | /* | ||
2 | * linux/drivers/net/ehea/ehea_qmr.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 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
30 | |||
31 | #include <linux/mm.h> | ||
32 | #include <linux/slab.h> | ||
33 | #include "ehea.h" | ||
34 | #include "ehea_phyp.h" | ||
35 | #include "ehea_qmr.h" | ||
36 | |||
37 | struct ehea_bmap *ehea_bmap = NULL; | ||
38 | |||
39 | |||
40 | |||
41 | static void *hw_qpageit_get_inc(struct hw_queue *queue) | ||
42 | { | ||
43 | void *retvalue = hw_qeit_get(queue); | ||
44 | |||
45 | queue->current_q_offset += queue->pagesize; | ||
46 | if (queue->current_q_offset > queue->queue_length) { | ||
47 | queue->current_q_offset -= queue->pagesize; | ||
48 | retvalue = NULL; | ||
49 | } else if (((u64) retvalue) & (EHEA_PAGESIZE-1)) { | ||
50 | pr_err("not on pageboundary\n"); | ||
51 | retvalue = NULL; | ||
52 | } | ||
53 | return retvalue; | ||
54 | } | ||
55 | |||
56 | static int hw_queue_ctor(struct hw_queue *queue, const u32 nr_of_pages, | ||
57 | const u32 pagesize, const u32 qe_size) | ||
58 | { | ||
59 | int pages_per_kpage = PAGE_SIZE / pagesize; | ||
60 | int i, k; | ||
61 | |||
62 | if ((pagesize > PAGE_SIZE) || (!pages_per_kpage)) { | ||
63 | pr_err("pagesize conflict! kernel pagesize=%d, ehea pagesize=%d\n", | ||
64 | (int)PAGE_SIZE, (int)pagesize); | ||
65 | return -EINVAL; | ||
66 | } | ||
67 | |||
68 | queue->queue_length = nr_of_pages * pagesize; | ||
69 | queue->queue_pages = kmalloc(nr_of_pages * sizeof(void *), GFP_KERNEL); | ||
70 | if (!queue->queue_pages) { | ||
71 | pr_err("no mem for queue_pages\n"); | ||
72 | return -ENOMEM; | ||
73 | } | ||
74 | |||
75 | /* | ||
76 | * allocate pages for queue: | ||
77 | * outer loop allocates whole kernel pages (page aligned) and | ||
78 | * inner loop divides a kernel page into smaller hea queue pages | ||
79 | */ | ||
80 | i = 0; | ||
81 | while (i < nr_of_pages) { | ||
82 | u8 *kpage = (u8 *)get_zeroed_page(GFP_KERNEL); | ||
83 | if (!kpage) | ||
84 | goto out_nomem; | ||
85 | for (k = 0; k < pages_per_kpage && i < nr_of_pages; k++) { | ||
86 | (queue->queue_pages)[i] = (struct ehea_page *)kpage; | ||
87 | kpage += pagesize; | ||
88 | i++; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | queue->current_q_offset = 0; | ||
93 | queue->qe_size = qe_size; | ||
94 | queue->pagesize = pagesize; | ||
95 | queue->toggle_state = 1; | ||
96 | |||
97 | return 0; | ||
98 | out_nomem: | ||
99 | for (i = 0; i < nr_of_pages; i += pages_per_kpage) { | ||
100 | if (!(queue->queue_pages)[i]) | ||
101 | break; | ||
102 | free_page((unsigned long)(queue->queue_pages)[i]); | ||
103 | } | ||
104 | return -ENOMEM; | ||
105 | } | ||
106 | |||
107 | static void hw_queue_dtor(struct hw_queue *queue) | ||
108 | { | ||
109 | int pages_per_kpage = PAGE_SIZE / queue->pagesize; | ||
110 | int i, nr_pages; | ||
111 | |||
112 | if (!queue || !queue->queue_pages) | ||
113 | return; | ||
114 | |||
115 | nr_pages = queue->queue_length / queue->pagesize; | ||
116 | |||
117 | for (i = 0; i < nr_pages; i += pages_per_kpage) | ||
118 | free_page((unsigned long)(queue->queue_pages)[i]); | ||
119 | |||
120 | kfree(queue->queue_pages); | ||
121 | } | ||
122 | |||
123 | struct ehea_cq *ehea_create_cq(struct ehea_adapter *adapter, | ||
124 | int nr_of_cqe, u64 eq_handle, u32 cq_token) | ||
125 | { | ||
126 | struct ehea_cq *cq; | ||
127 | struct h_epa epa; | ||
128 | u64 *cq_handle_ref, hret, rpage; | ||
129 | u32 act_nr_of_entries, act_pages, counter; | ||
130 | int ret; | ||
131 | void *vpage; | ||
132 | |||
133 | cq = kzalloc(sizeof(*cq), GFP_KERNEL); | ||
134 | if (!cq) { | ||
135 | pr_err("no mem for cq\n"); | ||
136 | goto out_nomem; | ||
137 | } | ||
138 | |||
139 | cq->attr.max_nr_of_cqes = nr_of_cqe; | ||
140 | cq->attr.cq_token = cq_token; | ||
141 | cq->attr.eq_handle = eq_handle; | ||
142 | |||
143 | cq->adapter = adapter; | ||
144 | |||
145 | cq_handle_ref = &cq->fw_handle; | ||
146 | act_nr_of_entries = 0; | ||
147 | act_pages = 0; | ||
148 | |||
149 | hret = ehea_h_alloc_resource_cq(adapter->handle, &cq->attr, | ||
150 | &cq->fw_handle, &cq->epas); | ||
151 | if (hret != H_SUCCESS) { | ||
152 | pr_err("alloc_resource_cq failed\n"); | ||
153 | goto out_freemem; | ||
154 | } | ||
155 | |||
156 | ret = hw_queue_ctor(&cq->hw_queue, cq->attr.nr_pages, | ||
157 | EHEA_PAGESIZE, sizeof(struct ehea_cqe)); | ||
158 | if (ret) | ||
159 | goto out_freeres; | ||
160 | |||
161 | for (counter = 0; counter < cq->attr.nr_pages; counter++) { | ||
162 | vpage = hw_qpageit_get_inc(&cq->hw_queue); | ||
163 | if (!vpage) { | ||
164 | pr_err("hw_qpageit_get_inc failed\n"); | ||
165 | goto out_kill_hwq; | ||
166 | } | ||
167 | |||
168 | rpage = virt_to_abs(vpage); | ||
169 | hret = ehea_h_register_rpage(adapter->handle, | ||
170 | 0, EHEA_CQ_REGISTER_ORIG, | ||
171 | cq->fw_handle, rpage, 1); | ||
172 | if (hret < H_SUCCESS) { | ||
173 | pr_err("register_rpage_cq failed ehea_cq=%p hret=%llx counter=%i act_pages=%i\n", | ||
174 | cq, hret, counter, cq->attr.nr_pages); | ||
175 | goto out_kill_hwq; | ||
176 | } | ||
177 | |||
178 | if (counter == (cq->attr.nr_pages - 1)) { | ||
179 | vpage = hw_qpageit_get_inc(&cq->hw_queue); | ||
180 | |||
181 | if ((hret != H_SUCCESS) || (vpage)) { | ||
182 | pr_err("registration of pages not complete hret=%llx\n", | ||
183 | hret); | ||
184 | goto out_kill_hwq; | ||
185 | } | ||
186 | } else { | ||
187 | if (hret != H_PAGE_REGISTERED) { | ||
188 | pr_err("CQ: registration of page failed hret=%llx\n", | ||
189 | hret); | ||
190 | goto out_kill_hwq; | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | |||
195 | hw_qeit_reset(&cq->hw_queue); | ||
196 | epa = cq->epas.kernel; | ||
197 | ehea_reset_cq_ep(cq); | ||
198 | ehea_reset_cq_n1(cq); | ||
199 | |||
200 | return cq; | ||
201 | |||
202 | out_kill_hwq: | ||
203 | hw_queue_dtor(&cq->hw_queue); | ||
204 | |||
205 | out_freeres: | ||
206 | ehea_h_free_resource(adapter->handle, cq->fw_handle, FORCE_FREE); | ||
207 | |||
208 | out_freemem: | ||
209 | kfree(cq); | ||
210 | |||
211 | out_nomem: | ||
212 | return NULL; | ||
213 | } | ||
214 | |||
215 | u64 ehea_destroy_cq_res(struct ehea_cq *cq, u64 force) | ||
216 | { | ||
217 | u64 hret; | ||
218 | u64 adapter_handle = cq->adapter->handle; | ||
219 | |||
220 | /* deregister all previous registered pages */ | ||
221 | hret = ehea_h_free_resource(adapter_handle, cq->fw_handle, force); | ||
222 | if (hret != H_SUCCESS) | ||
223 | return hret; | ||
224 | |||
225 | hw_queue_dtor(&cq->hw_queue); | ||
226 | kfree(cq); | ||
227 | |||
228 | return hret; | ||
229 | } | ||
230 | |||
231 | int ehea_destroy_cq(struct ehea_cq *cq) | ||
232 | { | ||
233 | u64 hret, aer, aerr; | ||
234 | if (!cq) | ||
235 | return 0; | ||
236 | |||
237 | hcp_epas_dtor(&cq->epas); | ||
238 | hret = ehea_destroy_cq_res(cq, NORMAL_FREE); | ||
239 | if (hret == H_R_STATE) { | ||
240 | ehea_error_data(cq->adapter, cq->fw_handle, &aer, &aerr); | ||
241 | hret = ehea_destroy_cq_res(cq, FORCE_FREE); | ||
242 | } | ||
243 | |||
244 | if (hret != H_SUCCESS) { | ||
245 | pr_err("destroy CQ failed\n"); | ||
246 | return -EIO; | ||
247 | } | ||
248 | |||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | struct ehea_eq *ehea_create_eq(struct ehea_adapter *adapter, | ||
253 | const enum ehea_eq_type type, | ||
254 | const u32 max_nr_of_eqes, const u8 eqe_gen) | ||
255 | { | ||
256 | int ret, i; | ||
257 | u64 hret, rpage; | ||
258 | void *vpage; | ||
259 | struct ehea_eq *eq; | ||
260 | |||
261 | eq = kzalloc(sizeof(*eq), GFP_KERNEL); | ||
262 | if (!eq) { | ||
263 | pr_err("no mem for eq\n"); | ||
264 | return NULL; | ||
265 | } | ||
266 | |||
267 | eq->adapter = adapter; | ||
268 | eq->attr.type = type; | ||
269 | eq->attr.max_nr_of_eqes = max_nr_of_eqes; | ||
270 | eq->attr.eqe_gen = eqe_gen; | ||
271 | spin_lock_init(&eq->spinlock); | ||
272 | |||
273 | hret = ehea_h_alloc_resource_eq(adapter->handle, | ||
274 | &eq->attr, &eq->fw_handle); | ||
275 | if (hret != H_SUCCESS) { | ||
276 | pr_err("alloc_resource_eq failed\n"); | ||
277 | goto out_freemem; | ||
278 | } | ||
279 | |||
280 | ret = hw_queue_ctor(&eq->hw_queue, eq->attr.nr_pages, | ||
281 | EHEA_PAGESIZE, sizeof(struct ehea_eqe)); | ||
282 | if (ret) { | ||
283 | pr_err("can't allocate eq pages\n"); | ||
284 | goto out_freeres; | ||
285 | } | ||
286 | |||
287 | for (i = 0; i < eq->attr.nr_pages; i++) { | ||
288 | vpage = hw_qpageit_get_inc(&eq->hw_queue); | ||
289 | if (!vpage) { | ||
290 | pr_err("hw_qpageit_get_inc failed\n"); | ||
291 | hret = H_RESOURCE; | ||
292 | goto out_kill_hwq; | ||
293 | } | ||
294 | |||
295 | rpage = virt_to_abs(vpage); | ||
296 | |||
297 | hret = ehea_h_register_rpage(adapter->handle, 0, | ||
298 | EHEA_EQ_REGISTER_ORIG, | ||
299 | eq->fw_handle, rpage, 1); | ||
300 | |||
301 | if (i == (eq->attr.nr_pages - 1)) { | ||
302 | /* last page */ | ||
303 | vpage = hw_qpageit_get_inc(&eq->hw_queue); | ||
304 | if ((hret != H_SUCCESS) || (vpage)) | ||
305 | goto out_kill_hwq; | ||
306 | |||
307 | } else { | ||
308 | if (hret != H_PAGE_REGISTERED) | ||
309 | goto out_kill_hwq; | ||
310 | |||
311 | } | ||
312 | } | ||
313 | |||
314 | hw_qeit_reset(&eq->hw_queue); | ||
315 | return eq; | ||
316 | |||
317 | out_kill_hwq: | ||
318 | hw_queue_dtor(&eq->hw_queue); | ||
319 | |||
320 | out_freeres: | ||
321 | ehea_h_free_resource(adapter->handle, eq->fw_handle, FORCE_FREE); | ||
322 | |||
323 | out_freemem: | ||
324 | kfree(eq); | ||
325 | return NULL; | ||
326 | } | ||
327 | |||
328 | struct ehea_eqe *ehea_poll_eq(struct ehea_eq *eq) | ||
329 | { | ||
330 | struct ehea_eqe *eqe; | ||
331 | unsigned long flags; | ||
332 | |||
333 | spin_lock_irqsave(&eq->spinlock, flags); | ||
334 | eqe = hw_eqit_eq_get_inc_valid(&eq->hw_queue); | ||
335 | spin_unlock_irqrestore(&eq->spinlock, flags); | ||
336 | |||
337 | return eqe; | ||
338 | } | ||
339 | |||
340 | u64 ehea_destroy_eq_res(struct ehea_eq *eq, u64 force) | ||
341 | { | ||
342 | u64 hret; | ||
343 | unsigned long flags; | ||
344 | |||
345 | spin_lock_irqsave(&eq->spinlock, flags); | ||
346 | |||
347 | hret = ehea_h_free_resource(eq->adapter->handle, eq->fw_handle, force); | ||
348 | spin_unlock_irqrestore(&eq->spinlock, flags); | ||
349 | |||
350 | if (hret != H_SUCCESS) | ||
351 | return hret; | ||
352 | |||
353 | hw_queue_dtor(&eq->hw_queue); | ||
354 | kfree(eq); | ||
355 | |||
356 | return hret; | ||
357 | } | ||
358 | |||
359 | int ehea_destroy_eq(struct ehea_eq *eq) | ||
360 | { | ||
361 | u64 hret, aer, aerr; | ||
362 | if (!eq) | ||
363 | return 0; | ||
364 | |||
365 | hcp_epas_dtor(&eq->epas); | ||
366 | |||
367 | hret = ehea_destroy_eq_res(eq, NORMAL_FREE); | ||
368 | if (hret == H_R_STATE) { | ||
369 | ehea_error_data(eq->adapter, eq->fw_handle, &aer, &aerr); | ||
370 | hret = ehea_destroy_eq_res(eq, FORCE_FREE); | ||
371 | } | ||
372 | |||
373 | if (hret != H_SUCCESS) { | ||
374 | pr_err("destroy EQ failed\n"); | ||
375 | return -EIO; | ||
376 | } | ||
377 | |||
378 | return 0; | ||
379 | } | ||
380 | |||
381 | /** | ||
382 | * allocates memory for a queue and registers pages in phyp | ||
383 | */ | ||
384 | int ehea_qp_alloc_register(struct ehea_qp *qp, struct hw_queue *hw_queue, | ||
385 | int nr_pages, int wqe_size, int act_nr_sges, | ||
386 | struct ehea_adapter *adapter, int h_call_q_selector) | ||
387 | { | ||
388 | u64 hret, rpage; | ||
389 | int ret, cnt; | ||
390 | void *vpage; | ||
391 | |||
392 | ret = hw_queue_ctor(hw_queue, nr_pages, EHEA_PAGESIZE, wqe_size); | ||
393 | if (ret) | ||
394 | return ret; | ||
395 | |||
396 | for (cnt = 0; cnt < nr_pages; cnt++) { | ||
397 | vpage = hw_qpageit_get_inc(hw_queue); | ||
398 | if (!vpage) { | ||
399 | pr_err("hw_qpageit_get_inc failed\n"); | ||
400 | goto out_kill_hwq; | ||
401 | } | ||
402 | rpage = virt_to_abs(vpage); | ||
403 | hret = ehea_h_register_rpage(adapter->handle, | ||
404 | 0, h_call_q_selector, | ||
405 | qp->fw_handle, rpage, 1); | ||
406 | if (hret < H_SUCCESS) { | ||
407 | pr_err("register_rpage_qp failed\n"); | ||
408 | goto out_kill_hwq; | ||
409 | } | ||
410 | } | ||
411 | hw_qeit_reset(hw_queue); | ||
412 | return 0; | ||
413 | |||
414 | out_kill_hwq: | ||
415 | hw_queue_dtor(hw_queue); | ||
416 | return -EIO; | ||
417 | } | ||
418 | |||
419 | static inline u32 map_wqe_size(u8 wqe_enc_size) | ||
420 | { | ||
421 | return 128 << wqe_enc_size; | ||
422 | } | ||
423 | |||
424 | struct ehea_qp *ehea_create_qp(struct ehea_adapter *adapter, | ||
425 | u32 pd, struct ehea_qp_init_attr *init_attr) | ||
426 | { | ||
427 | int ret; | ||
428 | u64 hret; | ||
429 | struct ehea_qp *qp; | ||
430 | u32 wqe_size_in_bytes_sq, wqe_size_in_bytes_rq1; | ||
431 | u32 wqe_size_in_bytes_rq2, wqe_size_in_bytes_rq3; | ||
432 | |||
433 | |||
434 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); | ||
435 | if (!qp) { | ||
436 | pr_err("no mem for qp\n"); | ||
437 | return NULL; | ||
438 | } | ||
439 | |||
440 | qp->adapter = adapter; | ||
441 | |||
442 | hret = ehea_h_alloc_resource_qp(adapter->handle, init_attr, pd, | ||
443 | &qp->fw_handle, &qp->epas); | ||
444 | if (hret != H_SUCCESS) { | ||
445 | pr_err("ehea_h_alloc_resource_qp failed\n"); | ||
446 | goto out_freemem; | ||
447 | } | ||
448 | |||
449 | wqe_size_in_bytes_sq = map_wqe_size(init_attr->act_wqe_size_enc_sq); | ||
450 | wqe_size_in_bytes_rq1 = map_wqe_size(init_attr->act_wqe_size_enc_rq1); | ||
451 | wqe_size_in_bytes_rq2 = map_wqe_size(init_attr->act_wqe_size_enc_rq2); | ||
452 | wqe_size_in_bytes_rq3 = map_wqe_size(init_attr->act_wqe_size_enc_rq3); | ||
453 | |||
454 | ret = ehea_qp_alloc_register(qp, &qp->hw_squeue, init_attr->nr_sq_pages, | ||
455 | wqe_size_in_bytes_sq, | ||
456 | init_attr->act_wqe_size_enc_sq, adapter, | ||
457 | 0); | ||
458 | if (ret) { | ||
459 | pr_err("can't register for sq ret=%x\n", ret); | ||
460 | goto out_freeres; | ||
461 | } | ||
462 | |||
463 | ret = ehea_qp_alloc_register(qp, &qp->hw_rqueue1, | ||
464 | init_attr->nr_rq1_pages, | ||
465 | wqe_size_in_bytes_rq1, | ||
466 | init_attr->act_wqe_size_enc_rq1, | ||
467 | adapter, 1); | ||
468 | if (ret) { | ||
469 | pr_err("can't register for rq1 ret=%x\n", ret); | ||
470 | goto out_kill_hwsq; | ||
471 | } | ||
472 | |||
473 | if (init_attr->rq_count > 1) { | ||
474 | ret = ehea_qp_alloc_register(qp, &qp->hw_rqueue2, | ||
475 | init_attr->nr_rq2_pages, | ||
476 | wqe_size_in_bytes_rq2, | ||
477 | init_attr->act_wqe_size_enc_rq2, | ||
478 | adapter, 2); | ||
479 | if (ret) { | ||
480 | pr_err("can't register for rq2 ret=%x\n", ret); | ||
481 | goto out_kill_hwr1q; | ||
482 | } | ||
483 | } | ||
484 | |||
485 | if (init_attr->rq_count > 2) { | ||
486 | ret = ehea_qp_alloc_register(qp, &qp->hw_rqueue3, | ||
487 | init_attr->nr_rq3_pages, | ||
488 | wqe_size_in_bytes_rq3, | ||
489 | init_attr->act_wqe_size_enc_rq3, | ||
490 | adapter, 3); | ||
491 | if (ret) { | ||
492 | pr_err("can't register for rq3 ret=%x\n", ret); | ||
493 | goto out_kill_hwr2q; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | qp->init_attr = *init_attr; | ||
498 | |||
499 | return qp; | ||
500 | |||
501 | out_kill_hwr2q: | ||
502 | hw_queue_dtor(&qp->hw_rqueue2); | ||
503 | |||
504 | out_kill_hwr1q: | ||
505 | hw_queue_dtor(&qp->hw_rqueue1); | ||
506 | |||
507 | out_kill_hwsq: | ||
508 | hw_queue_dtor(&qp->hw_squeue); | ||
509 | |||
510 | out_freeres: | ||
511 | ehea_h_disable_and_get_hea(adapter->handle, qp->fw_handle); | ||
512 | ehea_h_free_resource(adapter->handle, qp->fw_handle, FORCE_FREE); | ||
513 | |||
514 | out_freemem: | ||
515 | kfree(qp); | ||
516 | return NULL; | ||
517 | } | ||
518 | |||
519 | u64 ehea_destroy_qp_res(struct ehea_qp *qp, u64 force) | ||
520 | { | ||
521 | u64 hret; | ||
522 | struct ehea_qp_init_attr *qp_attr = &qp->init_attr; | ||
523 | |||
524 | |||
525 | ehea_h_disable_and_get_hea(qp->adapter->handle, qp->fw_handle); | ||
526 | hret = ehea_h_free_resource(qp->adapter->handle, qp->fw_handle, force); | ||
527 | if (hret != H_SUCCESS) | ||
528 | return hret; | ||
529 | |||
530 | hw_queue_dtor(&qp->hw_squeue); | ||
531 | hw_queue_dtor(&qp->hw_rqueue1); | ||
532 | |||
533 | if (qp_attr->rq_count > 1) | ||
534 | hw_queue_dtor(&qp->hw_rqueue2); | ||
535 | if (qp_attr->rq_count > 2) | ||
536 | hw_queue_dtor(&qp->hw_rqueue3); | ||
537 | kfree(qp); | ||
538 | |||
539 | return hret; | ||
540 | } | ||
541 | |||
542 | int ehea_destroy_qp(struct ehea_qp *qp) | ||
543 | { | ||
544 | u64 hret, aer, aerr; | ||
545 | if (!qp) | ||
546 | return 0; | ||
547 | |||
548 | hcp_epas_dtor(&qp->epas); | ||
549 | |||
550 | hret = ehea_destroy_qp_res(qp, NORMAL_FREE); | ||
551 | if (hret == H_R_STATE) { | ||
552 | ehea_error_data(qp->adapter, qp->fw_handle, &aer, &aerr); | ||
553 | hret = ehea_destroy_qp_res(qp, FORCE_FREE); | ||
554 | } | ||
555 | |||
556 | if (hret != H_SUCCESS) { | ||
557 | pr_err("destroy QP failed\n"); | ||
558 | return -EIO; | ||
559 | } | ||
560 | |||
561 | return 0; | ||
562 | } | ||
563 | |||
564 | static inline int ehea_calc_index(unsigned long i, unsigned long s) | ||
565 | { | ||
566 | return (i >> s) & EHEA_INDEX_MASK; | ||
567 | } | ||
568 | |||
569 | static inline int ehea_init_top_bmap(struct ehea_top_bmap *ehea_top_bmap, | ||
570 | int dir) | ||
571 | { | ||
572 | if (!ehea_top_bmap->dir[dir]) { | ||
573 | ehea_top_bmap->dir[dir] = | ||
574 | kzalloc(sizeof(struct ehea_dir_bmap), GFP_KERNEL); | ||
575 | if (!ehea_top_bmap->dir[dir]) | ||
576 | return -ENOMEM; | ||
577 | } | ||
578 | return 0; | ||
579 | } | ||
580 | |||
581 | static inline int ehea_init_bmap(struct ehea_bmap *ehea_bmap, int top, int dir) | ||
582 | { | ||
583 | if (!ehea_bmap->top[top]) { | ||
584 | ehea_bmap->top[top] = | ||
585 | kzalloc(sizeof(struct ehea_top_bmap), GFP_KERNEL); | ||
586 | if (!ehea_bmap->top[top]) | ||
587 | return -ENOMEM; | ||
588 | } | ||
589 | return ehea_init_top_bmap(ehea_bmap->top[top], dir); | ||
590 | } | ||
591 | |||
592 | static DEFINE_MUTEX(ehea_busmap_mutex); | ||
593 | static unsigned long ehea_mr_len; | ||
594 | |||
595 | #define EHEA_BUSMAP_ADD_SECT 1 | ||
596 | #define EHEA_BUSMAP_REM_SECT 0 | ||
597 | |||
598 | static void ehea_rebuild_busmap(void) | ||
599 | { | ||
600 | u64 vaddr = EHEA_BUSMAP_START; | ||
601 | int top, dir, idx; | ||
602 | |||
603 | for (top = 0; top < EHEA_MAP_ENTRIES; top++) { | ||
604 | struct ehea_top_bmap *ehea_top; | ||
605 | int valid_dir_entries = 0; | ||
606 | |||
607 | if (!ehea_bmap->top[top]) | ||
608 | continue; | ||
609 | ehea_top = ehea_bmap->top[top]; | ||
610 | for (dir = 0; dir < EHEA_MAP_ENTRIES; dir++) { | ||
611 | struct ehea_dir_bmap *ehea_dir; | ||
612 | int valid_entries = 0; | ||
613 | |||
614 | if (!ehea_top->dir[dir]) | ||
615 | continue; | ||
616 | valid_dir_entries++; | ||
617 | ehea_dir = ehea_top->dir[dir]; | ||
618 | for (idx = 0; idx < EHEA_MAP_ENTRIES; idx++) { | ||
619 | if (!ehea_dir->ent[idx]) | ||
620 | continue; | ||
621 | valid_entries++; | ||
622 | ehea_dir->ent[idx] = vaddr; | ||
623 | vaddr += EHEA_SECTSIZE; | ||
624 | } | ||
625 | if (!valid_entries) { | ||
626 | ehea_top->dir[dir] = NULL; | ||
627 | kfree(ehea_dir); | ||
628 | } | ||
629 | } | ||
630 | if (!valid_dir_entries) { | ||
631 | ehea_bmap->top[top] = NULL; | ||
632 | kfree(ehea_top); | ||
633 | } | ||
634 | } | ||
635 | } | ||
636 | |||
637 | static int ehea_update_busmap(unsigned long pfn, unsigned long nr_pages, int add) | ||
638 | { | ||
639 | unsigned long i, start_section, end_section; | ||
640 | |||
641 | if (!nr_pages) | ||
642 | return 0; | ||
643 | |||
644 | if (!ehea_bmap) { | ||
645 | ehea_bmap = kzalloc(sizeof(struct ehea_bmap), GFP_KERNEL); | ||
646 | if (!ehea_bmap) | ||
647 | return -ENOMEM; | ||
648 | } | ||
649 | |||
650 | start_section = (pfn * PAGE_SIZE) / EHEA_SECTSIZE; | ||
651 | end_section = start_section + ((nr_pages * PAGE_SIZE) / EHEA_SECTSIZE); | ||
652 | /* Mark entries as valid or invalid only; address is assigned later */ | ||
653 | for (i = start_section; i < end_section; i++) { | ||
654 | u64 flag; | ||
655 | int top = ehea_calc_index(i, EHEA_TOP_INDEX_SHIFT); | ||
656 | int dir = ehea_calc_index(i, EHEA_DIR_INDEX_SHIFT); | ||
657 | int idx = i & EHEA_INDEX_MASK; | ||
658 | |||
659 | if (add) { | ||
660 | int ret = ehea_init_bmap(ehea_bmap, top, dir); | ||
661 | if (ret) | ||
662 | return ret; | ||
663 | flag = 1; /* valid */ | ||
664 | ehea_mr_len += EHEA_SECTSIZE; | ||
665 | } else { | ||
666 | if (!ehea_bmap->top[top]) | ||
667 | continue; | ||
668 | if (!ehea_bmap->top[top]->dir[dir]) | ||
669 | continue; | ||
670 | flag = 0; /* invalid */ | ||
671 | ehea_mr_len -= EHEA_SECTSIZE; | ||
672 | } | ||
673 | |||
674 | ehea_bmap->top[top]->dir[dir]->ent[idx] = flag; | ||
675 | } | ||
676 | ehea_rebuild_busmap(); /* Assign contiguous addresses for mr */ | ||
677 | return 0; | ||
678 | } | ||
679 | |||
680 | int ehea_add_sect_bmap(unsigned long pfn, unsigned long nr_pages) | ||
681 | { | ||
682 | int ret; | ||
683 | |||
684 | mutex_lock(&ehea_busmap_mutex); | ||
685 | ret = ehea_update_busmap(pfn, nr_pages, EHEA_BUSMAP_ADD_SECT); | ||
686 | mutex_unlock(&ehea_busmap_mutex); | ||
687 | return ret; | ||
688 | } | ||
689 | |||
690 | int ehea_rem_sect_bmap(unsigned long pfn, unsigned long nr_pages) | ||
691 | { | ||
692 | int ret; | ||
693 | |||
694 | mutex_lock(&ehea_busmap_mutex); | ||
695 | ret = ehea_update_busmap(pfn, nr_pages, EHEA_BUSMAP_REM_SECT); | ||
696 | mutex_unlock(&ehea_busmap_mutex); | ||
697 | return ret; | ||
698 | } | ||
699 | |||
700 | static int ehea_is_hugepage(unsigned long pfn) | ||
701 | { | ||
702 | int page_order; | ||
703 | |||
704 | if (pfn & EHEA_HUGEPAGE_PFN_MASK) | ||
705 | return 0; | ||
706 | |||
707 | page_order = compound_order(pfn_to_page(pfn)); | ||
708 | if (page_order + PAGE_SHIFT != EHEA_HUGEPAGESHIFT) | ||
709 | return 0; | ||
710 | |||
711 | return 1; | ||
712 | } | ||
713 | |||
714 | static int ehea_create_busmap_callback(unsigned long initial_pfn, | ||
715 | unsigned long total_nr_pages, void *arg) | ||
716 | { | ||
717 | int ret; | ||
718 | unsigned long pfn, start_pfn, end_pfn, nr_pages; | ||
719 | |||
720 | if ((total_nr_pages * PAGE_SIZE) < EHEA_HUGEPAGE_SIZE) | ||
721 | return ehea_update_busmap(initial_pfn, total_nr_pages, | ||
722 | EHEA_BUSMAP_ADD_SECT); | ||
723 | |||
724 | /* Given chunk is >= 16GB -> check for hugepages */ | ||
725 | start_pfn = initial_pfn; | ||
726 | end_pfn = initial_pfn + total_nr_pages; | ||
727 | pfn = start_pfn; | ||
728 | |||
729 | while (pfn < end_pfn) { | ||
730 | if (ehea_is_hugepage(pfn)) { | ||
731 | /* Add mem found in front of the hugepage */ | ||
732 | nr_pages = pfn - start_pfn; | ||
733 | ret = ehea_update_busmap(start_pfn, nr_pages, | ||
734 | EHEA_BUSMAP_ADD_SECT); | ||
735 | if (ret) | ||
736 | return ret; | ||
737 | |||
738 | /* Skip the hugepage */ | ||
739 | pfn += (EHEA_HUGEPAGE_SIZE / PAGE_SIZE); | ||
740 | start_pfn = pfn; | ||
741 | } else | ||
742 | pfn += (EHEA_SECTSIZE / PAGE_SIZE); | ||
743 | } | ||
744 | |||
745 | /* Add mem found behind the hugepage(s) */ | ||
746 | nr_pages = pfn - start_pfn; | ||
747 | return ehea_update_busmap(start_pfn, nr_pages, EHEA_BUSMAP_ADD_SECT); | ||
748 | } | ||
749 | |||
750 | int ehea_create_busmap(void) | ||
751 | { | ||
752 | int ret; | ||
753 | |||
754 | mutex_lock(&ehea_busmap_mutex); | ||
755 | ehea_mr_len = 0; | ||
756 | ret = walk_system_ram_range(0, 1ULL << MAX_PHYSMEM_BITS, NULL, | ||
757 | ehea_create_busmap_callback); | ||
758 | mutex_unlock(&ehea_busmap_mutex); | ||
759 | return ret; | ||
760 | } | ||
761 | |||
762 | void ehea_destroy_busmap(void) | ||
763 | { | ||
764 | int top, dir; | ||
765 | mutex_lock(&ehea_busmap_mutex); | ||
766 | if (!ehea_bmap) | ||
767 | goto out_destroy; | ||
768 | |||
769 | for (top = 0; top < EHEA_MAP_ENTRIES; top++) { | ||
770 | if (!ehea_bmap->top[top]) | ||
771 | continue; | ||
772 | |||
773 | for (dir = 0; dir < EHEA_MAP_ENTRIES; dir++) { | ||
774 | if (!ehea_bmap->top[top]->dir[dir]) | ||
775 | continue; | ||
776 | |||
777 | kfree(ehea_bmap->top[top]->dir[dir]); | ||
778 | } | ||
779 | |||
780 | kfree(ehea_bmap->top[top]); | ||
781 | } | ||
782 | |||
783 | kfree(ehea_bmap); | ||
784 | ehea_bmap = NULL; | ||
785 | out_destroy: | ||
786 | mutex_unlock(&ehea_busmap_mutex); | ||
787 | } | ||
788 | |||
789 | u64 ehea_map_vaddr(void *caddr) | ||
790 | { | ||
791 | int top, dir, idx; | ||
792 | unsigned long index, offset; | ||
793 | |||
794 | if (!ehea_bmap) | ||
795 | return EHEA_INVAL_ADDR; | ||
796 | |||
797 | index = virt_to_abs(caddr) >> SECTION_SIZE_BITS; | ||
798 | top = (index >> EHEA_TOP_INDEX_SHIFT) & EHEA_INDEX_MASK; | ||
799 | if (!ehea_bmap->top[top]) | ||
800 | return EHEA_INVAL_ADDR; | ||
801 | |||
802 | dir = (index >> EHEA_DIR_INDEX_SHIFT) & EHEA_INDEX_MASK; | ||
803 | if (!ehea_bmap->top[top]->dir[dir]) | ||
804 | return EHEA_INVAL_ADDR; | ||
805 | |||
806 | idx = index & EHEA_INDEX_MASK; | ||
807 | if (!ehea_bmap->top[top]->dir[dir]->ent[idx]) | ||
808 | return EHEA_INVAL_ADDR; | ||
809 | |||
810 | offset = (unsigned long)caddr & (EHEA_SECTSIZE - 1); | ||
811 | return ehea_bmap->top[top]->dir[dir]->ent[idx] | offset; | ||
812 | } | ||
813 | |||
814 | static inline void *ehea_calc_sectbase(int top, int dir, int idx) | ||
815 | { | ||
816 | unsigned long ret = idx; | ||
817 | ret |= dir << EHEA_DIR_INDEX_SHIFT; | ||
818 | ret |= top << EHEA_TOP_INDEX_SHIFT; | ||
819 | return abs_to_virt(ret << SECTION_SIZE_BITS); | ||
820 | } | ||
821 | |||
822 | static u64 ehea_reg_mr_section(int top, int dir, int idx, u64 *pt, | ||
823 | struct ehea_adapter *adapter, | ||
824 | struct ehea_mr *mr) | ||
825 | { | ||
826 | void *pg; | ||
827 | u64 j, m, hret; | ||
828 | unsigned long k = 0; | ||
829 | u64 pt_abs = virt_to_abs(pt); | ||
830 | |||
831 | void *sectbase = ehea_calc_sectbase(top, dir, idx); | ||
832 | |||
833 | for (j = 0; j < (EHEA_PAGES_PER_SECTION / EHEA_MAX_RPAGE); j++) { | ||
834 | |||
835 | for (m = 0; m < EHEA_MAX_RPAGE; m++) { | ||
836 | pg = sectbase + ((k++) * EHEA_PAGESIZE); | ||
837 | pt[m] = virt_to_abs(pg); | ||
838 | } | ||
839 | hret = ehea_h_register_rpage_mr(adapter->handle, mr->handle, 0, | ||
840 | 0, pt_abs, EHEA_MAX_RPAGE); | ||
841 | |||
842 | if ((hret != H_SUCCESS) && | ||
843 | (hret != H_PAGE_REGISTERED)) { | ||
844 | ehea_h_free_resource(adapter->handle, mr->handle, | ||
845 | FORCE_FREE); | ||
846 | pr_err("register_rpage_mr failed\n"); | ||
847 | return hret; | ||
848 | } | ||
849 | } | ||
850 | return hret; | ||
851 | } | ||
852 | |||
853 | static u64 ehea_reg_mr_sections(int top, int dir, u64 *pt, | ||
854 | struct ehea_adapter *adapter, | ||
855 | struct ehea_mr *mr) | ||
856 | { | ||
857 | u64 hret = H_SUCCESS; | ||
858 | int idx; | ||
859 | |||
860 | for (idx = 0; idx < EHEA_MAP_ENTRIES; idx++) { | ||
861 | if (!ehea_bmap->top[top]->dir[dir]->ent[idx]) | ||
862 | continue; | ||
863 | |||
864 | hret = ehea_reg_mr_section(top, dir, idx, pt, adapter, mr); | ||
865 | if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED)) | ||
866 | return hret; | ||
867 | } | ||
868 | return hret; | ||
869 | } | ||
870 | |||
871 | static u64 ehea_reg_mr_dir_sections(int top, u64 *pt, | ||
872 | struct ehea_adapter *adapter, | ||
873 | struct ehea_mr *mr) | ||
874 | { | ||
875 | u64 hret = H_SUCCESS; | ||
876 | int dir; | ||
877 | |||
878 | for (dir = 0; dir < EHEA_MAP_ENTRIES; dir++) { | ||
879 | if (!ehea_bmap->top[top]->dir[dir]) | ||
880 | continue; | ||
881 | |||
882 | hret = ehea_reg_mr_sections(top, dir, pt, adapter, mr); | ||
883 | if ((hret != H_SUCCESS) && (hret != H_PAGE_REGISTERED)) | ||
884 | return hret; | ||
885 | } | ||
886 | return hret; | ||
887 | } | ||
888 | |||
889 | int ehea_reg_kernel_mr(struct ehea_adapter *adapter, struct ehea_mr *mr) | ||
890 | { | ||
891 | int ret; | ||
892 | u64 *pt; | ||
893 | u64 hret; | ||
894 | u32 acc_ctrl = EHEA_MR_ACC_CTRL; | ||
895 | |||
896 | unsigned long top; | ||
897 | |||
898 | pt = (void *)get_zeroed_page(GFP_KERNEL); | ||
899 | if (!pt) { | ||
900 | pr_err("no mem\n"); | ||
901 | ret = -ENOMEM; | ||
902 | goto out; | ||
903 | } | ||
904 | |||
905 | hret = ehea_h_alloc_resource_mr(adapter->handle, EHEA_BUSMAP_START, | ||
906 | ehea_mr_len, acc_ctrl, adapter->pd, | ||
907 | &mr->handle, &mr->lkey); | ||
908 | |||
909 | if (hret != H_SUCCESS) { | ||
910 | pr_err("alloc_resource_mr failed\n"); | ||
911 | ret = -EIO; | ||
912 | goto out; | ||
913 | } | ||
914 | |||
915 | if (!ehea_bmap) { | ||
916 | ehea_h_free_resource(adapter->handle, mr->handle, FORCE_FREE); | ||
917 | pr_err("no busmap available\n"); | ||
918 | ret = -EIO; | ||
919 | goto out; | ||
920 | } | ||
921 | |||
922 | for (top = 0; top < EHEA_MAP_ENTRIES; top++) { | ||
923 | if (!ehea_bmap->top[top]) | ||
924 | continue; | ||
925 | |||
926 | hret = ehea_reg_mr_dir_sections(top, pt, adapter, mr); | ||
927 | if((hret != H_PAGE_REGISTERED) && (hret != H_SUCCESS)) | ||
928 | break; | ||
929 | } | ||
930 | |||
931 | if (hret != H_SUCCESS) { | ||
932 | ehea_h_free_resource(adapter->handle, mr->handle, FORCE_FREE); | ||
933 | pr_err("registering mr failed\n"); | ||
934 | ret = -EIO; | ||
935 | goto out; | ||
936 | } | ||
937 | |||
938 | mr->vaddr = EHEA_BUSMAP_START; | ||
939 | mr->adapter = adapter; | ||
940 | ret = 0; | ||
941 | out: | ||
942 | free_page((unsigned long)pt); | ||
943 | return ret; | ||
944 | } | ||
945 | |||
946 | int ehea_rem_mr(struct ehea_mr *mr) | ||
947 | { | ||
948 | u64 hret; | ||
949 | |||
950 | if (!mr || !mr->adapter) | ||
951 | return -EINVAL; | ||
952 | |||
953 | hret = ehea_h_free_resource(mr->adapter->handle, mr->handle, | ||
954 | FORCE_FREE); | ||
955 | if (hret != H_SUCCESS) { | ||
956 | pr_err("destroy MR failed\n"); | ||
957 | return -EIO; | ||
958 | } | ||
959 | |||
960 | return 0; | ||
961 | } | ||
962 | |||
963 | int ehea_gen_smr(struct ehea_adapter *adapter, struct ehea_mr *old_mr, | ||
964 | struct ehea_mr *shared_mr) | ||
965 | { | ||
966 | u64 hret; | ||
967 | |||
968 | hret = ehea_h_register_smr(adapter->handle, old_mr->handle, | ||
969 | old_mr->vaddr, EHEA_MR_ACC_CTRL, | ||
970 | adapter->pd, shared_mr); | ||
971 | if (hret != H_SUCCESS) | ||
972 | return -EIO; | ||
973 | |||
974 | shared_mr->adapter = adapter; | ||
975 | |||
976 | return 0; | ||
977 | } | ||
978 | |||
979 | void print_error_data(u64 *data) | ||
980 | { | ||
981 | int length; | ||
982 | u64 type = EHEA_BMASK_GET(ERROR_DATA_TYPE, data[2]); | ||
983 | u64 resource = data[1]; | ||
984 | |||
985 | length = EHEA_BMASK_GET(ERROR_DATA_LENGTH, data[0]); | ||
986 | |||
987 | if (length > EHEA_PAGESIZE) | ||
988 | length = EHEA_PAGESIZE; | ||
989 | |||
990 | if (type == EHEA_AER_RESTYPE_QP) | ||
991 | pr_err("QP (resource=%llX) state: AER=0x%llX, AERR=0x%llX, port=%llX\n", | ||
992 | resource, data[6], data[12], data[22]); | ||
993 | else if (type == EHEA_AER_RESTYPE_CQ) | ||
994 | pr_err("CQ (resource=%llX) state: AER=0x%llX\n", | ||
995 | resource, data[6]); | ||
996 | else if (type == EHEA_AER_RESTYPE_EQ) | ||
997 | pr_err("EQ (resource=%llX) state: AER=0x%llX\n", | ||
998 | resource, data[6]); | ||
999 | |||
1000 | ehea_dump(data, length, "error data"); | ||
1001 | } | ||
1002 | |||
1003 | u64 ehea_error_data(struct ehea_adapter *adapter, u64 res_handle, | ||
1004 | u64 *aer, u64 *aerr) | ||
1005 | { | ||
1006 | unsigned long ret; | ||
1007 | u64 *rblock; | ||
1008 | u64 type = 0; | ||
1009 | |||
1010 | rblock = (void *)get_zeroed_page(GFP_KERNEL); | ||
1011 | if (!rblock) { | ||
1012 | pr_err("Cannot allocate rblock memory\n"); | ||
1013 | goto out; | ||
1014 | } | ||
1015 | |||
1016 | ret = ehea_h_error_data(adapter->handle, res_handle, rblock); | ||
1017 | |||
1018 | if (ret == H_SUCCESS) { | ||
1019 | type = EHEA_BMASK_GET(ERROR_DATA_TYPE, rblock[2]); | ||
1020 | *aer = rblock[6]; | ||
1021 | *aerr = rblock[12]; | ||
1022 | print_error_data(rblock); | ||
1023 | } else if (ret == H_R_STATE) { | ||
1024 | pr_err("No error data available: %llX\n", res_handle); | ||
1025 | } else | ||
1026 | pr_err("Error data could not be fetched: %llX\n", res_handle); | ||
1027 | |||
1028 | free_page((unsigned long)rblock); | ||
1029 | out: | ||
1030 | return type; | ||
1031 | } | ||
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_qmr.h b/drivers/net/ethernet/ibm/ehea/ehea_qmr.h new file mode 100644 index 000000000000..fddff8ec8cfd --- /dev/null +++ b/drivers/net/ethernet/ibm/ehea/ehea_qmr.h | |||
@@ -0,0 +1,404 @@ | |||
1 | /* | ||
2 | * linux/drivers/net/ehea/ehea_qmr.h | ||
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 | #ifndef __EHEA_QMR_H__ | ||
30 | #define __EHEA_QMR_H__ | ||
31 | |||
32 | #include <linux/prefetch.h> | ||
33 | #include "ehea.h" | ||
34 | #include "ehea_hw.h" | ||
35 | |||
36 | /* | ||
37 | * page size of ehea hardware queues | ||
38 | */ | ||
39 | |||
40 | #define EHEA_PAGESHIFT 12 | ||
41 | #define EHEA_PAGESIZE (1UL << EHEA_PAGESHIFT) | ||
42 | #define EHEA_SECTSIZE (1UL << 24) | ||
43 | #define EHEA_PAGES_PER_SECTION (EHEA_SECTSIZE >> EHEA_PAGESHIFT) | ||
44 | #define EHEA_HUGEPAGESHIFT 34 | ||
45 | #define EHEA_HUGEPAGE_SIZE (1UL << EHEA_HUGEPAGESHIFT) | ||
46 | #define EHEA_HUGEPAGE_PFN_MASK ((EHEA_HUGEPAGE_SIZE - 1) >> PAGE_SHIFT) | ||
47 | |||
48 | #if ((1UL << SECTION_SIZE_BITS) < EHEA_SECTSIZE) | ||
49 | #error eHEA module cannot work if kernel sectionsize < ehea sectionsize | ||
50 | #endif | ||
51 | |||
52 | /* Some abbreviations used here: | ||
53 | * | ||
54 | * WQE - Work Queue Entry | ||
55 | * SWQE - Send Work Queue Entry | ||
56 | * RWQE - Receive Work Queue Entry | ||
57 | * CQE - Completion Queue Entry | ||
58 | * EQE - Event Queue Entry | ||
59 | * MR - Memory Region | ||
60 | */ | ||
61 | |||
62 | /* Use of WR_ID field for EHEA */ | ||
63 | #define EHEA_WR_ID_COUNT EHEA_BMASK_IBM(0, 19) | ||
64 | #define EHEA_WR_ID_TYPE EHEA_BMASK_IBM(20, 23) | ||
65 | #define EHEA_SWQE2_TYPE 0x1 | ||
66 | #define EHEA_SWQE3_TYPE 0x2 | ||
67 | #define EHEA_RWQE2_TYPE 0x3 | ||
68 | #define EHEA_RWQE3_TYPE 0x4 | ||
69 | #define EHEA_WR_ID_INDEX EHEA_BMASK_IBM(24, 47) | ||
70 | #define EHEA_WR_ID_REFILL EHEA_BMASK_IBM(48, 63) | ||
71 | |||
72 | struct ehea_vsgentry { | ||
73 | u64 vaddr; | ||
74 | u32 l_key; | ||
75 | u32 len; | ||
76 | }; | ||
77 | |||
78 | /* maximum number of sg entries allowed in a WQE */ | ||
79 | #define EHEA_MAX_WQE_SG_ENTRIES 252 | ||
80 | #define SWQE2_MAX_IMM (0xD0 - 0x30) | ||
81 | #define SWQE3_MAX_IMM 224 | ||
82 | |||
83 | /* tx control flags for swqe */ | ||
84 | #define EHEA_SWQE_CRC 0x8000 | ||
85 | #define EHEA_SWQE_IP_CHECKSUM 0x4000 | ||
86 | #define EHEA_SWQE_TCP_CHECKSUM 0x2000 | ||
87 | #define EHEA_SWQE_TSO 0x1000 | ||
88 | #define EHEA_SWQE_SIGNALLED_COMPLETION 0x0800 | ||
89 | #define EHEA_SWQE_VLAN_INSERT 0x0400 | ||
90 | #define EHEA_SWQE_IMM_DATA_PRESENT 0x0200 | ||
91 | #define EHEA_SWQE_DESCRIPTORS_PRESENT 0x0100 | ||
92 | #define EHEA_SWQE_WRAP_CTL_REC 0x0080 | ||
93 | #define EHEA_SWQE_WRAP_CTL_FORCE 0x0040 | ||
94 | #define EHEA_SWQE_BIND 0x0020 | ||
95 | #define EHEA_SWQE_PURGE 0x0010 | ||
96 | |||
97 | /* sizeof(struct ehea_swqe) less the union */ | ||
98 | #define SWQE_HEADER_SIZE 32 | ||
99 | |||
100 | struct ehea_swqe { | ||
101 | u64 wr_id; | ||
102 | u16 tx_control; | ||
103 | u16 vlan_tag; | ||
104 | u8 reserved1; | ||
105 | u8 ip_start; | ||
106 | u8 ip_end; | ||
107 | u8 immediate_data_length; | ||
108 | u8 tcp_offset; | ||
109 | u8 reserved2; | ||
110 | u16 tcp_end; | ||
111 | u8 wrap_tag; | ||
112 | u8 descriptors; /* number of valid descriptors in WQE */ | ||
113 | u16 reserved3; | ||
114 | u16 reserved4; | ||
115 | u16 mss; | ||
116 | u32 reserved5; | ||
117 | union { | ||
118 | /* Send WQE Format 1 */ | ||
119 | struct { | ||
120 | struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES]; | ||
121 | } no_immediate_data; | ||
122 | |||
123 | /* Send WQE Format 2 */ | ||
124 | struct { | ||
125 | struct ehea_vsgentry sg_entry; | ||
126 | /* 0x30 */ | ||
127 | u8 immediate_data[SWQE2_MAX_IMM]; | ||
128 | /* 0xd0 */ | ||
129 | struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES-1]; | ||
130 | } immdata_desc __packed; | ||
131 | |||
132 | /* Send WQE Format 3 */ | ||
133 | struct { | ||
134 | u8 immediate_data[SWQE3_MAX_IMM]; | ||
135 | } immdata_nodesc; | ||
136 | } u; | ||
137 | }; | ||
138 | |||
139 | struct ehea_rwqe { | ||
140 | u64 wr_id; /* work request ID */ | ||
141 | u8 reserved1[5]; | ||
142 | u8 data_segments; | ||
143 | u16 reserved2; | ||
144 | u64 reserved3; | ||
145 | u64 reserved4; | ||
146 | struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES]; | ||
147 | }; | ||
148 | |||
149 | #define EHEA_CQE_VLAN_TAG_XTRACT 0x0400 | ||
150 | |||
151 | #define EHEA_CQE_TYPE_RQ 0x60 | ||
152 | #define EHEA_CQE_STAT_ERR_MASK 0x700F | ||
153 | #define EHEA_CQE_STAT_FAT_ERR_MASK 0xF | ||
154 | #define EHEA_CQE_BLIND_CKSUM 0x8000 | ||
155 | #define EHEA_CQE_STAT_ERR_TCP 0x4000 | ||
156 | #define EHEA_CQE_STAT_ERR_IP 0x2000 | ||
157 | #define EHEA_CQE_STAT_ERR_CRC 0x1000 | ||
158 | |||
159 | /* Defines which bad send cqe stati lead to a port reset */ | ||
160 | #define EHEA_CQE_STAT_RESET_MASK 0x0002 | ||
161 | |||
162 | struct ehea_cqe { | ||
163 | u64 wr_id; /* work request ID from WQE */ | ||
164 | u8 type; | ||
165 | u8 valid; | ||
166 | u16 status; | ||
167 | u16 reserved1; | ||
168 | u16 num_bytes_transfered; | ||
169 | u16 vlan_tag; | ||
170 | u16 inet_checksum_value; | ||
171 | u8 reserved2; | ||
172 | u8 header_length; | ||
173 | u16 reserved3; | ||
174 | u16 page_offset; | ||
175 | u16 wqe_count; | ||
176 | u32 qp_token; | ||
177 | u32 timestamp; | ||
178 | u32 reserved4; | ||
179 | u64 reserved5[3]; | ||
180 | }; | ||
181 | |||
182 | #define EHEA_EQE_VALID EHEA_BMASK_IBM(0, 0) | ||
183 | #define EHEA_EQE_IS_CQE EHEA_BMASK_IBM(1, 1) | ||
184 | #define EHEA_EQE_IDENTIFIER EHEA_BMASK_IBM(2, 7) | ||
185 | #define EHEA_EQE_QP_CQ_NUMBER EHEA_BMASK_IBM(8, 31) | ||
186 | #define EHEA_EQE_QP_TOKEN EHEA_BMASK_IBM(32, 63) | ||
187 | #define EHEA_EQE_CQ_TOKEN EHEA_BMASK_IBM(32, 63) | ||
188 | #define EHEA_EQE_KEY EHEA_BMASK_IBM(32, 63) | ||
189 | #define EHEA_EQE_PORT_NUMBER EHEA_BMASK_IBM(56, 63) | ||
190 | #define EHEA_EQE_EQ_NUMBER EHEA_BMASK_IBM(48, 63) | ||
191 | #define EHEA_EQE_SM_ID EHEA_BMASK_IBM(48, 63) | ||
192 | #define EHEA_EQE_SM_MECH_NUMBER EHEA_BMASK_IBM(48, 55) | ||
193 | #define EHEA_EQE_SM_PORT_NUMBER EHEA_BMASK_IBM(56, 63) | ||
194 | |||
195 | #define EHEA_AER_RESTYPE_QP 0x8 | ||
196 | #define EHEA_AER_RESTYPE_CQ 0x4 | ||
197 | #define EHEA_AER_RESTYPE_EQ 0x3 | ||
198 | |||
199 | /* Defines which affiliated errors lead to a port reset */ | ||
200 | #define EHEA_AER_RESET_MASK 0xFFFFFFFFFEFFFFFFULL | ||
201 | #define EHEA_AERR_RESET_MASK 0xFFFFFFFFFFFFFFFFULL | ||
202 | |||
203 | struct ehea_eqe { | ||
204 | u64 entry; | ||
205 | }; | ||
206 | |||
207 | #define ERROR_DATA_LENGTH EHEA_BMASK_IBM(52, 63) | ||
208 | #define ERROR_DATA_TYPE EHEA_BMASK_IBM(0, 7) | ||
209 | |||
210 | static inline void *hw_qeit_calc(struct hw_queue *queue, u64 q_offset) | ||
211 | { | ||
212 | struct ehea_page *current_page; | ||
213 | |||
214 | if (q_offset >= queue->queue_length) | ||
215 | q_offset -= queue->queue_length; | ||
216 | current_page = (queue->queue_pages)[q_offset >> EHEA_PAGESHIFT]; | ||
217 | return ¤t_page->entries[q_offset & (EHEA_PAGESIZE - 1)]; | ||
218 | } | ||
219 | |||
220 | static inline void *hw_qeit_get(struct hw_queue *queue) | ||
221 | { | ||
222 | return hw_qeit_calc(queue, queue->current_q_offset); | ||
223 | } | ||
224 | |||
225 | static inline void hw_qeit_inc(struct hw_queue *queue) | ||
226 | { | ||
227 | queue->current_q_offset += queue->qe_size; | ||
228 | if (queue->current_q_offset >= queue->queue_length) { | ||
229 | queue->current_q_offset = 0; | ||
230 | /* toggle the valid flag */ | ||
231 | queue->toggle_state = (~queue->toggle_state) & 1; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | static inline void *hw_qeit_get_inc(struct hw_queue *queue) | ||
236 | { | ||
237 | void *retvalue = hw_qeit_get(queue); | ||
238 | hw_qeit_inc(queue); | ||
239 | return retvalue; | ||
240 | } | ||
241 | |||
242 | static inline void *hw_qeit_get_inc_valid(struct hw_queue *queue) | ||
243 | { | ||
244 | struct ehea_cqe *retvalue = hw_qeit_get(queue); | ||
245 | u8 valid = retvalue->valid; | ||
246 | void *pref; | ||
247 | |||
248 | if ((valid >> 7) == (queue->toggle_state & 1)) { | ||
249 | /* this is a good one */ | ||
250 | hw_qeit_inc(queue); | ||
251 | pref = hw_qeit_calc(queue, queue->current_q_offset); | ||
252 | prefetch(pref); | ||
253 | prefetch(pref + 128); | ||
254 | } else | ||
255 | retvalue = NULL; | ||
256 | return retvalue; | ||
257 | } | ||
258 | |||
259 | static inline void *hw_qeit_get_valid(struct hw_queue *queue) | ||
260 | { | ||
261 | struct ehea_cqe *retvalue = hw_qeit_get(queue); | ||
262 | void *pref; | ||
263 | u8 valid; | ||
264 | |||
265 | pref = hw_qeit_calc(queue, queue->current_q_offset); | ||
266 | prefetch(pref); | ||
267 | prefetch(pref + 128); | ||
268 | prefetch(pref + 256); | ||
269 | valid = retvalue->valid; | ||
270 | if (!((valid >> 7) == (queue->toggle_state & 1))) | ||
271 | retvalue = NULL; | ||
272 | return retvalue; | ||
273 | } | ||
274 | |||
275 | static inline void *hw_qeit_reset(struct hw_queue *queue) | ||
276 | { | ||
277 | queue->current_q_offset = 0; | ||
278 | return hw_qeit_get(queue); | ||
279 | } | ||
280 | |||
281 | static inline void *hw_qeit_eq_get_inc(struct hw_queue *queue) | ||
282 | { | ||
283 | u64 last_entry_in_q = queue->queue_length - queue->qe_size; | ||
284 | void *retvalue; | ||
285 | |||
286 | retvalue = hw_qeit_get(queue); | ||
287 | queue->current_q_offset += queue->qe_size; | ||
288 | if (queue->current_q_offset > last_entry_in_q) { | ||
289 | queue->current_q_offset = 0; | ||
290 | queue->toggle_state = (~queue->toggle_state) & 1; | ||
291 | } | ||
292 | return retvalue; | ||
293 | } | ||
294 | |||
295 | static inline void *hw_eqit_eq_get_inc_valid(struct hw_queue *queue) | ||
296 | { | ||
297 | void *retvalue = hw_qeit_get(queue); | ||
298 | u32 qe = *(u8 *)retvalue; | ||
299 | if ((qe >> 7) == (queue->toggle_state & 1)) | ||
300 | hw_qeit_eq_get_inc(queue); | ||
301 | else | ||
302 | retvalue = NULL; | ||
303 | return retvalue; | ||
304 | } | ||
305 | |||
306 | static inline struct ehea_rwqe *ehea_get_next_rwqe(struct ehea_qp *qp, | ||
307 | int rq_nr) | ||
308 | { | ||
309 | struct hw_queue *queue; | ||
310 | |||
311 | if (rq_nr == 1) | ||
312 | queue = &qp->hw_rqueue1; | ||
313 | else if (rq_nr == 2) | ||
314 | queue = &qp->hw_rqueue2; | ||
315 | else | ||
316 | queue = &qp->hw_rqueue3; | ||
317 | |||
318 | return hw_qeit_get_inc(queue); | ||
319 | } | ||
320 | |||
321 | static inline struct ehea_swqe *ehea_get_swqe(struct ehea_qp *my_qp, | ||
322 | int *wqe_index) | ||
323 | { | ||
324 | struct hw_queue *queue = &my_qp->hw_squeue; | ||
325 | struct ehea_swqe *wqe_p; | ||
326 | |||
327 | *wqe_index = (queue->current_q_offset) >> (7 + EHEA_SG_SQ); | ||
328 | wqe_p = hw_qeit_get_inc(&my_qp->hw_squeue); | ||
329 | |||
330 | return wqe_p; | ||
331 | } | ||
332 | |||
333 | static inline void ehea_post_swqe(struct ehea_qp *my_qp, struct ehea_swqe *swqe) | ||
334 | { | ||
335 | iosync(); | ||
336 | ehea_update_sqa(my_qp, 1); | ||
337 | } | ||
338 | |||
339 | static inline struct ehea_cqe *ehea_poll_rq1(struct ehea_qp *qp, int *wqe_index) | ||
340 | { | ||
341 | struct hw_queue *queue = &qp->hw_rqueue1; | ||
342 | |||
343 | *wqe_index = (queue->current_q_offset) >> (7 + EHEA_SG_RQ1); | ||
344 | return hw_qeit_get_valid(queue); | ||
345 | } | ||
346 | |||
347 | static inline void ehea_inc_cq(struct ehea_cq *cq) | ||
348 | { | ||
349 | hw_qeit_inc(&cq->hw_queue); | ||
350 | } | ||
351 | |||
352 | static inline void ehea_inc_rq1(struct ehea_qp *qp) | ||
353 | { | ||
354 | hw_qeit_inc(&qp->hw_rqueue1); | ||
355 | } | ||
356 | |||
357 | static inline struct ehea_cqe *ehea_poll_cq(struct ehea_cq *my_cq) | ||
358 | { | ||
359 | return hw_qeit_get_valid(&my_cq->hw_queue); | ||
360 | } | ||
361 | |||
362 | #define EHEA_CQ_REGISTER_ORIG 0 | ||
363 | #define EHEA_EQ_REGISTER_ORIG 0 | ||
364 | |||
365 | enum ehea_eq_type { | ||
366 | EHEA_EQ = 0, /* event queue */ | ||
367 | EHEA_NEQ /* notification event queue */ | ||
368 | }; | ||
369 | |||
370 | struct ehea_eq *ehea_create_eq(struct ehea_adapter *adapter, | ||
371 | enum ehea_eq_type type, | ||
372 | const u32 length, const u8 eqe_gen); | ||
373 | |||
374 | int ehea_destroy_eq(struct ehea_eq *eq); | ||
375 | |||
376 | struct ehea_eqe *ehea_poll_eq(struct ehea_eq *eq); | ||
377 | |||
378 | struct ehea_cq *ehea_create_cq(struct ehea_adapter *adapter, int cqe, | ||
379 | u64 eq_handle, u32 cq_token); | ||
380 | |||
381 | int ehea_destroy_cq(struct ehea_cq *cq); | ||
382 | |||
383 | struct ehea_qp *ehea_create_qp(struct ehea_adapter *adapter, u32 pd, | ||
384 | struct ehea_qp_init_attr *init_attr); | ||
385 | |||
386 | int ehea_destroy_qp(struct ehea_qp *qp); | ||
387 | |||
388 | int ehea_reg_kernel_mr(struct ehea_adapter *adapter, struct ehea_mr *mr); | ||
389 | |||
390 | int ehea_gen_smr(struct ehea_adapter *adapter, struct ehea_mr *old_mr, | ||
391 | struct ehea_mr *shared_mr); | ||
392 | |||
393 | int ehea_rem_mr(struct ehea_mr *mr); | ||
394 | |||
395 | u64 ehea_error_data(struct ehea_adapter *adapter, u64 res_handle, | ||
396 | u64 *aer, u64 *aerr); | ||
397 | |||
398 | int ehea_add_sect_bmap(unsigned long pfn, unsigned long nr_pages); | ||
399 | int ehea_rem_sect_bmap(unsigned long pfn, unsigned long nr_pages); | ||
400 | int ehea_create_busmap(void); | ||
401 | void ehea_destroy_busmap(void); | ||
402 | u64 ehea_map_vaddr(void *caddr); | ||
403 | |||
404 | #endif /* __EHEA_QMR_H__ */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/Kconfig b/drivers/net/ethernet/ibm/emac/Kconfig new file mode 100644 index 000000000000..3f44a30e0615 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/Kconfig | |||
@@ -0,0 +1,76 @@ | |||
1 | config IBM_EMAC | ||
2 | tristate "IBM EMAC Ethernet support" | ||
3 | depends on PPC_DCR | ||
4 | select CRC32 | ||
5 | help | ||
6 | This driver supports the IBM EMAC family of Ethernet controllers | ||
7 | typically found on 4xx embedded PowerPC chips, but also on the | ||
8 | Axon southbridge for Cell. | ||
9 | |||
10 | config IBM_EMAC_RXB | ||
11 | int "Number of receive buffers" | ||
12 | depends on IBM_EMAC | ||
13 | default "128" | ||
14 | |||
15 | config IBM_EMAC_TXB | ||
16 | int "Number of transmit buffers" | ||
17 | depends on IBM_EMAC | ||
18 | default "64" | ||
19 | |||
20 | config IBM_EMAC_POLL_WEIGHT | ||
21 | int "MAL NAPI polling weight" | ||
22 | depends on IBM_EMAC | ||
23 | default "32" | ||
24 | |||
25 | config IBM_EMAC_RX_COPY_THRESHOLD | ||
26 | int "RX skb copy threshold (bytes)" | ||
27 | depends on IBM_EMAC | ||
28 | default "256" | ||
29 | |||
30 | config IBM_EMAC_RX_SKB_HEADROOM | ||
31 | int "Additional RX skb headroom (bytes)" | ||
32 | depends on IBM_EMAC | ||
33 | default "0" | ||
34 | help | ||
35 | Additional receive skb headroom. Note, that driver | ||
36 | will always reserve at least 2 bytes to make IP header | ||
37 | aligned, so usually there is no need to add any additional | ||
38 | headroom. | ||
39 | |||
40 | If unsure, set to 0. | ||
41 | |||
42 | config IBM_EMAC_DEBUG | ||
43 | bool "Debugging" | ||
44 | depends on IBM_EMAC | ||
45 | default n | ||
46 | |||
47 | # The options below has to be select'ed by the respective | ||
48 | # processor types or platforms | ||
49 | |||
50 | config IBM_EMAC_ZMII | ||
51 | bool | ||
52 | default n | ||
53 | |||
54 | config IBM_EMAC_RGMII | ||
55 | bool | ||
56 | default n | ||
57 | |||
58 | config IBM_EMAC_TAH | ||
59 | bool | ||
60 | default n | ||
61 | |||
62 | config IBM_EMAC_EMAC4 | ||
63 | bool | ||
64 | default n | ||
65 | |||
66 | config IBM_EMAC_NO_FLOW_CTRL | ||
67 | bool | ||
68 | default n | ||
69 | |||
70 | config IBM_EMAC_MAL_CLR_ICINTSTAT | ||
71 | bool | ||
72 | default n | ||
73 | |||
74 | config IBM_EMAC_MAL_COMMON_ERR | ||
75 | bool | ||
76 | default n | ||
diff --git a/drivers/net/ethernet/ibm/emac/Makefile b/drivers/net/ethernet/ibm/emac/Makefile new file mode 100644 index 000000000000..0b5c99512762 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | # | ||
2 | # Makefile for the PowerPC 4xx on-chip ethernet driver | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_IBM_NEW_EMAC) += ibm_newemac.o | ||
6 | |||
7 | ibm_newemac-y := mal.o core.o phy.o | ||
8 | ibm_newemac-$(CONFIG_IBM_NEW_EMAC_ZMII) += zmii.o | ||
9 | ibm_newemac-$(CONFIG_IBM_NEW_EMAC_RGMII) += rgmii.o | ||
10 | ibm_newemac-$(CONFIG_IBM_NEW_EMAC_TAH) += tah.o | ||
11 | ibm_newemac-$(CONFIG_IBM_NEW_EMAC_DEBUG) += debug.o | ||
diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c new file mode 100644 index 000000000000..70cb7d8a3b53 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/core.c | |||
@@ -0,0 +1,3074 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/core.c | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * Based on original work by | ||
15 | * Matt Porter <mporter@kernel.crashing.org> | ||
16 | * (c) 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org> | ||
17 | * Armin Kuster <akuster@mvista.com> | ||
18 | * Johnnie Peters <jpeters@mvista.com> | ||
19 | * | ||
20 | * This program is free software; you can redistribute it and/or modify it | ||
21 | * under the terms of the GNU General Public License as published by the | ||
22 | * Free Software Foundation; either version 2 of the License, or (at your | ||
23 | * option) any later version. | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | #include <linux/module.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/string.h> | ||
30 | #include <linux/errno.h> | ||
31 | #include <linux/delay.h> | ||
32 | #include <linux/types.h> | ||
33 | #include <linux/pci.h> | ||
34 | #include <linux/etherdevice.h> | ||
35 | #include <linux/skbuff.h> | ||
36 | #include <linux/crc32.h> | ||
37 | #include <linux/ethtool.h> | ||
38 | #include <linux/mii.h> | ||
39 | #include <linux/bitops.h> | ||
40 | #include <linux/workqueue.h> | ||
41 | #include <linux/of.h> | ||
42 | #include <linux/of_net.h> | ||
43 | #include <linux/slab.h> | ||
44 | |||
45 | #include <asm/processor.h> | ||
46 | #include <asm/io.h> | ||
47 | #include <asm/dma.h> | ||
48 | #include <asm/uaccess.h> | ||
49 | #include <asm/dcr.h> | ||
50 | #include <asm/dcr-regs.h> | ||
51 | |||
52 | #include "core.h" | ||
53 | |||
54 | /* | ||
55 | * Lack of dma_unmap_???? calls is intentional. | ||
56 | * | ||
57 | * API-correct usage requires additional support state information to be | ||
58 | * maintained for every RX and TX buffer descriptor (BD). Unfortunately, due to | ||
59 | * EMAC design (e.g. TX buffer passed from network stack can be split into | ||
60 | * several BDs, dma_map_single/dma_map_page can be used to map particular BD), | ||
61 | * maintaining such information will add additional overhead. | ||
62 | * Current DMA API implementation for 4xx processors only ensures cache coherency | ||
63 | * and dma_unmap_???? routines are empty and are likely to stay this way. | ||
64 | * I decided to omit dma_unmap_??? calls because I don't want to add additional | ||
65 | * complexity just for the sake of following some abstract API, when it doesn't | ||
66 | * add any real benefit to the driver. I understand that this decision maybe | ||
67 | * controversial, but I really tried to make code API-correct and efficient | ||
68 | * at the same time and didn't come up with code I liked :(. --ebs | ||
69 | */ | ||
70 | |||
71 | #define DRV_NAME "emac" | ||
72 | #define DRV_VERSION "3.54" | ||
73 | #define DRV_DESC "PPC 4xx OCP EMAC driver" | ||
74 | |||
75 | MODULE_DESCRIPTION(DRV_DESC); | ||
76 | MODULE_AUTHOR | ||
77 | ("Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>"); | ||
78 | MODULE_LICENSE("GPL"); | ||
79 | |||
80 | /* | ||
81 | * PPC64 doesn't (yet) have a cacheable_memcpy | ||
82 | */ | ||
83 | #ifdef CONFIG_PPC64 | ||
84 | #define cacheable_memcpy(d,s,n) memcpy((d),(s),(n)) | ||
85 | #endif | ||
86 | |||
87 | /* minimum number of free TX descriptors required to wake up TX process */ | ||
88 | #define EMAC_TX_WAKEUP_THRESH (NUM_TX_BUFF / 4) | ||
89 | |||
90 | /* If packet size is less than this number, we allocate small skb and copy packet | ||
91 | * contents into it instead of just sending original big skb up | ||
92 | */ | ||
93 | #define EMAC_RX_COPY_THRESH CONFIG_IBM_NEW_EMAC_RX_COPY_THRESHOLD | ||
94 | |||
95 | /* Since multiple EMACs share MDIO lines in various ways, we need | ||
96 | * to avoid re-using the same PHY ID in cases where the arch didn't | ||
97 | * setup precise phy_map entries | ||
98 | * | ||
99 | * XXX This is something that needs to be reworked as we can have multiple | ||
100 | * EMAC "sets" (multiple ASICs containing several EMACs) though we can | ||
101 | * probably require in that case to have explicit PHY IDs in the device-tree | ||
102 | */ | ||
103 | static u32 busy_phy_map; | ||
104 | static DEFINE_MUTEX(emac_phy_map_lock); | ||
105 | |||
106 | /* This is the wait queue used to wait on any event related to probe, that | ||
107 | * is discovery of MALs, other EMACs, ZMII/RGMIIs, etc... | ||
108 | */ | ||
109 | static DECLARE_WAIT_QUEUE_HEAD(emac_probe_wait); | ||
110 | |||
111 | /* Having stable interface names is a doomed idea. However, it would be nice | ||
112 | * if we didn't have completely random interface names at boot too :-) It's | ||
113 | * just a matter of making everybody's life easier. Since we are doing | ||
114 | * threaded probing, it's a bit harder though. The base idea here is that | ||
115 | * we make up a list of all emacs in the device-tree before we register the | ||
116 | * driver. Every emac will then wait for the previous one in the list to | ||
117 | * initialize before itself. We should also keep that list ordered by | ||
118 | * cell_index. | ||
119 | * That list is only 4 entries long, meaning that additional EMACs don't | ||
120 | * get ordering guarantees unless EMAC_BOOT_LIST_SIZE is increased. | ||
121 | */ | ||
122 | |||
123 | #define EMAC_BOOT_LIST_SIZE 4 | ||
124 | static struct device_node *emac_boot_list[EMAC_BOOT_LIST_SIZE]; | ||
125 | |||
126 | /* How long should I wait for dependent devices ? */ | ||
127 | #define EMAC_PROBE_DEP_TIMEOUT (HZ * 5) | ||
128 | |||
129 | /* I don't want to litter system log with timeout errors | ||
130 | * when we have brain-damaged PHY. | ||
131 | */ | ||
132 | static inline void emac_report_timeout_error(struct emac_instance *dev, | ||
133 | const char *error) | ||
134 | { | ||
135 | if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX | | ||
136 | EMAC_FTR_460EX_PHY_CLK_FIX | | ||
137 | EMAC_FTR_440EP_PHY_CLK_FIX)) | ||
138 | DBG(dev, "%s" NL, error); | ||
139 | else if (net_ratelimit()) | ||
140 | printk(KERN_ERR "%s: %s\n", dev->ofdev->dev.of_node->full_name, | ||
141 | error); | ||
142 | } | ||
143 | |||
144 | /* EMAC PHY clock workaround: | ||
145 | * 440EP/440GR has more sane SDR0_MFR register implementation than 440GX, | ||
146 | * which allows controlling each EMAC clock | ||
147 | */ | ||
148 | static inline void emac_rx_clk_tx(struct emac_instance *dev) | ||
149 | { | ||
150 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
151 | if (emac_has_feature(dev, EMAC_FTR_440EP_PHY_CLK_FIX)) | ||
152 | dcri_clrset(SDR0, SDR0_MFR, | ||
153 | 0, SDR0_MFR_ECS >> dev->cell_index); | ||
154 | #endif | ||
155 | } | ||
156 | |||
157 | static inline void emac_rx_clk_default(struct emac_instance *dev) | ||
158 | { | ||
159 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
160 | if (emac_has_feature(dev, EMAC_FTR_440EP_PHY_CLK_FIX)) | ||
161 | dcri_clrset(SDR0, SDR0_MFR, | ||
162 | SDR0_MFR_ECS >> dev->cell_index, 0); | ||
163 | #endif | ||
164 | } | ||
165 | |||
166 | /* PHY polling intervals */ | ||
167 | #define PHY_POLL_LINK_ON HZ | ||
168 | #define PHY_POLL_LINK_OFF (HZ / 5) | ||
169 | |||
170 | /* Graceful stop timeouts in us. | ||
171 | * We should allow up to 1 frame time (full-duplex, ignoring collisions) | ||
172 | */ | ||
173 | #define STOP_TIMEOUT_10 1230 | ||
174 | #define STOP_TIMEOUT_100 124 | ||
175 | #define STOP_TIMEOUT_1000 13 | ||
176 | #define STOP_TIMEOUT_1000_JUMBO 73 | ||
177 | |||
178 | static unsigned char default_mcast_addr[] = { | ||
179 | 0x01, 0x80, 0xC2, 0x00, 0x00, 0x01 | ||
180 | }; | ||
181 | |||
182 | /* Please, keep in sync with struct ibm_emac_stats/ibm_emac_error_stats */ | ||
183 | static const char emac_stats_keys[EMAC_ETHTOOL_STATS_COUNT][ETH_GSTRING_LEN] = { | ||
184 | "rx_packets", "rx_bytes", "tx_packets", "tx_bytes", "rx_packets_csum", | ||
185 | "tx_packets_csum", "tx_undo", "rx_dropped_stack", "rx_dropped_oom", | ||
186 | "rx_dropped_error", "rx_dropped_resize", "rx_dropped_mtu", | ||
187 | "rx_stopped", "rx_bd_errors", "rx_bd_overrun", "rx_bd_bad_packet", | ||
188 | "rx_bd_runt_packet", "rx_bd_short_event", "rx_bd_alignment_error", | ||
189 | "rx_bd_bad_fcs", "rx_bd_packet_too_long", "rx_bd_out_of_range", | ||
190 | "rx_bd_in_range", "rx_parity", "rx_fifo_overrun", "rx_overrun", | ||
191 | "rx_bad_packet", "rx_runt_packet", "rx_short_event", | ||
192 | "rx_alignment_error", "rx_bad_fcs", "rx_packet_too_long", | ||
193 | "rx_out_of_range", "rx_in_range", "tx_dropped", "tx_bd_errors", | ||
194 | "tx_bd_bad_fcs", "tx_bd_carrier_loss", "tx_bd_excessive_deferral", | ||
195 | "tx_bd_excessive_collisions", "tx_bd_late_collision", | ||
196 | "tx_bd_multple_collisions", "tx_bd_single_collision", | ||
197 | "tx_bd_underrun", "tx_bd_sqe", "tx_parity", "tx_underrun", "tx_sqe", | ||
198 | "tx_errors" | ||
199 | }; | ||
200 | |||
201 | static irqreturn_t emac_irq(int irq, void *dev_instance); | ||
202 | static void emac_clean_tx_ring(struct emac_instance *dev); | ||
203 | static void __emac_set_multicast_list(struct emac_instance *dev); | ||
204 | |||
205 | static inline int emac_phy_supports_gige(int phy_mode) | ||
206 | { | ||
207 | return phy_mode == PHY_MODE_GMII || | ||
208 | phy_mode == PHY_MODE_RGMII || | ||
209 | phy_mode == PHY_MODE_SGMII || | ||
210 | phy_mode == PHY_MODE_TBI || | ||
211 | phy_mode == PHY_MODE_RTBI; | ||
212 | } | ||
213 | |||
214 | static inline int emac_phy_gpcs(int phy_mode) | ||
215 | { | ||
216 | return phy_mode == PHY_MODE_SGMII || | ||
217 | phy_mode == PHY_MODE_TBI || | ||
218 | phy_mode == PHY_MODE_RTBI; | ||
219 | } | ||
220 | |||
221 | static inline void emac_tx_enable(struct emac_instance *dev) | ||
222 | { | ||
223 | struct emac_regs __iomem *p = dev->emacp; | ||
224 | u32 r; | ||
225 | |||
226 | DBG(dev, "tx_enable" NL); | ||
227 | |||
228 | r = in_be32(&p->mr0); | ||
229 | if (!(r & EMAC_MR0_TXE)) | ||
230 | out_be32(&p->mr0, r | EMAC_MR0_TXE); | ||
231 | } | ||
232 | |||
233 | static void emac_tx_disable(struct emac_instance *dev) | ||
234 | { | ||
235 | struct emac_regs __iomem *p = dev->emacp; | ||
236 | u32 r; | ||
237 | |||
238 | DBG(dev, "tx_disable" NL); | ||
239 | |||
240 | r = in_be32(&p->mr0); | ||
241 | if (r & EMAC_MR0_TXE) { | ||
242 | int n = dev->stop_timeout; | ||
243 | out_be32(&p->mr0, r & ~EMAC_MR0_TXE); | ||
244 | while (!(in_be32(&p->mr0) & EMAC_MR0_TXI) && n) { | ||
245 | udelay(1); | ||
246 | --n; | ||
247 | } | ||
248 | if (unlikely(!n)) | ||
249 | emac_report_timeout_error(dev, "TX disable timeout"); | ||
250 | } | ||
251 | } | ||
252 | |||
253 | static void emac_rx_enable(struct emac_instance *dev) | ||
254 | { | ||
255 | struct emac_regs __iomem *p = dev->emacp; | ||
256 | u32 r; | ||
257 | |||
258 | if (unlikely(test_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags))) | ||
259 | goto out; | ||
260 | |||
261 | DBG(dev, "rx_enable" NL); | ||
262 | |||
263 | r = in_be32(&p->mr0); | ||
264 | if (!(r & EMAC_MR0_RXE)) { | ||
265 | if (unlikely(!(r & EMAC_MR0_RXI))) { | ||
266 | /* Wait if previous async disable is still in progress */ | ||
267 | int n = dev->stop_timeout; | ||
268 | while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n) { | ||
269 | udelay(1); | ||
270 | --n; | ||
271 | } | ||
272 | if (unlikely(!n)) | ||
273 | emac_report_timeout_error(dev, | ||
274 | "RX disable timeout"); | ||
275 | } | ||
276 | out_be32(&p->mr0, r | EMAC_MR0_RXE); | ||
277 | } | ||
278 | out: | ||
279 | ; | ||
280 | } | ||
281 | |||
282 | static void emac_rx_disable(struct emac_instance *dev) | ||
283 | { | ||
284 | struct emac_regs __iomem *p = dev->emacp; | ||
285 | u32 r; | ||
286 | |||
287 | DBG(dev, "rx_disable" NL); | ||
288 | |||
289 | r = in_be32(&p->mr0); | ||
290 | if (r & EMAC_MR0_RXE) { | ||
291 | int n = dev->stop_timeout; | ||
292 | out_be32(&p->mr0, r & ~EMAC_MR0_RXE); | ||
293 | while (!(in_be32(&p->mr0) & EMAC_MR0_RXI) && n) { | ||
294 | udelay(1); | ||
295 | --n; | ||
296 | } | ||
297 | if (unlikely(!n)) | ||
298 | emac_report_timeout_error(dev, "RX disable timeout"); | ||
299 | } | ||
300 | } | ||
301 | |||
302 | static inline void emac_netif_stop(struct emac_instance *dev) | ||
303 | { | ||
304 | netif_tx_lock_bh(dev->ndev); | ||
305 | netif_addr_lock(dev->ndev); | ||
306 | dev->no_mcast = 1; | ||
307 | netif_addr_unlock(dev->ndev); | ||
308 | netif_tx_unlock_bh(dev->ndev); | ||
309 | dev->ndev->trans_start = jiffies; /* prevent tx timeout */ | ||
310 | mal_poll_disable(dev->mal, &dev->commac); | ||
311 | netif_tx_disable(dev->ndev); | ||
312 | } | ||
313 | |||
314 | static inline void emac_netif_start(struct emac_instance *dev) | ||
315 | { | ||
316 | netif_tx_lock_bh(dev->ndev); | ||
317 | netif_addr_lock(dev->ndev); | ||
318 | dev->no_mcast = 0; | ||
319 | if (dev->mcast_pending && netif_running(dev->ndev)) | ||
320 | __emac_set_multicast_list(dev); | ||
321 | netif_addr_unlock(dev->ndev); | ||
322 | netif_tx_unlock_bh(dev->ndev); | ||
323 | |||
324 | netif_wake_queue(dev->ndev); | ||
325 | |||
326 | /* NOTE: unconditional netif_wake_queue is only appropriate | ||
327 | * so long as all callers are assured to have free tx slots | ||
328 | * (taken from tg3... though the case where that is wrong is | ||
329 | * not terribly harmful) | ||
330 | */ | ||
331 | mal_poll_enable(dev->mal, &dev->commac); | ||
332 | } | ||
333 | |||
334 | static inline void emac_rx_disable_async(struct emac_instance *dev) | ||
335 | { | ||
336 | struct emac_regs __iomem *p = dev->emacp; | ||
337 | u32 r; | ||
338 | |||
339 | DBG(dev, "rx_disable_async" NL); | ||
340 | |||
341 | r = in_be32(&p->mr0); | ||
342 | if (r & EMAC_MR0_RXE) | ||
343 | out_be32(&p->mr0, r & ~EMAC_MR0_RXE); | ||
344 | } | ||
345 | |||
346 | static int emac_reset(struct emac_instance *dev) | ||
347 | { | ||
348 | struct emac_regs __iomem *p = dev->emacp; | ||
349 | int n = 20; | ||
350 | |||
351 | DBG(dev, "reset" NL); | ||
352 | |||
353 | if (!dev->reset_failed) { | ||
354 | /* 40x erratum suggests stopping RX channel before reset, | ||
355 | * we stop TX as well | ||
356 | */ | ||
357 | emac_rx_disable(dev); | ||
358 | emac_tx_disable(dev); | ||
359 | } | ||
360 | |||
361 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
362 | /* Enable internal clock source */ | ||
363 | if (emac_has_feature(dev, EMAC_FTR_460EX_PHY_CLK_FIX)) | ||
364 | dcri_clrset(SDR0, SDR0_ETH_CFG, | ||
365 | 0, SDR0_ETH_CFG_ECS << dev->cell_index); | ||
366 | #endif | ||
367 | |||
368 | out_be32(&p->mr0, EMAC_MR0_SRST); | ||
369 | while ((in_be32(&p->mr0) & EMAC_MR0_SRST) && n) | ||
370 | --n; | ||
371 | |||
372 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
373 | /* Enable external clock source */ | ||
374 | if (emac_has_feature(dev, EMAC_FTR_460EX_PHY_CLK_FIX)) | ||
375 | dcri_clrset(SDR0, SDR0_ETH_CFG, | ||
376 | SDR0_ETH_CFG_ECS << dev->cell_index, 0); | ||
377 | #endif | ||
378 | |||
379 | if (n) { | ||
380 | dev->reset_failed = 0; | ||
381 | return 0; | ||
382 | } else { | ||
383 | emac_report_timeout_error(dev, "reset timeout"); | ||
384 | dev->reset_failed = 1; | ||
385 | return -ETIMEDOUT; | ||
386 | } | ||
387 | } | ||
388 | |||
389 | static void emac_hash_mc(struct emac_instance *dev) | ||
390 | { | ||
391 | const int regs = EMAC_XAHT_REGS(dev); | ||
392 | u32 *gaht_base = emac_gaht_base(dev); | ||
393 | u32 gaht_temp[regs]; | ||
394 | struct netdev_hw_addr *ha; | ||
395 | int i; | ||
396 | |||
397 | DBG(dev, "hash_mc %d" NL, netdev_mc_count(dev->ndev)); | ||
398 | |||
399 | memset(gaht_temp, 0, sizeof (gaht_temp)); | ||
400 | |||
401 | netdev_for_each_mc_addr(ha, dev->ndev) { | ||
402 | int slot, reg, mask; | ||
403 | DBG2(dev, "mc %pM" NL, ha->addr); | ||
404 | |||
405 | slot = EMAC_XAHT_CRC_TO_SLOT(dev, | ||
406 | ether_crc(ETH_ALEN, ha->addr)); | ||
407 | reg = EMAC_XAHT_SLOT_TO_REG(dev, slot); | ||
408 | mask = EMAC_XAHT_SLOT_TO_MASK(dev, slot); | ||
409 | |||
410 | gaht_temp[reg] |= mask; | ||
411 | } | ||
412 | |||
413 | for (i = 0; i < regs; i++) | ||
414 | out_be32(gaht_base + i, gaht_temp[i]); | ||
415 | } | ||
416 | |||
417 | static inline u32 emac_iff2rmr(struct net_device *ndev) | ||
418 | { | ||
419 | struct emac_instance *dev = netdev_priv(ndev); | ||
420 | u32 r; | ||
421 | |||
422 | r = EMAC_RMR_SP | EMAC_RMR_SFCS | EMAC_RMR_IAE | EMAC_RMR_BAE; | ||
423 | |||
424 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
425 | r |= EMAC4_RMR_BASE; | ||
426 | else | ||
427 | r |= EMAC_RMR_BASE; | ||
428 | |||
429 | if (ndev->flags & IFF_PROMISC) | ||
430 | r |= EMAC_RMR_PME; | ||
431 | else if (ndev->flags & IFF_ALLMULTI || | ||
432 | (netdev_mc_count(ndev) > EMAC_XAHT_SLOTS(dev))) | ||
433 | r |= EMAC_RMR_PMME; | ||
434 | else if (!netdev_mc_empty(ndev)) | ||
435 | r |= EMAC_RMR_MAE; | ||
436 | |||
437 | return r; | ||
438 | } | ||
439 | |||
440 | static u32 __emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) | ||
441 | { | ||
442 | u32 ret = EMAC_MR1_VLE | EMAC_MR1_IST | EMAC_MR1_TR0_MULT; | ||
443 | |||
444 | DBG2(dev, "__emac_calc_base_mr1" NL); | ||
445 | |||
446 | switch(tx_size) { | ||
447 | case 2048: | ||
448 | ret |= EMAC_MR1_TFS_2K; | ||
449 | break; | ||
450 | default: | ||
451 | printk(KERN_WARNING "%s: Unknown Tx FIFO size %d\n", | ||
452 | dev->ndev->name, tx_size); | ||
453 | } | ||
454 | |||
455 | switch(rx_size) { | ||
456 | case 16384: | ||
457 | ret |= EMAC_MR1_RFS_16K; | ||
458 | break; | ||
459 | case 4096: | ||
460 | ret |= EMAC_MR1_RFS_4K; | ||
461 | break; | ||
462 | default: | ||
463 | printk(KERN_WARNING "%s: Unknown Rx FIFO size %d\n", | ||
464 | dev->ndev->name, rx_size); | ||
465 | } | ||
466 | |||
467 | return ret; | ||
468 | } | ||
469 | |||
470 | static u32 __emac4_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) | ||
471 | { | ||
472 | u32 ret = EMAC_MR1_VLE | EMAC_MR1_IST | EMAC4_MR1_TR | | ||
473 | EMAC4_MR1_OBCI(dev->opb_bus_freq / 1000000); | ||
474 | |||
475 | DBG2(dev, "__emac4_calc_base_mr1" NL); | ||
476 | |||
477 | switch(tx_size) { | ||
478 | case 16384: | ||
479 | ret |= EMAC4_MR1_TFS_16K; | ||
480 | break; | ||
481 | case 4096: | ||
482 | ret |= EMAC4_MR1_TFS_4K; | ||
483 | break; | ||
484 | case 2048: | ||
485 | ret |= EMAC4_MR1_TFS_2K; | ||
486 | break; | ||
487 | default: | ||
488 | printk(KERN_WARNING "%s: Unknown Tx FIFO size %d\n", | ||
489 | dev->ndev->name, tx_size); | ||
490 | } | ||
491 | |||
492 | switch(rx_size) { | ||
493 | case 16384: | ||
494 | ret |= EMAC4_MR1_RFS_16K; | ||
495 | break; | ||
496 | case 4096: | ||
497 | ret |= EMAC4_MR1_RFS_4K; | ||
498 | break; | ||
499 | case 2048: | ||
500 | ret |= EMAC4_MR1_RFS_2K; | ||
501 | break; | ||
502 | default: | ||
503 | printk(KERN_WARNING "%s: Unknown Rx FIFO size %d\n", | ||
504 | dev->ndev->name, rx_size); | ||
505 | } | ||
506 | |||
507 | return ret; | ||
508 | } | ||
509 | |||
510 | static u32 emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) | ||
511 | { | ||
512 | return emac_has_feature(dev, EMAC_FTR_EMAC4) ? | ||
513 | __emac4_calc_base_mr1(dev, tx_size, rx_size) : | ||
514 | __emac_calc_base_mr1(dev, tx_size, rx_size); | ||
515 | } | ||
516 | |||
517 | static inline u32 emac_calc_trtr(struct emac_instance *dev, unsigned int size) | ||
518 | { | ||
519 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
520 | return ((size >> 6) - 1) << EMAC_TRTR_SHIFT_EMAC4; | ||
521 | else | ||
522 | return ((size >> 6) - 1) << EMAC_TRTR_SHIFT; | ||
523 | } | ||
524 | |||
525 | static inline u32 emac_calc_rwmr(struct emac_instance *dev, | ||
526 | unsigned int low, unsigned int high) | ||
527 | { | ||
528 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
529 | return (low << 22) | ( (high & 0x3ff) << 6); | ||
530 | else | ||
531 | return (low << 23) | ( (high & 0x1ff) << 7); | ||
532 | } | ||
533 | |||
534 | static int emac_configure(struct emac_instance *dev) | ||
535 | { | ||
536 | struct emac_regs __iomem *p = dev->emacp; | ||
537 | struct net_device *ndev = dev->ndev; | ||
538 | int tx_size, rx_size, link = netif_carrier_ok(dev->ndev); | ||
539 | u32 r, mr1 = 0; | ||
540 | |||
541 | DBG(dev, "configure" NL); | ||
542 | |||
543 | if (!link) { | ||
544 | out_be32(&p->mr1, in_be32(&p->mr1) | ||
545 | | EMAC_MR1_FDE | EMAC_MR1_ILE); | ||
546 | udelay(100); | ||
547 | } else if (emac_reset(dev) < 0) | ||
548 | return -ETIMEDOUT; | ||
549 | |||
550 | if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) | ||
551 | tah_reset(dev->tah_dev); | ||
552 | |||
553 | DBG(dev, " link = %d duplex = %d, pause = %d, asym_pause = %d\n", | ||
554 | link, dev->phy.duplex, dev->phy.pause, dev->phy.asym_pause); | ||
555 | |||
556 | /* Default fifo sizes */ | ||
557 | tx_size = dev->tx_fifo_size; | ||
558 | rx_size = dev->rx_fifo_size; | ||
559 | |||
560 | /* No link, force loopback */ | ||
561 | if (!link) | ||
562 | mr1 = EMAC_MR1_FDE | EMAC_MR1_ILE; | ||
563 | |||
564 | /* Check for full duplex */ | ||
565 | else if (dev->phy.duplex == DUPLEX_FULL) | ||
566 | mr1 |= EMAC_MR1_FDE | EMAC_MR1_MWSW_001; | ||
567 | |||
568 | /* Adjust fifo sizes, mr1 and timeouts based on link speed */ | ||
569 | dev->stop_timeout = STOP_TIMEOUT_10; | ||
570 | switch (dev->phy.speed) { | ||
571 | case SPEED_1000: | ||
572 | if (emac_phy_gpcs(dev->phy.mode)) { | ||
573 | mr1 |= EMAC_MR1_MF_1000GPCS | EMAC_MR1_MF_IPPA( | ||
574 | (dev->phy.gpcs_address != 0xffffffff) ? | ||
575 | dev->phy.gpcs_address : dev->phy.address); | ||
576 | |||
577 | /* Put some arbitrary OUI, Manuf & Rev IDs so we can | ||
578 | * identify this GPCS PHY later. | ||
579 | */ | ||
580 | out_be32(&p->u1.emac4.ipcr, 0xdeadbeef); | ||
581 | } else | ||
582 | mr1 |= EMAC_MR1_MF_1000; | ||
583 | |||
584 | /* Extended fifo sizes */ | ||
585 | tx_size = dev->tx_fifo_size_gige; | ||
586 | rx_size = dev->rx_fifo_size_gige; | ||
587 | |||
588 | if (dev->ndev->mtu > ETH_DATA_LEN) { | ||
589 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
590 | mr1 |= EMAC4_MR1_JPSM; | ||
591 | else | ||
592 | mr1 |= EMAC_MR1_JPSM; | ||
593 | dev->stop_timeout = STOP_TIMEOUT_1000_JUMBO; | ||
594 | } else | ||
595 | dev->stop_timeout = STOP_TIMEOUT_1000; | ||
596 | break; | ||
597 | case SPEED_100: | ||
598 | mr1 |= EMAC_MR1_MF_100; | ||
599 | dev->stop_timeout = STOP_TIMEOUT_100; | ||
600 | break; | ||
601 | default: /* make gcc happy */ | ||
602 | break; | ||
603 | } | ||
604 | |||
605 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) | ||
606 | rgmii_set_speed(dev->rgmii_dev, dev->rgmii_port, | ||
607 | dev->phy.speed); | ||
608 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) | ||
609 | zmii_set_speed(dev->zmii_dev, dev->zmii_port, dev->phy.speed); | ||
610 | |||
611 | /* on 40x erratum forces us to NOT use integrated flow control, | ||
612 | * let's hope it works on 44x ;) | ||
613 | */ | ||
614 | if (!emac_has_feature(dev, EMAC_FTR_NO_FLOW_CONTROL_40x) && | ||
615 | dev->phy.duplex == DUPLEX_FULL) { | ||
616 | if (dev->phy.pause) | ||
617 | mr1 |= EMAC_MR1_EIFC | EMAC_MR1_APP; | ||
618 | else if (dev->phy.asym_pause) | ||
619 | mr1 |= EMAC_MR1_APP; | ||
620 | } | ||
621 | |||
622 | /* Add base settings & fifo sizes & program MR1 */ | ||
623 | mr1 |= emac_calc_base_mr1(dev, tx_size, rx_size); | ||
624 | out_be32(&p->mr1, mr1); | ||
625 | |||
626 | /* Set individual MAC address */ | ||
627 | out_be32(&p->iahr, (ndev->dev_addr[0] << 8) | ndev->dev_addr[1]); | ||
628 | out_be32(&p->ialr, (ndev->dev_addr[2] << 24) | | ||
629 | (ndev->dev_addr[3] << 16) | (ndev->dev_addr[4] << 8) | | ||
630 | ndev->dev_addr[5]); | ||
631 | |||
632 | /* VLAN Tag Protocol ID */ | ||
633 | out_be32(&p->vtpid, 0x8100); | ||
634 | |||
635 | /* Receive mode register */ | ||
636 | r = emac_iff2rmr(ndev); | ||
637 | if (r & EMAC_RMR_MAE) | ||
638 | emac_hash_mc(dev); | ||
639 | out_be32(&p->rmr, r); | ||
640 | |||
641 | /* FIFOs thresholds */ | ||
642 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
643 | r = EMAC4_TMR1((dev->mal_burst_size / dev->fifo_entry_size) + 1, | ||
644 | tx_size / 2 / dev->fifo_entry_size); | ||
645 | else | ||
646 | r = EMAC_TMR1((dev->mal_burst_size / dev->fifo_entry_size) + 1, | ||
647 | tx_size / 2 / dev->fifo_entry_size); | ||
648 | out_be32(&p->tmr1, r); | ||
649 | out_be32(&p->trtr, emac_calc_trtr(dev, tx_size / 2)); | ||
650 | |||
651 | /* PAUSE frame is sent when RX FIFO reaches its high-water mark, | ||
652 | there should be still enough space in FIFO to allow the our link | ||
653 | partner time to process this frame and also time to send PAUSE | ||
654 | frame itself. | ||
655 | |||
656 | Here is the worst case scenario for the RX FIFO "headroom" | ||
657 | (from "The Switch Book") (100Mbps, without preamble, inter-frame gap): | ||
658 | |||
659 | 1) One maximum-length frame on TX 1522 bytes | ||
660 | 2) One PAUSE frame time 64 bytes | ||
661 | 3) PAUSE frame decode time allowance 64 bytes | ||
662 | 4) One maximum-length frame on RX 1522 bytes | ||
663 | 5) Round-trip propagation delay of the link (100Mb) 15 bytes | ||
664 | ---------- | ||
665 | 3187 bytes | ||
666 | |||
667 | I chose to set high-water mark to RX_FIFO_SIZE / 4 (1024 bytes) | ||
668 | low-water mark to RX_FIFO_SIZE / 8 (512 bytes) | ||
669 | */ | ||
670 | r = emac_calc_rwmr(dev, rx_size / 8 / dev->fifo_entry_size, | ||
671 | rx_size / 4 / dev->fifo_entry_size); | ||
672 | out_be32(&p->rwmr, r); | ||
673 | |||
674 | /* Set PAUSE timer to the maximum */ | ||
675 | out_be32(&p->ptr, 0xffff); | ||
676 | |||
677 | /* IRQ sources */ | ||
678 | r = EMAC_ISR_OVR | EMAC_ISR_BP | EMAC_ISR_SE | | ||
679 | EMAC_ISR_ALE | EMAC_ISR_BFCS | EMAC_ISR_PTLE | EMAC_ISR_ORE | | ||
680 | EMAC_ISR_IRE | EMAC_ISR_TE; | ||
681 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
682 | r |= EMAC4_ISR_TXPE | EMAC4_ISR_RXPE /* | EMAC4_ISR_TXUE | | ||
683 | EMAC4_ISR_RXOE | */; | ||
684 | out_be32(&p->iser, r); | ||
685 | |||
686 | /* We need to take GPCS PHY out of isolate mode after EMAC reset */ | ||
687 | if (emac_phy_gpcs(dev->phy.mode)) { | ||
688 | if (dev->phy.gpcs_address != 0xffffffff) | ||
689 | emac_mii_reset_gpcs(&dev->phy); | ||
690 | else | ||
691 | emac_mii_reset_phy(&dev->phy); | ||
692 | } | ||
693 | |||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | static void emac_reinitialize(struct emac_instance *dev) | ||
698 | { | ||
699 | DBG(dev, "reinitialize" NL); | ||
700 | |||
701 | emac_netif_stop(dev); | ||
702 | if (!emac_configure(dev)) { | ||
703 | emac_tx_enable(dev); | ||
704 | emac_rx_enable(dev); | ||
705 | } | ||
706 | emac_netif_start(dev); | ||
707 | } | ||
708 | |||
709 | static void emac_full_tx_reset(struct emac_instance *dev) | ||
710 | { | ||
711 | DBG(dev, "full_tx_reset" NL); | ||
712 | |||
713 | emac_tx_disable(dev); | ||
714 | mal_disable_tx_channel(dev->mal, dev->mal_tx_chan); | ||
715 | emac_clean_tx_ring(dev); | ||
716 | dev->tx_cnt = dev->tx_slot = dev->ack_slot = 0; | ||
717 | |||
718 | emac_configure(dev); | ||
719 | |||
720 | mal_enable_tx_channel(dev->mal, dev->mal_tx_chan); | ||
721 | emac_tx_enable(dev); | ||
722 | emac_rx_enable(dev); | ||
723 | } | ||
724 | |||
725 | static void emac_reset_work(struct work_struct *work) | ||
726 | { | ||
727 | struct emac_instance *dev = container_of(work, struct emac_instance, reset_work); | ||
728 | |||
729 | DBG(dev, "reset_work" NL); | ||
730 | |||
731 | mutex_lock(&dev->link_lock); | ||
732 | if (dev->opened) { | ||
733 | emac_netif_stop(dev); | ||
734 | emac_full_tx_reset(dev); | ||
735 | emac_netif_start(dev); | ||
736 | } | ||
737 | mutex_unlock(&dev->link_lock); | ||
738 | } | ||
739 | |||
740 | static void emac_tx_timeout(struct net_device *ndev) | ||
741 | { | ||
742 | struct emac_instance *dev = netdev_priv(ndev); | ||
743 | |||
744 | DBG(dev, "tx_timeout" NL); | ||
745 | |||
746 | schedule_work(&dev->reset_work); | ||
747 | } | ||
748 | |||
749 | |||
750 | static inline int emac_phy_done(struct emac_instance *dev, u32 stacr) | ||
751 | { | ||
752 | int done = !!(stacr & EMAC_STACR_OC); | ||
753 | |||
754 | if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) | ||
755 | done = !done; | ||
756 | |||
757 | return done; | ||
758 | }; | ||
759 | |||
760 | static int __emac_mdio_read(struct emac_instance *dev, u8 id, u8 reg) | ||
761 | { | ||
762 | struct emac_regs __iomem *p = dev->emacp; | ||
763 | u32 r = 0; | ||
764 | int n, err = -ETIMEDOUT; | ||
765 | |||
766 | mutex_lock(&dev->mdio_lock); | ||
767 | |||
768 | DBG2(dev, "mdio_read(%02x,%02x)" NL, id, reg); | ||
769 | |||
770 | /* Enable proper MDIO port */ | ||
771 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) | ||
772 | zmii_get_mdio(dev->zmii_dev, dev->zmii_port); | ||
773 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) | ||
774 | rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port); | ||
775 | |||
776 | /* Wait for management interface to become idle */ | ||
777 | n = 20; | ||
778 | while (!emac_phy_done(dev, in_be32(&p->stacr))) { | ||
779 | udelay(1); | ||
780 | if (!--n) { | ||
781 | DBG2(dev, " -> timeout wait idle\n"); | ||
782 | goto bail; | ||
783 | } | ||
784 | } | ||
785 | |||
786 | /* Issue read command */ | ||
787 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
788 | r = EMAC4_STACR_BASE(dev->opb_bus_freq); | ||
789 | else | ||
790 | r = EMAC_STACR_BASE(dev->opb_bus_freq); | ||
791 | if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) | ||
792 | r |= EMAC_STACR_OC; | ||
793 | if (emac_has_feature(dev, EMAC_FTR_HAS_NEW_STACR)) | ||
794 | r |= EMACX_STACR_STAC_READ; | ||
795 | else | ||
796 | r |= EMAC_STACR_STAC_READ; | ||
797 | r |= (reg & EMAC_STACR_PRA_MASK) | ||
798 | | ((id & EMAC_STACR_PCDA_MASK) << EMAC_STACR_PCDA_SHIFT); | ||
799 | out_be32(&p->stacr, r); | ||
800 | |||
801 | /* Wait for read to complete */ | ||
802 | n = 200; | ||
803 | while (!emac_phy_done(dev, (r = in_be32(&p->stacr)))) { | ||
804 | udelay(1); | ||
805 | if (!--n) { | ||
806 | DBG2(dev, " -> timeout wait complete\n"); | ||
807 | goto bail; | ||
808 | } | ||
809 | } | ||
810 | |||
811 | if (unlikely(r & EMAC_STACR_PHYE)) { | ||
812 | DBG(dev, "mdio_read(%02x, %02x) failed" NL, id, reg); | ||
813 | err = -EREMOTEIO; | ||
814 | goto bail; | ||
815 | } | ||
816 | |||
817 | r = ((r >> EMAC_STACR_PHYD_SHIFT) & EMAC_STACR_PHYD_MASK); | ||
818 | |||
819 | DBG2(dev, "mdio_read -> %04x" NL, r); | ||
820 | err = 0; | ||
821 | bail: | ||
822 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) | ||
823 | rgmii_put_mdio(dev->rgmii_dev, dev->rgmii_port); | ||
824 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) | ||
825 | zmii_put_mdio(dev->zmii_dev, dev->zmii_port); | ||
826 | mutex_unlock(&dev->mdio_lock); | ||
827 | |||
828 | return err == 0 ? r : err; | ||
829 | } | ||
830 | |||
831 | static void __emac_mdio_write(struct emac_instance *dev, u8 id, u8 reg, | ||
832 | u16 val) | ||
833 | { | ||
834 | struct emac_regs __iomem *p = dev->emacp; | ||
835 | u32 r = 0; | ||
836 | int n, err = -ETIMEDOUT; | ||
837 | |||
838 | mutex_lock(&dev->mdio_lock); | ||
839 | |||
840 | DBG2(dev, "mdio_write(%02x,%02x,%04x)" NL, id, reg, val); | ||
841 | |||
842 | /* Enable proper MDIO port */ | ||
843 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) | ||
844 | zmii_get_mdio(dev->zmii_dev, dev->zmii_port); | ||
845 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) | ||
846 | rgmii_get_mdio(dev->rgmii_dev, dev->rgmii_port); | ||
847 | |||
848 | /* Wait for management interface to be idle */ | ||
849 | n = 20; | ||
850 | while (!emac_phy_done(dev, in_be32(&p->stacr))) { | ||
851 | udelay(1); | ||
852 | if (!--n) { | ||
853 | DBG2(dev, " -> timeout wait idle\n"); | ||
854 | goto bail; | ||
855 | } | ||
856 | } | ||
857 | |||
858 | /* Issue write command */ | ||
859 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
860 | r = EMAC4_STACR_BASE(dev->opb_bus_freq); | ||
861 | else | ||
862 | r = EMAC_STACR_BASE(dev->opb_bus_freq); | ||
863 | if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) | ||
864 | r |= EMAC_STACR_OC; | ||
865 | if (emac_has_feature(dev, EMAC_FTR_HAS_NEW_STACR)) | ||
866 | r |= EMACX_STACR_STAC_WRITE; | ||
867 | else | ||
868 | r |= EMAC_STACR_STAC_WRITE; | ||
869 | r |= (reg & EMAC_STACR_PRA_MASK) | | ||
870 | ((id & EMAC_STACR_PCDA_MASK) << EMAC_STACR_PCDA_SHIFT) | | ||
871 | (val << EMAC_STACR_PHYD_SHIFT); | ||
872 | out_be32(&p->stacr, r); | ||
873 | |||
874 | /* Wait for write to complete */ | ||
875 | n = 200; | ||
876 | while (!emac_phy_done(dev, in_be32(&p->stacr))) { | ||
877 | udelay(1); | ||
878 | if (!--n) { | ||
879 | DBG2(dev, " -> timeout wait complete\n"); | ||
880 | goto bail; | ||
881 | } | ||
882 | } | ||
883 | err = 0; | ||
884 | bail: | ||
885 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) | ||
886 | rgmii_put_mdio(dev->rgmii_dev, dev->rgmii_port); | ||
887 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) | ||
888 | zmii_put_mdio(dev->zmii_dev, dev->zmii_port); | ||
889 | mutex_unlock(&dev->mdio_lock); | ||
890 | } | ||
891 | |||
892 | static int emac_mdio_read(struct net_device *ndev, int id, int reg) | ||
893 | { | ||
894 | struct emac_instance *dev = netdev_priv(ndev); | ||
895 | int res; | ||
896 | |||
897 | res = __emac_mdio_read((dev->mdio_instance && | ||
898 | dev->phy.gpcs_address != id) ? | ||
899 | dev->mdio_instance : dev, | ||
900 | (u8) id, (u8) reg); | ||
901 | return res; | ||
902 | } | ||
903 | |||
904 | static void emac_mdio_write(struct net_device *ndev, int id, int reg, int val) | ||
905 | { | ||
906 | struct emac_instance *dev = netdev_priv(ndev); | ||
907 | |||
908 | __emac_mdio_write((dev->mdio_instance && | ||
909 | dev->phy.gpcs_address != id) ? | ||
910 | dev->mdio_instance : dev, | ||
911 | (u8) id, (u8) reg, (u16) val); | ||
912 | } | ||
913 | |||
914 | /* Tx lock BH */ | ||
915 | static void __emac_set_multicast_list(struct emac_instance *dev) | ||
916 | { | ||
917 | struct emac_regs __iomem *p = dev->emacp; | ||
918 | u32 rmr = emac_iff2rmr(dev->ndev); | ||
919 | |||
920 | DBG(dev, "__multicast %08x" NL, rmr); | ||
921 | |||
922 | /* I decided to relax register access rules here to avoid | ||
923 | * full EMAC reset. | ||
924 | * | ||
925 | * There is a real problem with EMAC4 core if we use MWSW_001 bit | ||
926 | * in MR1 register and do a full EMAC reset. | ||
927 | * One TX BD status update is delayed and, after EMAC reset, it | ||
928 | * never happens, resulting in TX hung (it'll be recovered by TX | ||
929 | * timeout handler eventually, but this is just gross). | ||
930 | * So we either have to do full TX reset or try to cheat here :) | ||
931 | * | ||
932 | * The only required change is to RX mode register, so I *think* all | ||
933 | * we need is just to stop RX channel. This seems to work on all | ||
934 | * tested SoCs. --ebs | ||
935 | * | ||
936 | * If we need the full reset, we might just trigger the workqueue | ||
937 | * and do it async... a bit nasty but should work --BenH | ||
938 | */ | ||
939 | dev->mcast_pending = 0; | ||
940 | emac_rx_disable(dev); | ||
941 | if (rmr & EMAC_RMR_MAE) | ||
942 | emac_hash_mc(dev); | ||
943 | out_be32(&p->rmr, rmr); | ||
944 | emac_rx_enable(dev); | ||
945 | } | ||
946 | |||
947 | /* Tx lock BH */ | ||
948 | static void emac_set_multicast_list(struct net_device *ndev) | ||
949 | { | ||
950 | struct emac_instance *dev = netdev_priv(ndev); | ||
951 | |||
952 | DBG(dev, "multicast" NL); | ||
953 | |||
954 | BUG_ON(!netif_running(dev->ndev)); | ||
955 | |||
956 | if (dev->no_mcast) { | ||
957 | dev->mcast_pending = 1; | ||
958 | return; | ||
959 | } | ||
960 | __emac_set_multicast_list(dev); | ||
961 | } | ||
962 | |||
963 | static int emac_resize_rx_ring(struct emac_instance *dev, int new_mtu) | ||
964 | { | ||
965 | int rx_sync_size = emac_rx_sync_size(new_mtu); | ||
966 | int rx_skb_size = emac_rx_skb_size(new_mtu); | ||
967 | int i, ret = 0; | ||
968 | |||
969 | mutex_lock(&dev->link_lock); | ||
970 | emac_netif_stop(dev); | ||
971 | emac_rx_disable(dev); | ||
972 | mal_disable_rx_channel(dev->mal, dev->mal_rx_chan); | ||
973 | |||
974 | if (dev->rx_sg_skb) { | ||
975 | ++dev->estats.rx_dropped_resize; | ||
976 | dev_kfree_skb(dev->rx_sg_skb); | ||
977 | dev->rx_sg_skb = NULL; | ||
978 | } | ||
979 | |||
980 | /* Make a first pass over RX ring and mark BDs ready, dropping | ||
981 | * non-processed packets on the way. We need this as a separate pass | ||
982 | * to simplify error recovery in the case of allocation failure later. | ||
983 | */ | ||
984 | for (i = 0; i < NUM_RX_BUFF; ++i) { | ||
985 | if (dev->rx_desc[i].ctrl & MAL_RX_CTRL_FIRST) | ||
986 | ++dev->estats.rx_dropped_resize; | ||
987 | |||
988 | dev->rx_desc[i].data_len = 0; | ||
989 | dev->rx_desc[i].ctrl = MAL_RX_CTRL_EMPTY | | ||
990 | (i == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0); | ||
991 | } | ||
992 | |||
993 | /* Reallocate RX ring only if bigger skb buffers are required */ | ||
994 | if (rx_skb_size <= dev->rx_skb_size) | ||
995 | goto skip; | ||
996 | |||
997 | /* Second pass, allocate new skbs */ | ||
998 | for (i = 0; i < NUM_RX_BUFF; ++i) { | ||
999 | struct sk_buff *skb = alloc_skb(rx_skb_size, GFP_ATOMIC); | ||
1000 | if (!skb) { | ||
1001 | ret = -ENOMEM; | ||
1002 | goto oom; | ||
1003 | } | ||
1004 | |||
1005 | BUG_ON(!dev->rx_skb[i]); | ||
1006 | dev_kfree_skb(dev->rx_skb[i]); | ||
1007 | |||
1008 | skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2); | ||
1009 | dev->rx_desc[i].data_ptr = | ||
1010 | dma_map_single(&dev->ofdev->dev, skb->data - 2, rx_sync_size, | ||
1011 | DMA_FROM_DEVICE) + 2; | ||
1012 | dev->rx_skb[i] = skb; | ||
1013 | } | ||
1014 | skip: | ||
1015 | /* Check if we need to change "Jumbo" bit in MR1 */ | ||
1016 | if ((new_mtu > ETH_DATA_LEN) ^ (dev->ndev->mtu > ETH_DATA_LEN)) { | ||
1017 | /* This is to prevent starting RX channel in emac_rx_enable() */ | ||
1018 | set_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); | ||
1019 | |||
1020 | dev->ndev->mtu = new_mtu; | ||
1021 | emac_full_tx_reset(dev); | ||
1022 | } | ||
1023 | |||
1024 | mal_set_rcbs(dev->mal, dev->mal_rx_chan, emac_rx_size(new_mtu)); | ||
1025 | oom: | ||
1026 | /* Restart RX */ | ||
1027 | clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); | ||
1028 | dev->rx_slot = 0; | ||
1029 | mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); | ||
1030 | emac_rx_enable(dev); | ||
1031 | emac_netif_start(dev); | ||
1032 | mutex_unlock(&dev->link_lock); | ||
1033 | |||
1034 | return ret; | ||
1035 | } | ||
1036 | |||
1037 | /* Process ctx, rtnl_lock semaphore */ | ||
1038 | static int emac_change_mtu(struct net_device *ndev, int new_mtu) | ||
1039 | { | ||
1040 | struct emac_instance *dev = netdev_priv(ndev); | ||
1041 | int ret = 0; | ||
1042 | |||
1043 | if (new_mtu < EMAC_MIN_MTU || new_mtu > dev->max_mtu) | ||
1044 | return -EINVAL; | ||
1045 | |||
1046 | DBG(dev, "change_mtu(%d)" NL, new_mtu); | ||
1047 | |||
1048 | if (netif_running(ndev)) { | ||
1049 | /* Check if we really need to reinitialize RX ring */ | ||
1050 | if (emac_rx_skb_size(ndev->mtu) != emac_rx_skb_size(new_mtu)) | ||
1051 | ret = emac_resize_rx_ring(dev, new_mtu); | ||
1052 | } | ||
1053 | |||
1054 | if (!ret) { | ||
1055 | ndev->mtu = new_mtu; | ||
1056 | dev->rx_skb_size = emac_rx_skb_size(new_mtu); | ||
1057 | dev->rx_sync_size = emac_rx_sync_size(new_mtu); | ||
1058 | } | ||
1059 | |||
1060 | return ret; | ||
1061 | } | ||
1062 | |||
1063 | static void emac_clean_tx_ring(struct emac_instance *dev) | ||
1064 | { | ||
1065 | int i; | ||
1066 | |||
1067 | for (i = 0; i < NUM_TX_BUFF; ++i) { | ||
1068 | if (dev->tx_skb[i]) { | ||
1069 | dev_kfree_skb(dev->tx_skb[i]); | ||
1070 | dev->tx_skb[i] = NULL; | ||
1071 | if (dev->tx_desc[i].ctrl & MAL_TX_CTRL_READY) | ||
1072 | ++dev->estats.tx_dropped; | ||
1073 | } | ||
1074 | dev->tx_desc[i].ctrl = 0; | ||
1075 | dev->tx_desc[i].data_ptr = 0; | ||
1076 | } | ||
1077 | } | ||
1078 | |||
1079 | static void emac_clean_rx_ring(struct emac_instance *dev) | ||
1080 | { | ||
1081 | int i; | ||
1082 | |||
1083 | for (i = 0; i < NUM_RX_BUFF; ++i) | ||
1084 | if (dev->rx_skb[i]) { | ||
1085 | dev->rx_desc[i].ctrl = 0; | ||
1086 | dev_kfree_skb(dev->rx_skb[i]); | ||
1087 | dev->rx_skb[i] = NULL; | ||
1088 | dev->rx_desc[i].data_ptr = 0; | ||
1089 | } | ||
1090 | |||
1091 | if (dev->rx_sg_skb) { | ||
1092 | dev_kfree_skb(dev->rx_sg_skb); | ||
1093 | dev->rx_sg_skb = NULL; | ||
1094 | } | ||
1095 | } | ||
1096 | |||
1097 | static inline int emac_alloc_rx_skb(struct emac_instance *dev, int slot, | ||
1098 | gfp_t flags) | ||
1099 | { | ||
1100 | struct sk_buff *skb = alloc_skb(dev->rx_skb_size, flags); | ||
1101 | if (unlikely(!skb)) | ||
1102 | return -ENOMEM; | ||
1103 | |||
1104 | dev->rx_skb[slot] = skb; | ||
1105 | dev->rx_desc[slot].data_len = 0; | ||
1106 | |||
1107 | skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2); | ||
1108 | dev->rx_desc[slot].data_ptr = | ||
1109 | dma_map_single(&dev->ofdev->dev, skb->data - 2, dev->rx_sync_size, | ||
1110 | DMA_FROM_DEVICE) + 2; | ||
1111 | wmb(); | ||
1112 | dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | | ||
1113 | (slot == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0); | ||
1114 | |||
1115 | return 0; | ||
1116 | } | ||
1117 | |||
1118 | static void emac_print_link_status(struct emac_instance *dev) | ||
1119 | { | ||
1120 | if (netif_carrier_ok(dev->ndev)) | ||
1121 | printk(KERN_INFO "%s: link is up, %d %s%s\n", | ||
1122 | dev->ndev->name, dev->phy.speed, | ||
1123 | dev->phy.duplex == DUPLEX_FULL ? "FDX" : "HDX", | ||
1124 | dev->phy.pause ? ", pause enabled" : | ||
1125 | dev->phy.asym_pause ? ", asymmetric pause enabled" : ""); | ||
1126 | else | ||
1127 | printk(KERN_INFO "%s: link is down\n", dev->ndev->name); | ||
1128 | } | ||
1129 | |||
1130 | /* Process ctx, rtnl_lock semaphore */ | ||
1131 | static int emac_open(struct net_device *ndev) | ||
1132 | { | ||
1133 | struct emac_instance *dev = netdev_priv(ndev); | ||
1134 | int err, i; | ||
1135 | |||
1136 | DBG(dev, "open" NL); | ||
1137 | |||
1138 | /* Setup error IRQ handler */ | ||
1139 | err = request_irq(dev->emac_irq, emac_irq, 0, "EMAC", dev); | ||
1140 | if (err) { | ||
1141 | printk(KERN_ERR "%s: failed to request IRQ %d\n", | ||
1142 | ndev->name, dev->emac_irq); | ||
1143 | return err; | ||
1144 | } | ||
1145 | |||
1146 | /* Allocate RX ring */ | ||
1147 | for (i = 0; i < NUM_RX_BUFF; ++i) | ||
1148 | if (emac_alloc_rx_skb(dev, i, GFP_KERNEL)) { | ||
1149 | printk(KERN_ERR "%s: failed to allocate RX ring\n", | ||
1150 | ndev->name); | ||
1151 | goto oom; | ||
1152 | } | ||
1153 | |||
1154 | dev->tx_cnt = dev->tx_slot = dev->ack_slot = dev->rx_slot = 0; | ||
1155 | clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); | ||
1156 | dev->rx_sg_skb = NULL; | ||
1157 | |||
1158 | mutex_lock(&dev->link_lock); | ||
1159 | dev->opened = 1; | ||
1160 | |||
1161 | /* Start PHY polling now. | ||
1162 | */ | ||
1163 | if (dev->phy.address >= 0) { | ||
1164 | int link_poll_interval; | ||
1165 | if (dev->phy.def->ops->poll_link(&dev->phy)) { | ||
1166 | dev->phy.def->ops->read_link(&dev->phy); | ||
1167 | emac_rx_clk_default(dev); | ||
1168 | netif_carrier_on(dev->ndev); | ||
1169 | link_poll_interval = PHY_POLL_LINK_ON; | ||
1170 | } else { | ||
1171 | emac_rx_clk_tx(dev); | ||
1172 | netif_carrier_off(dev->ndev); | ||
1173 | link_poll_interval = PHY_POLL_LINK_OFF; | ||
1174 | } | ||
1175 | dev->link_polling = 1; | ||
1176 | wmb(); | ||
1177 | schedule_delayed_work(&dev->link_work, link_poll_interval); | ||
1178 | emac_print_link_status(dev); | ||
1179 | } else | ||
1180 | netif_carrier_on(dev->ndev); | ||
1181 | |||
1182 | /* Required for Pause packet support in EMAC */ | ||
1183 | dev_mc_add_global(ndev, default_mcast_addr); | ||
1184 | |||
1185 | emac_configure(dev); | ||
1186 | mal_poll_add(dev->mal, &dev->commac); | ||
1187 | mal_enable_tx_channel(dev->mal, dev->mal_tx_chan); | ||
1188 | mal_set_rcbs(dev->mal, dev->mal_rx_chan, emac_rx_size(ndev->mtu)); | ||
1189 | mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); | ||
1190 | emac_tx_enable(dev); | ||
1191 | emac_rx_enable(dev); | ||
1192 | emac_netif_start(dev); | ||
1193 | |||
1194 | mutex_unlock(&dev->link_lock); | ||
1195 | |||
1196 | return 0; | ||
1197 | oom: | ||
1198 | emac_clean_rx_ring(dev); | ||
1199 | free_irq(dev->emac_irq, dev); | ||
1200 | |||
1201 | return -ENOMEM; | ||
1202 | } | ||
1203 | |||
1204 | /* BHs disabled */ | ||
1205 | #if 0 | ||
1206 | static int emac_link_differs(struct emac_instance *dev) | ||
1207 | { | ||
1208 | u32 r = in_be32(&dev->emacp->mr1); | ||
1209 | |||
1210 | int duplex = r & EMAC_MR1_FDE ? DUPLEX_FULL : DUPLEX_HALF; | ||
1211 | int speed, pause, asym_pause; | ||
1212 | |||
1213 | if (r & EMAC_MR1_MF_1000) | ||
1214 | speed = SPEED_1000; | ||
1215 | else if (r & EMAC_MR1_MF_100) | ||
1216 | speed = SPEED_100; | ||
1217 | else | ||
1218 | speed = SPEED_10; | ||
1219 | |||
1220 | switch (r & (EMAC_MR1_EIFC | EMAC_MR1_APP)) { | ||
1221 | case (EMAC_MR1_EIFC | EMAC_MR1_APP): | ||
1222 | pause = 1; | ||
1223 | asym_pause = 0; | ||
1224 | break; | ||
1225 | case EMAC_MR1_APP: | ||
1226 | pause = 0; | ||
1227 | asym_pause = 1; | ||
1228 | break; | ||
1229 | default: | ||
1230 | pause = asym_pause = 0; | ||
1231 | } | ||
1232 | return speed != dev->phy.speed || duplex != dev->phy.duplex || | ||
1233 | pause != dev->phy.pause || asym_pause != dev->phy.asym_pause; | ||
1234 | } | ||
1235 | #endif | ||
1236 | |||
1237 | static void emac_link_timer(struct work_struct *work) | ||
1238 | { | ||
1239 | struct emac_instance *dev = | ||
1240 | container_of(to_delayed_work(work), | ||
1241 | struct emac_instance, link_work); | ||
1242 | int link_poll_interval; | ||
1243 | |||
1244 | mutex_lock(&dev->link_lock); | ||
1245 | DBG2(dev, "link timer" NL); | ||
1246 | |||
1247 | if (!dev->opened) | ||
1248 | goto bail; | ||
1249 | |||
1250 | if (dev->phy.def->ops->poll_link(&dev->phy)) { | ||
1251 | if (!netif_carrier_ok(dev->ndev)) { | ||
1252 | emac_rx_clk_default(dev); | ||
1253 | /* Get new link parameters */ | ||
1254 | dev->phy.def->ops->read_link(&dev->phy); | ||
1255 | |||
1256 | netif_carrier_on(dev->ndev); | ||
1257 | emac_netif_stop(dev); | ||
1258 | emac_full_tx_reset(dev); | ||
1259 | emac_netif_start(dev); | ||
1260 | emac_print_link_status(dev); | ||
1261 | } | ||
1262 | link_poll_interval = PHY_POLL_LINK_ON; | ||
1263 | } else { | ||
1264 | if (netif_carrier_ok(dev->ndev)) { | ||
1265 | emac_rx_clk_tx(dev); | ||
1266 | netif_carrier_off(dev->ndev); | ||
1267 | netif_tx_disable(dev->ndev); | ||
1268 | emac_reinitialize(dev); | ||
1269 | emac_print_link_status(dev); | ||
1270 | } | ||
1271 | link_poll_interval = PHY_POLL_LINK_OFF; | ||
1272 | } | ||
1273 | schedule_delayed_work(&dev->link_work, link_poll_interval); | ||
1274 | bail: | ||
1275 | mutex_unlock(&dev->link_lock); | ||
1276 | } | ||
1277 | |||
1278 | static void emac_force_link_update(struct emac_instance *dev) | ||
1279 | { | ||
1280 | netif_carrier_off(dev->ndev); | ||
1281 | smp_rmb(); | ||
1282 | if (dev->link_polling) { | ||
1283 | cancel_delayed_work_sync(&dev->link_work); | ||
1284 | if (dev->link_polling) | ||
1285 | schedule_delayed_work(&dev->link_work, PHY_POLL_LINK_OFF); | ||
1286 | } | ||
1287 | } | ||
1288 | |||
1289 | /* Process ctx, rtnl_lock semaphore */ | ||
1290 | static int emac_close(struct net_device *ndev) | ||
1291 | { | ||
1292 | struct emac_instance *dev = netdev_priv(ndev); | ||
1293 | |||
1294 | DBG(dev, "close" NL); | ||
1295 | |||
1296 | if (dev->phy.address >= 0) { | ||
1297 | dev->link_polling = 0; | ||
1298 | cancel_delayed_work_sync(&dev->link_work); | ||
1299 | } | ||
1300 | mutex_lock(&dev->link_lock); | ||
1301 | emac_netif_stop(dev); | ||
1302 | dev->opened = 0; | ||
1303 | mutex_unlock(&dev->link_lock); | ||
1304 | |||
1305 | emac_rx_disable(dev); | ||
1306 | emac_tx_disable(dev); | ||
1307 | mal_disable_rx_channel(dev->mal, dev->mal_rx_chan); | ||
1308 | mal_disable_tx_channel(dev->mal, dev->mal_tx_chan); | ||
1309 | mal_poll_del(dev->mal, &dev->commac); | ||
1310 | |||
1311 | emac_clean_tx_ring(dev); | ||
1312 | emac_clean_rx_ring(dev); | ||
1313 | |||
1314 | free_irq(dev->emac_irq, dev); | ||
1315 | |||
1316 | netif_carrier_off(ndev); | ||
1317 | |||
1318 | return 0; | ||
1319 | } | ||
1320 | |||
1321 | static inline u16 emac_tx_csum(struct emac_instance *dev, | ||
1322 | struct sk_buff *skb) | ||
1323 | { | ||
1324 | if (emac_has_feature(dev, EMAC_FTR_HAS_TAH) && | ||
1325 | (skb->ip_summed == CHECKSUM_PARTIAL)) { | ||
1326 | ++dev->stats.tx_packets_csum; | ||
1327 | return EMAC_TX_CTRL_TAH_CSUM; | ||
1328 | } | ||
1329 | return 0; | ||
1330 | } | ||
1331 | |||
1332 | static inline int emac_xmit_finish(struct emac_instance *dev, int len) | ||
1333 | { | ||
1334 | struct emac_regs __iomem *p = dev->emacp; | ||
1335 | struct net_device *ndev = dev->ndev; | ||
1336 | |||
1337 | /* Send the packet out. If the if makes a significant perf | ||
1338 | * difference, then we can store the TMR0 value in "dev" | ||
1339 | * instead | ||
1340 | */ | ||
1341 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
1342 | out_be32(&p->tmr0, EMAC4_TMR0_XMIT); | ||
1343 | else | ||
1344 | out_be32(&p->tmr0, EMAC_TMR0_XMIT); | ||
1345 | |||
1346 | if (unlikely(++dev->tx_cnt == NUM_TX_BUFF)) { | ||
1347 | netif_stop_queue(ndev); | ||
1348 | DBG2(dev, "stopped TX queue" NL); | ||
1349 | } | ||
1350 | |||
1351 | ndev->trans_start = jiffies; | ||
1352 | ++dev->stats.tx_packets; | ||
1353 | dev->stats.tx_bytes += len; | ||
1354 | |||
1355 | return NETDEV_TX_OK; | ||
1356 | } | ||
1357 | |||
1358 | /* Tx lock BH */ | ||
1359 | static int emac_start_xmit(struct sk_buff *skb, struct net_device *ndev) | ||
1360 | { | ||
1361 | struct emac_instance *dev = netdev_priv(ndev); | ||
1362 | unsigned int len = skb->len; | ||
1363 | int slot; | ||
1364 | |||
1365 | u16 ctrl = EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP | MAL_TX_CTRL_READY | | ||
1366 | MAL_TX_CTRL_LAST | emac_tx_csum(dev, skb); | ||
1367 | |||
1368 | slot = dev->tx_slot++; | ||
1369 | if (dev->tx_slot == NUM_TX_BUFF) { | ||
1370 | dev->tx_slot = 0; | ||
1371 | ctrl |= MAL_TX_CTRL_WRAP; | ||
1372 | } | ||
1373 | |||
1374 | DBG2(dev, "xmit(%u) %d" NL, len, slot); | ||
1375 | |||
1376 | dev->tx_skb[slot] = skb; | ||
1377 | dev->tx_desc[slot].data_ptr = dma_map_single(&dev->ofdev->dev, | ||
1378 | skb->data, len, | ||
1379 | DMA_TO_DEVICE); | ||
1380 | dev->tx_desc[slot].data_len = (u16) len; | ||
1381 | wmb(); | ||
1382 | dev->tx_desc[slot].ctrl = ctrl; | ||
1383 | |||
1384 | return emac_xmit_finish(dev, len); | ||
1385 | } | ||
1386 | |||
1387 | static inline int emac_xmit_split(struct emac_instance *dev, int slot, | ||
1388 | u32 pd, int len, int last, u16 base_ctrl) | ||
1389 | { | ||
1390 | while (1) { | ||
1391 | u16 ctrl = base_ctrl; | ||
1392 | int chunk = min(len, MAL_MAX_TX_SIZE); | ||
1393 | len -= chunk; | ||
1394 | |||
1395 | slot = (slot + 1) % NUM_TX_BUFF; | ||
1396 | |||
1397 | if (last && !len) | ||
1398 | ctrl |= MAL_TX_CTRL_LAST; | ||
1399 | if (slot == NUM_TX_BUFF - 1) | ||
1400 | ctrl |= MAL_TX_CTRL_WRAP; | ||
1401 | |||
1402 | dev->tx_skb[slot] = NULL; | ||
1403 | dev->tx_desc[slot].data_ptr = pd; | ||
1404 | dev->tx_desc[slot].data_len = (u16) chunk; | ||
1405 | dev->tx_desc[slot].ctrl = ctrl; | ||
1406 | ++dev->tx_cnt; | ||
1407 | |||
1408 | if (!len) | ||
1409 | break; | ||
1410 | |||
1411 | pd += chunk; | ||
1412 | } | ||
1413 | return slot; | ||
1414 | } | ||
1415 | |||
1416 | /* Tx lock BH disabled (SG version for TAH equipped EMACs) */ | ||
1417 | static int emac_start_xmit_sg(struct sk_buff *skb, struct net_device *ndev) | ||
1418 | { | ||
1419 | struct emac_instance *dev = netdev_priv(ndev); | ||
1420 | int nr_frags = skb_shinfo(skb)->nr_frags; | ||
1421 | int len = skb->len, chunk; | ||
1422 | int slot, i; | ||
1423 | u16 ctrl; | ||
1424 | u32 pd; | ||
1425 | |||
1426 | /* This is common "fast" path */ | ||
1427 | if (likely(!nr_frags && len <= MAL_MAX_TX_SIZE)) | ||
1428 | return emac_start_xmit(skb, ndev); | ||
1429 | |||
1430 | len -= skb->data_len; | ||
1431 | |||
1432 | /* Note, this is only an *estimation*, we can still run out of empty | ||
1433 | * slots because of the additional fragmentation into | ||
1434 | * MAL_MAX_TX_SIZE-sized chunks | ||
1435 | */ | ||
1436 | if (unlikely(dev->tx_cnt + nr_frags + mal_tx_chunks(len) > NUM_TX_BUFF)) | ||
1437 | goto stop_queue; | ||
1438 | |||
1439 | ctrl = EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP | MAL_TX_CTRL_READY | | ||
1440 | emac_tx_csum(dev, skb); | ||
1441 | slot = dev->tx_slot; | ||
1442 | |||
1443 | /* skb data */ | ||
1444 | dev->tx_skb[slot] = NULL; | ||
1445 | chunk = min(len, MAL_MAX_TX_SIZE); | ||
1446 | dev->tx_desc[slot].data_ptr = pd = | ||
1447 | dma_map_single(&dev->ofdev->dev, skb->data, len, DMA_TO_DEVICE); | ||
1448 | dev->tx_desc[slot].data_len = (u16) chunk; | ||
1449 | len -= chunk; | ||
1450 | if (unlikely(len)) | ||
1451 | slot = emac_xmit_split(dev, slot, pd + chunk, len, !nr_frags, | ||
1452 | ctrl); | ||
1453 | /* skb fragments */ | ||
1454 | for (i = 0; i < nr_frags; ++i) { | ||
1455 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i]; | ||
1456 | len = frag->size; | ||
1457 | |||
1458 | if (unlikely(dev->tx_cnt + mal_tx_chunks(len) >= NUM_TX_BUFF)) | ||
1459 | goto undo_frame; | ||
1460 | |||
1461 | pd = dma_map_page(&dev->ofdev->dev, frag->page, frag->page_offset, len, | ||
1462 | DMA_TO_DEVICE); | ||
1463 | |||
1464 | slot = emac_xmit_split(dev, slot, pd, len, i == nr_frags - 1, | ||
1465 | ctrl); | ||
1466 | } | ||
1467 | |||
1468 | DBG2(dev, "xmit_sg(%u) %d - %d" NL, skb->len, dev->tx_slot, slot); | ||
1469 | |||
1470 | /* Attach skb to the last slot so we don't release it too early */ | ||
1471 | dev->tx_skb[slot] = skb; | ||
1472 | |||
1473 | /* Send the packet out */ | ||
1474 | if (dev->tx_slot == NUM_TX_BUFF - 1) | ||
1475 | ctrl |= MAL_TX_CTRL_WRAP; | ||
1476 | wmb(); | ||
1477 | dev->tx_desc[dev->tx_slot].ctrl = ctrl; | ||
1478 | dev->tx_slot = (slot + 1) % NUM_TX_BUFF; | ||
1479 | |||
1480 | return emac_xmit_finish(dev, skb->len); | ||
1481 | |||
1482 | undo_frame: | ||
1483 | /* Well, too bad. Our previous estimation was overly optimistic. | ||
1484 | * Undo everything. | ||
1485 | */ | ||
1486 | while (slot != dev->tx_slot) { | ||
1487 | dev->tx_desc[slot].ctrl = 0; | ||
1488 | --dev->tx_cnt; | ||
1489 | if (--slot < 0) | ||
1490 | slot = NUM_TX_BUFF - 1; | ||
1491 | } | ||
1492 | ++dev->estats.tx_undo; | ||
1493 | |||
1494 | stop_queue: | ||
1495 | netif_stop_queue(ndev); | ||
1496 | DBG2(dev, "stopped TX queue" NL); | ||
1497 | return NETDEV_TX_BUSY; | ||
1498 | } | ||
1499 | |||
1500 | /* Tx lock BHs */ | ||
1501 | static void emac_parse_tx_error(struct emac_instance *dev, u16 ctrl) | ||
1502 | { | ||
1503 | struct emac_error_stats *st = &dev->estats; | ||
1504 | |||
1505 | DBG(dev, "BD TX error %04x" NL, ctrl); | ||
1506 | |||
1507 | ++st->tx_bd_errors; | ||
1508 | if (ctrl & EMAC_TX_ST_BFCS) | ||
1509 | ++st->tx_bd_bad_fcs; | ||
1510 | if (ctrl & EMAC_TX_ST_LCS) | ||
1511 | ++st->tx_bd_carrier_loss; | ||
1512 | if (ctrl & EMAC_TX_ST_ED) | ||
1513 | ++st->tx_bd_excessive_deferral; | ||
1514 | if (ctrl & EMAC_TX_ST_EC) | ||
1515 | ++st->tx_bd_excessive_collisions; | ||
1516 | if (ctrl & EMAC_TX_ST_LC) | ||
1517 | ++st->tx_bd_late_collision; | ||
1518 | if (ctrl & EMAC_TX_ST_MC) | ||
1519 | ++st->tx_bd_multple_collisions; | ||
1520 | if (ctrl & EMAC_TX_ST_SC) | ||
1521 | ++st->tx_bd_single_collision; | ||
1522 | if (ctrl & EMAC_TX_ST_UR) | ||
1523 | ++st->tx_bd_underrun; | ||
1524 | if (ctrl & EMAC_TX_ST_SQE) | ||
1525 | ++st->tx_bd_sqe; | ||
1526 | } | ||
1527 | |||
1528 | static void emac_poll_tx(void *param) | ||
1529 | { | ||
1530 | struct emac_instance *dev = param; | ||
1531 | u32 bad_mask; | ||
1532 | |||
1533 | DBG2(dev, "poll_tx, %d %d" NL, dev->tx_cnt, dev->ack_slot); | ||
1534 | |||
1535 | if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) | ||
1536 | bad_mask = EMAC_IS_BAD_TX_TAH; | ||
1537 | else | ||
1538 | bad_mask = EMAC_IS_BAD_TX; | ||
1539 | |||
1540 | netif_tx_lock_bh(dev->ndev); | ||
1541 | if (dev->tx_cnt) { | ||
1542 | u16 ctrl; | ||
1543 | int slot = dev->ack_slot, n = 0; | ||
1544 | again: | ||
1545 | ctrl = dev->tx_desc[slot].ctrl; | ||
1546 | if (!(ctrl & MAL_TX_CTRL_READY)) { | ||
1547 | struct sk_buff *skb = dev->tx_skb[slot]; | ||
1548 | ++n; | ||
1549 | |||
1550 | if (skb) { | ||
1551 | dev_kfree_skb(skb); | ||
1552 | dev->tx_skb[slot] = NULL; | ||
1553 | } | ||
1554 | slot = (slot + 1) % NUM_TX_BUFF; | ||
1555 | |||
1556 | if (unlikely(ctrl & bad_mask)) | ||
1557 | emac_parse_tx_error(dev, ctrl); | ||
1558 | |||
1559 | if (--dev->tx_cnt) | ||
1560 | goto again; | ||
1561 | } | ||
1562 | if (n) { | ||
1563 | dev->ack_slot = slot; | ||
1564 | if (netif_queue_stopped(dev->ndev) && | ||
1565 | dev->tx_cnt < EMAC_TX_WAKEUP_THRESH) | ||
1566 | netif_wake_queue(dev->ndev); | ||
1567 | |||
1568 | DBG2(dev, "tx %d pkts" NL, n); | ||
1569 | } | ||
1570 | } | ||
1571 | netif_tx_unlock_bh(dev->ndev); | ||
1572 | } | ||
1573 | |||
1574 | static inline void emac_recycle_rx_skb(struct emac_instance *dev, int slot, | ||
1575 | int len) | ||
1576 | { | ||
1577 | struct sk_buff *skb = dev->rx_skb[slot]; | ||
1578 | |||
1579 | DBG2(dev, "recycle %d %d" NL, slot, len); | ||
1580 | |||
1581 | if (len) | ||
1582 | dma_map_single(&dev->ofdev->dev, skb->data - 2, | ||
1583 | EMAC_DMA_ALIGN(len + 2), DMA_FROM_DEVICE); | ||
1584 | |||
1585 | dev->rx_desc[slot].data_len = 0; | ||
1586 | wmb(); | ||
1587 | dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | | ||
1588 | (slot == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0); | ||
1589 | } | ||
1590 | |||
1591 | static void emac_parse_rx_error(struct emac_instance *dev, u16 ctrl) | ||
1592 | { | ||
1593 | struct emac_error_stats *st = &dev->estats; | ||
1594 | |||
1595 | DBG(dev, "BD RX error %04x" NL, ctrl); | ||
1596 | |||
1597 | ++st->rx_bd_errors; | ||
1598 | if (ctrl & EMAC_RX_ST_OE) | ||
1599 | ++st->rx_bd_overrun; | ||
1600 | if (ctrl & EMAC_RX_ST_BP) | ||
1601 | ++st->rx_bd_bad_packet; | ||
1602 | if (ctrl & EMAC_RX_ST_RP) | ||
1603 | ++st->rx_bd_runt_packet; | ||
1604 | if (ctrl & EMAC_RX_ST_SE) | ||
1605 | ++st->rx_bd_short_event; | ||
1606 | if (ctrl & EMAC_RX_ST_AE) | ||
1607 | ++st->rx_bd_alignment_error; | ||
1608 | if (ctrl & EMAC_RX_ST_BFCS) | ||
1609 | ++st->rx_bd_bad_fcs; | ||
1610 | if (ctrl & EMAC_RX_ST_PTL) | ||
1611 | ++st->rx_bd_packet_too_long; | ||
1612 | if (ctrl & EMAC_RX_ST_ORE) | ||
1613 | ++st->rx_bd_out_of_range; | ||
1614 | if (ctrl & EMAC_RX_ST_IRE) | ||
1615 | ++st->rx_bd_in_range; | ||
1616 | } | ||
1617 | |||
1618 | static inline void emac_rx_csum(struct emac_instance *dev, | ||
1619 | struct sk_buff *skb, u16 ctrl) | ||
1620 | { | ||
1621 | #ifdef CONFIG_IBM_NEW_EMAC_TAH | ||
1622 | if (!ctrl && dev->tah_dev) { | ||
1623 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
1624 | ++dev->stats.rx_packets_csum; | ||
1625 | } | ||
1626 | #endif | ||
1627 | } | ||
1628 | |||
1629 | static inline int emac_rx_sg_append(struct emac_instance *dev, int slot) | ||
1630 | { | ||
1631 | if (likely(dev->rx_sg_skb != NULL)) { | ||
1632 | int len = dev->rx_desc[slot].data_len; | ||
1633 | int tot_len = dev->rx_sg_skb->len + len; | ||
1634 | |||
1635 | if (unlikely(tot_len + 2 > dev->rx_skb_size)) { | ||
1636 | ++dev->estats.rx_dropped_mtu; | ||
1637 | dev_kfree_skb(dev->rx_sg_skb); | ||
1638 | dev->rx_sg_skb = NULL; | ||
1639 | } else { | ||
1640 | cacheable_memcpy(skb_tail_pointer(dev->rx_sg_skb), | ||
1641 | dev->rx_skb[slot]->data, len); | ||
1642 | skb_put(dev->rx_sg_skb, len); | ||
1643 | emac_recycle_rx_skb(dev, slot, len); | ||
1644 | return 0; | ||
1645 | } | ||
1646 | } | ||
1647 | emac_recycle_rx_skb(dev, slot, 0); | ||
1648 | return -1; | ||
1649 | } | ||
1650 | |||
1651 | /* NAPI poll context */ | ||
1652 | static int emac_poll_rx(void *param, int budget) | ||
1653 | { | ||
1654 | struct emac_instance *dev = param; | ||
1655 | int slot = dev->rx_slot, received = 0; | ||
1656 | |||
1657 | DBG2(dev, "poll_rx(%d)" NL, budget); | ||
1658 | |||
1659 | again: | ||
1660 | while (budget > 0) { | ||
1661 | int len; | ||
1662 | struct sk_buff *skb; | ||
1663 | u16 ctrl = dev->rx_desc[slot].ctrl; | ||
1664 | |||
1665 | if (ctrl & MAL_RX_CTRL_EMPTY) | ||
1666 | break; | ||
1667 | |||
1668 | skb = dev->rx_skb[slot]; | ||
1669 | mb(); | ||
1670 | len = dev->rx_desc[slot].data_len; | ||
1671 | |||
1672 | if (unlikely(!MAL_IS_SINGLE_RX(ctrl))) | ||
1673 | goto sg; | ||
1674 | |||
1675 | ctrl &= EMAC_BAD_RX_MASK; | ||
1676 | if (unlikely(ctrl && ctrl != EMAC_RX_TAH_BAD_CSUM)) { | ||
1677 | emac_parse_rx_error(dev, ctrl); | ||
1678 | ++dev->estats.rx_dropped_error; | ||
1679 | emac_recycle_rx_skb(dev, slot, 0); | ||
1680 | len = 0; | ||
1681 | goto next; | ||
1682 | } | ||
1683 | |||
1684 | if (len < ETH_HLEN) { | ||
1685 | ++dev->estats.rx_dropped_stack; | ||
1686 | emac_recycle_rx_skb(dev, slot, len); | ||
1687 | goto next; | ||
1688 | } | ||
1689 | |||
1690 | if (len && len < EMAC_RX_COPY_THRESH) { | ||
1691 | struct sk_buff *copy_skb = | ||
1692 | alloc_skb(len + EMAC_RX_SKB_HEADROOM + 2, GFP_ATOMIC); | ||
1693 | if (unlikely(!copy_skb)) | ||
1694 | goto oom; | ||
1695 | |||
1696 | skb_reserve(copy_skb, EMAC_RX_SKB_HEADROOM + 2); | ||
1697 | cacheable_memcpy(copy_skb->data - 2, skb->data - 2, | ||
1698 | len + 2); | ||
1699 | emac_recycle_rx_skb(dev, slot, len); | ||
1700 | skb = copy_skb; | ||
1701 | } else if (unlikely(emac_alloc_rx_skb(dev, slot, GFP_ATOMIC))) | ||
1702 | goto oom; | ||
1703 | |||
1704 | skb_put(skb, len); | ||
1705 | push_packet: | ||
1706 | skb->protocol = eth_type_trans(skb, dev->ndev); | ||
1707 | emac_rx_csum(dev, skb, ctrl); | ||
1708 | |||
1709 | if (unlikely(netif_receive_skb(skb) == NET_RX_DROP)) | ||
1710 | ++dev->estats.rx_dropped_stack; | ||
1711 | next: | ||
1712 | ++dev->stats.rx_packets; | ||
1713 | skip: | ||
1714 | dev->stats.rx_bytes += len; | ||
1715 | slot = (slot + 1) % NUM_RX_BUFF; | ||
1716 | --budget; | ||
1717 | ++received; | ||
1718 | continue; | ||
1719 | sg: | ||
1720 | if (ctrl & MAL_RX_CTRL_FIRST) { | ||
1721 | BUG_ON(dev->rx_sg_skb); | ||
1722 | if (unlikely(emac_alloc_rx_skb(dev, slot, GFP_ATOMIC))) { | ||
1723 | DBG(dev, "rx OOM %d" NL, slot); | ||
1724 | ++dev->estats.rx_dropped_oom; | ||
1725 | emac_recycle_rx_skb(dev, slot, 0); | ||
1726 | } else { | ||
1727 | dev->rx_sg_skb = skb; | ||
1728 | skb_put(skb, len); | ||
1729 | } | ||
1730 | } else if (!emac_rx_sg_append(dev, slot) && | ||
1731 | (ctrl & MAL_RX_CTRL_LAST)) { | ||
1732 | |||
1733 | skb = dev->rx_sg_skb; | ||
1734 | dev->rx_sg_skb = NULL; | ||
1735 | |||
1736 | ctrl &= EMAC_BAD_RX_MASK; | ||
1737 | if (unlikely(ctrl && ctrl != EMAC_RX_TAH_BAD_CSUM)) { | ||
1738 | emac_parse_rx_error(dev, ctrl); | ||
1739 | ++dev->estats.rx_dropped_error; | ||
1740 | dev_kfree_skb(skb); | ||
1741 | len = 0; | ||
1742 | } else | ||
1743 | goto push_packet; | ||
1744 | } | ||
1745 | goto skip; | ||
1746 | oom: | ||
1747 | DBG(dev, "rx OOM %d" NL, slot); | ||
1748 | /* Drop the packet and recycle skb */ | ||
1749 | ++dev->estats.rx_dropped_oom; | ||
1750 | emac_recycle_rx_skb(dev, slot, 0); | ||
1751 | goto next; | ||
1752 | } | ||
1753 | |||
1754 | if (received) { | ||
1755 | DBG2(dev, "rx %d BDs" NL, received); | ||
1756 | dev->rx_slot = slot; | ||
1757 | } | ||
1758 | |||
1759 | if (unlikely(budget && test_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags))) { | ||
1760 | mb(); | ||
1761 | if (!(dev->rx_desc[slot].ctrl & MAL_RX_CTRL_EMPTY)) { | ||
1762 | DBG2(dev, "rx restart" NL); | ||
1763 | received = 0; | ||
1764 | goto again; | ||
1765 | } | ||
1766 | |||
1767 | if (dev->rx_sg_skb) { | ||
1768 | DBG2(dev, "dropping partial rx packet" NL); | ||
1769 | ++dev->estats.rx_dropped_error; | ||
1770 | dev_kfree_skb(dev->rx_sg_skb); | ||
1771 | dev->rx_sg_skb = NULL; | ||
1772 | } | ||
1773 | |||
1774 | clear_bit(MAL_COMMAC_RX_STOPPED, &dev->commac.flags); | ||
1775 | mal_enable_rx_channel(dev->mal, dev->mal_rx_chan); | ||
1776 | emac_rx_enable(dev); | ||
1777 | dev->rx_slot = 0; | ||
1778 | } | ||
1779 | return received; | ||
1780 | } | ||
1781 | |||
1782 | /* NAPI poll context */ | ||
1783 | static int emac_peek_rx(void *param) | ||
1784 | { | ||
1785 | struct emac_instance *dev = param; | ||
1786 | |||
1787 | return !(dev->rx_desc[dev->rx_slot].ctrl & MAL_RX_CTRL_EMPTY); | ||
1788 | } | ||
1789 | |||
1790 | /* NAPI poll context */ | ||
1791 | static int emac_peek_rx_sg(void *param) | ||
1792 | { | ||
1793 | struct emac_instance *dev = param; | ||
1794 | |||
1795 | int slot = dev->rx_slot; | ||
1796 | while (1) { | ||
1797 | u16 ctrl = dev->rx_desc[slot].ctrl; | ||
1798 | if (ctrl & MAL_RX_CTRL_EMPTY) | ||
1799 | return 0; | ||
1800 | else if (ctrl & MAL_RX_CTRL_LAST) | ||
1801 | return 1; | ||
1802 | |||
1803 | slot = (slot + 1) % NUM_RX_BUFF; | ||
1804 | |||
1805 | /* I'm just being paranoid here :) */ | ||
1806 | if (unlikely(slot == dev->rx_slot)) | ||
1807 | return 0; | ||
1808 | } | ||
1809 | } | ||
1810 | |||
1811 | /* Hard IRQ */ | ||
1812 | static void emac_rxde(void *param) | ||
1813 | { | ||
1814 | struct emac_instance *dev = param; | ||
1815 | |||
1816 | ++dev->estats.rx_stopped; | ||
1817 | emac_rx_disable_async(dev); | ||
1818 | } | ||
1819 | |||
1820 | /* Hard IRQ */ | ||
1821 | static irqreturn_t emac_irq(int irq, void *dev_instance) | ||
1822 | { | ||
1823 | struct emac_instance *dev = dev_instance; | ||
1824 | struct emac_regs __iomem *p = dev->emacp; | ||
1825 | struct emac_error_stats *st = &dev->estats; | ||
1826 | u32 isr; | ||
1827 | |||
1828 | spin_lock(&dev->lock); | ||
1829 | |||
1830 | isr = in_be32(&p->isr); | ||
1831 | out_be32(&p->isr, isr); | ||
1832 | |||
1833 | DBG(dev, "isr = %08x" NL, isr); | ||
1834 | |||
1835 | if (isr & EMAC4_ISR_TXPE) | ||
1836 | ++st->tx_parity; | ||
1837 | if (isr & EMAC4_ISR_RXPE) | ||
1838 | ++st->rx_parity; | ||
1839 | if (isr & EMAC4_ISR_TXUE) | ||
1840 | ++st->tx_underrun; | ||
1841 | if (isr & EMAC4_ISR_RXOE) | ||
1842 | ++st->rx_fifo_overrun; | ||
1843 | if (isr & EMAC_ISR_OVR) | ||
1844 | ++st->rx_overrun; | ||
1845 | if (isr & EMAC_ISR_BP) | ||
1846 | ++st->rx_bad_packet; | ||
1847 | if (isr & EMAC_ISR_RP) | ||
1848 | ++st->rx_runt_packet; | ||
1849 | if (isr & EMAC_ISR_SE) | ||
1850 | ++st->rx_short_event; | ||
1851 | if (isr & EMAC_ISR_ALE) | ||
1852 | ++st->rx_alignment_error; | ||
1853 | if (isr & EMAC_ISR_BFCS) | ||
1854 | ++st->rx_bad_fcs; | ||
1855 | if (isr & EMAC_ISR_PTLE) | ||
1856 | ++st->rx_packet_too_long; | ||
1857 | if (isr & EMAC_ISR_ORE) | ||
1858 | ++st->rx_out_of_range; | ||
1859 | if (isr & EMAC_ISR_IRE) | ||
1860 | ++st->rx_in_range; | ||
1861 | if (isr & EMAC_ISR_SQE) | ||
1862 | ++st->tx_sqe; | ||
1863 | if (isr & EMAC_ISR_TE) | ||
1864 | ++st->tx_errors; | ||
1865 | |||
1866 | spin_unlock(&dev->lock); | ||
1867 | |||
1868 | return IRQ_HANDLED; | ||
1869 | } | ||
1870 | |||
1871 | static struct net_device_stats *emac_stats(struct net_device *ndev) | ||
1872 | { | ||
1873 | struct emac_instance *dev = netdev_priv(ndev); | ||
1874 | struct emac_stats *st = &dev->stats; | ||
1875 | struct emac_error_stats *est = &dev->estats; | ||
1876 | struct net_device_stats *nst = &dev->nstats; | ||
1877 | unsigned long flags; | ||
1878 | |||
1879 | DBG2(dev, "stats" NL); | ||
1880 | |||
1881 | /* Compute "legacy" statistics */ | ||
1882 | spin_lock_irqsave(&dev->lock, flags); | ||
1883 | nst->rx_packets = (unsigned long)st->rx_packets; | ||
1884 | nst->rx_bytes = (unsigned long)st->rx_bytes; | ||
1885 | nst->tx_packets = (unsigned long)st->tx_packets; | ||
1886 | nst->tx_bytes = (unsigned long)st->tx_bytes; | ||
1887 | nst->rx_dropped = (unsigned long)(est->rx_dropped_oom + | ||
1888 | est->rx_dropped_error + | ||
1889 | est->rx_dropped_resize + | ||
1890 | est->rx_dropped_mtu); | ||
1891 | nst->tx_dropped = (unsigned long)est->tx_dropped; | ||
1892 | |||
1893 | nst->rx_errors = (unsigned long)est->rx_bd_errors; | ||
1894 | nst->rx_fifo_errors = (unsigned long)(est->rx_bd_overrun + | ||
1895 | est->rx_fifo_overrun + | ||
1896 | est->rx_overrun); | ||
1897 | nst->rx_frame_errors = (unsigned long)(est->rx_bd_alignment_error + | ||
1898 | est->rx_alignment_error); | ||
1899 | nst->rx_crc_errors = (unsigned long)(est->rx_bd_bad_fcs + | ||
1900 | est->rx_bad_fcs); | ||
1901 | nst->rx_length_errors = (unsigned long)(est->rx_bd_runt_packet + | ||
1902 | est->rx_bd_short_event + | ||
1903 | est->rx_bd_packet_too_long + | ||
1904 | est->rx_bd_out_of_range + | ||
1905 | est->rx_bd_in_range + | ||
1906 | est->rx_runt_packet + | ||
1907 | est->rx_short_event + | ||
1908 | est->rx_packet_too_long + | ||
1909 | est->rx_out_of_range + | ||
1910 | est->rx_in_range); | ||
1911 | |||
1912 | nst->tx_errors = (unsigned long)(est->tx_bd_errors + est->tx_errors); | ||
1913 | nst->tx_fifo_errors = (unsigned long)(est->tx_bd_underrun + | ||
1914 | est->tx_underrun); | ||
1915 | nst->tx_carrier_errors = (unsigned long)est->tx_bd_carrier_loss; | ||
1916 | nst->collisions = (unsigned long)(est->tx_bd_excessive_deferral + | ||
1917 | est->tx_bd_excessive_collisions + | ||
1918 | est->tx_bd_late_collision + | ||
1919 | est->tx_bd_multple_collisions); | ||
1920 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1921 | return nst; | ||
1922 | } | ||
1923 | |||
1924 | static struct mal_commac_ops emac_commac_ops = { | ||
1925 | .poll_tx = &emac_poll_tx, | ||
1926 | .poll_rx = &emac_poll_rx, | ||
1927 | .peek_rx = &emac_peek_rx, | ||
1928 | .rxde = &emac_rxde, | ||
1929 | }; | ||
1930 | |||
1931 | static struct mal_commac_ops emac_commac_sg_ops = { | ||
1932 | .poll_tx = &emac_poll_tx, | ||
1933 | .poll_rx = &emac_poll_rx, | ||
1934 | .peek_rx = &emac_peek_rx_sg, | ||
1935 | .rxde = &emac_rxde, | ||
1936 | }; | ||
1937 | |||
1938 | /* Ethtool support */ | ||
1939 | static int emac_ethtool_get_settings(struct net_device *ndev, | ||
1940 | struct ethtool_cmd *cmd) | ||
1941 | { | ||
1942 | struct emac_instance *dev = netdev_priv(ndev); | ||
1943 | |||
1944 | cmd->supported = dev->phy.features; | ||
1945 | cmd->port = PORT_MII; | ||
1946 | cmd->phy_address = dev->phy.address; | ||
1947 | cmd->transceiver = | ||
1948 | dev->phy.address >= 0 ? XCVR_EXTERNAL : XCVR_INTERNAL; | ||
1949 | |||
1950 | mutex_lock(&dev->link_lock); | ||
1951 | cmd->advertising = dev->phy.advertising; | ||
1952 | cmd->autoneg = dev->phy.autoneg; | ||
1953 | cmd->speed = dev->phy.speed; | ||
1954 | cmd->duplex = dev->phy.duplex; | ||
1955 | mutex_unlock(&dev->link_lock); | ||
1956 | |||
1957 | return 0; | ||
1958 | } | ||
1959 | |||
1960 | static int emac_ethtool_set_settings(struct net_device *ndev, | ||
1961 | struct ethtool_cmd *cmd) | ||
1962 | { | ||
1963 | struct emac_instance *dev = netdev_priv(ndev); | ||
1964 | u32 f = dev->phy.features; | ||
1965 | |||
1966 | DBG(dev, "set_settings(%d, %d, %d, 0x%08x)" NL, | ||
1967 | cmd->autoneg, cmd->speed, cmd->duplex, cmd->advertising); | ||
1968 | |||
1969 | /* Basic sanity checks */ | ||
1970 | if (dev->phy.address < 0) | ||
1971 | return -EOPNOTSUPP; | ||
1972 | if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE) | ||
1973 | return -EINVAL; | ||
1974 | if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0) | ||
1975 | return -EINVAL; | ||
1976 | if (cmd->duplex != DUPLEX_HALF && cmd->duplex != DUPLEX_FULL) | ||
1977 | return -EINVAL; | ||
1978 | |||
1979 | if (cmd->autoneg == AUTONEG_DISABLE) { | ||
1980 | switch (cmd->speed) { | ||
1981 | case SPEED_10: | ||
1982 | if (cmd->duplex == DUPLEX_HALF && | ||
1983 | !(f & SUPPORTED_10baseT_Half)) | ||
1984 | return -EINVAL; | ||
1985 | if (cmd->duplex == DUPLEX_FULL && | ||
1986 | !(f & SUPPORTED_10baseT_Full)) | ||
1987 | return -EINVAL; | ||
1988 | break; | ||
1989 | case SPEED_100: | ||
1990 | if (cmd->duplex == DUPLEX_HALF && | ||
1991 | !(f & SUPPORTED_100baseT_Half)) | ||
1992 | return -EINVAL; | ||
1993 | if (cmd->duplex == DUPLEX_FULL && | ||
1994 | !(f & SUPPORTED_100baseT_Full)) | ||
1995 | return -EINVAL; | ||
1996 | break; | ||
1997 | case SPEED_1000: | ||
1998 | if (cmd->duplex == DUPLEX_HALF && | ||
1999 | !(f & SUPPORTED_1000baseT_Half)) | ||
2000 | return -EINVAL; | ||
2001 | if (cmd->duplex == DUPLEX_FULL && | ||
2002 | !(f & SUPPORTED_1000baseT_Full)) | ||
2003 | return -EINVAL; | ||
2004 | break; | ||
2005 | default: | ||
2006 | return -EINVAL; | ||
2007 | } | ||
2008 | |||
2009 | mutex_lock(&dev->link_lock); | ||
2010 | dev->phy.def->ops->setup_forced(&dev->phy, cmd->speed, | ||
2011 | cmd->duplex); | ||
2012 | mutex_unlock(&dev->link_lock); | ||
2013 | |||
2014 | } else { | ||
2015 | if (!(f & SUPPORTED_Autoneg)) | ||
2016 | return -EINVAL; | ||
2017 | |||
2018 | mutex_lock(&dev->link_lock); | ||
2019 | dev->phy.def->ops->setup_aneg(&dev->phy, | ||
2020 | (cmd->advertising & f) | | ||
2021 | (dev->phy.advertising & | ||
2022 | (ADVERTISED_Pause | | ||
2023 | ADVERTISED_Asym_Pause))); | ||
2024 | mutex_unlock(&dev->link_lock); | ||
2025 | } | ||
2026 | emac_force_link_update(dev); | ||
2027 | |||
2028 | return 0; | ||
2029 | } | ||
2030 | |||
2031 | static void emac_ethtool_get_ringparam(struct net_device *ndev, | ||
2032 | struct ethtool_ringparam *rp) | ||
2033 | { | ||
2034 | rp->rx_max_pending = rp->rx_pending = NUM_RX_BUFF; | ||
2035 | rp->tx_max_pending = rp->tx_pending = NUM_TX_BUFF; | ||
2036 | } | ||
2037 | |||
2038 | static void emac_ethtool_get_pauseparam(struct net_device *ndev, | ||
2039 | struct ethtool_pauseparam *pp) | ||
2040 | { | ||
2041 | struct emac_instance *dev = netdev_priv(ndev); | ||
2042 | |||
2043 | mutex_lock(&dev->link_lock); | ||
2044 | if ((dev->phy.features & SUPPORTED_Autoneg) && | ||
2045 | (dev->phy.advertising & (ADVERTISED_Pause | ADVERTISED_Asym_Pause))) | ||
2046 | pp->autoneg = 1; | ||
2047 | |||
2048 | if (dev->phy.duplex == DUPLEX_FULL) { | ||
2049 | if (dev->phy.pause) | ||
2050 | pp->rx_pause = pp->tx_pause = 1; | ||
2051 | else if (dev->phy.asym_pause) | ||
2052 | pp->tx_pause = 1; | ||
2053 | } | ||
2054 | mutex_unlock(&dev->link_lock); | ||
2055 | } | ||
2056 | |||
2057 | static int emac_get_regs_len(struct emac_instance *dev) | ||
2058 | { | ||
2059 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) | ||
2060 | return sizeof(struct emac_ethtool_regs_subhdr) + | ||
2061 | EMAC4_ETHTOOL_REGS_SIZE(dev); | ||
2062 | else | ||
2063 | return sizeof(struct emac_ethtool_regs_subhdr) + | ||
2064 | EMAC_ETHTOOL_REGS_SIZE(dev); | ||
2065 | } | ||
2066 | |||
2067 | static int emac_ethtool_get_regs_len(struct net_device *ndev) | ||
2068 | { | ||
2069 | struct emac_instance *dev = netdev_priv(ndev); | ||
2070 | int size; | ||
2071 | |||
2072 | size = sizeof(struct emac_ethtool_regs_hdr) + | ||
2073 | emac_get_regs_len(dev) + mal_get_regs_len(dev->mal); | ||
2074 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) | ||
2075 | size += zmii_get_regs_len(dev->zmii_dev); | ||
2076 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) | ||
2077 | size += rgmii_get_regs_len(dev->rgmii_dev); | ||
2078 | if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) | ||
2079 | size += tah_get_regs_len(dev->tah_dev); | ||
2080 | |||
2081 | return size; | ||
2082 | } | ||
2083 | |||
2084 | static void *emac_dump_regs(struct emac_instance *dev, void *buf) | ||
2085 | { | ||
2086 | struct emac_ethtool_regs_subhdr *hdr = buf; | ||
2087 | |||
2088 | hdr->index = dev->cell_index; | ||
2089 | if (emac_has_feature(dev, EMAC_FTR_EMAC4)) { | ||
2090 | hdr->version = EMAC4_ETHTOOL_REGS_VER; | ||
2091 | memcpy_fromio(hdr + 1, dev->emacp, EMAC4_ETHTOOL_REGS_SIZE(dev)); | ||
2092 | return (void *)(hdr + 1) + EMAC4_ETHTOOL_REGS_SIZE(dev); | ||
2093 | } else { | ||
2094 | hdr->version = EMAC_ETHTOOL_REGS_VER; | ||
2095 | memcpy_fromio(hdr + 1, dev->emacp, EMAC_ETHTOOL_REGS_SIZE(dev)); | ||
2096 | return (void *)(hdr + 1) + EMAC_ETHTOOL_REGS_SIZE(dev); | ||
2097 | } | ||
2098 | } | ||
2099 | |||
2100 | static void emac_ethtool_get_regs(struct net_device *ndev, | ||
2101 | struct ethtool_regs *regs, void *buf) | ||
2102 | { | ||
2103 | struct emac_instance *dev = netdev_priv(ndev); | ||
2104 | struct emac_ethtool_regs_hdr *hdr = buf; | ||
2105 | |||
2106 | hdr->components = 0; | ||
2107 | buf = hdr + 1; | ||
2108 | |||
2109 | buf = mal_dump_regs(dev->mal, buf); | ||
2110 | buf = emac_dump_regs(dev, buf); | ||
2111 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) { | ||
2112 | hdr->components |= EMAC_ETHTOOL_REGS_ZMII; | ||
2113 | buf = zmii_dump_regs(dev->zmii_dev, buf); | ||
2114 | } | ||
2115 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) { | ||
2116 | hdr->components |= EMAC_ETHTOOL_REGS_RGMII; | ||
2117 | buf = rgmii_dump_regs(dev->rgmii_dev, buf); | ||
2118 | } | ||
2119 | if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) { | ||
2120 | hdr->components |= EMAC_ETHTOOL_REGS_TAH; | ||
2121 | buf = tah_dump_regs(dev->tah_dev, buf); | ||
2122 | } | ||
2123 | } | ||
2124 | |||
2125 | static int emac_ethtool_nway_reset(struct net_device *ndev) | ||
2126 | { | ||
2127 | struct emac_instance *dev = netdev_priv(ndev); | ||
2128 | int res = 0; | ||
2129 | |||
2130 | DBG(dev, "nway_reset" NL); | ||
2131 | |||
2132 | if (dev->phy.address < 0) | ||
2133 | return -EOPNOTSUPP; | ||
2134 | |||
2135 | mutex_lock(&dev->link_lock); | ||
2136 | if (!dev->phy.autoneg) { | ||
2137 | res = -EINVAL; | ||
2138 | goto out; | ||
2139 | } | ||
2140 | |||
2141 | dev->phy.def->ops->setup_aneg(&dev->phy, dev->phy.advertising); | ||
2142 | out: | ||
2143 | mutex_unlock(&dev->link_lock); | ||
2144 | emac_force_link_update(dev); | ||
2145 | return res; | ||
2146 | } | ||
2147 | |||
2148 | static int emac_ethtool_get_sset_count(struct net_device *ndev, int stringset) | ||
2149 | { | ||
2150 | if (stringset == ETH_SS_STATS) | ||
2151 | return EMAC_ETHTOOL_STATS_COUNT; | ||
2152 | else | ||
2153 | return -EINVAL; | ||
2154 | } | ||
2155 | |||
2156 | static void emac_ethtool_get_strings(struct net_device *ndev, u32 stringset, | ||
2157 | u8 * buf) | ||
2158 | { | ||
2159 | if (stringset == ETH_SS_STATS) | ||
2160 | memcpy(buf, &emac_stats_keys, sizeof(emac_stats_keys)); | ||
2161 | } | ||
2162 | |||
2163 | static void emac_ethtool_get_ethtool_stats(struct net_device *ndev, | ||
2164 | struct ethtool_stats *estats, | ||
2165 | u64 * tmp_stats) | ||
2166 | { | ||
2167 | struct emac_instance *dev = netdev_priv(ndev); | ||
2168 | |||
2169 | memcpy(tmp_stats, &dev->stats, sizeof(dev->stats)); | ||
2170 | tmp_stats += sizeof(dev->stats) / sizeof(u64); | ||
2171 | memcpy(tmp_stats, &dev->estats, sizeof(dev->estats)); | ||
2172 | } | ||
2173 | |||
2174 | static void emac_ethtool_get_drvinfo(struct net_device *ndev, | ||
2175 | struct ethtool_drvinfo *info) | ||
2176 | { | ||
2177 | struct emac_instance *dev = netdev_priv(ndev); | ||
2178 | |||
2179 | strcpy(info->driver, "ibm_emac"); | ||
2180 | strcpy(info->version, DRV_VERSION); | ||
2181 | info->fw_version[0] = '\0'; | ||
2182 | sprintf(info->bus_info, "PPC 4xx EMAC-%d %s", | ||
2183 | dev->cell_index, dev->ofdev->dev.of_node->full_name); | ||
2184 | info->regdump_len = emac_ethtool_get_regs_len(ndev); | ||
2185 | } | ||
2186 | |||
2187 | static const struct ethtool_ops emac_ethtool_ops = { | ||
2188 | .get_settings = emac_ethtool_get_settings, | ||
2189 | .set_settings = emac_ethtool_set_settings, | ||
2190 | .get_drvinfo = emac_ethtool_get_drvinfo, | ||
2191 | |||
2192 | .get_regs_len = emac_ethtool_get_regs_len, | ||
2193 | .get_regs = emac_ethtool_get_regs, | ||
2194 | |||
2195 | .nway_reset = emac_ethtool_nway_reset, | ||
2196 | |||
2197 | .get_ringparam = emac_ethtool_get_ringparam, | ||
2198 | .get_pauseparam = emac_ethtool_get_pauseparam, | ||
2199 | |||
2200 | .get_strings = emac_ethtool_get_strings, | ||
2201 | .get_sset_count = emac_ethtool_get_sset_count, | ||
2202 | .get_ethtool_stats = emac_ethtool_get_ethtool_stats, | ||
2203 | |||
2204 | .get_link = ethtool_op_get_link, | ||
2205 | }; | ||
2206 | |||
2207 | static int emac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) | ||
2208 | { | ||
2209 | struct emac_instance *dev = netdev_priv(ndev); | ||
2210 | struct mii_ioctl_data *data = if_mii(rq); | ||
2211 | |||
2212 | DBG(dev, "ioctl %08x" NL, cmd); | ||
2213 | |||
2214 | if (dev->phy.address < 0) | ||
2215 | return -EOPNOTSUPP; | ||
2216 | |||
2217 | switch (cmd) { | ||
2218 | case SIOCGMIIPHY: | ||
2219 | data->phy_id = dev->phy.address; | ||
2220 | /* Fall through */ | ||
2221 | case SIOCGMIIREG: | ||
2222 | data->val_out = emac_mdio_read(ndev, dev->phy.address, | ||
2223 | data->reg_num); | ||
2224 | return 0; | ||
2225 | |||
2226 | case SIOCSMIIREG: | ||
2227 | emac_mdio_write(ndev, dev->phy.address, data->reg_num, | ||
2228 | data->val_in); | ||
2229 | return 0; | ||
2230 | default: | ||
2231 | return -EOPNOTSUPP; | ||
2232 | } | ||
2233 | } | ||
2234 | |||
2235 | struct emac_depentry { | ||
2236 | u32 phandle; | ||
2237 | struct device_node *node; | ||
2238 | struct platform_device *ofdev; | ||
2239 | void *drvdata; | ||
2240 | }; | ||
2241 | |||
2242 | #define EMAC_DEP_MAL_IDX 0 | ||
2243 | #define EMAC_DEP_ZMII_IDX 1 | ||
2244 | #define EMAC_DEP_RGMII_IDX 2 | ||
2245 | #define EMAC_DEP_TAH_IDX 3 | ||
2246 | #define EMAC_DEP_MDIO_IDX 4 | ||
2247 | #define EMAC_DEP_PREV_IDX 5 | ||
2248 | #define EMAC_DEP_COUNT 6 | ||
2249 | |||
2250 | static int __devinit emac_check_deps(struct emac_instance *dev, | ||
2251 | struct emac_depentry *deps) | ||
2252 | { | ||
2253 | int i, there = 0; | ||
2254 | struct device_node *np; | ||
2255 | |||
2256 | for (i = 0; i < EMAC_DEP_COUNT; i++) { | ||
2257 | /* no dependency on that item, allright */ | ||
2258 | if (deps[i].phandle == 0) { | ||
2259 | there++; | ||
2260 | continue; | ||
2261 | } | ||
2262 | /* special case for blist as the dependency might go away */ | ||
2263 | if (i == EMAC_DEP_PREV_IDX) { | ||
2264 | np = *(dev->blist - 1); | ||
2265 | if (np == NULL) { | ||
2266 | deps[i].phandle = 0; | ||
2267 | there++; | ||
2268 | continue; | ||
2269 | } | ||
2270 | if (deps[i].node == NULL) | ||
2271 | deps[i].node = of_node_get(np); | ||
2272 | } | ||
2273 | if (deps[i].node == NULL) | ||
2274 | deps[i].node = of_find_node_by_phandle(deps[i].phandle); | ||
2275 | if (deps[i].node == NULL) | ||
2276 | continue; | ||
2277 | if (deps[i].ofdev == NULL) | ||
2278 | deps[i].ofdev = of_find_device_by_node(deps[i].node); | ||
2279 | if (deps[i].ofdev == NULL) | ||
2280 | continue; | ||
2281 | if (deps[i].drvdata == NULL) | ||
2282 | deps[i].drvdata = dev_get_drvdata(&deps[i].ofdev->dev); | ||
2283 | if (deps[i].drvdata != NULL) | ||
2284 | there++; | ||
2285 | } | ||
2286 | return there == EMAC_DEP_COUNT; | ||
2287 | } | ||
2288 | |||
2289 | static void emac_put_deps(struct emac_instance *dev) | ||
2290 | { | ||
2291 | if (dev->mal_dev) | ||
2292 | of_dev_put(dev->mal_dev); | ||
2293 | if (dev->zmii_dev) | ||
2294 | of_dev_put(dev->zmii_dev); | ||
2295 | if (dev->rgmii_dev) | ||
2296 | of_dev_put(dev->rgmii_dev); | ||
2297 | if (dev->mdio_dev) | ||
2298 | of_dev_put(dev->mdio_dev); | ||
2299 | if (dev->tah_dev) | ||
2300 | of_dev_put(dev->tah_dev); | ||
2301 | } | ||
2302 | |||
2303 | static int __devinit emac_of_bus_notify(struct notifier_block *nb, | ||
2304 | unsigned long action, void *data) | ||
2305 | { | ||
2306 | /* We are only intereted in device addition */ | ||
2307 | if (action == BUS_NOTIFY_BOUND_DRIVER) | ||
2308 | wake_up_all(&emac_probe_wait); | ||
2309 | return 0; | ||
2310 | } | ||
2311 | |||
2312 | static struct notifier_block emac_of_bus_notifier __devinitdata = { | ||
2313 | .notifier_call = emac_of_bus_notify | ||
2314 | }; | ||
2315 | |||
2316 | static int __devinit emac_wait_deps(struct emac_instance *dev) | ||
2317 | { | ||
2318 | struct emac_depentry deps[EMAC_DEP_COUNT]; | ||
2319 | int i, err; | ||
2320 | |||
2321 | memset(&deps, 0, sizeof(deps)); | ||
2322 | |||
2323 | deps[EMAC_DEP_MAL_IDX].phandle = dev->mal_ph; | ||
2324 | deps[EMAC_DEP_ZMII_IDX].phandle = dev->zmii_ph; | ||
2325 | deps[EMAC_DEP_RGMII_IDX].phandle = dev->rgmii_ph; | ||
2326 | if (dev->tah_ph) | ||
2327 | deps[EMAC_DEP_TAH_IDX].phandle = dev->tah_ph; | ||
2328 | if (dev->mdio_ph) | ||
2329 | deps[EMAC_DEP_MDIO_IDX].phandle = dev->mdio_ph; | ||
2330 | if (dev->blist && dev->blist > emac_boot_list) | ||
2331 | deps[EMAC_DEP_PREV_IDX].phandle = 0xffffffffu; | ||
2332 | bus_register_notifier(&platform_bus_type, &emac_of_bus_notifier); | ||
2333 | wait_event_timeout(emac_probe_wait, | ||
2334 | emac_check_deps(dev, deps), | ||
2335 | EMAC_PROBE_DEP_TIMEOUT); | ||
2336 | bus_unregister_notifier(&platform_bus_type, &emac_of_bus_notifier); | ||
2337 | err = emac_check_deps(dev, deps) ? 0 : -ENODEV; | ||
2338 | for (i = 0; i < EMAC_DEP_COUNT; i++) { | ||
2339 | if (deps[i].node) | ||
2340 | of_node_put(deps[i].node); | ||
2341 | if (err && deps[i].ofdev) | ||
2342 | of_dev_put(deps[i].ofdev); | ||
2343 | } | ||
2344 | if (err == 0) { | ||
2345 | dev->mal_dev = deps[EMAC_DEP_MAL_IDX].ofdev; | ||
2346 | dev->zmii_dev = deps[EMAC_DEP_ZMII_IDX].ofdev; | ||
2347 | dev->rgmii_dev = deps[EMAC_DEP_RGMII_IDX].ofdev; | ||
2348 | dev->tah_dev = deps[EMAC_DEP_TAH_IDX].ofdev; | ||
2349 | dev->mdio_dev = deps[EMAC_DEP_MDIO_IDX].ofdev; | ||
2350 | } | ||
2351 | if (deps[EMAC_DEP_PREV_IDX].ofdev) | ||
2352 | of_dev_put(deps[EMAC_DEP_PREV_IDX].ofdev); | ||
2353 | return err; | ||
2354 | } | ||
2355 | |||
2356 | static int __devinit emac_read_uint_prop(struct device_node *np, const char *name, | ||
2357 | u32 *val, int fatal) | ||
2358 | { | ||
2359 | int len; | ||
2360 | const u32 *prop = of_get_property(np, name, &len); | ||
2361 | if (prop == NULL || len < sizeof(u32)) { | ||
2362 | if (fatal) | ||
2363 | printk(KERN_ERR "%s: missing %s property\n", | ||
2364 | np->full_name, name); | ||
2365 | return -ENODEV; | ||
2366 | } | ||
2367 | *val = *prop; | ||
2368 | return 0; | ||
2369 | } | ||
2370 | |||
2371 | static int __devinit emac_init_phy(struct emac_instance *dev) | ||
2372 | { | ||
2373 | struct device_node *np = dev->ofdev->dev.of_node; | ||
2374 | struct net_device *ndev = dev->ndev; | ||
2375 | u32 phy_map, adv; | ||
2376 | int i; | ||
2377 | |||
2378 | dev->phy.dev = ndev; | ||
2379 | dev->phy.mode = dev->phy_mode; | ||
2380 | |||
2381 | /* PHY-less configuration. | ||
2382 | * XXX I probably should move these settings to the dev tree | ||
2383 | */ | ||
2384 | if (dev->phy_address == 0xffffffff && dev->phy_map == 0xffffffff) { | ||
2385 | emac_reset(dev); | ||
2386 | |||
2387 | /* PHY-less configuration. | ||
2388 | * XXX I probably should move these settings to the dev tree | ||
2389 | */ | ||
2390 | dev->phy.address = -1; | ||
2391 | dev->phy.features = SUPPORTED_MII; | ||
2392 | if (emac_phy_supports_gige(dev->phy_mode)) | ||
2393 | dev->phy.features |= SUPPORTED_1000baseT_Full; | ||
2394 | else | ||
2395 | dev->phy.features |= SUPPORTED_100baseT_Full; | ||
2396 | dev->phy.pause = 1; | ||
2397 | |||
2398 | return 0; | ||
2399 | } | ||
2400 | |||
2401 | mutex_lock(&emac_phy_map_lock); | ||
2402 | phy_map = dev->phy_map | busy_phy_map; | ||
2403 | |||
2404 | DBG(dev, "PHY maps %08x %08x" NL, dev->phy_map, busy_phy_map); | ||
2405 | |||
2406 | dev->phy.mdio_read = emac_mdio_read; | ||
2407 | dev->phy.mdio_write = emac_mdio_write; | ||
2408 | |||
2409 | /* Enable internal clock source */ | ||
2410 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
2411 | if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) | ||
2412 | dcri_clrset(SDR0, SDR0_MFR, 0, SDR0_MFR_ECS); | ||
2413 | #endif | ||
2414 | /* PHY clock workaround */ | ||
2415 | emac_rx_clk_tx(dev); | ||
2416 | |||
2417 | /* Enable internal clock source on 440GX*/ | ||
2418 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
2419 | if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) | ||
2420 | dcri_clrset(SDR0, SDR0_MFR, 0, SDR0_MFR_ECS); | ||
2421 | #endif | ||
2422 | /* Configure EMAC with defaults so we can at least use MDIO | ||
2423 | * This is needed mostly for 440GX | ||
2424 | */ | ||
2425 | if (emac_phy_gpcs(dev->phy.mode)) { | ||
2426 | /* XXX | ||
2427 | * Make GPCS PHY address equal to EMAC index. | ||
2428 | * We probably should take into account busy_phy_map | ||
2429 | * and/or phy_map here. | ||
2430 | * | ||
2431 | * Note that the busy_phy_map is currently global | ||
2432 | * while it should probably be per-ASIC... | ||
2433 | */ | ||
2434 | dev->phy.gpcs_address = dev->gpcs_address; | ||
2435 | if (dev->phy.gpcs_address == 0xffffffff) | ||
2436 | dev->phy.address = dev->cell_index; | ||
2437 | } | ||
2438 | |||
2439 | emac_configure(dev); | ||
2440 | |||
2441 | if (dev->phy_address != 0xffffffff) | ||
2442 | phy_map = ~(1 << dev->phy_address); | ||
2443 | |||
2444 | for (i = 0; i < 0x20; phy_map >>= 1, ++i) | ||
2445 | if (!(phy_map & 1)) { | ||
2446 | int r; | ||
2447 | busy_phy_map |= 1 << i; | ||
2448 | |||
2449 | /* Quick check if there is a PHY at the address */ | ||
2450 | r = emac_mdio_read(dev->ndev, i, MII_BMCR); | ||
2451 | if (r == 0xffff || r < 0) | ||
2452 | continue; | ||
2453 | if (!emac_mii_phy_probe(&dev->phy, i)) | ||
2454 | break; | ||
2455 | } | ||
2456 | |||
2457 | /* Enable external clock source */ | ||
2458 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
2459 | if (emac_has_feature(dev, EMAC_FTR_440GX_PHY_CLK_FIX)) | ||
2460 | dcri_clrset(SDR0, SDR0_MFR, SDR0_MFR_ECS, 0); | ||
2461 | #endif | ||
2462 | mutex_unlock(&emac_phy_map_lock); | ||
2463 | if (i == 0x20) { | ||
2464 | printk(KERN_WARNING "%s: can't find PHY!\n", np->full_name); | ||
2465 | return -ENXIO; | ||
2466 | } | ||
2467 | |||
2468 | /* Init PHY */ | ||
2469 | if (dev->phy.def->ops->init) | ||
2470 | dev->phy.def->ops->init(&dev->phy); | ||
2471 | |||
2472 | /* Disable any PHY features not supported by the platform */ | ||
2473 | dev->phy.def->features &= ~dev->phy_feat_exc; | ||
2474 | |||
2475 | /* Setup initial link parameters */ | ||
2476 | if (dev->phy.features & SUPPORTED_Autoneg) { | ||
2477 | adv = dev->phy.features; | ||
2478 | if (!emac_has_feature(dev, EMAC_FTR_NO_FLOW_CONTROL_40x)) | ||
2479 | adv |= ADVERTISED_Pause | ADVERTISED_Asym_Pause; | ||
2480 | /* Restart autonegotiation */ | ||
2481 | dev->phy.def->ops->setup_aneg(&dev->phy, adv); | ||
2482 | } else { | ||
2483 | u32 f = dev->phy.def->features; | ||
2484 | int speed = SPEED_10, fd = DUPLEX_HALF; | ||
2485 | |||
2486 | /* Select highest supported speed/duplex */ | ||
2487 | if (f & SUPPORTED_1000baseT_Full) { | ||
2488 | speed = SPEED_1000; | ||
2489 | fd = DUPLEX_FULL; | ||
2490 | } else if (f & SUPPORTED_1000baseT_Half) | ||
2491 | speed = SPEED_1000; | ||
2492 | else if (f & SUPPORTED_100baseT_Full) { | ||
2493 | speed = SPEED_100; | ||
2494 | fd = DUPLEX_FULL; | ||
2495 | } else if (f & SUPPORTED_100baseT_Half) | ||
2496 | speed = SPEED_100; | ||
2497 | else if (f & SUPPORTED_10baseT_Full) | ||
2498 | fd = DUPLEX_FULL; | ||
2499 | |||
2500 | /* Force link parameters */ | ||
2501 | dev->phy.def->ops->setup_forced(&dev->phy, speed, fd); | ||
2502 | } | ||
2503 | return 0; | ||
2504 | } | ||
2505 | |||
2506 | static int __devinit emac_init_config(struct emac_instance *dev) | ||
2507 | { | ||
2508 | struct device_node *np = dev->ofdev->dev.of_node; | ||
2509 | const void *p; | ||
2510 | |||
2511 | /* Read config from device-tree */ | ||
2512 | if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1)) | ||
2513 | return -ENXIO; | ||
2514 | if (emac_read_uint_prop(np, "mal-tx-channel", &dev->mal_tx_chan, 1)) | ||
2515 | return -ENXIO; | ||
2516 | if (emac_read_uint_prop(np, "mal-rx-channel", &dev->mal_rx_chan, 1)) | ||
2517 | return -ENXIO; | ||
2518 | if (emac_read_uint_prop(np, "cell-index", &dev->cell_index, 1)) | ||
2519 | return -ENXIO; | ||
2520 | if (emac_read_uint_prop(np, "max-frame-size", &dev->max_mtu, 0)) | ||
2521 | dev->max_mtu = 1500; | ||
2522 | if (emac_read_uint_prop(np, "rx-fifo-size", &dev->rx_fifo_size, 0)) | ||
2523 | dev->rx_fifo_size = 2048; | ||
2524 | if (emac_read_uint_prop(np, "tx-fifo-size", &dev->tx_fifo_size, 0)) | ||
2525 | dev->tx_fifo_size = 2048; | ||
2526 | if (emac_read_uint_prop(np, "rx-fifo-size-gige", &dev->rx_fifo_size_gige, 0)) | ||
2527 | dev->rx_fifo_size_gige = dev->rx_fifo_size; | ||
2528 | if (emac_read_uint_prop(np, "tx-fifo-size-gige", &dev->tx_fifo_size_gige, 0)) | ||
2529 | dev->tx_fifo_size_gige = dev->tx_fifo_size; | ||
2530 | if (emac_read_uint_prop(np, "phy-address", &dev->phy_address, 0)) | ||
2531 | dev->phy_address = 0xffffffff; | ||
2532 | if (emac_read_uint_prop(np, "phy-map", &dev->phy_map, 0)) | ||
2533 | dev->phy_map = 0xffffffff; | ||
2534 | if (emac_read_uint_prop(np, "gpcs-address", &dev->gpcs_address, 0)) | ||
2535 | dev->gpcs_address = 0xffffffff; | ||
2536 | if (emac_read_uint_prop(np->parent, "clock-frequency", &dev->opb_bus_freq, 1)) | ||
2537 | return -ENXIO; | ||
2538 | if (emac_read_uint_prop(np, "tah-device", &dev->tah_ph, 0)) | ||
2539 | dev->tah_ph = 0; | ||
2540 | if (emac_read_uint_prop(np, "tah-channel", &dev->tah_port, 0)) | ||
2541 | dev->tah_port = 0; | ||
2542 | if (emac_read_uint_prop(np, "mdio-device", &dev->mdio_ph, 0)) | ||
2543 | dev->mdio_ph = 0; | ||
2544 | if (emac_read_uint_prop(np, "zmii-device", &dev->zmii_ph, 0)) | ||
2545 | dev->zmii_ph = 0; | ||
2546 | if (emac_read_uint_prop(np, "zmii-channel", &dev->zmii_port, 0)) | ||
2547 | dev->zmii_port = 0xffffffff; | ||
2548 | if (emac_read_uint_prop(np, "rgmii-device", &dev->rgmii_ph, 0)) | ||
2549 | dev->rgmii_ph = 0; | ||
2550 | if (emac_read_uint_prop(np, "rgmii-channel", &dev->rgmii_port, 0)) | ||
2551 | dev->rgmii_port = 0xffffffff; | ||
2552 | if (emac_read_uint_prop(np, "fifo-entry-size", &dev->fifo_entry_size, 0)) | ||
2553 | dev->fifo_entry_size = 16; | ||
2554 | if (emac_read_uint_prop(np, "mal-burst-size", &dev->mal_burst_size, 0)) | ||
2555 | dev->mal_burst_size = 256; | ||
2556 | |||
2557 | /* PHY mode needs some decoding */ | ||
2558 | dev->phy_mode = of_get_phy_mode(np); | ||
2559 | if (dev->phy_mode < 0) | ||
2560 | dev->phy_mode = PHY_MODE_NA; | ||
2561 | |||
2562 | /* Check EMAC version */ | ||
2563 | if (of_device_is_compatible(np, "ibm,emac4sync")) { | ||
2564 | dev->features |= (EMAC_FTR_EMAC4 | EMAC_FTR_EMAC4SYNC); | ||
2565 | if (of_device_is_compatible(np, "ibm,emac-460ex") || | ||
2566 | of_device_is_compatible(np, "ibm,emac-460gt")) | ||
2567 | dev->features |= EMAC_FTR_460EX_PHY_CLK_FIX; | ||
2568 | if (of_device_is_compatible(np, "ibm,emac-405ex") || | ||
2569 | of_device_is_compatible(np, "ibm,emac-405exr")) | ||
2570 | dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX; | ||
2571 | } else if (of_device_is_compatible(np, "ibm,emac4")) { | ||
2572 | dev->features |= EMAC_FTR_EMAC4; | ||
2573 | if (of_device_is_compatible(np, "ibm,emac-440gx")) | ||
2574 | dev->features |= EMAC_FTR_440GX_PHY_CLK_FIX; | ||
2575 | } else { | ||
2576 | if (of_device_is_compatible(np, "ibm,emac-440ep") || | ||
2577 | of_device_is_compatible(np, "ibm,emac-440gr")) | ||
2578 | dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX; | ||
2579 | if (of_device_is_compatible(np, "ibm,emac-405ez")) { | ||
2580 | #ifdef CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL | ||
2581 | dev->features |= EMAC_FTR_NO_FLOW_CONTROL_40x; | ||
2582 | #else | ||
2583 | printk(KERN_ERR "%s: Flow control not disabled!\n", | ||
2584 | np->full_name); | ||
2585 | return -ENXIO; | ||
2586 | #endif | ||
2587 | } | ||
2588 | |||
2589 | } | ||
2590 | |||
2591 | /* Fixup some feature bits based on the device tree */ | ||
2592 | if (of_get_property(np, "has-inverted-stacr-oc", NULL)) | ||
2593 | dev->features |= EMAC_FTR_STACR_OC_INVERT; | ||
2594 | if (of_get_property(np, "has-new-stacr-staopc", NULL)) | ||
2595 | dev->features |= EMAC_FTR_HAS_NEW_STACR; | ||
2596 | |||
2597 | /* CAB lacks the appropriate properties */ | ||
2598 | if (of_device_is_compatible(np, "ibm,emac-axon")) | ||
2599 | dev->features |= EMAC_FTR_HAS_NEW_STACR | | ||
2600 | EMAC_FTR_STACR_OC_INVERT; | ||
2601 | |||
2602 | /* Enable TAH/ZMII/RGMII features as found */ | ||
2603 | if (dev->tah_ph != 0) { | ||
2604 | #ifdef CONFIG_IBM_NEW_EMAC_TAH | ||
2605 | dev->features |= EMAC_FTR_HAS_TAH; | ||
2606 | #else | ||
2607 | printk(KERN_ERR "%s: TAH support not enabled !\n", | ||
2608 | np->full_name); | ||
2609 | return -ENXIO; | ||
2610 | #endif | ||
2611 | } | ||
2612 | |||
2613 | if (dev->zmii_ph != 0) { | ||
2614 | #ifdef CONFIG_IBM_NEW_EMAC_ZMII | ||
2615 | dev->features |= EMAC_FTR_HAS_ZMII; | ||
2616 | #else | ||
2617 | printk(KERN_ERR "%s: ZMII support not enabled !\n", | ||
2618 | np->full_name); | ||
2619 | return -ENXIO; | ||
2620 | #endif | ||
2621 | } | ||
2622 | |||
2623 | if (dev->rgmii_ph != 0) { | ||
2624 | #ifdef CONFIG_IBM_NEW_EMAC_RGMII | ||
2625 | dev->features |= EMAC_FTR_HAS_RGMII; | ||
2626 | #else | ||
2627 | printk(KERN_ERR "%s: RGMII support not enabled !\n", | ||
2628 | np->full_name); | ||
2629 | return -ENXIO; | ||
2630 | #endif | ||
2631 | } | ||
2632 | |||
2633 | /* Read MAC-address */ | ||
2634 | p = of_get_property(np, "local-mac-address", NULL); | ||
2635 | if (p == NULL) { | ||
2636 | printk(KERN_ERR "%s: Can't find local-mac-address property\n", | ||
2637 | np->full_name); | ||
2638 | return -ENXIO; | ||
2639 | } | ||
2640 | memcpy(dev->ndev->dev_addr, p, 6); | ||
2641 | |||
2642 | /* IAHT and GAHT filter parameterization */ | ||
2643 | if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC)) { | ||
2644 | dev->xaht_slots_shift = EMAC4SYNC_XAHT_SLOTS_SHIFT; | ||
2645 | dev->xaht_width_shift = EMAC4SYNC_XAHT_WIDTH_SHIFT; | ||
2646 | } else { | ||
2647 | dev->xaht_slots_shift = EMAC4_XAHT_SLOTS_SHIFT; | ||
2648 | dev->xaht_width_shift = EMAC4_XAHT_WIDTH_SHIFT; | ||
2649 | } | ||
2650 | |||
2651 | DBG(dev, "features : 0x%08x / 0x%08x\n", dev->features, EMAC_FTRS_POSSIBLE); | ||
2652 | DBG(dev, "tx_fifo_size : %d (%d gige)\n", dev->tx_fifo_size, dev->tx_fifo_size_gige); | ||
2653 | DBG(dev, "rx_fifo_size : %d (%d gige)\n", dev->rx_fifo_size, dev->rx_fifo_size_gige); | ||
2654 | DBG(dev, "max_mtu : %d\n", dev->max_mtu); | ||
2655 | DBG(dev, "OPB freq : %d\n", dev->opb_bus_freq); | ||
2656 | |||
2657 | return 0; | ||
2658 | } | ||
2659 | |||
2660 | static const struct net_device_ops emac_netdev_ops = { | ||
2661 | .ndo_open = emac_open, | ||
2662 | .ndo_stop = emac_close, | ||
2663 | .ndo_get_stats = emac_stats, | ||
2664 | .ndo_set_multicast_list = emac_set_multicast_list, | ||
2665 | .ndo_do_ioctl = emac_ioctl, | ||
2666 | .ndo_tx_timeout = emac_tx_timeout, | ||
2667 | .ndo_validate_addr = eth_validate_addr, | ||
2668 | .ndo_set_mac_address = eth_mac_addr, | ||
2669 | .ndo_start_xmit = emac_start_xmit, | ||
2670 | .ndo_change_mtu = eth_change_mtu, | ||
2671 | }; | ||
2672 | |||
2673 | static const struct net_device_ops emac_gige_netdev_ops = { | ||
2674 | .ndo_open = emac_open, | ||
2675 | .ndo_stop = emac_close, | ||
2676 | .ndo_get_stats = emac_stats, | ||
2677 | .ndo_set_multicast_list = emac_set_multicast_list, | ||
2678 | .ndo_do_ioctl = emac_ioctl, | ||
2679 | .ndo_tx_timeout = emac_tx_timeout, | ||
2680 | .ndo_validate_addr = eth_validate_addr, | ||
2681 | .ndo_set_mac_address = eth_mac_addr, | ||
2682 | .ndo_start_xmit = emac_start_xmit_sg, | ||
2683 | .ndo_change_mtu = emac_change_mtu, | ||
2684 | }; | ||
2685 | |||
2686 | static int __devinit emac_probe(struct platform_device *ofdev) | ||
2687 | { | ||
2688 | struct net_device *ndev; | ||
2689 | struct emac_instance *dev; | ||
2690 | struct device_node *np = ofdev->dev.of_node; | ||
2691 | struct device_node **blist = NULL; | ||
2692 | int err, i; | ||
2693 | |||
2694 | /* Skip unused/unwired EMACS. We leave the check for an unused | ||
2695 | * property here for now, but new flat device trees should set a | ||
2696 | * status property to "disabled" instead. | ||
2697 | */ | ||
2698 | if (of_get_property(np, "unused", NULL) || !of_device_is_available(np)) | ||
2699 | return -ENODEV; | ||
2700 | |||
2701 | /* Find ourselves in the bootlist if we are there */ | ||
2702 | for (i = 0; i < EMAC_BOOT_LIST_SIZE; i++) | ||
2703 | if (emac_boot_list[i] == np) | ||
2704 | blist = &emac_boot_list[i]; | ||
2705 | |||
2706 | /* Allocate our net_device structure */ | ||
2707 | err = -ENOMEM; | ||
2708 | ndev = alloc_etherdev(sizeof(struct emac_instance)); | ||
2709 | if (!ndev) { | ||
2710 | printk(KERN_ERR "%s: could not allocate ethernet device!\n", | ||
2711 | np->full_name); | ||
2712 | goto err_gone; | ||
2713 | } | ||
2714 | dev = netdev_priv(ndev); | ||
2715 | dev->ndev = ndev; | ||
2716 | dev->ofdev = ofdev; | ||
2717 | dev->blist = blist; | ||
2718 | SET_NETDEV_DEV(ndev, &ofdev->dev); | ||
2719 | |||
2720 | /* Initialize some embedded data structures */ | ||
2721 | mutex_init(&dev->mdio_lock); | ||
2722 | mutex_init(&dev->link_lock); | ||
2723 | spin_lock_init(&dev->lock); | ||
2724 | INIT_WORK(&dev->reset_work, emac_reset_work); | ||
2725 | |||
2726 | /* Init various config data based on device-tree */ | ||
2727 | err = emac_init_config(dev); | ||
2728 | if (err != 0) | ||
2729 | goto err_free; | ||
2730 | |||
2731 | /* Get interrupts. EMAC irq is mandatory, WOL irq is optional */ | ||
2732 | dev->emac_irq = irq_of_parse_and_map(np, 0); | ||
2733 | dev->wol_irq = irq_of_parse_and_map(np, 1); | ||
2734 | if (dev->emac_irq == NO_IRQ) { | ||
2735 | printk(KERN_ERR "%s: Can't map main interrupt\n", np->full_name); | ||
2736 | goto err_free; | ||
2737 | } | ||
2738 | ndev->irq = dev->emac_irq; | ||
2739 | |||
2740 | /* Map EMAC regs */ | ||
2741 | if (of_address_to_resource(np, 0, &dev->rsrc_regs)) { | ||
2742 | printk(KERN_ERR "%s: Can't get registers address\n", | ||
2743 | np->full_name); | ||
2744 | goto err_irq_unmap; | ||
2745 | } | ||
2746 | // TODO : request_mem_region | ||
2747 | dev->emacp = ioremap(dev->rsrc_regs.start, | ||
2748 | resource_size(&dev->rsrc_regs)); | ||
2749 | if (dev->emacp == NULL) { | ||
2750 | printk(KERN_ERR "%s: Can't map device registers!\n", | ||
2751 | np->full_name); | ||
2752 | err = -ENOMEM; | ||
2753 | goto err_irq_unmap; | ||
2754 | } | ||
2755 | |||
2756 | /* Wait for dependent devices */ | ||
2757 | err = emac_wait_deps(dev); | ||
2758 | if (err) { | ||
2759 | printk(KERN_ERR | ||
2760 | "%s: Timeout waiting for dependent devices\n", | ||
2761 | np->full_name); | ||
2762 | /* display more info about what's missing ? */ | ||
2763 | goto err_reg_unmap; | ||
2764 | } | ||
2765 | dev->mal = dev_get_drvdata(&dev->mal_dev->dev); | ||
2766 | if (dev->mdio_dev != NULL) | ||
2767 | dev->mdio_instance = dev_get_drvdata(&dev->mdio_dev->dev); | ||
2768 | |||
2769 | /* Register with MAL */ | ||
2770 | dev->commac.ops = &emac_commac_ops; | ||
2771 | dev->commac.dev = dev; | ||
2772 | dev->commac.tx_chan_mask = MAL_CHAN_MASK(dev->mal_tx_chan); | ||
2773 | dev->commac.rx_chan_mask = MAL_CHAN_MASK(dev->mal_rx_chan); | ||
2774 | err = mal_register_commac(dev->mal, &dev->commac); | ||
2775 | if (err) { | ||
2776 | printk(KERN_ERR "%s: failed to register with mal %s!\n", | ||
2777 | np->full_name, dev->mal_dev->dev.of_node->full_name); | ||
2778 | goto err_rel_deps; | ||
2779 | } | ||
2780 | dev->rx_skb_size = emac_rx_skb_size(ndev->mtu); | ||
2781 | dev->rx_sync_size = emac_rx_sync_size(ndev->mtu); | ||
2782 | |||
2783 | /* Get pointers to BD rings */ | ||
2784 | dev->tx_desc = | ||
2785 | dev->mal->bd_virt + mal_tx_bd_offset(dev->mal, dev->mal_tx_chan); | ||
2786 | dev->rx_desc = | ||
2787 | dev->mal->bd_virt + mal_rx_bd_offset(dev->mal, dev->mal_rx_chan); | ||
2788 | |||
2789 | DBG(dev, "tx_desc %p" NL, dev->tx_desc); | ||
2790 | DBG(dev, "rx_desc %p" NL, dev->rx_desc); | ||
2791 | |||
2792 | /* Clean rings */ | ||
2793 | memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct mal_descriptor)); | ||
2794 | memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct mal_descriptor)); | ||
2795 | memset(dev->tx_skb, 0, NUM_TX_BUFF * sizeof(struct sk_buff *)); | ||
2796 | memset(dev->rx_skb, 0, NUM_RX_BUFF * sizeof(struct sk_buff *)); | ||
2797 | |||
2798 | /* Attach to ZMII, if needed */ | ||
2799 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII) && | ||
2800 | (err = zmii_attach(dev->zmii_dev, dev->zmii_port, &dev->phy_mode)) != 0) | ||
2801 | goto err_unreg_commac; | ||
2802 | |||
2803 | /* Attach to RGMII, if needed */ | ||
2804 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII) && | ||
2805 | (err = rgmii_attach(dev->rgmii_dev, dev->rgmii_port, dev->phy_mode)) != 0) | ||
2806 | goto err_detach_zmii; | ||
2807 | |||
2808 | /* Attach to TAH, if needed */ | ||
2809 | if (emac_has_feature(dev, EMAC_FTR_HAS_TAH) && | ||
2810 | (err = tah_attach(dev->tah_dev, dev->tah_port)) != 0) | ||
2811 | goto err_detach_rgmii; | ||
2812 | |||
2813 | /* Set some link defaults before we can find out real parameters */ | ||
2814 | dev->phy.speed = SPEED_100; | ||
2815 | dev->phy.duplex = DUPLEX_FULL; | ||
2816 | dev->phy.autoneg = AUTONEG_DISABLE; | ||
2817 | dev->phy.pause = dev->phy.asym_pause = 0; | ||
2818 | dev->stop_timeout = STOP_TIMEOUT_100; | ||
2819 | INIT_DELAYED_WORK(&dev->link_work, emac_link_timer); | ||
2820 | |||
2821 | /* Find PHY if any */ | ||
2822 | err = emac_init_phy(dev); | ||
2823 | if (err != 0) | ||
2824 | goto err_detach_tah; | ||
2825 | |||
2826 | if (dev->tah_dev) { | ||
2827 | ndev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG; | ||
2828 | ndev->features |= ndev->hw_features | NETIF_F_RXCSUM; | ||
2829 | } | ||
2830 | ndev->watchdog_timeo = 5 * HZ; | ||
2831 | if (emac_phy_supports_gige(dev->phy_mode)) { | ||
2832 | ndev->netdev_ops = &emac_gige_netdev_ops; | ||
2833 | dev->commac.ops = &emac_commac_sg_ops; | ||
2834 | } else | ||
2835 | ndev->netdev_ops = &emac_netdev_ops; | ||
2836 | SET_ETHTOOL_OPS(ndev, &emac_ethtool_ops); | ||
2837 | |||
2838 | netif_carrier_off(ndev); | ||
2839 | |||
2840 | err = register_netdev(ndev); | ||
2841 | if (err) { | ||
2842 | printk(KERN_ERR "%s: failed to register net device (%d)!\n", | ||
2843 | np->full_name, err); | ||
2844 | goto err_detach_tah; | ||
2845 | } | ||
2846 | |||
2847 | /* Set our drvdata last as we don't want them visible until we are | ||
2848 | * fully initialized | ||
2849 | */ | ||
2850 | wmb(); | ||
2851 | dev_set_drvdata(&ofdev->dev, dev); | ||
2852 | |||
2853 | /* There's a new kid in town ! Let's tell everybody */ | ||
2854 | wake_up_all(&emac_probe_wait); | ||
2855 | |||
2856 | |||
2857 | printk(KERN_INFO "%s: EMAC-%d %s, MAC %pM\n", | ||
2858 | ndev->name, dev->cell_index, np->full_name, ndev->dev_addr); | ||
2859 | |||
2860 | if (dev->phy_mode == PHY_MODE_SGMII) | ||
2861 | printk(KERN_NOTICE "%s: in SGMII mode\n", ndev->name); | ||
2862 | |||
2863 | if (dev->phy.address >= 0) | ||
2864 | printk("%s: found %s PHY (0x%02x)\n", ndev->name, | ||
2865 | dev->phy.def->name, dev->phy.address); | ||
2866 | |||
2867 | emac_dbg_register(dev); | ||
2868 | |||
2869 | /* Life is good */ | ||
2870 | return 0; | ||
2871 | |||
2872 | /* I have a bad feeling about this ... */ | ||
2873 | |||
2874 | err_detach_tah: | ||
2875 | if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) | ||
2876 | tah_detach(dev->tah_dev, dev->tah_port); | ||
2877 | err_detach_rgmii: | ||
2878 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) | ||
2879 | rgmii_detach(dev->rgmii_dev, dev->rgmii_port); | ||
2880 | err_detach_zmii: | ||
2881 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) | ||
2882 | zmii_detach(dev->zmii_dev, dev->zmii_port); | ||
2883 | err_unreg_commac: | ||
2884 | mal_unregister_commac(dev->mal, &dev->commac); | ||
2885 | err_rel_deps: | ||
2886 | emac_put_deps(dev); | ||
2887 | err_reg_unmap: | ||
2888 | iounmap(dev->emacp); | ||
2889 | err_irq_unmap: | ||
2890 | if (dev->wol_irq != NO_IRQ) | ||
2891 | irq_dispose_mapping(dev->wol_irq); | ||
2892 | if (dev->emac_irq != NO_IRQ) | ||
2893 | irq_dispose_mapping(dev->emac_irq); | ||
2894 | err_free: | ||
2895 | free_netdev(ndev); | ||
2896 | err_gone: | ||
2897 | /* if we were on the bootlist, remove us as we won't show up and | ||
2898 | * wake up all waiters to notify them in case they were waiting | ||
2899 | * on us | ||
2900 | */ | ||
2901 | if (blist) { | ||
2902 | *blist = NULL; | ||
2903 | wake_up_all(&emac_probe_wait); | ||
2904 | } | ||
2905 | return err; | ||
2906 | } | ||
2907 | |||
2908 | static int __devexit emac_remove(struct platform_device *ofdev) | ||
2909 | { | ||
2910 | struct emac_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
2911 | |||
2912 | DBG(dev, "remove" NL); | ||
2913 | |||
2914 | dev_set_drvdata(&ofdev->dev, NULL); | ||
2915 | |||
2916 | unregister_netdev(dev->ndev); | ||
2917 | |||
2918 | cancel_work_sync(&dev->reset_work); | ||
2919 | |||
2920 | if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) | ||
2921 | tah_detach(dev->tah_dev, dev->tah_port); | ||
2922 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) | ||
2923 | rgmii_detach(dev->rgmii_dev, dev->rgmii_port); | ||
2924 | if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII)) | ||
2925 | zmii_detach(dev->zmii_dev, dev->zmii_port); | ||
2926 | |||
2927 | mal_unregister_commac(dev->mal, &dev->commac); | ||
2928 | emac_put_deps(dev); | ||
2929 | |||
2930 | emac_dbg_unregister(dev); | ||
2931 | iounmap(dev->emacp); | ||
2932 | |||
2933 | if (dev->wol_irq != NO_IRQ) | ||
2934 | irq_dispose_mapping(dev->wol_irq); | ||
2935 | if (dev->emac_irq != NO_IRQ) | ||
2936 | irq_dispose_mapping(dev->emac_irq); | ||
2937 | |||
2938 | free_netdev(dev->ndev); | ||
2939 | |||
2940 | return 0; | ||
2941 | } | ||
2942 | |||
2943 | /* XXX Features in here should be replaced by properties... */ | ||
2944 | static struct of_device_id emac_match[] = | ||
2945 | { | ||
2946 | { | ||
2947 | .type = "network", | ||
2948 | .compatible = "ibm,emac", | ||
2949 | }, | ||
2950 | { | ||
2951 | .type = "network", | ||
2952 | .compatible = "ibm,emac4", | ||
2953 | }, | ||
2954 | { | ||
2955 | .type = "network", | ||
2956 | .compatible = "ibm,emac4sync", | ||
2957 | }, | ||
2958 | {}, | ||
2959 | }; | ||
2960 | MODULE_DEVICE_TABLE(of, emac_match); | ||
2961 | |||
2962 | static struct platform_driver emac_driver = { | ||
2963 | .driver = { | ||
2964 | .name = "emac", | ||
2965 | .owner = THIS_MODULE, | ||
2966 | .of_match_table = emac_match, | ||
2967 | }, | ||
2968 | .probe = emac_probe, | ||
2969 | .remove = emac_remove, | ||
2970 | }; | ||
2971 | |||
2972 | static void __init emac_make_bootlist(void) | ||
2973 | { | ||
2974 | struct device_node *np = NULL; | ||
2975 | int j, max, i = 0, k; | ||
2976 | int cell_indices[EMAC_BOOT_LIST_SIZE]; | ||
2977 | |||
2978 | /* Collect EMACs */ | ||
2979 | while((np = of_find_all_nodes(np)) != NULL) { | ||
2980 | const u32 *idx; | ||
2981 | |||
2982 | if (of_match_node(emac_match, np) == NULL) | ||
2983 | continue; | ||
2984 | if (of_get_property(np, "unused", NULL)) | ||
2985 | continue; | ||
2986 | idx = of_get_property(np, "cell-index", NULL); | ||
2987 | if (idx == NULL) | ||
2988 | continue; | ||
2989 | cell_indices[i] = *idx; | ||
2990 | emac_boot_list[i++] = of_node_get(np); | ||
2991 | if (i >= EMAC_BOOT_LIST_SIZE) { | ||
2992 | of_node_put(np); | ||
2993 | break; | ||
2994 | } | ||
2995 | } | ||
2996 | max = i; | ||
2997 | |||
2998 | /* Bubble sort them (doh, what a creative algorithm :-) */ | ||
2999 | for (i = 0; max > 1 && (i < (max - 1)); i++) | ||
3000 | for (j = i; j < max; j++) { | ||
3001 | if (cell_indices[i] > cell_indices[j]) { | ||
3002 | np = emac_boot_list[i]; | ||
3003 | emac_boot_list[i] = emac_boot_list[j]; | ||
3004 | emac_boot_list[j] = np; | ||
3005 | k = cell_indices[i]; | ||
3006 | cell_indices[i] = cell_indices[j]; | ||
3007 | cell_indices[j] = k; | ||
3008 | } | ||
3009 | } | ||
3010 | } | ||
3011 | |||
3012 | static int __init emac_init(void) | ||
3013 | { | ||
3014 | int rc; | ||
3015 | |||
3016 | printk(KERN_INFO DRV_DESC ", version " DRV_VERSION "\n"); | ||
3017 | |||
3018 | /* Init debug stuff */ | ||
3019 | emac_init_debug(); | ||
3020 | |||
3021 | /* Build EMAC boot list */ | ||
3022 | emac_make_bootlist(); | ||
3023 | |||
3024 | /* Init submodules */ | ||
3025 | rc = mal_init(); | ||
3026 | if (rc) | ||
3027 | goto err; | ||
3028 | rc = zmii_init(); | ||
3029 | if (rc) | ||
3030 | goto err_mal; | ||
3031 | rc = rgmii_init(); | ||
3032 | if (rc) | ||
3033 | goto err_zmii; | ||
3034 | rc = tah_init(); | ||
3035 | if (rc) | ||
3036 | goto err_rgmii; | ||
3037 | rc = platform_driver_register(&emac_driver); | ||
3038 | if (rc) | ||
3039 | goto err_tah; | ||
3040 | |||
3041 | return 0; | ||
3042 | |||
3043 | err_tah: | ||
3044 | tah_exit(); | ||
3045 | err_rgmii: | ||
3046 | rgmii_exit(); | ||
3047 | err_zmii: | ||
3048 | zmii_exit(); | ||
3049 | err_mal: | ||
3050 | mal_exit(); | ||
3051 | err: | ||
3052 | return rc; | ||
3053 | } | ||
3054 | |||
3055 | static void __exit emac_exit(void) | ||
3056 | { | ||
3057 | int i; | ||
3058 | |||
3059 | platform_driver_unregister(&emac_driver); | ||
3060 | |||
3061 | tah_exit(); | ||
3062 | rgmii_exit(); | ||
3063 | zmii_exit(); | ||
3064 | mal_exit(); | ||
3065 | emac_fini_debug(); | ||
3066 | |||
3067 | /* Destroy EMAC boot list */ | ||
3068 | for (i = 0; i < EMAC_BOOT_LIST_SIZE; i++) | ||
3069 | if (emac_boot_list[i]) | ||
3070 | of_node_put(emac_boot_list[i]); | ||
3071 | } | ||
3072 | |||
3073 | module_init(emac_init); | ||
3074 | module_exit(emac_exit); | ||
diff --git a/drivers/net/ethernet/ibm/emac/core.h b/drivers/net/ethernet/ibm/emac/core.h new file mode 100644 index 000000000000..4fec0844d59d --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/core.h | |||
@@ -0,0 +1,462 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/core.h | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * Based on original work by | ||
15 | * Armin Kuster <akuster@mvista.com> | ||
16 | * Johnnie Peters <jpeters@mvista.com> | ||
17 | * Copyright 2000, 2001 MontaVista Softare Inc. | ||
18 | * | ||
19 | * This program is free software; you can redistribute it and/or modify it | ||
20 | * under the terms of the GNU General Public License as published by the | ||
21 | * Free Software Foundation; either version 2 of the License, or (at your | ||
22 | * option) any later version. | ||
23 | * | ||
24 | */ | ||
25 | #ifndef __IBM_NEWEMAC_CORE_H | ||
26 | #define __IBM_NEWEMAC_CORE_H | ||
27 | |||
28 | #include <linux/module.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/list.h> | ||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/interrupt.h> | ||
33 | #include <linux/netdevice.h> | ||
34 | #include <linux/dma-mapping.h> | ||
35 | #include <linux/spinlock.h> | ||
36 | #include <linux/of_platform.h> | ||
37 | #include <linux/slab.h> | ||
38 | |||
39 | #include <asm/io.h> | ||
40 | #include <asm/dcr.h> | ||
41 | |||
42 | #include "emac.h" | ||
43 | #include "phy.h" | ||
44 | #include "zmii.h" | ||
45 | #include "rgmii.h" | ||
46 | #include "mal.h" | ||
47 | #include "tah.h" | ||
48 | #include "debug.h" | ||
49 | |||
50 | #define NUM_TX_BUFF CONFIG_IBM_NEW_EMAC_TXB | ||
51 | #define NUM_RX_BUFF CONFIG_IBM_NEW_EMAC_RXB | ||
52 | |||
53 | /* Simple sanity check */ | ||
54 | #if NUM_TX_BUFF > 256 || NUM_RX_BUFF > 256 | ||
55 | #error Invalid number of buffer descriptors (greater than 256) | ||
56 | #endif | ||
57 | |||
58 | #define EMAC_MIN_MTU 46 | ||
59 | |||
60 | /* Maximum L2 header length (VLAN tagged, no FCS) */ | ||
61 | #define EMAC_MTU_OVERHEAD (6 * 2 + 2 + 4) | ||
62 | |||
63 | /* RX BD size for the given MTU */ | ||
64 | static inline int emac_rx_size(int mtu) | ||
65 | { | ||
66 | if (mtu > ETH_DATA_LEN) | ||
67 | return MAL_MAX_RX_SIZE; | ||
68 | else | ||
69 | return mal_rx_size(ETH_DATA_LEN + EMAC_MTU_OVERHEAD); | ||
70 | } | ||
71 | |||
72 | #define EMAC_DMA_ALIGN(x) ALIGN((x), dma_get_cache_alignment()) | ||
73 | |||
74 | #define EMAC_RX_SKB_HEADROOM \ | ||
75 | EMAC_DMA_ALIGN(CONFIG_IBM_NEW_EMAC_RX_SKB_HEADROOM) | ||
76 | |||
77 | /* Size of RX skb for the given MTU */ | ||
78 | static inline int emac_rx_skb_size(int mtu) | ||
79 | { | ||
80 | int size = max(mtu + EMAC_MTU_OVERHEAD, emac_rx_size(mtu)); | ||
81 | return EMAC_DMA_ALIGN(size + 2) + EMAC_RX_SKB_HEADROOM; | ||
82 | } | ||
83 | |||
84 | /* RX DMA sync size */ | ||
85 | static inline int emac_rx_sync_size(int mtu) | ||
86 | { | ||
87 | return EMAC_DMA_ALIGN(emac_rx_size(mtu) + 2); | ||
88 | } | ||
89 | |||
90 | /* Driver statistcs is split into two parts to make it more cache friendly: | ||
91 | * - normal statistics (packet count, etc) | ||
92 | * - error statistics | ||
93 | * | ||
94 | * When statistics is requested by ethtool, these parts are concatenated, | ||
95 | * normal one goes first. | ||
96 | * | ||
97 | * Please, keep these structures in sync with emac_stats_keys. | ||
98 | */ | ||
99 | |||
100 | /* Normal TX/RX Statistics */ | ||
101 | struct emac_stats { | ||
102 | u64 rx_packets; | ||
103 | u64 rx_bytes; | ||
104 | u64 tx_packets; | ||
105 | u64 tx_bytes; | ||
106 | u64 rx_packets_csum; | ||
107 | u64 tx_packets_csum; | ||
108 | }; | ||
109 | |||
110 | /* Error statistics */ | ||
111 | struct emac_error_stats { | ||
112 | u64 tx_undo; | ||
113 | |||
114 | /* Software RX Errors */ | ||
115 | u64 rx_dropped_stack; | ||
116 | u64 rx_dropped_oom; | ||
117 | u64 rx_dropped_error; | ||
118 | u64 rx_dropped_resize; | ||
119 | u64 rx_dropped_mtu; | ||
120 | u64 rx_stopped; | ||
121 | /* BD reported RX errors */ | ||
122 | u64 rx_bd_errors; | ||
123 | u64 rx_bd_overrun; | ||
124 | u64 rx_bd_bad_packet; | ||
125 | u64 rx_bd_runt_packet; | ||
126 | u64 rx_bd_short_event; | ||
127 | u64 rx_bd_alignment_error; | ||
128 | u64 rx_bd_bad_fcs; | ||
129 | u64 rx_bd_packet_too_long; | ||
130 | u64 rx_bd_out_of_range; | ||
131 | u64 rx_bd_in_range; | ||
132 | /* EMAC IRQ reported RX errors */ | ||
133 | u64 rx_parity; | ||
134 | u64 rx_fifo_overrun; | ||
135 | u64 rx_overrun; | ||
136 | u64 rx_bad_packet; | ||
137 | u64 rx_runt_packet; | ||
138 | u64 rx_short_event; | ||
139 | u64 rx_alignment_error; | ||
140 | u64 rx_bad_fcs; | ||
141 | u64 rx_packet_too_long; | ||
142 | u64 rx_out_of_range; | ||
143 | u64 rx_in_range; | ||
144 | |||
145 | /* Software TX Errors */ | ||
146 | u64 tx_dropped; | ||
147 | /* BD reported TX errors */ | ||
148 | u64 tx_bd_errors; | ||
149 | u64 tx_bd_bad_fcs; | ||
150 | u64 tx_bd_carrier_loss; | ||
151 | u64 tx_bd_excessive_deferral; | ||
152 | u64 tx_bd_excessive_collisions; | ||
153 | u64 tx_bd_late_collision; | ||
154 | u64 tx_bd_multple_collisions; | ||
155 | u64 tx_bd_single_collision; | ||
156 | u64 tx_bd_underrun; | ||
157 | u64 tx_bd_sqe; | ||
158 | /* EMAC IRQ reported TX errors */ | ||
159 | u64 tx_parity; | ||
160 | u64 tx_underrun; | ||
161 | u64 tx_sqe; | ||
162 | u64 tx_errors; | ||
163 | }; | ||
164 | |||
165 | #define EMAC_ETHTOOL_STATS_COUNT ((sizeof(struct emac_stats) + \ | ||
166 | sizeof(struct emac_error_stats)) \ | ||
167 | / sizeof(u64)) | ||
168 | |||
169 | struct emac_instance { | ||
170 | struct net_device *ndev; | ||
171 | struct resource rsrc_regs; | ||
172 | struct emac_regs __iomem *emacp; | ||
173 | struct platform_device *ofdev; | ||
174 | struct device_node **blist; /* bootlist entry */ | ||
175 | |||
176 | /* MAL linkage */ | ||
177 | u32 mal_ph; | ||
178 | struct platform_device *mal_dev; | ||
179 | u32 mal_rx_chan; | ||
180 | u32 mal_tx_chan; | ||
181 | struct mal_instance *mal; | ||
182 | struct mal_commac commac; | ||
183 | |||
184 | /* PHY infos */ | ||
185 | u32 phy_mode; | ||
186 | u32 phy_map; | ||
187 | u32 phy_address; | ||
188 | u32 phy_feat_exc; | ||
189 | struct mii_phy phy; | ||
190 | struct mutex link_lock; | ||
191 | struct delayed_work link_work; | ||
192 | int link_polling; | ||
193 | |||
194 | /* GPCS PHY infos */ | ||
195 | u32 gpcs_address; | ||
196 | |||
197 | /* Shared MDIO if any */ | ||
198 | u32 mdio_ph; | ||
199 | struct platform_device *mdio_dev; | ||
200 | struct emac_instance *mdio_instance; | ||
201 | struct mutex mdio_lock; | ||
202 | |||
203 | /* ZMII infos if any */ | ||
204 | u32 zmii_ph; | ||
205 | u32 zmii_port; | ||
206 | struct platform_device *zmii_dev; | ||
207 | |||
208 | /* RGMII infos if any */ | ||
209 | u32 rgmii_ph; | ||
210 | u32 rgmii_port; | ||
211 | struct platform_device *rgmii_dev; | ||
212 | |||
213 | /* TAH infos if any */ | ||
214 | u32 tah_ph; | ||
215 | u32 tah_port; | ||
216 | struct platform_device *tah_dev; | ||
217 | |||
218 | /* IRQs */ | ||
219 | int wol_irq; | ||
220 | int emac_irq; | ||
221 | |||
222 | /* OPB bus frequency in Mhz */ | ||
223 | u32 opb_bus_freq; | ||
224 | |||
225 | /* Cell index within an ASIC (for clk mgmnt) */ | ||
226 | u32 cell_index; | ||
227 | |||
228 | /* Max supported MTU */ | ||
229 | u32 max_mtu; | ||
230 | |||
231 | /* Feature bits (from probe table) */ | ||
232 | unsigned int features; | ||
233 | |||
234 | /* Tx and Rx fifo sizes & other infos in bytes */ | ||
235 | u32 tx_fifo_size; | ||
236 | u32 tx_fifo_size_gige; | ||
237 | u32 rx_fifo_size; | ||
238 | u32 rx_fifo_size_gige; | ||
239 | u32 fifo_entry_size; | ||
240 | u32 mal_burst_size; /* move to MAL ? */ | ||
241 | |||
242 | /* IAHT and GAHT filter parameterization */ | ||
243 | u32 xaht_slots_shift; | ||
244 | u32 xaht_width_shift; | ||
245 | |||
246 | /* Descriptor management | ||
247 | */ | ||
248 | struct mal_descriptor *tx_desc; | ||
249 | int tx_cnt; | ||
250 | int tx_slot; | ||
251 | int ack_slot; | ||
252 | |||
253 | struct mal_descriptor *rx_desc; | ||
254 | int rx_slot; | ||
255 | struct sk_buff *rx_sg_skb; /* 1 */ | ||
256 | int rx_skb_size; | ||
257 | int rx_sync_size; | ||
258 | |||
259 | struct sk_buff *tx_skb[NUM_TX_BUFF]; | ||
260 | struct sk_buff *rx_skb[NUM_RX_BUFF]; | ||
261 | |||
262 | /* Stats | ||
263 | */ | ||
264 | struct emac_error_stats estats; | ||
265 | struct net_device_stats nstats; | ||
266 | struct emac_stats stats; | ||
267 | |||
268 | /* Misc | ||
269 | */ | ||
270 | int reset_failed; | ||
271 | int stop_timeout; /* in us */ | ||
272 | int no_mcast; | ||
273 | int mcast_pending; | ||
274 | int opened; | ||
275 | struct work_struct reset_work; | ||
276 | spinlock_t lock; | ||
277 | }; | ||
278 | |||
279 | /* | ||
280 | * Features of various EMAC implementations | ||
281 | */ | ||
282 | |||
283 | /* | ||
284 | * No flow control on 40x according to the original driver | ||
285 | */ | ||
286 | #define EMAC_FTR_NO_FLOW_CONTROL_40x 0x00000001 | ||
287 | /* | ||
288 | * Cell is an EMAC4 | ||
289 | */ | ||
290 | #define EMAC_FTR_EMAC4 0x00000002 | ||
291 | /* | ||
292 | * For the 440SPe, AMCC inexplicably changed the polarity of | ||
293 | * the "operation complete" bit in the MII control register. | ||
294 | */ | ||
295 | #define EMAC_FTR_STACR_OC_INVERT 0x00000004 | ||
296 | /* | ||
297 | * Set if we have a TAH. | ||
298 | */ | ||
299 | #define EMAC_FTR_HAS_TAH 0x00000008 | ||
300 | /* | ||
301 | * Set if we have a ZMII. | ||
302 | */ | ||
303 | #define EMAC_FTR_HAS_ZMII 0x00000010 | ||
304 | /* | ||
305 | * Set if we have a RGMII. | ||
306 | */ | ||
307 | #define EMAC_FTR_HAS_RGMII 0x00000020 | ||
308 | /* | ||
309 | * Set if we have new type STACR with STAOPC | ||
310 | */ | ||
311 | #define EMAC_FTR_HAS_NEW_STACR 0x00000040 | ||
312 | /* | ||
313 | * Set if we need phy clock workaround for 440gx | ||
314 | */ | ||
315 | #define EMAC_FTR_440GX_PHY_CLK_FIX 0x00000080 | ||
316 | /* | ||
317 | * Set if we need phy clock workaround for 440ep or 440gr | ||
318 | */ | ||
319 | #define EMAC_FTR_440EP_PHY_CLK_FIX 0x00000100 | ||
320 | /* | ||
321 | * The 405EX and 460EX contain the EMAC4SYNC core | ||
322 | */ | ||
323 | #define EMAC_FTR_EMAC4SYNC 0x00000200 | ||
324 | /* | ||
325 | * Set if we need phy clock workaround for 460ex or 460gt | ||
326 | */ | ||
327 | #define EMAC_FTR_460EX_PHY_CLK_FIX 0x00000400 | ||
328 | |||
329 | |||
330 | /* Right now, we don't quite handle the always/possible masks on the | ||
331 | * most optimal way as we don't have a way to say something like | ||
332 | * always EMAC4. Patches welcome. | ||
333 | */ | ||
334 | enum { | ||
335 | EMAC_FTRS_ALWAYS = 0, | ||
336 | |||
337 | EMAC_FTRS_POSSIBLE = | ||
338 | #ifdef CONFIG_IBM_NEW_EMAC_EMAC4 | ||
339 | EMAC_FTR_EMAC4 | EMAC_FTR_EMAC4SYNC | | ||
340 | EMAC_FTR_HAS_NEW_STACR | | ||
341 | EMAC_FTR_STACR_OC_INVERT | EMAC_FTR_440GX_PHY_CLK_FIX | | ||
342 | #endif | ||
343 | #ifdef CONFIG_IBM_NEW_EMAC_TAH | ||
344 | EMAC_FTR_HAS_TAH | | ||
345 | #endif | ||
346 | #ifdef CONFIG_IBM_NEW_EMAC_ZMII | ||
347 | EMAC_FTR_HAS_ZMII | | ||
348 | #endif | ||
349 | #ifdef CONFIG_IBM_NEW_EMAC_RGMII | ||
350 | EMAC_FTR_HAS_RGMII | | ||
351 | #endif | ||
352 | #ifdef CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL | ||
353 | EMAC_FTR_NO_FLOW_CONTROL_40x | | ||
354 | #endif | ||
355 | EMAC_FTR_460EX_PHY_CLK_FIX | | ||
356 | EMAC_FTR_440EP_PHY_CLK_FIX, | ||
357 | }; | ||
358 | |||
359 | static inline int emac_has_feature(struct emac_instance *dev, | ||
360 | unsigned long feature) | ||
361 | { | ||
362 | return (EMAC_FTRS_ALWAYS & feature) || | ||
363 | (EMAC_FTRS_POSSIBLE & dev->features & feature); | ||
364 | } | ||
365 | |||
366 | /* | ||
367 | * Various instances of the EMAC core have varying 1) number of | ||
368 | * address match slots, 2) width of the registers for handling address | ||
369 | * match slots, 3) number of registers for handling address match | ||
370 | * slots and 4) base offset for those registers. | ||
371 | * | ||
372 | * These macros and inlines handle these differences based on | ||
373 | * parameters supplied by the device structure which are, in turn, | ||
374 | * initialized based on the "compatible" entry in the device tree. | ||
375 | */ | ||
376 | |||
377 | #define EMAC4_XAHT_SLOTS_SHIFT 6 | ||
378 | #define EMAC4_XAHT_WIDTH_SHIFT 4 | ||
379 | |||
380 | #define EMAC4SYNC_XAHT_SLOTS_SHIFT 8 | ||
381 | #define EMAC4SYNC_XAHT_WIDTH_SHIFT 5 | ||
382 | |||
383 | #define EMAC_XAHT_SLOTS(dev) (1 << (dev)->xaht_slots_shift) | ||
384 | #define EMAC_XAHT_WIDTH(dev) (1 << (dev)->xaht_width_shift) | ||
385 | #define EMAC_XAHT_REGS(dev) (1 << ((dev)->xaht_slots_shift - \ | ||
386 | (dev)->xaht_width_shift)) | ||
387 | |||
388 | #define EMAC_XAHT_CRC_TO_SLOT(dev, crc) \ | ||
389 | ((EMAC_XAHT_SLOTS(dev) - 1) - \ | ||
390 | ((crc) >> ((sizeof (u32) * BITS_PER_BYTE) - \ | ||
391 | (dev)->xaht_slots_shift))) | ||
392 | |||
393 | #define EMAC_XAHT_SLOT_TO_REG(dev, slot) \ | ||
394 | ((slot) >> (dev)->xaht_width_shift) | ||
395 | |||
396 | #define EMAC_XAHT_SLOT_TO_MASK(dev, slot) \ | ||
397 | ((u32)(1 << (EMAC_XAHT_WIDTH(dev) - 1)) >> \ | ||
398 | ((slot) & (u32)(EMAC_XAHT_WIDTH(dev) - 1))) | ||
399 | |||
400 | static inline u32 *emac_xaht_base(struct emac_instance *dev) | ||
401 | { | ||
402 | struct emac_regs __iomem *p = dev->emacp; | ||
403 | int offset; | ||
404 | |||
405 | /* The first IAHT entry always is the base of the block of | ||
406 | * IAHT and GAHT registers. | ||
407 | */ | ||
408 | if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC)) | ||
409 | offset = offsetof(struct emac_regs, u1.emac4sync.iaht1); | ||
410 | else | ||
411 | offset = offsetof(struct emac_regs, u0.emac4.iaht1); | ||
412 | |||
413 | return (u32 *)((ptrdiff_t)p + offset); | ||
414 | } | ||
415 | |||
416 | static inline u32 *emac_gaht_base(struct emac_instance *dev) | ||
417 | { | ||
418 | /* GAHT registers always come after an identical number of | ||
419 | * IAHT registers. | ||
420 | */ | ||
421 | return emac_xaht_base(dev) + EMAC_XAHT_REGS(dev); | ||
422 | } | ||
423 | |||
424 | static inline u32 *emac_iaht_base(struct emac_instance *dev) | ||
425 | { | ||
426 | /* IAHT registers always come before an identical number of | ||
427 | * GAHT registers. | ||
428 | */ | ||
429 | return emac_xaht_base(dev); | ||
430 | } | ||
431 | |||
432 | /* Ethtool get_regs complex data. | ||
433 | * We want to get not just EMAC registers, but also MAL, ZMII, RGMII, TAH | ||
434 | * when available. | ||
435 | * | ||
436 | * Returned BLOB consists of the ibm_emac_ethtool_regs_hdr, | ||
437 | * MAL registers, EMAC registers and optional ZMII, RGMII, TAH registers. | ||
438 | * Each register component is preceded with emac_ethtool_regs_subhdr. | ||
439 | * Order of the optional headers follows their relative bit posititions | ||
440 | * in emac_ethtool_regs_hdr.components | ||
441 | */ | ||
442 | #define EMAC_ETHTOOL_REGS_ZMII 0x00000001 | ||
443 | #define EMAC_ETHTOOL_REGS_RGMII 0x00000002 | ||
444 | #define EMAC_ETHTOOL_REGS_TAH 0x00000004 | ||
445 | |||
446 | struct emac_ethtool_regs_hdr { | ||
447 | u32 components; | ||
448 | }; | ||
449 | |||
450 | struct emac_ethtool_regs_subhdr { | ||
451 | u32 version; | ||
452 | u32 index; | ||
453 | }; | ||
454 | |||
455 | #define EMAC_ETHTOOL_REGS_VER 0 | ||
456 | #define EMAC_ETHTOOL_REGS_SIZE(dev) ((dev)->rsrc_regs.end - \ | ||
457 | (dev)->rsrc_regs.start + 1) | ||
458 | #define EMAC4_ETHTOOL_REGS_VER 1 | ||
459 | #define EMAC4_ETHTOOL_REGS_SIZE(dev) ((dev)->rsrc_regs.end - \ | ||
460 | (dev)->rsrc_regs.start + 1) | ||
461 | |||
462 | #endif /* __IBM_NEWEMAC_CORE_H */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/debug.c b/drivers/net/ethernet/ibm/emac/debug.c new file mode 100644 index 000000000000..8c6c1e2a8750 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/debug.c | |||
@@ -0,0 +1,270 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/debug.c | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify it | ||
15 | * under the terms of the GNU General Public License as published by the | ||
16 | * Free Software Foundation; either version 2 of the License, or (at your | ||
17 | * option) any later version. | ||
18 | * | ||
19 | */ | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/netdevice.h> | ||
24 | #include <linux/sysrq.h> | ||
25 | #include <asm/io.h> | ||
26 | |||
27 | #include "core.h" | ||
28 | |||
29 | static DEFINE_SPINLOCK(emac_dbg_lock); | ||
30 | |||
31 | static void emac_desc_dump(struct emac_instance *p) | ||
32 | { | ||
33 | int i; | ||
34 | printk("** EMAC %s TX BDs **\n" | ||
35 | " tx_cnt = %d tx_slot = %d ack_slot = %d\n", | ||
36 | p->ofdev->dev.of_node->full_name, | ||
37 | p->tx_cnt, p->tx_slot, p->ack_slot); | ||
38 | for (i = 0; i < NUM_TX_BUFF / 2; ++i) | ||
39 | printk | ||
40 | ("bd[%2d] 0x%08x %c 0x%04x %4u - bd[%2d] 0x%08x %c 0x%04x %4u\n", | ||
41 | i, p->tx_desc[i].data_ptr, p->tx_skb[i] ? 'V' : ' ', | ||
42 | p->tx_desc[i].ctrl, p->tx_desc[i].data_len, | ||
43 | NUM_TX_BUFF / 2 + i, | ||
44 | p->tx_desc[NUM_TX_BUFF / 2 + i].data_ptr, | ||
45 | p->tx_skb[NUM_TX_BUFF / 2 + i] ? 'V' : ' ', | ||
46 | p->tx_desc[NUM_TX_BUFF / 2 + i].ctrl, | ||
47 | p->tx_desc[NUM_TX_BUFF / 2 + i].data_len); | ||
48 | |||
49 | printk("** EMAC %s RX BDs **\n" | ||
50 | " rx_slot = %d flags = 0x%lx rx_skb_size = %d rx_sync_size = %d\n" | ||
51 | " rx_sg_skb = 0x%p\n", | ||
52 | p->ofdev->dev.of_node->full_name, | ||
53 | p->rx_slot, p->commac.flags, p->rx_skb_size, | ||
54 | p->rx_sync_size, p->rx_sg_skb); | ||
55 | for (i = 0; i < NUM_RX_BUFF / 2; ++i) | ||
56 | printk | ||
57 | ("bd[%2d] 0x%08x %c 0x%04x %4u - bd[%2d] 0x%08x %c 0x%04x %4u\n", | ||
58 | i, p->rx_desc[i].data_ptr, p->rx_skb[i] ? 'V' : ' ', | ||
59 | p->rx_desc[i].ctrl, p->rx_desc[i].data_len, | ||
60 | NUM_RX_BUFF / 2 + i, | ||
61 | p->rx_desc[NUM_RX_BUFF / 2 + i].data_ptr, | ||
62 | p->rx_skb[NUM_RX_BUFF / 2 + i] ? 'V' : ' ', | ||
63 | p->rx_desc[NUM_RX_BUFF / 2 + i].ctrl, | ||
64 | p->rx_desc[NUM_RX_BUFF / 2 + i].data_len); | ||
65 | } | ||
66 | |||
67 | static void emac_mac_dump(struct emac_instance *dev) | ||
68 | { | ||
69 | struct emac_regs __iomem *p = dev->emacp; | ||
70 | const int xaht_regs = EMAC_XAHT_REGS(dev); | ||
71 | u32 *gaht_base = emac_gaht_base(dev); | ||
72 | u32 *iaht_base = emac_iaht_base(dev); | ||
73 | int emac4sync = emac_has_feature(dev, EMAC_FTR_EMAC4SYNC); | ||
74 | int n; | ||
75 | |||
76 | printk("** EMAC %s registers **\n" | ||
77 | "MR0 = 0x%08x MR1 = 0x%08x TMR0 = 0x%08x TMR1 = 0x%08x\n" | ||
78 | "RMR = 0x%08x ISR = 0x%08x ISER = 0x%08x\n" | ||
79 | "IAR = %04x%08x VTPID = 0x%04x VTCI = 0x%04x\n", | ||
80 | dev->ofdev->dev.of_node->full_name, | ||
81 | in_be32(&p->mr0), in_be32(&p->mr1), | ||
82 | in_be32(&p->tmr0), in_be32(&p->tmr1), | ||
83 | in_be32(&p->rmr), in_be32(&p->isr), in_be32(&p->iser), | ||
84 | in_be32(&p->iahr), in_be32(&p->ialr), in_be32(&p->vtpid), | ||
85 | in_be32(&p->vtci) | ||
86 | ); | ||
87 | |||
88 | if (emac4sync) | ||
89 | printk("MAR = %04x%08x MMAR = %04x%08x\n", | ||
90 | in_be32(&p->u0.emac4sync.mahr), | ||
91 | in_be32(&p->u0.emac4sync.malr), | ||
92 | in_be32(&p->u0.emac4sync.mmahr), | ||
93 | in_be32(&p->u0.emac4sync.mmalr) | ||
94 | ); | ||
95 | |||
96 | for (n = 0; n < xaht_regs; n++) | ||
97 | printk("IAHT%02d = 0x%08x\n", n + 1, in_be32(iaht_base + n)); | ||
98 | |||
99 | for (n = 0; n < xaht_regs; n++) | ||
100 | printk("GAHT%02d = 0x%08x\n", n + 1, in_be32(gaht_base + n)); | ||
101 | |||
102 | printk("LSA = %04x%08x IPGVR = 0x%04x\n" | ||
103 | "STACR = 0x%08x TRTR = 0x%08x RWMR = 0x%08x\n" | ||
104 | "OCTX = 0x%08x OCRX = 0x%08x\n", | ||
105 | in_be32(&p->lsah), in_be32(&p->lsal), in_be32(&p->ipgvr), | ||
106 | in_be32(&p->stacr), in_be32(&p->trtr), in_be32(&p->rwmr), | ||
107 | in_be32(&p->octx), in_be32(&p->ocrx) | ||
108 | ); | ||
109 | |||
110 | if (!emac4sync) { | ||
111 | printk("IPCR = 0x%08x\n", | ||
112 | in_be32(&p->u1.emac4.ipcr) | ||
113 | ); | ||
114 | } else { | ||
115 | printk("REVID = 0x%08x TPC = 0x%08x\n", | ||
116 | in_be32(&p->u1.emac4sync.revid), | ||
117 | in_be32(&p->u1.emac4sync.tpc) | ||
118 | ); | ||
119 | } | ||
120 | |||
121 | emac_desc_dump(dev); | ||
122 | } | ||
123 | |||
124 | static void emac_mal_dump(struct mal_instance *mal) | ||
125 | { | ||
126 | int i; | ||
127 | |||
128 | printk("** MAL %s Registers **\n" | ||
129 | "CFG = 0x%08x ESR = 0x%08x IER = 0x%08x\n" | ||
130 | "TX|CASR = 0x%08x CARR = 0x%08x EOBISR = 0x%08x DEIR = 0x%08x\n" | ||
131 | "RX|CASR = 0x%08x CARR = 0x%08x EOBISR = 0x%08x DEIR = 0x%08x\n", | ||
132 | mal->ofdev->dev.of_node->full_name, | ||
133 | get_mal_dcrn(mal, MAL_CFG), get_mal_dcrn(mal, MAL_ESR), | ||
134 | get_mal_dcrn(mal, MAL_IER), | ||
135 | get_mal_dcrn(mal, MAL_TXCASR), get_mal_dcrn(mal, MAL_TXCARR), | ||
136 | get_mal_dcrn(mal, MAL_TXEOBISR), get_mal_dcrn(mal, MAL_TXDEIR), | ||
137 | get_mal_dcrn(mal, MAL_RXCASR), get_mal_dcrn(mal, MAL_RXCARR), | ||
138 | get_mal_dcrn(mal, MAL_RXEOBISR), get_mal_dcrn(mal, MAL_RXDEIR) | ||
139 | ); | ||
140 | |||
141 | printk("TX|"); | ||
142 | for (i = 0; i < mal->num_tx_chans; ++i) { | ||
143 | if (i && !(i % 4)) | ||
144 | printk("\n "); | ||
145 | printk("CTP%d = 0x%08x ", i, get_mal_dcrn(mal, MAL_TXCTPR(i))); | ||
146 | } | ||
147 | printk("\nRX|"); | ||
148 | for (i = 0; i < mal->num_rx_chans; ++i) { | ||
149 | if (i && !(i % 4)) | ||
150 | printk("\n "); | ||
151 | printk("CTP%d = 0x%08x ", i, get_mal_dcrn(mal, MAL_RXCTPR(i))); | ||
152 | } | ||
153 | printk("\n "); | ||
154 | for (i = 0; i < mal->num_rx_chans; ++i) { | ||
155 | u32 r = get_mal_dcrn(mal, MAL_RCBS(i)); | ||
156 | if (i && !(i % 3)) | ||
157 | printk("\n "); | ||
158 | printk("RCBS%d = 0x%08x (%d) ", i, r, r * 16); | ||
159 | } | ||
160 | printk("\n"); | ||
161 | } | ||
162 | |||
163 | static struct emac_instance *__emacs[4]; | ||
164 | static struct mal_instance *__mals[1]; | ||
165 | |||
166 | void emac_dbg_register(struct emac_instance *dev) | ||
167 | { | ||
168 | unsigned long flags; | ||
169 | int i; | ||
170 | |||
171 | spin_lock_irqsave(&emac_dbg_lock, flags); | ||
172 | for (i = 0; i < ARRAY_SIZE(__emacs); i++) | ||
173 | if (__emacs[i] == NULL) { | ||
174 | __emacs[i] = dev; | ||
175 | break; | ||
176 | } | ||
177 | spin_unlock_irqrestore(&emac_dbg_lock, flags); | ||
178 | } | ||
179 | |||
180 | void emac_dbg_unregister(struct emac_instance *dev) | ||
181 | { | ||
182 | unsigned long flags; | ||
183 | int i; | ||
184 | |||
185 | spin_lock_irqsave(&emac_dbg_lock, flags); | ||
186 | for (i = 0; i < ARRAY_SIZE(__emacs); i++) | ||
187 | if (__emacs[i] == dev) { | ||
188 | __emacs[i] = NULL; | ||
189 | break; | ||
190 | } | ||
191 | spin_unlock_irqrestore(&emac_dbg_lock, flags); | ||
192 | } | ||
193 | |||
194 | void mal_dbg_register(struct mal_instance *mal) | ||
195 | { | ||
196 | unsigned long flags; | ||
197 | int i; | ||
198 | |||
199 | spin_lock_irqsave(&emac_dbg_lock, flags); | ||
200 | for (i = 0; i < ARRAY_SIZE(__mals); i++) | ||
201 | if (__mals[i] == NULL) { | ||
202 | __mals[i] = mal; | ||
203 | break; | ||
204 | } | ||
205 | spin_unlock_irqrestore(&emac_dbg_lock, flags); | ||
206 | } | ||
207 | |||
208 | void mal_dbg_unregister(struct mal_instance *mal) | ||
209 | { | ||
210 | unsigned long flags; | ||
211 | int i; | ||
212 | |||
213 | spin_lock_irqsave(&emac_dbg_lock, flags); | ||
214 | for (i = 0; i < ARRAY_SIZE(__mals); i++) | ||
215 | if (__mals[i] == mal) { | ||
216 | __mals[i] = NULL; | ||
217 | break; | ||
218 | } | ||
219 | spin_unlock_irqrestore(&emac_dbg_lock, flags); | ||
220 | } | ||
221 | |||
222 | void emac_dbg_dump_all(void) | ||
223 | { | ||
224 | unsigned int i; | ||
225 | unsigned long flags; | ||
226 | |||
227 | spin_lock_irqsave(&emac_dbg_lock, flags); | ||
228 | |||
229 | for (i = 0; i < ARRAY_SIZE(__mals); ++i) | ||
230 | if (__mals[i]) | ||
231 | emac_mal_dump(__mals[i]); | ||
232 | |||
233 | for (i = 0; i < ARRAY_SIZE(__emacs); ++i) | ||
234 | if (__emacs[i]) | ||
235 | emac_mac_dump(__emacs[i]); | ||
236 | |||
237 | spin_unlock_irqrestore(&emac_dbg_lock, flags); | ||
238 | } | ||
239 | |||
240 | #if defined(CONFIG_MAGIC_SYSRQ) | ||
241 | static void emac_sysrq_handler(int key) | ||
242 | { | ||
243 | emac_dbg_dump_all(); | ||
244 | } | ||
245 | |||
246 | static struct sysrq_key_op emac_sysrq_op = { | ||
247 | .handler = emac_sysrq_handler, | ||
248 | .help_msg = "emaC", | ||
249 | .action_msg = "Show EMAC(s) status", | ||
250 | }; | ||
251 | |||
252 | int __init emac_init_debug(void) | ||
253 | { | ||
254 | return register_sysrq_key('c', &emac_sysrq_op); | ||
255 | } | ||
256 | |||
257 | void __exit emac_fini_debug(void) | ||
258 | { | ||
259 | unregister_sysrq_key('c', &emac_sysrq_op); | ||
260 | } | ||
261 | |||
262 | #else | ||
263 | int __init emac_init_debug(void) | ||
264 | { | ||
265 | return 0; | ||
266 | } | ||
267 | void __exit emac_fini_debug(void) | ||
268 | { | ||
269 | } | ||
270 | #endif /* CONFIG_MAGIC_SYSRQ */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/debug.h b/drivers/net/ethernet/ibm/emac/debug.h new file mode 100644 index 000000000000..e596c77ccdf7 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/debug.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/debug.h | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify it | ||
15 | * under the terms of the GNU General Public License as published by the | ||
16 | * Free Software Foundation; either version 2 of the License, or (at your | ||
17 | * option) any later version. | ||
18 | * | ||
19 | */ | ||
20 | #ifndef __IBM_NEWEMAC_DEBUG_H | ||
21 | #define __IBM_NEWEMAC_DEBUG_H | ||
22 | |||
23 | #include <linux/init.h> | ||
24 | |||
25 | #include "core.h" | ||
26 | |||
27 | #if defined(CONFIG_IBM_NEW_EMAC_DEBUG) | ||
28 | |||
29 | struct emac_instance; | ||
30 | struct mal_instance; | ||
31 | |||
32 | extern void emac_dbg_register(struct emac_instance *dev); | ||
33 | extern void emac_dbg_unregister(struct emac_instance *dev); | ||
34 | extern void mal_dbg_register(struct mal_instance *mal); | ||
35 | extern void mal_dbg_unregister(struct mal_instance *mal); | ||
36 | extern int emac_init_debug(void) __init; | ||
37 | extern void emac_fini_debug(void) __exit; | ||
38 | extern void emac_dbg_dump_all(void); | ||
39 | |||
40 | # define DBG_LEVEL 1 | ||
41 | |||
42 | #else | ||
43 | |||
44 | # define emac_dbg_register(x) do { } while(0) | ||
45 | # define emac_dbg_unregister(x) do { } while(0) | ||
46 | # define mal_dbg_register(x) do { } while(0) | ||
47 | # define mal_dbg_unregister(x) do { } while(0) | ||
48 | # define emac_init_debug() do { } while(0) | ||
49 | # define emac_fini_debug() do { } while(0) | ||
50 | # define emac_dbg_dump_all() do { } while(0) | ||
51 | |||
52 | # define DBG_LEVEL 0 | ||
53 | |||
54 | #endif | ||
55 | |||
56 | #define EMAC_DBG(d, name, fmt, arg...) \ | ||
57 | printk(KERN_DEBUG #name "%s: " fmt, d->ofdev->dev.of_node->full_name, ## arg) | ||
58 | |||
59 | #if DBG_LEVEL > 0 | ||
60 | # define DBG(d,f,x...) EMAC_DBG(d, emac, f, ##x) | ||
61 | # define MAL_DBG(d,f,x...) EMAC_DBG(d, mal, f, ##x) | ||
62 | # define ZMII_DBG(d,f,x...) EMAC_DBG(d, zmii, f, ##x) | ||
63 | # define RGMII_DBG(d,f,x...) EMAC_DBG(d, rgmii, f, ##x) | ||
64 | # define NL "\n" | ||
65 | #else | ||
66 | # define DBG(f,x...) ((void)0) | ||
67 | # define MAL_DBG(d,f,x...) ((void)0) | ||
68 | # define ZMII_DBG(d,f,x...) ((void)0) | ||
69 | # define RGMII_DBG(d,f,x...) ((void)0) | ||
70 | #endif | ||
71 | #if DBG_LEVEL > 1 | ||
72 | # define DBG2(d,f,x...) DBG(d,f, ##x) | ||
73 | # define MAL_DBG2(d,f,x...) MAL_DBG(d,f, ##x) | ||
74 | # define ZMII_DBG2(d,f,x...) ZMII_DBG(d,f, ##x) | ||
75 | # define RGMII_DBG2(d,f,x...) RGMII_DBG(d,f, ##x) | ||
76 | #else | ||
77 | # define DBG2(f,x...) ((void)0) | ||
78 | # define MAL_DBG2(d,f,x...) ((void)0) | ||
79 | # define ZMII_DBG2(d,f,x...) ((void)0) | ||
80 | # define RGMII_DBG2(d,f,x...) ((void)0) | ||
81 | #endif | ||
82 | |||
83 | #endif /* __IBM_NEWEMAC_DEBUG_H */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/emac.h b/drivers/net/ethernet/ibm/emac/emac.h new file mode 100644 index 000000000000..1568278d759a --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/emac.h | |||
@@ -0,0 +1,312 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/emac.h | ||
3 | * | ||
4 | * Register definitions for PowerPC 4xx on-chip ethernet contoller | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * Based on original work by | ||
15 | * Matt Porter <mporter@kernel.crashing.org> | ||
16 | * Armin Kuster <akuster@mvista.com> | ||
17 | * Copyright 2002-2004 MontaVista Software Inc. | ||
18 | * | ||
19 | * This program is free software; you can redistribute it and/or modify it | ||
20 | * under the terms of the GNU General Public License as published by the | ||
21 | * Free Software Foundation; either version 2 of the License, or (at your | ||
22 | * option) any later version. | ||
23 | * | ||
24 | */ | ||
25 | #ifndef __IBM_NEWEMAC_H | ||
26 | #define __IBM_NEWEMAC_H | ||
27 | |||
28 | #include <linux/types.h> | ||
29 | #include <linux/phy.h> | ||
30 | |||
31 | /* EMAC registers Write Access rules */ | ||
32 | struct emac_regs { | ||
33 | /* Common registers across all EMAC implementations. */ | ||
34 | u32 mr0; /* Special */ | ||
35 | u32 mr1; /* Reset */ | ||
36 | u32 tmr0; /* Special */ | ||
37 | u32 tmr1; /* Special */ | ||
38 | u32 rmr; /* Reset */ | ||
39 | u32 isr; /* Always */ | ||
40 | u32 iser; /* Reset */ | ||
41 | u32 iahr; /* Reset, R, T */ | ||
42 | u32 ialr; /* Reset, R, T */ | ||
43 | u32 vtpid; /* Reset, R, T */ | ||
44 | u32 vtci; /* Reset, R, T */ | ||
45 | u32 ptr; /* Reset, T */ | ||
46 | union { | ||
47 | /* Registers unique to EMAC4 implementations */ | ||
48 | struct { | ||
49 | u32 iaht1; /* Reset, R */ | ||
50 | u32 iaht2; /* Reset, R */ | ||
51 | u32 iaht3; /* Reset, R */ | ||
52 | u32 iaht4; /* Reset, R */ | ||
53 | u32 gaht1; /* Reset, R */ | ||
54 | u32 gaht2; /* Reset, R */ | ||
55 | u32 gaht3; /* Reset, R */ | ||
56 | u32 gaht4; /* Reset, R */ | ||
57 | } emac4; | ||
58 | /* Registers unique to EMAC4SYNC implementations */ | ||
59 | struct { | ||
60 | u32 mahr; /* Reset, R, T */ | ||
61 | u32 malr; /* Reset, R, T */ | ||
62 | u32 mmahr; /* Reset, R, T */ | ||
63 | u32 mmalr; /* Reset, R, T */ | ||
64 | u32 rsvd0[4]; | ||
65 | } emac4sync; | ||
66 | } u0; | ||
67 | /* Common registers across all EMAC implementations. */ | ||
68 | u32 lsah; | ||
69 | u32 lsal; | ||
70 | u32 ipgvr; /* Reset, T */ | ||
71 | u32 stacr; /* Special */ | ||
72 | u32 trtr; /* Special */ | ||
73 | u32 rwmr; /* Reset */ | ||
74 | u32 octx; | ||
75 | u32 ocrx; | ||
76 | union { | ||
77 | /* Registers unique to EMAC4 implementations */ | ||
78 | struct { | ||
79 | u32 ipcr; | ||
80 | } emac4; | ||
81 | /* Registers unique to EMAC4SYNC implementations */ | ||
82 | struct { | ||
83 | u32 rsvd1; | ||
84 | u32 revid; | ||
85 | u32 rsvd2[2]; | ||
86 | u32 iaht1; /* Reset, R */ | ||
87 | u32 iaht2; /* Reset, R */ | ||
88 | u32 iaht3; /* Reset, R */ | ||
89 | u32 iaht4; /* Reset, R */ | ||
90 | u32 iaht5; /* Reset, R */ | ||
91 | u32 iaht6; /* Reset, R */ | ||
92 | u32 iaht7; /* Reset, R */ | ||
93 | u32 iaht8; /* Reset, R */ | ||
94 | u32 gaht1; /* Reset, R */ | ||
95 | u32 gaht2; /* Reset, R */ | ||
96 | u32 gaht3; /* Reset, R */ | ||
97 | u32 gaht4; /* Reset, R */ | ||
98 | u32 gaht5; /* Reset, R */ | ||
99 | u32 gaht6; /* Reset, R */ | ||
100 | u32 gaht7; /* Reset, R */ | ||
101 | u32 gaht8; /* Reset, R */ | ||
102 | u32 tpc; /* Reset, T */ | ||
103 | } emac4sync; | ||
104 | } u1; | ||
105 | }; | ||
106 | |||
107 | /* | ||
108 | * PHY mode settings (EMAC <-> ZMII/RGMII bridge <-> PHY) | ||
109 | */ | ||
110 | #define PHY_MODE_NA PHY_INTERFACE_MODE_NA | ||
111 | #define PHY_MODE_MII PHY_INTERFACE_MODE_MII | ||
112 | #define PHY_MODE_RMII PHY_INTERFACE_MODE_RMII | ||
113 | #define PHY_MODE_SMII PHY_INTERFACE_MODE_SMII | ||
114 | #define PHY_MODE_RGMII PHY_INTERFACE_MODE_RGMII | ||
115 | #define PHY_MODE_TBI PHY_INTERFACE_MODE_TBI | ||
116 | #define PHY_MODE_GMII PHY_INTERFACE_MODE_GMII | ||
117 | #define PHY_MODE_RTBI PHY_INTERFACE_MODE_RTBI | ||
118 | #define PHY_MODE_SGMII PHY_INTERFACE_MODE_SGMII | ||
119 | |||
120 | /* EMACx_MR0 */ | ||
121 | #define EMAC_MR0_RXI 0x80000000 | ||
122 | #define EMAC_MR0_TXI 0x40000000 | ||
123 | #define EMAC_MR0_SRST 0x20000000 | ||
124 | #define EMAC_MR0_TXE 0x10000000 | ||
125 | #define EMAC_MR0_RXE 0x08000000 | ||
126 | #define EMAC_MR0_WKE 0x04000000 | ||
127 | |||
128 | /* EMACx_MR1 */ | ||
129 | #define EMAC_MR1_FDE 0x80000000 | ||
130 | #define EMAC_MR1_ILE 0x40000000 | ||
131 | #define EMAC_MR1_VLE 0x20000000 | ||
132 | #define EMAC_MR1_EIFC 0x10000000 | ||
133 | #define EMAC_MR1_APP 0x08000000 | ||
134 | #define EMAC_MR1_IST 0x01000000 | ||
135 | |||
136 | #define EMAC_MR1_MF_MASK 0x00c00000 | ||
137 | #define EMAC_MR1_MF_10 0x00000000 | ||
138 | #define EMAC_MR1_MF_100 0x00400000 | ||
139 | #define EMAC_MR1_MF_1000 0x00800000 | ||
140 | #define EMAC_MR1_MF_1000GPCS 0x00c00000 | ||
141 | #define EMAC_MR1_MF_IPPA(id) (((id) & 0x1f) << 6) | ||
142 | |||
143 | #define EMAC_MR1_RFS_4K 0x00300000 | ||
144 | #define EMAC_MR1_RFS_16K 0x00000000 | ||
145 | #define EMAC_MR1_TFS_2K 0x00080000 | ||
146 | #define EMAC_MR1_TR0_MULT 0x00008000 | ||
147 | #define EMAC_MR1_JPSM 0x00000000 | ||
148 | #define EMAC_MR1_MWSW_001 0x00000000 | ||
149 | #define EMAC_MR1_BASE(opb) (EMAC_MR1_TFS_2K | EMAC_MR1_TR0_MULT) | ||
150 | |||
151 | |||
152 | #define EMAC4_MR1_RFS_2K 0x00100000 | ||
153 | #define EMAC4_MR1_RFS_4K 0x00180000 | ||
154 | #define EMAC4_MR1_RFS_16K 0x00280000 | ||
155 | #define EMAC4_MR1_TFS_2K 0x00020000 | ||
156 | #define EMAC4_MR1_TFS_4K 0x00030000 | ||
157 | #define EMAC4_MR1_TFS_16K 0x00050000 | ||
158 | #define EMAC4_MR1_TR 0x00008000 | ||
159 | #define EMAC4_MR1_MWSW_001 0x00001000 | ||
160 | #define EMAC4_MR1_JPSM 0x00000800 | ||
161 | #define EMAC4_MR1_OBCI_MASK 0x00000038 | ||
162 | #define EMAC4_MR1_OBCI_50 0x00000000 | ||
163 | #define EMAC4_MR1_OBCI_66 0x00000008 | ||
164 | #define EMAC4_MR1_OBCI_83 0x00000010 | ||
165 | #define EMAC4_MR1_OBCI_100 0x00000018 | ||
166 | #define EMAC4_MR1_OBCI_100P 0x00000020 | ||
167 | #define EMAC4_MR1_OBCI(freq) ((freq) <= 50 ? EMAC4_MR1_OBCI_50 : \ | ||
168 | (freq) <= 66 ? EMAC4_MR1_OBCI_66 : \ | ||
169 | (freq) <= 83 ? EMAC4_MR1_OBCI_83 : \ | ||
170 | (freq) <= 100 ? EMAC4_MR1_OBCI_100 : \ | ||
171 | EMAC4_MR1_OBCI_100P) | ||
172 | |||
173 | /* EMACx_TMR0 */ | ||
174 | #define EMAC_TMR0_GNP 0x80000000 | ||
175 | #define EMAC_TMR0_DEFAULT 0x00000000 | ||
176 | #define EMAC4_TMR0_TFAE_2_32 0x00000001 | ||
177 | #define EMAC4_TMR0_TFAE_4_64 0x00000002 | ||
178 | #define EMAC4_TMR0_TFAE_8_128 0x00000003 | ||
179 | #define EMAC4_TMR0_TFAE_16_256 0x00000004 | ||
180 | #define EMAC4_TMR0_TFAE_32_512 0x00000005 | ||
181 | #define EMAC4_TMR0_TFAE_64_1024 0x00000006 | ||
182 | #define EMAC4_TMR0_TFAE_128_2048 0x00000007 | ||
183 | #define EMAC4_TMR0_DEFAULT EMAC4_TMR0_TFAE_2_32 | ||
184 | #define EMAC_TMR0_XMIT (EMAC_TMR0_GNP | EMAC_TMR0_DEFAULT) | ||
185 | #define EMAC4_TMR0_XMIT (EMAC_TMR0_GNP | EMAC4_TMR0_DEFAULT) | ||
186 | |||
187 | /* EMACx_TMR1 */ | ||
188 | |||
189 | #define EMAC_TMR1(l,h) (((l) << 27) | (((h) & 0xff) << 16)) | ||
190 | #define EMAC4_TMR1(l,h) (((l) << 27) | (((h) & 0x3ff) << 14)) | ||
191 | |||
192 | /* EMACx_RMR */ | ||
193 | #define EMAC_RMR_SP 0x80000000 | ||
194 | #define EMAC_RMR_SFCS 0x40000000 | ||
195 | #define EMAC_RMR_RRP 0x20000000 | ||
196 | #define EMAC_RMR_RFP 0x10000000 | ||
197 | #define EMAC_RMR_ROP 0x08000000 | ||
198 | #define EMAC_RMR_RPIR 0x04000000 | ||
199 | #define EMAC_RMR_PPP 0x02000000 | ||
200 | #define EMAC_RMR_PME 0x01000000 | ||
201 | #define EMAC_RMR_PMME 0x00800000 | ||
202 | #define EMAC_RMR_IAE 0x00400000 | ||
203 | #define EMAC_RMR_MIAE 0x00200000 | ||
204 | #define EMAC_RMR_BAE 0x00100000 | ||
205 | #define EMAC_RMR_MAE 0x00080000 | ||
206 | #define EMAC_RMR_BASE 0x00000000 | ||
207 | #define EMAC4_RMR_RFAF_2_32 0x00000001 | ||
208 | #define EMAC4_RMR_RFAF_4_64 0x00000002 | ||
209 | #define EMAC4_RMR_RFAF_8_128 0x00000003 | ||
210 | #define EMAC4_RMR_RFAF_16_256 0x00000004 | ||
211 | #define EMAC4_RMR_RFAF_32_512 0x00000005 | ||
212 | #define EMAC4_RMR_RFAF_64_1024 0x00000006 | ||
213 | #define EMAC4_RMR_RFAF_128_2048 0x00000007 | ||
214 | #define EMAC4_RMR_BASE EMAC4_RMR_RFAF_128_2048 | ||
215 | |||
216 | /* EMACx_ISR & EMACx_ISER */ | ||
217 | #define EMAC4_ISR_TXPE 0x20000000 | ||
218 | #define EMAC4_ISR_RXPE 0x10000000 | ||
219 | #define EMAC4_ISR_TXUE 0x08000000 | ||
220 | #define EMAC4_ISR_RXOE 0x04000000 | ||
221 | #define EMAC_ISR_OVR 0x02000000 | ||
222 | #define EMAC_ISR_PP 0x01000000 | ||
223 | #define EMAC_ISR_BP 0x00800000 | ||
224 | #define EMAC_ISR_RP 0x00400000 | ||
225 | #define EMAC_ISR_SE 0x00200000 | ||
226 | #define EMAC_ISR_ALE 0x00100000 | ||
227 | #define EMAC_ISR_BFCS 0x00080000 | ||
228 | #define EMAC_ISR_PTLE 0x00040000 | ||
229 | #define EMAC_ISR_ORE 0x00020000 | ||
230 | #define EMAC_ISR_IRE 0x00010000 | ||
231 | #define EMAC_ISR_SQE 0x00000080 | ||
232 | #define EMAC_ISR_TE 0x00000040 | ||
233 | #define EMAC_ISR_MOS 0x00000002 | ||
234 | #define EMAC_ISR_MOF 0x00000001 | ||
235 | |||
236 | /* EMACx_STACR */ | ||
237 | #define EMAC_STACR_PHYD_MASK 0xffff | ||
238 | #define EMAC_STACR_PHYD_SHIFT 16 | ||
239 | #define EMAC_STACR_OC 0x00008000 | ||
240 | #define EMAC_STACR_PHYE 0x00004000 | ||
241 | #define EMAC_STACR_STAC_MASK 0x00003000 | ||
242 | #define EMAC_STACR_STAC_READ 0x00001000 | ||
243 | #define EMAC_STACR_STAC_WRITE 0x00002000 | ||
244 | #define EMAC_STACR_OPBC_MASK 0x00000C00 | ||
245 | #define EMAC_STACR_OPBC_50 0x00000000 | ||
246 | #define EMAC_STACR_OPBC_66 0x00000400 | ||
247 | #define EMAC_STACR_OPBC_83 0x00000800 | ||
248 | #define EMAC_STACR_OPBC_100 0x00000C00 | ||
249 | #define EMAC_STACR_OPBC(freq) ((freq) <= 50 ? EMAC_STACR_OPBC_50 : \ | ||
250 | (freq) <= 66 ? EMAC_STACR_OPBC_66 : \ | ||
251 | (freq) <= 83 ? EMAC_STACR_OPBC_83 : EMAC_STACR_OPBC_100) | ||
252 | #define EMAC_STACR_BASE(opb) EMAC_STACR_OPBC(opb) | ||
253 | #define EMAC4_STACR_BASE(opb) 0x00000000 | ||
254 | #define EMAC_STACR_PCDA_MASK 0x1f | ||
255 | #define EMAC_STACR_PCDA_SHIFT 5 | ||
256 | #define EMAC_STACR_PRA_MASK 0x1f | ||
257 | #define EMACX_STACR_STAC_MASK 0x00003800 | ||
258 | #define EMACX_STACR_STAC_READ 0x00001000 | ||
259 | #define EMACX_STACR_STAC_WRITE 0x00000800 | ||
260 | #define EMACX_STACR_STAC_IND_ADDR 0x00002000 | ||
261 | #define EMACX_STACR_STAC_IND_READ 0x00003800 | ||
262 | #define EMACX_STACR_STAC_IND_READINC 0x00003000 | ||
263 | #define EMACX_STACR_STAC_IND_WRITE 0x00002800 | ||
264 | |||
265 | |||
266 | /* EMACx_TRTR */ | ||
267 | #define EMAC_TRTR_SHIFT_EMAC4 24 | ||
268 | #define EMAC_TRTR_SHIFT 27 | ||
269 | |||
270 | /* EMAC specific TX descriptor control fields (write access) */ | ||
271 | #define EMAC_TX_CTRL_GFCS 0x0200 | ||
272 | #define EMAC_TX_CTRL_GP 0x0100 | ||
273 | #define EMAC_TX_CTRL_ISA 0x0080 | ||
274 | #define EMAC_TX_CTRL_RSA 0x0040 | ||
275 | #define EMAC_TX_CTRL_IVT 0x0020 | ||
276 | #define EMAC_TX_CTRL_RVT 0x0010 | ||
277 | #define EMAC_TX_CTRL_TAH_CSUM 0x000e | ||
278 | |||
279 | /* EMAC specific TX descriptor status fields (read access) */ | ||
280 | #define EMAC_TX_ST_BFCS 0x0200 | ||
281 | #define EMAC_TX_ST_LCS 0x0080 | ||
282 | #define EMAC_TX_ST_ED 0x0040 | ||
283 | #define EMAC_TX_ST_EC 0x0020 | ||
284 | #define EMAC_TX_ST_LC 0x0010 | ||
285 | #define EMAC_TX_ST_MC 0x0008 | ||
286 | #define EMAC_TX_ST_SC 0x0004 | ||
287 | #define EMAC_TX_ST_UR 0x0002 | ||
288 | #define EMAC_TX_ST_SQE 0x0001 | ||
289 | #define EMAC_IS_BAD_TX (EMAC_TX_ST_LCS | EMAC_TX_ST_ED | \ | ||
290 | EMAC_TX_ST_EC | EMAC_TX_ST_LC | \ | ||
291 | EMAC_TX_ST_MC | EMAC_TX_ST_UR) | ||
292 | #define EMAC_IS_BAD_TX_TAH (EMAC_TX_ST_LCS | EMAC_TX_ST_ED | \ | ||
293 | EMAC_TX_ST_EC | EMAC_TX_ST_LC) | ||
294 | |||
295 | /* EMAC specific RX descriptor status fields (read access) */ | ||
296 | #define EMAC_RX_ST_OE 0x0200 | ||
297 | #define EMAC_RX_ST_PP 0x0100 | ||
298 | #define EMAC_RX_ST_BP 0x0080 | ||
299 | #define EMAC_RX_ST_RP 0x0040 | ||
300 | #define EMAC_RX_ST_SE 0x0020 | ||
301 | #define EMAC_RX_ST_AE 0x0010 | ||
302 | #define EMAC_RX_ST_BFCS 0x0008 | ||
303 | #define EMAC_RX_ST_PTL 0x0004 | ||
304 | #define EMAC_RX_ST_ORE 0x0002 | ||
305 | #define EMAC_RX_ST_IRE 0x0001 | ||
306 | #define EMAC_RX_TAH_BAD_CSUM 0x0003 | ||
307 | #define EMAC_BAD_RX_MASK (EMAC_RX_ST_OE | EMAC_RX_ST_BP | \ | ||
308 | EMAC_RX_ST_RP | EMAC_RX_ST_SE | \ | ||
309 | EMAC_RX_ST_AE | EMAC_RX_ST_BFCS | \ | ||
310 | EMAC_RX_ST_PTL | EMAC_RX_ST_ORE | \ | ||
311 | EMAC_RX_ST_IRE ) | ||
312 | #endif /* __IBM_NEWEMAC_H */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/mal.c b/drivers/net/ethernet/ibm/emac/mal.c new file mode 100644 index 000000000000..d268f404b7b0 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/mal.c | |||
@@ -0,0 +1,809 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/mal.c | ||
3 | * | ||
4 | * Memory Access Layer (MAL) support | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * Based on original work by | ||
15 | * Benjamin Herrenschmidt <benh@kernel.crashing.org>, | ||
16 | * David Gibson <hermes@gibson.dropbear.id.au>, | ||
17 | * | ||
18 | * Armin Kuster <akuster@mvista.com> | ||
19 | * Copyright 2002 MontaVista Softare Inc. | ||
20 | * | ||
21 | * This program is free software; you can redistribute it and/or modify it | ||
22 | * under the terms of the GNU General Public License as published by the | ||
23 | * Free Software Foundation; either version 2 of the License, or (at your | ||
24 | * option) any later version. | ||
25 | * | ||
26 | */ | ||
27 | |||
28 | #include <linux/delay.h> | ||
29 | #include <linux/slab.h> | ||
30 | |||
31 | #include "core.h" | ||
32 | #include <asm/dcr-regs.h> | ||
33 | |||
34 | static int mal_count; | ||
35 | |||
36 | int __devinit mal_register_commac(struct mal_instance *mal, | ||
37 | struct mal_commac *commac) | ||
38 | { | ||
39 | unsigned long flags; | ||
40 | |||
41 | spin_lock_irqsave(&mal->lock, flags); | ||
42 | |||
43 | MAL_DBG(mal, "reg(%08x, %08x)" NL, | ||
44 | commac->tx_chan_mask, commac->rx_chan_mask); | ||
45 | |||
46 | /* Don't let multiple commacs claim the same channel(s) */ | ||
47 | if ((mal->tx_chan_mask & commac->tx_chan_mask) || | ||
48 | (mal->rx_chan_mask & commac->rx_chan_mask)) { | ||
49 | spin_unlock_irqrestore(&mal->lock, flags); | ||
50 | printk(KERN_WARNING "mal%d: COMMAC channels conflict!\n", | ||
51 | mal->index); | ||
52 | return -EBUSY; | ||
53 | } | ||
54 | |||
55 | if (list_empty(&mal->list)) | ||
56 | napi_enable(&mal->napi); | ||
57 | mal->tx_chan_mask |= commac->tx_chan_mask; | ||
58 | mal->rx_chan_mask |= commac->rx_chan_mask; | ||
59 | list_add(&commac->list, &mal->list); | ||
60 | |||
61 | spin_unlock_irqrestore(&mal->lock, flags); | ||
62 | |||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | void mal_unregister_commac(struct mal_instance *mal, | ||
67 | struct mal_commac *commac) | ||
68 | { | ||
69 | unsigned long flags; | ||
70 | |||
71 | spin_lock_irqsave(&mal->lock, flags); | ||
72 | |||
73 | MAL_DBG(mal, "unreg(%08x, %08x)" NL, | ||
74 | commac->tx_chan_mask, commac->rx_chan_mask); | ||
75 | |||
76 | mal->tx_chan_mask &= ~commac->tx_chan_mask; | ||
77 | mal->rx_chan_mask &= ~commac->rx_chan_mask; | ||
78 | list_del_init(&commac->list); | ||
79 | if (list_empty(&mal->list)) | ||
80 | napi_disable(&mal->napi); | ||
81 | |||
82 | spin_unlock_irqrestore(&mal->lock, flags); | ||
83 | } | ||
84 | |||
85 | int mal_set_rcbs(struct mal_instance *mal, int channel, unsigned long size) | ||
86 | { | ||
87 | BUG_ON(channel < 0 || channel >= mal->num_rx_chans || | ||
88 | size > MAL_MAX_RX_SIZE); | ||
89 | |||
90 | MAL_DBG(mal, "set_rbcs(%d, %lu)" NL, channel, size); | ||
91 | |||
92 | if (size & 0xf) { | ||
93 | printk(KERN_WARNING | ||
94 | "mal%d: incorrect RX size %lu for the channel %d\n", | ||
95 | mal->index, size, channel); | ||
96 | return -EINVAL; | ||
97 | } | ||
98 | |||
99 | set_mal_dcrn(mal, MAL_RCBS(channel), size >> 4); | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | int mal_tx_bd_offset(struct mal_instance *mal, int channel) | ||
104 | { | ||
105 | BUG_ON(channel < 0 || channel >= mal->num_tx_chans); | ||
106 | |||
107 | return channel * NUM_TX_BUFF; | ||
108 | } | ||
109 | |||
110 | int mal_rx_bd_offset(struct mal_instance *mal, int channel) | ||
111 | { | ||
112 | BUG_ON(channel < 0 || channel >= mal->num_rx_chans); | ||
113 | return mal->num_tx_chans * NUM_TX_BUFF + channel * NUM_RX_BUFF; | ||
114 | } | ||
115 | |||
116 | void mal_enable_tx_channel(struct mal_instance *mal, int channel) | ||
117 | { | ||
118 | unsigned long flags; | ||
119 | |||
120 | spin_lock_irqsave(&mal->lock, flags); | ||
121 | |||
122 | MAL_DBG(mal, "enable_tx(%d)" NL, channel); | ||
123 | |||
124 | set_mal_dcrn(mal, MAL_TXCASR, | ||
125 | get_mal_dcrn(mal, MAL_TXCASR) | MAL_CHAN_MASK(channel)); | ||
126 | |||
127 | spin_unlock_irqrestore(&mal->lock, flags); | ||
128 | } | ||
129 | |||
130 | void mal_disable_tx_channel(struct mal_instance *mal, int channel) | ||
131 | { | ||
132 | set_mal_dcrn(mal, MAL_TXCARR, MAL_CHAN_MASK(channel)); | ||
133 | |||
134 | MAL_DBG(mal, "disable_tx(%d)" NL, channel); | ||
135 | } | ||
136 | |||
137 | void mal_enable_rx_channel(struct mal_instance *mal, int channel) | ||
138 | { | ||
139 | unsigned long flags; | ||
140 | |||
141 | /* | ||
142 | * On some 4xx PPC's (e.g. 460EX/GT), the rx channel is a multiple | ||
143 | * of 8, but enabling in MAL_RXCASR needs the divided by 8 value | ||
144 | * for the bitmask | ||
145 | */ | ||
146 | if (!(channel % 8)) | ||
147 | channel >>= 3; | ||
148 | |||
149 | spin_lock_irqsave(&mal->lock, flags); | ||
150 | |||
151 | MAL_DBG(mal, "enable_rx(%d)" NL, channel); | ||
152 | |||
153 | set_mal_dcrn(mal, MAL_RXCASR, | ||
154 | get_mal_dcrn(mal, MAL_RXCASR) | MAL_CHAN_MASK(channel)); | ||
155 | |||
156 | spin_unlock_irqrestore(&mal->lock, flags); | ||
157 | } | ||
158 | |||
159 | void mal_disable_rx_channel(struct mal_instance *mal, int channel) | ||
160 | { | ||
161 | /* | ||
162 | * On some 4xx PPC's (e.g. 460EX/GT), the rx channel is a multiple | ||
163 | * of 8, but enabling in MAL_RXCASR needs the divided by 8 value | ||
164 | * for the bitmask | ||
165 | */ | ||
166 | if (!(channel % 8)) | ||
167 | channel >>= 3; | ||
168 | |||
169 | set_mal_dcrn(mal, MAL_RXCARR, MAL_CHAN_MASK(channel)); | ||
170 | |||
171 | MAL_DBG(mal, "disable_rx(%d)" NL, channel); | ||
172 | } | ||
173 | |||
174 | void mal_poll_add(struct mal_instance *mal, struct mal_commac *commac) | ||
175 | { | ||
176 | unsigned long flags; | ||
177 | |||
178 | spin_lock_irqsave(&mal->lock, flags); | ||
179 | |||
180 | MAL_DBG(mal, "poll_add(%p)" NL, commac); | ||
181 | |||
182 | /* starts disabled */ | ||
183 | set_bit(MAL_COMMAC_POLL_DISABLED, &commac->flags); | ||
184 | |||
185 | list_add_tail(&commac->poll_list, &mal->poll_list); | ||
186 | |||
187 | spin_unlock_irqrestore(&mal->lock, flags); | ||
188 | } | ||
189 | |||
190 | void mal_poll_del(struct mal_instance *mal, struct mal_commac *commac) | ||
191 | { | ||
192 | unsigned long flags; | ||
193 | |||
194 | spin_lock_irqsave(&mal->lock, flags); | ||
195 | |||
196 | MAL_DBG(mal, "poll_del(%p)" NL, commac); | ||
197 | |||
198 | list_del(&commac->poll_list); | ||
199 | |||
200 | spin_unlock_irqrestore(&mal->lock, flags); | ||
201 | } | ||
202 | |||
203 | /* synchronized by mal_poll() */ | ||
204 | static inline void mal_enable_eob_irq(struct mal_instance *mal) | ||
205 | { | ||
206 | MAL_DBG2(mal, "enable_irq" NL); | ||
207 | |||
208 | // XXX might want to cache MAL_CFG as the DCR read can be slooooow | ||
209 | set_mal_dcrn(mal, MAL_CFG, get_mal_dcrn(mal, MAL_CFG) | MAL_CFG_EOPIE); | ||
210 | } | ||
211 | |||
212 | /* synchronized by NAPI state */ | ||
213 | static inline void mal_disable_eob_irq(struct mal_instance *mal) | ||
214 | { | ||
215 | // XXX might want to cache MAL_CFG as the DCR read can be slooooow | ||
216 | set_mal_dcrn(mal, MAL_CFG, get_mal_dcrn(mal, MAL_CFG) & ~MAL_CFG_EOPIE); | ||
217 | |||
218 | MAL_DBG2(mal, "disable_irq" NL); | ||
219 | } | ||
220 | |||
221 | static irqreturn_t mal_serr(int irq, void *dev_instance) | ||
222 | { | ||
223 | struct mal_instance *mal = dev_instance; | ||
224 | |||
225 | u32 esr = get_mal_dcrn(mal, MAL_ESR); | ||
226 | |||
227 | /* Clear the error status register */ | ||
228 | set_mal_dcrn(mal, MAL_ESR, esr); | ||
229 | |||
230 | MAL_DBG(mal, "SERR %08x" NL, esr); | ||
231 | |||
232 | if (esr & MAL_ESR_EVB) { | ||
233 | if (esr & MAL_ESR_DE) { | ||
234 | /* We ignore Descriptor error, | ||
235 | * TXDE or RXDE interrupt will be generated anyway. | ||
236 | */ | ||
237 | return IRQ_HANDLED; | ||
238 | } | ||
239 | |||
240 | if (esr & MAL_ESR_PEIN) { | ||
241 | /* PLB error, it's probably buggy hardware or | ||
242 | * incorrect physical address in BD (i.e. bug) | ||
243 | */ | ||
244 | if (net_ratelimit()) | ||
245 | printk(KERN_ERR | ||
246 | "mal%d: system error, " | ||
247 | "PLB (ESR = 0x%08x)\n", | ||
248 | mal->index, esr); | ||
249 | return IRQ_HANDLED; | ||
250 | } | ||
251 | |||
252 | /* OPB error, it's probably buggy hardware or incorrect | ||
253 | * EBC setup | ||
254 | */ | ||
255 | if (net_ratelimit()) | ||
256 | printk(KERN_ERR | ||
257 | "mal%d: system error, OPB (ESR = 0x%08x)\n", | ||
258 | mal->index, esr); | ||
259 | } | ||
260 | return IRQ_HANDLED; | ||
261 | } | ||
262 | |||
263 | static inline void mal_schedule_poll(struct mal_instance *mal) | ||
264 | { | ||
265 | if (likely(napi_schedule_prep(&mal->napi))) { | ||
266 | MAL_DBG2(mal, "schedule_poll" NL); | ||
267 | mal_disable_eob_irq(mal); | ||
268 | __napi_schedule(&mal->napi); | ||
269 | } else | ||
270 | MAL_DBG2(mal, "already in poll" NL); | ||
271 | } | ||
272 | |||
273 | static irqreturn_t mal_txeob(int irq, void *dev_instance) | ||
274 | { | ||
275 | struct mal_instance *mal = dev_instance; | ||
276 | |||
277 | u32 r = get_mal_dcrn(mal, MAL_TXEOBISR); | ||
278 | |||
279 | MAL_DBG2(mal, "txeob %08x" NL, r); | ||
280 | |||
281 | mal_schedule_poll(mal); | ||
282 | set_mal_dcrn(mal, MAL_TXEOBISR, r); | ||
283 | |||
284 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
285 | if (mal_has_feature(mal, MAL_FTR_CLEAR_ICINTSTAT)) | ||
286 | mtdcri(SDR0, DCRN_SDR_ICINTSTAT, | ||
287 | (mfdcri(SDR0, DCRN_SDR_ICINTSTAT) | ICINTSTAT_ICTX)); | ||
288 | #endif | ||
289 | |||
290 | return IRQ_HANDLED; | ||
291 | } | ||
292 | |||
293 | static irqreturn_t mal_rxeob(int irq, void *dev_instance) | ||
294 | { | ||
295 | struct mal_instance *mal = dev_instance; | ||
296 | |||
297 | u32 r = get_mal_dcrn(mal, MAL_RXEOBISR); | ||
298 | |||
299 | MAL_DBG2(mal, "rxeob %08x" NL, r); | ||
300 | |||
301 | mal_schedule_poll(mal); | ||
302 | set_mal_dcrn(mal, MAL_RXEOBISR, r); | ||
303 | |||
304 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
305 | if (mal_has_feature(mal, MAL_FTR_CLEAR_ICINTSTAT)) | ||
306 | mtdcri(SDR0, DCRN_SDR_ICINTSTAT, | ||
307 | (mfdcri(SDR0, DCRN_SDR_ICINTSTAT) | ICINTSTAT_ICRX)); | ||
308 | #endif | ||
309 | |||
310 | return IRQ_HANDLED; | ||
311 | } | ||
312 | |||
313 | static irqreturn_t mal_txde(int irq, void *dev_instance) | ||
314 | { | ||
315 | struct mal_instance *mal = dev_instance; | ||
316 | |||
317 | u32 deir = get_mal_dcrn(mal, MAL_TXDEIR); | ||
318 | set_mal_dcrn(mal, MAL_TXDEIR, deir); | ||
319 | |||
320 | MAL_DBG(mal, "txde %08x" NL, deir); | ||
321 | |||
322 | if (net_ratelimit()) | ||
323 | printk(KERN_ERR | ||
324 | "mal%d: TX descriptor error (TXDEIR = 0x%08x)\n", | ||
325 | mal->index, deir); | ||
326 | |||
327 | return IRQ_HANDLED; | ||
328 | } | ||
329 | |||
330 | static irqreturn_t mal_rxde(int irq, void *dev_instance) | ||
331 | { | ||
332 | struct mal_instance *mal = dev_instance; | ||
333 | struct list_head *l; | ||
334 | |||
335 | u32 deir = get_mal_dcrn(mal, MAL_RXDEIR); | ||
336 | |||
337 | MAL_DBG(mal, "rxde %08x" NL, deir); | ||
338 | |||
339 | list_for_each(l, &mal->list) { | ||
340 | struct mal_commac *mc = list_entry(l, struct mal_commac, list); | ||
341 | if (deir & mc->rx_chan_mask) { | ||
342 | set_bit(MAL_COMMAC_RX_STOPPED, &mc->flags); | ||
343 | mc->ops->rxde(mc->dev); | ||
344 | } | ||
345 | } | ||
346 | |||
347 | mal_schedule_poll(mal); | ||
348 | set_mal_dcrn(mal, MAL_RXDEIR, deir); | ||
349 | |||
350 | return IRQ_HANDLED; | ||
351 | } | ||
352 | |||
353 | static irqreturn_t mal_int(int irq, void *dev_instance) | ||
354 | { | ||
355 | struct mal_instance *mal = dev_instance; | ||
356 | u32 esr = get_mal_dcrn(mal, MAL_ESR); | ||
357 | |||
358 | if (esr & MAL_ESR_EVB) { | ||
359 | /* descriptor error */ | ||
360 | if (esr & MAL_ESR_DE) { | ||
361 | if (esr & MAL_ESR_CIDT) | ||
362 | return mal_rxde(irq, dev_instance); | ||
363 | else | ||
364 | return mal_txde(irq, dev_instance); | ||
365 | } else { /* SERR */ | ||
366 | return mal_serr(irq, dev_instance); | ||
367 | } | ||
368 | } | ||
369 | return IRQ_HANDLED; | ||
370 | } | ||
371 | |||
372 | void mal_poll_disable(struct mal_instance *mal, struct mal_commac *commac) | ||
373 | { | ||
374 | /* Spinlock-type semantics: only one caller disable poll at a time */ | ||
375 | while (test_and_set_bit(MAL_COMMAC_POLL_DISABLED, &commac->flags)) | ||
376 | msleep(1); | ||
377 | |||
378 | /* Synchronize with the MAL NAPI poller */ | ||
379 | napi_synchronize(&mal->napi); | ||
380 | } | ||
381 | |||
382 | void mal_poll_enable(struct mal_instance *mal, struct mal_commac *commac) | ||
383 | { | ||
384 | smp_wmb(); | ||
385 | clear_bit(MAL_COMMAC_POLL_DISABLED, &commac->flags); | ||
386 | |||
387 | /* Feels better to trigger a poll here to catch up with events that | ||
388 | * may have happened on this channel while disabled. It will most | ||
389 | * probably be delayed until the next interrupt but that's mostly a | ||
390 | * non-issue in the context where this is called. | ||
391 | */ | ||
392 | napi_schedule(&mal->napi); | ||
393 | } | ||
394 | |||
395 | static int mal_poll(struct napi_struct *napi, int budget) | ||
396 | { | ||
397 | struct mal_instance *mal = container_of(napi, struct mal_instance, napi); | ||
398 | struct list_head *l; | ||
399 | int received = 0; | ||
400 | unsigned long flags; | ||
401 | |||
402 | MAL_DBG2(mal, "poll(%d)" NL, budget); | ||
403 | again: | ||
404 | /* Process TX skbs */ | ||
405 | list_for_each(l, &mal->poll_list) { | ||
406 | struct mal_commac *mc = | ||
407 | list_entry(l, struct mal_commac, poll_list); | ||
408 | mc->ops->poll_tx(mc->dev); | ||
409 | } | ||
410 | |||
411 | /* Process RX skbs. | ||
412 | * | ||
413 | * We _might_ need something more smart here to enforce polling | ||
414 | * fairness. | ||
415 | */ | ||
416 | list_for_each(l, &mal->poll_list) { | ||
417 | struct mal_commac *mc = | ||
418 | list_entry(l, struct mal_commac, poll_list); | ||
419 | int n; | ||
420 | if (unlikely(test_bit(MAL_COMMAC_POLL_DISABLED, &mc->flags))) | ||
421 | continue; | ||
422 | n = mc->ops->poll_rx(mc->dev, budget); | ||
423 | if (n) { | ||
424 | received += n; | ||
425 | budget -= n; | ||
426 | if (budget <= 0) | ||
427 | goto more_work; // XXX What if this is the last one ? | ||
428 | } | ||
429 | } | ||
430 | |||
431 | /* We need to disable IRQs to protect from RXDE IRQ here */ | ||
432 | spin_lock_irqsave(&mal->lock, flags); | ||
433 | __napi_complete(napi); | ||
434 | mal_enable_eob_irq(mal); | ||
435 | spin_unlock_irqrestore(&mal->lock, flags); | ||
436 | |||
437 | /* Check for "rotting" packet(s) */ | ||
438 | list_for_each(l, &mal->poll_list) { | ||
439 | struct mal_commac *mc = | ||
440 | list_entry(l, struct mal_commac, poll_list); | ||
441 | if (unlikely(test_bit(MAL_COMMAC_POLL_DISABLED, &mc->flags))) | ||
442 | continue; | ||
443 | if (unlikely(mc->ops->peek_rx(mc->dev) || | ||
444 | test_bit(MAL_COMMAC_RX_STOPPED, &mc->flags))) { | ||
445 | MAL_DBG2(mal, "rotting packet" NL); | ||
446 | if (napi_reschedule(napi)) | ||
447 | mal_disable_eob_irq(mal); | ||
448 | else | ||
449 | MAL_DBG2(mal, "already in poll list" NL); | ||
450 | |||
451 | if (budget > 0) | ||
452 | goto again; | ||
453 | else | ||
454 | goto more_work; | ||
455 | } | ||
456 | mc->ops->poll_tx(mc->dev); | ||
457 | } | ||
458 | |||
459 | more_work: | ||
460 | MAL_DBG2(mal, "poll() %d <- %d" NL, budget, received); | ||
461 | return received; | ||
462 | } | ||
463 | |||
464 | static void mal_reset(struct mal_instance *mal) | ||
465 | { | ||
466 | int n = 10; | ||
467 | |||
468 | MAL_DBG(mal, "reset" NL); | ||
469 | |||
470 | set_mal_dcrn(mal, MAL_CFG, MAL_CFG_SR); | ||
471 | |||
472 | /* Wait for reset to complete (1 system clock) */ | ||
473 | while ((get_mal_dcrn(mal, MAL_CFG) & MAL_CFG_SR) && n) | ||
474 | --n; | ||
475 | |||
476 | if (unlikely(!n)) | ||
477 | printk(KERN_ERR "mal%d: reset timeout\n", mal->index); | ||
478 | } | ||
479 | |||
480 | int mal_get_regs_len(struct mal_instance *mal) | ||
481 | { | ||
482 | return sizeof(struct emac_ethtool_regs_subhdr) + | ||
483 | sizeof(struct mal_regs); | ||
484 | } | ||
485 | |||
486 | void *mal_dump_regs(struct mal_instance *mal, void *buf) | ||
487 | { | ||
488 | struct emac_ethtool_regs_subhdr *hdr = buf; | ||
489 | struct mal_regs *regs = (struct mal_regs *)(hdr + 1); | ||
490 | int i; | ||
491 | |||
492 | hdr->version = mal->version; | ||
493 | hdr->index = mal->index; | ||
494 | |||
495 | regs->tx_count = mal->num_tx_chans; | ||
496 | regs->rx_count = mal->num_rx_chans; | ||
497 | |||
498 | regs->cfg = get_mal_dcrn(mal, MAL_CFG); | ||
499 | regs->esr = get_mal_dcrn(mal, MAL_ESR); | ||
500 | regs->ier = get_mal_dcrn(mal, MAL_IER); | ||
501 | regs->tx_casr = get_mal_dcrn(mal, MAL_TXCASR); | ||
502 | regs->tx_carr = get_mal_dcrn(mal, MAL_TXCARR); | ||
503 | regs->tx_eobisr = get_mal_dcrn(mal, MAL_TXEOBISR); | ||
504 | regs->tx_deir = get_mal_dcrn(mal, MAL_TXDEIR); | ||
505 | regs->rx_casr = get_mal_dcrn(mal, MAL_RXCASR); | ||
506 | regs->rx_carr = get_mal_dcrn(mal, MAL_RXCARR); | ||
507 | regs->rx_eobisr = get_mal_dcrn(mal, MAL_RXEOBISR); | ||
508 | regs->rx_deir = get_mal_dcrn(mal, MAL_RXDEIR); | ||
509 | |||
510 | for (i = 0; i < regs->tx_count; ++i) | ||
511 | regs->tx_ctpr[i] = get_mal_dcrn(mal, MAL_TXCTPR(i)); | ||
512 | |||
513 | for (i = 0; i < regs->rx_count; ++i) { | ||
514 | regs->rx_ctpr[i] = get_mal_dcrn(mal, MAL_RXCTPR(i)); | ||
515 | regs->rcbs[i] = get_mal_dcrn(mal, MAL_RCBS(i)); | ||
516 | } | ||
517 | return regs + 1; | ||
518 | } | ||
519 | |||
520 | static int __devinit mal_probe(struct platform_device *ofdev) | ||
521 | { | ||
522 | struct mal_instance *mal; | ||
523 | int err = 0, i, bd_size; | ||
524 | int index = mal_count++; | ||
525 | unsigned int dcr_base; | ||
526 | const u32 *prop; | ||
527 | u32 cfg; | ||
528 | unsigned long irqflags; | ||
529 | irq_handler_t hdlr_serr, hdlr_txde, hdlr_rxde; | ||
530 | |||
531 | mal = kzalloc(sizeof(struct mal_instance), GFP_KERNEL); | ||
532 | if (!mal) { | ||
533 | printk(KERN_ERR | ||
534 | "mal%d: out of memory allocating MAL structure!\n", | ||
535 | index); | ||
536 | return -ENOMEM; | ||
537 | } | ||
538 | mal->index = index; | ||
539 | mal->ofdev = ofdev; | ||
540 | mal->version = of_device_is_compatible(ofdev->dev.of_node, "ibm,mcmal2") ? 2 : 1; | ||
541 | |||
542 | MAL_DBG(mal, "probe" NL); | ||
543 | |||
544 | prop = of_get_property(ofdev->dev.of_node, "num-tx-chans", NULL); | ||
545 | if (prop == NULL) { | ||
546 | printk(KERN_ERR | ||
547 | "mal%d: can't find MAL num-tx-chans property!\n", | ||
548 | index); | ||
549 | err = -ENODEV; | ||
550 | goto fail; | ||
551 | } | ||
552 | mal->num_tx_chans = prop[0]; | ||
553 | |||
554 | prop = of_get_property(ofdev->dev.of_node, "num-rx-chans", NULL); | ||
555 | if (prop == NULL) { | ||
556 | printk(KERN_ERR | ||
557 | "mal%d: can't find MAL num-rx-chans property!\n", | ||
558 | index); | ||
559 | err = -ENODEV; | ||
560 | goto fail; | ||
561 | } | ||
562 | mal->num_rx_chans = prop[0]; | ||
563 | |||
564 | dcr_base = dcr_resource_start(ofdev->dev.of_node, 0); | ||
565 | if (dcr_base == 0) { | ||
566 | printk(KERN_ERR | ||
567 | "mal%d: can't find DCR resource!\n", index); | ||
568 | err = -ENODEV; | ||
569 | goto fail; | ||
570 | } | ||
571 | mal->dcr_host = dcr_map(ofdev->dev.of_node, dcr_base, 0x100); | ||
572 | if (!DCR_MAP_OK(mal->dcr_host)) { | ||
573 | printk(KERN_ERR | ||
574 | "mal%d: failed to map DCRs !\n", index); | ||
575 | err = -ENODEV; | ||
576 | goto fail; | ||
577 | } | ||
578 | |||
579 | if (of_device_is_compatible(ofdev->dev.of_node, "ibm,mcmal-405ez")) { | ||
580 | #if defined(CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT) && \ | ||
581 | defined(CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR) | ||
582 | mal->features |= (MAL_FTR_CLEAR_ICINTSTAT | | ||
583 | MAL_FTR_COMMON_ERR_INT); | ||
584 | #else | ||
585 | printk(KERN_ERR "%s: Support for 405EZ not enabled!\n", | ||
586 | ofdev->dev.of_node->full_name); | ||
587 | err = -ENODEV; | ||
588 | goto fail; | ||
589 | #endif | ||
590 | } | ||
591 | |||
592 | mal->txeob_irq = irq_of_parse_and_map(ofdev->dev.of_node, 0); | ||
593 | mal->rxeob_irq = irq_of_parse_and_map(ofdev->dev.of_node, 1); | ||
594 | mal->serr_irq = irq_of_parse_and_map(ofdev->dev.of_node, 2); | ||
595 | |||
596 | if (mal_has_feature(mal, MAL_FTR_COMMON_ERR_INT)) { | ||
597 | mal->txde_irq = mal->rxde_irq = mal->serr_irq; | ||
598 | } else { | ||
599 | mal->txde_irq = irq_of_parse_and_map(ofdev->dev.of_node, 3); | ||
600 | mal->rxde_irq = irq_of_parse_and_map(ofdev->dev.of_node, 4); | ||
601 | } | ||
602 | |||
603 | if (mal->txeob_irq == NO_IRQ || mal->rxeob_irq == NO_IRQ || | ||
604 | mal->serr_irq == NO_IRQ || mal->txde_irq == NO_IRQ || | ||
605 | mal->rxde_irq == NO_IRQ) { | ||
606 | printk(KERN_ERR | ||
607 | "mal%d: failed to map interrupts !\n", index); | ||
608 | err = -ENODEV; | ||
609 | goto fail_unmap; | ||
610 | } | ||
611 | |||
612 | INIT_LIST_HEAD(&mal->poll_list); | ||
613 | INIT_LIST_HEAD(&mal->list); | ||
614 | spin_lock_init(&mal->lock); | ||
615 | |||
616 | init_dummy_netdev(&mal->dummy_dev); | ||
617 | |||
618 | netif_napi_add(&mal->dummy_dev, &mal->napi, mal_poll, | ||
619 | CONFIG_IBM_NEW_EMAC_POLL_WEIGHT); | ||
620 | |||
621 | /* Load power-on reset defaults */ | ||
622 | mal_reset(mal); | ||
623 | |||
624 | /* Set the MAL configuration register */ | ||
625 | cfg = (mal->version == 2) ? MAL2_CFG_DEFAULT : MAL1_CFG_DEFAULT; | ||
626 | cfg |= MAL_CFG_PLBB | MAL_CFG_OPBBL | MAL_CFG_LEA; | ||
627 | |||
628 | /* Current Axon is not happy with priority being non-0, it can | ||
629 | * deadlock, fix it up here | ||
630 | */ | ||
631 | if (of_device_is_compatible(ofdev->dev.of_node, "ibm,mcmal-axon")) | ||
632 | cfg &= ~(MAL2_CFG_RPP_10 | MAL2_CFG_WPP_10); | ||
633 | |||
634 | /* Apply configuration */ | ||
635 | set_mal_dcrn(mal, MAL_CFG, cfg); | ||
636 | |||
637 | /* Allocate space for BD rings */ | ||
638 | BUG_ON(mal->num_tx_chans <= 0 || mal->num_tx_chans > 32); | ||
639 | BUG_ON(mal->num_rx_chans <= 0 || mal->num_rx_chans > 32); | ||
640 | |||
641 | bd_size = sizeof(struct mal_descriptor) * | ||
642 | (NUM_TX_BUFF * mal->num_tx_chans + | ||
643 | NUM_RX_BUFF * mal->num_rx_chans); | ||
644 | mal->bd_virt = | ||
645 | dma_alloc_coherent(&ofdev->dev, bd_size, &mal->bd_dma, | ||
646 | GFP_KERNEL); | ||
647 | if (mal->bd_virt == NULL) { | ||
648 | printk(KERN_ERR | ||
649 | "mal%d: out of memory allocating RX/TX descriptors!\n", | ||
650 | index); | ||
651 | err = -ENOMEM; | ||
652 | goto fail_unmap; | ||
653 | } | ||
654 | memset(mal->bd_virt, 0, bd_size); | ||
655 | |||
656 | for (i = 0; i < mal->num_tx_chans; ++i) | ||
657 | set_mal_dcrn(mal, MAL_TXCTPR(i), mal->bd_dma + | ||
658 | sizeof(struct mal_descriptor) * | ||
659 | mal_tx_bd_offset(mal, i)); | ||
660 | |||
661 | for (i = 0; i < mal->num_rx_chans; ++i) | ||
662 | set_mal_dcrn(mal, MAL_RXCTPR(i), mal->bd_dma + | ||
663 | sizeof(struct mal_descriptor) * | ||
664 | mal_rx_bd_offset(mal, i)); | ||
665 | |||
666 | if (mal_has_feature(mal, MAL_FTR_COMMON_ERR_INT)) { | ||
667 | irqflags = IRQF_SHARED; | ||
668 | hdlr_serr = hdlr_txde = hdlr_rxde = mal_int; | ||
669 | } else { | ||
670 | irqflags = 0; | ||
671 | hdlr_serr = mal_serr; | ||
672 | hdlr_txde = mal_txde; | ||
673 | hdlr_rxde = mal_rxde; | ||
674 | } | ||
675 | |||
676 | err = request_irq(mal->serr_irq, hdlr_serr, irqflags, "MAL SERR", mal); | ||
677 | if (err) | ||
678 | goto fail2; | ||
679 | err = request_irq(mal->txde_irq, hdlr_txde, irqflags, "MAL TX DE", mal); | ||
680 | if (err) | ||
681 | goto fail3; | ||
682 | err = request_irq(mal->txeob_irq, mal_txeob, 0, "MAL TX EOB", mal); | ||
683 | if (err) | ||
684 | goto fail4; | ||
685 | err = request_irq(mal->rxde_irq, hdlr_rxde, irqflags, "MAL RX DE", mal); | ||
686 | if (err) | ||
687 | goto fail5; | ||
688 | err = request_irq(mal->rxeob_irq, mal_rxeob, 0, "MAL RX EOB", mal); | ||
689 | if (err) | ||
690 | goto fail6; | ||
691 | |||
692 | /* Enable all MAL SERR interrupt sources */ | ||
693 | if (mal->version == 2) | ||
694 | set_mal_dcrn(mal, MAL_IER, MAL2_IER_EVENTS); | ||
695 | else | ||
696 | set_mal_dcrn(mal, MAL_IER, MAL1_IER_EVENTS); | ||
697 | |||
698 | /* Enable EOB interrupt */ | ||
699 | mal_enable_eob_irq(mal); | ||
700 | |||
701 | printk(KERN_INFO | ||
702 | "MAL v%d %s, %d TX channels, %d RX channels\n", | ||
703 | mal->version, ofdev->dev.of_node->full_name, | ||
704 | mal->num_tx_chans, mal->num_rx_chans); | ||
705 | |||
706 | /* Advertise this instance to the rest of the world */ | ||
707 | wmb(); | ||
708 | dev_set_drvdata(&ofdev->dev, mal); | ||
709 | |||
710 | mal_dbg_register(mal); | ||
711 | |||
712 | return 0; | ||
713 | |||
714 | fail6: | ||
715 | free_irq(mal->rxde_irq, mal); | ||
716 | fail5: | ||
717 | free_irq(mal->txeob_irq, mal); | ||
718 | fail4: | ||
719 | free_irq(mal->txde_irq, mal); | ||
720 | fail3: | ||
721 | free_irq(mal->serr_irq, mal); | ||
722 | fail2: | ||
723 | dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma); | ||
724 | fail_unmap: | ||
725 | dcr_unmap(mal->dcr_host, 0x100); | ||
726 | fail: | ||
727 | kfree(mal); | ||
728 | |||
729 | return err; | ||
730 | } | ||
731 | |||
732 | static int __devexit mal_remove(struct platform_device *ofdev) | ||
733 | { | ||
734 | struct mal_instance *mal = dev_get_drvdata(&ofdev->dev); | ||
735 | |||
736 | MAL_DBG(mal, "remove" NL); | ||
737 | |||
738 | /* Synchronize with scheduled polling */ | ||
739 | napi_disable(&mal->napi); | ||
740 | |||
741 | if (!list_empty(&mal->list)) { | ||
742 | /* This is *very* bad */ | ||
743 | printk(KERN_EMERG | ||
744 | "mal%d: commac list is not empty on remove!\n", | ||
745 | mal->index); | ||
746 | WARN_ON(1); | ||
747 | } | ||
748 | |||
749 | dev_set_drvdata(&ofdev->dev, NULL); | ||
750 | |||
751 | free_irq(mal->serr_irq, mal); | ||
752 | free_irq(mal->txde_irq, mal); | ||
753 | free_irq(mal->txeob_irq, mal); | ||
754 | free_irq(mal->rxde_irq, mal); | ||
755 | free_irq(mal->rxeob_irq, mal); | ||
756 | |||
757 | mal_reset(mal); | ||
758 | |||
759 | mal_dbg_unregister(mal); | ||
760 | |||
761 | dma_free_coherent(&ofdev->dev, | ||
762 | sizeof(struct mal_descriptor) * | ||
763 | (NUM_TX_BUFF * mal->num_tx_chans + | ||
764 | NUM_RX_BUFF * mal->num_rx_chans), mal->bd_virt, | ||
765 | mal->bd_dma); | ||
766 | kfree(mal); | ||
767 | |||
768 | return 0; | ||
769 | } | ||
770 | |||
771 | static struct of_device_id mal_platform_match[] = | ||
772 | { | ||
773 | { | ||
774 | .compatible = "ibm,mcmal", | ||
775 | }, | ||
776 | { | ||
777 | .compatible = "ibm,mcmal2", | ||
778 | }, | ||
779 | /* Backward compat */ | ||
780 | { | ||
781 | .type = "mcmal-dma", | ||
782 | .compatible = "ibm,mcmal", | ||
783 | }, | ||
784 | { | ||
785 | .type = "mcmal-dma", | ||
786 | .compatible = "ibm,mcmal2", | ||
787 | }, | ||
788 | {}, | ||
789 | }; | ||
790 | |||
791 | static struct platform_driver mal_of_driver = { | ||
792 | .driver = { | ||
793 | .name = "mcmal", | ||
794 | .owner = THIS_MODULE, | ||
795 | .of_match_table = mal_platform_match, | ||
796 | }, | ||
797 | .probe = mal_probe, | ||
798 | .remove = mal_remove, | ||
799 | }; | ||
800 | |||
801 | int __init mal_init(void) | ||
802 | { | ||
803 | return platform_driver_register(&mal_of_driver); | ||
804 | } | ||
805 | |||
806 | void mal_exit(void) | ||
807 | { | ||
808 | platform_driver_unregister(&mal_of_driver); | ||
809 | } | ||
diff --git a/drivers/net/ethernet/ibm/emac/mal.h b/drivers/net/ethernet/ibm/emac/mal.h new file mode 100644 index 000000000000..66084214bf45 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/mal.h | |||
@@ -0,0 +1,316 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/mal.h | ||
3 | * | ||
4 | * Memory Access Layer (MAL) support | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * Based on original work by | ||
15 | * Armin Kuster <akuster@mvista.com> | ||
16 | * Copyright 2002 MontaVista Softare Inc. | ||
17 | * | ||
18 | * This program is free software; you can redistribute it and/or modify it | ||
19 | * under the terms of the GNU General Public License as published by the | ||
20 | * Free Software Foundation; either version 2 of the License, or (at your | ||
21 | * option) any later version. | ||
22 | * | ||
23 | */ | ||
24 | #ifndef __IBM_NEWEMAC_MAL_H | ||
25 | #define __IBM_NEWEMAC_MAL_H | ||
26 | |||
27 | /* | ||
28 | * There are some variations on the MAL, we express them in this driver as | ||
29 | * MAL Version 1 and 2 though that doesn't match any IBM terminology. | ||
30 | * | ||
31 | * We call MAL 1 the version in 405GP, 405GPR, 405EP, 440EP, 440GR and | ||
32 | * NP405H. | ||
33 | * | ||
34 | * We call MAL 2 the version in 440GP, 440GX, 440SP, 440SPE and Axon | ||
35 | * | ||
36 | * The driver expects a "version" property in the emac node containing | ||
37 | * a number 1 or 2. New device-trees for EMAC capable platforms are thus | ||
38 | * required to include that when porting to arch/powerpc. | ||
39 | */ | ||
40 | |||
41 | /* MALx DCR registers */ | ||
42 | #define MAL_CFG 0x00 | ||
43 | #define MAL_CFG_SR 0x80000000 | ||
44 | #define MAL_CFG_PLBB 0x00004000 | ||
45 | #define MAL_CFG_OPBBL 0x00000080 | ||
46 | #define MAL_CFG_EOPIE 0x00000004 | ||
47 | #define MAL_CFG_LEA 0x00000002 | ||
48 | #define MAL_CFG_SD 0x00000001 | ||
49 | |||
50 | /* MAL V1 CFG bits */ | ||
51 | #define MAL1_CFG_PLBP_MASK 0x00c00000 | ||
52 | #define MAL1_CFG_PLBP_10 0x00800000 | ||
53 | #define MAL1_CFG_GA 0x00200000 | ||
54 | #define MAL1_CFG_OA 0x00100000 | ||
55 | #define MAL1_CFG_PLBLE 0x00080000 | ||
56 | #define MAL1_CFG_PLBT_MASK 0x00078000 | ||
57 | #define MAL1_CFG_DEFAULT (MAL1_CFG_PLBP_10 | MAL1_CFG_PLBT_MASK) | ||
58 | |||
59 | /* MAL V2 CFG bits */ | ||
60 | #define MAL2_CFG_RPP_MASK 0x00c00000 | ||
61 | #define MAL2_CFG_RPP_10 0x00800000 | ||
62 | #define MAL2_CFG_RMBS_MASK 0x00300000 | ||
63 | #define MAL2_CFG_WPP_MASK 0x000c0000 | ||
64 | #define MAL2_CFG_WPP_10 0x00080000 | ||
65 | #define MAL2_CFG_WMBS_MASK 0x00030000 | ||
66 | #define MAL2_CFG_PLBLE 0x00008000 | ||
67 | #define MAL2_CFG_DEFAULT (MAL2_CFG_RMBS_MASK | MAL2_CFG_WMBS_MASK | \ | ||
68 | MAL2_CFG_RPP_10 | MAL2_CFG_WPP_10) | ||
69 | |||
70 | #define MAL_ESR 0x01 | ||
71 | #define MAL_ESR_EVB 0x80000000 | ||
72 | #define MAL_ESR_CIDT 0x40000000 | ||
73 | #define MAL_ESR_CID_MASK 0x3e000000 | ||
74 | #define MAL_ESR_CID_SHIFT 25 | ||
75 | #define MAL_ESR_DE 0x00100000 | ||
76 | #define MAL_ESR_OTE 0x00040000 | ||
77 | #define MAL_ESR_OSE 0x00020000 | ||
78 | #define MAL_ESR_PEIN 0x00010000 | ||
79 | #define MAL_ESR_DEI 0x00000010 | ||
80 | #define MAL_ESR_OTEI 0x00000004 | ||
81 | #define MAL_ESR_OSEI 0x00000002 | ||
82 | #define MAL_ESR_PBEI 0x00000001 | ||
83 | |||
84 | /* MAL V1 ESR bits */ | ||
85 | #define MAL1_ESR_ONE 0x00080000 | ||
86 | #define MAL1_ESR_ONEI 0x00000008 | ||
87 | |||
88 | /* MAL V2 ESR bits */ | ||
89 | #define MAL2_ESR_PTE 0x00800000 | ||
90 | #define MAL2_ESR_PRE 0x00400000 | ||
91 | #define MAL2_ESR_PWE 0x00200000 | ||
92 | #define MAL2_ESR_PTEI 0x00000080 | ||
93 | #define MAL2_ESR_PREI 0x00000040 | ||
94 | #define MAL2_ESR_PWEI 0x00000020 | ||
95 | |||
96 | |||
97 | #define MAL_IER 0x02 | ||
98 | #define MAL_IER_DE 0x00000010 | ||
99 | #define MAL_IER_OTE 0x00000004 | ||
100 | #define MAL_IER_OE 0x00000002 | ||
101 | #define MAL_IER_PE 0x00000001 | ||
102 | /* MAL V1 IER bits */ | ||
103 | #define MAL1_IER_NWE 0x00000008 | ||
104 | #define MAL1_IER_SOC_EVENTS MAL1_IER_NWE | ||
105 | #define MAL1_IER_EVENTS (MAL1_IER_SOC_EVENTS | MAL_IER_DE | \ | ||
106 | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE) | ||
107 | |||
108 | /* MAL V2 IER bits */ | ||
109 | #define MAL2_IER_PT 0x00000080 | ||
110 | #define MAL2_IER_PRE 0x00000040 | ||
111 | #define MAL2_IER_PWE 0x00000020 | ||
112 | #define MAL2_IER_SOC_EVENTS (MAL2_IER_PT | MAL2_IER_PRE | MAL2_IER_PWE) | ||
113 | #define MAL2_IER_EVENTS (MAL2_IER_SOC_EVENTS | MAL_IER_DE | \ | ||
114 | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE) | ||
115 | |||
116 | |||
117 | #define MAL_TXCASR 0x04 | ||
118 | #define MAL_TXCARR 0x05 | ||
119 | #define MAL_TXEOBISR 0x06 | ||
120 | #define MAL_TXDEIR 0x07 | ||
121 | #define MAL_RXCASR 0x10 | ||
122 | #define MAL_RXCARR 0x11 | ||
123 | #define MAL_RXEOBISR 0x12 | ||
124 | #define MAL_RXDEIR 0x13 | ||
125 | #define MAL_TXCTPR(n) ((n) + 0x20) | ||
126 | #define MAL_RXCTPR(n) ((n) + 0x40) | ||
127 | #define MAL_RCBS(n) ((n) + 0x60) | ||
128 | |||
129 | /* In reality MAL can handle TX buffers up to 4095 bytes long, | ||
130 | * but this isn't a good round number :) --ebs | ||
131 | */ | ||
132 | #define MAL_MAX_TX_SIZE 4080 | ||
133 | #define MAL_MAX_RX_SIZE 4080 | ||
134 | |||
135 | static inline int mal_rx_size(int len) | ||
136 | { | ||
137 | len = (len + 0xf) & ~0xf; | ||
138 | return len > MAL_MAX_RX_SIZE ? MAL_MAX_RX_SIZE : len; | ||
139 | } | ||
140 | |||
141 | static inline int mal_tx_chunks(int len) | ||
142 | { | ||
143 | return (len + MAL_MAX_TX_SIZE - 1) / MAL_MAX_TX_SIZE; | ||
144 | } | ||
145 | |||
146 | #define MAL_CHAN_MASK(n) (0x80000000 >> (n)) | ||
147 | |||
148 | /* MAL Buffer Descriptor structure */ | ||
149 | struct mal_descriptor { | ||
150 | u16 ctrl; /* MAL / Commac status control bits */ | ||
151 | u16 data_len; /* Max length is 4K-1 (12 bits) */ | ||
152 | u32 data_ptr; /* pointer to actual data buffer */ | ||
153 | }; | ||
154 | |||
155 | /* the following defines are for the MadMAL status and control registers. */ | ||
156 | /* MADMAL transmit and receive status/control bits */ | ||
157 | #define MAL_RX_CTRL_EMPTY 0x8000 | ||
158 | #define MAL_RX_CTRL_WRAP 0x4000 | ||
159 | #define MAL_RX_CTRL_CM 0x2000 | ||
160 | #define MAL_RX_CTRL_LAST 0x1000 | ||
161 | #define MAL_RX_CTRL_FIRST 0x0800 | ||
162 | #define MAL_RX_CTRL_INTR 0x0400 | ||
163 | #define MAL_RX_CTRL_SINGLE (MAL_RX_CTRL_LAST | MAL_RX_CTRL_FIRST) | ||
164 | #define MAL_IS_SINGLE_RX(ctrl) (((ctrl) & MAL_RX_CTRL_SINGLE) == MAL_RX_CTRL_SINGLE) | ||
165 | |||
166 | #define MAL_TX_CTRL_READY 0x8000 | ||
167 | #define MAL_TX_CTRL_WRAP 0x4000 | ||
168 | #define MAL_TX_CTRL_CM 0x2000 | ||
169 | #define MAL_TX_CTRL_LAST 0x1000 | ||
170 | #define MAL_TX_CTRL_INTR 0x0400 | ||
171 | |||
172 | struct mal_commac_ops { | ||
173 | void (*poll_tx) (void *dev); | ||
174 | int (*poll_rx) (void *dev, int budget); | ||
175 | int (*peek_rx) (void *dev); | ||
176 | void (*rxde) (void *dev); | ||
177 | }; | ||
178 | |||
179 | struct mal_commac { | ||
180 | struct mal_commac_ops *ops; | ||
181 | void *dev; | ||
182 | struct list_head poll_list; | ||
183 | long flags; | ||
184 | #define MAL_COMMAC_RX_STOPPED 0 | ||
185 | #define MAL_COMMAC_POLL_DISABLED 1 | ||
186 | u32 tx_chan_mask; | ||
187 | u32 rx_chan_mask; | ||
188 | struct list_head list; | ||
189 | }; | ||
190 | |||
191 | struct mal_instance { | ||
192 | int version; | ||
193 | dcr_host_t dcr_host; | ||
194 | |||
195 | int num_tx_chans; /* Number of TX channels */ | ||
196 | int num_rx_chans; /* Number of RX channels */ | ||
197 | int txeob_irq; /* TX End Of Buffer IRQ */ | ||
198 | int rxeob_irq; /* RX End Of Buffer IRQ */ | ||
199 | int txde_irq; /* TX Descriptor Error IRQ */ | ||
200 | int rxde_irq; /* RX Descriptor Error IRQ */ | ||
201 | int serr_irq; /* MAL System Error IRQ */ | ||
202 | |||
203 | struct list_head poll_list; | ||
204 | struct napi_struct napi; | ||
205 | |||
206 | struct list_head list; | ||
207 | u32 tx_chan_mask; | ||
208 | u32 rx_chan_mask; | ||
209 | |||
210 | dma_addr_t bd_dma; | ||
211 | struct mal_descriptor *bd_virt; | ||
212 | |||
213 | struct platform_device *ofdev; | ||
214 | int index; | ||
215 | spinlock_t lock; | ||
216 | |||
217 | struct net_device dummy_dev; | ||
218 | |||
219 | unsigned int features; | ||
220 | }; | ||
221 | |||
222 | static inline u32 get_mal_dcrn(struct mal_instance *mal, int reg) | ||
223 | { | ||
224 | return dcr_read(mal->dcr_host, reg); | ||
225 | } | ||
226 | |||
227 | static inline void set_mal_dcrn(struct mal_instance *mal, int reg, u32 val) | ||
228 | { | ||
229 | dcr_write(mal->dcr_host, reg, val); | ||
230 | } | ||
231 | |||
232 | /* Features of various MAL implementations */ | ||
233 | |||
234 | /* Set if you have interrupt coalescing and you have to clear the SDR | ||
235 | * register for TXEOB and RXEOB interrupts to work | ||
236 | */ | ||
237 | #define MAL_FTR_CLEAR_ICINTSTAT 0x00000001 | ||
238 | |||
239 | /* Set if your MAL has SERR, TXDE, and RXDE OR'd into a single UIC | ||
240 | * interrupt | ||
241 | */ | ||
242 | #define MAL_FTR_COMMON_ERR_INT 0x00000002 | ||
243 | |||
244 | enum { | ||
245 | MAL_FTRS_ALWAYS = 0, | ||
246 | |||
247 | MAL_FTRS_POSSIBLE = | ||
248 | #ifdef CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT | ||
249 | MAL_FTR_CLEAR_ICINTSTAT | | ||
250 | #endif | ||
251 | #ifdef CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR | ||
252 | MAL_FTR_COMMON_ERR_INT | | ||
253 | #endif | ||
254 | 0, | ||
255 | }; | ||
256 | |||
257 | static inline int mal_has_feature(struct mal_instance *dev, | ||
258 | unsigned long feature) | ||
259 | { | ||
260 | return (MAL_FTRS_ALWAYS & feature) || | ||
261 | (MAL_FTRS_POSSIBLE & dev->features & feature); | ||
262 | } | ||
263 | |||
264 | /* Register MAL devices */ | ||
265 | int mal_init(void); | ||
266 | void mal_exit(void); | ||
267 | |||
268 | int mal_register_commac(struct mal_instance *mal, | ||
269 | struct mal_commac *commac); | ||
270 | void mal_unregister_commac(struct mal_instance *mal, | ||
271 | struct mal_commac *commac); | ||
272 | int mal_set_rcbs(struct mal_instance *mal, int channel, unsigned long size); | ||
273 | |||
274 | /* Returns BD ring offset for a particular channel | ||
275 | (in 'struct mal_descriptor' elements) | ||
276 | */ | ||
277 | int mal_tx_bd_offset(struct mal_instance *mal, int channel); | ||
278 | int mal_rx_bd_offset(struct mal_instance *mal, int channel); | ||
279 | |||
280 | void mal_enable_tx_channel(struct mal_instance *mal, int channel); | ||
281 | void mal_disable_tx_channel(struct mal_instance *mal, int channel); | ||
282 | void mal_enable_rx_channel(struct mal_instance *mal, int channel); | ||
283 | void mal_disable_rx_channel(struct mal_instance *mal, int channel); | ||
284 | |||
285 | void mal_poll_disable(struct mal_instance *mal, struct mal_commac *commac); | ||
286 | void mal_poll_enable(struct mal_instance *mal, struct mal_commac *commac); | ||
287 | |||
288 | /* Add/remove EMAC to/from MAL polling list */ | ||
289 | void mal_poll_add(struct mal_instance *mal, struct mal_commac *commac); | ||
290 | void mal_poll_del(struct mal_instance *mal, struct mal_commac *commac); | ||
291 | |||
292 | /* Ethtool MAL registers */ | ||
293 | struct mal_regs { | ||
294 | u32 tx_count; | ||
295 | u32 rx_count; | ||
296 | |||
297 | u32 cfg; | ||
298 | u32 esr; | ||
299 | u32 ier; | ||
300 | u32 tx_casr; | ||
301 | u32 tx_carr; | ||
302 | u32 tx_eobisr; | ||
303 | u32 tx_deir; | ||
304 | u32 rx_casr; | ||
305 | u32 rx_carr; | ||
306 | u32 rx_eobisr; | ||
307 | u32 rx_deir; | ||
308 | u32 tx_ctpr[32]; | ||
309 | u32 rx_ctpr[32]; | ||
310 | u32 rcbs[32]; | ||
311 | }; | ||
312 | |||
313 | int mal_get_regs_len(struct mal_instance *mal); | ||
314 | void *mal_dump_regs(struct mal_instance *mal, void *buf); | ||
315 | |||
316 | #endif /* __IBM_NEWEMAC_MAL_H */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/phy.c b/drivers/net/ethernet/ibm/emac/phy.c new file mode 100644 index 000000000000..ab4e5969fe65 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/phy.c | |||
@@ -0,0 +1,541 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/phy.c | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, PHY support. | ||
5 | * Borrowed from sungem_phy.c, though I only kept the generic MII | ||
6 | * driver for now. | ||
7 | * | ||
8 | * This file should be shared with other drivers or eventually | ||
9 | * merged as the "low level" part of miilib | ||
10 | * | ||
11 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
12 | * <benh@kernel.crashing.org> | ||
13 | * | ||
14 | * Based on the arch/ppc version of the driver: | ||
15 | * | ||
16 | * (c) 2003, Benjamin Herrenscmidt (benh@kernel.crashing.org) | ||
17 | * (c) 2004-2005, Eugene Surovegin <ebs@ebshome.net> | ||
18 | * | ||
19 | */ | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/types.h> | ||
23 | #include <linux/netdevice.h> | ||
24 | #include <linux/mii.h> | ||
25 | #include <linux/ethtool.h> | ||
26 | #include <linux/delay.h> | ||
27 | |||
28 | #include "emac.h" | ||
29 | #include "phy.h" | ||
30 | |||
31 | #define phy_read _phy_read | ||
32 | #define phy_write _phy_write | ||
33 | |||
34 | static inline int _phy_read(struct mii_phy *phy, int reg) | ||
35 | { | ||
36 | return phy->mdio_read(phy->dev, phy->address, reg); | ||
37 | } | ||
38 | |||
39 | static inline void _phy_write(struct mii_phy *phy, int reg, int val) | ||
40 | { | ||
41 | phy->mdio_write(phy->dev, phy->address, reg, val); | ||
42 | } | ||
43 | |||
44 | static inline int gpcs_phy_read(struct mii_phy *phy, int reg) | ||
45 | { | ||
46 | return phy->mdio_read(phy->dev, phy->gpcs_address, reg); | ||
47 | } | ||
48 | |||
49 | static inline void gpcs_phy_write(struct mii_phy *phy, int reg, int val) | ||
50 | { | ||
51 | phy->mdio_write(phy->dev, phy->gpcs_address, reg, val); | ||
52 | } | ||
53 | |||
54 | int emac_mii_reset_phy(struct mii_phy *phy) | ||
55 | { | ||
56 | int val; | ||
57 | int limit = 10000; | ||
58 | |||
59 | val = phy_read(phy, MII_BMCR); | ||
60 | val &= ~(BMCR_ISOLATE | BMCR_ANENABLE); | ||
61 | val |= BMCR_RESET; | ||
62 | phy_write(phy, MII_BMCR, val); | ||
63 | |||
64 | udelay(300); | ||
65 | |||
66 | while (--limit) { | ||
67 | val = phy_read(phy, MII_BMCR); | ||
68 | if (val >= 0 && (val & BMCR_RESET) == 0) | ||
69 | break; | ||
70 | udelay(10); | ||
71 | } | ||
72 | if ((val & BMCR_ISOLATE) && limit > 0) | ||
73 | phy_write(phy, MII_BMCR, val & ~BMCR_ISOLATE); | ||
74 | |||
75 | return limit <= 0; | ||
76 | } | ||
77 | |||
78 | int emac_mii_reset_gpcs(struct mii_phy *phy) | ||
79 | { | ||
80 | int val; | ||
81 | int limit = 10000; | ||
82 | |||
83 | val = gpcs_phy_read(phy, MII_BMCR); | ||
84 | val &= ~(BMCR_ISOLATE | BMCR_ANENABLE); | ||
85 | val |= BMCR_RESET; | ||
86 | gpcs_phy_write(phy, MII_BMCR, val); | ||
87 | |||
88 | udelay(300); | ||
89 | |||
90 | while (--limit) { | ||
91 | val = gpcs_phy_read(phy, MII_BMCR); | ||
92 | if (val >= 0 && (val & BMCR_RESET) == 0) | ||
93 | break; | ||
94 | udelay(10); | ||
95 | } | ||
96 | if ((val & BMCR_ISOLATE) && limit > 0) | ||
97 | gpcs_phy_write(phy, MII_BMCR, val & ~BMCR_ISOLATE); | ||
98 | |||
99 | if (limit > 0 && phy->mode == PHY_MODE_SGMII) { | ||
100 | /* Configure GPCS interface to recommended setting for SGMII */ | ||
101 | gpcs_phy_write(phy, 0x04, 0x8120); /* AsymPause, FDX */ | ||
102 | gpcs_phy_write(phy, 0x07, 0x2801); /* msg_pg, toggle */ | ||
103 | gpcs_phy_write(phy, 0x00, 0x0140); /* 1Gbps, FDX */ | ||
104 | } | ||
105 | |||
106 | return limit <= 0; | ||
107 | } | ||
108 | |||
109 | static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise) | ||
110 | { | ||
111 | int ctl, adv; | ||
112 | |||
113 | phy->autoneg = AUTONEG_ENABLE; | ||
114 | phy->speed = SPEED_10; | ||
115 | phy->duplex = DUPLEX_HALF; | ||
116 | phy->pause = phy->asym_pause = 0; | ||
117 | phy->advertising = advertise; | ||
118 | |||
119 | ctl = phy_read(phy, MII_BMCR); | ||
120 | if (ctl < 0) | ||
121 | return ctl; | ||
122 | ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE); | ||
123 | |||
124 | /* First clear the PHY */ | ||
125 | phy_write(phy, MII_BMCR, ctl); | ||
126 | |||
127 | /* Setup standard advertise */ | ||
128 | adv = phy_read(phy, MII_ADVERTISE); | ||
129 | if (adv < 0) | ||
130 | return adv; | ||
131 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | | ||
132 | ADVERTISE_PAUSE_ASYM); | ||
133 | if (advertise & ADVERTISED_10baseT_Half) | ||
134 | adv |= ADVERTISE_10HALF; | ||
135 | if (advertise & ADVERTISED_10baseT_Full) | ||
136 | adv |= ADVERTISE_10FULL; | ||
137 | if (advertise & ADVERTISED_100baseT_Half) | ||
138 | adv |= ADVERTISE_100HALF; | ||
139 | if (advertise & ADVERTISED_100baseT_Full) | ||
140 | adv |= ADVERTISE_100FULL; | ||
141 | if (advertise & ADVERTISED_Pause) | ||
142 | adv |= ADVERTISE_PAUSE_CAP; | ||
143 | if (advertise & ADVERTISED_Asym_Pause) | ||
144 | adv |= ADVERTISE_PAUSE_ASYM; | ||
145 | phy_write(phy, MII_ADVERTISE, adv); | ||
146 | |||
147 | if (phy->features & | ||
148 | (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half)) { | ||
149 | adv = phy_read(phy, MII_CTRL1000); | ||
150 | if (adv < 0) | ||
151 | return adv; | ||
152 | adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); | ||
153 | if (advertise & ADVERTISED_1000baseT_Full) | ||
154 | adv |= ADVERTISE_1000FULL; | ||
155 | if (advertise & ADVERTISED_1000baseT_Half) | ||
156 | adv |= ADVERTISE_1000HALF; | ||
157 | phy_write(phy, MII_CTRL1000, adv); | ||
158 | } | ||
159 | |||
160 | /* Start/Restart aneg */ | ||
161 | ctl = phy_read(phy, MII_BMCR); | ||
162 | ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); | ||
163 | phy_write(phy, MII_BMCR, ctl); | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd) | ||
169 | { | ||
170 | int ctl; | ||
171 | |||
172 | phy->autoneg = AUTONEG_DISABLE; | ||
173 | phy->speed = speed; | ||
174 | phy->duplex = fd; | ||
175 | phy->pause = phy->asym_pause = 0; | ||
176 | |||
177 | ctl = phy_read(phy, MII_BMCR); | ||
178 | if (ctl < 0) | ||
179 | return ctl; | ||
180 | ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE); | ||
181 | |||
182 | /* First clear the PHY */ | ||
183 | phy_write(phy, MII_BMCR, ctl | BMCR_RESET); | ||
184 | |||
185 | /* Select speed & duplex */ | ||
186 | switch (speed) { | ||
187 | case SPEED_10: | ||
188 | break; | ||
189 | case SPEED_100: | ||
190 | ctl |= BMCR_SPEED100; | ||
191 | break; | ||
192 | case SPEED_1000: | ||
193 | ctl |= BMCR_SPEED1000; | ||
194 | break; | ||
195 | default: | ||
196 | return -EINVAL; | ||
197 | } | ||
198 | if (fd == DUPLEX_FULL) | ||
199 | ctl |= BMCR_FULLDPLX; | ||
200 | phy_write(phy, MII_BMCR, ctl); | ||
201 | |||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | static int genmii_poll_link(struct mii_phy *phy) | ||
206 | { | ||
207 | int status; | ||
208 | |||
209 | /* Clear latched value with dummy read */ | ||
210 | phy_read(phy, MII_BMSR); | ||
211 | status = phy_read(phy, MII_BMSR); | ||
212 | if (status < 0 || (status & BMSR_LSTATUS) == 0) | ||
213 | return 0; | ||
214 | if (phy->autoneg == AUTONEG_ENABLE && !(status & BMSR_ANEGCOMPLETE)) | ||
215 | return 0; | ||
216 | return 1; | ||
217 | } | ||
218 | |||
219 | static int genmii_read_link(struct mii_phy *phy) | ||
220 | { | ||
221 | if (phy->autoneg == AUTONEG_ENABLE) { | ||
222 | int glpa = 0; | ||
223 | int lpa = phy_read(phy, MII_LPA) & phy_read(phy, MII_ADVERTISE); | ||
224 | if (lpa < 0) | ||
225 | return lpa; | ||
226 | |||
227 | if (phy->features & | ||
228 | (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half)) { | ||
229 | int adv = phy_read(phy, MII_CTRL1000); | ||
230 | glpa = phy_read(phy, MII_STAT1000); | ||
231 | |||
232 | if (glpa < 0 || adv < 0) | ||
233 | return adv; | ||
234 | |||
235 | glpa &= adv << 2; | ||
236 | } | ||
237 | |||
238 | phy->speed = SPEED_10; | ||
239 | phy->duplex = DUPLEX_HALF; | ||
240 | phy->pause = phy->asym_pause = 0; | ||
241 | |||
242 | if (glpa & (LPA_1000FULL | LPA_1000HALF)) { | ||
243 | phy->speed = SPEED_1000; | ||
244 | if (glpa & LPA_1000FULL) | ||
245 | phy->duplex = DUPLEX_FULL; | ||
246 | } else if (lpa & (LPA_100FULL | LPA_100HALF)) { | ||
247 | phy->speed = SPEED_100; | ||
248 | if (lpa & LPA_100FULL) | ||
249 | phy->duplex = DUPLEX_FULL; | ||
250 | } else if (lpa & LPA_10FULL) | ||
251 | phy->duplex = DUPLEX_FULL; | ||
252 | |||
253 | if (phy->duplex == DUPLEX_FULL) { | ||
254 | phy->pause = lpa & LPA_PAUSE_CAP ? 1 : 0; | ||
255 | phy->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0; | ||
256 | } | ||
257 | } else { | ||
258 | int bmcr = phy_read(phy, MII_BMCR); | ||
259 | if (bmcr < 0) | ||
260 | return bmcr; | ||
261 | |||
262 | if (bmcr & BMCR_FULLDPLX) | ||
263 | phy->duplex = DUPLEX_FULL; | ||
264 | else | ||
265 | phy->duplex = DUPLEX_HALF; | ||
266 | if (bmcr & BMCR_SPEED1000) | ||
267 | phy->speed = SPEED_1000; | ||
268 | else if (bmcr & BMCR_SPEED100) | ||
269 | phy->speed = SPEED_100; | ||
270 | else | ||
271 | phy->speed = SPEED_10; | ||
272 | |||
273 | phy->pause = phy->asym_pause = 0; | ||
274 | } | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | /* Generic implementation for most 10/100/1000 PHYs */ | ||
279 | static struct mii_phy_ops generic_phy_ops = { | ||
280 | .setup_aneg = genmii_setup_aneg, | ||
281 | .setup_forced = genmii_setup_forced, | ||
282 | .poll_link = genmii_poll_link, | ||
283 | .read_link = genmii_read_link | ||
284 | }; | ||
285 | |||
286 | static struct mii_phy_def genmii_phy_def = { | ||
287 | .phy_id = 0x00000000, | ||
288 | .phy_id_mask = 0x00000000, | ||
289 | .name = "Generic MII", | ||
290 | .ops = &generic_phy_ops | ||
291 | }; | ||
292 | |||
293 | /* CIS8201 */ | ||
294 | #define MII_CIS8201_10BTCSR 0x16 | ||
295 | #define TENBTCSR_ECHO_DISABLE 0x2000 | ||
296 | #define MII_CIS8201_EPCR 0x17 | ||
297 | #define EPCR_MODE_MASK 0x3000 | ||
298 | #define EPCR_GMII_MODE 0x0000 | ||
299 | #define EPCR_RGMII_MODE 0x1000 | ||
300 | #define EPCR_TBI_MODE 0x2000 | ||
301 | #define EPCR_RTBI_MODE 0x3000 | ||
302 | #define MII_CIS8201_ACSR 0x1c | ||
303 | #define ACSR_PIN_PRIO_SELECT 0x0004 | ||
304 | |||
305 | static int cis8201_init(struct mii_phy *phy) | ||
306 | { | ||
307 | int epcr; | ||
308 | |||
309 | epcr = phy_read(phy, MII_CIS8201_EPCR); | ||
310 | if (epcr < 0) | ||
311 | return epcr; | ||
312 | |||
313 | epcr &= ~EPCR_MODE_MASK; | ||
314 | |||
315 | switch (phy->mode) { | ||
316 | case PHY_MODE_TBI: | ||
317 | epcr |= EPCR_TBI_MODE; | ||
318 | break; | ||
319 | case PHY_MODE_RTBI: | ||
320 | epcr |= EPCR_RTBI_MODE; | ||
321 | break; | ||
322 | case PHY_MODE_GMII: | ||
323 | epcr |= EPCR_GMII_MODE; | ||
324 | break; | ||
325 | case PHY_MODE_RGMII: | ||
326 | default: | ||
327 | epcr |= EPCR_RGMII_MODE; | ||
328 | } | ||
329 | |||
330 | phy_write(phy, MII_CIS8201_EPCR, epcr); | ||
331 | |||
332 | /* MII regs override strap pins */ | ||
333 | phy_write(phy, MII_CIS8201_ACSR, | ||
334 | phy_read(phy, MII_CIS8201_ACSR) | ACSR_PIN_PRIO_SELECT); | ||
335 | |||
336 | /* Disable TX_EN -> CRS echo mode, otherwise 10/HDX doesn't work */ | ||
337 | phy_write(phy, MII_CIS8201_10BTCSR, | ||
338 | phy_read(phy, MII_CIS8201_10BTCSR) | TENBTCSR_ECHO_DISABLE); | ||
339 | |||
340 | return 0; | ||
341 | } | ||
342 | |||
343 | static struct mii_phy_ops cis8201_phy_ops = { | ||
344 | .init = cis8201_init, | ||
345 | .setup_aneg = genmii_setup_aneg, | ||
346 | .setup_forced = genmii_setup_forced, | ||
347 | .poll_link = genmii_poll_link, | ||
348 | .read_link = genmii_read_link | ||
349 | }; | ||
350 | |||
351 | static struct mii_phy_def cis8201_phy_def = { | ||
352 | .phy_id = 0x000fc410, | ||
353 | .phy_id_mask = 0x000ffff0, | ||
354 | .name = "CIS8201 Gigabit Ethernet", | ||
355 | .ops = &cis8201_phy_ops | ||
356 | }; | ||
357 | |||
358 | static struct mii_phy_def bcm5248_phy_def = { | ||
359 | |||
360 | .phy_id = 0x0143bc00, | ||
361 | .phy_id_mask = 0x0ffffff0, | ||
362 | .name = "BCM5248 10/100 SMII Ethernet", | ||
363 | .ops = &generic_phy_ops | ||
364 | }; | ||
365 | |||
366 | static int m88e1111_init(struct mii_phy *phy) | ||
367 | { | ||
368 | pr_debug("%s: Marvell 88E1111 Ethernet\n", __func__); | ||
369 | phy_write(phy, 0x14, 0x0ce3); | ||
370 | phy_write(phy, 0x18, 0x4101); | ||
371 | phy_write(phy, 0x09, 0x0e00); | ||
372 | phy_write(phy, 0x04, 0x01e1); | ||
373 | phy_write(phy, 0x00, 0x9140); | ||
374 | phy_write(phy, 0x00, 0x1140); | ||
375 | |||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | static int m88e1112_init(struct mii_phy *phy) | ||
380 | { | ||
381 | /* | ||
382 | * Marvell 88E1112 PHY needs to have the SGMII MAC | ||
383 | * interace (page 2) properly configured to | ||
384 | * communicate with the 460EX/GT GPCS interface. | ||
385 | */ | ||
386 | |||
387 | u16 reg_short; | ||
388 | |||
389 | pr_debug("%s: Marvell 88E1112 Ethernet\n", __func__); | ||
390 | |||
391 | /* Set access to Page 2 */ | ||
392 | phy_write(phy, 0x16, 0x0002); | ||
393 | |||
394 | phy_write(phy, 0x00, 0x0040); /* 1Gbps */ | ||
395 | reg_short = (u16)(phy_read(phy, 0x1a)); | ||
396 | reg_short |= 0x8000; /* bypass Auto-Negotiation */ | ||
397 | phy_write(phy, 0x1a, reg_short); | ||
398 | emac_mii_reset_phy(phy); /* reset MAC interface */ | ||
399 | |||
400 | /* Reset access to Page 0 */ | ||
401 | phy_write(phy, 0x16, 0x0000); | ||
402 | |||
403 | return 0; | ||
404 | } | ||
405 | |||
406 | static int et1011c_init(struct mii_phy *phy) | ||
407 | { | ||
408 | u16 reg_short; | ||
409 | |||
410 | reg_short = (u16)(phy_read(phy, 0x16)); | ||
411 | reg_short &= ~(0x7); | ||
412 | reg_short |= 0x6; /* RGMII Trace Delay*/ | ||
413 | phy_write(phy, 0x16, reg_short); | ||
414 | |||
415 | reg_short = (u16)(phy_read(phy, 0x17)); | ||
416 | reg_short &= ~(0x40); | ||
417 | phy_write(phy, 0x17, reg_short); | ||
418 | |||
419 | phy_write(phy, 0x1c, 0x74f0); | ||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | static struct mii_phy_ops et1011c_phy_ops = { | ||
424 | .init = et1011c_init, | ||
425 | .setup_aneg = genmii_setup_aneg, | ||
426 | .setup_forced = genmii_setup_forced, | ||
427 | .poll_link = genmii_poll_link, | ||
428 | .read_link = genmii_read_link | ||
429 | }; | ||
430 | |||
431 | static struct mii_phy_def et1011c_phy_def = { | ||
432 | .phy_id = 0x0282f000, | ||
433 | .phy_id_mask = 0x0fffff00, | ||
434 | .name = "ET1011C Gigabit Ethernet", | ||
435 | .ops = &et1011c_phy_ops | ||
436 | }; | ||
437 | |||
438 | |||
439 | |||
440 | |||
441 | |||
442 | static struct mii_phy_ops m88e1111_phy_ops = { | ||
443 | .init = m88e1111_init, | ||
444 | .setup_aneg = genmii_setup_aneg, | ||
445 | .setup_forced = genmii_setup_forced, | ||
446 | .poll_link = genmii_poll_link, | ||
447 | .read_link = genmii_read_link | ||
448 | }; | ||
449 | |||
450 | static struct mii_phy_def m88e1111_phy_def = { | ||
451 | |||
452 | .phy_id = 0x01410CC0, | ||
453 | .phy_id_mask = 0x0ffffff0, | ||
454 | .name = "Marvell 88E1111 Ethernet", | ||
455 | .ops = &m88e1111_phy_ops, | ||
456 | }; | ||
457 | |||
458 | static struct mii_phy_ops m88e1112_phy_ops = { | ||
459 | .init = m88e1112_init, | ||
460 | .setup_aneg = genmii_setup_aneg, | ||
461 | .setup_forced = genmii_setup_forced, | ||
462 | .poll_link = genmii_poll_link, | ||
463 | .read_link = genmii_read_link | ||
464 | }; | ||
465 | |||
466 | static struct mii_phy_def m88e1112_phy_def = { | ||
467 | .phy_id = 0x01410C90, | ||
468 | .phy_id_mask = 0x0ffffff0, | ||
469 | .name = "Marvell 88E1112 Ethernet", | ||
470 | .ops = &m88e1112_phy_ops, | ||
471 | }; | ||
472 | |||
473 | static struct mii_phy_def *mii_phy_table[] = { | ||
474 | &et1011c_phy_def, | ||
475 | &cis8201_phy_def, | ||
476 | &bcm5248_phy_def, | ||
477 | &m88e1111_phy_def, | ||
478 | &m88e1112_phy_def, | ||
479 | &genmii_phy_def, | ||
480 | NULL | ||
481 | }; | ||
482 | |||
483 | int emac_mii_phy_probe(struct mii_phy *phy, int address) | ||
484 | { | ||
485 | struct mii_phy_def *def; | ||
486 | int i; | ||
487 | u32 id; | ||
488 | |||
489 | phy->autoneg = AUTONEG_DISABLE; | ||
490 | phy->advertising = 0; | ||
491 | phy->address = address; | ||
492 | phy->speed = SPEED_10; | ||
493 | phy->duplex = DUPLEX_HALF; | ||
494 | phy->pause = phy->asym_pause = 0; | ||
495 | |||
496 | /* Take PHY out of isolate mode and reset it. */ | ||
497 | if (emac_mii_reset_phy(phy)) | ||
498 | return -ENODEV; | ||
499 | |||
500 | /* Read ID and find matching entry */ | ||
501 | id = (phy_read(phy, MII_PHYSID1) << 16) | phy_read(phy, MII_PHYSID2); | ||
502 | for (i = 0; (def = mii_phy_table[i]) != NULL; i++) | ||
503 | if ((id & def->phy_id_mask) == def->phy_id) | ||
504 | break; | ||
505 | /* Should never be NULL (we have a generic entry), but... */ | ||
506 | if (!def) | ||
507 | return -ENODEV; | ||
508 | |||
509 | phy->def = def; | ||
510 | |||
511 | /* Determine PHY features if needed */ | ||
512 | phy->features = def->features; | ||
513 | if (!phy->features) { | ||
514 | u16 bmsr = phy_read(phy, MII_BMSR); | ||
515 | if (bmsr & BMSR_ANEGCAPABLE) | ||
516 | phy->features |= SUPPORTED_Autoneg; | ||
517 | if (bmsr & BMSR_10HALF) | ||
518 | phy->features |= SUPPORTED_10baseT_Half; | ||
519 | if (bmsr & BMSR_10FULL) | ||
520 | phy->features |= SUPPORTED_10baseT_Full; | ||
521 | if (bmsr & BMSR_100HALF) | ||
522 | phy->features |= SUPPORTED_100baseT_Half; | ||
523 | if (bmsr & BMSR_100FULL) | ||
524 | phy->features |= SUPPORTED_100baseT_Full; | ||
525 | if (bmsr & BMSR_ESTATEN) { | ||
526 | u16 esr = phy_read(phy, MII_ESTATUS); | ||
527 | if (esr & ESTATUS_1000_TFULL) | ||
528 | phy->features |= SUPPORTED_1000baseT_Full; | ||
529 | if (esr & ESTATUS_1000_THALF) | ||
530 | phy->features |= SUPPORTED_1000baseT_Half; | ||
531 | } | ||
532 | phy->features |= SUPPORTED_MII; | ||
533 | } | ||
534 | |||
535 | /* Setup default advertising */ | ||
536 | phy->advertising = phy->features; | ||
537 | |||
538 | return 0; | ||
539 | } | ||
540 | |||
541 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/net/ethernet/ibm/emac/phy.h b/drivers/net/ethernet/ibm/emac/phy.h new file mode 100644 index 000000000000..5d2bf4cbe50b --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/phy.h | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/phy.h | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, PHY support | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Benjamin Herrenschmidt <benh@kernel.crashing.org> | ||
12 | * February 2003 | ||
13 | * | ||
14 | * Minor additions by Eugene Surovegin <ebs@ebshome.net>, 2004 | ||
15 | * | ||
16 | * This program is free software; you can redistribute it and/or modify it | ||
17 | * under the terms of the GNU General Public License as published by the | ||
18 | * Free Software Foundation; either version 2 of the License, or (at your | ||
19 | * option) any later version. | ||
20 | * | ||
21 | * This file basically duplicates sungem_phy.{c,h} with different PHYs | ||
22 | * supported. I'm looking into merging that in a single mii layer more | ||
23 | * flexible than mii.c | ||
24 | */ | ||
25 | |||
26 | #ifndef __IBM_NEWEMAC_PHY_H | ||
27 | #define __IBM_NEWEMAC_PHY_H | ||
28 | |||
29 | struct mii_phy; | ||
30 | |||
31 | /* Operations supported by any kind of PHY */ | ||
32 | struct mii_phy_ops { | ||
33 | int (*init) (struct mii_phy * phy); | ||
34 | int (*suspend) (struct mii_phy * phy, int wol_options); | ||
35 | int (*setup_aneg) (struct mii_phy * phy, u32 advertise); | ||
36 | int (*setup_forced) (struct mii_phy * phy, int speed, int fd); | ||
37 | int (*poll_link) (struct mii_phy * phy); | ||
38 | int (*read_link) (struct mii_phy * phy); | ||
39 | }; | ||
40 | |||
41 | /* Structure used to statically define an mii/gii based PHY */ | ||
42 | struct mii_phy_def { | ||
43 | u32 phy_id; /* Concatenated ID1 << 16 | ID2 */ | ||
44 | u32 phy_id_mask; /* Significant bits */ | ||
45 | u32 features; /* Ethtool SUPPORTED_* defines or | ||
46 | 0 for autodetect */ | ||
47 | int magic_aneg; /* Autoneg does all speed test for us */ | ||
48 | const char *name; | ||
49 | const struct mii_phy_ops *ops; | ||
50 | }; | ||
51 | |||
52 | /* An instance of a PHY, partially borrowed from mii_if_info */ | ||
53 | struct mii_phy { | ||
54 | struct mii_phy_def *def; | ||
55 | u32 advertising; /* Ethtool ADVERTISED_* defines */ | ||
56 | u32 features; /* Copied from mii_phy_def.features | ||
57 | or determined automaticaly */ | ||
58 | int address; /* PHY address */ | ||
59 | int mode; /* PHY mode */ | ||
60 | int gpcs_address; /* GPCS PHY address */ | ||
61 | |||
62 | /* 1: autoneg enabled, 0: disabled */ | ||
63 | int autoneg; | ||
64 | |||
65 | /* forced speed & duplex (no autoneg) | ||
66 | * partner speed & duplex & pause (autoneg) | ||
67 | */ | ||
68 | int speed; | ||
69 | int duplex; | ||
70 | int pause; | ||
71 | int asym_pause; | ||
72 | |||
73 | /* Provided by host chip */ | ||
74 | struct net_device *dev; | ||
75 | int (*mdio_read) (struct net_device * dev, int addr, int reg); | ||
76 | void (*mdio_write) (struct net_device * dev, int addr, int reg, | ||
77 | int val); | ||
78 | }; | ||
79 | |||
80 | /* Pass in a struct mii_phy with dev, mdio_read and mdio_write | ||
81 | * filled, the remaining fields will be filled on return | ||
82 | */ | ||
83 | int emac_mii_phy_probe(struct mii_phy *phy, int address); | ||
84 | int emac_mii_reset_phy(struct mii_phy *phy); | ||
85 | int emac_mii_reset_gpcs(struct mii_phy *phy); | ||
86 | |||
87 | #endif /* __IBM_NEWEMAC_PHY_H */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/rgmii.c b/drivers/net/ethernet/ibm/emac/rgmii.c new file mode 100644 index 000000000000..4fa53f3def64 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/rgmii.c | |||
@@ -0,0 +1,338 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/rgmii.c | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * Based on original work by | ||
15 | * Matt Porter <mporter@kernel.crashing.org> | ||
16 | * Copyright 2004 MontaVista Software, Inc. | ||
17 | * | ||
18 | * This program is free software; you can redistribute it and/or modify it | ||
19 | * under the terms of the GNU General Public License as published by the | ||
20 | * Free Software Foundation; either version 2 of the License, or (at your | ||
21 | * option) any later version. | ||
22 | * | ||
23 | */ | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/ethtool.h> | ||
27 | #include <asm/io.h> | ||
28 | |||
29 | #include "emac.h" | ||
30 | #include "debug.h" | ||
31 | |||
32 | // XXX FIXME: Axon seems to support a subset of the RGMII, we | ||
33 | // thus need to take that into account and possibly change some | ||
34 | // of the bit settings below that don't seem to quite match the | ||
35 | // AXON spec | ||
36 | |||
37 | /* RGMIIx_FER */ | ||
38 | #define RGMII_FER_MASK(idx) (0x7 << ((idx) * 4)) | ||
39 | #define RGMII_FER_RTBI(idx) (0x4 << ((idx) * 4)) | ||
40 | #define RGMII_FER_RGMII(idx) (0x5 << ((idx) * 4)) | ||
41 | #define RGMII_FER_TBI(idx) (0x6 << ((idx) * 4)) | ||
42 | #define RGMII_FER_GMII(idx) (0x7 << ((idx) * 4)) | ||
43 | #define RGMII_FER_MII(idx) RGMII_FER_GMII(idx) | ||
44 | |||
45 | /* RGMIIx_SSR */ | ||
46 | #define RGMII_SSR_MASK(idx) (0x7 << ((idx) * 8)) | ||
47 | #define RGMII_SSR_100(idx) (0x2 << ((idx) * 8)) | ||
48 | #define RGMII_SSR_1000(idx) (0x4 << ((idx) * 8)) | ||
49 | |||
50 | /* RGMII bridge supports only GMII/TBI and RGMII/RTBI PHYs */ | ||
51 | static inline int rgmii_valid_mode(int phy_mode) | ||
52 | { | ||
53 | return phy_mode == PHY_MODE_GMII || | ||
54 | phy_mode == PHY_MODE_MII || | ||
55 | phy_mode == PHY_MODE_RGMII || | ||
56 | phy_mode == PHY_MODE_TBI || | ||
57 | phy_mode == PHY_MODE_RTBI; | ||
58 | } | ||
59 | |||
60 | static inline const char *rgmii_mode_name(int mode) | ||
61 | { | ||
62 | switch (mode) { | ||
63 | case PHY_MODE_RGMII: | ||
64 | return "RGMII"; | ||
65 | case PHY_MODE_TBI: | ||
66 | return "TBI"; | ||
67 | case PHY_MODE_GMII: | ||
68 | return "GMII"; | ||
69 | case PHY_MODE_MII: | ||
70 | return "MII"; | ||
71 | case PHY_MODE_RTBI: | ||
72 | return "RTBI"; | ||
73 | default: | ||
74 | BUG(); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | static inline u32 rgmii_mode_mask(int mode, int input) | ||
79 | { | ||
80 | switch (mode) { | ||
81 | case PHY_MODE_RGMII: | ||
82 | return RGMII_FER_RGMII(input); | ||
83 | case PHY_MODE_TBI: | ||
84 | return RGMII_FER_TBI(input); | ||
85 | case PHY_MODE_GMII: | ||
86 | return RGMII_FER_GMII(input); | ||
87 | case PHY_MODE_MII: | ||
88 | return RGMII_FER_MII(input); | ||
89 | case PHY_MODE_RTBI: | ||
90 | return RGMII_FER_RTBI(input); | ||
91 | default: | ||
92 | BUG(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | int __devinit rgmii_attach(struct platform_device *ofdev, int input, int mode) | ||
97 | { | ||
98 | struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
99 | struct rgmii_regs __iomem *p = dev->base; | ||
100 | |||
101 | RGMII_DBG(dev, "attach(%d)" NL, input); | ||
102 | |||
103 | /* Check if we need to attach to a RGMII */ | ||
104 | if (input < 0 || !rgmii_valid_mode(mode)) { | ||
105 | printk(KERN_ERR "%s: unsupported settings !\n", | ||
106 | ofdev->dev.of_node->full_name); | ||
107 | return -ENODEV; | ||
108 | } | ||
109 | |||
110 | mutex_lock(&dev->lock); | ||
111 | |||
112 | /* Enable this input */ | ||
113 | out_be32(&p->fer, in_be32(&p->fer) | rgmii_mode_mask(mode, input)); | ||
114 | |||
115 | printk(KERN_NOTICE "%s: input %d in %s mode\n", | ||
116 | ofdev->dev.of_node->full_name, input, rgmii_mode_name(mode)); | ||
117 | |||
118 | ++dev->users; | ||
119 | |||
120 | mutex_unlock(&dev->lock); | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | void rgmii_set_speed(struct platform_device *ofdev, int input, int speed) | ||
126 | { | ||
127 | struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
128 | struct rgmii_regs __iomem *p = dev->base; | ||
129 | u32 ssr; | ||
130 | |||
131 | mutex_lock(&dev->lock); | ||
132 | |||
133 | ssr = in_be32(&p->ssr) & ~RGMII_SSR_MASK(input); | ||
134 | |||
135 | RGMII_DBG(dev, "speed(%d, %d)" NL, input, speed); | ||
136 | |||
137 | if (speed == SPEED_1000) | ||
138 | ssr |= RGMII_SSR_1000(input); | ||
139 | else if (speed == SPEED_100) | ||
140 | ssr |= RGMII_SSR_100(input); | ||
141 | |||
142 | out_be32(&p->ssr, ssr); | ||
143 | |||
144 | mutex_unlock(&dev->lock); | ||
145 | } | ||
146 | |||
147 | void rgmii_get_mdio(struct platform_device *ofdev, int input) | ||
148 | { | ||
149 | struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
150 | struct rgmii_regs __iomem *p = dev->base; | ||
151 | u32 fer; | ||
152 | |||
153 | RGMII_DBG2(dev, "get_mdio(%d)" NL, input); | ||
154 | |||
155 | if (!(dev->flags & EMAC_RGMII_FLAG_HAS_MDIO)) | ||
156 | return; | ||
157 | |||
158 | mutex_lock(&dev->lock); | ||
159 | |||
160 | fer = in_be32(&p->fer); | ||
161 | fer |= 0x00080000u >> input; | ||
162 | out_be32(&p->fer, fer); | ||
163 | (void)in_be32(&p->fer); | ||
164 | |||
165 | DBG2(dev, " fer = 0x%08x\n", fer); | ||
166 | } | ||
167 | |||
168 | void rgmii_put_mdio(struct platform_device *ofdev, int input) | ||
169 | { | ||
170 | struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
171 | struct rgmii_regs __iomem *p = dev->base; | ||
172 | u32 fer; | ||
173 | |||
174 | RGMII_DBG2(dev, "put_mdio(%d)" NL, input); | ||
175 | |||
176 | if (!(dev->flags & EMAC_RGMII_FLAG_HAS_MDIO)) | ||
177 | return; | ||
178 | |||
179 | fer = in_be32(&p->fer); | ||
180 | fer &= ~(0x00080000u >> input); | ||
181 | out_be32(&p->fer, fer); | ||
182 | (void)in_be32(&p->fer); | ||
183 | |||
184 | DBG2(dev, " fer = 0x%08x\n", fer); | ||
185 | |||
186 | mutex_unlock(&dev->lock); | ||
187 | } | ||
188 | |||
189 | void rgmii_detach(struct platform_device *ofdev, int input) | ||
190 | { | ||
191 | struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
192 | struct rgmii_regs __iomem *p; | ||
193 | |||
194 | BUG_ON(!dev || dev->users == 0); | ||
195 | p = dev->base; | ||
196 | |||
197 | mutex_lock(&dev->lock); | ||
198 | |||
199 | RGMII_DBG(dev, "detach(%d)" NL, input); | ||
200 | |||
201 | /* Disable this input */ | ||
202 | out_be32(&p->fer, in_be32(&p->fer) & ~RGMII_FER_MASK(input)); | ||
203 | |||
204 | --dev->users; | ||
205 | |||
206 | mutex_unlock(&dev->lock); | ||
207 | } | ||
208 | |||
209 | int rgmii_get_regs_len(struct platform_device *ofdev) | ||
210 | { | ||
211 | return sizeof(struct emac_ethtool_regs_subhdr) + | ||
212 | sizeof(struct rgmii_regs); | ||
213 | } | ||
214 | |||
215 | void *rgmii_dump_regs(struct platform_device *ofdev, void *buf) | ||
216 | { | ||
217 | struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
218 | struct emac_ethtool_regs_subhdr *hdr = buf; | ||
219 | struct rgmii_regs *regs = (struct rgmii_regs *)(hdr + 1); | ||
220 | |||
221 | hdr->version = 0; | ||
222 | hdr->index = 0; /* for now, are there chips with more than one | ||
223 | * rgmii ? if yes, then we'll add a cell_index | ||
224 | * like we do for emac | ||
225 | */ | ||
226 | memcpy_fromio(regs, dev->base, sizeof(struct rgmii_regs)); | ||
227 | return regs + 1; | ||
228 | } | ||
229 | |||
230 | |||
231 | static int __devinit rgmii_probe(struct platform_device *ofdev) | ||
232 | { | ||
233 | struct device_node *np = ofdev->dev.of_node; | ||
234 | struct rgmii_instance *dev; | ||
235 | struct resource regs; | ||
236 | int rc; | ||
237 | |||
238 | rc = -ENOMEM; | ||
239 | dev = kzalloc(sizeof(struct rgmii_instance), GFP_KERNEL); | ||
240 | if (dev == NULL) { | ||
241 | printk(KERN_ERR "%s: could not allocate RGMII device!\n", | ||
242 | np->full_name); | ||
243 | goto err_gone; | ||
244 | } | ||
245 | |||
246 | mutex_init(&dev->lock); | ||
247 | dev->ofdev = ofdev; | ||
248 | |||
249 | rc = -ENXIO; | ||
250 | if (of_address_to_resource(np, 0, ®s)) { | ||
251 | printk(KERN_ERR "%s: Can't get registers address\n", | ||
252 | np->full_name); | ||
253 | goto err_free; | ||
254 | } | ||
255 | |||
256 | rc = -ENOMEM; | ||
257 | dev->base = (struct rgmii_regs __iomem *)ioremap(regs.start, | ||
258 | sizeof(struct rgmii_regs)); | ||
259 | if (dev->base == NULL) { | ||
260 | printk(KERN_ERR "%s: Can't map device registers!\n", | ||
261 | np->full_name); | ||
262 | goto err_free; | ||
263 | } | ||
264 | |||
265 | /* Check for RGMII flags */ | ||
266 | if (of_get_property(ofdev->dev.of_node, "has-mdio", NULL)) | ||
267 | dev->flags |= EMAC_RGMII_FLAG_HAS_MDIO; | ||
268 | |||
269 | /* CAB lacks the right properties, fix this up */ | ||
270 | if (of_device_is_compatible(ofdev->dev.of_node, "ibm,rgmii-axon")) | ||
271 | dev->flags |= EMAC_RGMII_FLAG_HAS_MDIO; | ||
272 | |||
273 | DBG2(dev, " Boot FER = 0x%08x, SSR = 0x%08x\n", | ||
274 | in_be32(&dev->base->fer), in_be32(&dev->base->ssr)); | ||
275 | |||
276 | /* Disable all inputs by default */ | ||
277 | out_be32(&dev->base->fer, 0); | ||
278 | |||
279 | printk(KERN_INFO | ||
280 | "RGMII %s initialized with%s MDIO support\n", | ||
281 | ofdev->dev.of_node->full_name, | ||
282 | (dev->flags & EMAC_RGMII_FLAG_HAS_MDIO) ? "" : "out"); | ||
283 | |||
284 | wmb(); | ||
285 | dev_set_drvdata(&ofdev->dev, dev); | ||
286 | |||
287 | return 0; | ||
288 | |||
289 | err_free: | ||
290 | kfree(dev); | ||
291 | err_gone: | ||
292 | return rc; | ||
293 | } | ||
294 | |||
295 | static int __devexit rgmii_remove(struct platform_device *ofdev) | ||
296 | { | ||
297 | struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
298 | |||
299 | dev_set_drvdata(&ofdev->dev, NULL); | ||
300 | |||
301 | WARN_ON(dev->users != 0); | ||
302 | |||
303 | iounmap(dev->base); | ||
304 | kfree(dev); | ||
305 | |||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | static struct of_device_id rgmii_match[] = | ||
310 | { | ||
311 | { | ||
312 | .compatible = "ibm,rgmii", | ||
313 | }, | ||
314 | { | ||
315 | .type = "emac-rgmii", | ||
316 | }, | ||
317 | {}, | ||
318 | }; | ||
319 | |||
320 | static struct platform_driver rgmii_driver = { | ||
321 | .driver = { | ||
322 | .name = "emac-rgmii", | ||
323 | .owner = THIS_MODULE, | ||
324 | .of_match_table = rgmii_match, | ||
325 | }, | ||
326 | .probe = rgmii_probe, | ||
327 | .remove = rgmii_remove, | ||
328 | }; | ||
329 | |||
330 | int __init rgmii_init(void) | ||
331 | { | ||
332 | return platform_driver_register(&rgmii_driver); | ||
333 | } | ||
334 | |||
335 | void rgmii_exit(void) | ||
336 | { | ||
337 | platform_driver_unregister(&rgmii_driver); | ||
338 | } | ||
diff --git a/drivers/net/ethernet/ibm/emac/rgmii.h b/drivers/net/ethernet/ibm/emac/rgmii.h new file mode 100644 index 000000000000..d69799049865 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/rgmii.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/rgmii.h | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Based on ocp_zmii.h/ibm_emac_zmii.h | ||
12 | * Armin Kuster akuster@mvista.com | ||
13 | * | ||
14 | * Copyright 2004 MontaVista Software, Inc. | ||
15 | * Matt Porter <mporter@kernel.crashing.org> | ||
16 | * | ||
17 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
18 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
19 | * | ||
20 | * This program is free software; you can redistribute it and/or modify it | ||
21 | * under the terms of the GNU General Public License as published by the | ||
22 | * Free Software Foundation; either version 2 of the License, or (at your | ||
23 | * option) any later version. | ||
24 | */ | ||
25 | |||
26 | #ifndef __IBM_NEWEMAC_RGMII_H | ||
27 | #define __IBM_NEWEMAC_RGMII_H | ||
28 | |||
29 | /* RGMII bridge type */ | ||
30 | #define RGMII_STANDARD 0 | ||
31 | #define RGMII_AXON 1 | ||
32 | |||
33 | /* RGMII bridge */ | ||
34 | struct rgmii_regs { | ||
35 | u32 fer; /* Function enable register */ | ||
36 | u32 ssr; /* Speed select register */ | ||
37 | }; | ||
38 | |||
39 | /* RGMII device */ | ||
40 | struct rgmii_instance { | ||
41 | struct rgmii_regs __iomem *base; | ||
42 | |||
43 | /* RGMII bridge flags */ | ||
44 | int flags; | ||
45 | #define EMAC_RGMII_FLAG_HAS_MDIO 0x00000001 | ||
46 | |||
47 | /* Only one EMAC whacks us at a time */ | ||
48 | struct mutex lock; | ||
49 | |||
50 | /* number of EMACs using this RGMII bridge */ | ||
51 | int users; | ||
52 | |||
53 | /* OF device instance */ | ||
54 | struct platform_device *ofdev; | ||
55 | }; | ||
56 | |||
57 | #ifdef CONFIG_IBM_NEW_EMAC_RGMII | ||
58 | |||
59 | extern int rgmii_init(void); | ||
60 | extern void rgmii_exit(void); | ||
61 | extern int rgmii_attach(struct platform_device *ofdev, int input, int mode); | ||
62 | extern void rgmii_detach(struct platform_device *ofdev, int input); | ||
63 | extern void rgmii_get_mdio(struct platform_device *ofdev, int input); | ||
64 | extern void rgmii_put_mdio(struct platform_device *ofdev, int input); | ||
65 | extern void rgmii_set_speed(struct platform_device *ofdev, int input, int speed); | ||
66 | extern int rgmii_get_regs_len(struct platform_device *ofdev); | ||
67 | extern void *rgmii_dump_regs(struct platform_device *ofdev, void *buf); | ||
68 | |||
69 | #else | ||
70 | |||
71 | # define rgmii_init() 0 | ||
72 | # define rgmii_exit() do { } while(0) | ||
73 | # define rgmii_attach(x,y,z) (-ENXIO) | ||
74 | # define rgmii_detach(x,y) do { } while(0) | ||
75 | # define rgmii_get_mdio(o,i) do { } while (0) | ||
76 | # define rgmii_put_mdio(o,i) do { } while (0) | ||
77 | # define rgmii_set_speed(x,y,z) do { } while(0) | ||
78 | # define rgmii_get_regs_len(x) 0 | ||
79 | # define rgmii_dump_regs(x,buf) (buf) | ||
80 | #endif /* !CONFIG_IBM_NEW_EMAC_RGMII */ | ||
81 | |||
82 | #endif /* __IBM_NEWEMAC_RGMII_H */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/tah.c b/drivers/net/ethernet/ibm/emac/tah.c new file mode 100644 index 000000000000..5f51bf7c9dc5 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/tah.c | |||
@@ -0,0 +1,185 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/tah.c | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, TAH support. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright 2004 MontaVista Software, Inc. | ||
12 | * Matt Porter <mporter@kernel.crashing.org> | ||
13 | * | ||
14 | * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net> | ||
15 | * | ||
16 | * This program is free software; you can redistribute it and/or modify it | ||
17 | * under the terms of the GNU General Public License as published by the | ||
18 | * Free Software Foundation; either version 2 of the License, or (at your | ||
19 | * option) any later version. | ||
20 | */ | ||
21 | #include <asm/io.h> | ||
22 | |||
23 | #include "emac.h" | ||
24 | #include "core.h" | ||
25 | |||
26 | int __devinit tah_attach(struct platform_device *ofdev, int channel) | ||
27 | { | ||
28 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
29 | |||
30 | mutex_lock(&dev->lock); | ||
31 | /* Reset has been done at probe() time... nothing else to do for now */ | ||
32 | ++dev->users; | ||
33 | mutex_unlock(&dev->lock); | ||
34 | |||
35 | return 0; | ||
36 | } | ||
37 | |||
38 | void tah_detach(struct platform_device *ofdev, int channel) | ||
39 | { | ||
40 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
41 | |||
42 | mutex_lock(&dev->lock); | ||
43 | --dev->users; | ||
44 | mutex_unlock(&dev->lock); | ||
45 | } | ||
46 | |||
47 | void tah_reset(struct platform_device *ofdev) | ||
48 | { | ||
49 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
50 | struct tah_regs __iomem *p = dev->base; | ||
51 | int n; | ||
52 | |||
53 | /* Reset TAH */ | ||
54 | out_be32(&p->mr, TAH_MR_SR); | ||
55 | n = 100; | ||
56 | while ((in_be32(&p->mr) & TAH_MR_SR) && n) | ||
57 | --n; | ||
58 | |||
59 | if (unlikely(!n)) | ||
60 | printk(KERN_ERR "%s: reset timeout\n", | ||
61 | ofdev->dev.of_node->full_name); | ||
62 | |||
63 | /* 10KB TAH TX FIFO accommodates the max MTU of 9000 */ | ||
64 | out_be32(&p->mr, | ||
65 | TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP | | ||
66 | TAH_MR_DIG); | ||
67 | } | ||
68 | |||
69 | int tah_get_regs_len(struct platform_device *ofdev) | ||
70 | { | ||
71 | return sizeof(struct emac_ethtool_regs_subhdr) + | ||
72 | sizeof(struct tah_regs); | ||
73 | } | ||
74 | |||
75 | void *tah_dump_regs(struct platform_device *ofdev, void *buf) | ||
76 | { | ||
77 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
78 | struct emac_ethtool_regs_subhdr *hdr = buf; | ||
79 | struct tah_regs *regs = (struct tah_regs *)(hdr + 1); | ||
80 | |||
81 | hdr->version = 0; | ||
82 | hdr->index = 0; /* for now, are there chips with more than one | ||
83 | * zmii ? if yes, then we'll add a cell_index | ||
84 | * like we do for emac | ||
85 | */ | ||
86 | memcpy_fromio(regs, dev->base, sizeof(struct tah_regs)); | ||
87 | return regs + 1; | ||
88 | } | ||
89 | |||
90 | static int __devinit tah_probe(struct platform_device *ofdev) | ||
91 | { | ||
92 | struct device_node *np = ofdev->dev.of_node; | ||
93 | struct tah_instance *dev; | ||
94 | struct resource regs; | ||
95 | int rc; | ||
96 | |||
97 | rc = -ENOMEM; | ||
98 | dev = kzalloc(sizeof(struct tah_instance), GFP_KERNEL); | ||
99 | if (dev == NULL) { | ||
100 | printk(KERN_ERR "%s: could not allocate TAH device!\n", | ||
101 | np->full_name); | ||
102 | goto err_gone; | ||
103 | } | ||
104 | |||
105 | mutex_init(&dev->lock); | ||
106 | dev->ofdev = ofdev; | ||
107 | |||
108 | rc = -ENXIO; | ||
109 | if (of_address_to_resource(np, 0, ®s)) { | ||
110 | printk(KERN_ERR "%s: Can't get registers address\n", | ||
111 | np->full_name); | ||
112 | goto err_free; | ||
113 | } | ||
114 | |||
115 | rc = -ENOMEM; | ||
116 | dev->base = (struct tah_regs __iomem *)ioremap(regs.start, | ||
117 | sizeof(struct tah_regs)); | ||
118 | if (dev->base == NULL) { | ||
119 | printk(KERN_ERR "%s: Can't map device registers!\n", | ||
120 | np->full_name); | ||
121 | goto err_free; | ||
122 | } | ||
123 | |||
124 | dev_set_drvdata(&ofdev->dev, dev); | ||
125 | |||
126 | /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */ | ||
127 | tah_reset(ofdev); | ||
128 | |||
129 | printk(KERN_INFO | ||
130 | "TAH %s initialized\n", ofdev->dev.of_node->full_name); | ||
131 | wmb(); | ||
132 | |||
133 | return 0; | ||
134 | |||
135 | err_free: | ||
136 | kfree(dev); | ||
137 | err_gone: | ||
138 | return rc; | ||
139 | } | ||
140 | |||
141 | static int __devexit tah_remove(struct platform_device *ofdev) | ||
142 | { | ||
143 | struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
144 | |||
145 | dev_set_drvdata(&ofdev->dev, NULL); | ||
146 | |||
147 | WARN_ON(dev->users != 0); | ||
148 | |||
149 | iounmap(dev->base); | ||
150 | kfree(dev); | ||
151 | |||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | static struct of_device_id tah_match[] = | ||
156 | { | ||
157 | { | ||
158 | .compatible = "ibm,tah", | ||
159 | }, | ||
160 | /* For backward compat with old DT */ | ||
161 | { | ||
162 | .type = "tah", | ||
163 | }, | ||
164 | {}, | ||
165 | }; | ||
166 | |||
167 | static struct platform_driver tah_driver = { | ||
168 | .driver = { | ||
169 | .name = "emac-tah", | ||
170 | .owner = THIS_MODULE, | ||
171 | .of_match_table = tah_match, | ||
172 | }, | ||
173 | .probe = tah_probe, | ||
174 | .remove = tah_remove, | ||
175 | }; | ||
176 | |||
177 | int __init tah_init(void) | ||
178 | { | ||
179 | return platform_driver_register(&tah_driver); | ||
180 | } | ||
181 | |||
182 | void tah_exit(void) | ||
183 | { | ||
184 | platform_driver_unregister(&tah_driver); | ||
185 | } | ||
diff --git a/drivers/net/ethernet/ibm/emac/tah.h b/drivers/net/ethernet/ibm/emac/tah.h new file mode 100644 index 000000000000..61dbeca006d1 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/tah.h | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/tah.h | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, TAH support. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright 2004 MontaVista Software, Inc. | ||
12 | * Matt Porter <mporter@kernel.crashing.org> | ||
13 | * | ||
14 | * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net> | ||
15 | * | ||
16 | * This program is free software; you can redistribute it and/or modify it | ||
17 | * under the terms of the GNU General Public License as published by the | ||
18 | * Free Software Foundation; either version 2 of the License, or (at your | ||
19 | * option) any later version. | ||
20 | */ | ||
21 | |||
22 | #ifndef __IBM_NEWEMAC_TAH_H | ||
23 | #define __IBM_NEWEMAC_TAH_H | ||
24 | |||
25 | /* TAH */ | ||
26 | struct tah_regs { | ||
27 | u32 revid; | ||
28 | u32 pad[3]; | ||
29 | u32 mr; | ||
30 | u32 ssr0; | ||
31 | u32 ssr1; | ||
32 | u32 ssr2; | ||
33 | u32 ssr3; | ||
34 | u32 ssr4; | ||
35 | u32 ssr5; | ||
36 | u32 tsr; | ||
37 | }; | ||
38 | |||
39 | |||
40 | /* TAH device */ | ||
41 | struct tah_instance { | ||
42 | struct tah_regs __iomem *base; | ||
43 | |||
44 | /* Only one EMAC whacks us at a time */ | ||
45 | struct mutex lock; | ||
46 | |||
47 | /* number of EMACs using this TAH */ | ||
48 | int users; | ||
49 | |||
50 | /* OF device instance */ | ||
51 | struct platform_device *ofdev; | ||
52 | }; | ||
53 | |||
54 | |||
55 | /* TAH engine */ | ||
56 | #define TAH_MR_CVR 0x80000000 | ||
57 | #define TAH_MR_SR 0x40000000 | ||
58 | #define TAH_MR_ST_256 0x01000000 | ||
59 | #define TAH_MR_ST_512 0x02000000 | ||
60 | #define TAH_MR_ST_768 0x03000000 | ||
61 | #define TAH_MR_ST_1024 0x04000000 | ||
62 | #define TAH_MR_ST_1280 0x05000000 | ||
63 | #define TAH_MR_ST_1536 0x06000000 | ||
64 | #define TAH_MR_TFS_16KB 0x00000000 | ||
65 | #define TAH_MR_TFS_2KB 0x00200000 | ||
66 | #define TAH_MR_TFS_4KB 0x00400000 | ||
67 | #define TAH_MR_TFS_6KB 0x00600000 | ||
68 | #define TAH_MR_TFS_8KB 0x00800000 | ||
69 | #define TAH_MR_TFS_10KB 0x00a00000 | ||
70 | #define TAH_MR_DTFP 0x00100000 | ||
71 | #define TAH_MR_DIG 0x00080000 | ||
72 | |||
73 | #ifdef CONFIG_IBM_NEW_EMAC_TAH | ||
74 | |||
75 | extern int tah_init(void); | ||
76 | extern void tah_exit(void); | ||
77 | extern int tah_attach(struct platform_device *ofdev, int channel); | ||
78 | extern void tah_detach(struct platform_device *ofdev, int channel); | ||
79 | extern void tah_reset(struct platform_device *ofdev); | ||
80 | extern int tah_get_regs_len(struct platform_device *ofdev); | ||
81 | extern void *tah_dump_regs(struct platform_device *ofdev, void *buf); | ||
82 | |||
83 | #else | ||
84 | |||
85 | # define tah_init() 0 | ||
86 | # define tah_exit() do { } while(0) | ||
87 | # define tah_attach(x,y) (-ENXIO) | ||
88 | # define tah_detach(x,y) do { } while(0) | ||
89 | # define tah_reset(x) do { } while(0) | ||
90 | # define tah_get_regs_len(x) 0 | ||
91 | # define tah_dump_regs(x,buf) (buf) | ||
92 | |||
93 | #endif /* !CONFIG_IBM_NEW_EMAC_TAH */ | ||
94 | |||
95 | #endif /* __IBM_NEWEMAC_TAH_H */ | ||
diff --git a/drivers/net/ethernet/ibm/emac/zmii.c b/drivers/net/ethernet/ibm/emac/zmii.c new file mode 100644 index 000000000000..97449e786d61 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/zmii.c | |||
@@ -0,0 +1,332 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/zmii.c | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * Based on original work by | ||
15 | * Armin Kuster <akuster@mvista.com> | ||
16 | * Copyright 2001 MontaVista Softare Inc. | ||
17 | * | ||
18 | * This program is free software; you can redistribute it and/or modify it | ||
19 | * under the terms of the GNU General Public License as published by the | ||
20 | * Free Software Foundation; either version 2 of the License, or (at your | ||
21 | * option) any later version. | ||
22 | * | ||
23 | */ | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/ethtool.h> | ||
27 | #include <asm/io.h> | ||
28 | |||
29 | #include "emac.h" | ||
30 | #include "core.h" | ||
31 | |||
32 | /* ZMIIx_FER */ | ||
33 | #define ZMII_FER_MDI(idx) (0x80000000 >> ((idx) * 4)) | ||
34 | #define ZMII_FER_MDI_ALL (ZMII_FER_MDI(0) | ZMII_FER_MDI(1) | \ | ||
35 | ZMII_FER_MDI(2) | ZMII_FER_MDI(3)) | ||
36 | |||
37 | #define ZMII_FER_SMII(idx) (0x40000000 >> ((idx) * 4)) | ||
38 | #define ZMII_FER_RMII(idx) (0x20000000 >> ((idx) * 4)) | ||
39 | #define ZMII_FER_MII(idx) (0x10000000 >> ((idx) * 4)) | ||
40 | |||
41 | /* ZMIIx_SSR */ | ||
42 | #define ZMII_SSR_SCI(idx) (0x40000000 >> ((idx) * 4)) | ||
43 | #define ZMII_SSR_FSS(idx) (0x20000000 >> ((idx) * 4)) | ||
44 | #define ZMII_SSR_SP(idx) (0x10000000 >> ((idx) * 4)) | ||
45 | |||
46 | /* ZMII only supports MII, RMII and SMII | ||
47 | * we also support autodetection for backward compatibility | ||
48 | */ | ||
49 | static inline int zmii_valid_mode(int mode) | ||
50 | { | ||
51 | return mode == PHY_MODE_MII || | ||
52 | mode == PHY_MODE_RMII || | ||
53 | mode == PHY_MODE_SMII || | ||
54 | mode == PHY_MODE_NA; | ||
55 | } | ||
56 | |||
57 | static inline const char *zmii_mode_name(int mode) | ||
58 | { | ||
59 | switch (mode) { | ||
60 | case PHY_MODE_MII: | ||
61 | return "MII"; | ||
62 | case PHY_MODE_RMII: | ||
63 | return "RMII"; | ||
64 | case PHY_MODE_SMII: | ||
65 | return "SMII"; | ||
66 | default: | ||
67 | BUG(); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | static inline u32 zmii_mode_mask(int mode, int input) | ||
72 | { | ||
73 | switch (mode) { | ||
74 | case PHY_MODE_MII: | ||
75 | return ZMII_FER_MII(input); | ||
76 | case PHY_MODE_RMII: | ||
77 | return ZMII_FER_RMII(input); | ||
78 | case PHY_MODE_SMII: | ||
79 | return ZMII_FER_SMII(input); | ||
80 | default: | ||
81 | return 0; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | int __devinit zmii_attach(struct platform_device *ofdev, int input, int *mode) | ||
86 | { | ||
87 | struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
88 | struct zmii_regs __iomem *p = dev->base; | ||
89 | |||
90 | ZMII_DBG(dev, "init(%d, %d)" NL, input, *mode); | ||
91 | |||
92 | if (!zmii_valid_mode(*mode)) { | ||
93 | /* Probably an EMAC connected to RGMII, | ||
94 | * but it still may need ZMII for MDIO so | ||
95 | * we don't fail here. | ||
96 | */ | ||
97 | dev->users++; | ||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | mutex_lock(&dev->lock); | ||
102 | |||
103 | /* Autodetect ZMII mode if not specified. | ||
104 | * This is only for backward compatibility with the old driver. | ||
105 | * Please, always specify PHY mode in your board port to avoid | ||
106 | * any surprises. | ||
107 | */ | ||
108 | if (dev->mode == PHY_MODE_NA) { | ||
109 | if (*mode == PHY_MODE_NA) { | ||
110 | u32 r = dev->fer_save; | ||
111 | |||
112 | ZMII_DBG(dev, "autodetecting mode, FER = 0x%08x" NL, r); | ||
113 | |||
114 | if (r & (ZMII_FER_MII(0) | ZMII_FER_MII(1))) | ||
115 | dev->mode = PHY_MODE_MII; | ||
116 | else if (r & (ZMII_FER_RMII(0) | ZMII_FER_RMII(1))) | ||
117 | dev->mode = PHY_MODE_RMII; | ||
118 | else | ||
119 | dev->mode = PHY_MODE_SMII; | ||
120 | } else | ||
121 | dev->mode = *mode; | ||
122 | |||
123 | printk(KERN_NOTICE "%s: bridge in %s mode\n", | ||
124 | ofdev->dev.of_node->full_name, | ||
125 | zmii_mode_name(dev->mode)); | ||
126 | } else { | ||
127 | /* All inputs must use the same mode */ | ||
128 | if (*mode != PHY_MODE_NA && *mode != dev->mode) { | ||
129 | printk(KERN_ERR | ||
130 | "%s: invalid mode %d specified for input %d\n", | ||
131 | ofdev->dev.of_node->full_name, *mode, input); | ||
132 | mutex_unlock(&dev->lock); | ||
133 | return -EINVAL; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | /* Report back correct PHY mode, | ||
138 | * it may be used during PHY initialization. | ||
139 | */ | ||
140 | *mode = dev->mode; | ||
141 | |||
142 | /* Enable this input */ | ||
143 | out_be32(&p->fer, in_be32(&p->fer) | zmii_mode_mask(dev->mode, input)); | ||
144 | ++dev->users; | ||
145 | |||
146 | mutex_unlock(&dev->lock); | ||
147 | |||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | void zmii_get_mdio(struct platform_device *ofdev, int input) | ||
152 | { | ||
153 | struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
154 | u32 fer; | ||
155 | |||
156 | ZMII_DBG2(dev, "get_mdio(%d)" NL, input); | ||
157 | |||
158 | mutex_lock(&dev->lock); | ||
159 | |||
160 | fer = in_be32(&dev->base->fer) & ~ZMII_FER_MDI_ALL; | ||
161 | out_be32(&dev->base->fer, fer | ZMII_FER_MDI(input)); | ||
162 | } | ||
163 | |||
164 | void zmii_put_mdio(struct platform_device *ofdev, int input) | ||
165 | { | ||
166 | struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
167 | |||
168 | ZMII_DBG2(dev, "put_mdio(%d)" NL, input); | ||
169 | mutex_unlock(&dev->lock); | ||
170 | } | ||
171 | |||
172 | |||
173 | void zmii_set_speed(struct platform_device *ofdev, int input, int speed) | ||
174 | { | ||
175 | struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
176 | u32 ssr; | ||
177 | |||
178 | mutex_lock(&dev->lock); | ||
179 | |||
180 | ssr = in_be32(&dev->base->ssr); | ||
181 | |||
182 | ZMII_DBG(dev, "speed(%d, %d)" NL, input, speed); | ||
183 | |||
184 | if (speed == SPEED_100) | ||
185 | ssr |= ZMII_SSR_SP(input); | ||
186 | else | ||
187 | ssr &= ~ZMII_SSR_SP(input); | ||
188 | |||
189 | out_be32(&dev->base->ssr, ssr); | ||
190 | |||
191 | mutex_unlock(&dev->lock); | ||
192 | } | ||
193 | |||
194 | void zmii_detach(struct platform_device *ofdev, int input) | ||
195 | { | ||
196 | struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
197 | |||
198 | BUG_ON(!dev || dev->users == 0); | ||
199 | |||
200 | mutex_lock(&dev->lock); | ||
201 | |||
202 | ZMII_DBG(dev, "detach(%d)" NL, input); | ||
203 | |||
204 | /* Disable this input */ | ||
205 | out_be32(&dev->base->fer, | ||
206 | in_be32(&dev->base->fer) & ~zmii_mode_mask(dev->mode, input)); | ||
207 | |||
208 | --dev->users; | ||
209 | |||
210 | mutex_unlock(&dev->lock); | ||
211 | } | ||
212 | |||
213 | int zmii_get_regs_len(struct platform_device *ofdev) | ||
214 | { | ||
215 | return sizeof(struct emac_ethtool_regs_subhdr) + | ||
216 | sizeof(struct zmii_regs); | ||
217 | } | ||
218 | |||
219 | void *zmii_dump_regs(struct platform_device *ofdev, void *buf) | ||
220 | { | ||
221 | struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
222 | struct emac_ethtool_regs_subhdr *hdr = buf; | ||
223 | struct zmii_regs *regs = (struct zmii_regs *)(hdr + 1); | ||
224 | |||
225 | hdr->version = 0; | ||
226 | hdr->index = 0; /* for now, are there chips with more than one | ||
227 | * zmii ? if yes, then we'll add a cell_index | ||
228 | * like we do for emac | ||
229 | */ | ||
230 | memcpy_fromio(regs, dev->base, sizeof(struct zmii_regs)); | ||
231 | return regs + 1; | ||
232 | } | ||
233 | |||
234 | static int __devinit zmii_probe(struct platform_device *ofdev) | ||
235 | { | ||
236 | struct device_node *np = ofdev->dev.of_node; | ||
237 | struct zmii_instance *dev; | ||
238 | struct resource regs; | ||
239 | int rc; | ||
240 | |||
241 | rc = -ENOMEM; | ||
242 | dev = kzalloc(sizeof(struct zmii_instance), GFP_KERNEL); | ||
243 | if (dev == NULL) { | ||
244 | printk(KERN_ERR "%s: could not allocate ZMII device!\n", | ||
245 | np->full_name); | ||
246 | goto err_gone; | ||
247 | } | ||
248 | |||
249 | mutex_init(&dev->lock); | ||
250 | dev->ofdev = ofdev; | ||
251 | dev->mode = PHY_MODE_NA; | ||
252 | |||
253 | rc = -ENXIO; | ||
254 | if (of_address_to_resource(np, 0, ®s)) { | ||
255 | printk(KERN_ERR "%s: Can't get registers address\n", | ||
256 | np->full_name); | ||
257 | goto err_free; | ||
258 | } | ||
259 | |||
260 | rc = -ENOMEM; | ||
261 | dev->base = (struct zmii_regs __iomem *)ioremap(regs.start, | ||
262 | sizeof(struct zmii_regs)); | ||
263 | if (dev->base == NULL) { | ||
264 | printk(KERN_ERR "%s: Can't map device registers!\n", | ||
265 | np->full_name); | ||
266 | goto err_free; | ||
267 | } | ||
268 | |||
269 | /* We may need FER value for autodetection later */ | ||
270 | dev->fer_save = in_be32(&dev->base->fer); | ||
271 | |||
272 | /* Disable all inputs by default */ | ||
273 | out_be32(&dev->base->fer, 0); | ||
274 | |||
275 | printk(KERN_INFO | ||
276 | "ZMII %s initialized\n", ofdev->dev.of_node->full_name); | ||
277 | wmb(); | ||
278 | dev_set_drvdata(&ofdev->dev, dev); | ||
279 | |||
280 | return 0; | ||
281 | |||
282 | err_free: | ||
283 | kfree(dev); | ||
284 | err_gone: | ||
285 | return rc; | ||
286 | } | ||
287 | |||
288 | static int __devexit zmii_remove(struct platform_device *ofdev) | ||
289 | { | ||
290 | struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); | ||
291 | |||
292 | dev_set_drvdata(&ofdev->dev, NULL); | ||
293 | |||
294 | WARN_ON(dev->users != 0); | ||
295 | |||
296 | iounmap(dev->base); | ||
297 | kfree(dev); | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | static struct of_device_id zmii_match[] = | ||
303 | { | ||
304 | { | ||
305 | .compatible = "ibm,zmii", | ||
306 | }, | ||
307 | /* For backward compat with old DT */ | ||
308 | { | ||
309 | .type = "emac-zmii", | ||
310 | }, | ||
311 | {}, | ||
312 | }; | ||
313 | |||
314 | static struct platform_driver zmii_driver = { | ||
315 | .driver = { | ||
316 | .name = "emac-zmii", | ||
317 | .owner = THIS_MODULE, | ||
318 | .of_match_table = zmii_match, | ||
319 | }, | ||
320 | .probe = zmii_probe, | ||
321 | .remove = zmii_remove, | ||
322 | }; | ||
323 | |||
324 | int __init zmii_init(void) | ||
325 | { | ||
326 | return platform_driver_register(&zmii_driver); | ||
327 | } | ||
328 | |||
329 | void zmii_exit(void) | ||
330 | { | ||
331 | platform_driver_unregister(&zmii_driver); | ||
332 | } | ||
diff --git a/drivers/net/ethernet/ibm/emac/zmii.h b/drivers/net/ethernet/ibm/emac/zmii.h new file mode 100644 index 000000000000..1333fa2b2781 --- /dev/null +++ b/drivers/net/ethernet/ibm/emac/zmii.h | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | * drivers/net/ibm_newemac/zmii.h | ||
3 | * | ||
4 | * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support. | ||
5 | * | ||
6 | * Copyright 2007 Benjamin Herrenschmidt, IBM Corp. | ||
7 | * <benh@kernel.crashing.org> | ||
8 | * | ||
9 | * Based on the arch/ppc version of the driver: | ||
10 | * | ||
11 | * Copyright (c) 2004, 2005 Zultys Technologies. | ||
12 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> | ||
13 | * | ||
14 | * Based on original work by | ||
15 | * Armin Kuster <akuster@mvista.com> | ||
16 | * Copyright 2001 MontaVista Softare Inc. | ||
17 | * | ||
18 | * This program is free software; you can redistribute it and/or modify it | ||
19 | * under the terms of the GNU General Public License as published by the | ||
20 | * Free Software Foundation; either version 2 of the License, or (at your | ||
21 | * option) any later version. | ||
22 | * | ||
23 | */ | ||
24 | #ifndef __IBM_NEWEMAC_ZMII_H | ||
25 | #define __IBM_NEWEMAC_ZMII_H | ||
26 | |||
27 | /* ZMII bridge registers */ | ||
28 | struct zmii_regs { | ||
29 | u32 fer; /* Function enable reg */ | ||
30 | u32 ssr; /* Speed select reg */ | ||
31 | u32 smiirs; /* SMII status reg */ | ||
32 | }; | ||
33 | |||
34 | /* ZMII device */ | ||
35 | struct zmii_instance { | ||
36 | struct zmii_regs __iomem *base; | ||
37 | |||
38 | /* Only one EMAC whacks us at a time */ | ||
39 | struct mutex lock; | ||
40 | |||
41 | /* subset of PHY_MODE_XXXX */ | ||
42 | int mode; | ||
43 | |||
44 | /* number of EMACs using this ZMII bridge */ | ||
45 | int users; | ||
46 | |||
47 | /* FER value left by firmware */ | ||
48 | u32 fer_save; | ||
49 | |||
50 | /* OF device instance */ | ||
51 | struct platform_device *ofdev; | ||
52 | }; | ||
53 | |||
54 | #ifdef CONFIG_IBM_NEW_EMAC_ZMII | ||
55 | |||
56 | extern int zmii_init(void); | ||
57 | extern void zmii_exit(void); | ||
58 | extern int zmii_attach(struct platform_device *ofdev, int input, int *mode); | ||
59 | extern void zmii_detach(struct platform_device *ofdev, int input); | ||
60 | extern void zmii_get_mdio(struct platform_device *ofdev, int input); | ||
61 | extern void zmii_put_mdio(struct platform_device *ofdev, int input); | ||
62 | extern void zmii_set_speed(struct platform_device *ofdev, int input, int speed); | ||
63 | extern int zmii_get_regs_len(struct platform_device *ocpdev); | ||
64 | extern void *zmii_dump_regs(struct platform_device *ofdev, void *buf); | ||
65 | |||
66 | #else | ||
67 | # define zmii_init() 0 | ||
68 | # define zmii_exit() do { } while(0) | ||
69 | # define zmii_attach(x,y,z) (-ENXIO) | ||
70 | # define zmii_detach(x,y) do { } while(0) | ||
71 | # define zmii_get_mdio(x,y) do { } while(0) | ||
72 | # define zmii_put_mdio(x,y) do { } while(0) | ||
73 | # define zmii_set_speed(x,y,z) do { } while(0) | ||
74 | # define zmii_get_regs_len(x) 0 | ||
75 | # define zmii_dump_regs(x,buf) (buf) | ||
76 | #endif /* !CONFIG_IBM_NEW_EMAC_ZMII */ | ||
77 | |||
78 | #endif /* __IBM_NEWEMAC_ZMII_H */ | ||
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c new file mode 100644 index 000000000000..ba99af05bf62 --- /dev/null +++ b/drivers/net/ethernet/ibm/ibmveth.c | |||
@@ -0,0 +1,1619 @@ | |||
1 | /* | ||
2 | * IBM Power Virtual Ethernet Device Driver | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
17 | * | ||
18 | * Copyright (C) IBM Corporation, 2003, 2010 | ||
19 | * | ||
20 | * Authors: Dave Larson <larson1@us.ibm.com> | ||
21 | * Santiago Leon <santil@linux.vnet.ibm.com> | ||
22 | * Brian King <brking@linux.vnet.ibm.com> | ||
23 | * Robert Jennings <rcj@linux.vnet.ibm.com> | ||
24 | * Anton Blanchard <anton@au.ibm.com> | ||
25 | */ | ||
26 | |||
27 | #include <linux/module.h> | ||
28 | #include <linux/moduleparam.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/errno.h> | ||
31 | #include <linux/dma-mapping.h> | ||
32 | #include <linux/kernel.h> | ||
33 | #include <linux/netdevice.h> | ||
34 | #include <linux/etherdevice.h> | ||
35 | #include <linux/skbuff.h> | ||
36 | #include <linux/init.h> | ||
37 | #include <linux/interrupt.h> | ||
38 | #include <linux/mm.h> | ||
39 | #include <linux/pm.h> | ||
40 | #include <linux/ethtool.h> | ||
41 | #include <linux/in.h> | ||
42 | #include <linux/ip.h> | ||
43 | #include <linux/ipv6.h> | ||
44 | #include <linux/slab.h> | ||
45 | #include <asm/hvcall.h> | ||
46 | #include <linux/atomic.h> | ||
47 | #include <asm/vio.h> | ||
48 | #include <asm/iommu.h> | ||
49 | #include <asm/firmware.h> | ||
50 | |||
51 | #include "ibmveth.h" | ||
52 | |||
53 | static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance); | ||
54 | static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter); | ||
55 | static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev); | ||
56 | |||
57 | static struct kobj_type ktype_veth_pool; | ||
58 | |||
59 | |||
60 | static const char ibmveth_driver_name[] = "ibmveth"; | ||
61 | static const char ibmveth_driver_string[] = "IBM Power Virtual Ethernet Driver"; | ||
62 | #define ibmveth_driver_version "1.04" | ||
63 | |||
64 | MODULE_AUTHOR("Santiago Leon <santil@linux.vnet.ibm.com>"); | ||
65 | MODULE_DESCRIPTION("IBM Power Virtual Ethernet Driver"); | ||
66 | MODULE_LICENSE("GPL"); | ||
67 | MODULE_VERSION(ibmveth_driver_version); | ||
68 | |||
69 | static unsigned int tx_copybreak __read_mostly = 128; | ||
70 | module_param(tx_copybreak, uint, 0644); | ||
71 | MODULE_PARM_DESC(tx_copybreak, | ||
72 | "Maximum size of packet that is copied to a new buffer on transmit"); | ||
73 | |||
74 | static unsigned int rx_copybreak __read_mostly = 128; | ||
75 | module_param(rx_copybreak, uint, 0644); | ||
76 | MODULE_PARM_DESC(rx_copybreak, | ||
77 | "Maximum size of packet that is copied to a new buffer on receive"); | ||
78 | |||
79 | static unsigned int rx_flush __read_mostly = 0; | ||
80 | module_param(rx_flush, uint, 0644); | ||
81 | MODULE_PARM_DESC(rx_flush, "Flush receive buffers before use"); | ||
82 | |||
83 | struct ibmveth_stat { | ||
84 | char name[ETH_GSTRING_LEN]; | ||
85 | int offset; | ||
86 | }; | ||
87 | |||
88 | #define IBMVETH_STAT_OFF(stat) offsetof(struct ibmveth_adapter, stat) | ||
89 | #define IBMVETH_GET_STAT(a, off) *((u64 *)(((unsigned long)(a)) + off)) | ||
90 | |||
91 | struct ibmveth_stat ibmveth_stats[] = { | ||
92 | { "replenish_task_cycles", IBMVETH_STAT_OFF(replenish_task_cycles) }, | ||
93 | { "replenish_no_mem", IBMVETH_STAT_OFF(replenish_no_mem) }, | ||
94 | { "replenish_add_buff_failure", | ||
95 | IBMVETH_STAT_OFF(replenish_add_buff_failure) }, | ||
96 | { "replenish_add_buff_success", | ||
97 | IBMVETH_STAT_OFF(replenish_add_buff_success) }, | ||
98 | { "rx_invalid_buffer", IBMVETH_STAT_OFF(rx_invalid_buffer) }, | ||
99 | { "rx_no_buffer", IBMVETH_STAT_OFF(rx_no_buffer) }, | ||
100 | { "tx_map_failed", IBMVETH_STAT_OFF(tx_map_failed) }, | ||
101 | { "tx_send_failed", IBMVETH_STAT_OFF(tx_send_failed) }, | ||
102 | { "fw_enabled_ipv4_csum", IBMVETH_STAT_OFF(fw_ipv4_csum_support) }, | ||
103 | { "fw_enabled_ipv6_csum", IBMVETH_STAT_OFF(fw_ipv6_csum_support) }, | ||
104 | }; | ||
105 | |||
106 | /* simple methods of getting data from the current rxq entry */ | ||
107 | static inline u32 ibmveth_rxq_flags(struct ibmveth_adapter *adapter) | ||
108 | { | ||
109 | return adapter->rx_queue.queue_addr[adapter->rx_queue.index].flags_off; | ||
110 | } | ||
111 | |||
112 | static inline int ibmveth_rxq_toggle(struct ibmveth_adapter *adapter) | ||
113 | { | ||
114 | return (ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_TOGGLE) >> | ||
115 | IBMVETH_RXQ_TOGGLE_SHIFT; | ||
116 | } | ||
117 | |||
118 | static inline int ibmveth_rxq_pending_buffer(struct ibmveth_adapter *adapter) | ||
119 | { | ||
120 | return ibmveth_rxq_toggle(adapter) == adapter->rx_queue.toggle; | ||
121 | } | ||
122 | |||
123 | static inline int ibmveth_rxq_buffer_valid(struct ibmveth_adapter *adapter) | ||
124 | { | ||
125 | return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_VALID; | ||
126 | } | ||
127 | |||
128 | static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter) | ||
129 | { | ||
130 | return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK; | ||
131 | } | ||
132 | |||
133 | static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter) | ||
134 | { | ||
135 | return adapter->rx_queue.queue_addr[adapter->rx_queue.index].length; | ||
136 | } | ||
137 | |||
138 | static inline int ibmveth_rxq_csum_good(struct ibmveth_adapter *adapter) | ||
139 | { | ||
140 | return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_CSUM_GOOD; | ||
141 | } | ||
142 | |||
143 | /* setup the initial settings for a buffer pool */ | ||
144 | static void ibmveth_init_buffer_pool(struct ibmveth_buff_pool *pool, | ||
145 | u32 pool_index, u32 pool_size, | ||
146 | u32 buff_size, u32 pool_active) | ||
147 | { | ||
148 | pool->size = pool_size; | ||
149 | pool->index = pool_index; | ||
150 | pool->buff_size = buff_size; | ||
151 | pool->threshold = pool_size * 7 / 8; | ||
152 | pool->active = pool_active; | ||
153 | } | ||
154 | |||
155 | /* allocate and setup an buffer pool - called during open */ | ||
156 | static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool) | ||
157 | { | ||
158 | int i; | ||
159 | |||
160 | pool->free_map = kmalloc(sizeof(u16) * pool->size, GFP_KERNEL); | ||
161 | |||
162 | if (!pool->free_map) | ||
163 | return -1; | ||
164 | |||
165 | pool->dma_addr = kmalloc(sizeof(dma_addr_t) * pool->size, GFP_KERNEL); | ||
166 | if (!pool->dma_addr) { | ||
167 | kfree(pool->free_map); | ||
168 | pool->free_map = NULL; | ||
169 | return -1; | ||
170 | } | ||
171 | |||
172 | pool->skbuff = kcalloc(pool->size, sizeof(void *), GFP_KERNEL); | ||
173 | |||
174 | if (!pool->skbuff) { | ||
175 | kfree(pool->dma_addr); | ||
176 | pool->dma_addr = NULL; | ||
177 | |||
178 | kfree(pool->free_map); | ||
179 | pool->free_map = NULL; | ||
180 | return -1; | ||
181 | } | ||
182 | |||
183 | memset(pool->dma_addr, 0, sizeof(dma_addr_t) * pool->size); | ||
184 | |||
185 | for (i = 0; i < pool->size; ++i) | ||
186 | pool->free_map[i] = i; | ||
187 | |||
188 | atomic_set(&pool->available, 0); | ||
189 | pool->producer_index = 0; | ||
190 | pool->consumer_index = 0; | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | static inline void ibmveth_flush_buffer(void *addr, unsigned long length) | ||
196 | { | ||
197 | unsigned long offset; | ||
198 | |||
199 | for (offset = 0; offset < length; offset += SMP_CACHE_BYTES) | ||
200 | asm("dcbfl %0,%1" :: "b" (addr), "r" (offset)); | ||
201 | } | ||
202 | |||
203 | /* replenish the buffers for a pool. note that we don't need to | ||
204 | * skb_reserve these since they are used for incoming... | ||
205 | */ | ||
206 | static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, | ||
207 | struct ibmveth_buff_pool *pool) | ||
208 | { | ||
209 | u32 i; | ||
210 | u32 count = pool->size - atomic_read(&pool->available); | ||
211 | u32 buffers_added = 0; | ||
212 | struct sk_buff *skb; | ||
213 | unsigned int free_index, index; | ||
214 | u64 correlator; | ||
215 | unsigned long lpar_rc; | ||
216 | dma_addr_t dma_addr; | ||
217 | |||
218 | mb(); | ||
219 | |||
220 | for (i = 0; i < count; ++i) { | ||
221 | union ibmveth_buf_desc desc; | ||
222 | |||
223 | skb = netdev_alloc_skb(adapter->netdev, pool->buff_size); | ||
224 | |||
225 | if (!skb) { | ||
226 | netdev_dbg(adapter->netdev, | ||
227 | "replenish: unable to allocate skb\n"); | ||
228 | adapter->replenish_no_mem++; | ||
229 | break; | ||
230 | } | ||
231 | |||
232 | free_index = pool->consumer_index; | ||
233 | pool->consumer_index++; | ||
234 | if (pool->consumer_index >= pool->size) | ||
235 | pool->consumer_index = 0; | ||
236 | index = pool->free_map[free_index]; | ||
237 | |||
238 | BUG_ON(index == IBM_VETH_INVALID_MAP); | ||
239 | BUG_ON(pool->skbuff[index] != NULL); | ||
240 | |||
241 | dma_addr = dma_map_single(&adapter->vdev->dev, skb->data, | ||
242 | pool->buff_size, DMA_FROM_DEVICE); | ||
243 | |||
244 | if (dma_mapping_error(&adapter->vdev->dev, dma_addr)) | ||
245 | goto failure; | ||
246 | |||
247 | pool->free_map[free_index] = IBM_VETH_INVALID_MAP; | ||
248 | pool->dma_addr[index] = dma_addr; | ||
249 | pool->skbuff[index] = skb; | ||
250 | |||
251 | correlator = ((u64)pool->index << 32) | index; | ||
252 | *(u64 *)skb->data = correlator; | ||
253 | |||
254 | desc.fields.flags_len = IBMVETH_BUF_VALID | pool->buff_size; | ||
255 | desc.fields.address = dma_addr; | ||
256 | |||
257 | if (rx_flush) { | ||
258 | unsigned int len = min(pool->buff_size, | ||
259 | adapter->netdev->mtu + | ||
260 | IBMVETH_BUFF_OH); | ||
261 | ibmveth_flush_buffer(skb->data, len); | ||
262 | } | ||
263 | lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, | ||
264 | desc.desc); | ||
265 | |||
266 | if (lpar_rc != H_SUCCESS) { | ||
267 | goto failure; | ||
268 | } else { | ||
269 | buffers_added++; | ||
270 | adapter->replenish_add_buff_success++; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | mb(); | ||
275 | atomic_add(buffers_added, &(pool->available)); | ||
276 | return; | ||
277 | |||
278 | failure: | ||
279 | pool->free_map[free_index] = index; | ||
280 | pool->skbuff[index] = NULL; | ||
281 | if (pool->consumer_index == 0) | ||
282 | pool->consumer_index = pool->size - 1; | ||
283 | else | ||
284 | pool->consumer_index--; | ||
285 | if (!dma_mapping_error(&adapter->vdev->dev, dma_addr)) | ||
286 | dma_unmap_single(&adapter->vdev->dev, | ||
287 | pool->dma_addr[index], pool->buff_size, | ||
288 | DMA_FROM_DEVICE); | ||
289 | dev_kfree_skb_any(skb); | ||
290 | adapter->replenish_add_buff_failure++; | ||
291 | |||
292 | mb(); | ||
293 | atomic_add(buffers_added, &(pool->available)); | ||
294 | } | ||
295 | |||
296 | /* replenish routine */ | ||
297 | static void ibmveth_replenish_task(struct ibmveth_adapter *adapter) | ||
298 | { | ||
299 | int i; | ||
300 | |||
301 | adapter->replenish_task_cycles++; | ||
302 | |||
303 | for (i = (IBMVETH_NUM_BUFF_POOLS - 1); i >= 0; i--) { | ||
304 | struct ibmveth_buff_pool *pool = &adapter->rx_buff_pool[i]; | ||
305 | |||
306 | if (pool->active && | ||
307 | (atomic_read(&pool->available) < pool->threshold)) | ||
308 | ibmveth_replenish_buffer_pool(adapter, pool); | ||
309 | } | ||
310 | |||
311 | adapter->rx_no_buffer = *(u64 *)(((char*)adapter->buffer_list_addr) + | ||
312 | 4096 - 8); | ||
313 | } | ||
314 | |||
315 | /* empty and free ana buffer pool - also used to do cleanup in error paths */ | ||
316 | static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, | ||
317 | struct ibmveth_buff_pool *pool) | ||
318 | { | ||
319 | int i; | ||
320 | |||
321 | kfree(pool->free_map); | ||
322 | pool->free_map = NULL; | ||
323 | |||
324 | if (pool->skbuff && pool->dma_addr) { | ||
325 | for (i = 0; i < pool->size; ++i) { | ||
326 | struct sk_buff *skb = pool->skbuff[i]; | ||
327 | if (skb) { | ||
328 | dma_unmap_single(&adapter->vdev->dev, | ||
329 | pool->dma_addr[i], | ||
330 | pool->buff_size, | ||
331 | DMA_FROM_DEVICE); | ||
332 | dev_kfree_skb_any(skb); | ||
333 | pool->skbuff[i] = NULL; | ||
334 | } | ||
335 | } | ||
336 | } | ||
337 | |||
338 | if (pool->dma_addr) { | ||
339 | kfree(pool->dma_addr); | ||
340 | pool->dma_addr = NULL; | ||
341 | } | ||
342 | |||
343 | if (pool->skbuff) { | ||
344 | kfree(pool->skbuff); | ||
345 | pool->skbuff = NULL; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | /* remove a buffer from a pool */ | ||
350 | static void ibmveth_remove_buffer_from_pool(struct ibmveth_adapter *adapter, | ||
351 | u64 correlator) | ||
352 | { | ||
353 | unsigned int pool = correlator >> 32; | ||
354 | unsigned int index = correlator & 0xffffffffUL; | ||
355 | unsigned int free_index; | ||
356 | struct sk_buff *skb; | ||
357 | |||
358 | BUG_ON(pool >= IBMVETH_NUM_BUFF_POOLS); | ||
359 | BUG_ON(index >= adapter->rx_buff_pool[pool].size); | ||
360 | |||
361 | skb = adapter->rx_buff_pool[pool].skbuff[index]; | ||
362 | |||
363 | BUG_ON(skb == NULL); | ||
364 | |||
365 | adapter->rx_buff_pool[pool].skbuff[index] = NULL; | ||
366 | |||
367 | dma_unmap_single(&adapter->vdev->dev, | ||
368 | adapter->rx_buff_pool[pool].dma_addr[index], | ||
369 | adapter->rx_buff_pool[pool].buff_size, | ||
370 | DMA_FROM_DEVICE); | ||
371 | |||
372 | free_index = adapter->rx_buff_pool[pool].producer_index; | ||
373 | adapter->rx_buff_pool[pool].producer_index++; | ||
374 | if (adapter->rx_buff_pool[pool].producer_index >= | ||
375 | adapter->rx_buff_pool[pool].size) | ||
376 | adapter->rx_buff_pool[pool].producer_index = 0; | ||
377 | adapter->rx_buff_pool[pool].free_map[free_index] = index; | ||
378 | |||
379 | mb(); | ||
380 | |||
381 | atomic_dec(&(adapter->rx_buff_pool[pool].available)); | ||
382 | } | ||
383 | |||
384 | /* get the current buffer on the rx queue */ | ||
385 | static inline struct sk_buff *ibmveth_rxq_get_buffer(struct ibmveth_adapter *adapter) | ||
386 | { | ||
387 | u64 correlator = adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator; | ||
388 | unsigned int pool = correlator >> 32; | ||
389 | unsigned int index = correlator & 0xffffffffUL; | ||
390 | |||
391 | BUG_ON(pool >= IBMVETH_NUM_BUFF_POOLS); | ||
392 | BUG_ON(index >= adapter->rx_buff_pool[pool].size); | ||
393 | |||
394 | return adapter->rx_buff_pool[pool].skbuff[index]; | ||
395 | } | ||
396 | |||
397 | /* recycle the current buffer on the rx queue */ | ||
398 | static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter) | ||
399 | { | ||
400 | u32 q_index = adapter->rx_queue.index; | ||
401 | u64 correlator = adapter->rx_queue.queue_addr[q_index].correlator; | ||
402 | unsigned int pool = correlator >> 32; | ||
403 | unsigned int index = correlator & 0xffffffffUL; | ||
404 | union ibmveth_buf_desc desc; | ||
405 | unsigned long lpar_rc; | ||
406 | |||
407 | BUG_ON(pool >= IBMVETH_NUM_BUFF_POOLS); | ||
408 | BUG_ON(index >= adapter->rx_buff_pool[pool].size); | ||
409 | |||
410 | if (!adapter->rx_buff_pool[pool].active) { | ||
411 | ibmveth_rxq_harvest_buffer(adapter); | ||
412 | ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]); | ||
413 | return; | ||
414 | } | ||
415 | |||
416 | desc.fields.flags_len = IBMVETH_BUF_VALID | | ||
417 | adapter->rx_buff_pool[pool].buff_size; | ||
418 | desc.fields.address = adapter->rx_buff_pool[pool].dma_addr[index]; | ||
419 | |||
420 | lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); | ||
421 | |||
422 | if (lpar_rc != H_SUCCESS) { | ||
423 | netdev_dbg(adapter->netdev, "h_add_logical_lan_buffer failed " | ||
424 | "during recycle rc=%ld", lpar_rc); | ||
425 | ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator); | ||
426 | } | ||
427 | |||
428 | if (++adapter->rx_queue.index == adapter->rx_queue.num_slots) { | ||
429 | adapter->rx_queue.index = 0; | ||
430 | adapter->rx_queue.toggle = !adapter->rx_queue.toggle; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter) | ||
435 | { | ||
436 | ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator); | ||
437 | |||
438 | if (++adapter->rx_queue.index == adapter->rx_queue.num_slots) { | ||
439 | adapter->rx_queue.index = 0; | ||
440 | adapter->rx_queue.toggle = !adapter->rx_queue.toggle; | ||
441 | } | ||
442 | } | ||
443 | |||
444 | static void ibmveth_cleanup(struct ibmveth_adapter *adapter) | ||
445 | { | ||
446 | int i; | ||
447 | struct device *dev = &adapter->vdev->dev; | ||
448 | |||
449 | if (adapter->buffer_list_addr != NULL) { | ||
450 | if (!dma_mapping_error(dev, adapter->buffer_list_dma)) { | ||
451 | dma_unmap_single(dev, adapter->buffer_list_dma, 4096, | ||
452 | DMA_BIDIRECTIONAL); | ||
453 | adapter->buffer_list_dma = DMA_ERROR_CODE; | ||
454 | } | ||
455 | free_page((unsigned long)adapter->buffer_list_addr); | ||
456 | adapter->buffer_list_addr = NULL; | ||
457 | } | ||
458 | |||
459 | if (adapter->filter_list_addr != NULL) { | ||
460 | if (!dma_mapping_error(dev, adapter->filter_list_dma)) { | ||
461 | dma_unmap_single(dev, adapter->filter_list_dma, 4096, | ||
462 | DMA_BIDIRECTIONAL); | ||
463 | adapter->filter_list_dma = DMA_ERROR_CODE; | ||
464 | } | ||
465 | free_page((unsigned long)adapter->filter_list_addr); | ||
466 | adapter->filter_list_addr = NULL; | ||
467 | } | ||
468 | |||
469 | if (adapter->rx_queue.queue_addr != NULL) { | ||
470 | if (!dma_mapping_error(dev, adapter->rx_queue.queue_dma)) { | ||
471 | dma_unmap_single(dev, | ||
472 | adapter->rx_queue.queue_dma, | ||
473 | adapter->rx_queue.queue_len, | ||
474 | DMA_BIDIRECTIONAL); | ||
475 | adapter->rx_queue.queue_dma = DMA_ERROR_CODE; | ||
476 | } | ||
477 | kfree(adapter->rx_queue.queue_addr); | ||
478 | adapter->rx_queue.queue_addr = NULL; | ||
479 | } | ||
480 | |||
481 | for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) | ||
482 | if (adapter->rx_buff_pool[i].active) | ||
483 | ibmveth_free_buffer_pool(adapter, | ||
484 | &adapter->rx_buff_pool[i]); | ||
485 | |||
486 | if (adapter->bounce_buffer != NULL) { | ||
487 | if (!dma_mapping_error(dev, adapter->bounce_buffer_dma)) { | ||
488 | dma_unmap_single(&adapter->vdev->dev, | ||
489 | adapter->bounce_buffer_dma, | ||
490 | adapter->netdev->mtu + IBMVETH_BUFF_OH, | ||
491 | DMA_BIDIRECTIONAL); | ||
492 | adapter->bounce_buffer_dma = DMA_ERROR_CODE; | ||
493 | } | ||
494 | kfree(adapter->bounce_buffer); | ||
495 | adapter->bounce_buffer = NULL; | ||
496 | } | ||
497 | } | ||
498 | |||
499 | static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter, | ||
500 | union ibmveth_buf_desc rxq_desc, u64 mac_address) | ||
501 | { | ||
502 | int rc, try_again = 1; | ||
503 | |||
504 | /* | ||
505 | * After a kexec the adapter will still be open, so our attempt to | ||
506 | * open it will fail. So if we get a failure we free the adapter and | ||
507 | * try again, but only once. | ||
508 | */ | ||
509 | retry: | ||
510 | rc = h_register_logical_lan(adapter->vdev->unit_address, | ||
511 | adapter->buffer_list_dma, rxq_desc.desc, | ||
512 | adapter->filter_list_dma, mac_address); | ||
513 | |||
514 | if (rc != H_SUCCESS && try_again) { | ||
515 | do { | ||
516 | rc = h_free_logical_lan(adapter->vdev->unit_address); | ||
517 | } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY)); | ||
518 | |||
519 | try_again = 0; | ||
520 | goto retry; | ||
521 | } | ||
522 | |||
523 | return rc; | ||
524 | } | ||
525 | |||
526 | static int ibmveth_open(struct net_device *netdev) | ||
527 | { | ||
528 | struct ibmveth_adapter *adapter = netdev_priv(netdev); | ||
529 | u64 mac_address = 0; | ||
530 | int rxq_entries = 1; | ||
531 | unsigned long lpar_rc; | ||
532 | int rc; | ||
533 | union ibmveth_buf_desc rxq_desc; | ||
534 | int i; | ||
535 | struct device *dev; | ||
536 | |||
537 | netdev_dbg(netdev, "open starting\n"); | ||
538 | |||
539 | napi_enable(&adapter->napi); | ||
540 | |||
541 | for(i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) | ||
542 | rxq_entries += adapter->rx_buff_pool[i].size; | ||
543 | |||
544 | adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL); | ||
545 | adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL); | ||
546 | |||
547 | if (!adapter->buffer_list_addr || !adapter->filter_list_addr) { | ||
548 | netdev_err(netdev, "unable to allocate filter or buffer list " | ||
549 | "pages\n"); | ||
550 | rc = -ENOMEM; | ||
551 | goto err_out; | ||
552 | } | ||
553 | |||
554 | adapter->rx_queue.queue_len = sizeof(struct ibmveth_rx_q_entry) * | ||
555 | rxq_entries; | ||
556 | adapter->rx_queue.queue_addr = kmalloc(adapter->rx_queue.queue_len, | ||
557 | GFP_KERNEL); | ||
558 | |||
559 | if (!adapter->rx_queue.queue_addr) { | ||
560 | netdev_err(netdev, "unable to allocate rx queue pages\n"); | ||
561 | rc = -ENOMEM; | ||
562 | goto err_out; | ||
563 | } | ||
564 | |||
565 | dev = &adapter->vdev->dev; | ||
566 | |||
567 | adapter->buffer_list_dma = dma_map_single(dev, | ||
568 | adapter->buffer_list_addr, 4096, DMA_BIDIRECTIONAL); | ||
569 | adapter->filter_list_dma = dma_map_single(dev, | ||
570 | adapter->filter_list_addr, 4096, DMA_BIDIRECTIONAL); | ||
571 | adapter->rx_queue.queue_dma = dma_map_single(dev, | ||
572 | adapter->rx_queue.queue_addr, | ||
573 | adapter->rx_queue.queue_len, DMA_BIDIRECTIONAL); | ||
574 | |||
575 | if ((dma_mapping_error(dev, adapter->buffer_list_dma)) || | ||
576 | (dma_mapping_error(dev, adapter->filter_list_dma)) || | ||
577 | (dma_mapping_error(dev, adapter->rx_queue.queue_dma))) { | ||
578 | netdev_err(netdev, "unable to map filter or buffer list " | ||
579 | "pages\n"); | ||
580 | rc = -ENOMEM; | ||
581 | goto err_out; | ||
582 | } | ||
583 | |||
584 | adapter->rx_queue.index = 0; | ||
585 | adapter->rx_queue.num_slots = rxq_entries; | ||
586 | adapter->rx_queue.toggle = 1; | ||
587 | |||
588 | memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); | ||
589 | mac_address = mac_address >> 16; | ||
590 | |||
591 | rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | | ||
592 | adapter->rx_queue.queue_len; | ||
593 | rxq_desc.fields.address = adapter->rx_queue.queue_dma; | ||
594 | |||
595 | netdev_dbg(netdev, "buffer list @ 0x%p\n", adapter->buffer_list_addr); | ||
596 | netdev_dbg(netdev, "filter list @ 0x%p\n", adapter->filter_list_addr); | ||
597 | netdev_dbg(netdev, "receive q @ 0x%p\n", adapter->rx_queue.queue_addr); | ||
598 | |||
599 | h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); | ||
600 | |||
601 | lpar_rc = ibmveth_register_logical_lan(adapter, rxq_desc, mac_address); | ||
602 | |||
603 | if (lpar_rc != H_SUCCESS) { | ||
604 | netdev_err(netdev, "h_register_logical_lan failed with %ld\n", | ||
605 | lpar_rc); | ||
606 | netdev_err(netdev, "buffer TCE:0x%llx filter TCE:0x%llx rxq " | ||
607 | "desc:0x%llx MAC:0x%llx\n", | ||
608 | adapter->buffer_list_dma, | ||
609 | adapter->filter_list_dma, | ||
610 | rxq_desc.desc, | ||
611 | mac_address); | ||
612 | rc = -ENONET; | ||
613 | goto err_out; | ||
614 | } | ||
615 | |||
616 | for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { | ||
617 | if (!adapter->rx_buff_pool[i].active) | ||
618 | continue; | ||
619 | if (ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[i])) { | ||
620 | netdev_err(netdev, "unable to alloc pool\n"); | ||
621 | adapter->rx_buff_pool[i].active = 0; | ||
622 | rc = -ENOMEM; | ||
623 | goto err_out; | ||
624 | } | ||
625 | } | ||
626 | |||
627 | netdev_dbg(netdev, "registering irq 0x%x\n", netdev->irq); | ||
628 | rc = request_irq(netdev->irq, ibmveth_interrupt, 0, netdev->name, | ||
629 | netdev); | ||
630 | if (rc != 0) { | ||
631 | netdev_err(netdev, "unable to request irq 0x%x, rc %d\n", | ||
632 | netdev->irq, rc); | ||
633 | do { | ||
634 | rc = h_free_logical_lan(adapter->vdev->unit_address); | ||
635 | } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY)); | ||
636 | |||
637 | goto err_out; | ||
638 | } | ||
639 | |||
640 | adapter->bounce_buffer = | ||
641 | kmalloc(netdev->mtu + IBMVETH_BUFF_OH, GFP_KERNEL); | ||
642 | if (!adapter->bounce_buffer) { | ||
643 | netdev_err(netdev, "unable to allocate bounce buffer\n"); | ||
644 | rc = -ENOMEM; | ||
645 | goto err_out_free_irq; | ||
646 | } | ||
647 | adapter->bounce_buffer_dma = | ||
648 | dma_map_single(&adapter->vdev->dev, adapter->bounce_buffer, | ||
649 | netdev->mtu + IBMVETH_BUFF_OH, DMA_BIDIRECTIONAL); | ||
650 | if (dma_mapping_error(dev, adapter->bounce_buffer_dma)) { | ||
651 | netdev_err(netdev, "unable to map bounce buffer\n"); | ||
652 | rc = -ENOMEM; | ||
653 | goto err_out_free_irq; | ||
654 | } | ||
655 | |||
656 | netdev_dbg(netdev, "initial replenish cycle\n"); | ||
657 | ibmveth_interrupt(netdev->irq, netdev); | ||
658 | |||
659 | netif_start_queue(netdev); | ||
660 | |||
661 | netdev_dbg(netdev, "open complete\n"); | ||
662 | |||
663 | return 0; | ||
664 | |||
665 | err_out_free_irq: | ||
666 | free_irq(netdev->irq, netdev); | ||
667 | err_out: | ||
668 | ibmveth_cleanup(adapter); | ||
669 | napi_disable(&adapter->napi); | ||
670 | return rc; | ||
671 | } | ||
672 | |||
673 | static int ibmveth_close(struct net_device *netdev) | ||
674 | { | ||
675 | struct ibmveth_adapter *adapter = netdev_priv(netdev); | ||
676 | long lpar_rc; | ||
677 | |||
678 | netdev_dbg(netdev, "close starting\n"); | ||
679 | |||
680 | napi_disable(&adapter->napi); | ||
681 | |||
682 | if (!adapter->pool_config) | ||
683 | netif_stop_queue(netdev); | ||
684 | |||
685 | h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); | ||
686 | |||
687 | do { | ||
688 | lpar_rc = h_free_logical_lan(adapter->vdev->unit_address); | ||
689 | } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY)); | ||
690 | |||
691 | if (lpar_rc != H_SUCCESS) { | ||
692 | netdev_err(netdev, "h_free_logical_lan failed with %lx, " | ||
693 | "continuing with close\n", lpar_rc); | ||
694 | } | ||
695 | |||
696 | free_irq(netdev->irq, netdev); | ||
697 | |||
698 | adapter->rx_no_buffer = *(u64 *)(((char *)adapter->buffer_list_addr) + | ||
699 | 4096 - 8); | ||
700 | |||
701 | ibmveth_cleanup(adapter); | ||
702 | |||
703 | netdev_dbg(netdev, "close complete\n"); | ||
704 | |||
705 | return 0; | ||
706 | } | ||
707 | |||
708 | static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
709 | { | ||
710 | cmd->supported = (SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | | ||
711 | SUPPORTED_FIBRE); | ||
712 | cmd->advertising = (ADVERTISED_1000baseT_Full | ADVERTISED_Autoneg | | ||
713 | ADVERTISED_FIBRE); | ||
714 | ethtool_cmd_speed_set(cmd, SPEED_1000); | ||
715 | cmd->duplex = DUPLEX_FULL; | ||
716 | cmd->port = PORT_FIBRE; | ||
717 | cmd->phy_address = 0; | ||
718 | cmd->transceiver = XCVR_INTERNAL; | ||
719 | cmd->autoneg = AUTONEG_ENABLE; | ||
720 | cmd->maxtxpkt = 0; | ||
721 | cmd->maxrxpkt = 1; | ||
722 | return 0; | ||
723 | } | ||
724 | |||
725 | static void netdev_get_drvinfo(struct net_device *dev, | ||
726 | struct ethtool_drvinfo *info) | ||
727 | { | ||
728 | strncpy(info->driver, ibmveth_driver_name, sizeof(info->driver) - 1); | ||
729 | strncpy(info->version, ibmveth_driver_version, | ||
730 | sizeof(info->version) - 1); | ||
731 | } | ||
732 | |||
733 | static u32 ibmveth_fix_features(struct net_device *dev, u32 features) | ||
734 | { | ||
735 | /* | ||
736 | * Since the ibmveth firmware interface does not have the | ||
737 | * concept of separate tx/rx checksum offload enable, if rx | ||
738 | * checksum is disabled we also have to disable tx checksum | ||
739 | * offload. Once we disable rx checksum offload, we are no | ||
740 | * longer allowed to send tx buffers that are not properly | ||
741 | * checksummed. | ||
742 | */ | ||
743 | |||
744 | if (!(features & NETIF_F_RXCSUM)) | ||
745 | features &= ~NETIF_F_ALL_CSUM; | ||
746 | |||
747 | return features; | ||
748 | } | ||
749 | |||
750 | static int ibmveth_set_csum_offload(struct net_device *dev, u32 data) | ||
751 | { | ||
752 | struct ibmveth_adapter *adapter = netdev_priv(dev); | ||
753 | unsigned long set_attr, clr_attr, ret_attr; | ||
754 | unsigned long set_attr6, clr_attr6; | ||
755 | long ret, ret6; | ||
756 | int rc1 = 0, rc2 = 0; | ||
757 | int restart = 0; | ||
758 | |||
759 | if (netif_running(dev)) { | ||
760 | restart = 1; | ||
761 | adapter->pool_config = 1; | ||
762 | ibmveth_close(dev); | ||
763 | adapter->pool_config = 0; | ||
764 | } | ||
765 | |||
766 | set_attr = 0; | ||
767 | clr_attr = 0; | ||
768 | |||
769 | if (data) { | ||
770 | set_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM; | ||
771 | set_attr6 = IBMVETH_ILLAN_IPV6_TCP_CSUM; | ||
772 | } else { | ||
773 | clr_attr = IBMVETH_ILLAN_IPV4_TCP_CSUM; | ||
774 | clr_attr6 = IBMVETH_ILLAN_IPV6_TCP_CSUM; | ||
775 | } | ||
776 | |||
777 | ret = h_illan_attributes(adapter->vdev->unit_address, 0, 0, &ret_attr); | ||
778 | |||
779 | if (ret == H_SUCCESS && !(ret_attr & IBMVETH_ILLAN_ACTIVE_TRUNK) && | ||
780 | !(ret_attr & IBMVETH_ILLAN_TRUNK_PRI_MASK) && | ||
781 | (ret_attr & IBMVETH_ILLAN_PADDED_PKT_CSUM)) { | ||
782 | ret = h_illan_attributes(adapter->vdev->unit_address, clr_attr, | ||
783 | set_attr, &ret_attr); | ||
784 | |||
785 | if (ret != H_SUCCESS) { | ||
786 | netdev_err(dev, "unable to change IPv4 checksum " | ||
787 | "offload settings. %d rc=%ld\n", | ||
788 | data, ret); | ||
789 | |||
790 | ret = h_illan_attributes(adapter->vdev->unit_address, | ||
791 | set_attr, clr_attr, &ret_attr); | ||
792 | } else { | ||
793 | adapter->fw_ipv4_csum_support = data; | ||
794 | } | ||
795 | |||
796 | ret6 = h_illan_attributes(adapter->vdev->unit_address, | ||
797 | clr_attr6, set_attr6, &ret_attr); | ||
798 | |||
799 | if (ret6 != H_SUCCESS) { | ||
800 | netdev_err(dev, "unable to change IPv6 checksum " | ||
801 | "offload settings. %d rc=%ld\n", | ||
802 | data, ret); | ||
803 | |||
804 | ret = h_illan_attributes(adapter->vdev->unit_address, | ||
805 | set_attr6, clr_attr6, | ||
806 | &ret_attr); | ||
807 | } else | ||
808 | adapter->fw_ipv6_csum_support = data; | ||
809 | |||
810 | if (ret != H_SUCCESS || ret6 != H_SUCCESS) | ||
811 | adapter->rx_csum = data; | ||
812 | else | ||
813 | rc1 = -EIO; | ||
814 | } else { | ||
815 | rc1 = -EIO; | ||
816 | netdev_err(dev, "unable to change checksum offload settings." | ||
817 | " %d rc=%ld ret_attr=%lx\n", data, ret, | ||
818 | ret_attr); | ||
819 | } | ||
820 | |||
821 | if (restart) | ||
822 | rc2 = ibmveth_open(dev); | ||
823 | |||
824 | return rc1 ? rc1 : rc2; | ||
825 | } | ||
826 | |||
827 | static int ibmveth_set_features(struct net_device *dev, u32 features) | ||
828 | { | ||
829 | struct ibmveth_adapter *adapter = netdev_priv(dev); | ||
830 | int rx_csum = !!(features & NETIF_F_RXCSUM); | ||
831 | int rc; | ||
832 | |||
833 | if (rx_csum == adapter->rx_csum) | ||
834 | return 0; | ||
835 | |||
836 | rc = ibmveth_set_csum_offload(dev, rx_csum); | ||
837 | if (rc && !adapter->rx_csum) | ||
838 | dev->features = features & ~(NETIF_F_ALL_CSUM | NETIF_F_RXCSUM); | ||
839 | |||
840 | return rc; | ||
841 | } | ||
842 | |||
843 | static void ibmveth_get_strings(struct net_device *dev, u32 stringset, u8 *data) | ||
844 | { | ||
845 | int i; | ||
846 | |||
847 | if (stringset != ETH_SS_STATS) | ||
848 | return; | ||
849 | |||
850 | for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++, data += ETH_GSTRING_LEN) | ||
851 | memcpy(data, ibmveth_stats[i].name, ETH_GSTRING_LEN); | ||
852 | } | ||
853 | |||
854 | static int ibmveth_get_sset_count(struct net_device *dev, int sset) | ||
855 | { | ||
856 | switch (sset) { | ||
857 | case ETH_SS_STATS: | ||
858 | return ARRAY_SIZE(ibmveth_stats); | ||
859 | default: | ||
860 | return -EOPNOTSUPP; | ||
861 | } | ||
862 | } | ||
863 | |||
864 | static void ibmveth_get_ethtool_stats(struct net_device *dev, | ||
865 | struct ethtool_stats *stats, u64 *data) | ||
866 | { | ||
867 | int i; | ||
868 | struct ibmveth_adapter *adapter = netdev_priv(dev); | ||
869 | |||
870 | for (i = 0; i < ARRAY_SIZE(ibmveth_stats); i++) | ||
871 | data[i] = IBMVETH_GET_STAT(adapter, ibmveth_stats[i].offset); | ||
872 | } | ||
873 | |||
874 | static const struct ethtool_ops netdev_ethtool_ops = { | ||
875 | .get_drvinfo = netdev_get_drvinfo, | ||
876 | .get_settings = netdev_get_settings, | ||
877 | .get_link = ethtool_op_get_link, | ||
878 | .get_strings = ibmveth_get_strings, | ||
879 | .get_sset_count = ibmveth_get_sset_count, | ||
880 | .get_ethtool_stats = ibmveth_get_ethtool_stats, | ||
881 | }; | ||
882 | |||
883 | static int ibmveth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) | ||
884 | { | ||
885 | return -EOPNOTSUPP; | ||
886 | } | ||
887 | |||
888 | #define page_offset(v) ((unsigned long)(v) & ((1 << 12) - 1)) | ||
889 | |||
890 | static int ibmveth_send(struct ibmveth_adapter *adapter, | ||
891 | union ibmveth_buf_desc *descs) | ||
892 | { | ||
893 | unsigned long correlator; | ||
894 | unsigned int retry_count; | ||
895 | unsigned long ret; | ||
896 | |||
897 | /* | ||
898 | * The retry count sets a maximum for the number of broadcast and | ||
899 | * multicast destinations within the system. | ||
900 | */ | ||
901 | retry_count = 1024; | ||
902 | correlator = 0; | ||
903 | do { | ||
904 | ret = h_send_logical_lan(adapter->vdev->unit_address, | ||
905 | descs[0].desc, descs[1].desc, | ||
906 | descs[2].desc, descs[3].desc, | ||
907 | descs[4].desc, descs[5].desc, | ||
908 | correlator, &correlator); | ||
909 | } while ((ret == H_BUSY) && (retry_count--)); | ||
910 | |||
911 | if (ret != H_SUCCESS && ret != H_DROPPED) { | ||
912 | netdev_err(adapter->netdev, "tx: h_send_logical_lan failed " | ||
913 | "with rc=%ld\n", ret); | ||
914 | return 1; | ||
915 | } | ||
916 | |||
917 | return 0; | ||
918 | } | ||
919 | |||
920 | static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, | ||
921 | struct net_device *netdev) | ||
922 | { | ||
923 | struct ibmveth_adapter *adapter = netdev_priv(netdev); | ||
924 | unsigned int desc_flags; | ||
925 | union ibmveth_buf_desc descs[6]; | ||
926 | int last, i; | ||
927 | int force_bounce = 0; | ||
928 | |||
929 | /* | ||
930 | * veth handles a maximum of 6 segments including the header, so | ||
931 | * we have to linearize the skb if there are more than this. | ||
932 | */ | ||
933 | if (skb_shinfo(skb)->nr_frags > 5 && __skb_linearize(skb)) { | ||
934 | netdev->stats.tx_dropped++; | ||
935 | goto out; | ||
936 | } | ||
937 | |||
938 | /* veth can't checksum offload UDP */ | ||
939 | if (skb->ip_summed == CHECKSUM_PARTIAL && | ||
940 | ((skb->protocol == htons(ETH_P_IP) && | ||
941 | ip_hdr(skb)->protocol != IPPROTO_TCP) || | ||
942 | (skb->protocol == htons(ETH_P_IPV6) && | ||
943 | ipv6_hdr(skb)->nexthdr != IPPROTO_TCP)) && | ||
944 | skb_checksum_help(skb)) { | ||
945 | |||
946 | netdev_err(netdev, "tx: failed to checksum packet\n"); | ||
947 | netdev->stats.tx_dropped++; | ||
948 | goto out; | ||
949 | } | ||
950 | |||
951 | desc_flags = IBMVETH_BUF_VALID; | ||
952 | |||
953 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | ||
954 | unsigned char *buf = skb_transport_header(skb) + | ||
955 | skb->csum_offset; | ||
956 | |||
957 | desc_flags |= (IBMVETH_BUF_NO_CSUM | IBMVETH_BUF_CSUM_GOOD); | ||
958 | |||
959 | /* Need to zero out the checksum */ | ||
960 | buf[0] = 0; | ||
961 | buf[1] = 0; | ||
962 | } | ||
963 | |||
964 | retry_bounce: | ||
965 | memset(descs, 0, sizeof(descs)); | ||
966 | |||
967 | /* | ||
968 | * If a linear packet is below the rx threshold then | ||
969 | * copy it into the static bounce buffer. This avoids the | ||
970 | * cost of a TCE insert and remove. | ||
971 | */ | ||
972 | if (force_bounce || (!skb_is_nonlinear(skb) && | ||
973 | (skb->len < tx_copybreak))) { | ||
974 | skb_copy_from_linear_data(skb, adapter->bounce_buffer, | ||
975 | skb->len); | ||
976 | |||
977 | descs[0].fields.flags_len = desc_flags | skb->len; | ||
978 | descs[0].fields.address = adapter->bounce_buffer_dma; | ||
979 | |||
980 | if (ibmveth_send(adapter, descs)) { | ||
981 | adapter->tx_send_failed++; | ||
982 | netdev->stats.tx_dropped++; | ||
983 | } else { | ||
984 | netdev->stats.tx_packets++; | ||
985 | netdev->stats.tx_bytes += skb->len; | ||
986 | } | ||
987 | |||
988 | goto out; | ||
989 | } | ||
990 | |||
991 | /* Map the header */ | ||
992 | descs[0].fields.address = dma_map_single(&adapter->vdev->dev, skb->data, | ||
993 | skb_headlen(skb), | ||
994 | DMA_TO_DEVICE); | ||
995 | if (dma_mapping_error(&adapter->vdev->dev, descs[0].fields.address)) | ||
996 | goto map_failed; | ||
997 | |||
998 | descs[0].fields.flags_len = desc_flags | skb_headlen(skb); | ||
999 | |||
1000 | /* Map the frags */ | ||
1001 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | ||
1002 | unsigned long dma_addr; | ||
1003 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | ||
1004 | |||
1005 | dma_addr = dma_map_page(&adapter->vdev->dev, frag->page, | ||
1006 | frag->page_offset, frag->size, | ||
1007 | DMA_TO_DEVICE); | ||
1008 | |||
1009 | if (dma_mapping_error(&adapter->vdev->dev, dma_addr)) | ||
1010 | goto map_failed_frags; | ||
1011 | |||
1012 | descs[i+1].fields.flags_len = desc_flags | frag->size; | ||
1013 | descs[i+1].fields.address = dma_addr; | ||
1014 | } | ||
1015 | |||
1016 | if (ibmveth_send(adapter, descs)) { | ||
1017 | adapter->tx_send_failed++; | ||
1018 | netdev->stats.tx_dropped++; | ||
1019 | } else { | ||
1020 | netdev->stats.tx_packets++; | ||
1021 | netdev->stats.tx_bytes += skb->len; | ||
1022 | } | ||
1023 | |||
1024 | for (i = 0; i < skb_shinfo(skb)->nr_frags + 1; i++) | ||
1025 | dma_unmap_page(&adapter->vdev->dev, descs[i].fields.address, | ||
1026 | descs[i].fields.flags_len & IBMVETH_BUF_LEN_MASK, | ||
1027 | DMA_TO_DEVICE); | ||
1028 | |||
1029 | out: | ||
1030 | dev_kfree_skb(skb); | ||
1031 | return NETDEV_TX_OK; | ||
1032 | |||
1033 | map_failed_frags: | ||
1034 | last = i+1; | ||
1035 | for (i = 0; i < last; i++) | ||
1036 | dma_unmap_page(&adapter->vdev->dev, descs[i].fields.address, | ||
1037 | descs[i].fields.flags_len & IBMVETH_BUF_LEN_MASK, | ||
1038 | DMA_TO_DEVICE); | ||
1039 | |||
1040 | map_failed: | ||
1041 | if (!firmware_has_feature(FW_FEATURE_CMO)) | ||
1042 | netdev_err(netdev, "tx: unable to map xmit buffer\n"); | ||
1043 | adapter->tx_map_failed++; | ||
1044 | skb_linearize(skb); | ||
1045 | force_bounce = 1; | ||
1046 | goto retry_bounce; | ||
1047 | } | ||
1048 | |||
1049 | static int ibmveth_poll(struct napi_struct *napi, int budget) | ||
1050 | { | ||
1051 | struct ibmveth_adapter *adapter = | ||
1052 | container_of(napi, struct ibmveth_adapter, napi); | ||
1053 | struct net_device *netdev = adapter->netdev; | ||
1054 | int frames_processed = 0; | ||
1055 | unsigned long lpar_rc; | ||
1056 | |||
1057 | restart_poll: | ||
1058 | do { | ||
1059 | if (!ibmveth_rxq_pending_buffer(adapter)) | ||
1060 | break; | ||
1061 | |||
1062 | smp_rmb(); | ||
1063 | if (!ibmveth_rxq_buffer_valid(adapter)) { | ||
1064 | wmb(); /* suggested by larson1 */ | ||
1065 | adapter->rx_invalid_buffer++; | ||
1066 | netdev_dbg(netdev, "recycling invalid buffer\n"); | ||
1067 | ibmveth_rxq_recycle_buffer(adapter); | ||
1068 | } else { | ||
1069 | struct sk_buff *skb, *new_skb; | ||
1070 | int length = ibmveth_rxq_frame_length(adapter); | ||
1071 | int offset = ibmveth_rxq_frame_offset(adapter); | ||
1072 | int csum_good = ibmveth_rxq_csum_good(adapter); | ||
1073 | |||
1074 | skb = ibmveth_rxq_get_buffer(adapter); | ||
1075 | |||
1076 | new_skb = NULL; | ||
1077 | if (length < rx_copybreak) | ||
1078 | new_skb = netdev_alloc_skb(netdev, length); | ||
1079 | |||
1080 | if (new_skb) { | ||
1081 | skb_copy_to_linear_data(new_skb, | ||
1082 | skb->data + offset, | ||
1083 | length); | ||
1084 | if (rx_flush) | ||
1085 | ibmveth_flush_buffer(skb->data, | ||
1086 | length + offset); | ||
1087 | skb = new_skb; | ||
1088 | ibmveth_rxq_recycle_buffer(adapter); | ||
1089 | } else { | ||
1090 | ibmveth_rxq_harvest_buffer(adapter); | ||
1091 | skb_reserve(skb, offset); | ||
1092 | } | ||
1093 | |||
1094 | skb_put(skb, length); | ||
1095 | skb->protocol = eth_type_trans(skb, netdev); | ||
1096 | |||
1097 | if (csum_good) | ||
1098 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
1099 | |||
1100 | netif_receive_skb(skb); /* send it up */ | ||
1101 | |||
1102 | netdev->stats.rx_packets++; | ||
1103 | netdev->stats.rx_bytes += length; | ||
1104 | frames_processed++; | ||
1105 | } | ||
1106 | } while (frames_processed < budget); | ||
1107 | |||
1108 | ibmveth_replenish_task(adapter); | ||
1109 | |||
1110 | if (frames_processed < budget) { | ||
1111 | /* We think we are done - reenable interrupts, | ||
1112 | * then check once more to make sure we are done. | ||
1113 | */ | ||
1114 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, | ||
1115 | VIO_IRQ_ENABLE); | ||
1116 | |||
1117 | BUG_ON(lpar_rc != H_SUCCESS); | ||
1118 | |||
1119 | napi_complete(napi); | ||
1120 | |||
1121 | if (ibmveth_rxq_pending_buffer(adapter) && | ||
1122 | napi_reschedule(napi)) { | ||
1123 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, | ||
1124 | VIO_IRQ_DISABLE); | ||
1125 | goto restart_poll; | ||
1126 | } | ||
1127 | } | ||
1128 | |||
1129 | return frames_processed; | ||
1130 | } | ||
1131 | |||
1132 | static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance) | ||
1133 | { | ||
1134 | struct net_device *netdev = dev_instance; | ||
1135 | struct ibmveth_adapter *adapter = netdev_priv(netdev); | ||
1136 | unsigned long lpar_rc; | ||
1137 | |||
1138 | if (napi_schedule_prep(&adapter->napi)) { | ||
1139 | lpar_rc = h_vio_signal(adapter->vdev->unit_address, | ||
1140 | VIO_IRQ_DISABLE); | ||
1141 | BUG_ON(lpar_rc != H_SUCCESS); | ||
1142 | __napi_schedule(&adapter->napi); | ||
1143 | } | ||
1144 | return IRQ_HANDLED; | ||
1145 | } | ||
1146 | |||
1147 | static void ibmveth_set_multicast_list(struct net_device *netdev) | ||
1148 | { | ||
1149 | struct ibmveth_adapter *adapter = netdev_priv(netdev); | ||
1150 | unsigned long lpar_rc; | ||
1151 | |||
1152 | if ((netdev->flags & IFF_PROMISC) || | ||
1153 | (netdev_mc_count(netdev) > adapter->mcastFilterSize)) { | ||
1154 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, | ||
1155 | IbmVethMcastEnableRecv | | ||
1156 | IbmVethMcastDisableFiltering, | ||
1157 | 0); | ||
1158 | if (lpar_rc != H_SUCCESS) { | ||
1159 | netdev_err(netdev, "h_multicast_ctrl rc=%ld when " | ||
1160 | "entering promisc mode\n", lpar_rc); | ||
1161 | } | ||
1162 | } else { | ||
1163 | struct netdev_hw_addr *ha; | ||
1164 | /* clear the filter table & disable filtering */ | ||
1165 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, | ||
1166 | IbmVethMcastEnableRecv | | ||
1167 | IbmVethMcastDisableFiltering | | ||
1168 | IbmVethMcastClearFilterTable, | ||
1169 | 0); | ||
1170 | if (lpar_rc != H_SUCCESS) { | ||
1171 | netdev_err(netdev, "h_multicast_ctrl rc=%ld when " | ||
1172 | "attempting to clear filter table\n", | ||
1173 | lpar_rc); | ||
1174 | } | ||
1175 | /* add the addresses to the filter table */ | ||
1176 | netdev_for_each_mc_addr(ha, netdev) { | ||
1177 | /* add the multicast address to the filter table */ | ||
1178 | unsigned long mcast_addr = 0; | ||
1179 | memcpy(((char *)&mcast_addr)+2, ha->addr, 6); | ||
1180 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, | ||
1181 | IbmVethMcastAddFilter, | ||
1182 | mcast_addr); | ||
1183 | if (lpar_rc != H_SUCCESS) { | ||
1184 | netdev_err(netdev, "h_multicast_ctrl rc=%ld " | ||
1185 | "when adding an entry to the filter " | ||
1186 | "table\n", lpar_rc); | ||
1187 | } | ||
1188 | } | ||
1189 | |||
1190 | /* re-enable filtering */ | ||
1191 | lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, | ||
1192 | IbmVethMcastEnableFiltering, | ||
1193 | 0); | ||
1194 | if (lpar_rc != H_SUCCESS) { | ||
1195 | netdev_err(netdev, "h_multicast_ctrl rc=%ld when " | ||
1196 | "enabling filtering\n", lpar_rc); | ||
1197 | } | ||
1198 | } | ||
1199 | } | ||
1200 | |||
1201 | static int ibmveth_change_mtu(struct net_device *dev, int new_mtu) | ||
1202 | { | ||
1203 | struct ibmveth_adapter *adapter = netdev_priv(dev); | ||
1204 | struct vio_dev *viodev = adapter->vdev; | ||
1205 | int new_mtu_oh = new_mtu + IBMVETH_BUFF_OH; | ||
1206 | int i, rc; | ||
1207 | int need_restart = 0; | ||
1208 | |||
1209 | if (new_mtu < IBMVETH_MIN_MTU) | ||
1210 | return -EINVAL; | ||
1211 | |||
1212 | for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) | ||
1213 | if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) | ||
1214 | break; | ||
1215 | |||
1216 | if (i == IBMVETH_NUM_BUFF_POOLS) | ||
1217 | return -EINVAL; | ||
1218 | |||
1219 | /* Deactivate all the buffer pools so that the next loop can activate | ||
1220 | only the buffer pools necessary to hold the new MTU */ | ||
1221 | if (netif_running(adapter->netdev)) { | ||
1222 | need_restart = 1; | ||
1223 | adapter->pool_config = 1; | ||
1224 | ibmveth_close(adapter->netdev); | ||
1225 | adapter->pool_config = 0; | ||
1226 | } | ||
1227 | |||
1228 | /* Look for an active buffer pool that can hold the new MTU */ | ||
1229 | for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { | ||
1230 | adapter->rx_buff_pool[i].active = 1; | ||
1231 | |||
1232 | if (new_mtu_oh < adapter->rx_buff_pool[i].buff_size) { | ||
1233 | dev->mtu = new_mtu; | ||
1234 | vio_cmo_set_dev_desired(viodev, | ||
1235 | ibmveth_get_desired_dma | ||
1236 | (viodev)); | ||
1237 | if (need_restart) { | ||
1238 | return ibmveth_open(adapter->netdev); | ||
1239 | } | ||
1240 | return 0; | ||
1241 | } | ||
1242 | } | ||
1243 | |||
1244 | if (need_restart && (rc = ibmveth_open(adapter->netdev))) | ||
1245 | return rc; | ||
1246 | |||
1247 | return -EINVAL; | ||
1248 | } | ||
1249 | |||
1250 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
1251 | static void ibmveth_poll_controller(struct net_device *dev) | ||
1252 | { | ||
1253 | ibmveth_replenish_task(netdev_priv(dev)); | ||
1254 | ibmveth_interrupt(dev->irq, dev); | ||
1255 | } | ||
1256 | #endif | ||
1257 | |||
1258 | /** | ||
1259 | * ibmveth_get_desired_dma - Calculate IO memory desired by the driver | ||
1260 | * | ||
1261 | * @vdev: struct vio_dev for the device whose desired IO mem is to be returned | ||
1262 | * | ||
1263 | * Return value: | ||
1264 | * Number of bytes of IO data the driver will need to perform well. | ||
1265 | */ | ||
1266 | static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev) | ||
1267 | { | ||
1268 | struct net_device *netdev = dev_get_drvdata(&vdev->dev); | ||
1269 | struct ibmveth_adapter *adapter; | ||
1270 | unsigned long ret; | ||
1271 | int i; | ||
1272 | int rxqentries = 1; | ||
1273 | |||
1274 | /* netdev inits at probe time along with the structures we need below*/ | ||
1275 | if (netdev == NULL) | ||
1276 | return IOMMU_PAGE_ALIGN(IBMVETH_IO_ENTITLEMENT_DEFAULT); | ||
1277 | |||
1278 | adapter = netdev_priv(netdev); | ||
1279 | |||
1280 | ret = IBMVETH_BUFF_LIST_SIZE + IBMVETH_FILT_LIST_SIZE; | ||
1281 | ret += IOMMU_PAGE_ALIGN(netdev->mtu); | ||
1282 | |||
1283 | for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { | ||
1284 | /* add the size of the active receive buffers */ | ||
1285 | if (adapter->rx_buff_pool[i].active) | ||
1286 | ret += | ||
1287 | adapter->rx_buff_pool[i].size * | ||
1288 | IOMMU_PAGE_ALIGN(adapter->rx_buff_pool[i]. | ||
1289 | buff_size); | ||
1290 | rxqentries += adapter->rx_buff_pool[i].size; | ||
1291 | } | ||
1292 | /* add the size of the receive queue entries */ | ||
1293 | ret += IOMMU_PAGE_ALIGN(rxqentries * sizeof(struct ibmveth_rx_q_entry)); | ||
1294 | |||
1295 | return ret; | ||
1296 | } | ||
1297 | |||
1298 | static const struct net_device_ops ibmveth_netdev_ops = { | ||
1299 | .ndo_open = ibmveth_open, | ||
1300 | .ndo_stop = ibmveth_close, | ||
1301 | .ndo_start_xmit = ibmveth_start_xmit, | ||
1302 | .ndo_set_multicast_list = ibmveth_set_multicast_list, | ||
1303 | .ndo_do_ioctl = ibmveth_ioctl, | ||
1304 | .ndo_change_mtu = ibmveth_change_mtu, | ||
1305 | .ndo_fix_features = ibmveth_fix_features, | ||
1306 | .ndo_set_features = ibmveth_set_features, | ||
1307 | .ndo_validate_addr = eth_validate_addr, | ||
1308 | .ndo_set_mac_address = eth_mac_addr, | ||
1309 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
1310 | .ndo_poll_controller = ibmveth_poll_controller, | ||
1311 | #endif | ||
1312 | }; | ||
1313 | |||
1314 | static int __devinit ibmveth_probe(struct vio_dev *dev, | ||
1315 | const struct vio_device_id *id) | ||
1316 | { | ||
1317 | int rc, i; | ||
1318 | struct net_device *netdev; | ||
1319 | struct ibmveth_adapter *adapter; | ||
1320 | unsigned char *mac_addr_p; | ||
1321 | unsigned int *mcastFilterSize_p; | ||
1322 | |||
1323 | dev_dbg(&dev->dev, "entering ibmveth_probe for UA 0x%x\n", | ||
1324 | dev->unit_address); | ||
1325 | |||
1326 | mac_addr_p = (unsigned char *)vio_get_attribute(dev, VETH_MAC_ADDR, | ||
1327 | NULL); | ||
1328 | if (!mac_addr_p) { | ||
1329 | dev_err(&dev->dev, "Can't find VETH_MAC_ADDR attribute\n"); | ||
1330 | return -EINVAL; | ||
1331 | } | ||
1332 | |||
1333 | mcastFilterSize_p = (unsigned int *)vio_get_attribute(dev, | ||
1334 | VETH_MCAST_FILTER_SIZE, NULL); | ||
1335 | if (!mcastFilterSize_p) { | ||
1336 | dev_err(&dev->dev, "Can't find VETH_MCAST_FILTER_SIZE " | ||
1337 | "attribute\n"); | ||
1338 | return -EINVAL; | ||
1339 | } | ||
1340 | |||
1341 | netdev = alloc_etherdev(sizeof(struct ibmveth_adapter)); | ||
1342 | |||
1343 | if (!netdev) | ||
1344 | return -ENOMEM; | ||
1345 | |||
1346 | adapter = netdev_priv(netdev); | ||
1347 | dev_set_drvdata(&dev->dev, netdev); | ||
1348 | |||
1349 | adapter->vdev = dev; | ||
1350 | adapter->netdev = netdev; | ||
1351 | adapter->mcastFilterSize = *mcastFilterSize_p; | ||
1352 | adapter->pool_config = 0; | ||
1353 | |||
1354 | netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16); | ||
1355 | |||
1356 | /* | ||
1357 | * Some older boxes running PHYP non-natively have an OF that returns | ||
1358 | * a 8-byte local-mac-address field (and the first 2 bytes have to be | ||
1359 | * ignored) while newer boxes' OF return a 6-byte field. Note that | ||
1360 | * IEEE 1275 specifies that local-mac-address must be a 6-byte field. | ||
1361 | * The RPA doc specifies that the first byte must be 10b, so we'll | ||
1362 | * just look for it to solve this 8 vs. 6 byte field issue | ||
1363 | */ | ||
1364 | if ((*mac_addr_p & 0x3) != 0x02) | ||
1365 | mac_addr_p += 2; | ||
1366 | |||
1367 | adapter->mac_addr = 0; | ||
1368 | memcpy(&adapter->mac_addr, mac_addr_p, 6); | ||
1369 | |||
1370 | netdev->irq = dev->irq; | ||
1371 | netdev->netdev_ops = &ibmveth_netdev_ops; | ||
1372 | netdev->ethtool_ops = &netdev_ethtool_ops; | ||
1373 | SET_NETDEV_DEV(netdev, &dev->dev); | ||
1374 | netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM | | ||
1375 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; | ||
1376 | netdev->features |= netdev->hw_features; | ||
1377 | |||
1378 | memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); | ||
1379 | |||
1380 | for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { | ||
1381 | struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; | ||
1382 | int error; | ||
1383 | |||
1384 | ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i, | ||
1385 | pool_count[i], pool_size[i], | ||
1386 | pool_active[i]); | ||
1387 | error = kobject_init_and_add(kobj, &ktype_veth_pool, | ||
1388 | &dev->dev.kobj, "pool%d", i); | ||
1389 | if (!error) | ||
1390 | kobject_uevent(kobj, KOBJ_ADD); | ||
1391 | } | ||
1392 | |||
1393 | netdev_dbg(netdev, "adapter @ 0x%p\n", adapter); | ||
1394 | |||
1395 | adapter->buffer_list_dma = DMA_ERROR_CODE; | ||
1396 | adapter->filter_list_dma = DMA_ERROR_CODE; | ||
1397 | adapter->rx_queue.queue_dma = DMA_ERROR_CODE; | ||
1398 | |||
1399 | netdev_dbg(netdev, "registering netdev...\n"); | ||
1400 | |||
1401 | ibmveth_set_features(netdev, netdev->features); | ||
1402 | |||
1403 | rc = register_netdev(netdev); | ||
1404 | |||
1405 | if (rc) { | ||
1406 | netdev_dbg(netdev, "failed to register netdev rc=%d\n", rc); | ||
1407 | free_netdev(netdev); | ||
1408 | return rc; | ||
1409 | } | ||
1410 | |||
1411 | netdev_dbg(netdev, "registered\n"); | ||
1412 | |||
1413 | return 0; | ||
1414 | } | ||
1415 | |||
1416 | static int __devexit ibmveth_remove(struct vio_dev *dev) | ||
1417 | { | ||
1418 | struct net_device *netdev = dev_get_drvdata(&dev->dev); | ||
1419 | struct ibmveth_adapter *adapter = netdev_priv(netdev); | ||
1420 | int i; | ||
1421 | |||
1422 | for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) | ||
1423 | kobject_put(&adapter->rx_buff_pool[i].kobj); | ||
1424 | |||
1425 | unregister_netdev(netdev); | ||
1426 | |||
1427 | free_netdev(netdev); | ||
1428 | dev_set_drvdata(&dev->dev, NULL); | ||
1429 | |||
1430 | return 0; | ||
1431 | } | ||
1432 | |||
1433 | static struct attribute veth_active_attr; | ||
1434 | static struct attribute veth_num_attr; | ||
1435 | static struct attribute veth_size_attr; | ||
1436 | |||
1437 | static ssize_t veth_pool_show(struct kobject *kobj, | ||
1438 | struct attribute *attr, char *buf) | ||
1439 | { | ||
1440 | struct ibmveth_buff_pool *pool = container_of(kobj, | ||
1441 | struct ibmveth_buff_pool, | ||
1442 | kobj); | ||
1443 | |||
1444 | if (attr == &veth_active_attr) | ||
1445 | return sprintf(buf, "%d\n", pool->active); | ||
1446 | else if (attr == &veth_num_attr) | ||
1447 | return sprintf(buf, "%d\n", pool->size); | ||
1448 | else if (attr == &veth_size_attr) | ||
1449 | return sprintf(buf, "%d\n", pool->buff_size); | ||
1450 | return 0; | ||
1451 | } | ||
1452 | |||
1453 | static ssize_t veth_pool_store(struct kobject *kobj, struct attribute *attr, | ||
1454 | const char *buf, size_t count) | ||
1455 | { | ||
1456 | struct ibmveth_buff_pool *pool = container_of(kobj, | ||
1457 | struct ibmveth_buff_pool, | ||
1458 | kobj); | ||
1459 | struct net_device *netdev = dev_get_drvdata( | ||
1460 | container_of(kobj->parent, struct device, kobj)); | ||
1461 | struct ibmveth_adapter *adapter = netdev_priv(netdev); | ||
1462 | long value = simple_strtol(buf, NULL, 10); | ||
1463 | long rc; | ||
1464 | |||
1465 | if (attr == &veth_active_attr) { | ||
1466 | if (value && !pool->active) { | ||
1467 | if (netif_running(netdev)) { | ||
1468 | if (ibmveth_alloc_buffer_pool(pool)) { | ||
1469 | netdev_err(netdev, | ||
1470 | "unable to alloc pool\n"); | ||
1471 | return -ENOMEM; | ||
1472 | } | ||
1473 | pool->active = 1; | ||
1474 | adapter->pool_config = 1; | ||
1475 | ibmveth_close(netdev); | ||
1476 | adapter->pool_config = 0; | ||
1477 | if ((rc = ibmveth_open(netdev))) | ||
1478 | return rc; | ||
1479 | } else { | ||
1480 | pool->active = 1; | ||
1481 | } | ||
1482 | } else if (!value && pool->active) { | ||
1483 | int mtu = netdev->mtu + IBMVETH_BUFF_OH; | ||
1484 | int i; | ||
1485 | /* Make sure there is a buffer pool with buffers that | ||
1486 | can hold a packet of the size of the MTU */ | ||
1487 | for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { | ||
1488 | if (pool == &adapter->rx_buff_pool[i]) | ||
1489 | continue; | ||
1490 | if (!adapter->rx_buff_pool[i].active) | ||
1491 | continue; | ||
1492 | if (mtu <= adapter->rx_buff_pool[i].buff_size) | ||
1493 | break; | ||
1494 | } | ||
1495 | |||
1496 | if (i == IBMVETH_NUM_BUFF_POOLS) { | ||
1497 | netdev_err(netdev, "no active pool >= MTU\n"); | ||
1498 | return -EPERM; | ||
1499 | } | ||
1500 | |||
1501 | if (netif_running(netdev)) { | ||
1502 | adapter->pool_config = 1; | ||
1503 | ibmveth_close(netdev); | ||
1504 | pool->active = 0; | ||
1505 | adapter->pool_config = 0; | ||
1506 | if ((rc = ibmveth_open(netdev))) | ||
1507 | return rc; | ||
1508 | } | ||
1509 | pool->active = 0; | ||
1510 | } | ||
1511 | } else if (attr == &veth_num_attr) { | ||
1512 | if (value <= 0 || value > IBMVETH_MAX_POOL_COUNT) { | ||
1513 | return -EINVAL; | ||
1514 | } else { | ||
1515 | if (netif_running(netdev)) { | ||
1516 | adapter->pool_config = 1; | ||
1517 | ibmveth_close(netdev); | ||
1518 | adapter->pool_config = 0; | ||
1519 | pool->size = value; | ||
1520 | if ((rc = ibmveth_open(netdev))) | ||
1521 | return rc; | ||
1522 | } else { | ||
1523 | pool->size = value; | ||
1524 | } | ||
1525 | } | ||
1526 | } else if (attr == &veth_size_attr) { | ||
1527 | if (value <= IBMVETH_BUFF_OH || value > IBMVETH_MAX_BUF_SIZE) { | ||
1528 | return -EINVAL; | ||
1529 | } else { | ||
1530 | if (netif_running(netdev)) { | ||
1531 | adapter->pool_config = 1; | ||
1532 | ibmveth_close(netdev); | ||
1533 | adapter->pool_config = 0; | ||
1534 | pool->buff_size = value; | ||
1535 | if ((rc = ibmveth_open(netdev))) | ||
1536 | return rc; | ||
1537 | } else { | ||
1538 | pool->buff_size = value; | ||
1539 | } | ||
1540 | } | ||
1541 | } | ||
1542 | |||
1543 | /* kick the interrupt handler to allocate/deallocate pools */ | ||
1544 | ibmveth_interrupt(netdev->irq, netdev); | ||
1545 | return count; | ||
1546 | } | ||
1547 | |||
1548 | |||
1549 | #define ATTR(_name, _mode) \ | ||
1550 | struct attribute veth_##_name##_attr = { \ | ||
1551 | .name = __stringify(_name), .mode = _mode, \ | ||
1552 | }; | ||
1553 | |||
1554 | static ATTR(active, 0644); | ||
1555 | static ATTR(num, 0644); | ||
1556 | static ATTR(size, 0644); | ||
1557 | |||
1558 | static struct attribute *veth_pool_attrs[] = { | ||
1559 | &veth_active_attr, | ||
1560 | &veth_num_attr, | ||
1561 | &veth_size_attr, | ||
1562 | NULL, | ||
1563 | }; | ||
1564 | |||
1565 | static const struct sysfs_ops veth_pool_ops = { | ||
1566 | .show = veth_pool_show, | ||
1567 | .store = veth_pool_store, | ||
1568 | }; | ||
1569 | |||
1570 | static struct kobj_type ktype_veth_pool = { | ||
1571 | .release = NULL, | ||
1572 | .sysfs_ops = &veth_pool_ops, | ||
1573 | .default_attrs = veth_pool_attrs, | ||
1574 | }; | ||
1575 | |||
1576 | static int ibmveth_resume(struct device *dev) | ||
1577 | { | ||
1578 | struct net_device *netdev = dev_get_drvdata(dev); | ||
1579 | ibmveth_interrupt(netdev->irq, netdev); | ||
1580 | return 0; | ||
1581 | } | ||
1582 | |||
1583 | static struct vio_device_id ibmveth_device_table[] __devinitdata = { | ||
1584 | { "network", "IBM,l-lan"}, | ||
1585 | { "", "" } | ||
1586 | }; | ||
1587 | MODULE_DEVICE_TABLE(vio, ibmveth_device_table); | ||
1588 | |||
1589 | static struct dev_pm_ops ibmveth_pm_ops = { | ||
1590 | .resume = ibmveth_resume | ||
1591 | }; | ||
1592 | |||
1593 | static struct vio_driver ibmveth_driver = { | ||
1594 | .id_table = ibmveth_device_table, | ||
1595 | .probe = ibmveth_probe, | ||
1596 | .remove = ibmveth_remove, | ||
1597 | .get_desired_dma = ibmveth_get_desired_dma, | ||
1598 | .driver = { | ||
1599 | .name = ibmveth_driver_name, | ||
1600 | .owner = THIS_MODULE, | ||
1601 | .pm = &ibmveth_pm_ops, | ||
1602 | } | ||
1603 | }; | ||
1604 | |||
1605 | static int __init ibmveth_module_init(void) | ||
1606 | { | ||
1607 | printk(KERN_DEBUG "%s: %s %s\n", ibmveth_driver_name, | ||
1608 | ibmveth_driver_string, ibmveth_driver_version); | ||
1609 | |||
1610 | return vio_register_driver(&ibmveth_driver); | ||
1611 | } | ||
1612 | |||
1613 | static void __exit ibmveth_module_exit(void) | ||
1614 | { | ||
1615 | vio_unregister_driver(&ibmveth_driver); | ||
1616 | } | ||
1617 | |||
1618 | module_init(ibmveth_module_init); | ||
1619 | module_exit(ibmveth_module_exit); | ||
diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h new file mode 100644 index 000000000000..43a794fab9ff --- /dev/null +++ b/drivers/net/ethernet/ibm/ibmveth.h | |||
@@ -0,0 +1,195 @@ | |||
1 | /* | ||
2 | * IBM Power Virtual Ethernet Device Driver | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
17 | * | ||
18 | * Copyright (C) IBM Corporation, 2003, 2010 | ||
19 | * | ||
20 | * Authors: Dave Larson <larson1@us.ibm.com> | ||
21 | * Santiago Leon <santil@linux.vnet.ibm.com> | ||
22 | * Brian King <brking@linux.vnet.ibm.com> | ||
23 | * Robert Jennings <rcj@linux.vnet.ibm.com> | ||
24 | * Anton Blanchard <anton@au.ibm.com> | ||
25 | */ | ||
26 | |||
27 | #ifndef _IBMVETH_H | ||
28 | #define _IBMVETH_H | ||
29 | |||
30 | /* constants for H_MULTICAST_CTRL */ | ||
31 | #define IbmVethMcastReceptionModifyBit 0x80000UL | ||
32 | #define IbmVethMcastReceptionEnableBit 0x20000UL | ||
33 | #define IbmVethMcastFilterModifyBit 0x40000UL | ||
34 | #define IbmVethMcastFilterEnableBit 0x10000UL | ||
35 | |||
36 | #define IbmVethMcastEnableRecv (IbmVethMcastReceptionModifyBit | IbmVethMcastReceptionEnableBit) | ||
37 | #define IbmVethMcastDisableRecv (IbmVethMcastReceptionModifyBit) | ||
38 | #define IbmVethMcastEnableFiltering (IbmVethMcastFilterModifyBit | IbmVethMcastFilterEnableBit) | ||
39 | #define IbmVethMcastDisableFiltering (IbmVethMcastFilterModifyBit) | ||
40 | #define IbmVethMcastAddFilter 0x1UL | ||
41 | #define IbmVethMcastRemoveFilter 0x2UL | ||
42 | #define IbmVethMcastClearFilterTable 0x3UL | ||
43 | |||
44 | #define IBMVETH_ILLAN_PADDED_PKT_CSUM 0x0000000000002000UL | ||
45 | #define IBMVETH_ILLAN_TRUNK_PRI_MASK 0x0000000000000F00UL | ||
46 | #define IBMVETH_ILLAN_IPV6_TCP_CSUM 0x0000000000000004UL | ||
47 | #define IBMVETH_ILLAN_IPV4_TCP_CSUM 0x0000000000000002UL | ||
48 | #define IBMVETH_ILLAN_ACTIVE_TRUNK 0x0000000000000001UL | ||
49 | |||
50 | /* hcall macros */ | ||
51 | #define h_register_logical_lan(ua, buflst, rxq, fltlst, mac) \ | ||
52 | plpar_hcall_norets(H_REGISTER_LOGICAL_LAN, ua, buflst, rxq, fltlst, mac) | ||
53 | |||
54 | #define h_free_logical_lan(ua) \ | ||
55 | plpar_hcall_norets(H_FREE_LOGICAL_LAN, ua) | ||
56 | |||
57 | #define h_add_logical_lan_buffer(ua, buf) \ | ||
58 | plpar_hcall_norets(H_ADD_LOGICAL_LAN_BUFFER, ua, buf) | ||
59 | |||
60 | static inline long h_send_logical_lan(unsigned long unit_address, | ||
61 | unsigned long desc1, unsigned long desc2, unsigned long desc3, | ||
62 | unsigned long desc4, unsigned long desc5, unsigned long desc6, | ||
63 | unsigned long corellator_in, unsigned long *corellator_out) | ||
64 | { | ||
65 | long rc; | ||
66 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; | ||
67 | |||
68 | rc = plpar_hcall9(H_SEND_LOGICAL_LAN, retbuf, unit_address, desc1, | ||
69 | desc2, desc3, desc4, desc5, desc6, corellator_in); | ||
70 | |||
71 | *corellator_out = retbuf[0]; | ||
72 | |||
73 | return rc; | ||
74 | } | ||
75 | |||
76 | static inline long h_illan_attributes(unsigned long unit_address, | ||
77 | unsigned long reset_mask, unsigned long set_mask, | ||
78 | unsigned long *ret_attributes) | ||
79 | { | ||
80 | long rc; | ||
81 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; | ||
82 | |||
83 | rc = plpar_hcall(H_ILLAN_ATTRIBUTES, retbuf, unit_address, | ||
84 | reset_mask, set_mask); | ||
85 | |||
86 | *ret_attributes = retbuf[0]; | ||
87 | |||
88 | return rc; | ||
89 | } | ||
90 | |||
91 | #define h_multicast_ctrl(ua, cmd, mac) \ | ||
92 | plpar_hcall_norets(H_MULTICAST_CTRL, ua, cmd, mac) | ||
93 | |||
94 | #define h_change_logical_lan_mac(ua, mac) \ | ||
95 | plpar_hcall_norets(H_CHANGE_LOGICAL_LAN_MAC, ua, mac) | ||
96 | |||
97 | #define IBMVETH_NUM_BUFF_POOLS 5 | ||
98 | #define IBMVETH_IO_ENTITLEMENT_DEFAULT 4243456 /* MTU of 1500 needs 4.2Mb */ | ||
99 | #define IBMVETH_BUFF_OH 22 /* Overhead: 14 ethernet header + 8 opaque handle */ | ||
100 | #define IBMVETH_MIN_MTU 68 | ||
101 | #define IBMVETH_MAX_POOL_COUNT 4096 | ||
102 | #define IBMVETH_BUFF_LIST_SIZE 4096 | ||
103 | #define IBMVETH_FILT_LIST_SIZE 4096 | ||
104 | #define IBMVETH_MAX_BUF_SIZE (1024 * 128) | ||
105 | |||
106 | static int pool_size[] = { 512, 1024 * 2, 1024 * 16, 1024 * 32, 1024 * 64 }; | ||
107 | static int pool_count[] = { 256, 512, 256, 256, 256 }; | ||
108 | static int pool_active[] = { 1, 1, 0, 0, 0}; | ||
109 | |||
110 | #define IBM_VETH_INVALID_MAP ((u16)0xffff) | ||
111 | |||
112 | struct ibmveth_buff_pool { | ||
113 | u32 size; | ||
114 | u32 index; | ||
115 | u32 buff_size; | ||
116 | u32 threshold; | ||
117 | atomic_t available; | ||
118 | u32 consumer_index; | ||
119 | u32 producer_index; | ||
120 | u16 *free_map; | ||
121 | dma_addr_t *dma_addr; | ||
122 | struct sk_buff **skbuff; | ||
123 | int active; | ||
124 | struct kobject kobj; | ||
125 | }; | ||
126 | |||
127 | struct ibmveth_rx_q { | ||
128 | u64 index; | ||
129 | u64 num_slots; | ||
130 | u64 toggle; | ||
131 | dma_addr_t queue_dma; | ||
132 | u32 queue_len; | ||
133 | struct ibmveth_rx_q_entry *queue_addr; | ||
134 | }; | ||
135 | |||
136 | struct ibmveth_adapter { | ||
137 | struct vio_dev *vdev; | ||
138 | struct net_device *netdev; | ||
139 | struct napi_struct napi; | ||
140 | struct net_device_stats stats; | ||
141 | unsigned int mcastFilterSize; | ||
142 | unsigned long mac_addr; | ||
143 | void * buffer_list_addr; | ||
144 | void * filter_list_addr; | ||
145 | dma_addr_t buffer_list_dma; | ||
146 | dma_addr_t filter_list_dma; | ||
147 | struct ibmveth_buff_pool rx_buff_pool[IBMVETH_NUM_BUFF_POOLS]; | ||
148 | struct ibmveth_rx_q rx_queue; | ||
149 | int pool_config; | ||
150 | int rx_csum; | ||
151 | void *bounce_buffer; | ||
152 | dma_addr_t bounce_buffer_dma; | ||
153 | |||
154 | u64 fw_ipv6_csum_support; | ||
155 | u64 fw_ipv4_csum_support; | ||
156 | /* adapter specific stats */ | ||
157 | u64 replenish_task_cycles; | ||
158 | u64 replenish_no_mem; | ||
159 | u64 replenish_add_buff_failure; | ||
160 | u64 replenish_add_buff_success; | ||
161 | u64 rx_invalid_buffer; | ||
162 | u64 rx_no_buffer; | ||
163 | u64 tx_map_failed; | ||
164 | u64 tx_send_failed; | ||
165 | }; | ||
166 | |||
167 | struct ibmveth_buf_desc_fields { | ||
168 | u32 flags_len; | ||
169 | #define IBMVETH_BUF_VALID 0x80000000 | ||
170 | #define IBMVETH_BUF_TOGGLE 0x40000000 | ||
171 | #define IBMVETH_BUF_NO_CSUM 0x02000000 | ||
172 | #define IBMVETH_BUF_CSUM_GOOD 0x01000000 | ||
173 | #define IBMVETH_BUF_LEN_MASK 0x00FFFFFF | ||
174 | u32 address; | ||
175 | }; | ||
176 | |||
177 | union ibmveth_buf_desc { | ||
178 | u64 desc; | ||
179 | struct ibmveth_buf_desc_fields fields; | ||
180 | }; | ||
181 | |||
182 | struct ibmveth_rx_q_entry { | ||
183 | u32 flags_off; | ||
184 | #define IBMVETH_RXQ_TOGGLE 0x80000000 | ||
185 | #define IBMVETH_RXQ_TOGGLE_SHIFT 31 | ||
186 | #define IBMVETH_RXQ_VALID 0x40000000 | ||
187 | #define IBMVETH_RXQ_NO_CSUM 0x02000000 | ||
188 | #define IBMVETH_RXQ_CSUM_GOOD 0x01000000 | ||
189 | #define IBMVETH_RXQ_OFF_MASK 0x0000FFFF | ||
190 | |||
191 | u32 length; | ||
192 | u64 correlator; | ||
193 | }; | ||
194 | |||
195 | #endif /* _IBMVETH_H */ | ||
diff --git a/drivers/net/ethernet/ibm/iseries_veth.c b/drivers/net/ethernet/ibm/iseries_veth.c new file mode 100644 index 000000000000..53dd39e9130e --- /dev/null +++ b/drivers/net/ethernet/ibm/iseries_veth.c | |||
@@ -0,0 +1,1710 @@ | |||
1 | /* File veth.c created by Kyle A. Lucke on Mon Aug 7 2000. */ | ||
2 | /* | ||
3 | * IBM eServer iSeries Virtual Ethernet Device Driver | ||
4 | * Copyright (C) 2001 Kyle A. Lucke (klucke@us.ibm.com), IBM Corp. | ||
5 | * Substantially cleaned up by: | ||
6 | * Copyright (C) 2003 David Gibson <dwg@au1.ibm.com>, IBM Corporation. | ||
7 | * Copyright (C) 2004-2005 Michael Ellerman, IBM Corporation. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License as | ||
11 | * published by the Free Software Foundation; either version 2 of the | ||
12 | * License, or (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
22 | * USA | ||
23 | * | ||
24 | * | ||
25 | * This module implements the virtual ethernet device for iSeries LPAR | ||
26 | * Linux. It uses hypervisor message passing to implement an | ||
27 | * ethernet-like network device communicating between partitions on | ||
28 | * the iSeries. | ||
29 | * | ||
30 | * The iSeries LPAR hypervisor currently allows for up to 16 different | ||
31 | * virtual ethernets. These are all dynamically configurable on | ||
32 | * OS/400 partitions, but dynamic configuration is not supported under | ||
33 | * Linux yet. An ethXX network device will be created for each | ||
34 | * virtual ethernet this partition is connected to. | ||
35 | * | ||
36 | * - This driver is responsible for routing packets to and from other | ||
37 | * partitions. The MAC addresses used by the virtual ethernets | ||
38 | * contains meaning and must not be modified. | ||
39 | * | ||
40 | * - Having 2 virtual ethernets to the same remote partition DOES NOT | ||
41 | * double the available bandwidth. The 2 devices will share the | ||
42 | * available hypervisor bandwidth. | ||
43 | * | ||
44 | * - If you send a packet to your own mac address, it will just be | ||
45 | * dropped, you won't get it on the receive side. | ||
46 | * | ||
47 | * - Multicast is implemented by sending the frame frame to every | ||
48 | * other partition. It is the responsibility of the receiving | ||
49 | * partition to filter the addresses desired. | ||
50 | * | ||
51 | * Tunable parameters: | ||
52 | * | ||
53 | * VETH_NUMBUFFERS: This compile time option defaults to 120. It | ||
54 | * controls how much memory Linux will allocate per remote partition | ||
55 | * it is communicating with. It can be thought of as the maximum | ||
56 | * number of packets outstanding to a remote partition at a time. | ||
57 | */ | ||
58 | |||
59 | #include <linux/module.h> | ||
60 | #include <linux/types.h> | ||
61 | #include <linux/errno.h> | ||
62 | #include <linux/ioport.h> | ||
63 | #include <linux/kernel.h> | ||
64 | #include <linux/netdevice.h> | ||
65 | #include <linux/etherdevice.h> | ||
66 | #include <linux/skbuff.h> | ||
67 | #include <linux/init.h> | ||
68 | #include <linux/delay.h> | ||
69 | #include <linux/mm.h> | ||
70 | #include <linux/ethtool.h> | ||
71 | #include <linux/if_ether.h> | ||
72 | #include <linux/slab.h> | ||
73 | |||
74 | #include <asm/abs_addr.h> | ||
75 | #include <asm/iseries/mf.h> | ||
76 | #include <asm/uaccess.h> | ||
77 | #include <asm/firmware.h> | ||
78 | #include <asm/iseries/hv_lp_config.h> | ||
79 | #include <asm/iseries/hv_types.h> | ||
80 | #include <asm/iseries/hv_lp_event.h> | ||
81 | #include <asm/iommu.h> | ||
82 | #include <asm/vio.h> | ||
83 | |||
84 | #undef DEBUG | ||
85 | |||
86 | MODULE_AUTHOR("Kyle Lucke <klucke@us.ibm.com>"); | ||
87 | MODULE_DESCRIPTION("iSeries Virtual ethernet driver"); | ||
88 | MODULE_LICENSE("GPL"); | ||
89 | |||
90 | #define VETH_EVENT_CAP (0) | ||
91 | #define VETH_EVENT_FRAMES (1) | ||
92 | #define VETH_EVENT_MONITOR (2) | ||
93 | #define VETH_EVENT_FRAMES_ACK (3) | ||
94 | |||
95 | #define VETH_MAX_ACKS_PER_MSG (20) | ||
96 | #define VETH_MAX_FRAMES_PER_MSG (6) | ||
97 | |||
98 | struct veth_frames_data { | ||
99 | u32 addr[VETH_MAX_FRAMES_PER_MSG]; | ||
100 | u16 len[VETH_MAX_FRAMES_PER_MSG]; | ||
101 | u32 eofmask; | ||
102 | }; | ||
103 | #define VETH_EOF_SHIFT (32-VETH_MAX_FRAMES_PER_MSG) | ||
104 | |||
105 | struct veth_frames_ack_data { | ||
106 | u16 token[VETH_MAX_ACKS_PER_MSG]; | ||
107 | }; | ||
108 | |||
109 | struct veth_cap_data { | ||
110 | u8 caps_version; | ||
111 | u8 rsvd1; | ||
112 | u16 num_buffers; | ||
113 | u16 ack_threshold; | ||
114 | u16 rsvd2; | ||
115 | u32 ack_timeout; | ||
116 | u32 rsvd3; | ||
117 | u64 rsvd4[3]; | ||
118 | }; | ||
119 | |||
120 | struct veth_lpevent { | ||
121 | struct HvLpEvent base_event; | ||
122 | union { | ||
123 | struct veth_cap_data caps_data; | ||
124 | struct veth_frames_data frames_data; | ||
125 | struct veth_frames_ack_data frames_ack_data; | ||
126 | } u; | ||
127 | |||
128 | }; | ||
129 | |||
130 | #define DRV_NAME "iseries_veth" | ||
131 | #define DRV_VERSION "2.0" | ||
132 | |||
133 | #define VETH_NUMBUFFERS (120) | ||
134 | #define VETH_ACKTIMEOUT (1000000) /* microseconds */ | ||
135 | #define VETH_MAX_MCAST (12) | ||
136 | |||
137 | #define VETH_MAX_MTU (9000) | ||
138 | |||
139 | #if VETH_NUMBUFFERS < 10 | ||
140 | #define ACK_THRESHOLD (1) | ||
141 | #elif VETH_NUMBUFFERS < 20 | ||
142 | #define ACK_THRESHOLD (4) | ||
143 | #elif VETH_NUMBUFFERS < 40 | ||
144 | #define ACK_THRESHOLD (10) | ||
145 | #else | ||
146 | #define ACK_THRESHOLD (20) | ||
147 | #endif | ||
148 | |||
149 | #define VETH_STATE_SHUTDOWN (0x0001) | ||
150 | #define VETH_STATE_OPEN (0x0002) | ||
151 | #define VETH_STATE_RESET (0x0004) | ||
152 | #define VETH_STATE_SENTMON (0x0008) | ||
153 | #define VETH_STATE_SENTCAPS (0x0010) | ||
154 | #define VETH_STATE_GOTCAPACK (0x0020) | ||
155 | #define VETH_STATE_GOTCAPS (0x0040) | ||
156 | #define VETH_STATE_SENTCAPACK (0x0080) | ||
157 | #define VETH_STATE_READY (0x0100) | ||
158 | |||
159 | struct veth_msg { | ||
160 | struct veth_msg *next; | ||
161 | struct veth_frames_data data; | ||
162 | int token; | ||
163 | int in_use; | ||
164 | struct sk_buff *skb; | ||
165 | struct device *dev; | ||
166 | }; | ||
167 | |||
168 | struct veth_lpar_connection { | ||
169 | HvLpIndex remote_lp; | ||
170 | struct delayed_work statemachine_wq; | ||
171 | struct veth_msg *msgs; | ||
172 | int num_events; | ||
173 | struct veth_cap_data local_caps; | ||
174 | |||
175 | struct kobject kobject; | ||
176 | struct timer_list ack_timer; | ||
177 | |||
178 | struct timer_list reset_timer; | ||
179 | unsigned int reset_timeout; | ||
180 | unsigned long last_contact; | ||
181 | int outstanding_tx; | ||
182 | |||
183 | spinlock_t lock; | ||
184 | unsigned long state; | ||
185 | HvLpInstanceId src_inst; | ||
186 | HvLpInstanceId dst_inst; | ||
187 | struct veth_lpevent cap_event, cap_ack_event; | ||
188 | u16 pending_acks[VETH_MAX_ACKS_PER_MSG]; | ||
189 | u32 num_pending_acks; | ||
190 | |||
191 | int num_ack_events; | ||
192 | struct veth_cap_data remote_caps; | ||
193 | u32 ack_timeout; | ||
194 | |||
195 | struct veth_msg *msg_stack_head; | ||
196 | }; | ||
197 | |||
198 | struct veth_port { | ||
199 | struct device *dev; | ||
200 | u64 mac_addr; | ||
201 | HvLpIndexMap lpar_map; | ||
202 | |||
203 | /* queue_lock protects the stopped_map and dev's queue. */ | ||
204 | spinlock_t queue_lock; | ||
205 | HvLpIndexMap stopped_map; | ||
206 | |||
207 | /* mcast_gate protects promiscuous, num_mcast & mcast_addr. */ | ||
208 | rwlock_t mcast_gate; | ||
209 | int promiscuous; | ||
210 | int num_mcast; | ||
211 | u64 mcast_addr[VETH_MAX_MCAST]; | ||
212 | |||
213 | struct kobject kobject; | ||
214 | }; | ||
215 | |||
216 | static HvLpIndex this_lp; | ||
217 | static struct veth_lpar_connection *veth_cnx[HVMAXARCHITECTEDLPS]; /* = 0 */ | ||
218 | static struct net_device *veth_dev[HVMAXARCHITECTEDVIRTUALLANS]; /* = 0 */ | ||
219 | |||
220 | static int veth_start_xmit(struct sk_buff *skb, struct net_device *dev); | ||
221 | static void veth_recycle_msg(struct veth_lpar_connection *, struct veth_msg *); | ||
222 | static void veth_wake_queues(struct veth_lpar_connection *cnx); | ||
223 | static void veth_stop_queues(struct veth_lpar_connection *cnx); | ||
224 | static void veth_receive(struct veth_lpar_connection *, struct veth_lpevent *); | ||
225 | static void veth_release_connection(struct kobject *kobject); | ||
226 | static void veth_timed_ack(unsigned long ptr); | ||
227 | static void veth_timed_reset(unsigned long ptr); | ||
228 | |||
229 | /* | ||
230 | * Utility functions | ||
231 | */ | ||
232 | |||
233 | #define veth_info(fmt, args...) \ | ||
234 | printk(KERN_INFO DRV_NAME ": " fmt, ## args) | ||
235 | |||
236 | #define veth_error(fmt, args...) \ | ||
237 | printk(KERN_ERR DRV_NAME ": Error: " fmt, ## args) | ||
238 | |||
239 | #ifdef DEBUG | ||
240 | #define veth_debug(fmt, args...) \ | ||
241 | printk(KERN_DEBUG DRV_NAME ": " fmt, ## args) | ||
242 | #else | ||
243 | #define veth_debug(fmt, args...) do {} while (0) | ||
244 | #endif | ||
245 | |||
246 | /* You must hold the connection's lock when you call this function. */ | ||
247 | static inline void veth_stack_push(struct veth_lpar_connection *cnx, | ||
248 | struct veth_msg *msg) | ||
249 | { | ||
250 | msg->next = cnx->msg_stack_head; | ||
251 | cnx->msg_stack_head = msg; | ||
252 | } | ||
253 | |||
254 | /* You must hold the connection's lock when you call this function. */ | ||
255 | static inline struct veth_msg *veth_stack_pop(struct veth_lpar_connection *cnx) | ||
256 | { | ||
257 | struct veth_msg *msg; | ||
258 | |||
259 | msg = cnx->msg_stack_head; | ||
260 | if (msg) | ||
261 | cnx->msg_stack_head = cnx->msg_stack_head->next; | ||
262 | |||
263 | return msg; | ||
264 | } | ||
265 | |||
266 | /* You must hold the connection's lock when you call this function. */ | ||
267 | static inline int veth_stack_is_empty(struct veth_lpar_connection *cnx) | ||
268 | { | ||
269 | return cnx->msg_stack_head == NULL; | ||
270 | } | ||
271 | |||
272 | static inline HvLpEvent_Rc | ||
273 | veth_signalevent(struct veth_lpar_connection *cnx, u16 subtype, | ||
274 | HvLpEvent_AckInd ackind, HvLpEvent_AckType acktype, | ||
275 | u64 token, | ||
276 | u64 data1, u64 data2, u64 data3, u64 data4, u64 data5) | ||
277 | { | ||
278 | return HvCallEvent_signalLpEventFast(cnx->remote_lp, | ||
279 | HvLpEvent_Type_VirtualLan, | ||
280 | subtype, ackind, acktype, | ||
281 | cnx->src_inst, | ||
282 | cnx->dst_inst, | ||
283 | token, data1, data2, data3, | ||
284 | data4, data5); | ||
285 | } | ||
286 | |||
287 | static inline HvLpEvent_Rc veth_signaldata(struct veth_lpar_connection *cnx, | ||
288 | u16 subtype, u64 token, void *data) | ||
289 | { | ||
290 | u64 *p = (u64 *) data; | ||
291 | |||
292 | return veth_signalevent(cnx, subtype, HvLpEvent_AckInd_NoAck, | ||
293 | HvLpEvent_AckType_ImmediateAck, | ||
294 | token, p[0], p[1], p[2], p[3], p[4]); | ||
295 | } | ||
296 | |||
297 | struct veth_allocation { | ||
298 | struct completion c; | ||
299 | int num; | ||
300 | }; | ||
301 | |||
302 | static void veth_complete_allocation(void *parm, int number) | ||
303 | { | ||
304 | struct veth_allocation *vc = (struct veth_allocation *)parm; | ||
305 | |||
306 | vc->num = number; | ||
307 | complete(&vc->c); | ||
308 | } | ||
309 | |||
310 | static int veth_allocate_events(HvLpIndex rlp, int number) | ||
311 | { | ||
312 | struct veth_allocation vc = | ||
313 | { COMPLETION_INITIALIZER_ONSTACK(vc.c), 0 }; | ||
314 | |||
315 | mf_allocate_lp_events(rlp, HvLpEvent_Type_VirtualLan, | ||
316 | sizeof(struct veth_lpevent), number, | ||
317 | &veth_complete_allocation, &vc); | ||
318 | wait_for_completion(&vc.c); | ||
319 | |||
320 | return vc.num; | ||
321 | } | ||
322 | |||
323 | /* | ||
324 | * sysfs support | ||
325 | */ | ||
326 | |||
327 | struct veth_cnx_attribute { | ||
328 | struct attribute attr; | ||
329 | ssize_t (*show)(struct veth_lpar_connection *, char *buf); | ||
330 | ssize_t (*store)(struct veth_lpar_connection *, const char *buf); | ||
331 | }; | ||
332 | |||
333 | static ssize_t veth_cnx_attribute_show(struct kobject *kobj, | ||
334 | struct attribute *attr, char *buf) | ||
335 | { | ||
336 | struct veth_cnx_attribute *cnx_attr; | ||
337 | struct veth_lpar_connection *cnx; | ||
338 | |||
339 | cnx_attr = container_of(attr, struct veth_cnx_attribute, attr); | ||
340 | cnx = container_of(kobj, struct veth_lpar_connection, kobject); | ||
341 | |||
342 | if (!cnx_attr->show) | ||
343 | return -EIO; | ||
344 | |||
345 | return cnx_attr->show(cnx, buf); | ||
346 | } | ||
347 | |||
348 | #define CUSTOM_CNX_ATTR(_name, _format, _expression) \ | ||
349 | static ssize_t _name##_show(struct veth_lpar_connection *cnx, char *buf)\ | ||
350 | { \ | ||
351 | return sprintf(buf, _format, _expression); \ | ||
352 | } \ | ||
353 | struct veth_cnx_attribute veth_cnx_attr_##_name = __ATTR_RO(_name) | ||
354 | |||
355 | #define SIMPLE_CNX_ATTR(_name) \ | ||
356 | CUSTOM_CNX_ATTR(_name, "%lu\n", (unsigned long)cnx->_name) | ||
357 | |||
358 | SIMPLE_CNX_ATTR(outstanding_tx); | ||
359 | SIMPLE_CNX_ATTR(remote_lp); | ||
360 | SIMPLE_CNX_ATTR(num_events); | ||
361 | SIMPLE_CNX_ATTR(src_inst); | ||
362 | SIMPLE_CNX_ATTR(dst_inst); | ||
363 | SIMPLE_CNX_ATTR(num_pending_acks); | ||
364 | SIMPLE_CNX_ATTR(num_ack_events); | ||
365 | CUSTOM_CNX_ATTR(ack_timeout, "%d\n", jiffies_to_msecs(cnx->ack_timeout)); | ||
366 | CUSTOM_CNX_ATTR(reset_timeout, "%d\n", jiffies_to_msecs(cnx->reset_timeout)); | ||
367 | CUSTOM_CNX_ATTR(state, "0x%.4lX\n", cnx->state); | ||
368 | CUSTOM_CNX_ATTR(last_contact, "%d\n", cnx->last_contact ? | ||
369 | jiffies_to_msecs(jiffies - cnx->last_contact) : 0); | ||
370 | |||
371 | #define GET_CNX_ATTR(_name) (&veth_cnx_attr_##_name.attr) | ||
372 | |||
373 | static struct attribute *veth_cnx_default_attrs[] = { | ||
374 | GET_CNX_ATTR(outstanding_tx), | ||
375 | GET_CNX_ATTR(remote_lp), | ||
376 | GET_CNX_ATTR(num_events), | ||
377 | GET_CNX_ATTR(reset_timeout), | ||
378 | GET_CNX_ATTR(last_contact), | ||
379 | GET_CNX_ATTR(state), | ||
380 | GET_CNX_ATTR(src_inst), | ||
381 | GET_CNX_ATTR(dst_inst), | ||
382 | GET_CNX_ATTR(num_pending_acks), | ||
383 | GET_CNX_ATTR(num_ack_events), | ||
384 | GET_CNX_ATTR(ack_timeout), | ||
385 | NULL | ||
386 | }; | ||
387 | |||
388 | static const struct sysfs_ops veth_cnx_sysfs_ops = { | ||
389 | .show = veth_cnx_attribute_show | ||
390 | }; | ||
391 | |||
392 | static struct kobj_type veth_lpar_connection_ktype = { | ||
393 | .release = veth_release_connection, | ||
394 | .sysfs_ops = &veth_cnx_sysfs_ops, | ||
395 | .default_attrs = veth_cnx_default_attrs | ||
396 | }; | ||
397 | |||
398 | struct veth_port_attribute { | ||
399 | struct attribute attr; | ||
400 | ssize_t (*show)(struct veth_port *, char *buf); | ||
401 | ssize_t (*store)(struct veth_port *, const char *buf); | ||
402 | }; | ||
403 | |||
404 | static ssize_t veth_port_attribute_show(struct kobject *kobj, | ||
405 | struct attribute *attr, char *buf) | ||
406 | { | ||
407 | struct veth_port_attribute *port_attr; | ||
408 | struct veth_port *port; | ||
409 | |||
410 | port_attr = container_of(attr, struct veth_port_attribute, attr); | ||
411 | port = container_of(kobj, struct veth_port, kobject); | ||
412 | |||
413 | if (!port_attr->show) | ||
414 | return -EIO; | ||
415 | |||
416 | return port_attr->show(port, buf); | ||
417 | } | ||
418 | |||
419 | #define CUSTOM_PORT_ATTR(_name, _format, _expression) \ | ||
420 | static ssize_t _name##_show(struct veth_port *port, char *buf) \ | ||
421 | { \ | ||
422 | return sprintf(buf, _format, _expression); \ | ||
423 | } \ | ||
424 | struct veth_port_attribute veth_port_attr_##_name = __ATTR_RO(_name) | ||
425 | |||
426 | #define SIMPLE_PORT_ATTR(_name) \ | ||
427 | CUSTOM_PORT_ATTR(_name, "%lu\n", (unsigned long)port->_name) | ||
428 | |||
429 | SIMPLE_PORT_ATTR(promiscuous); | ||
430 | SIMPLE_PORT_ATTR(num_mcast); | ||
431 | CUSTOM_PORT_ATTR(lpar_map, "0x%X\n", port->lpar_map); | ||
432 | CUSTOM_PORT_ATTR(stopped_map, "0x%X\n", port->stopped_map); | ||
433 | CUSTOM_PORT_ATTR(mac_addr, "0x%llX\n", port->mac_addr); | ||
434 | |||
435 | #define GET_PORT_ATTR(_name) (&veth_port_attr_##_name.attr) | ||
436 | static struct attribute *veth_port_default_attrs[] = { | ||
437 | GET_PORT_ATTR(mac_addr), | ||
438 | GET_PORT_ATTR(lpar_map), | ||
439 | GET_PORT_ATTR(stopped_map), | ||
440 | GET_PORT_ATTR(promiscuous), | ||
441 | GET_PORT_ATTR(num_mcast), | ||
442 | NULL | ||
443 | }; | ||
444 | |||
445 | static const struct sysfs_ops veth_port_sysfs_ops = { | ||
446 | .show = veth_port_attribute_show | ||
447 | }; | ||
448 | |||
449 | static struct kobj_type veth_port_ktype = { | ||
450 | .sysfs_ops = &veth_port_sysfs_ops, | ||
451 | .default_attrs = veth_port_default_attrs | ||
452 | }; | ||
453 | |||
454 | /* | ||
455 | * LPAR connection code | ||
456 | */ | ||
457 | |||
458 | static inline void veth_kick_statemachine(struct veth_lpar_connection *cnx) | ||
459 | { | ||
460 | schedule_delayed_work(&cnx->statemachine_wq, 0); | ||
461 | } | ||
462 | |||
463 | static void veth_take_cap(struct veth_lpar_connection *cnx, | ||
464 | struct veth_lpevent *event) | ||
465 | { | ||
466 | unsigned long flags; | ||
467 | |||
468 | spin_lock_irqsave(&cnx->lock, flags); | ||
469 | /* Receiving caps may mean the other end has just come up, so | ||
470 | * we need to reload the instance ID of the far end */ | ||
471 | cnx->dst_inst = | ||
472 | HvCallEvent_getTargetLpInstanceId(cnx->remote_lp, | ||
473 | HvLpEvent_Type_VirtualLan); | ||
474 | |||
475 | if (cnx->state & VETH_STATE_GOTCAPS) { | ||
476 | veth_error("Received a second capabilities from LPAR %d.\n", | ||
477 | cnx->remote_lp); | ||
478 | event->base_event.xRc = HvLpEvent_Rc_BufferNotAvailable; | ||
479 | HvCallEvent_ackLpEvent((struct HvLpEvent *) event); | ||
480 | } else { | ||
481 | memcpy(&cnx->cap_event, event, sizeof(cnx->cap_event)); | ||
482 | cnx->state |= VETH_STATE_GOTCAPS; | ||
483 | veth_kick_statemachine(cnx); | ||
484 | } | ||
485 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
486 | } | ||
487 | |||
488 | static void veth_take_cap_ack(struct veth_lpar_connection *cnx, | ||
489 | struct veth_lpevent *event) | ||
490 | { | ||
491 | unsigned long flags; | ||
492 | |||
493 | spin_lock_irqsave(&cnx->lock, flags); | ||
494 | if (cnx->state & VETH_STATE_GOTCAPACK) { | ||
495 | veth_error("Received a second capabilities ack from LPAR %d.\n", | ||
496 | cnx->remote_lp); | ||
497 | } else { | ||
498 | memcpy(&cnx->cap_ack_event, event, | ||
499 | sizeof(cnx->cap_ack_event)); | ||
500 | cnx->state |= VETH_STATE_GOTCAPACK; | ||
501 | veth_kick_statemachine(cnx); | ||
502 | } | ||
503 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
504 | } | ||
505 | |||
506 | static void veth_take_monitor_ack(struct veth_lpar_connection *cnx, | ||
507 | struct veth_lpevent *event) | ||
508 | { | ||
509 | unsigned long flags; | ||
510 | |||
511 | spin_lock_irqsave(&cnx->lock, flags); | ||
512 | veth_debug("cnx %d: lost connection.\n", cnx->remote_lp); | ||
513 | |||
514 | /* Avoid kicking the statemachine once we're shutdown. | ||
515 | * It's unnecessary and it could break veth_stop_connection(). */ | ||
516 | |||
517 | if (! (cnx->state & VETH_STATE_SHUTDOWN)) { | ||
518 | cnx->state |= VETH_STATE_RESET; | ||
519 | veth_kick_statemachine(cnx); | ||
520 | } | ||
521 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
522 | } | ||
523 | |||
524 | static void veth_handle_ack(struct veth_lpevent *event) | ||
525 | { | ||
526 | HvLpIndex rlp = event->base_event.xTargetLp; | ||
527 | struct veth_lpar_connection *cnx = veth_cnx[rlp]; | ||
528 | |||
529 | BUG_ON(! cnx); | ||
530 | |||
531 | switch (event->base_event.xSubtype) { | ||
532 | case VETH_EVENT_CAP: | ||
533 | veth_take_cap_ack(cnx, event); | ||
534 | break; | ||
535 | case VETH_EVENT_MONITOR: | ||
536 | veth_take_monitor_ack(cnx, event); | ||
537 | break; | ||
538 | default: | ||
539 | veth_error("Unknown ack type %d from LPAR %d.\n", | ||
540 | event->base_event.xSubtype, rlp); | ||
541 | } | ||
542 | } | ||
543 | |||
544 | static void veth_handle_int(struct veth_lpevent *event) | ||
545 | { | ||
546 | HvLpIndex rlp = event->base_event.xSourceLp; | ||
547 | struct veth_lpar_connection *cnx = veth_cnx[rlp]; | ||
548 | unsigned long flags; | ||
549 | int i, acked = 0; | ||
550 | |||
551 | BUG_ON(! cnx); | ||
552 | |||
553 | switch (event->base_event.xSubtype) { | ||
554 | case VETH_EVENT_CAP: | ||
555 | veth_take_cap(cnx, event); | ||
556 | break; | ||
557 | case VETH_EVENT_MONITOR: | ||
558 | /* do nothing... this'll hang out here til we're dead, | ||
559 | * and the hypervisor will return it for us. */ | ||
560 | break; | ||
561 | case VETH_EVENT_FRAMES_ACK: | ||
562 | spin_lock_irqsave(&cnx->lock, flags); | ||
563 | |||
564 | for (i = 0; i < VETH_MAX_ACKS_PER_MSG; ++i) { | ||
565 | u16 msgnum = event->u.frames_ack_data.token[i]; | ||
566 | |||
567 | if (msgnum < VETH_NUMBUFFERS) { | ||
568 | veth_recycle_msg(cnx, cnx->msgs + msgnum); | ||
569 | cnx->outstanding_tx--; | ||
570 | acked++; | ||
571 | } | ||
572 | } | ||
573 | |||
574 | if (acked > 0) { | ||
575 | cnx->last_contact = jiffies; | ||
576 | veth_wake_queues(cnx); | ||
577 | } | ||
578 | |||
579 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
580 | break; | ||
581 | case VETH_EVENT_FRAMES: | ||
582 | veth_receive(cnx, event); | ||
583 | break; | ||
584 | default: | ||
585 | veth_error("Unknown interrupt type %d from LPAR %d.\n", | ||
586 | event->base_event.xSubtype, rlp); | ||
587 | } | ||
588 | } | ||
589 | |||
590 | static void veth_handle_event(struct HvLpEvent *event) | ||
591 | { | ||
592 | struct veth_lpevent *veth_event = (struct veth_lpevent *)event; | ||
593 | |||
594 | if (hvlpevent_is_ack(event)) | ||
595 | veth_handle_ack(veth_event); | ||
596 | else | ||
597 | veth_handle_int(veth_event); | ||
598 | } | ||
599 | |||
600 | static int veth_process_caps(struct veth_lpar_connection *cnx) | ||
601 | { | ||
602 | struct veth_cap_data *remote_caps = &cnx->remote_caps; | ||
603 | int num_acks_needed; | ||
604 | |||
605 | /* Convert timer to jiffies */ | ||
606 | cnx->ack_timeout = remote_caps->ack_timeout * HZ / 1000000; | ||
607 | |||
608 | if ( (remote_caps->num_buffers == 0) || | ||
609 | (remote_caps->ack_threshold > VETH_MAX_ACKS_PER_MSG) || | ||
610 | (remote_caps->ack_threshold == 0) || | ||
611 | (cnx->ack_timeout == 0) ) { | ||
612 | veth_error("Received incompatible capabilities from LPAR %d.\n", | ||
613 | cnx->remote_lp); | ||
614 | return HvLpEvent_Rc_InvalidSubtypeData; | ||
615 | } | ||
616 | |||
617 | num_acks_needed = (remote_caps->num_buffers | ||
618 | / remote_caps->ack_threshold) + 1; | ||
619 | |||
620 | /* FIXME: locking on num_ack_events? */ | ||
621 | if (cnx->num_ack_events < num_acks_needed) { | ||
622 | int num; | ||
623 | |||
624 | num = veth_allocate_events(cnx->remote_lp, | ||
625 | num_acks_needed-cnx->num_ack_events); | ||
626 | if (num > 0) | ||
627 | cnx->num_ack_events += num; | ||
628 | |||
629 | if (cnx->num_ack_events < num_acks_needed) { | ||
630 | veth_error("Couldn't allocate enough ack events " | ||
631 | "for LPAR %d.\n", cnx->remote_lp); | ||
632 | |||
633 | return HvLpEvent_Rc_BufferNotAvailable; | ||
634 | } | ||
635 | } | ||
636 | |||
637 | |||
638 | return HvLpEvent_Rc_Good; | ||
639 | } | ||
640 | |||
641 | /* FIXME: The gotos here are a bit dubious */ | ||
642 | static void veth_statemachine(struct work_struct *work) | ||
643 | { | ||
644 | struct veth_lpar_connection *cnx = | ||
645 | container_of(work, struct veth_lpar_connection, | ||
646 | statemachine_wq.work); | ||
647 | int rlp = cnx->remote_lp; | ||
648 | int rc; | ||
649 | |||
650 | spin_lock_irq(&cnx->lock); | ||
651 | |||
652 | restart: | ||
653 | if (cnx->state & VETH_STATE_RESET) { | ||
654 | if (cnx->state & VETH_STATE_OPEN) | ||
655 | HvCallEvent_closeLpEventPath(cnx->remote_lp, | ||
656 | HvLpEvent_Type_VirtualLan); | ||
657 | |||
658 | /* | ||
659 | * Reset ack data. This prevents the ack_timer actually | ||
660 | * doing anything, even if it runs one more time when | ||
661 | * we drop the lock below. | ||
662 | */ | ||
663 | memset(&cnx->pending_acks, 0xff, sizeof (cnx->pending_acks)); | ||
664 | cnx->num_pending_acks = 0; | ||
665 | |||
666 | cnx->state &= ~(VETH_STATE_RESET | VETH_STATE_SENTMON | ||
667 | | VETH_STATE_OPEN | VETH_STATE_SENTCAPS | ||
668 | | VETH_STATE_GOTCAPACK | VETH_STATE_GOTCAPS | ||
669 | | VETH_STATE_SENTCAPACK | VETH_STATE_READY); | ||
670 | |||
671 | /* Clean up any leftover messages */ | ||
672 | if (cnx->msgs) { | ||
673 | int i; | ||
674 | for (i = 0; i < VETH_NUMBUFFERS; ++i) | ||
675 | veth_recycle_msg(cnx, cnx->msgs + i); | ||
676 | } | ||
677 | |||
678 | cnx->outstanding_tx = 0; | ||
679 | veth_wake_queues(cnx); | ||
680 | |||
681 | /* Drop the lock so we can do stuff that might sleep or | ||
682 | * take other locks. */ | ||
683 | spin_unlock_irq(&cnx->lock); | ||
684 | |||
685 | del_timer_sync(&cnx->ack_timer); | ||
686 | del_timer_sync(&cnx->reset_timer); | ||
687 | |||
688 | spin_lock_irq(&cnx->lock); | ||
689 | |||
690 | if (cnx->state & VETH_STATE_RESET) | ||
691 | goto restart; | ||
692 | |||
693 | /* Hack, wait for the other end to reset itself. */ | ||
694 | if (! (cnx->state & VETH_STATE_SHUTDOWN)) { | ||
695 | schedule_delayed_work(&cnx->statemachine_wq, 5 * HZ); | ||
696 | goto out; | ||
697 | } | ||
698 | } | ||
699 | |||
700 | if (cnx->state & VETH_STATE_SHUTDOWN) | ||
701 | /* It's all over, do nothing */ | ||
702 | goto out; | ||
703 | |||
704 | if ( !(cnx->state & VETH_STATE_OPEN) ) { | ||
705 | if (! cnx->msgs || (cnx->num_events < (2 + VETH_NUMBUFFERS)) ) | ||
706 | goto cant_cope; | ||
707 | |||
708 | HvCallEvent_openLpEventPath(rlp, HvLpEvent_Type_VirtualLan); | ||
709 | cnx->src_inst = | ||
710 | HvCallEvent_getSourceLpInstanceId(rlp, | ||
711 | HvLpEvent_Type_VirtualLan); | ||
712 | cnx->dst_inst = | ||
713 | HvCallEvent_getTargetLpInstanceId(rlp, | ||
714 | HvLpEvent_Type_VirtualLan); | ||
715 | cnx->state |= VETH_STATE_OPEN; | ||
716 | } | ||
717 | |||
718 | if ( (cnx->state & VETH_STATE_OPEN) && | ||
719 | !(cnx->state & VETH_STATE_SENTMON) ) { | ||
720 | rc = veth_signalevent(cnx, VETH_EVENT_MONITOR, | ||
721 | HvLpEvent_AckInd_DoAck, | ||
722 | HvLpEvent_AckType_DeferredAck, | ||
723 | 0, 0, 0, 0, 0, 0); | ||
724 | |||
725 | if (rc == HvLpEvent_Rc_Good) { | ||
726 | cnx->state |= VETH_STATE_SENTMON; | ||
727 | } else { | ||
728 | if ( (rc != HvLpEvent_Rc_PartitionDead) && | ||
729 | (rc != HvLpEvent_Rc_PathClosed) ) | ||
730 | veth_error("Error sending monitor to LPAR %d, " | ||
731 | "rc = %d\n", rlp, rc); | ||
732 | |||
733 | /* Oh well, hope we get a cap from the other | ||
734 | * end and do better when that kicks us */ | ||
735 | goto out; | ||
736 | } | ||
737 | } | ||
738 | |||
739 | if ( (cnx->state & VETH_STATE_OPEN) && | ||
740 | !(cnx->state & VETH_STATE_SENTCAPS)) { | ||
741 | u64 *rawcap = (u64 *)&cnx->local_caps; | ||
742 | |||
743 | rc = veth_signalevent(cnx, VETH_EVENT_CAP, | ||
744 | HvLpEvent_AckInd_DoAck, | ||
745 | HvLpEvent_AckType_ImmediateAck, | ||
746 | 0, rawcap[0], rawcap[1], rawcap[2], | ||
747 | rawcap[3], rawcap[4]); | ||
748 | |||
749 | if (rc == HvLpEvent_Rc_Good) { | ||
750 | cnx->state |= VETH_STATE_SENTCAPS; | ||
751 | } else { | ||
752 | if ( (rc != HvLpEvent_Rc_PartitionDead) && | ||
753 | (rc != HvLpEvent_Rc_PathClosed) ) | ||
754 | veth_error("Error sending caps to LPAR %d, " | ||
755 | "rc = %d\n", rlp, rc); | ||
756 | |||
757 | /* Oh well, hope we get a cap from the other | ||
758 | * end and do better when that kicks us */ | ||
759 | goto out; | ||
760 | } | ||
761 | } | ||
762 | |||
763 | if ((cnx->state & VETH_STATE_GOTCAPS) && | ||
764 | !(cnx->state & VETH_STATE_SENTCAPACK)) { | ||
765 | struct veth_cap_data *remote_caps = &cnx->remote_caps; | ||
766 | |||
767 | memcpy(remote_caps, &cnx->cap_event.u.caps_data, | ||
768 | sizeof(*remote_caps)); | ||
769 | |||
770 | spin_unlock_irq(&cnx->lock); | ||
771 | rc = veth_process_caps(cnx); | ||
772 | spin_lock_irq(&cnx->lock); | ||
773 | |||
774 | /* We dropped the lock, so recheck for anything which | ||
775 | * might mess us up */ | ||
776 | if (cnx->state & (VETH_STATE_RESET|VETH_STATE_SHUTDOWN)) | ||
777 | goto restart; | ||
778 | |||
779 | cnx->cap_event.base_event.xRc = rc; | ||
780 | HvCallEvent_ackLpEvent((struct HvLpEvent *)&cnx->cap_event); | ||
781 | if (rc == HvLpEvent_Rc_Good) | ||
782 | cnx->state |= VETH_STATE_SENTCAPACK; | ||
783 | else | ||
784 | goto cant_cope; | ||
785 | } | ||
786 | |||
787 | if ((cnx->state & VETH_STATE_GOTCAPACK) && | ||
788 | (cnx->state & VETH_STATE_GOTCAPS) && | ||
789 | !(cnx->state & VETH_STATE_READY)) { | ||
790 | if (cnx->cap_ack_event.base_event.xRc == HvLpEvent_Rc_Good) { | ||
791 | /* Start the ACK timer */ | ||
792 | cnx->ack_timer.expires = jiffies + cnx->ack_timeout; | ||
793 | add_timer(&cnx->ack_timer); | ||
794 | cnx->state |= VETH_STATE_READY; | ||
795 | } else { | ||
796 | veth_error("Caps rejected by LPAR %d, rc = %d\n", | ||
797 | rlp, cnx->cap_ack_event.base_event.xRc); | ||
798 | goto cant_cope; | ||
799 | } | ||
800 | } | ||
801 | |||
802 | out: | ||
803 | spin_unlock_irq(&cnx->lock); | ||
804 | return; | ||
805 | |||
806 | cant_cope: | ||
807 | /* FIXME: we get here if something happens we really can't | ||
808 | * cope with. The link will never work once we get here, and | ||
809 | * all we can do is not lock the rest of the system up */ | ||
810 | veth_error("Unrecoverable error on connection to LPAR %d, shutting down" | ||
811 | " (state = 0x%04lx)\n", rlp, cnx->state); | ||
812 | cnx->state |= VETH_STATE_SHUTDOWN; | ||
813 | spin_unlock_irq(&cnx->lock); | ||
814 | } | ||
815 | |||
816 | static int veth_init_connection(u8 rlp) | ||
817 | { | ||
818 | struct veth_lpar_connection *cnx; | ||
819 | struct veth_msg *msgs; | ||
820 | int i; | ||
821 | |||
822 | if ( (rlp == this_lp) || | ||
823 | ! HvLpConfig_doLpsCommunicateOnVirtualLan(this_lp, rlp) ) | ||
824 | return 0; | ||
825 | |||
826 | cnx = kzalloc(sizeof(*cnx), GFP_KERNEL); | ||
827 | if (! cnx) | ||
828 | return -ENOMEM; | ||
829 | |||
830 | cnx->remote_lp = rlp; | ||
831 | spin_lock_init(&cnx->lock); | ||
832 | INIT_DELAYED_WORK(&cnx->statemachine_wq, veth_statemachine); | ||
833 | |||
834 | init_timer(&cnx->ack_timer); | ||
835 | cnx->ack_timer.function = veth_timed_ack; | ||
836 | cnx->ack_timer.data = (unsigned long) cnx; | ||
837 | |||
838 | init_timer(&cnx->reset_timer); | ||
839 | cnx->reset_timer.function = veth_timed_reset; | ||
840 | cnx->reset_timer.data = (unsigned long) cnx; | ||
841 | cnx->reset_timeout = 5 * HZ * (VETH_ACKTIMEOUT / 1000000); | ||
842 | |||
843 | memset(&cnx->pending_acks, 0xff, sizeof (cnx->pending_acks)); | ||
844 | |||
845 | veth_cnx[rlp] = cnx; | ||
846 | |||
847 | /* This gets us 1 reference, which is held on behalf of the driver | ||
848 | * infrastructure. It's released at module unload. */ | ||
849 | kobject_init(&cnx->kobject, &veth_lpar_connection_ktype); | ||
850 | |||
851 | msgs = kcalloc(VETH_NUMBUFFERS, sizeof(struct veth_msg), GFP_KERNEL); | ||
852 | if (! msgs) { | ||
853 | veth_error("Can't allocate buffers for LPAR %d.\n", rlp); | ||
854 | return -ENOMEM; | ||
855 | } | ||
856 | |||
857 | cnx->msgs = msgs; | ||
858 | |||
859 | for (i = 0; i < VETH_NUMBUFFERS; i++) { | ||
860 | msgs[i].token = i; | ||
861 | veth_stack_push(cnx, msgs + i); | ||
862 | } | ||
863 | |||
864 | cnx->num_events = veth_allocate_events(rlp, 2 + VETH_NUMBUFFERS); | ||
865 | |||
866 | if (cnx->num_events < (2 + VETH_NUMBUFFERS)) { | ||
867 | veth_error("Can't allocate enough events for LPAR %d.\n", rlp); | ||
868 | return -ENOMEM; | ||
869 | } | ||
870 | |||
871 | cnx->local_caps.num_buffers = VETH_NUMBUFFERS; | ||
872 | cnx->local_caps.ack_threshold = ACK_THRESHOLD; | ||
873 | cnx->local_caps.ack_timeout = VETH_ACKTIMEOUT; | ||
874 | |||
875 | return 0; | ||
876 | } | ||
877 | |||
878 | static void veth_stop_connection(struct veth_lpar_connection *cnx) | ||
879 | { | ||
880 | if (!cnx) | ||
881 | return; | ||
882 | |||
883 | spin_lock_irq(&cnx->lock); | ||
884 | cnx->state |= VETH_STATE_RESET | VETH_STATE_SHUTDOWN; | ||
885 | veth_kick_statemachine(cnx); | ||
886 | spin_unlock_irq(&cnx->lock); | ||
887 | |||
888 | /* ensure the statemachine runs now and waits for its completion */ | ||
889 | flush_delayed_work_sync(&cnx->statemachine_wq); | ||
890 | } | ||
891 | |||
892 | static void veth_destroy_connection(struct veth_lpar_connection *cnx) | ||
893 | { | ||
894 | if (!cnx) | ||
895 | return; | ||
896 | |||
897 | if (cnx->num_events > 0) | ||
898 | mf_deallocate_lp_events(cnx->remote_lp, | ||
899 | HvLpEvent_Type_VirtualLan, | ||
900 | cnx->num_events, | ||
901 | NULL, NULL); | ||
902 | if (cnx->num_ack_events > 0) | ||
903 | mf_deallocate_lp_events(cnx->remote_lp, | ||
904 | HvLpEvent_Type_VirtualLan, | ||
905 | cnx->num_ack_events, | ||
906 | NULL, NULL); | ||
907 | |||
908 | kfree(cnx->msgs); | ||
909 | veth_cnx[cnx->remote_lp] = NULL; | ||
910 | kfree(cnx); | ||
911 | } | ||
912 | |||
913 | static void veth_release_connection(struct kobject *kobj) | ||
914 | { | ||
915 | struct veth_lpar_connection *cnx; | ||
916 | cnx = container_of(kobj, struct veth_lpar_connection, kobject); | ||
917 | veth_stop_connection(cnx); | ||
918 | veth_destroy_connection(cnx); | ||
919 | } | ||
920 | |||
921 | /* | ||
922 | * net_device code | ||
923 | */ | ||
924 | |||
925 | static int veth_open(struct net_device *dev) | ||
926 | { | ||
927 | netif_start_queue(dev); | ||
928 | return 0; | ||
929 | } | ||
930 | |||
931 | static int veth_close(struct net_device *dev) | ||
932 | { | ||
933 | netif_stop_queue(dev); | ||
934 | return 0; | ||
935 | } | ||
936 | |||
937 | static int veth_change_mtu(struct net_device *dev, int new_mtu) | ||
938 | { | ||
939 | if ((new_mtu < 68) || (new_mtu > VETH_MAX_MTU)) | ||
940 | return -EINVAL; | ||
941 | dev->mtu = new_mtu; | ||
942 | return 0; | ||
943 | } | ||
944 | |||
945 | static void veth_set_multicast_list(struct net_device *dev) | ||
946 | { | ||
947 | struct veth_port *port = netdev_priv(dev); | ||
948 | unsigned long flags; | ||
949 | |||
950 | write_lock_irqsave(&port->mcast_gate, flags); | ||
951 | |||
952 | if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) || | ||
953 | (netdev_mc_count(dev) > VETH_MAX_MCAST)) { | ||
954 | port->promiscuous = 1; | ||
955 | } else { | ||
956 | struct netdev_hw_addr *ha; | ||
957 | |||
958 | port->promiscuous = 0; | ||
959 | |||
960 | /* Update table */ | ||
961 | port->num_mcast = 0; | ||
962 | |||
963 | netdev_for_each_mc_addr(ha, dev) { | ||
964 | u8 *addr = ha->addr; | ||
965 | u64 xaddr = 0; | ||
966 | |||
967 | memcpy(&xaddr, addr, ETH_ALEN); | ||
968 | port->mcast_addr[port->num_mcast] = xaddr; | ||
969 | port->num_mcast++; | ||
970 | } | ||
971 | } | ||
972 | |||
973 | write_unlock_irqrestore(&port->mcast_gate, flags); | ||
974 | } | ||
975 | |||
976 | static void veth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | ||
977 | { | ||
978 | strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1); | ||
979 | info->driver[sizeof(info->driver) - 1] = '\0'; | ||
980 | strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1); | ||
981 | info->version[sizeof(info->version) - 1] = '\0'; | ||
982 | } | ||
983 | |||
984 | static int veth_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) | ||
985 | { | ||
986 | ecmd->supported = (SUPPORTED_1000baseT_Full | ||
987 | | SUPPORTED_Autoneg | SUPPORTED_FIBRE); | ||
988 | ecmd->advertising = (SUPPORTED_1000baseT_Full | ||
989 | | SUPPORTED_Autoneg | SUPPORTED_FIBRE); | ||
990 | ecmd->port = PORT_FIBRE; | ||
991 | ecmd->transceiver = XCVR_INTERNAL; | ||
992 | ecmd->phy_address = 0; | ||
993 | ecmd->speed = SPEED_1000; | ||
994 | ecmd->duplex = DUPLEX_FULL; | ||
995 | ecmd->autoneg = AUTONEG_ENABLE; | ||
996 | ecmd->maxtxpkt = 120; | ||
997 | ecmd->maxrxpkt = 120; | ||
998 | return 0; | ||
999 | } | ||
1000 | |||
1001 | static const struct ethtool_ops ops = { | ||
1002 | .get_drvinfo = veth_get_drvinfo, | ||
1003 | .get_settings = veth_get_settings, | ||
1004 | .get_link = ethtool_op_get_link, | ||
1005 | }; | ||
1006 | |||
1007 | static const struct net_device_ops veth_netdev_ops = { | ||
1008 | .ndo_open = veth_open, | ||
1009 | .ndo_stop = veth_close, | ||
1010 | .ndo_start_xmit = veth_start_xmit, | ||
1011 | .ndo_change_mtu = veth_change_mtu, | ||
1012 | .ndo_set_multicast_list = veth_set_multicast_list, | ||
1013 | .ndo_set_mac_address = NULL, | ||
1014 | .ndo_validate_addr = eth_validate_addr, | ||
1015 | }; | ||
1016 | |||
1017 | static struct net_device *veth_probe_one(int vlan, | ||
1018 | struct vio_dev *vio_dev) | ||
1019 | { | ||
1020 | struct net_device *dev; | ||
1021 | struct veth_port *port; | ||
1022 | struct device *vdev = &vio_dev->dev; | ||
1023 | int i, rc; | ||
1024 | const unsigned char *mac_addr; | ||
1025 | |||
1026 | mac_addr = vio_get_attribute(vio_dev, "local-mac-address", NULL); | ||
1027 | if (mac_addr == NULL) | ||
1028 | mac_addr = vio_get_attribute(vio_dev, "mac-address", NULL); | ||
1029 | if (mac_addr == NULL) { | ||
1030 | veth_error("Unable to fetch MAC address from device tree.\n"); | ||
1031 | return NULL; | ||
1032 | } | ||
1033 | |||
1034 | dev = alloc_etherdev(sizeof (struct veth_port)); | ||
1035 | if (! dev) { | ||
1036 | veth_error("Unable to allocate net_device structure!\n"); | ||
1037 | return NULL; | ||
1038 | } | ||
1039 | |||
1040 | port = netdev_priv(dev); | ||
1041 | |||
1042 | spin_lock_init(&port->queue_lock); | ||
1043 | rwlock_init(&port->mcast_gate); | ||
1044 | port->stopped_map = 0; | ||
1045 | |||
1046 | for (i = 0; i < HVMAXARCHITECTEDLPS; i++) { | ||
1047 | HvLpVirtualLanIndexMap map; | ||
1048 | |||
1049 | if (i == this_lp) | ||
1050 | continue; | ||
1051 | map = HvLpConfig_getVirtualLanIndexMapForLp(i); | ||
1052 | if (map & (0x8000 >> vlan)) | ||
1053 | port->lpar_map |= (1 << i); | ||
1054 | } | ||
1055 | port->dev = vdev; | ||
1056 | |||
1057 | memcpy(dev->dev_addr, mac_addr, ETH_ALEN); | ||
1058 | |||
1059 | dev->mtu = VETH_MAX_MTU; | ||
1060 | |||
1061 | memcpy(&port->mac_addr, mac_addr, ETH_ALEN); | ||
1062 | |||
1063 | dev->netdev_ops = &veth_netdev_ops; | ||
1064 | SET_ETHTOOL_OPS(dev, &ops); | ||
1065 | |||
1066 | SET_NETDEV_DEV(dev, vdev); | ||
1067 | |||
1068 | rc = register_netdev(dev); | ||
1069 | if (rc != 0) { | ||
1070 | veth_error("Failed registering net device for vlan%d.\n", vlan); | ||
1071 | free_netdev(dev); | ||
1072 | return NULL; | ||
1073 | } | ||
1074 | |||
1075 | kobject_init(&port->kobject, &veth_port_ktype); | ||
1076 | if (0 != kobject_add(&port->kobject, &dev->dev.kobj, "veth_port")) | ||
1077 | veth_error("Failed adding port for %s to sysfs.\n", dev->name); | ||
1078 | |||
1079 | veth_info("%s attached to iSeries vlan %d (LPAR map = 0x%.4X)\n", | ||
1080 | dev->name, vlan, port->lpar_map); | ||
1081 | |||
1082 | return dev; | ||
1083 | } | ||
1084 | |||
1085 | /* | ||
1086 | * Tx path | ||
1087 | */ | ||
1088 | |||
1089 | static int veth_transmit_to_one(struct sk_buff *skb, HvLpIndex rlp, | ||
1090 | struct net_device *dev) | ||
1091 | { | ||
1092 | struct veth_lpar_connection *cnx = veth_cnx[rlp]; | ||
1093 | struct veth_port *port = netdev_priv(dev); | ||
1094 | HvLpEvent_Rc rc; | ||
1095 | struct veth_msg *msg = NULL; | ||
1096 | unsigned long flags; | ||
1097 | |||
1098 | if (! cnx) | ||
1099 | return 0; | ||
1100 | |||
1101 | spin_lock_irqsave(&cnx->lock, flags); | ||
1102 | |||
1103 | if (! (cnx->state & VETH_STATE_READY)) | ||
1104 | goto no_error; | ||
1105 | |||
1106 | if ((skb->len - ETH_HLEN) > VETH_MAX_MTU) | ||
1107 | goto drop; | ||
1108 | |||
1109 | msg = veth_stack_pop(cnx); | ||
1110 | if (! msg) | ||
1111 | goto drop; | ||
1112 | |||
1113 | msg->in_use = 1; | ||
1114 | msg->skb = skb_get(skb); | ||
1115 | |||
1116 | msg->data.addr[0] = dma_map_single(port->dev, skb->data, | ||
1117 | skb->len, DMA_TO_DEVICE); | ||
1118 | |||
1119 | if (dma_mapping_error(port->dev, msg->data.addr[0])) | ||
1120 | goto recycle_and_drop; | ||
1121 | |||
1122 | msg->dev = port->dev; | ||
1123 | msg->data.len[0] = skb->len; | ||
1124 | msg->data.eofmask = 1 << VETH_EOF_SHIFT; | ||
1125 | |||
1126 | rc = veth_signaldata(cnx, VETH_EVENT_FRAMES, msg->token, &msg->data); | ||
1127 | |||
1128 | if (rc != HvLpEvent_Rc_Good) | ||
1129 | goto recycle_and_drop; | ||
1130 | |||
1131 | /* If the timer's not already running, start it now. */ | ||
1132 | if (0 == cnx->outstanding_tx) | ||
1133 | mod_timer(&cnx->reset_timer, jiffies + cnx->reset_timeout); | ||
1134 | |||
1135 | cnx->last_contact = jiffies; | ||
1136 | cnx->outstanding_tx++; | ||
1137 | |||
1138 | if (veth_stack_is_empty(cnx)) | ||
1139 | veth_stop_queues(cnx); | ||
1140 | |||
1141 | no_error: | ||
1142 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
1143 | return 0; | ||
1144 | |||
1145 | recycle_and_drop: | ||
1146 | veth_recycle_msg(cnx, msg); | ||
1147 | drop: | ||
1148 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
1149 | return 1; | ||
1150 | } | ||
1151 | |||
1152 | static void veth_transmit_to_many(struct sk_buff *skb, | ||
1153 | HvLpIndexMap lpmask, | ||
1154 | struct net_device *dev) | ||
1155 | { | ||
1156 | int i, success, error; | ||
1157 | |||
1158 | success = error = 0; | ||
1159 | |||
1160 | for (i = 0; i < HVMAXARCHITECTEDLPS; i++) { | ||
1161 | if ((lpmask & (1 << i)) == 0) | ||
1162 | continue; | ||
1163 | |||
1164 | if (veth_transmit_to_one(skb, i, dev)) | ||
1165 | error = 1; | ||
1166 | else | ||
1167 | success = 1; | ||
1168 | } | ||
1169 | |||
1170 | if (error) | ||
1171 | dev->stats.tx_errors++; | ||
1172 | |||
1173 | if (success) { | ||
1174 | dev->stats.tx_packets++; | ||
1175 | dev->stats.tx_bytes += skb->len; | ||
1176 | } | ||
1177 | } | ||
1178 | |||
1179 | static int veth_start_xmit(struct sk_buff *skb, struct net_device *dev) | ||
1180 | { | ||
1181 | unsigned char *frame = skb->data; | ||
1182 | struct veth_port *port = netdev_priv(dev); | ||
1183 | HvLpIndexMap lpmask; | ||
1184 | |||
1185 | if (is_unicast_ether_addr(frame)) { | ||
1186 | /* unicast packet */ | ||
1187 | HvLpIndex rlp = frame[5]; | ||
1188 | |||
1189 | if ( ! ((1 << rlp) & port->lpar_map) ) { | ||
1190 | dev_kfree_skb(skb); | ||
1191 | return NETDEV_TX_OK; | ||
1192 | } | ||
1193 | |||
1194 | lpmask = 1 << rlp; | ||
1195 | } else { | ||
1196 | lpmask = port->lpar_map; | ||
1197 | } | ||
1198 | |||
1199 | veth_transmit_to_many(skb, lpmask, dev); | ||
1200 | |||
1201 | dev_kfree_skb(skb); | ||
1202 | |||
1203 | return NETDEV_TX_OK; | ||
1204 | } | ||
1205 | |||
1206 | /* You must hold the connection's lock when you call this function. */ | ||
1207 | static void veth_recycle_msg(struct veth_lpar_connection *cnx, | ||
1208 | struct veth_msg *msg) | ||
1209 | { | ||
1210 | u32 dma_address, dma_length; | ||
1211 | |||
1212 | if (msg->in_use) { | ||
1213 | msg->in_use = 0; | ||
1214 | dma_address = msg->data.addr[0]; | ||
1215 | dma_length = msg->data.len[0]; | ||
1216 | |||
1217 | if (!dma_mapping_error(msg->dev, dma_address)) | ||
1218 | dma_unmap_single(msg->dev, dma_address, dma_length, | ||
1219 | DMA_TO_DEVICE); | ||
1220 | |||
1221 | if (msg->skb) { | ||
1222 | dev_kfree_skb_any(msg->skb); | ||
1223 | msg->skb = NULL; | ||
1224 | } | ||
1225 | |||
1226 | memset(&msg->data, 0, sizeof(msg->data)); | ||
1227 | veth_stack_push(cnx, msg); | ||
1228 | } else if (cnx->state & VETH_STATE_OPEN) { | ||
1229 | veth_error("Non-pending frame (# %d) acked by LPAR %d.\n", | ||
1230 | cnx->remote_lp, msg->token); | ||
1231 | } | ||
1232 | } | ||
1233 | |||
1234 | static void veth_wake_queues(struct veth_lpar_connection *cnx) | ||
1235 | { | ||
1236 | int i; | ||
1237 | |||
1238 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) { | ||
1239 | struct net_device *dev = veth_dev[i]; | ||
1240 | struct veth_port *port; | ||
1241 | unsigned long flags; | ||
1242 | |||
1243 | if (! dev) | ||
1244 | continue; | ||
1245 | |||
1246 | port = netdev_priv(dev); | ||
1247 | |||
1248 | if (! (port->lpar_map & (1<<cnx->remote_lp))) | ||
1249 | continue; | ||
1250 | |||
1251 | spin_lock_irqsave(&port->queue_lock, flags); | ||
1252 | |||
1253 | port->stopped_map &= ~(1 << cnx->remote_lp); | ||
1254 | |||
1255 | if (0 == port->stopped_map && netif_queue_stopped(dev)) { | ||
1256 | veth_debug("cnx %d: woke queue for %s.\n", | ||
1257 | cnx->remote_lp, dev->name); | ||
1258 | netif_wake_queue(dev); | ||
1259 | } | ||
1260 | spin_unlock_irqrestore(&port->queue_lock, flags); | ||
1261 | } | ||
1262 | } | ||
1263 | |||
1264 | static void veth_stop_queues(struct veth_lpar_connection *cnx) | ||
1265 | { | ||
1266 | int i; | ||
1267 | |||
1268 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) { | ||
1269 | struct net_device *dev = veth_dev[i]; | ||
1270 | struct veth_port *port; | ||
1271 | |||
1272 | if (! dev) | ||
1273 | continue; | ||
1274 | |||
1275 | port = netdev_priv(dev); | ||
1276 | |||
1277 | /* If this cnx is not on the vlan for this port, continue */ | ||
1278 | if (! (port->lpar_map & (1 << cnx->remote_lp))) | ||
1279 | continue; | ||
1280 | |||
1281 | spin_lock(&port->queue_lock); | ||
1282 | |||
1283 | netif_stop_queue(dev); | ||
1284 | port->stopped_map |= (1 << cnx->remote_lp); | ||
1285 | |||
1286 | veth_debug("cnx %d: stopped queue for %s, map = 0x%x.\n", | ||
1287 | cnx->remote_lp, dev->name, port->stopped_map); | ||
1288 | |||
1289 | spin_unlock(&port->queue_lock); | ||
1290 | } | ||
1291 | } | ||
1292 | |||
1293 | static void veth_timed_reset(unsigned long ptr) | ||
1294 | { | ||
1295 | struct veth_lpar_connection *cnx = (struct veth_lpar_connection *)ptr; | ||
1296 | unsigned long trigger_time, flags; | ||
1297 | |||
1298 | /* FIXME is it possible this fires after veth_stop_connection()? | ||
1299 | * That would reschedule the statemachine for 5 seconds and probably | ||
1300 | * execute it after the module's been unloaded. Hmm. */ | ||
1301 | |||
1302 | spin_lock_irqsave(&cnx->lock, flags); | ||
1303 | |||
1304 | if (cnx->outstanding_tx > 0) { | ||
1305 | trigger_time = cnx->last_contact + cnx->reset_timeout; | ||
1306 | |||
1307 | if (trigger_time < jiffies) { | ||
1308 | cnx->state |= VETH_STATE_RESET; | ||
1309 | veth_kick_statemachine(cnx); | ||
1310 | veth_error("%d packets not acked by LPAR %d within %d " | ||
1311 | "seconds, resetting.\n", | ||
1312 | cnx->outstanding_tx, cnx->remote_lp, | ||
1313 | cnx->reset_timeout / HZ); | ||
1314 | } else { | ||
1315 | /* Reschedule the timer */ | ||
1316 | trigger_time = jiffies + cnx->reset_timeout; | ||
1317 | mod_timer(&cnx->reset_timer, trigger_time); | ||
1318 | } | ||
1319 | } | ||
1320 | |||
1321 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
1322 | } | ||
1323 | |||
1324 | /* | ||
1325 | * Rx path | ||
1326 | */ | ||
1327 | |||
1328 | static inline int veth_frame_wanted(struct veth_port *port, u64 mac_addr) | ||
1329 | { | ||
1330 | int wanted = 0; | ||
1331 | int i; | ||
1332 | unsigned long flags; | ||
1333 | |||
1334 | if ( (mac_addr == port->mac_addr) || (mac_addr == 0xffffffffffff0000) ) | ||
1335 | return 1; | ||
1336 | |||
1337 | read_lock_irqsave(&port->mcast_gate, flags); | ||
1338 | |||
1339 | if (port->promiscuous) { | ||
1340 | wanted = 1; | ||
1341 | goto out; | ||
1342 | } | ||
1343 | |||
1344 | for (i = 0; i < port->num_mcast; ++i) { | ||
1345 | if (port->mcast_addr[i] == mac_addr) { | ||
1346 | wanted = 1; | ||
1347 | break; | ||
1348 | } | ||
1349 | } | ||
1350 | |||
1351 | out: | ||
1352 | read_unlock_irqrestore(&port->mcast_gate, flags); | ||
1353 | |||
1354 | return wanted; | ||
1355 | } | ||
1356 | |||
1357 | struct dma_chunk { | ||
1358 | u64 addr; | ||
1359 | u64 size; | ||
1360 | }; | ||
1361 | |||
1362 | #define VETH_MAX_PAGES_PER_FRAME ( (VETH_MAX_MTU+PAGE_SIZE-2)/PAGE_SIZE + 1 ) | ||
1363 | |||
1364 | static inline void veth_build_dma_list(struct dma_chunk *list, | ||
1365 | unsigned char *p, unsigned long length) | ||
1366 | { | ||
1367 | unsigned long done; | ||
1368 | int i = 1; | ||
1369 | |||
1370 | /* FIXME: skbs are contiguous in real addresses. Do we | ||
1371 | * really need to break it into PAGE_SIZE chunks, or can we do | ||
1372 | * it just at the granularity of iSeries real->absolute | ||
1373 | * mapping? Indeed, given the way the allocator works, can we | ||
1374 | * count on them being absolutely contiguous? */ | ||
1375 | list[0].addr = iseries_hv_addr(p); | ||
1376 | list[0].size = min(length, | ||
1377 | PAGE_SIZE - ((unsigned long)p & ~PAGE_MASK)); | ||
1378 | |||
1379 | done = list[0].size; | ||
1380 | while (done < length) { | ||
1381 | list[i].addr = iseries_hv_addr(p + done); | ||
1382 | list[i].size = min(length-done, PAGE_SIZE); | ||
1383 | done += list[i].size; | ||
1384 | i++; | ||
1385 | } | ||
1386 | } | ||
1387 | |||
1388 | static void veth_flush_acks(struct veth_lpar_connection *cnx) | ||
1389 | { | ||
1390 | HvLpEvent_Rc rc; | ||
1391 | |||
1392 | rc = veth_signaldata(cnx, VETH_EVENT_FRAMES_ACK, | ||
1393 | 0, &cnx->pending_acks); | ||
1394 | |||
1395 | if (rc != HvLpEvent_Rc_Good) | ||
1396 | veth_error("Failed acking frames from LPAR %d, rc = %d\n", | ||
1397 | cnx->remote_lp, (int)rc); | ||
1398 | |||
1399 | cnx->num_pending_acks = 0; | ||
1400 | memset(&cnx->pending_acks, 0xff, sizeof(cnx->pending_acks)); | ||
1401 | } | ||
1402 | |||
1403 | static void veth_receive(struct veth_lpar_connection *cnx, | ||
1404 | struct veth_lpevent *event) | ||
1405 | { | ||
1406 | struct veth_frames_data *senddata = &event->u.frames_data; | ||
1407 | int startchunk = 0; | ||
1408 | int nchunks; | ||
1409 | unsigned long flags; | ||
1410 | HvLpDma_Rc rc; | ||
1411 | |||
1412 | do { | ||
1413 | u16 length = 0; | ||
1414 | struct sk_buff *skb; | ||
1415 | struct dma_chunk local_list[VETH_MAX_PAGES_PER_FRAME]; | ||
1416 | struct dma_chunk remote_list[VETH_MAX_FRAMES_PER_MSG]; | ||
1417 | u64 dest; | ||
1418 | HvLpVirtualLanIndex vlan; | ||
1419 | struct net_device *dev; | ||
1420 | struct veth_port *port; | ||
1421 | |||
1422 | /* FIXME: do we need this? */ | ||
1423 | memset(local_list, 0, sizeof(local_list)); | ||
1424 | memset(remote_list, 0, sizeof(VETH_MAX_FRAMES_PER_MSG)); | ||
1425 | |||
1426 | /* a 0 address marks the end of the valid entries */ | ||
1427 | if (senddata->addr[startchunk] == 0) | ||
1428 | break; | ||
1429 | |||
1430 | /* make sure that we have at least 1 EOF entry in the | ||
1431 | * remaining entries */ | ||
1432 | if (! (senddata->eofmask >> (startchunk + VETH_EOF_SHIFT))) { | ||
1433 | veth_error("Missing EOF fragment in event " | ||
1434 | "eofmask = 0x%x startchunk = %d\n", | ||
1435 | (unsigned)senddata->eofmask, | ||
1436 | startchunk); | ||
1437 | break; | ||
1438 | } | ||
1439 | |||
1440 | /* build list of chunks in this frame */ | ||
1441 | nchunks = 0; | ||
1442 | do { | ||
1443 | remote_list[nchunks].addr = | ||
1444 | (u64) senddata->addr[startchunk+nchunks] << 32; | ||
1445 | remote_list[nchunks].size = | ||
1446 | senddata->len[startchunk+nchunks]; | ||
1447 | length += remote_list[nchunks].size; | ||
1448 | } while (! (senddata->eofmask & | ||
1449 | (1 << (VETH_EOF_SHIFT + startchunk + nchunks++)))); | ||
1450 | |||
1451 | /* length == total length of all chunks */ | ||
1452 | /* nchunks == # of chunks in this frame */ | ||
1453 | |||
1454 | if ((length - ETH_HLEN) > VETH_MAX_MTU) { | ||
1455 | veth_error("Received oversize frame from LPAR %d " | ||
1456 | "(length = %d)\n", | ||
1457 | cnx->remote_lp, length); | ||
1458 | continue; | ||
1459 | } | ||
1460 | |||
1461 | skb = alloc_skb(length, GFP_ATOMIC); | ||
1462 | if (!skb) | ||
1463 | continue; | ||
1464 | |||
1465 | veth_build_dma_list(local_list, skb->data, length); | ||
1466 | |||
1467 | rc = HvCallEvent_dmaBufList(HvLpEvent_Type_VirtualLan, | ||
1468 | event->base_event.xSourceLp, | ||
1469 | HvLpDma_Direction_RemoteToLocal, | ||
1470 | cnx->src_inst, | ||
1471 | cnx->dst_inst, | ||
1472 | HvLpDma_AddressType_RealAddress, | ||
1473 | HvLpDma_AddressType_TceIndex, | ||
1474 | iseries_hv_addr(&local_list), | ||
1475 | iseries_hv_addr(&remote_list), | ||
1476 | length); | ||
1477 | if (rc != HvLpDma_Rc_Good) { | ||
1478 | dev_kfree_skb_irq(skb); | ||
1479 | continue; | ||
1480 | } | ||
1481 | |||
1482 | vlan = skb->data[9]; | ||
1483 | dev = veth_dev[vlan]; | ||
1484 | if (! dev) { | ||
1485 | /* | ||
1486 | * Some earlier versions of the driver sent | ||
1487 | * broadcasts down all connections, even to lpars | ||
1488 | * that weren't on the relevant vlan. So ignore | ||
1489 | * packets belonging to a vlan we're not on. | ||
1490 | * We can also be here if we receive packets while | ||
1491 | * the driver is going down, because then dev is NULL. | ||
1492 | */ | ||
1493 | dev_kfree_skb_irq(skb); | ||
1494 | continue; | ||
1495 | } | ||
1496 | |||
1497 | port = netdev_priv(dev); | ||
1498 | dest = *((u64 *) skb->data) & 0xFFFFFFFFFFFF0000; | ||
1499 | |||
1500 | if ((vlan > HVMAXARCHITECTEDVIRTUALLANS) || !port) { | ||
1501 | dev_kfree_skb_irq(skb); | ||
1502 | continue; | ||
1503 | } | ||
1504 | if (! veth_frame_wanted(port, dest)) { | ||
1505 | dev_kfree_skb_irq(skb); | ||
1506 | continue; | ||
1507 | } | ||
1508 | |||
1509 | skb_put(skb, length); | ||
1510 | skb->protocol = eth_type_trans(skb, dev); | ||
1511 | skb_checksum_none_assert(skb); | ||
1512 | netif_rx(skb); /* send it up */ | ||
1513 | dev->stats.rx_packets++; | ||
1514 | dev->stats.rx_bytes += length; | ||
1515 | } while (startchunk += nchunks, startchunk < VETH_MAX_FRAMES_PER_MSG); | ||
1516 | |||
1517 | /* Ack it */ | ||
1518 | spin_lock_irqsave(&cnx->lock, flags); | ||
1519 | BUG_ON(cnx->num_pending_acks > VETH_MAX_ACKS_PER_MSG); | ||
1520 | |||
1521 | cnx->pending_acks[cnx->num_pending_acks++] = | ||
1522 | event->base_event.xCorrelationToken; | ||
1523 | |||
1524 | if ( (cnx->num_pending_acks >= cnx->remote_caps.ack_threshold) || | ||
1525 | (cnx->num_pending_acks >= VETH_MAX_ACKS_PER_MSG) ) | ||
1526 | veth_flush_acks(cnx); | ||
1527 | |||
1528 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
1529 | } | ||
1530 | |||
1531 | static void veth_timed_ack(unsigned long ptr) | ||
1532 | { | ||
1533 | struct veth_lpar_connection *cnx = (struct veth_lpar_connection *) ptr; | ||
1534 | unsigned long flags; | ||
1535 | |||
1536 | /* Ack all the events */ | ||
1537 | spin_lock_irqsave(&cnx->lock, flags); | ||
1538 | if (cnx->num_pending_acks > 0) | ||
1539 | veth_flush_acks(cnx); | ||
1540 | |||
1541 | /* Reschedule the timer */ | ||
1542 | cnx->ack_timer.expires = jiffies + cnx->ack_timeout; | ||
1543 | add_timer(&cnx->ack_timer); | ||
1544 | spin_unlock_irqrestore(&cnx->lock, flags); | ||
1545 | } | ||
1546 | |||
1547 | static int veth_remove(struct vio_dev *vdev) | ||
1548 | { | ||
1549 | struct veth_lpar_connection *cnx; | ||
1550 | struct net_device *dev; | ||
1551 | struct veth_port *port; | ||
1552 | int i; | ||
1553 | |||
1554 | dev = veth_dev[vdev->unit_address]; | ||
1555 | |||
1556 | if (! dev) | ||
1557 | return 0; | ||
1558 | |||
1559 | port = netdev_priv(dev); | ||
1560 | |||
1561 | for (i = 0; i < HVMAXARCHITECTEDLPS; i++) { | ||
1562 | cnx = veth_cnx[i]; | ||
1563 | |||
1564 | if (cnx && (port->lpar_map & (1 << i))) { | ||
1565 | /* Drop our reference to connections on our VLAN */ | ||
1566 | kobject_put(&cnx->kobject); | ||
1567 | } | ||
1568 | } | ||
1569 | |||
1570 | veth_dev[vdev->unit_address] = NULL; | ||
1571 | kobject_del(&port->kobject); | ||
1572 | kobject_put(&port->kobject); | ||
1573 | unregister_netdev(dev); | ||
1574 | free_netdev(dev); | ||
1575 | |||
1576 | return 0; | ||
1577 | } | ||
1578 | |||
1579 | static int veth_probe(struct vio_dev *vdev, const struct vio_device_id *id) | ||
1580 | { | ||
1581 | int i = vdev->unit_address; | ||
1582 | struct net_device *dev; | ||
1583 | struct veth_port *port; | ||
1584 | |||
1585 | dev = veth_probe_one(i, vdev); | ||
1586 | if (dev == NULL) { | ||
1587 | veth_remove(vdev); | ||
1588 | return 1; | ||
1589 | } | ||
1590 | veth_dev[i] = dev; | ||
1591 | |||
1592 | port = netdev_priv(dev); | ||
1593 | |||
1594 | /* Start the state machine on each connection on this vlan. If we're | ||
1595 | * the first dev to do so this will commence link negotiation */ | ||
1596 | for (i = 0; i < HVMAXARCHITECTEDLPS; i++) { | ||
1597 | struct veth_lpar_connection *cnx; | ||
1598 | |||
1599 | if (! (port->lpar_map & (1 << i))) | ||
1600 | continue; | ||
1601 | |||
1602 | cnx = veth_cnx[i]; | ||
1603 | if (!cnx) | ||
1604 | continue; | ||
1605 | |||
1606 | kobject_get(&cnx->kobject); | ||
1607 | veth_kick_statemachine(cnx); | ||
1608 | } | ||
1609 | |||
1610 | return 0; | ||
1611 | } | ||
1612 | |||
1613 | /** | ||
1614 | * veth_device_table: Used by vio.c to match devices that we | ||
1615 | * support. | ||
1616 | */ | ||
1617 | static struct vio_device_id veth_device_table[] __devinitdata = { | ||
1618 | { "network", "IBM,iSeries-l-lan" }, | ||
1619 | { "", "" } | ||
1620 | }; | ||
1621 | MODULE_DEVICE_TABLE(vio, veth_device_table); | ||
1622 | |||
1623 | static struct vio_driver veth_driver = { | ||
1624 | .id_table = veth_device_table, | ||
1625 | .probe = veth_probe, | ||
1626 | .remove = veth_remove, | ||
1627 | .driver = { | ||
1628 | .name = DRV_NAME, | ||
1629 | .owner = THIS_MODULE, | ||
1630 | } | ||
1631 | }; | ||
1632 | |||
1633 | /* | ||
1634 | * Module initialization/cleanup | ||
1635 | */ | ||
1636 | |||
1637 | static void __exit veth_module_cleanup(void) | ||
1638 | { | ||
1639 | int i; | ||
1640 | struct veth_lpar_connection *cnx; | ||
1641 | |||
1642 | /* Disconnect our "irq" to stop events coming from the Hypervisor. */ | ||
1643 | HvLpEvent_unregisterHandler(HvLpEvent_Type_VirtualLan); | ||
1644 | |||
1645 | for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) { | ||
1646 | cnx = veth_cnx[i]; | ||
1647 | |||
1648 | if (!cnx) | ||
1649 | continue; | ||
1650 | |||
1651 | /* Cancel work queued from Hypervisor callbacks */ | ||
1652 | cancel_delayed_work_sync(&cnx->statemachine_wq); | ||
1653 | /* Remove the connection from sysfs */ | ||
1654 | kobject_del(&cnx->kobject); | ||
1655 | /* Drop the driver's reference to the connection */ | ||
1656 | kobject_put(&cnx->kobject); | ||
1657 | } | ||
1658 | |||
1659 | /* Unregister the driver, which will close all the netdevs and stop | ||
1660 | * the connections when they're no longer referenced. */ | ||
1661 | vio_unregister_driver(&veth_driver); | ||
1662 | } | ||
1663 | module_exit(veth_module_cleanup); | ||
1664 | |||
1665 | static int __init veth_module_init(void) | ||
1666 | { | ||
1667 | int i; | ||
1668 | int rc; | ||
1669 | |||
1670 | if (!firmware_has_feature(FW_FEATURE_ISERIES)) | ||
1671 | return -ENODEV; | ||
1672 | |||
1673 | this_lp = HvLpConfig_getLpIndex_outline(); | ||
1674 | |||
1675 | for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) { | ||
1676 | rc = veth_init_connection(i); | ||
1677 | if (rc != 0) | ||
1678 | goto error; | ||
1679 | } | ||
1680 | |||
1681 | HvLpEvent_registerHandler(HvLpEvent_Type_VirtualLan, | ||
1682 | &veth_handle_event); | ||
1683 | |||
1684 | rc = vio_register_driver(&veth_driver); | ||
1685 | if (rc != 0) | ||
1686 | goto error; | ||
1687 | |||
1688 | for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) { | ||
1689 | struct kobject *kobj; | ||
1690 | |||
1691 | if (!veth_cnx[i]) | ||
1692 | continue; | ||
1693 | |||
1694 | kobj = &veth_cnx[i]->kobject; | ||
1695 | /* If the add failes, complain but otherwise continue */ | ||
1696 | if (0 != driver_add_kobj(&veth_driver.driver, kobj, | ||
1697 | "cnx%.2d", veth_cnx[i]->remote_lp)) | ||
1698 | veth_error("cnx %d: Failed adding to sysfs.\n", i); | ||
1699 | } | ||
1700 | |||
1701 | return 0; | ||
1702 | |||
1703 | error: | ||
1704 | for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) { | ||
1705 | veth_destroy_connection(veth_cnx[i]); | ||
1706 | } | ||
1707 | |||
1708 | return rc; | ||
1709 | } | ||
1710 | module_init(veth_module_init); | ||