1 // SPDX-License-Identifier: GPL-2.0-only
3 * FUJITSU Extended Socket Network Device driver
4 * Copyright (c) 2015 FUJITSU LIMITED
9 #include "fjes_trace.h"
11 static void fjes_hw_update_zone_task(struct work_struct
*);
12 static void fjes_hw_epstop_task(struct work_struct
*);
14 /* supported MTU list */
15 const u32 fjes_support_mtu
[] = {
16 FJES_MTU_DEFINE(8 * 1024),
17 FJES_MTU_DEFINE(16 * 1024),
18 FJES_MTU_DEFINE(32 * 1024),
19 FJES_MTU_DEFINE(64 * 1024),
23 u32
fjes_hw_rd32(struct fjes_hw
*hw
, u32 reg
)
28 value
= readl(&base
[reg
]);
33 static u8
*fjes_hw_iomap(struct fjes_hw
*hw
)
37 if (!request_mem_region(hw
->hw_res
.start
, hw
->hw_res
.size
,
39 pr_err("request_mem_region failed\n");
43 base
= (u8
*)ioremap(hw
->hw_res
.start
, hw
->hw_res
.size
);
48 static void fjes_hw_iounmap(struct fjes_hw
*hw
)
51 release_mem_region(hw
->hw_res
.start
, hw
->hw_res
.size
);
54 int fjes_hw_reset(struct fjes_hw
*hw
)
61 wr32(XSCT_DCTL
, dctl
.reg
);
63 timeout
= FJES_DEVICE_RESET_TIMEOUT
* 1000;
64 dctl
.reg
= rd32(XSCT_DCTL
);
65 while ((dctl
.bits
.reset
== 1) && (timeout
> 0)) {
67 dctl
.reg
= rd32(XSCT_DCTL
);
71 return timeout
> 0 ? 0 : -EIO
;
74 static int fjes_hw_get_max_epid(struct fjes_hw
*hw
)
76 union REG_MAX_EP info
;
78 info
.reg
= rd32(XSCT_MAX_EP
);
80 return info
.bits
.maxep
;
83 static int fjes_hw_get_my_epid(struct fjes_hw
*hw
)
85 union REG_OWNER_EPID info
;
87 info
.reg
= rd32(XSCT_OWNER_EPID
);
89 return info
.bits
.epid
;
92 static int fjes_hw_alloc_shared_status_region(struct fjes_hw
*hw
)
96 size
= sizeof(struct fjes_device_shared_info
) +
97 (sizeof(u8
) * hw
->max_epid
);
98 hw
->hw_info
.share
= kzalloc(size
, GFP_KERNEL
);
99 if (!hw
->hw_info
.share
)
102 hw
->hw_info
.share
->epnum
= hw
->max_epid
;
107 static void fjes_hw_free_shared_status_region(struct fjes_hw
*hw
)
109 kfree(hw
->hw_info
.share
);
110 hw
->hw_info
.share
= NULL
;
113 static int fjes_hw_alloc_epbuf(struct epbuf_handler
*epbh
)
117 mem
= vzalloc(EP_BUFFER_SIZE
);
122 epbh
->size
= EP_BUFFER_SIZE
;
124 epbh
->info
= (union ep_buffer_info
*)mem
;
125 epbh
->ring
= (u8
*)(mem
+ sizeof(union ep_buffer_info
));
130 static void fjes_hw_free_epbuf(struct epbuf_handler
*epbh
)
140 void fjes_hw_setup_epbuf(struct epbuf_handler
*epbh
, const u8
*mac_addr
,
143 union ep_buffer_info
*info
= epbh
->info
;
144 u16 vlan_id
[EP_BUFFER_SUPPORT_VLAN_MAX
];
147 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++)
148 vlan_id
[i
] = info
->v1i
.vlan_id
[i
];
150 memset(info
, 0, sizeof(union ep_buffer_info
));
152 info
->v1i
.version
= 0; /* version 0 */
154 for (i
= 0; i
< ETH_ALEN
; i
++)
155 info
->v1i
.mac_addr
[i
] = mac_addr
[i
];
160 info
->v1i
.info_size
= sizeof(union ep_buffer_info
);
161 info
->v1i
.buffer_size
= epbh
->size
- info
->v1i
.info_size
;
163 info
->v1i
.frame_max
= FJES_MTU_TO_FRAME_SIZE(mtu
);
164 info
->v1i
.count_max
=
165 EP_RING_NUM(info
->v1i
.buffer_size
, info
->v1i
.frame_max
);
167 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++)
168 info
->v1i
.vlan_id
[i
] = vlan_id
[i
];
170 info
->v1i
.rx_status
|= FJES_RX_MTU_CHANGING_DONE
;
174 fjes_hw_init_command_registers(struct fjes_hw
*hw
,
175 struct fjes_device_command_param
*param
)
177 /* Request Buffer length */
178 wr32(XSCT_REQBL
, (__le32
)(param
->req_len
));
179 /* Response Buffer Length */
180 wr32(XSCT_RESPBL
, (__le32
)(param
->res_len
));
182 /* Request Buffer Address */
184 (__le32
)(param
->req_start
& GENMASK_ULL(31, 0)));
186 (__le32
)((param
->req_start
& GENMASK_ULL(63, 32)) >> 32));
188 /* Response Buffer Address */
190 (__le32
)(param
->res_start
& GENMASK_ULL(31, 0)));
192 (__le32
)((param
->res_start
& GENMASK_ULL(63, 32)) >> 32));
194 /* Share status address */
196 (__le32
)(param
->share_start
& GENMASK_ULL(31, 0)));
198 (__le32
)((param
->share_start
& GENMASK_ULL(63, 32)) >> 32));
201 static int fjes_hw_setup(struct fjes_hw
*hw
)
203 u8 mac
[ETH_ALEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
204 struct fjes_device_command_param param
;
205 struct ep_share_mem_info
*buf_pair
;
212 hw
->hw_info
.max_epid
= &hw
->max_epid
;
213 hw
->hw_info
.my_epid
= &hw
->my_epid
;
215 buf
= kcalloc(hw
->max_epid
, sizeof(struct ep_share_mem_info
),
220 hw
->ep_shm_info
= (struct ep_share_mem_info
*)buf
;
222 mem_size
= FJES_DEV_REQ_BUF_SIZE(hw
->max_epid
);
223 hw
->hw_info
.req_buf
= kzalloc(mem_size
, GFP_KERNEL
);
224 if (!(hw
->hw_info
.req_buf
)) {
229 hw
->hw_info
.req_buf_size
= mem_size
;
231 mem_size
= FJES_DEV_RES_BUF_SIZE(hw
->max_epid
);
232 hw
->hw_info
.res_buf
= kzalloc(mem_size
, GFP_KERNEL
);
233 if (!(hw
->hw_info
.res_buf
)) {
238 hw
->hw_info
.res_buf_size
= mem_size
;
240 result
= fjes_hw_alloc_shared_status_region(hw
);
244 hw
->hw_info
.buffer_share_bit
= 0;
245 hw
->hw_info
.buffer_unshare_reserve_bit
= 0;
247 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
248 if (epidx
!= hw
->my_epid
) {
249 buf_pair
= &hw
->ep_shm_info
[epidx
];
251 result
= fjes_hw_alloc_epbuf(&buf_pair
->tx
);
255 result
= fjes_hw_alloc_epbuf(&buf_pair
->rx
);
259 spin_lock_irqsave(&hw
->rx_status_lock
, flags
);
260 fjes_hw_setup_epbuf(&buf_pair
->tx
, mac
,
261 fjes_support_mtu
[0]);
262 fjes_hw_setup_epbuf(&buf_pair
->rx
, mac
,
263 fjes_support_mtu
[0]);
264 spin_unlock_irqrestore(&hw
->rx_status_lock
, flags
);
268 memset(¶m
, 0, sizeof(param
));
270 param
.req_len
= hw
->hw_info
.req_buf_size
;
271 param
.req_start
= __pa(hw
->hw_info
.req_buf
);
272 param
.res_len
= hw
->hw_info
.res_buf_size
;
273 param
.res_start
= __pa(hw
->hw_info
.res_buf
);
275 param
.share_start
= __pa(hw
->hw_info
.share
->ep_status
);
277 fjes_hw_init_command_registers(hw
, ¶m
);
282 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
283 if (epidx
== hw
->my_epid
)
285 fjes_hw_free_epbuf(&hw
->ep_shm_info
[epidx
].tx
);
286 fjes_hw_free_epbuf(&hw
->ep_shm_info
[epidx
].rx
);
288 fjes_hw_free_shared_status_region(hw
);
290 kfree(hw
->hw_info
.res_buf
);
291 hw
->hw_info
.res_buf
= NULL
;
293 kfree(hw
->hw_info
.req_buf
);
294 hw
->hw_info
.req_buf
= NULL
;
296 kfree(hw
->ep_shm_info
);
297 hw
->ep_shm_info
= NULL
;
301 static void fjes_hw_cleanup(struct fjes_hw
*hw
)
305 if (!hw
->ep_shm_info
)
308 fjes_hw_free_shared_status_region(hw
);
310 kfree(hw
->hw_info
.req_buf
);
311 hw
->hw_info
.req_buf
= NULL
;
313 kfree(hw
->hw_info
.res_buf
);
314 hw
->hw_info
.res_buf
= NULL
;
316 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
317 if (epidx
== hw
->my_epid
)
319 fjes_hw_free_epbuf(&hw
->ep_shm_info
[epidx
].tx
);
320 fjes_hw_free_epbuf(&hw
->ep_shm_info
[epidx
].rx
);
323 kfree(hw
->ep_shm_info
);
324 hw
->ep_shm_info
= NULL
;
327 int fjes_hw_init(struct fjes_hw
*hw
)
331 hw
->base
= fjes_hw_iomap(hw
);
335 ret
= fjes_hw_reset(hw
);
339 fjes_hw_set_irqmask(hw
, REG_ICTL_MASK_ALL
, true);
341 INIT_WORK(&hw
->update_zone_task
, fjes_hw_update_zone_task
);
342 INIT_WORK(&hw
->epstop_task
, fjes_hw_epstop_task
);
344 mutex_init(&hw
->hw_info
.lock
);
345 spin_lock_init(&hw
->rx_status_lock
);
347 hw
->max_epid
= fjes_hw_get_max_epid(hw
);
348 hw
->my_epid
= fjes_hw_get_my_epid(hw
);
350 if ((hw
->max_epid
== 0) || (hw
->my_epid
>= hw
->max_epid
))
353 ret
= fjes_hw_setup(hw
);
355 hw
->hw_info
.trace
= vzalloc(FJES_DEBUG_BUFFER_SIZE
);
356 hw
->hw_info
.trace_size
= FJES_DEBUG_BUFFER_SIZE
;
361 void fjes_hw_exit(struct fjes_hw
*hw
)
367 if (hw
->debug_mode
) {
368 /* disable debug mode */
369 mutex_lock(&hw
->hw_info
.lock
);
370 fjes_hw_stop_debug(hw
);
371 mutex_unlock(&hw
->hw_info
.lock
);
373 vfree(hw
->hw_info
.trace
);
374 hw
->hw_info
.trace
= NULL
;
375 hw
->hw_info
.trace_size
= 0;
378 ret
= fjes_hw_reset(hw
);
380 pr_err("%s: reset error", __func__
);
388 cancel_work_sync(&hw
->update_zone_task
);
389 cancel_work_sync(&hw
->epstop_task
);
392 static enum fjes_dev_command_response_e
393 fjes_hw_issue_request_command(struct fjes_hw
*hw
,
394 enum fjes_dev_command_request_type type
)
396 enum fjes_dev_command_response_e ret
= FJES_CMD_STATUS_UNKNOWN
;
399 int timeout
= FJES_COMMAND_REQ_TIMEOUT
* 1000;
402 cr
.bits
.req_start
= 1;
403 cr
.bits
.req_code
= type
;
404 wr32(XSCT_CR
, cr
.reg
);
405 cr
.reg
= rd32(XSCT_CR
);
407 if (cr
.bits
.error
== 0) {
408 timeout
= FJES_COMMAND_REQ_TIMEOUT
* 1000;
409 cs
.reg
= rd32(XSCT_CS
);
411 while ((cs
.bits
.complete
!= 1) && timeout
> 0) {
413 cs
.reg
= rd32(XSCT_CS
);
417 if (cs
.bits
.complete
== 1)
418 ret
= FJES_CMD_STATUS_NORMAL
;
419 else if (timeout
<= 0)
420 ret
= FJES_CMD_STATUS_TIMEOUT
;
423 switch (cr
.bits
.err_info
) {
424 case FJES_CMD_REQ_ERR_INFO_PARAM
:
425 ret
= FJES_CMD_STATUS_ERROR_PARAM
;
427 case FJES_CMD_REQ_ERR_INFO_STATUS
:
428 ret
= FJES_CMD_STATUS_ERROR_STATUS
;
431 ret
= FJES_CMD_STATUS_UNKNOWN
;
436 trace_fjes_hw_issue_request_command(&cr
, &cs
, timeout
, ret
);
441 int fjes_hw_request_info(struct fjes_hw
*hw
)
443 union fjes_device_command_req
*req_buf
= hw
->hw_info
.req_buf
;
444 union fjes_device_command_res
*res_buf
= hw
->hw_info
.res_buf
;
445 enum fjes_dev_command_response_e ret
;
448 memset(req_buf
, 0, hw
->hw_info
.req_buf_size
);
449 memset(res_buf
, 0, hw
->hw_info
.res_buf_size
);
451 req_buf
->info
.length
= FJES_DEV_COMMAND_INFO_REQ_LEN
;
453 res_buf
->info
.length
= 0;
454 res_buf
->info
.code
= 0;
456 ret
= fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_INFO
);
457 trace_fjes_hw_request_info(hw
, res_buf
);
461 if (FJES_DEV_COMMAND_INFO_RES_LEN((*hw
->hw_info
.max_epid
)) !=
462 res_buf
->info
.length
) {
463 trace_fjes_hw_request_info_err("Invalid res_buf");
465 } else if (ret
== FJES_CMD_STATUS_NORMAL
) {
466 switch (res_buf
->info
.code
) {
467 case FJES_CMD_REQ_RES_CODE_NORMAL
:
476 case FJES_CMD_STATUS_UNKNOWN
:
479 case FJES_CMD_STATUS_TIMEOUT
:
480 trace_fjes_hw_request_info_err("Timeout");
483 case FJES_CMD_STATUS_ERROR_PARAM
:
486 case FJES_CMD_STATUS_ERROR_STATUS
:
498 int fjes_hw_register_buff_addr(struct fjes_hw
*hw
, int dest_epid
,
499 struct ep_share_mem_info
*buf_pair
)
501 union fjes_device_command_req
*req_buf
= hw
->hw_info
.req_buf
;
502 union fjes_device_command_res
*res_buf
= hw
->hw_info
.res_buf
;
503 enum fjes_dev_command_response_e ret
;
510 if (test_bit(dest_epid
, &hw
->hw_info
.buffer_share_bit
))
513 memset(req_buf
, 0, hw
->hw_info
.req_buf_size
);
514 memset(res_buf
, 0, hw
->hw_info
.res_buf_size
);
516 req_buf
->share_buffer
.length
= FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(
519 req_buf
->share_buffer
.epid
= dest_epid
;
522 req_buf
->share_buffer
.buffer
[idx
++] = buf_pair
->tx
.size
;
523 page_count
= buf_pair
->tx
.size
/ EP_BUFFER_INFO_SIZE
;
524 for (i
= 0; i
< page_count
; i
++) {
525 addr
= ((u8
*)(buf_pair
->tx
.buffer
)) +
526 (i
* EP_BUFFER_INFO_SIZE
);
527 req_buf
->share_buffer
.buffer
[idx
++] =
528 (__le64
)(page_to_phys(vmalloc_to_page(addr
)) +
529 offset_in_page(addr
));
532 req_buf
->share_buffer
.buffer
[idx
++] = buf_pair
->rx
.size
;
533 page_count
= buf_pair
->rx
.size
/ EP_BUFFER_INFO_SIZE
;
534 for (i
= 0; i
< page_count
; i
++) {
535 addr
= ((u8
*)(buf_pair
->rx
.buffer
)) +
536 (i
* EP_BUFFER_INFO_SIZE
);
537 req_buf
->share_buffer
.buffer
[idx
++] =
538 (__le64
)(page_to_phys(vmalloc_to_page(addr
)) +
539 offset_in_page(addr
));
542 res_buf
->share_buffer
.length
= 0;
543 res_buf
->share_buffer
.code
= 0;
545 trace_fjes_hw_register_buff_addr_req(req_buf
, buf_pair
);
547 ret
= fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_SHARE_BUFFER
);
549 timeout
= FJES_COMMAND_REQ_BUFF_TIMEOUT
* 1000;
550 while ((ret
== FJES_CMD_STATUS_NORMAL
) &&
551 (res_buf
->share_buffer
.length
==
552 FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN
) &&
553 (res_buf
->share_buffer
.code
== FJES_CMD_REQ_RES_CODE_BUSY
) &&
555 msleep(200 + hw
->my_epid
* 20);
556 timeout
-= (200 + hw
->my_epid
* 20);
558 res_buf
->share_buffer
.length
= 0;
559 res_buf
->share_buffer
.code
= 0;
561 ret
= fjes_hw_issue_request_command(
562 hw
, FJES_CMD_REQ_SHARE_BUFFER
);
567 trace_fjes_hw_register_buff_addr(res_buf
, timeout
);
569 if (res_buf
->share_buffer
.length
!=
570 FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN
) {
571 trace_fjes_hw_register_buff_addr_err("Invalid res_buf");
573 } else if (ret
== FJES_CMD_STATUS_NORMAL
) {
574 switch (res_buf
->share_buffer
.code
) {
575 case FJES_CMD_REQ_RES_CODE_NORMAL
:
577 set_bit(dest_epid
, &hw
->hw_info
.buffer_share_bit
);
579 case FJES_CMD_REQ_RES_CODE_BUSY
:
580 trace_fjes_hw_register_buff_addr_err("Busy Timeout");
589 case FJES_CMD_STATUS_UNKNOWN
:
592 case FJES_CMD_STATUS_TIMEOUT
:
593 trace_fjes_hw_register_buff_addr_err("Timeout");
596 case FJES_CMD_STATUS_ERROR_PARAM
:
597 case FJES_CMD_STATUS_ERROR_STATUS
:
607 int fjes_hw_unregister_buff_addr(struct fjes_hw
*hw
, int dest_epid
)
609 union fjes_device_command_req
*req_buf
= hw
->hw_info
.req_buf
;
610 union fjes_device_command_res
*res_buf
= hw
->hw_info
.res_buf
;
611 struct fjes_device_shared_info
*share
= hw
->hw_info
.share
;
612 enum fjes_dev_command_response_e ret
;
619 if (!req_buf
|| !res_buf
|| !share
)
622 if (!test_bit(dest_epid
, &hw
->hw_info
.buffer_share_bit
))
625 memset(req_buf
, 0, hw
->hw_info
.req_buf_size
);
626 memset(res_buf
, 0, hw
->hw_info
.res_buf_size
);
628 req_buf
->unshare_buffer
.length
=
629 FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN
;
630 req_buf
->unshare_buffer
.epid
= dest_epid
;
632 res_buf
->unshare_buffer
.length
= 0;
633 res_buf
->unshare_buffer
.code
= 0;
635 trace_fjes_hw_unregister_buff_addr_req(req_buf
);
636 ret
= fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_UNSHARE_BUFFER
);
638 timeout
= FJES_COMMAND_REQ_BUFF_TIMEOUT
* 1000;
639 while ((ret
== FJES_CMD_STATUS_NORMAL
) &&
640 (res_buf
->unshare_buffer
.length
==
641 FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN
) &&
642 (res_buf
->unshare_buffer
.code
==
643 FJES_CMD_REQ_RES_CODE_BUSY
) &&
645 msleep(200 + hw
->my_epid
* 20);
646 timeout
-= (200 + hw
->my_epid
* 20);
648 res_buf
->unshare_buffer
.length
= 0;
649 res_buf
->unshare_buffer
.code
= 0;
652 fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_UNSHARE_BUFFER
);
657 trace_fjes_hw_unregister_buff_addr(res_buf
, timeout
);
659 if (res_buf
->unshare_buffer
.length
!=
660 FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN
) {
661 trace_fjes_hw_unregister_buff_addr_err("Invalid res_buf");
663 } else if (ret
== FJES_CMD_STATUS_NORMAL
) {
664 switch (res_buf
->unshare_buffer
.code
) {
665 case FJES_CMD_REQ_RES_CODE_NORMAL
:
667 clear_bit(dest_epid
, &hw
->hw_info
.buffer_share_bit
);
669 case FJES_CMD_REQ_RES_CODE_BUSY
:
670 trace_fjes_hw_unregister_buff_addr_err("Busy Timeout");
679 case FJES_CMD_STATUS_UNKNOWN
:
682 case FJES_CMD_STATUS_TIMEOUT
:
683 trace_fjes_hw_unregister_buff_addr_err("Timeout");
686 case FJES_CMD_STATUS_ERROR_PARAM
:
687 case FJES_CMD_STATUS_ERROR_STATUS
:
697 int fjes_hw_raise_interrupt(struct fjes_hw
*hw
, int dest_epid
,
698 enum REG_ICTL_MASK mask
)
700 u32 ig
= mask
| dest_epid
;
702 wr32(XSCT_IG
, cpu_to_le32(ig
));
707 u32
fjes_hw_capture_interrupt_status(struct fjes_hw
*hw
)
711 cur_is
= rd32(XSCT_IS
);
716 void fjes_hw_set_irqmask(struct fjes_hw
*hw
,
717 enum REG_ICTL_MASK intr_mask
, bool mask
)
720 wr32(XSCT_IMS
, intr_mask
);
722 wr32(XSCT_IMC
, intr_mask
);
725 bool fjes_hw_epid_is_same_zone(struct fjes_hw
*hw
, int epid
)
727 if (epid
>= hw
->max_epid
)
730 if ((hw
->ep_shm_info
[epid
].es_status
!=
731 FJES_ZONING_STATUS_ENABLE
) ||
732 (hw
->ep_shm_info
[hw
->my_epid
].zone
==
733 FJES_ZONING_ZONE_TYPE_NONE
))
736 return (hw
->ep_shm_info
[epid
].zone
==
737 hw
->ep_shm_info
[hw
->my_epid
].zone
);
740 int fjes_hw_epid_is_shared(struct fjes_device_shared_info
*share
,
745 if (dest_epid
< share
->epnum
)
746 value
= share
->ep_status
[dest_epid
];
751 static bool fjes_hw_epid_is_stop_requested(struct fjes_hw
*hw
, int src_epid
)
753 return test_bit(src_epid
, &hw
->txrx_stop_req_bit
);
756 static bool fjes_hw_epid_is_stop_process_done(struct fjes_hw
*hw
, int src_epid
)
758 return (hw
->ep_shm_info
[src_epid
].tx
.info
->v1i
.rx_status
&
759 FJES_RX_STOP_REQ_DONE
);
762 enum ep_partner_status
763 fjes_hw_get_partner_ep_status(struct fjes_hw
*hw
, int epid
)
765 enum ep_partner_status status
;
767 if (fjes_hw_epid_is_shared(hw
->hw_info
.share
, epid
)) {
768 if (fjes_hw_epid_is_stop_requested(hw
, epid
)) {
769 status
= EP_PARTNER_WAITING
;
771 if (fjes_hw_epid_is_stop_process_done(hw
, epid
))
772 status
= EP_PARTNER_COMPLETE
;
774 status
= EP_PARTNER_SHARED
;
777 status
= EP_PARTNER_UNSHARE
;
783 void fjes_hw_raise_epstop(struct fjes_hw
*hw
)
785 enum ep_partner_status status
;
789 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
790 if (epidx
== hw
->my_epid
)
793 status
= fjes_hw_get_partner_ep_status(hw
, epidx
);
795 case EP_PARTNER_SHARED
:
796 fjes_hw_raise_interrupt(hw
, epidx
,
797 REG_ICTL_MASK_TXRX_STOP_REQ
);
798 hw
->ep_shm_info
[epidx
].ep_stats
.send_intr_unshare
+= 1;
804 set_bit(epidx
, &hw
->hw_info
.buffer_unshare_reserve_bit
);
805 set_bit(epidx
, &hw
->txrx_stop_req_bit
);
807 spin_lock_irqsave(&hw
->rx_status_lock
, flags
);
808 hw
->ep_shm_info
[epidx
].tx
.info
->v1i
.rx_status
|=
809 FJES_RX_STOP_REQ_REQUEST
;
810 spin_unlock_irqrestore(&hw
->rx_status_lock
, flags
);
814 int fjes_hw_wait_epstop(struct fjes_hw
*hw
)
816 enum ep_partner_status status
;
817 union ep_buffer_info
*info
;
821 while (hw
->hw_info
.buffer_unshare_reserve_bit
&&
822 (wait_time
< FJES_COMMAND_EPSTOP_WAIT_TIMEOUT
* 1000)) {
823 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
824 if (epidx
== hw
->my_epid
)
826 status
= fjes_hw_epid_is_shared(hw
->hw_info
.share
,
828 info
= hw
->ep_shm_info
[epidx
].rx
.info
;
830 (info
->v1i
.rx_status
&
831 FJES_RX_STOP_REQ_DONE
)) &&
833 &hw
->hw_info
.buffer_unshare_reserve_bit
)) {
835 &hw
->hw_info
.buffer_unshare_reserve_bit
);
843 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
844 if (epidx
== hw
->my_epid
)
846 if (test_bit(epidx
, &hw
->hw_info
.buffer_unshare_reserve_bit
))
848 &hw
->hw_info
.buffer_unshare_reserve_bit
);
851 return (wait_time
< FJES_COMMAND_EPSTOP_WAIT_TIMEOUT
* 1000)
855 bool fjes_hw_check_epbuf_version(struct epbuf_handler
*epbh
, u32 version
)
857 union ep_buffer_info
*info
= epbh
->info
;
859 return (info
->common
.version
== version
);
862 bool fjes_hw_check_mtu(struct epbuf_handler
*epbh
, u32 mtu
)
864 union ep_buffer_info
*info
= epbh
->info
;
866 return ((info
->v1i
.frame_max
== FJES_MTU_TO_FRAME_SIZE(mtu
)) &&
867 info
->v1i
.rx_status
& FJES_RX_MTU_CHANGING_DONE
);
870 bool fjes_hw_check_vlan_id(struct epbuf_handler
*epbh
, u16 vlan_id
)
872 union ep_buffer_info
*info
= epbh
->info
;
879 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++) {
880 if (vlan_id
== info
->v1i
.vlan_id
[i
]) {
889 bool fjes_hw_set_vlan_id(struct epbuf_handler
*epbh
, u16 vlan_id
)
891 union ep_buffer_info
*info
= epbh
->info
;
894 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++) {
895 if (info
->v1i
.vlan_id
[i
] == 0) {
896 info
->v1i
.vlan_id
[i
] = vlan_id
;
903 void fjes_hw_del_vlan_id(struct epbuf_handler
*epbh
, u16 vlan_id
)
905 union ep_buffer_info
*info
= epbh
->info
;
909 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++) {
910 if (vlan_id
== info
->v1i
.vlan_id
[i
])
911 info
->v1i
.vlan_id
[i
] = 0;
916 bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler
*epbh
)
918 union ep_buffer_info
*info
= epbh
->info
;
920 if (!(info
->v1i
.rx_status
& FJES_RX_MTU_CHANGING_DONE
))
923 if (info
->v1i
.count_max
== 0)
926 return EP_RING_EMPTY(info
->v1i
.head
, info
->v1i
.tail
,
927 info
->v1i
.count_max
);
930 void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler
*epbh
,
933 union ep_buffer_info
*info
= epbh
->info
;
934 struct esmem_frame
*ring_frame
;
937 ring_frame
= (struct esmem_frame
*)&(epbh
->ring
[EP_RING_INDEX
939 info
->v1i
.count_max
) *
940 info
->v1i
.frame_max
]);
942 *psize
= (size_t)ring_frame
->frame_size
;
944 frame
= ring_frame
->frame_data
;
949 void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler
*epbh
)
951 union ep_buffer_info
*info
= epbh
->info
;
953 if (fjes_hw_epbuf_rx_is_empty(epbh
))
956 EP_RING_INDEX_INC(epbh
->info
->v1i
.head
, info
->v1i
.count_max
);
959 int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler
*epbh
,
960 void *frame
, size_t size
)
962 union ep_buffer_info
*info
= epbh
->info
;
963 struct esmem_frame
*ring_frame
;
965 if (EP_RING_FULL(info
->v1i
.head
, info
->v1i
.tail
, info
->v1i
.count_max
))
968 ring_frame
= (struct esmem_frame
*)&(epbh
->ring
[EP_RING_INDEX
970 info
->v1i
.count_max
) *
971 info
->v1i
.frame_max
]);
973 ring_frame
->frame_size
= size
;
974 memcpy((void *)(ring_frame
->frame_data
), (void *)frame
, size
);
976 EP_RING_INDEX_INC(epbh
->info
->v1i
.tail
, info
->v1i
.count_max
);
981 static void fjes_hw_update_zone_task(struct work_struct
*work
)
983 struct fjes_hw
*hw
= container_of(work
,
984 struct fjes_hw
, update_zone_task
);
986 struct my_s
{u8 es_status
; u8 zone
; } *info
;
987 union fjes_device_command_res
*res_buf
;
988 enum ep_partner_status pstatus
;
990 struct fjes_adapter
*adapter
;
991 struct net_device
*netdev
;
994 ulong unshare_bit
= 0;
1001 adapter
= (struct fjes_adapter
*)hw
->back
;
1002 netdev
= adapter
->netdev
;
1003 res_buf
= hw
->hw_info
.res_buf
;
1004 info
= (struct my_s
*)&res_buf
->info
.info
;
1006 mutex_lock(&hw
->hw_info
.lock
);
1008 ret
= fjes_hw_request_info(hw
);
1013 if (!work_pending(&adapter
->force_close_task
)) {
1014 adapter
->force_reset
= true;
1015 schedule_work(&adapter
->force_close_task
);
1021 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
1022 if (epidx
== hw
->my_epid
) {
1023 hw
->ep_shm_info
[epidx
].es_status
=
1024 info
[epidx
].es_status
;
1025 hw
->ep_shm_info
[epidx
].zone
=
1030 pstatus
= fjes_hw_get_partner_ep_status(hw
, epidx
);
1032 case EP_PARTNER_UNSHARE
:
1034 if ((info
[epidx
].zone
!=
1035 FJES_ZONING_ZONE_TYPE_NONE
) &&
1036 (info
[epidx
].es_status
==
1037 FJES_ZONING_STATUS_ENABLE
) &&
1038 (info
[epidx
].zone
==
1039 info
[hw
->my_epid
].zone
))
1040 set_bit(epidx
, &share_bit
);
1042 set_bit(epidx
, &unshare_bit
);
1045 case EP_PARTNER_COMPLETE
:
1046 case EP_PARTNER_WAITING
:
1047 if ((info
[epidx
].zone
==
1048 FJES_ZONING_ZONE_TYPE_NONE
) ||
1049 (info
[epidx
].es_status
!=
1050 FJES_ZONING_STATUS_ENABLE
) ||
1051 (info
[epidx
].zone
!=
1052 info
[hw
->my_epid
].zone
)) {
1054 &adapter
->unshare_watch_bitmask
);
1056 &hw
->hw_info
.buffer_unshare_reserve_bit
);
1060 case EP_PARTNER_SHARED
:
1061 if ((info
[epidx
].zone
==
1062 FJES_ZONING_ZONE_TYPE_NONE
) ||
1063 (info
[epidx
].es_status
!=
1064 FJES_ZONING_STATUS_ENABLE
) ||
1065 (info
[epidx
].zone
!=
1066 info
[hw
->my_epid
].zone
))
1067 set_bit(epidx
, &irq_bit
);
1071 hw
->ep_shm_info
[epidx
].es_status
=
1072 info
[epidx
].es_status
;
1073 hw
->ep_shm_info
[epidx
].zone
= info
[epidx
].zone
;
1078 mutex_unlock(&hw
->hw_info
.lock
);
1080 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
1081 if (epidx
== hw
->my_epid
)
1084 if (test_bit(epidx
, &share_bit
)) {
1085 spin_lock_irqsave(&hw
->rx_status_lock
, flags
);
1086 fjes_hw_setup_epbuf(&hw
->ep_shm_info
[epidx
].tx
,
1087 netdev
->dev_addr
, netdev
->mtu
);
1088 spin_unlock_irqrestore(&hw
->rx_status_lock
, flags
);
1090 mutex_lock(&hw
->hw_info
.lock
);
1092 ret
= fjes_hw_register_buff_addr(
1093 hw
, epidx
, &hw
->ep_shm_info
[epidx
]);
1101 if (!work_pending(&adapter
->force_close_task
)) {
1102 adapter
->force_reset
= true;
1104 &adapter
->force_close_task
);
1108 mutex_unlock(&hw
->hw_info
.lock
);
1110 hw
->ep_shm_info
[epidx
].ep_stats
1111 .com_regist_buf_exec
+= 1;
1114 if (test_bit(epidx
, &unshare_bit
)) {
1115 mutex_lock(&hw
->hw_info
.lock
);
1117 ret
= fjes_hw_unregister_buff_addr(hw
, epidx
);
1125 if (!work_pending(&adapter
->force_close_task
)) {
1126 adapter
->force_reset
= true;
1128 &adapter
->force_close_task
);
1133 mutex_unlock(&hw
->hw_info
.lock
);
1135 hw
->ep_shm_info
[epidx
].ep_stats
1136 .com_unregist_buf_exec
+= 1;
1139 spin_lock_irqsave(&hw
->rx_status_lock
, flags
);
1140 fjes_hw_setup_epbuf(
1141 &hw
->ep_shm_info
[epidx
].tx
,
1142 netdev
->dev_addr
, netdev
->mtu
);
1143 spin_unlock_irqrestore(&hw
->rx_status_lock
,
1148 if (test_bit(epidx
, &irq_bit
)) {
1149 fjes_hw_raise_interrupt(hw
, epidx
,
1150 REG_ICTL_MASK_TXRX_STOP_REQ
);
1152 hw
->ep_shm_info
[epidx
].ep_stats
.send_intr_unshare
+= 1;
1154 set_bit(epidx
, &hw
->txrx_stop_req_bit
);
1155 spin_lock_irqsave(&hw
->rx_status_lock
, flags
);
1156 hw
->ep_shm_info
[epidx
].tx
.
1157 info
->v1i
.rx_status
|=
1158 FJES_RX_STOP_REQ_REQUEST
;
1159 spin_unlock_irqrestore(&hw
->rx_status_lock
, flags
);
1160 set_bit(epidx
, &hw
->hw_info
.buffer_unshare_reserve_bit
);
1164 if (irq_bit
|| adapter
->unshare_watch_bitmask
) {
1165 if (!work_pending(&adapter
->unshare_watch_task
))
1166 queue_work(adapter
->control_wq
,
1167 &adapter
->unshare_watch_task
);
1171 static void fjes_hw_epstop_task(struct work_struct
*work
)
1173 struct fjes_hw
*hw
= container_of(work
, struct fjes_hw
, epstop_task
);
1174 struct fjes_adapter
*adapter
= (struct fjes_adapter
*)hw
->back
;
1175 unsigned long flags
;
1180 while ((remain_bit
= hw
->epstop_req_bit
)) {
1181 for (epid_bit
= 0; remain_bit
; remain_bit
>>= 1, epid_bit
++) {
1182 if (remain_bit
& 1) {
1183 spin_lock_irqsave(&hw
->rx_status_lock
, flags
);
1184 hw
->ep_shm_info
[epid_bit
].
1185 tx
.info
->v1i
.rx_status
|=
1186 FJES_RX_STOP_REQ_DONE
;
1187 spin_unlock_irqrestore(&hw
->rx_status_lock
,
1190 clear_bit(epid_bit
, &hw
->epstop_req_bit
);
1192 &adapter
->unshare_watch_bitmask
);
1194 if (!work_pending(&adapter
->unshare_watch_task
))
1196 adapter
->control_wq
,
1197 &adapter
->unshare_watch_task
);
1203 int fjes_hw_start_debug(struct fjes_hw
*hw
)
1205 union fjes_device_command_req
*req_buf
= hw
->hw_info
.req_buf
;
1206 union fjes_device_command_res
*res_buf
= hw
->hw_info
.res_buf
;
1207 enum fjes_dev_command_response_e ret
;
1213 if (!hw
->hw_info
.trace
)
1215 memset(hw
->hw_info
.trace
, 0, FJES_DEBUG_BUFFER_SIZE
);
1217 memset(req_buf
, 0, hw
->hw_info
.req_buf_size
);
1218 memset(res_buf
, 0, hw
->hw_info
.res_buf_size
);
1220 req_buf
->start_trace
.length
=
1221 FJES_DEV_COMMAND_START_DBG_REQ_LEN(hw
->hw_info
.trace_size
);
1222 req_buf
->start_trace
.mode
= hw
->debug_mode
;
1223 req_buf
->start_trace
.buffer_len
= hw
->hw_info
.trace_size
;
1224 page_count
= hw
->hw_info
.trace_size
/ FJES_DEBUG_PAGE_SIZE
;
1225 for (i
= 0; i
< page_count
; i
++) {
1226 addr
= ((u8
*)hw
->hw_info
.trace
) + i
* FJES_DEBUG_PAGE_SIZE
;
1227 req_buf
->start_trace
.buffer
[i
] =
1228 (__le64
)(page_to_phys(vmalloc_to_page(addr
)) +
1229 offset_in_page(addr
));
1232 res_buf
->start_trace
.length
= 0;
1233 res_buf
->start_trace
.code
= 0;
1235 trace_fjes_hw_start_debug_req(req_buf
);
1236 ret
= fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_START_DEBUG
);
1237 trace_fjes_hw_start_debug(res_buf
);
1239 if (res_buf
->start_trace
.length
!=
1240 FJES_DEV_COMMAND_START_DBG_RES_LEN
) {
1242 trace_fjes_hw_start_debug_err("Invalid res_buf");
1243 } else if (ret
== FJES_CMD_STATUS_NORMAL
) {
1244 switch (res_buf
->start_trace
.code
) {
1245 case FJES_CMD_REQ_RES_CODE_NORMAL
:
1254 case FJES_CMD_STATUS_UNKNOWN
:
1257 case FJES_CMD_STATUS_TIMEOUT
:
1258 trace_fjes_hw_start_debug_err("Busy Timeout");
1261 case FJES_CMD_STATUS_ERROR_PARAM
:
1262 case FJES_CMD_STATUS_ERROR_STATUS
:
1272 int fjes_hw_stop_debug(struct fjes_hw
*hw
)
1274 union fjes_device_command_req
*req_buf
= hw
->hw_info
.req_buf
;
1275 union fjes_device_command_res
*res_buf
= hw
->hw_info
.res_buf
;
1276 enum fjes_dev_command_response_e ret
;
1279 if (!hw
->hw_info
.trace
)
1282 memset(req_buf
, 0, hw
->hw_info
.req_buf_size
);
1283 memset(res_buf
, 0, hw
->hw_info
.res_buf_size
);
1284 req_buf
->stop_trace
.length
= FJES_DEV_COMMAND_STOP_DBG_REQ_LEN
;
1286 res_buf
->stop_trace
.length
= 0;
1287 res_buf
->stop_trace
.code
= 0;
1289 ret
= fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_STOP_DEBUG
);
1290 trace_fjes_hw_stop_debug(res_buf
);
1292 if (res_buf
->stop_trace
.length
!= FJES_DEV_COMMAND_STOP_DBG_RES_LEN
) {
1293 trace_fjes_hw_stop_debug_err("Invalid res_buf");
1295 } else if (ret
== FJES_CMD_STATUS_NORMAL
) {
1296 switch (res_buf
->stop_trace
.code
) {
1297 case FJES_CMD_REQ_RES_CODE_NORMAL
:
1307 case FJES_CMD_STATUS_UNKNOWN
:
1310 case FJES_CMD_STATUS_TIMEOUT
:
1312 trace_fjes_hw_stop_debug_err("Busy Timeout");
1314 case FJES_CMD_STATUS_ERROR_PARAM
:
1315 case FJES_CMD_STATUS_ERROR_STATUS
: