2 * FUJITSU Extended Socket Network Device driver
3 * Copyright (c) 2015 FUJITSU LIMITED
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see <http://www.gnu.org/licenses/>.
17 * The full GNU General Public License is included in this distribution in
18 * the file called "COPYING".
25 static void fjes_hw_update_zone_task(struct work_struct
*);
26 static void fjes_hw_epstop_task(struct work_struct
*);
28 /* supported MTU list */
29 const u32 fjes_support_mtu
[] = {
30 FJES_MTU_DEFINE(8 * 1024),
31 FJES_MTU_DEFINE(16 * 1024),
32 FJES_MTU_DEFINE(32 * 1024),
33 FJES_MTU_DEFINE(64 * 1024),
37 u32
fjes_hw_rd32(struct fjes_hw
*hw
, u32 reg
)
42 value
= readl(&base
[reg
]);
47 static u8
*fjes_hw_iomap(struct fjes_hw
*hw
)
51 if (!request_mem_region(hw
->hw_res
.start
, hw
->hw_res
.size
,
53 pr_err("request_mem_region failed\n");
57 base
= (u8
*)ioremap_nocache(hw
->hw_res
.start
, hw
->hw_res
.size
);
62 static void fjes_hw_iounmap(struct fjes_hw
*hw
)
65 release_mem_region(hw
->hw_res
.start
, hw
->hw_res
.size
);
68 int fjes_hw_reset(struct fjes_hw
*hw
)
75 wr32(XSCT_DCTL
, dctl
.reg
);
77 timeout
= FJES_DEVICE_RESET_TIMEOUT
* 1000;
78 dctl
.reg
= rd32(XSCT_DCTL
);
79 while ((dctl
.bits
.reset
== 1) && (timeout
> 0)) {
81 dctl
.reg
= rd32(XSCT_DCTL
);
85 return timeout
> 0 ? 0 : -EIO
;
88 static int fjes_hw_get_max_epid(struct fjes_hw
*hw
)
90 union REG_MAX_EP info
;
92 info
.reg
= rd32(XSCT_MAX_EP
);
94 return info
.bits
.maxep
;
97 static int fjes_hw_get_my_epid(struct fjes_hw
*hw
)
99 union REG_OWNER_EPID info
;
101 info
.reg
= rd32(XSCT_OWNER_EPID
);
103 return info
.bits
.epid
;
106 static int fjes_hw_alloc_shared_status_region(struct fjes_hw
*hw
)
110 size
= sizeof(struct fjes_device_shared_info
) +
111 (sizeof(u8
) * hw
->max_epid
);
112 hw
->hw_info
.share
= kzalloc(size
, GFP_KERNEL
);
113 if (!hw
->hw_info
.share
)
116 hw
->hw_info
.share
->epnum
= hw
->max_epid
;
121 static void fjes_hw_free_shared_status_region(struct fjes_hw
*hw
)
123 kfree(hw
->hw_info
.share
);
124 hw
->hw_info
.share
= NULL
;
127 static int fjes_hw_alloc_epbuf(struct epbuf_handler
*epbh
)
131 mem
= vzalloc(EP_BUFFER_SIZE
);
136 epbh
->size
= EP_BUFFER_SIZE
;
138 epbh
->info
= (union ep_buffer_info
*)mem
;
139 epbh
->ring
= (u8
*)(mem
+ sizeof(union ep_buffer_info
));
144 static void fjes_hw_free_epbuf(struct epbuf_handler
*epbh
)
154 void fjes_hw_setup_epbuf(struct epbuf_handler
*epbh
, u8
*mac_addr
, u32 mtu
)
156 union ep_buffer_info
*info
= epbh
->info
;
157 u16 vlan_id
[EP_BUFFER_SUPPORT_VLAN_MAX
];
160 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++)
161 vlan_id
[i
] = info
->v1i
.vlan_id
[i
];
163 memset(info
, 0, sizeof(union ep_buffer_info
));
165 info
->v1i
.version
= 0; /* version 0 */
167 for (i
= 0; i
< ETH_ALEN
; i
++)
168 info
->v1i
.mac_addr
[i
] = mac_addr
[i
];
173 info
->v1i
.info_size
= sizeof(union ep_buffer_info
);
174 info
->v1i
.buffer_size
= epbh
->size
- info
->v1i
.info_size
;
176 info
->v1i
.frame_max
= FJES_MTU_TO_FRAME_SIZE(mtu
);
177 info
->v1i
.count_max
=
178 EP_RING_NUM(info
->v1i
.buffer_size
, info
->v1i
.frame_max
);
180 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++)
181 info
->v1i
.vlan_id
[i
] = vlan_id
[i
];
185 fjes_hw_init_command_registers(struct fjes_hw
*hw
,
186 struct fjes_device_command_param
*param
)
188 /* Request Buffer length */
189 wr32(XSCT_REQBL
, (__le32
)(param
->req_len
));
190 /* Response Buffer Length */
191 wr32(XSCT_RESPBL
, (__le32
)(param
->res_len
));
193 /* Request Buffer Address */
195 (__le32
)(param
->req_start
& GENMASK_ULL(31, 0)));
197 (__le32
)((param
->req_start
& GENMASK_ULL(63, 32)) >> 32));
199 /* Response Buffer Address */
201 (__le32
)(param
->res_start
& GENMASK_ULL(31, 0)));
203 (__le32
)((param
->res_start
& GENMASK_ULL(63, 32)) >> 32));
205 /* Share status address */
207 (__le32
)(param
->share_start
& GENMASK_ULL(31, 0)));
209 (__le32
)((param
->share_start
& GENMASK_ULL(63, 32)) >> 32));
212 static int fjes_hw_setup(struct fjes_hw
*hw
)
214 u8 mac
[ETH_ALEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
215 struct fjes_device_command_param param
;
216 struct ep_share_mem_info
*buf_pair
;
222 hw
->hw_info
.max_epid
= &hw
->max_epid
;
223 hw
->hw_info
.my_epid
= &hw
->my_epid
;
225 buf
= kcalloc(hw
->max_epid
, sizeof(struct ep_share_mem_info
),
230 hw
->ep_shm_info
= (struct ep_share_mem_info
*)buf
;
232 mem_size
= FJES_DEV_REQ_BUF_SIZE(hw
->max_epid
);
233 hw
->hw_info
.req_buf
= kzalloc(mem_size
, GFP_KERNEL
);
234 if (!(hw
->hw_info
.req_buf
))
237 hw
->hw_info
.req_buf_size
= mem_size
;
239 mem_size
= FJES_DEV_RES_BUF_SIZE(hw
->max_epid
);
240 hw
->hw_info
.res_buf
= kzalloc(mem_size
, GFP_KERNEL
);
241 if (!(hw
->hw_info
.res_buf
))
244 hw
->hw_info
.res_buf_size
= mem_size
;
246 result
= fjes_hw_alloc_shared_status_region(hw
);
250 hw
->hw_info
.buffer_share_bit
= 0;
251 hw
->hw_info
.buffer_unshare_reserve_bit
= 0;
253 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
254 if (epidx
!= hw
->my_epid
) {
255 buf_pair
= &hw
->ep_shm_info
[epidx
];
257 result
= fjes_hw_alloc_epbuf(&buf_pair
->tx
);
261 result
= fjes_hw_alloc_epbuf(&buf_pair
->rx
);
265 fjes_hw_setup_epbuf(&buf_pair
->tx
, mac
,
266 fjes_support_mtu
[0]);
267 fjes_hw_setup_epbuf(&buf_pair
->rx
, mac
,
268 fjes_support_mtu
[0]);
272 memset(¶m
, 0, sizeof(param
));
274 param
.req_len
= hw
->hw_info
.req_buf_size
;
275 param
.req_start
= __pa(hw
->hw_info
.req_buf
);
276 param
.res_len
= hw
->hw_info
.res_buf_size
;
277 param
.res_start
= __pa(hw
->hw_info
.res_buf
);
279 param
.share_start
= __pa(hw
->hw_info
.share
->ep_status
);
281 fjes_hw_init_command_registers(hw
, ¶m
);
286 static void fjes_hw_cleanup(struct fjes_hw
*hw
)
290 if (!hw
->ep_shm_info
)
293 fjes_hw_free_shared_status_region(hw
);
295 kfree(hw
->hw_info
.req_buf
);
296 hw
->hw_info
.req_buf
= NULL
;
298 kfree(hw
->hw_info
.res_buf
);
299 hw
->hw_info
.res_buf
= NULL
;
301 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
302 if (epidx
== hw
->my_epid
)
304 fjes_hw_free_epbuf(&hw
->ep_shm_info
[epidx
].tx
);
305 fjes_hw_free_epbuf(&hw
->ep_shm_info
[epidx
].rx
);
308 kfree(hw
->ep_shm_info
);
309 hw
->ep_shm_info
= NULL
;
312 int fjes_hw_init(struct fjes_hw
*hw
)
316 hw
->base
= fjes_hw_iomap(hw
);
320 ret
= fjes_hw_reset(hw
);
324 fjes_hw_set_irqmask(hw
, REG_ICTL_MASK_ALL
, true);
326 INIT_WORK(&hw
->update_zone_task
, fjes_hw_update_zone_task
);
327 INIT_WORK(&hw
->epstop_task
, fjes_hw_epstop_task
);
329 mutex_init(&hw
->hw_info
.lock
);
331 hw
->max_epid
= fjes_hw_get_max_epid(hw
);
332 hw
->my_epid
= fjes_hw_get_my_epid(hw
);
334 if ((hw
->max_epid
== 0) || (hw
->my_epid
>= hw
->max_epid
))
337 ret
= fjes_hw_setup(hw
);
342 void fjes_hw_exit(struct fjes_hw
*hw
)
347 ret
= fjes_hw_reset(hw
);
349 pr_err("%s: reset error", __func__
);
357 cancel_work_sync(&hw
->update_zone_task
);
358 cancel_work_sync(&hw
->epstop_task
);
361 static enum fjes_dev_command_response_e
362 fjes_hw_issue_request_command(struct fjes_hw
*hw
,
363 enum fjes_dev_command_request_type type
)
365 enum fjes_dev_command_response_e ret
= FJES_CMD_STATUS_UNKNOWN
;
371 cr
.bits
.req_start
= 1;
372 cr
.bits
.req_code
= type
;
373 wr32(XSCT_CR
, cr
.reg
);
374 cr
.reg
= rd32(XSCT_CR
);
376 if (cr
.bits
.error
== 0) {
377 timeout
= FJES_COMMAND_REQ_TIMEOUT
* 1000;
378 cs
.reg
= rd32(XSCT_CS
);
380 while ((cs
.bits
.complete
!= 1) && timeout
> 0) {
382 cs
.reg
= rd32(XSCT_CS
);
386 if (cs
.bits
.complete
== 1)
387 ret
= FJES_CMD_STATUS_NORMAL
;
388 else if (timeout
<= 0)
389 ret
= FJES_CMD_STATUS_TIMEOUT
;
392 switch (cr
.bits
.err_info
) {
393 case FJES_CMD_REQ_ERR_INFO_PARAM
:
394 ret
= FJES_CMD_STATUS_ERROR_PARAM
;
396 case FJES_CMD_REQ_ERR_INFO_STATUS
:
397 ret
= FJES_CMD_STATUS_ERROR_STATUS
;
400 ret
= FJES_CMD_STATUS_UNKNOWN
;
408 int fjes_hw_request_info(struct fjes_hw
*hw
)
410 union fjes_device_command_req
*req_buf
= hw
->hw_info
.req_buf
;
411 union fjes_device_command_res
*res_buf
= hw
->hw_info
.res_buf
;
412 enum fjes_dev_command_response_e ret
;
415 memset(req_buf
, 0, hw
->hw_info
.req_buf_size
);
416 memset(res_buf
, 0, hw
->hw_info
.res_buf_size
);
418 req_buf
->info
.length
= FJES_DEV_COMMAND_INFO_REQ_LEN
;
420 res_buf
->info
.length
= 0;
421 res_buf
->info
.code
= 0;
423 ret
= fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_INFO
);
427 if (FJES_DEV_COMMAND_INFO_RES_LEN((*hw
->hw_info
.max_epid
)) !=
428 res_buf
->info
.length
) {
430 } else if (ret
== FJES_CMD_STATUS_NORMAL
) {
431 switch (res_buf
->info
.code
) {
432 case FJES_CMD_REQ_RES_CODE_NORMAL
:
441 case FJES_CMD_STATUS_UNKNOWN
:
444 case FJES_CMD_STATUS_TIMEOUT
:
447 case FJES_CMD_STATUS_ERROR_PARAM
:
450 case FJES_CMD_STATUS_ERROR_STATUS
:
462 int fjes_hw_register_buff_addr(struct fjes_hw
*hw
, int dest_epid
,
463 struct ep_share_mem_info
*buf_pair
)
465 union fjes_device_command_req
*req_buf
= hw
->hw_info
.req_buf
;
466 union fjes_device_command_res
*res_buf
= hw
->hw_info
.res_buf
;
467 enum fjes_dev_command_response_e ret
;
474 if (test_bit(dest_epid
, &hw
->hw_info
.buffer_share_bit
))
477 memset(req_buf
, 0, hw
->hw_info
.req_buf_size
);
478 memset(res_buf
, 0, hw
->hw_info
.res_buf_size
);
480 req_buf
->share_buffer
.length
= FJES_DEV_COMMAND_SHARE_BUFFER_REQ_LEN(
483 req_buf
->share_buffer
.epid
= dest_epid
;
486 req_buf
->share_buffer
.buffer
[idx
++] = buf_pair
->tx
.size
;
487 page_count
= buf_pair
->tx
.size
/ EP_BUFFER_INFO_SIZE
;
488 for (i
= 0; i
< page_count
; i
++) {
489 addr
= ((u8
*)(buf_pair
->tx
.buffer
)) +
490 (i
* EP_BUFFER_INFO_SIZE
);
491 req_buf
->share_buffer
.buffer
[idx
++] =
492 (__le64
)(page_to_phys(vmalloc_to_page(addr
)) +
493 offset_in_page(addr
));
496 req_buf
->share_buffer
.buffer
[idx
++] = buf_pair
->rx
.size
;
497 page_count
= buf_pair
->rx
.size
/ EP_BUFFER_INFO_SIZE
;
498 for (i
= 0; i
< page_count
; i
++) {
499 addr
= ((u8
*)(buf_pair
->rx
.buffer
)) +
500 (i
* EP_BUFFER_INFO_SIZE
);
501 req_buf
->share_buffer
.buffer
[idx
++] =
502 (__le64
)(page_to_phys(vmalloc_to_page(addr
)) +
503 offset_in_page(addr
));
506 res_buf
->share_buffer
.length
= 0;
507 res_buf
->share_buffer
.code
= 0;
509 ret
= fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_SHARE_BUFFER
);
511 timeout
= FJES_COMMAND_REQ_BUFF_TIMEOUT
* 1000;
512 while ((ret
== FJES_CMD_STATUS_NORMAL
) &&
513 (res_buf
->share_buffer
.length
==
514 FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN
) &&
515 (res_buf
->share_buffer
.code
== FJES_CMD_REQ_RES_CODE_BUSY
) &&
517 msleep(200 + hw
->my_epid
* 20);
518 timeout
-= (200 + hw
->my_epid
* 20);
520 res_buf
->share_buffer
.length
= 0;
521 res_buf
->share_buffer
.code
= 0;
523 ret
= fjes_hw_issue_request_command(
524 hw
, FJES_CMD_REQ_SHARE_BUFFER
);
529 if (res_buf
->share_buffer
.length
!=
530 FJES_DEV_COMMAND_SHARE_BUFFER_RES_LEN
)
532 else if (ret
== FJES_CMD_STATUS_NORMAL
) {
533 switch (res_buf
->share_buffer
.code
) {
534 case FJES_CMD_REQ_RES_CODE_NORMAL
:
536 set_bit(dest_epid
, &hw
->hw_info
.buffer_share_bit
);
538 case FJES_CMD_REQ_RES_CODE_BUSY
:
547 case FJES_CMD_STATUS_UNKNOWN
:
550 case FJES_CMD_STATUS_TIMEOUT
:
553 case FJES_CMD_STATUS_ERROR_PARAM
:
554 case FJES_CMD_STATUS_ERROR_STATUS
:
564 int fjes_hw_unregister_buff_addr(struct fjes_hw
*hw
, int dest_epid
)
566 union fjes_device_command_req
*req_buf
= hw
->hw_info
.req_buf
;
567 union fjes_device_command_res
*res_buf
= hw
->hw_info
.res_buf
;
568 struct fjes_device_shared_info
*share
= hw
->hw_info
.share
;
569 enum fjes_dev_command_response_e ret
;
576 if (!req_buf
|| !res_buf
|| !share
)
579 if (!test_bit(dest_epid
, &hw
->hw_info
.buffer_share_bit
))
582 memset(req_buf
, 0, hw
->hw_info
.req_buf_size
);
583 memset(res_buf
, 0, hw
->hw_info
.res_buf_size
);
585 req_buf
->unshare_buffer
.length
=
586 FJES_DEV_COMMAND_UNSHARE_BUFFER_REQ_LEN
;
587 req_buf
->unshare_buffer
.epid
= dest_epid
;
589 res_buf
->unshare_buffer
.length
= 0;
590 res_buf
->unshare_buffer
.code
= 0;
592 ret
= fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_UNSHARE_BUFFER
);
594 timeout
= FJES_COMMAND_REQ_BUFF_TIMEOUT
* 1000;
595 while ((ret
== FJES_CMD_STATUS_NORMAL
) &&
596 (res_buf
->unshare_buffer
.length
==
597 FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN
) &&
598 (res_buf
->unshare_buffer
.code
==
599 FJES_CMD_REQ_RES_CODE_BUSY
) &&
601 msleep(200 + hw
->my_epid
* 20);
602 timeout
-= (200 + hw
->my_epid
* 20);
604 res_buf
->unshare_buffer
.length
= 0;
605 res_buf
->unshare_buffer
.code
= 0;
608 fjes_hw_issue_request_command(hw
, FJES_CMD_REQ_UNSHARE_BUFFER
);
613 if (res_buf
->unshare_buffer
.length
!=
614 FJES_DEV_COMMAND_UNSHARE_BUFFER_RES_LEN
) {
616 } else if (ret
== FJES_CMD_STATUS_NORMAL
) {
617 switch (res_buf
->unshare_buffer
.code
) {
618 case FJES_CMD_REQ_RES_CODE_NORMAL
:
620 clear_bit(dest_epid
, &hw
->hw_info
.buffer_share_bit
);
622 case FJES_CMD_REQ_RES_CODE_BUSY
:
631 case FJES_CMD_STATUS_UNKNOWN
:
634 case FJES_CMD_STATUS_TIMEOUT
:
637 case FJES_CMD_STATUS_ERROR_PARAM
:
638 case FJES_CMD_STATUS_ERROR_STATUS
:
648 int fjes_hw_raise_interrupt(struct fjes_hw
*hw
, int dest_epid
,
649 enum REG_ICTL_MASK mask
)
651 u32 ig
= mask
| dest_epid
;
653 wr32(XSCT_IG
, cpu_to_le32(ig
));
658 u32
fjes_hw_capture_interrupt_status(struct fjes_hw
*hw
)
662 cur_is
= rd32(XSCT_IS
);
667 void fjes_hw_set_irqmask(struct fjes_hw
*hw
,
668 enum REG_ICTL_MASK intr_mask
, bool mask
)
671 wr32(XSCT_IMS
, intr_mask
);
673 wr32(XSCT_IMC
, intr_mask
);
676 bool fjes_hw_epid_is_same_zone(struct fjes_hw
*hw
, int epid
)
678 if (epid
>= hw
->max_epid
)
681 if ((hw
->ep_shm_info
[epid
].es_status
!=
682 FJES_ZONING_STATUS_ENABLE
) ||
683 (hw
->ep_shm_info
[hw
->my_epid
].zone
==
684 FJES_ZONING_ZONE_TYPE_NONE
))
687 return (hw
->ep_shm_info
[epid
].zone
==
688 hw
->ep_shm_info
[hw
->my_epid
].zone
);
691 int fjes_hw_epid_is_shared(struct fjes_device_shared_info
*share
,
696 if (dest_epid
< share
->epnum
)
697 value
= share
->ep_status
[dest_epid
];
702 static bool fjes_hw_epid_is_stop_requested(struct fjes_hw
*hw
, int src_epid
)
704 return test_bit(src_epid
, &hw
->txrx_stop_req_bit
);
707 static bool fjes_hw_epid_is_stop_process_done(struct fjes_hw
*hw
, int src_epid
)
709 return (hw
->ep_shm_info
[src_epid
].tx
.info
->v1i
.rx_status
&
710 FJES_RX_STOP_REQ_DONE
);
713 enum ep_partner_status
714 fjes_hw_get_partner_ep_status(struct fjes_hw
*hw
, int epid
)
716 enum ep_partner_status status
;
718 if (fjes_hw_epid_is_shared(hw
->hw_info
.share
, epid
)) {
719 if (fjes_hw_epid_is_stop_requested(hw
, epid
)) {
720 status
= EP_PARTNER_WAITING
;
722 if (fjes_hw_epid_is_stop_process_done(hw
, epid
))
723 status
= EP_PARTNER_COMPLETE
;
725 status
= EP_PARTNER_SHARED
;
728 status
= EP_PARTNER_UNSHARE
;
734 void fjes_hw_raise_epstop(struct fjes_hw
*hw
)
736 enum ep_partner_status status
;
739 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
740 if (epidx
== hw
->my_epid
)
743 status
= fjes_hw_get_partner_ep_status(hw
, epidx
);
745 case EP_PARTNER_SHARED
:
746 fjes_hw_raise_interrupt(hw
, epidx
,
747 REG_ICTL_MASK_TXRX_STOP_REQ
);
753 set_bit(epidx
, &hw
->hw_info
.buffer_unshare_reserve_bit
);
754 set_bit(epidx
, &hw
->txrx_stop_req_bit
);
756 hw
->ep_shm_info
[epidx
].tx
.info
->v1i
.rx_status
|=
757 FJES_RX_STOP_REQ_REQUEST
;
761 int fjes_hw_wait_epstop(struct fjes_hw
*hw
)
763 enum ep_partner_status status
;
764 union ep_buffer_info
*info
;
768 while (hw
->hw_info
.buffer_unshare_reserve_bit
&&
769 (wait_time
< FJES_COMMAND_EPSTOP_WAIT_TIMEOUT
* 1000)) {
770 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
771 if (epidx
== hw
->my_epid
)
773 status
= fjes_hw_epid_is_shared(hw
->hw_info
.share
,
775 info
= hw
->ep_shm_info
[epidx
].rx
.info
;
777 (info
->v1i
.rx_status
&
778 FJES_RX_STOP_REQ_DONE
)) &&
780 &hw
->hw_info
.buffer_unshare_reserve_bit
)) {
782 &hw
->hw_info
.buffer_unshare_reserve_bit
);
790 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
791 if (epidx
== hw
->my_epid
)
793 if (test_bit(epidx
, &hw
->hw_info
.buffer_unshare_reserve_bit
))
795 &hw
->hw_info
.buffer_unshare_reserve_bit
);
798 return (wait_time
< FJES_COMMAND_EPSTOP_WAIT_TIMEOUT
* 1000)
802 bool fjes_hw_check_epbuf_version(struct epbuf_handler
*epbh
, u32 version
)
804 union ep_buffer_info
*info
= epbh
->info
;
806 return (info
->common
.version
== version
);
809 bool fjes_hw_check_mtu(struct epbuf_handler
*epbh
, u32 mtu
)
811 union ep_buffer_info
*info
= epbh
->info
;
813 return (info
->v1i
.frame_max
== FJES_MTU_TO_FRAME_SIZE(mtu
));
816 bool fjes_hw_check_vlan_id(struct epbuf_handler
*epbh
, u16 vlan_id
)
818 union ep_buffer_info
*info
= epbh
->info
;
825 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++) {
826 if (vlan_id
== info
->v1i
.vlan_id
[i
]) {
835 bool fjes_hw_set_vlan_id(struct epbuf_handler
*epbh
, u16 vlan_id
)
837 union ep_buffer_info
*info
= epbh
->info
;
840 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++) {
841 if (info
->v1i
.vlan_id
[i
] == 0) {
842 info
->v1i
.vlan_id
[i
] = vlan_id
;
849 void fjes_hw_del_vlan_id(struct epbuf_handler
*epbh
, u16 vlan_id
)
851 union ep_buffer_info
*info
= epbh
->info
;
855 for (i
= 0; i
< EP_BUFFER_SUPPORT_VLAN_MAX
; i
++) {
856 if (vlan_id
== info
->v1i
.vlan_id
[i
])
857 info
->v1i
.vlan_id
[i
] = 0;
862 bool fjes_hw_epbuf_rx_is_empty(struct epbuf_handler
*epbh
)
864 union ep_buffer_info
*info
= epbh
->info
;
866 if (info
->v1i
.count_max
== 0)
869 return EP_RING_EMPTY(info
->v1i
.head
, info
->v1i
.tail
,
870 info
->v1i
.count_max
);
873 void *fjes_hw_epbuf_rx_curpkt_get_addr(struct epbuf_handler
*epbh
,
876 union ep_buffer_info
*info
= epbh
->info
;
877 struct esmem_frame
*ring_frame
;
880 ring_frame
= (struct esmem_frame
*)&(epbh
->ring
[EP_RING_INDEX
882 info
->v1i
.count_max
) *
883 info
->v1i
.frame_max
]);
885 *psize
= (size_t)ring_frame
->frame_size
;
887 frame
= ring_frame
->frame_data
;
892 void fjes_hw_epbuf_rx_curpkt_drop(struct epbuf_handler
*epbh
)
894 union ep_buffer_info
*info
= epbh
->info
;
896 if (fjes_hw_epbuf_rx_is_empty(epbh
))
899 EP_RING_INDEX_INC(epbh
->info
->v1i
.head
, info
->v1i
.count_max
);
902 int fjes_hw_epbuf_tx_pkt_send(struct epbuf_handler
*epbh
,
903 void *frame
, size_t size
)
905 union ep_buffer_info
*info
= epbh
->info
;
906 struct esmem_frame
*ring_frame
;
908 if (EP_RING_FULL(info
->v1i
.head
, info
->v1i
.tail
, info
->v1i
.count_max
))
911 ring_frame
= (struct esmem_frame
*)&(epbh
->ring
[EP_RING_INDEX
913 info
->v1i
.count_max
) *
914 info
->v1i
.frame_max
]);
916 ring_frame
->frame_size
= size
;
917 memcpy((void *)(ring_frame
->frame_data
), (void *)frame
, size
);
919 EP_RING_INDEX_INC(epbh
->info
->v1i
.tail
, info
->v1i
.count_max
);
924 static void fjes_hw_update_zone_task(struct work_struct
*work
)
926 struct fjes_hw
*hw
= container_of(work
,
927 struct fjes_hw
, update_zone_task
);
929 struct my_s
{u8 es_status
; u8 zone
; } *info
;
930 union fjes_device_command_res
*res_buf
;
931 enum ep_partner_status pstatus
;
933 struct fjes_adapter
*adapter
;
934 struct net_device
*netdev
;
936 ulong unshare_bit
= 0;
943 adapter
= (struct fjes_adapter
*)hw
->back
;
944 netdev
= adapter
->netdev
;
945 res_buf
= hw
->hw_info
.res_buf
;
946 info
= (struct my_s
*)&res_buf
->info
.info
;
948 mutex_lock(&hw
->hw_info
.lock
);
950 ret
= fjes_hw_request_info(hw
);
955 if (!work_pending(&adapter
->force_close_task
)) {
956 adapter
->force_reset
= true;
957 schedule_work(&adapter
->force_close_task
);
963 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
964 if (epidx
== hw
->my_epid
) {
965 hw
->ep_shm_info
[epidx
].es_status
=
966 info
[epidx
].es_status
;
967 hw
->ep_shm_info
[epidx
].zone
=
972 pstatus
= fjes_hw_get_partner_ep_status(hw
, epidx
);
974 case EP_PARTNER_UNSHARE
:
976 if ((info
[epidx
].zone
!=
977 FJES_ZONING_ZONE_TYPE_NONE
) &&
978 (info
[epidx
].es_status
==
979 FJES_ZONING_STATUS_ENABLE
) &&
981 info
[hw
->my_epid
].zone
))
982 set_bit(epidx
, &share_bit
);
984 set_bit(epidx
, &unshare_bit
);
987 case EP_PARTNER_COMPLETE
:
988 case EP_PARTNER_WAITING
:
989 if ((info
[epidx
].zone
==
990 FJES_ZONING_ZONE_TYPE_NONE
) ||
991 (info
[epidx
].es_status
!=
992 FJES_ZONING_STATUS_ENABLE
) ||
994 info
[hw
->my_epid
].zone
)) {
996 &adapter
->unshare_watch_bitmask
);
998 &hw
->hw_info
.buffer_unshare_reserve_bit
);
1002 case EP_PARTNER_SHARED
:
1003 if ((info
[epidx
].zone
==
1004 FJES_ZONING_ZONE_TYPE_NONE
) ||
1005 (info
[epidx
].es_status
!=
1006 FJES_ZONING_STATUS_ENABLE
) ||
1007 (info
[epidx
].zone
!=
1008 info
[hw
->my_epid
].zone
))
1009 set_bit(epidx
, &irq_bit
);
1013 hw
->ep_shm_info
[epidx
].es_status
=
1014 info
[epidx
].es_status
;
1015 hw
->ep_shm_info
[epidx
].zone
= info
[epidx
].zone
;
1020 mutex_unlock(&hw
->hw_info
.lock
);
1022 for (epidx
= 0; epidx
< hw
->max_epid
; epidx
++) {
1023 if (epidx
== hw
->my_epid
)
1026 if (test_bit(epidx
, &share_bit
)) {
1027 fjes_hw_setup_epbuf(&hw
->ep_shm_info
[epidx
].tx
,
1028 netdev
->dev_addr
, netdev
->mtu
);
1030 mutex_lock(&hw
->hw_info
.lock
);
1032 ret
= fjes_hw_register_buff_addr(
1033 hw
, epidx
, &hw
->ep_shm_info
[epidx
]);
1041 if (!work_pending(&adapter
->force_close_task
)) {
1042 adapter
->force_reset
= true;
1044 &adapter
->force_close_task
);
1048 mutex_unlock(&hw
->hw_info
.lock
);
1051 if (test_bit(epidx
, &unshare_bit
)) {
1052 mutex_lock(&hw
->hw_info
.lock
);
1054 ret
= fjes_hw_unregister_buff_addr(hw
, epidx
);
1062 if (!work_pending(&adapter
->force_close_task
)) {
1063 adapter
->force_reset
= true;
1065 &adapter
->force_close_task
);
1070 mutex_unlock(&hw
->hw_info
.lock
);
1073 fjes_hw_setup_epbuf(
1074 &hw
->ep_shm_info
[epidx
].tx
,
1075 netdev
->dev_addr
, netdev
->mtu
);
1078 if (test_bit(epidx
, &irq_bit
)) {
1079 fjes_hw_raise_interrupt(hw
, epidx
,
1080 REG_ICTL_MASK_TXRX_STOP_REQ
);
1082 set_bit(epidx
, &hw
->txrx_stop_req_bit
);
1083 hw
->ep_shm_info
[epidx
].tx
.
1084 info
->v1i
.rx_status
|=
1085 FJES_RX_STOP_REQ_REQUEST
;
1086 set_bit(epidx
, &hw
->hw_info
.buffer_unshare_reserve_bit
);
1090 if (irq_bit
|| adapter
->unshare_watch_bitmask
) {
1091 if (!work_pending(&adapter
->unshare_watch_task
))
1092 queue_work(adapter
->control_wq
,
1093 &adapter
->unshare_watch_task
);
1097 static void fjes_hw_epstop_task(struct work_struct
*work
)
1099 struct fjes_hw
*hw
= container_of(work
, struct fjes_hw
, epstop_task
);
1100 struct fjes_adapter
*adapter
= (struct fjes_adapter
*)hw
->back
;
1105 while ((remain_bit
= hw
->epstop_req_bit
)) {
1106 for (epid_bit
= 0; remain_bit
; remain_bit
>>= 1, epid_bit
++) {
1107 if (remain_bit
& 1) {
1108 hw
->ep_shm_info
[epid_bit
].
1109 tx
.info
->v1i
.rx_status
|=
1110 FJES_RX_STOP_REQ_DONE
;
1112 clear_bit(epid_bit
, &hw
->epstop_req_bit
);
1114 &adapter
->unshare_watch_bitmask
);
1116 if (!work_pending(&adapter
->unshare_watch_task
))
1118 adapter
->control_wq
,
1119 &adapter
->unshare_watch_task
);