1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/module.h>
23#include <linux/types.h>
24#include <linux/nls.h>
25#include <linux/platform_device.h>
26#include <linux/netdevice.h>
27#include <linux/interrupt.h>
28
29#include "fjes.h"
30#include "fjes_trace.h"
31
32#define MAJ 1
33#define MIN 2
34#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN)
35#define DRV_NAME "fjes"
36char fjes_driver_name[] = DRV_NAME;
37char fjes_driver_version[] = DRV_VERSION;
38static const char fjes_driver_string[] =
39 "FUJITSU Extended Socket Network Device Driver";
40static const char fjes_copyright[] =
41 "Copyright (c) 2015 FUJITSU LIMITED";
42
43MODULE_AUTHOR("Taku Izumi <izumi.taku@jp.fujitsu.com>");
44MODULE_DESCRIPTION("FUJITSU Extended Socket Network Device Driver");
45MODULE_LICENSE("GPL");
46MODULE_VERSION(DRV_VERSION);
47
48#define ACPI_MOTHERBOARD_RESOURCE_HID "PNP0C02"
49
50static int fjes_request_irq(struct fjes_adapter *);
51static void fjes_free_irq(struct fjes_adapter *);
52
53static int fjes_open(struct net_device *);
54static int fjes_close(struct net_device *);
55static int fjes_setup_resources(struct fjes_adapter *);
56static void fjes_free_resources(struct fjes_adapter *);
57static netdev_tx_t fjes_xmit_frame(struct sk_buff *, struct net_device *);
58static void fjes_raise_intr_rxdata_task(struct work_struct *);
59static void fjes_tx_stall_task(struct work_struct *);
60static void fjes_force_close_task(struct work_struct *);
61static irqreturn_t fjes_intr(int, void*);
62static void fjes_get_stats64(struct net_device *, struct rtnl_link_stats64 *);
63static int fjes_change_mtu(struct net_device *, int);
64static int fjes_vlan_rx_add_vid(struct net_device *, __be16 proto, u16);
65static int fjes_vlan_rx_kill_vid(struct net_device *, __be16 proto, u16);
66static void fjes_tx_retry(struct net_device *);
67
68static int fjes_acpi_add(struct acpi_device *);
69static int fjes_acpi_remove(struct acpi_device *);
70static acpi_status fjes_get_acpi_resource(struct acpi_resource *, void*);
71
72static int fjes_probe(struct platform_device *);
73static int fjes_remove(struct platform_device *);
74
75static int fjes_sw_init(struct fjes_adapter *);
76static void fjes_netdev_setup(struct net_device *);
77static void fjes_irq_watch_task(struct work_struct *);
78static void fjes_watch_unshare_task(struct work_struct *);
79static void fjes_rx_irq(struct fjes_adapter *, int);
80static int fjes_poll(struct napi_struct *, int);
81
82static const struct acpi_device_id fjes_acpi_ids[] = {
83 {ACPI_MOTHERBOARD_RESOURCE_HID, 0},
84 {"", 0},
85};
86MODULE_DEVICE_TABLE(acpi, fjes_acpi_ids);
87
88static struct acpi_driver fjes_acpi_driver = {
89 .name = DRV_NAME,
90 .class = DRV_NAME,
91 .owner = THIS_MODULE,
92 .ids = fjes_acpi_ids,
93 .ops = {
94 .add = fjes_acpi_add,
95 .remove = fjes_acpi_remove,
96 },
97};
98
99static struct platform_driver fjes_driver = {
100 .driver = {
101 .name = DRV_NAME,
102 },
103 .probe = fjes_probe,
104 .remove = fjes_remove,
105};
106
107static struct resource fjes_resource[] = {
108 {
109 .flags = IORESOURCE_MEM,
110 .start = 0,
111 .end = 0,
112 },
113 {
114 .flags = IORESOURCE_IRQ,
115 .start = 0,
116 .end = 0,
117 },
118};
119
120static bool is_extended_socket_device(struct acpi_device *device)
121{
122 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
123 char str_buf[sizeof(FJES_ACPI_SYMBOL) + 1];
124 union acpi_object *str;
125 acpi_status status;
126 int result;
127
128 status = acpi_evaluate_object(device->handle, "_STR", NULL, &buffer);
129 if (ACPI_FAILURE(status))
130 return false;
131
132 str = buffer.pointer;
133 result = utf16s_to_utf8s((wchar_t *)str->string.pointer,
134 str->string.length, UTF16_LITTLE_ENDIAN,
135 str_buf, sizeof(str_buf) - 1);
136 str_buf[result] = 0;
137
138 if (strncmp(FJES_ACPI_SYMBOL, str_buf, strlen(FJES_ACPI_SYMBOL)) != 0) {
139 kfree(buffer.pointer);
140 return false;
141 }
142 kfree(buffer.pointer);
143
144 return true;
145}
146
147static int acpi_check_extended_socket_status(struct acpi_device *device)
148{
149 unsigned long long sta;
150 acpi_status status;
151
152 status = acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
153 if (ACPI_FAILURE(status))
154 return -ENODEV;
155
156 if (!((sta & ACPI_STA_DEVICE_PRESENT) &&
157 (sta & ACPI_STA_DEVICE_ENABLED) &&
158 (sta & ACPI_STA_DEVICE_UI) &&
159 (sta & ACPI_STA_DEVICE_FUNCTIONING)))
160 return -ENODEV;
161
162 return 0;
163}
164
165static int fjes_acpi_add(struct acpi_device *device)
166{
167 struct platform_device *plat_dev;
168 acpi_status status;
169
170 if (!is_extended_socket_device(device))
171 return -ENODEV;
172
173 if (acpi_check_extended_socket_status(device))
174 return -ENODEV;
175
176 status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
177 fjes_get_acpi_resource, fjes_resource);
178 if (ACPI_FAILURE(status))
179 return -ENODEV;
180
181
182 plat_dev = platform_device_register_simple(DRV_NAME, 0, fjes_resource,
183 ARRAY_SIZE(fjes_resource));
184 device->driver_data = plat_dev;
185
186 return 0;
187}
188
189static int fjes_acpi_remove(struct acpi_device *device)
190{
191 struct platform_device *plat_dev;
192
193 plat_dev = (struct platform_device *)acpi_driver_data(device);
194 platform_device_unregister(plat_dev);
195
196 return 0;
197}
198
199static acpi_status
200fjes_get_acpi_resource(struct acpi_resource *acpi_res, void *data)
201{
202 struct acpi_resource_address32 *addr;
203 struct acpi_resource_irq *irq;
204 struct resource *res = data;
205
206 switch (acpi_res->type) {
207 case ACPI_RESOURCE_TYPE_ADDRESS32:
208 addr = &acpi_res->data.address32;
209 res[0].start = addr->address.minimum;
210 res[0].end = addr->address.minimum +
211 addr->address.address_length - 1;
212 break;
213
214 case ACPI_RESOURCE_TYPE_IRQ:
215 irq = &acpi_res->data.irq;
216 if (irq->interrupt_count != 1)
217 return AE_ERROR;
218 res[1].start = irq->interrupts[0];
219 res[1].end = irq->interrupts[0];
220 break;
221
222 default:
223 break;
224 }
225
226 return AE_OK;
227}
228
229static int fjes_request_irq(struct fjes_adapter *adapter)
230{
231 struct net_device *netdev = adapter->netdev;
232 int result = -1;
233
234 adapter->interrupt_watch_enable = true;
235 if (!delayed_work_pending(&adapter->interrupt_watch_task)) {
236 queue_delayed_work(adapter->control_wq,
237 &adapter->interrupt_watch_task,
238 FJES_IRQ_WATCH_DELAY);
239 }
240
241 if (!adapter->irq_registered) {
242 result = request_irq(adapter->hw.hw_res.irq, fjes_intr,
243 IRQF_SHARED, netdev->name, adapter);
244 if (result)
245 adapter->irq_registered = false;
246 else
247 adapter->irq_registered = true;
248 }
249
250 return result;
251}
252
253static void fjes_free_irq(struct fjes_adapter *adapter)
254{
255 struct fjes_hw *hw = &adapter->hw;
256
257 adapter->interrupt_watch_enable = false;
258 cancel_delayed_work_sync(&adapter->interrupt_watch_task);
259
260 fjes_hw_set_irqmask(hw, REG_ICTL_MASK_ALL, true);
261
262 if (adapter->irq_registered) {
263 free_irq(adapter->hw.hw_res.irq, adapter);
264 adapter->irq_registered = false;
265 }
266}
267
268static const struct net_device_ops fjes_netdev_ops = {
269 .ndo_open = fjes_open,
270 .ndo_stop = fjes_close,
271 .ndo_start_xmit = fjes_xmit_frame,
272 .ndo_get_stats64 = fjes_get_stats64,
273 .ndo_change_mtu = fjes_change_mtu,
274 .ndo_tx_timeout = fjes_tx_retry,
275 .ndo_vlan_rx_add_vid = fjes_vlan_rx_add_vid,
276 .ndo_vlan_rx_kill_vid = fjes_vlan_rx_kill_vid,
277};
278
279
280static int fjes_open(struct net_device *netdev)
281{
282 struct fjes_adapter *adapter = netdev_priv(netdev);
283 struct fjes_hw *hw = &adapter->hw;
284 int result;
285
286 if (adapter->open_guard)
287 return -ENXIO;
288
289 result = fjes_setup_resources(adapter);
290 if (result)
291 goto err_setup_res;
292
293 hw->txrx_stop_req_bit = 0;
294 hw->epstop_req_bit = 0;
295
296 napi_enable(&adapter->napi);
297
298 fjes_hw_capture_interrupt_status(hw);
299
300 result = fjes_request_irq(adapter);
301 if (result)
302 goto err_req_irq;
303
304 fjes_hw_set_irqmask(hw, REG_ICTL_MASK_ALL, false);
305
306 netif_tx_start_all_queues(netdev);
307 netif_carrier_on(netdev);
308
309 return 0;
310
311err_req_irq:
312 fjes_free_irq(adapter);
313 napi_disable(&adapter->napi);
314
315err_setup_res:
316 fjes_free_resources(adapter);
317 return result;
318}
319
320
321static int fjes_close(struct net_device *netdev)
322{
323 struct fjes_adapter *adapter = netdev_priv(netdev);
324 struct fjes_hw *hw = &adapter->hw;
325 unsigned long flags;
326 int epidx;
327
328 netif_tx_stop_all_queues(netdev);
329 netif_carrier_off(netdev);
330
331 fjes_hw_raise_epstop(hw);
332
333 napi_disable(&adapter->napi);
334
335 spin_lock_irqsave(&hw->rx_status_lock, flags);
336 for (epidx = 0; epidx < hw->max_epid; epidx++) {
337 if (epidx == hw->my_epid)
338 continue;
339
340 if (fjes_hw_get_partner_ep_status(hw, epidx) ==
341 EP_PARTNER_SHARED)
342 adapter->hw.ep_shm_info[epidx]
343 .tx.info->v1i.rx_status &=
344 ~FJES_RX_POLL_WORK;
345 }
346 spin_unlock_irqrestore(&hw->rx_status_lock, flags);
347
348 fjes_free_irq(adapter);
349
350 cancel_delayed_work_sync(&adapter->interrupt_watch_task);
351 cancel_work_sync(&adapter->unshare_watch_task);
352 adapter->unshare_watch_bitmask = 0;
353 cancel_work_sync(&adapter->raise_intr_rxdata_task);
354 cancel_work_sync(&adapter->tx_stall_task);
355
356 cancel_work_sync(&hw->update_zone_task);
357 cancel_work_sync(&hw->epstop_task);
358
359 fjes_hw_wait_epstop(hw);
360
361 fjes_free_resources(adapter);
362
363 return 0;
364}
365
366static int fjes_setup_resources(struct fjes_adapter *adapter)
367{
368 struct net_device *netdev = adapter->netdev;
369 struct ep_share_mem_info *buf_pair;
370 struct fjes_hw *hw = &adapter->hw;
371 unsigned long flags;
372 int result;
373 int epidx;
374
375 mutex_lock(&hw->hw_info.lock);
376 result = fjes_hw_request_info(hw);
377 switch (result) {
378 case 0:
379 for (epidx = 0; epidx < hw->max_epid; epidx++) {
380 hw->ep_shm_info[epidx].es_status =
381 hw->hw_info.res_buf->info.info[epidx].es_status;
382 hw->ep_shm_info[epidx].zone =
383 hw->hw_info.res_buf->info.info[epidx].zone;
384 }
385 break;
386 default:
387 case -ENOMSG:
388 case -EBUSY:
389 adapter->force_reset = true;
390
391 mutex_unlock(&hw->hw_info.lock);
392 return result;
393 }
394 mutex_unlock(&hw->hw_info.lock);
395
396 for (epidx = 0; epidx < (hw->max_epid); epidx++) {
397 if ((epidx != hw->my_epid) &&
398 (hw->ep_shm_info[epidx].es_status ==
399 FJES_ZONING_STATUS_ENABLE)) {
400 fjes_hw_raise_interrupt(hw, epidx,
401 REG_ICTL_MASK_INFO_UPDATE);
402 hw->ep_shm_info[epidx].ep_stats
403 .send_intr_zoneupdate += 1;
404 }
405 }
406
407 msleep(FJES_OPEN_ZONE_UPDATE_WAIT * hw->max_epid);
408
409 for (epidx = 0; epidx < (hw->max_epid); epidx++) {
410 if (epidx == hw->my_epid)
411 continue;
412
413 buf_pair = &hw->ep_shm_info[epidx];
414
415 spin_lock_irqsave(&hw->rx_status_lock, flags);
416 fjes_hw_setup_epbuf(&buf_pair->tx, netdev->dev_addr,
417 netdev->mtu);
418 spin_unlock_irqrestore(&hw->rx_status_lock, flags);
419
420 if (fjes_hw_epid_is_same_zone(hw, epidx)) {
421 mutex_lock(&hw->hw_info.lock);
422 result =
423 fjes_hw_register_buff_addr(hw, epidx, buf_pair);
424 mutex_unlock(&hw->hw_info.lock);
425
426 switch (result) {
427 case 0:
428 break;
429 case -ENOMSG:
430 case -EBUSY:
431 default:
432 adapter->force_reset = true;
433 return result;
434 }
435
436 hw->ep_shm_info[epidx].ep_stats
437 .com_regist_buf_exec += 1;
438 }
439 }
440
441 return 0;
442}
443
444static void fjes_free_resources(struct fjes_adapter *adapter)
445{
446 struct net_device *netdev = adapter->netdev;
447 struct fjes_device_command_param param;
448 struct ep_share_mem_info *buf_pair;
449 struct fjes_hw *hw = &adapter->hw;
450 bool reset_flag = false;
451 unsigned long flags;
452 int result;
453 int epidx;
454
455 for (epidx = 0; epidx < hw->max_epid; epidx++) {
456 if (epidx == hw->my_epid)
457 continue;
458
459 mutex_lock(&hw->hw_info.lock);
460 result = fjes_hw_unregister_buff_addr(hw, epidx);
461 mutex_unlock(&hw->hw_info.lock);
462
463 hw->ep_shm_info[epidx].ep_stats.com_unregist_buf_exec += 1;
464
465 if (result)
466 reset_flag = true;
467
468 buf_pair = &hw->ep_shm_info[epidx];
469
470 spin_lock_irqsave(&hw->rx_status_lock, flags);
471 fjes_hw_setup_epbuf(&buf_pair->tx,
472 netdev->dev_addr, netdev->mtu);
473 spin_unlock_irqrestore(&hw->rx_status_lock, flags);
474
475 clear_bit(epidx, &hw->txrx_stop_req_bit);
476 }
477
478 if (reset_flag || adapter->force_reset) {
479 result = fjes_hw_reset(hw);
480
481 adapter->force_reset = false;
482
483 if (result)
484 adapter->open_guard = true;
485
486 hw->hw_info.buffer_share_bit = 0;
487
488 memset((void *)¶m, 0, sizeof(param));
489
490 param.req_len = hw->hw_info.req_buf_size;
491 param.req_start = __pa(hw->hw_info.req_buf);
492 param.res_len = hw->hw_info.res_buf_size;
493 param.res_start = __pa(hw->hw_info.res_buf);
494 param.share_start = __pa(hw->hw_info.share->ep_status);
495
496 fjes_hw_init_command_registers(hw, ¶m);
497 }
498}
499
500static void fjes_tx_stall_task(struct work_struct *work)
501{
502 struct fjes_adapter *adapter = container_of(work,
503 struct fjes_adapter, tx_stall_task);
504 struct net_device *netdev = adapter->netdev;
505 struct fjes_hw *hw = &adapter->hw;
506 int all_queue_available, sendable;
507 enum ep_partner_status pstatus;
508 int max_epid, my_epid, epid;
509 union ep_buffer_info *info;
510 int i;
511
512 if (((long)jiffies -
513 dev_trans_start(netdev)) > FJES_TX_TX_STALL_TIMEOUT) {
514 netif_wake_queue(netdev);
515 return;
516 }
517
518 my_epid = hw->my_epid;
519 max_epid = hw->max_epid;
520
521 for (i = 0; i < 5; i++) {
522 all_queue_available = 1;
523
524 for (epid = 0; epid < max_epid; epid++) {
525 if (my_epid == epid)
526 continue;
527
528 pstatus = fjes_hw_get_partner_ep_status(hw, epid);
529 sendable = (pstatus == EP_PARTNER_SHARED);
530 if (!sendable)
531 continue;
532
533 info = adapter->hw.ep_shm_info[epid].tx.info;
534
535 if (!(info->v1i.rx_status & FJES_RX_MTU_CHANGING_DONE))
536 return;
537
538 if (EP_RING_FULL(info->v1i.head, info->v1i.tail,
539 info->v1i.count_max)) {
540 all_queue_available = 0;
541 break;
542 }
543 }
544
545 if (all_queue_available) {
546 netif_wake_queue(netdev);
547 return;
548 }
549 }
550
551 usleep_range(50, 100);
552
553 queue_work(adapter->txrx_wq, &adapter->tx_stall_task);
554}
555
556static void fjes_force_close_task(struct work_struct *work)
557{
558 struct fjes_adapter *adapter = container_of(work,
559 struct fjes_adapter, force_close_task);
560 struct net_device *netdev = adapter->netdev;
561
562 rtnl_lock();
563 dev_close(netdev);
564 rtnl_unlock();
565}
566
567static void fjes_raise_intr_rxdata_task(struct work_struct *work)
568{
569 struct fjes_adapter *adapter = container_of(work,
570 struct fjes_adapter, raise_intr_rxdata_task);
571 struct fjes_hw *hw = &adapter->hw;
572 enum ep_partner_status pstatus;
573 int max_epid, my_epid, epid;
574
575 my_epid = hw->my_epid;
576 max_epid = hw->max_epid;
577
578 for (epid = 0; epid < max_epid; epid++)
579 hw->ep_shm_info[epid].tx_status_work = 0;
580
581 for (epid = 0; epid < max_epid; epid++) {
582 if (epid == my_epid)
583 continue;
584
585 pstatus = fjes_hw_get_partner_ep_status(hw, epid);
586 if (pstatus == EP_PARTNER_SHARED) {
587 hw->ep_shm_info[epid].tx_status_work =
588 hw->ep_shm_info[epid].tx.info->v1i.tx_status;
589
590 if (hw->ep_shm_info[epid].tx_status_work ==
591 FJES_TX_DELAY_SEND_PENDING) {
592 hw->ep_shm_info[epid].tx.info->v1i.tx_status =
593 FJES_TX_DELAY_SEND_NONE;
594 }
595 }
596 }
597
598 for (epid = 0; epid < max_epid; epid++) {
599 if (epid == my_epid)
600 continue;
601
602 pstatus = fjes_hw_get_partner_ep_status(hw, epid);
603 if ((hw->ep_shm_info[epid].tx_status_work ==
604 FJES_TX_DELAY_SEND_PENDING) &&
605 (pstatus == EP_PARTNER_SHARED) &&
606 !(hw->ep_shm_info[epid].rx.info->v1i.rx_status &
607 FJES_RX_POLL_WORK)) {
608 fjes_hw_raise_interrupt(hw, epid,
609 REG_ICTL_MASK_RX_DATA);
610 hw->ep_shm_info[epid].ep_stats.send_intr_rx += 1;
611 }
612 }
613
614 usleep_range(500, 1000);
615}
616
617static int fjes_tx_send(struct fjes_adapter *adapter, int dest,
618 void *data, size_t len)
619{
620 int retval;
621
622 retval = fjes_hw_epbuf_tx_pkt_send(&adapter->hw.ep_shm_info[dest].tx,
623 data, len);
624 if (retval)
625 return retval;
626
627 adapter->hw.ep_shm_info[dest].tx.info->v1i.tx_status =
628 FJES_TX_DELAY_SEND_PENDING;
629 if (!work_pending(&adapter->raise_intr_rxdata_task))
630 queue_work(adapter->txrx_wq,
631 &adapter->raise_intr_rxdata_task);
632
633 retval = 0;
634 return retval;
635}
636
637static netdev_tx_t
638fjes_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
639{
640 struct fjes_adapter *adapter = netdev_priv(netdev);
641 struct fjes_hw *hw = &adapter->hw;
642
643 int max_epid, my_epid, dest_epid;
644 enum ep_partner_status pstatus;
645 struct netdev_queue *cur_queue;
646 char shortpkt[VLAN_ETH_HLEN];
647 bool is_multi, vlan;
648 struct ethhdr *eth;
649 u16 queue_no = 0;
650 u16 vlan_id = 0;
651 netdev_tx_t ret;
652 char *data;
653 int len;
654
655 ret = NETDEV_TX_OK;
656 is_multi = false;
657 cur_queue = netdev_get_tx_queue(netdev, queue_no);
658
659 eth = (struct ethhdr *)skb->data;
660 my_epid = hw->my_epid;
661
662 vlan = (vlan_get_tag(skb, &vlan_id) == 0) ? true : false;
663
664 data = skb->data;
665 len = skb->len;
666
667 if (is_multicast_ether_addr(eth->h_dest)) {
668 dest_epid = 0;
669 max_epid = hw->max_epid;
670 is_multi = true;
671 } else if (is_local_ether_addr(eth->h_dest)) {
672 dest_epid = eth->h_dest[ETH_ALEN - 1];
673 max_epid = dest_epid + 1;
674
675 if ((eth->h_dest[0] == 0x02) &&
676 (0x00 == (eth->h_dest[1] | eth->h_dest[2] |
677 eth->h_dest[3] | eth->h_dest[4])) &&
678 (dest_epid < hw->max_epid)) {
679 ;
680 } else {
681 dest_epid = 0;
682 max_epid = 0;
683 ret = NETDEV_TX_OK;
684
685 adapter->stats64.tx_packets += 1;
686 hw->ep_shm_info[my_epid].net_stats.tx_packets += 1;
687 adapter->stats64.tx_bytes += len;
688 hw->ep_shm_info[my_epid].net_stats.tx_bytes += len;
689 }
690 } else {
691 dest_epid = 0;
692 max_epid = 0;
693 ret = NETDEV_TX_OK;
694
695 adapter->stats64.tx_packets += 1;
696 hw->ep_shm_info[my_epid].net_stats.tx_packets += 1;
697 adapter->stats64.tx_bytes += len;
698 hw->ep_shm_info[my_epid].net_stats.tx_bytes += len;
699 }
700
701 for (; dest_epid < max_epid; dest_epid++) {
702 if (my_epid == dest_epid)
703 continue;
704
705 pstatus = fjes_hw_get_partner_ep_status(hw, dest_epid);
706 if (pstatus != EP_PARTNER_SHARED) {
707 if (!is_multi)
708 hw->ep_shm_info[dest_epid].ep_stats
709 .tx_dropped_not_shared += 1;
710 ret = NETDEV_TX_OK;
711 } else if (!fjes_hw_check_epbuf_version(
712 &adapter->hw.ep_shm_info[dest_epid].rx, 0)) {
713
714 adapter->stats64.tx_carrier_errors += 1;
715 hw->ep_shm_info[dest_epid].net_stats
716 .tx_carrier_errors += 1;
717 hw->ep_shm_info[dest_epid].ep_stats
718 .tx_dropped_ver_mismatch += 1;
719
720 ret = NETDEV_TX_OK;
721 } else if (!fjes_hw_check_mtu(
722 &adapter->hw.ep_shm_info[dest_epid].rx,
723 netdev->mtu)) {
724 adapter->stats64.tx_dropped += 1;
725 hw->ep_shm_info[dest_epid].net_stats.tx_dropped += 1;
726 adapter->stats64.tx_errors += 1;
727 hw->ep_shm_info[dest_epid].net_stats.tx_errors += 1;
728 hw->ep_shm_info[dest_epid].ep_stats
729 .tx_dropped_buf_size_mismatch += 1;
730
731 ret = NETDEV_TX_OK;
732 } else if (vlan &&
733 !fjes_hw_check_vlan_id(
734 &adapter->hw.ep_shm_info[dest_epid].rx,
735 vlan_id)) {
736 hw->ep_shm_info[dest_epid].ep_stats
737 .tx_dropped_vlanid_mismatch += 1;
738 ret = NETDEV_TX_OK;
739 } else {
740 if (len < VLAN_ETH_HLEN) {
741 memset(shortpkt, 0, VLAN_ETH_HLEN);
742 memcpy(shortpkt, skb->data, skb->len);
743 len = VLAN_ETH_HLEN;
744 data = shortpkt;
745 }
746
747 if (adapter->tx_retry_count == 0) {
748 adapter->tx_start_jiffies = jiffies;
749 adapter->tx_retry_count = 1;
750 } else {
751 adapter->tx_retry_count++;
752 }
753
754 if (fjes_tx_send(adapter, dest_epid, data, len)) {
755 if (is_multi) {
756 ret = NETDEV_TX_OK;
757 } else if (
758 ((long)jiffies -
759 (long)adapter->tx_start_jiffies) >=
760 FJES_TX_RETRY_TIMEOUT) {
761 adapter->stats64.tx_fifo_errors += 1;
762 hw->ep_shm_info[dest_epid].net_stats
763 .tx_fifo_errors += 1;
764 adapter->stats64.tx_errors += 1;
765 hw->ep_shm_info[dest_epid].net_stats
766 .tx_errors += 1;
767
768 ret = NETDEV_TX_OK;
769 } else {
770 netif_trans_update(netdev);
771 hw->ep_shm_info[dest_epid].ep_stats
772 .tx_buffer_full += 1;
773 netif_tx_stop_queue(cur_queue);
774
775 if (!work_pending(&adapter->tx_stall_task))
776 queue_work(adapter->txrx_wq,
777 &adapter->tx_stall_task);
778
779 ret = NETDEV_TX_BUSY;
780 }
781 } else {
782 if (!is_multi) {
783 adapter->stats64.tx_packets += 1;
784 hw->ep_shm_info[dest_epid].net_stats
785 .tx_packets += 1;
786 adapter->stats64.tx_bytes += len;
787 hw->ep_shm_info[dest_epid].net_stats
788 .tx_bytes += len;
789 }
790
791 adapter->tx_retry_count = 0;
792 ret = NETDEV_TX_OK;
793 }
794 }
795 }
796
797 if (ret == NETDEV_TX_OK) {
798 dev_kfree_skb(skb);
799 if (is_multi) {
800 adapter->stats64.tx_packets += 1;
801 hw->ep_shm_info[my_epid].net_stats.tx_packets += 1;
802 adapter->stats64.tx_bytes += 1;
803 hw->ep_shm_info[my_epid].net_stats.tx_bytes += len;
804 }
805 }
806
807 return ret;
808}
809
810static void fjes_tx_retry(struct net_device *netdev)
811{
812 struct netdev_queue *queue = netdev_get_tx_queue(netdev, 0);
813
814 netif_tx_wake_queue(queue);
815}
816
817static void
818fjes_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
819{
820 struct fjes_adapter *adapter = netdev_priv(netdev);
821
822 memcpy(stats, &adapter->stats64, sizeof(struct rtnl_link_stats64));
823}
824
825static int fjes_change_mtu(struct net_device *netdev, int new_mtu)
826{
827 struct fjes_adapter *adapter = netdev_priv(netdev);
828 bool running = netif_running(netdev);
829 struct fjes_hw *hw = &adapter->hw;
830 unsigned long flags;
831 int ret = -EINVAL;
832 int idx, epidx;
833
834 for (idx = 0; fjes_support_mtu[idx] != 0; idx++) {
835 if (new_mtu <= fjes_support_mtu[idx]) {
836 new_mtu = fjes_support_mtu[idx];
837 if (new_mtu == netdev->mtu)
838 return 0;
839
840 ret = 0;
841 break;
842 }
843 }
844
845 if (ret)
846 return ret;
847
848 if (running) {
849 spin_lock_irqsave(&hw->rx_status_lock, flags);
850 for (epidx = 0; epidx < hw->max_epid; epidx++) {
851 if (epidx == hw->my_epid)
852 continue;
853 hw->ep_shm_info[epidx].tx.info->v1i.rx_status &=
854 ~FJES_RX_MTU_CHANGING_DONE;
855 }
856 spin_unlock_irqrestore(&hw->rx_status_lock, flags);
857
858 netif_tx_stop_all_queues(netdev);
859 netif_carrier_off(netdev);
860 cancel_work_sync(&adapter->tx_stall_task);
861 napi_disable(&adapter->napi);
862
863 msleep(1000);
864
865 netif_tx_stop_all_queues(netdev);
866 }
867
868 netdev->mtu = new_mtu;
869
870 if (running) {
871 for (epidx = 0; epidx < hw->max_epid; epidx++) {
872 if (epidx == hw->my_epid)
873 continue;
874
875 spin_lock_irqsave(&hw->rx_status_lock, flags);
876 fjes_hw_setup_epbuf(&hw->ep_shm_info[epidx].tx,
877 netdev->dev_addr,
878 netdev->mtu);
879
880 hw->ep_shm_info[epidx].tx.info->v1i.rx_status |=
881 FJES_RX_MTU_CHANGING_DONE;
882 spin_unlock_irqrestore(&hw->rx_status_lock, flags);
883 }
884
885 netif_tx_wake_all_queues(netdev);
886 netif_carrier_on(netdev);
887 napi_enable(&adapter->napi);
888 napi_schedule(&adapter->napi);
889 }
890
891 return ret;
892}
893
894static int fjes_vlan_rx_add_vid(struct net_device *netdev,
895 __be16 proto, u16 vid)
896{
897 struct fjes_adapter *adapter = netdev_priv(netdev);
898 bool ret = true;
899 int epid;
900
901 for (epid = 0; epid < adapter->hw.max_epid; epid++) {
902 if (epid == adapter->hw.my_epid)
903 continue;
904
905 if (!fjes_hw_check_vlan_id(
906 &adapter->hw.ep_shm_info[epid].tx, vid))
907 ret = fjes_hw_set_vlan_id(
908 &adapter->hw.ep_shm_info[epid].tx, vid);
909 }
910
911 return ret ? 0 : -ENOSPC;
912}
913
914static int fjes_vlan_rx_kill_vid(struct net_device *netdev,
915 __be16 proto, u16 vid)
916{
917 struct fjes_adapter *adapter = netdev_priv(netdev);
918 int epid;
919
920 for (epid = 0; epid < adapter->hw.max_epid; epid++) {
921 if (epid == adapter->hw.my_epid)
922 continue;
923
924 fjes_hw_del_vlan_id(&adapter->hw.ep_shm_info[epid].tx, vid);
925 }
926
927 return 0;
928}
929
930static void fjes_txrx_stop_req_irq(struct fjes_adapter *adapter,
931 int src_epid)
932{
933 struct fjes_hw *hw = &adapter->hw;
934 enum ep_partner_status status;
935 unsigned long flags;
936
937 status = fjes_hw_get_partner_ep_status(hw, src_epid);
938 trace_fjes_txrx_stop_req_irq_pre(hw, src_epid, status);
939 switch (status) {
940 case EP_PARTNER_UNSHARE:
941 case EP_PARTNER_COMPLETE:
942 default:
943 break;
944 case EP_PARTNER_WAITING:
945 if (src_epid < hw->my_epid) {
946 spin_lock_irqsave(&hw->rx_status_lock, flags);
947 hw->ep_shm_info[src_epid].tx.info->v1i.rx_status |=
948 FJES_RX_STOP_REQ_DONE;
949 spin_unlock_irqrestore(&hw->rx_status_lock, flags);
950
951 clear_bit(src_epid, &hw->txrx_stop_req_bit);
952 set_bit(src_epid, &adapter->unshare_watch_bitmask);
953
954 if (!work_pending(&adapter->unshare_watch_task))
955 queue_work(adapter->control_wq,
956 &adapter->unshare_watch_task);
957 }
958 break;
959 case EP_PARTNER_SHARED:
960 if (hw->ep_shm_info[src_epid].rx.info->v1i.rx_status &
961 FJES_RX_STOP_REQ_REQUEST) {
962 set_bit(src_epid, &hw->epstop_req_bit);
963 if (!work_pending(&hw->epstop_task))
964 queue_work(adapter->control_wq,
965 &hw->epstop_task);
966 }
967 break;
968 }
969 trace_fjes_txrx_stop_req_irq_post(hw, src_epid);
970}
971
972static void fjes_stop_req_irq(struct fjes_adapter *adapter, int src_epid)
973{
974 struct fjes_hw *hw = &adapter->hw;
975 enum ep_partner_status status;
976 unsigned long flags;
977
978 set_bit(src_epid, &hw->hw_info.buffer_unshare_reserve_bit);
979
980 status = fjes_hw_get_partner_ep_status(hw, src_epid);
981 trace_fjes_stop_req_irq_pre(hw, src_epid, status);
982 switch (status) {
983 case EP_PARTNER_WAITING:
984 spin_lock_irqsave(&hw->rx_status_lock, flags);
985 hw->ep_shm_info[src_epid].tx.info->v1i.rx_status |=
986 FJES_RX_STOP_REQ_DONE;
987 spin_unlock_irqrestore(&hw->rx_status_lock, flags);
988 clear_bit(src_epid, &hw->txrx_stop_req_bit);
989
990 case EP_PARTNER_UNSHARE:
991 case EP_PARTNER_COMPLETE:
992 default:
993 set_bit(src_epid, &adapter->unshare_watch_bitmask);
994 if (!work_pending(&adapter->unshare_watch_task))
995 queue_work(adapter->control_wq,
996 &adapter->unshare_watch_task);
997 break;
998 case EP_PARTNER_SHARED:
999 set_bit(src_epid, &hw->epstop_req_bit);
1000
1001 if (!work_pending(&hw->epstop_task))
1002 queue_work(adapter->control_wq, &hw->epstop_task);
1003 break;
1004 }
1005 trace_fjes_stop_req_irq_post(hw, src_epid);
1006}
1007
1008static void fjes_update_zone_irq(struct fjes_adapter *adapter,
1009 int src_epid)
1010{
1011 struct fjes_hw *hw = &adapter->hw;
1012
1013 if (!work_pending(&hw->update_zone_task))
1014 queue_work(adapter->control_wq, &hw->update_zone_task);
1015}
1016
1017static irqreturn_t fjes_intr(int irq, void *data)
1018{
1019 struct fjes_adapter *adapter = data;
1020 struct fjes_hw *hw = &adapter->hw;
1021 irqreturn_t ret;
1022 u32 icr;
1023
1024 icr = fjes_hw_capture_interrupt_status(hw);
1025
1026 if (icr & REG_IS_MASK_IS_ASSERT) {
1027 if (icr & REG_ICTL_MASK_RX_DATA) {
1028 fjes_rx_irq(adapter, icr & REG_IS_MASK_EPID);
1029 hw->ep_shm_info[icr & REG_IS_MASK_EPID].ep_stats
1030 .recv_intr_rx += 1;
1031 }
1032
1033 if (icr & REG_ICTL_MASK_DEV_STOP_REQ) {
1034 fjes_stop_req_irq(adapter, icr & REG_IS_MASK_EPID);
1035 hw->ep_shm_info[icr & REG_IS_MASK_EPID].ep_stats
1036 .recv_intr_stop += 1;
1037 }
1038
1039 if (icr & REG_ICTL_MASK_TXRX_STOP_REQ) {
1040 fjes_txrx_stop_req_irq(adapter, icr & REG_IS_MASK_EPID);
1041 hw->ep_shm_info[icr & REG_IS_MASK_EPID].ep_stats
1042 .recv_intr_unshare += 1;
1043 }
1044
1045 if (icr & REG_ICTL_MASK_TXRX_STOP_DONE)
1046 fjes_hw_set_irqmask(hw,
1047 REG_ICTL_MASK_TXRX_STOP_DONE, true);
1048
1049 if (icr & REG_ICTL_MASK_INFO_UPDATE) {
1050 fjes_update_zone_irq(adapter, icr & REG_IS_MASK_EPID);
1051 hw->ep_shm_info[icr & REG_IS_MASK_EPID].ep_stats
1052 .recv_intr_zoneupdate += 1;
1053 }
1054
1055 ret = IRQ_HANDLED;
1056 } else {
1057 ret = IRQ_NONE;
1058 }
1059
1060 return ret;
1061}
1062
1063static int fjes_rxframe_search_exist(struct fjes_adapter *adapter,
1064 int start_epid)
1065{
1066 struct fjes_hw *hw = &adapter->hw;
1067 enum ep_partner_status pstatus;
1068 int max_epid, cur_epid;
1069 int i;
1070
1071 max_epid = hw->max_epid;
1072 start_epid = (start_epid + 1 + max_epid) % max_epid;
1073
1074 for (i = 0; i < max_epid; i++) {
1075 cur_epid = (start_epid + i) % max_epid;
1076 if (cur_epid == hw->my_epid)
1077 continue;
1078
1079 pstatus = fjes_hw_get_partner_ep_status(hw, cur_epid);
1080 if (pstatus == EP_PARTNER_SHARED) {
1081 if (!fjes_hw_epbuf_rx_is_empty(
1082 &hw->ep_shm_info[cur_epid].rx))
1083 return cur_epid;
1084 }
1085 }
1086 return -1;
1087}
1088
1089static void *fjes_rxframe_get(struct fjes_adapter *adapter, size_t *psize,
1090 int *cur_epid)
1091{
1092 void *frame;
1093
1094 *cur_epid = fjes_rxframe_search_exist(adapter, *cur_epid);
1095 if (*cur_epid < 0)
1096 return NULL;
1097
1098 frame =
1099 fjes_hw_epbuf_rx_curpkt_get_addr(
1100 &adapter->hw.ep_shm_info[*cur_epid].rx, psize);
1101
1102 return frame;
1103}
1104
1105static void fjes_rxframe_release(struct fjes_adapter *adapter, int cur_epid)
1106{
1107 fjes_hw_epbuf_rx_curpkt_drop(&adapter->hw.ep_shm_info[cur_epid].rx);
1108}
1109
1110static void fjes_rx_irq(struct fjes_adapter *adapter, int src_epid)
1111{
1112 struct fjes_hw *hw = &adapter->hw;
1113
1114 fjes_hw_set_irqmask(hw, REG_ICTL_MASK_RX_DATA, true);
1115
1116 adapter->unset_rx_last = true;
1117 napi_schedule(&adapter->napi);
1118}
1119
1120static int fjes_poll(struct napi_struct *napi, int budget)
1121{
1122 struct fjes_adapter *adapter =
1123 container_of(napi, struct fjes_adapter, napi);
1124 struct net_device *netdev = napi->dev;
1125 struct fjes_hw *hw = &adapter->hw;
1126 struct sk_buff *skb;
1127 int work_done = 0;
1128 int cur_epid = 0;
1129 int epidx;
1130 size_t frame_len;
1131 void *frame;
1132
1133 spin_lock(&hw->rx_status_lock);
1134 for (epidx = 0; epidx < hw->max_epid; epidx++) {
1135 if (epidx == hw->my_epid)
1136 continue;
1137
1138 if (fjes_hw_get_partner_ep_status(hw, epidx) ==
1139 EP_PARTNER_SHARED)
1140 adapter->hw.ep_shm_info[epidx]
1141 .tx.info->v1i.rx_status |= FJES_RX_POLL_WORK;
1142 }
1143 spin_unlock(&hw->rx_status_lock);
1144
1145 while (work_done < budget) {
1146 prefetch(&adapter->hw);
1147 frame = fjes_rxframe_get(adapter, &frame_len, &cur_epid);
1148
1149 if (frame) {
1150 skb = napi_alloc_skb(napi, frame_len);
1151 if (!skb) {
1152 adapter->stats64.rx_dropped += 1;
1153 hw->ep_shm_info[cur_epid].net_stats
1154 .rx_dropped += 1;
1155 adapter->stats64.rx_errors += 1;
1156 hw->ep_shm_info[cur_epid].net_stats
1157 .rx_errors += 1;
1158 } else {
1159 memcpy(skb_put(skb, frame_len),
1160 frame, frame_len);
1161 skb->protocol = eth_type_trans(skb, netdev);
1162 skb->ip_summed = CHECKSUM_UNNECESSARY;
1163
1164 netif_receive_skb(skb);
1165
1166 work_done++;
1167
1168 adapter->stats64.rx_packets += 1;
1169 hw->ep_shm_info[cur_epid].net_stats
1170 .rx_packets += 1;
1171 adapter->stats64.rx_bytes += frame_len;
1172 hw->ep_shm_info[cur_epid].net_stats
1173 .rx_bytes += frame_len;
1174
1175 if (is_multicast_ether_addr(
1176 ((struct ethhdr *)frame)->h_dest)) {
1177 adapter->stats64.multicast += 1;
1178 hw->ep_shm_info[cur_epid].net_stats
1179 .multicast += 1;
1180 }
1181 }
1182
1183 fjes_rxframe_release(adapter, cur_epid);
1184 adapter->unset_rx_last = true;
1185 } else {
1186 break;
1187 }
1188 }
1189
1190 if (work_done < budget) {
1191 napi_complete_done(napi, work_done);
1192
1193 if (adapter->unset_rx_last) {
1194 adapter->rx_last_jiffies = jiffies;
1195 adapter->unset_rx_last = false;
1196 }
1197
1198 if (((long)jiffies - (long)adapter->rx_last_jiffies) < 3) {
1199 napi_reschedule(napi);
1200 } else {
1201 spin_lock(&hw->rx_status_lock);
1202 for (epidx = 0; epidx < hw->max_epid; epidx++) {
1203 if (epidx == hw->my_epid)
1204 continue;
1205 if (fjes_hw_get_partner_ep_status(hw, epidx) ==
1206 EP_PARTNER_SHARED)
1207 adapter->hw.ep_shm_info[epidx].tx
1208 .info->v1i.rx_status &=
1209 ~FJES_RX_POLL_WORK;
1210 }
1211 spin_unlock(&hw->rx_status_lock);
1212
1213 fjes_hw_set_irqmask(hw, REG_ICTL_MASK_RX_DATA, false);
1214 }
1215 }
1216
1217 return work_done;
1218}
1219
1220
1221static int fjes_probe(struct platform_device *plat_dev)
1222{
1223 struct fjes_adapter *adapter;
1224 struct net_device *netdev;
1225 struct resource *res;
1226 struct fjes_hw *hw;
1227 int err;
1228
1229 err = -ENOMEM;
1230 netdev = alloc_netdev_mq(sizeof(struct fjes_adapter), "es%d",
1231 NET_NAME_UNKNOWN, fjes_netdev_setup,
1232 FJES_MAX_QUEUES);
1233
1234 if (!netdev)
1235 goto err_out;
1236
1237 SET_NETDEV_DEV(netdev, &plat_dev->dev);
1238
1239 dev_set_drvdata(&plat_dev->dev, netdev);
1240 adapter = netdev_priv(netdev);
1241 adapter->netdev = netdev;
1242 adapter->plat_dev = plat_dev;
1243 hw = &adapter->hw;
1244 hw->back = adapter;
1245
1246
1247 err = fjes_sw_init(adapter);
1248 if (err)
1249 goto err_free_netdev;
1250
1251 INIT_WORK(&adapter->force_close_task, fjes_force_close_task);
1252 adapter->force_reset = false;
1253 adapter->open_guard = false;
1254
1255 adapter->txrx_wq = alloc_workqueue(DRV_NAME "/txrx", WQ_MEM_RECLAIM, 0);
1256 adapter->control_wq = alloc_workqueue(DRV_NAME "/control",
1257 WQ_MEM_RECLAIM, 0);
1258
1259 INIT_WORK(&adapter->tx_stall_task, fjes_tx_stall_task);
1260 INIT_WORK(&adapter->raise_intr_rxdata_task,
1261 fjes_raise_intr_rxdata_task);
1262 INIT_WORK(&adapter->unshare_watch_task, fjes_watch_unshare_task);
1263 adapter->unshare_watch_bitmask = 0;
1264
1265 INIT_DELAYED_WORK(&adapter->interrupt_watch_task, fjes_irq_watch_task);
1266 adapter->interrupt_watch_enable = false;
1267
1268 res = platform_get_resource(plat_dev, IORESOURCE_MEM, 0);
1269 hw->hw_res.start = res->start;
1270 hw->hw_res.size = resource_size(res);
1271 hw->hw_res.irq = platform_get_irq(plat_dev, 0);
1272 err = fjes_hw_init(&adapter->hw);
1273 if (err)
1274 goto err_free_netdev;
1275
1276
1277 netdev->dev_addr[0] = 2;
1278 netdev->dev_addr[1] = 0;
1279 netdev->dev_addr[2] = 0;
1280 netdev->dev_addr[3] = 0;
1281 netdev->dev_addr[4] = 0;
1282 netdev->dev_addr[5] = hw->my_epid;
1283
1284 err = register_netdev(netdev);
1285 if (err)
1286 goto err_hw_exit;
1287
1288 netif_carrier_off(netdev);
1289
1290 fjes_dbg_adapter_init(adapter);
1291
1292 return 0;
1293
1294err_hw_exit:
1295 fjes_hw_exit(&adapter->hw);
1296err_free_netdev:
1297 free_netdev(netdev);
1298err_out:
1299 return err;
1300}
1301
1302
1303static int fjes_remove(struct platform_device *plat_dev)
1304{
1305 struct net_device *netdev = dev_get_drvdata(&plat_dev->dev);
1306 struct fjes_adapter *adapter = netdev_priv(netdev);
1307 struct fjes_hw *hw = &adapter->hw;
1308
1309 fjes_dbg_adapter_exit(adapter);
1310
1311 cancel_delayed_work_sync(&adapter->interrupt_watch_task);
1312 cancel_work_sync(&adapter->unshare_watch_task);
1313 cancel_work_sync(&adapter->raise_intr_rxdata_task);
1314 cancel_work_sync(&adapter->tx_stall_task);
1315 if (adapter->control_wq)
1316 destroy_workqueue(adapter->control_wq);
1317 if (adapter->txrx_wq)
1318 destroy_workqueue(adapter->txrx_wq);
1319
1320 unregister_netdev(netdev);
1321
1322 fjes_hw_exit(hw);
1323
1324 netif_napi_del(&adapter->napi);
1325
1326 free_netdev(netdev);
1327
1328 return 0;
1329}
1330
1331static int fjes_sw_init(struct fjes_adapter *adapter)
1332{
1333 struct net_device *netdev = adapter->netdev;
1334
1335 netif_napi_add(netdev, &adapter->napi, fjes_poll, 64);
1336
1337 return 0;
1338}
1339
1340
1341static void fjes_netdev_setup(struct net_device *netdev)
1342{
1343 ether_setup(netdev);
1344
1345 netdev->watchdog_timeo = FJES_TX_RETRY_INTERVAL;
1346 netdev->netdev_ops = &fjes_netdev_ops;
1347 fjes_set_ethtool_ops(netdev);
1348 netdev->mtu = fjes_support_mtu[3];
1349 netdev->min_mtu = fjes_support_mtu[0];
1350 netdev->max_mtu = fjes_support_mtu[3];
1351 netdev->flags |= IFF_BROADCAST;
1352 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
1353}
1354
1355static void fjes_irq_watch_task(struct work_struct *work)
1356{
1357 struct fjes_adapter *adapter = container_of(to_delayed_work(work),
1358 struct fjes_adapter, interrupt_watch_task);
1359
1360 local_irq_disable();
1361 fjes_intr(adapter->hw.hw_res.irq, adapter);
1362 local_irq_enable();
1363
1364 if (fjes_rxframe_search_exist(adapter, 0) >= 0)
1365 napi_schedule(&adapter->napi);
1366
1367 if (adapter->interrupt_watch_enable) {
1368 if (!delayed_work_pending(&adapter->interrupt_watch_task))
1369 queue_delayed_work(adapter->control_wq,
1370 &adapter->interrupt_watch_task,
1371 FJES_IRQ_WATCH_DELAY);
1372 }
1373}
1374
1375static void fjes_watch_unshare_task(struct work_struct *work)
1376{
1377 struct fjes_adapter *adapter =
1378 container_of(work, struct fjes_adapter, unshare_watch_task);
1379
1380 struct net_device *netdev = adapter->netdev;
1381 struct fjes_hw *hw = &adapter->hw;
1382
1383 int unshare_watch, unshare_reserve;
1384 int max_epid, my_epid, epidx;
1385 int stop_req, stop_req_done;
1386 ulong unshare_watch_bitmask;
1387 unsigned long flags;
1388 int wait_time = 0;
1389 int is_shared;
1390 int ret;
1391
1392 my_epid = hw->my_epid;
1393 max_epid = hw->max_epid;
1394
1395 unshare_watch_bitmask = adapter->unshare_watch_bitmask;
1396 adapter->unshare_watch_bitmask = 0;
1397
1398 while ((unshare_watch_bitmask || hw->txrx_stop_req_bit) &&
1399 (wait_time < 3000)) {
1400 for (epidx = 0; epidx < hw->max_epid; epidx++) {
1401 if (epidx == hw->my_epid)
1402 continue;
1403
1404 is_shared = fjes_hw_epid_is_shared(hw->hw_info.share,
1405 epidx);
1406
1407 stop_req = test_bit(epidx, &hw->txrx_stop_req_bit);
1408
1409 stop_req_done = hw->ep_shm_info[epidx].rx.info->v1i.rx_status &
1410 FJES_RX_STOP_REQ_DONE;
1411
1412 unshare_watch = test_bit(epidx, &unshare_watch_bitmask);
1413
1414 unshare_reserve = test_bit(epidx,
1415 &hw->hw_info.buffer_unshare_reserve_bit);
1416
1417 if ((!stop_req ||
1418 (is_shared && (!is_shared || !stop_req_done))) &&
1419 (is_shared || !unshare_watch || !unshare_reserve))
1420 continue;
1421
1422 mutex_lock(&hw->hw_info.lock);
1423 ret = fjes_hw_unregister_buff_addr(hw, epidx);
1424 switch (ret) {
1425 case 0:
1426 break;
1427 case -ENOMSG:
1428 case -EBUSY:
1429 default:
1430 if (!work_pending(
1431 &adapter->force_close_task)) {
1432 adapter->force_reset = true;
1433 schedule_work(
1434 &adapter->force_close_task);
1435 }
1436 break;
1437 }
1438 mutex_unlock(&hw->hw_info.lock);
1439 hw->ep_shm_info[epidx].ep_stats
1440 .com_unregist_buf_exec += 1;
1441
1442 spin_lock_irqsave(&hw->rx_status_lock, flags);
1443 fjes_hw_setup_epbuf(&hw->ep_shm_info[epidx].tx,
1444 netdev->dev_addr, netdev->mtu);
1445 spin_unlock_irqrestore(&hw->rx_status_lock, flags);
1446
1447 clear_bit(epidx, &hw->txrx_stop_req_bit);
1448 clear_bit(epidx, &unshare_watch_bitmask);
1449 clear_bit(epidx,
1450 &hw->hw_info.buffer_unshare_reserve_bit);
1451 }
1452
1453 msleep(100);
1454 wait_time += 100;
1455 }
1456
1457 if (hw->hw_info.buffer_unshare_reserve_bit) {
1458 for (epidx = 0; epidx < hw->max_epid; epidx++) {
1459 if (epidx == hw->my_epid)
1460 continue;
1461
1462 if (test_bit(epidx,
1463 &hw->hw_info.buffer_unshare_reserve_bit)) {
1464 mutex_lock(&hw->hw_info.lock);
1465
1466 ret = fjes_hw_unregister_buff_addr(hw, epidx);
1467 switch (ret) {
1468 case 0:
1469 break;
1470 case -ENOMSG:
1471 case -EBUSY:
1472 default:
1473 if (!work_pending(
1474 &adapter->force_close_task)) {
1475 adapter->force_reset = true;
1476 schedule_work(
1477 &adapter->force_close_task);
1478 }
1479 break;
1480 }
1481 mutex_unlock(&hw->hw_info.lock);
1482
1483 hw->ep_shm_info[epidx].ep_stats
1484 .com_unregist_buf_exec += 1;
1485
1486 spin_lock_irqsave(&hw->rx_status_lock, flags);
1487 fjes_hw_setup_epbuf(
1488 &hw->ep_shm_info[epidx].tx,
1489 netdev->dev_addr, netdev->mtu);
1490 spin_unlock_irqrestore(&hw->rx_status_lock,
1491 flags);
1492
1493 clear_bit(epidx, &hw->txrx_stop_req_bit);
1494 clear_bit(epidx, &unshare_watch_bitmask);
1495 clear_bit(epidx, &hw->hw_info.buffer_unshare_reserve_bit);
1496 }
1497
1498 if (test_bit(epidx, &unshare_watch_bitmask)) {
1499 spin_lock_irqsave(&hw->rx_status_lock, flags);
1500 hw->ep_shm_info[epidx].tx.info->v1i.rx_status &=
1501 ~FJES_RX_STOP_REQ_DONE;
1502 spin_unlock_irqrestore(&hw->rx_status_lock,
1503 flags);
1504 }
1505 }
1506 }
1507}
1508
1509static acpi_status
1510acpi_find_extended_socket_device(acpi_handle obj_handle, u32 level,
1511 void *context, void **return_value)
1512{
1513 struct acpi_device *device;
1514 bool *found = context;
1515 int result;
1516
1517 result = acpi_bus_get_device(obj_handle, &device);
1518 if (result)
1519 return AE_OK;
1520
1521 if (strcmp(acpi_device_hid(device), ACPI_MOTHERBOARD_RESOURCE_HID))
1522 return AE_OK;
1523
1524 if (!is_extended_socket_device(device))
1525 return AE_OK;
1526
1527 if (acpi_check_extended_socket_status(device))
1528 return AE_OK;
1529
1530 *found = true;
1531 return AE_CTRL_TERMINATE;
1532}
1533
1534
1535static int __init fjes_init_module(void)
1536{
1537 bool found = false;
1538 int result;
1539
1540 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1541 acpi_find_extended_socket_device, NULL, &found,
1542 NULL);
1543
1544 if (!found)
1545 return -ENODEV;
1546
1547 pr_info("%s - version %s - %s\n",
1548 fjes_driver_string, fjes_driver_version, fjes_copyright);
1549
1550 fjes_dbg_init();
1551
1552 result = platform_driver_register(&fjes_driver);
1553 if (result < 0) {
1554 fjes_dbg_exit();
1555 return result;
1556 }
1557
1558 result = acpi_bus_register_driver(&fjes_acpi_driver);
1559 if (result < 0)
1560 goto fail_acpi_driver;
1561
1562 return 0;
1563
1564fail_acpi_driver:
1565 platform_driver_unregister(&fjes_driver);
1566 fjes_dbg_exit();
1567 return result;
1568}
1569
1570module_init(fjes_init_module);
1571
1572
1573static void __exit fjes_exit_module(void)
1574{
1575 acpi_bus_unregister_driver(&fjes_acpi_driver);
1576 platform_driver_unregister(&fjes_driver);
1577 fjes_dbg_exit();
1578}
1579
1580module_exit(fjes_exit_module);
1581