2 * drivers/net/ethernet/rocker/rocker.c - Rocker switch device driver
3 * Copyright (c) 2014-2016 Jiri Pirko <jiri@mellanox.com>
4 * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/pci.h>
15 #include <linux/interrupt.h>
16 #include <linux/sched.h>
17 #include <linux/wait.h>
18 #include <linux/spinlock.h>
19 #include <linux/sort.h>
20 #include <linux/random.h>
21 #include <linux/netdevice.h>
22 #include <linux/skbuff.h>
23 #include <linux/socket.h>
24 #include <linux/etherdevice.h>
25 #include <linux/ethtool.h>
26 #include <linux/if_ether.h>
27 #include <linux/if_vlan.h>
28 #include <linux/if_bridge.h>
29 #include <linux/bitops.h>
30 #include <linux/ctype.h>
31 #include <net/switchdev.h>
32 #include <net/rtnetlink.h>
33 #include <net/netevent.h>
35 #include <linux/io-64-nonatomic-lo-hi.h>
36 #include <generated/utsrelease.h>
38 #include "rocker_hw.h"
40 #include "rocker_tlv.h"
42 static const char rocker_driver_name
[] = "rocker";
44 static const struct pci_device_id rocker_pci_id_table
[] = {
45 {PCI_VDEVICE(REDHAT
, PCI_DEVICE_ID_REDHAT_ROCKER
), 0},
50 wait_queue_head_t wait
;
55 static void rocker_wait_reset(struct rocker_wait
*wait
)
61 static void rocker_wait_init(struct rocker_wait
*wait
)
63 init_waitqueue_head(&wait
->wait
);
64 rocker_wait_reset(wait
);
67 static struct rocker_wait
*rocker_wait_create(void)
69 struct rocker_wait
*wait
;
71 wait
= kzalloc(sizeof(*wait
), GFP_KERNEL
);
77 static void rocker_wait_destroy(struct rocker_wait
*wait
)
82 static bool rocker_wait_event_timeout(struct rocker_wait
*wait
,
83 unsigned long timeout
)
85 wait_event_timeout(wait
->wait
, wait
->done
, HZ
/ 10);
91 static void rocker_wait_wake_up(struct rocker_wait
*wait
)
97 static u32
rocker_msix_vector(const struct rocker
*rocker
, unsigned int vector
)
99 return rocker
->msix_entries
[vector
].vector
;
102 static u32
rocker_msix_tx_vector(const struct rocker_port
*rocker_port
)
104 return rocker_msix_vector(rocker_port
->rocker
,
105 ROCKER_MSIX_VEC_TX(rocker_port
->port_number
));
108 static u32
rocker_msix_rx_vector(const struct rocker_port
*rocker_port
)
110 return rocker_msix_vector(rocker_port
->rocker
,
111 ROCKER_MSIX_VEC_RX(rocker_port
->port_number
));
114 #define rocker_write32(rocker, reg, val) \
115 writel((val), (rocker)->hw_addr + (ROCKER_ ## reg))
116 #define rocker_read32(rocker, reg) \
117 readl((rocker)->hw_addr + (ROCKER_ ## reg))
118 #define rocker_write64(rocker, reg, val) \
119 writeq((val), (rocker)->hw_addr + (ROCKER_ ## reg))
120 #define rocker_read64(rocker, reg) \
121 readq((rocker)->hw_addr + (ROCKER_ ## reg))
123 /*****************************
124 * HW basic testing functions
125 *****************************/
127 static int rocker_reg_test(const struct rocker
*rocker
)
129 const struct pci_dev
*pdev
= rocker
->pdev
;
135 rocker_write32(rocker
, TEST_REG
, rnd
);
136 test_reg
= rocker_read32(rocker
, TEST_REG
);
137 if (test_reg
!= rnd
* 2) {
138 dev_err(&pdev
->dev
, "unexpected 32bit register value %08llx, expected %08llx\n",
145 rnd
|= prandom_u32();
146 rocker_write64(rocker
, TEST_REG64
, rnd
);
147 test_reg
= rocker_read64(rocker
, TEST_REG64
);
148 if (test_reg
!= rnd
* 2) {
149 dev_err(&pdev
->dev
, "unexpected 64bit register value %16llx, expected %16llx\n",
157 static int rocker_dma_test_one(const struct rocker
*rocker
,
158 struct rocker_wait
*wait
, u32 test_type
,
159 dma_addr_t dma_handle
, const unsigned char *buf
,
160 const unsigned char *expect
, size_t size
)
162 const struct pci_dev
*pdev
= rocker
->pdev
;
165 rocker_wait_reset(wait
);
166 rocker_write32(rocker
, TEST_DMA_CTRL
, test_type
);
168 if (!rocker_wait_event_timeout(wait
, HZ
/ 10)) {
169 dev_err(&pdev
->dev
, "no interrupt received within a timeout\n");
173 for (i
= 0; i
< size
; i
++) {
174 if (buf
[i
] != expect
[i
]) {
175 dev_err(&pdev
->dev
, "unexpected memory content %02x at byte %x\n, %02x expected",
176 buf
[i
], i
, expect
[i
]);
183 #define ROCKER_TEST_DMA_BUF_SIZE (PAGE_SIZE * 4)
184 #define ROCKER_TEST_DMA_FILL_PATTERN 0x96
186 static int rocker_dma_test_offset(const struct rocker
*rocker
,
187 struct rocker_wait
*wait
, int offset
)
189 struct pci_dev
*pdev
= rocker
->pdev
;
190 unsigned char *alloc
;
192 unsigned char *expect
;
193 dma_addr_t dma_handle
;
197 alloc
= kzalloc(ROCKER_TEST_DMA_BUF_SIZE
* 2 + offset
,
198 GFP_KERNEL
| GFP_DMA
);
201 buf
= alloc
+ offset
;
202 expect
= buf
+ ROCKER_TEST_DMA_BUF_SIZE
;
204 dma_handle
= pci_map_single(pdev
, buf
, ROCKER_TEST_DMA_BUF_SIZE
,
205 PCI_DMA_BIDIRECTIONAL
);
206 if (pci_dma_mapping_error(pdev
, dma_handle
)) {
211 rocker_write64(rocker
, TEST_DMA_ADDR
, dma_handle
);
212 rocker_write32(rocker
, TEST_DMA_SIZE
, ROCKER_TEST_DMA_BUF_SIZE
);
214 memset(expect
, ROCKER_TEST_DMA_FILL_PATTERN
, ROCKER_TEST_DMA_BUF_SIZE
);
215 err
= rocker_dma_test_one(rocker
, wait
, ROCKER_TEST_DMA_CTRL_FILL
,
216 dma_handle
, buf
, expect
,
217 ROCKER_TEST_DMA_BUF_SIZE
);
221 memset(expect
, 0, ROCKER_TEST_DMA_BUF_SIZE
);
222 err
= rocker_dma_test_one(rocker
, wait
, ROCKER_TEST_DMA_CTRL_CLEAR
,
223 dma_handle
, buf
, expect
,
224 ROCKER_TEST_DMA_BUF_SIZE
);
228 prandom_bytes(buf
, ROCKER_TEST_DMA_BUF_SIZE
);
229 for (i
= 0; i
< ROCKER_TEST_DMA_BUF_SIZE
; i
++)
231 err
= rocker_dma_test_one(rocker
, wait
, ROCKER_TEST_DMA_CTRL_INVERT
,
232 dma_handle
, buf
, expect
,
233 ROCKER_TEST_DMA_BUF_SIZE
);
238 pci_unmap_single(pdev
, dma_handle
, ROCKER_TEST_DMA_BUF_SIZE
,
239 PCI_DMA_BIDIRECTIONAL
);
246 static int rocker_dma_test(const struct rocker
*rocker
,
247 struct rocker_wait
*wait
)
252 for (i
= 0; i
< 8; i
++) {
253 err
= rocker_dma_test_offset(rocker
, wait
, i
);
260 static irqreturn_t
rocker_test_irq_handler(int irq
, void *dev_id
)
262 struct rocker_wait
*wait
= dev_id
;
264 rocker_wait_wake_up(wait
);
269 static int rocker_basic_hw_test(const struct rocker
*rocker
)
271 const struct pci_dev
*pdev
= rocker
->pdev
;
272 struct rocker_wait wait
;
275 err
= rocker_reg_test(rocker
);
277 dev_err(&pdev
->dev
, "reg test failed\n");
281 err
= request_irq(rocker_msix_vector(rocker
, ROCKER_MSIX_VEC_TEST
),
282 rocker_test_irq_handler
, 0,
283 rocker_driver_name
, &wait
);
285 dev_err(&pdev
->dev
, "cannot assign test irq\n");
289 rocker_wait_init(&wait
);
290 rocker_write32(rocker
, TEST_IRQ
, ROCKER_MSIX_VEC_TEST
);
292 if (!rocker_wait_event_timeout(&wait
, HZ
/ 10)) {
293 dev_err(&pdev
->dev
, "no interrupt received within a timeout\n");
298 err
= rocker_dma_test(rocker
, &wait
);
300 dev_err(&pdev
->dev
, "dma test failed\n");
303 free_irq(rocker_msix_vector(rocker
, ROCKER_MSIX_VEC_TEST
), &wait
);
307 /******************************************
308 * DMA rings and descriptors manipulations
309 ******************************************/
311 static u32
__pos_inc(u32 pos
, size_t limit
)
313 return ++pos
== limit
? 0 : pos
;
316 static int rocker_desc_err(const struct rocker_desc_info
*desc_info
)
318 int err
= desc_info
->desc
->comp_err
& ~ROCKER_DMA_DESC_COMP_ERR_GEN
;
333 case -ROCKER_EMSGSIZE
:
335 case -ROCKER_ENOTSUP
:
337 case -ROCKER_ENOBUFS
:
344 static void rocker_desc_gen_clear(const struct rocker_desc_info
*desc_info
)
346 desc_info
->desc
->comp_err
&= ~ROCKER_DMA_DESC_COMP_ERR_GEN
;
349 static bool rocker_desc_gen(const struct rocker_desc_info
*desc_info
)
351 u32 comp_err
= desc_info
->desc
->comp_err
;
353 return comp_err
& ROCKER_DMA_DESC_COMP_ERR_GEN
? true : false;
357 rocker_desc_cookie_ptr_get(const struct rocker_desc_info
*desc_info
)
359 return (void *)(uintptr_t)desc_info
->desc
->cookie
;
362 static void rocker_desc_cookie_ptr_set(const struct rocker_desc_info
*desc_info
,
365 desc_info
->desc
->cookie
= (uintptr_t) ptr
;
368 static struct rocker_desc_info
*
369 rocker_desc_head_get(const struct rocker_dma_ring_info
*info
)
371 static struct rocker_desc_info
*desc_info
;
372 u32 head
= __pos_inc(info
->head
, info
->size
);
374 desc_info
= &info
->desc_info
[info
->head
];
375 if (head
== info
->tail
)
376 return NULL
; /* ring full */
377 desc_info
->tlv_size
= 0;
381 static void rocker_desc_commit(const struct rocker_desc_info
*desc_info
)
383 desc_info
->desc
->buf_size
= desc_info
->data_size
;
384 desc_info
->desc
->tlv_size
= desc_info
->tlv_size
;
387 static void rocker_desc_head_set(const struct rocker
*rocker
,
388 struct rocker_dma_ring_info
*info
,
389 const struct rocker_desc_info
*desc_info
)
391 u32 head
= __pos_inc(info
->head
, info
->size
);
393 BUG_ON(head
== info
->tail
);
394 rocker_desc_commit(desc_info
);
396 rocker_write32(rocker
, DMA_DESC_HEAD(info
->type
), head
);
399 static struct rocker_desc_info
*
400 rocker_desc_tail_get(struct rocker_dma_ring_info
*info
)
402 static struct rocker_desc_info
*desc_info
;
404 if (info
->tail
== info
->head
)
405 return NULL
; /* nothing to be done between head and tail */
406 desc_info
= &info
->desc_info
[info
->tail
];
407 if (!rocker_desc_gen(desc_info
))
408 return NULL
; /* gen bit not set, desc is not ready yet */
409 info
->tail
= __pos_inc(info
->tail
, info
->size
);
410 desc_info
->tlv_size
= desc_info
->desc
->tlv_size
;
414 static void rocker_dma_ring_credits_set(const struct rocker
*rocker
,
415 const struct rocker_dma_ring_info
*info
,
419 rocker_write32(rocker
, DMA_DESC_CREDITS(info
->type
), credits
);
422 static unsigned long rocker_dma_ring_size_fix(size_t size
)
424 return max(ROCKER_DMA_SIZE_MIN
,
425 min(roundup_pow_of_two(size
), ROCKER_DMA_SIZE_MAX
));
428 static int rocker_dma_ring_create(const struct rocker
*rocker
,
431 struct rocker_dma_ring_info
*info
)
435 BUG_ON(size
!= rocker_dma_ring_size_fix(size
));
440 info
->desc_info
= kcalloc(info
->size
, sizeof(*info
->desc_info
),
442 if (!info
->desc_info
)
445 info
->desc
= pci_alloc_consistent(rocker
->pdev
,
446 info
->size
* sizeof(*info
->desc
),
449 kfree(info
->desc_info
);
453 for (i
= 0; i
< info
->size
; i
++)
454 info
->desc_info
[i
].desc
= &info
->desc
[i
];
456 rocker_write32(rocker
, DMA_DESC_CTRL(info
->type
),
457 ROCKER_DMA_DESC_CTRL_RESET
);
458 rocker_write64(rocker
, DMA_DESC_ADDR(info
->type
), info
->mapaddr
);
459 rocker_write32(rocker
, DMA_DESC_SIZE(info
->type
), info
->size
);
464 static void rocker_dma_ring_destroy(const struct rocker
*rocker
,
465 const struct rocker_dma_ring_info
*info
)
467 rocker_write64(rocker
, DMA_DESC_ADDR(info
->type
), 0);
469 pci_free_consistent(rocker
->pdev
,
470 info
->size
* sizeof(struct rocker_desc
),
471 info
->desc
, info
->mapaddr
);
472 kfree(info
->desc_info
);
475 static void rocker_dma_ring_pass_to_producer(const struct rocker
*rocker
,
476 struct rocker_dma_ring_info
*info
)
480 BUG_ON(info
->head
|| info
->tail
);
482 /* When ring is consumer, we need to advance head for each desc.
483 * That tells hw that the desc is ready to be used by it.
485 for (i
= 0; i
< info
->size
- 1; i
++)
486 rocker_desc_head_set(rocker
, info
, &info
->desc_info
[i
]);
487 rocker_desc_commit(&info
->desc_info
[i
]);
490 static int rocker_dma_ring_bufs_alloc(const struct rocker
*rocker
,
491 const struct rocker_dma_ring_info
*info
,
492 int direction
, size_t buf_size
)
494 struct pci_dev
*pdev
= rocker
->pdev
;
498 for (i
= 0; i
< info
->size
; i
++) {
499 struct rocker_desc_info
*desc_info
= &info
->desc_info
[i
];
500 struct rocker_desc
*desc
= &info
->desc
[i
];
501 dma_addr_t dma_handle
;
504 buf
= kzalloc(buf_size
, GFP_KERNEL
| GFP_DMA
);
510 dma_handle
= pci_map_single(pdev
, buf
, buf_size
, direction
);
511 if (pci_dma_mapping_error(pdev
, dma_handle
)) {
517 desc_info
->data
= buf
;
518 desc_info
->data_size
= buf_size
;
519 dma_unmap_addr_set(desc_info
, mapaddr
, dma_handle
);
521 desc
->buf_addr
= dma_handle
;
522 desc
->buf_size
= buf_size
;
527 for (i
--; i
>= 0; i
--) {
528 const struct rocker_desc_info
*desc_info
= &info
->desc_info
[i
];
530 pci_unmap_single(pdev
, dma_unmap_addr(desc_info
, mapaddr
),
531 desc_info
->data_size
, direction
);
532 kfree(desc_info
->data
);
537 static void rocker_dma_ring_bufs_free(const struct rocker
*rocker
,
538 const struct rocker_dma_ring_info
*info
,
541 struct pci_dev
*pdev
= rocker
->pdev
;
544 for (i
= 0; i
< info
->size
; i
++) {
545 const struct rocker_desc_info
*desc_info
= &info
->desc_info
[i
];
546 struct rocker_desc
*desc
= &info
->desc
[i
];
550 pci_unmap_single(pdev
, dma_unmap_addr(desc_info
, mapaddr
),
551 desc_info
->data_size
, direction
);
552 kfree(desc_info
->data
);
556 static int rocker_dma_cmd_ring_wait_alloc(struct rocker_desc_info
*desc_info
)
558 struct rocker_wait
*wait
;
560 wait
= rocker_wait_create();
563 rocker_desc_cookie_ptr_set(desc_info
, wait
);
568 rocker_dma_cmd_ring_wait_free(const struct rocker_desc_info
*desc_info
)
570 struct rocker_wait
*wait
= rocker_desc_cookie_ptr_get(desc_info
);
572 rocker_wait_destroy(wait
);
575 static int rocker_dma_cmd_ring_waits_alloc(const struct rocker
*rocker
)
577 const struct rocker_dma_ring_info
*cmd_ring
= &rocker
->cmd_ring
;
581 for (i
= 0; i
< cmd_ring
->size
; i
++) {
582 err
= rocker_dma_cmd_ring_wait_alloc(&cmd_ring
->desc_info
[i
]);
589 for (i
--; i
>= 0; i
--)
590 rocker_dma_cmd_ring_wait_free(&cmd_ring
->desc_info
[i
]);
594 static void rocker_dma_cmd_ring_waits_free(const struct rocker
*rocker
)
596 const struct rocker_dma_ring_info
*cmd_ring
= &rocker
->cmd_ring
;
599 for (i
= 0; i
< cmd_ring
->size
; i
++)
600 rocker_dma_cmd_ring_wait_free(&cmd_ring
->desc_info
[i
]);
603 static int rocker_dma_rings_init(struct rocker
*rocker
)
605 const struct pci_dev
*pdev
= rocker
->pdev
;
608 err
= rocker_dma_ring_create(rocker
, ROCKER_DMA_CMD
,
609 ROCKER_DMA_CMD_DEFAULT_SIZE
,
612 dev_err(&pdev
->dev
, "failed to create command dma ring\n");
616 spin_lock_init(&rocker
->cmd_ring_lock
);
618 err
= rocker_dma_ring_bufs_alloc(rocker
, &rocker
->cmd_ring
,
619 PCI_DMA_BIDIRECTIONAL
, PAGE_SIZE
);
621 dev_err(&pdev
->dev
, "failed to alloc command dma ring buffers\n");
622 goto err_dma_cmd_ring_bufs_alloc
;
625 err
= rocker_dma_cmd_ring_waits_alloc(rocker
);
627 dev_err(&pdev
->dev
, "failed to alloc command dma ring waits\n");
628 goto err_dma_cmd_ring_waits_alloc
;
631 err
= rocker_dma_ring_create(rocker
, ROCKER_DMA_EVENT
,
632 ROCKER_DMA_EVENT_DEFAULT_SIZE
,
633 &rocker
->event_ring
);
635 dev_err(&pdev
->dev
, "failed to create event dma ring\n");
636 goto err_dma_event_ring_create
;
639 err
= rocker_dma_ring_bufs_alloc(rocker
, &rocker
->event_ring
,
640 PCI_DMA_FROMDEVICE
, PAGE_SIZE
);
642 dev_err(&pdev
->dev
, "failed to alloc event dma ring buffers\n");
643 goto err_dma_event_ring_bufs_alloc
;
645 rocker_dma_ring_pass_to_producer(rocker
, &rocker
->event_ring
);
648 err_dma_event_ring_bufs_alloc
:
649 rocker_dma_ring_destroy(rocker
, &rocker
->event_ring
);
650 err_dma_event_ring_create
:
651 rocker_dma_ring_bufs_free(rocker
, &rocker
->cmd_ring
,
652 PCI_DMA_BIDIRECTIONAL
);
653 err_dma_cmd_ring_waits_alloc
:
654 rocker_dma_cmd_ring_waits_free(rocker
);
655 err_dma_cmd_ring_bufs_alloc
:
656 rocker_dma_ring_destroy(rocker
, &rocker
->cmd_ring
);
660 static void rocker_dma_rings_fini(struct rocker
*rocker
)
662 rocker_dma_ring_bufs_free(rocker
, &rocker
->event_ring
,
663 PCI_DMA_BIDIRECTIONAL
);
664 rocker_dma_ring_destroy(rocker
, &rocker
->event_ring
);
665 rocker_dma_cmd_ring_waits_free(rocker
);
666 rocker_dma_ring_bufs_free(rocker
, &rocker
->cmd_ring
,
667 PCI_DMA_BIDIRECTIONAL
);
668 rocker_dma_ring_destroy(rocker
, &rocker
->cmd_ring
);
671 static int rocker_dma_rx_ring_skb_map(const struct rocker_port
*rocker_port
,
672 struct rocker_desc_info
*desc_info
,
673 struct sk_buff
*skb
, size_t buf_len
)
675 const struct rocker
*rocker
= rocker_port
->rocker
;
676 struct pci_dev
*pdev
= rocker
->pdev
;
677 dma_addr_t dma_handle
;
679 dma_handle
= pci_map_single(pdev
, skb
->data
, buf_len
,
681 if (pci_dma_mapping_error(pdev
, dma_handle
))
683 if (rocker_tlv_put_u64(desc_info
, ROCKER_TLV_RX_FRAG_ADDR
, dma_handle
))
684 goto tlv_put_failure
;
685 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_RX_FRAG_MAX_LEN
, buf_len
))
686 goto tlv_put_failure
;
690 pci_unmap_single(pdev
, dma_handle
, buf_len
, PCI_DMA_FROMDEVICE
);
691 desc_info
->tlv_size
= 0;
695 static size_t rocker_port_rx_buf_len(const struct rocker_port
*rocker_port
)
697 return rocker_port
->dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
700 static int rocker_dma_rx_ring_skb_alloc(const struct rocker_port
*rocker_port
,
701 struct rocker_desc_info
*desc_info
)
703 struct net_device
*dev
= rocker_port
->dev
;
705 size_t buf_len
= rocker_port_rx_buf_len(rocker_port
);
708 /* Ensure that hw will see tlv_size zero in case of an error.
709 * That tells hw to use another descriptor.
711 rocker_desc_cookie_ptr_set(desc_info
, NULL
);
712 desc_info
->tlv_size
= 0;
714 skb
= netdev_alloc_skb_ip_align(dev
, buf_len
);
717 err
= rocker_dma_rx_ring_skb_map(rocker_port
, desc_info
, skb
, buf_len
);
719 dev_kfree_skb_any(skb
);
722 rocker_desc_cookie_ptr_set(desc_info
, skb
);
726 static void rocker_dma_rx_ring_skb_unmap(const struct rocker
*rocker
,
727 const struct rocker_tlv
**attrs
)
729 struct pci_dev
*pdev
= rocker
->pdev
;
730 dma_addr_t dma_handle
;
733 if (!attrs
[ROCKER_TLV_RX_FRAG_ADDR
] ||
734 !attrs
[ROCKER_TLV_RX_FRAG_MAX_LEN
])
736 dma_handle
= rocker_tlv_get_u64(attrs
[ROCKER_TLV_RX_FRAG_ADDR
]);
737 len
= rocker_tlv_get_u16(attrs
[ROCKER_TLV_RX_FRAG_MAX_LEN
]);
738 pci_unmap_single(pdev
, dma_handle
, len
, PCI_DMA_FROMDEVICE
);
741 static void rocker_dma_rx_ring_skb_free(const struct rocker
*rocker
,
742 const struct rocker_desc_info
*desc_info
)
744 const struct rocker_tlv
*attrs
[ROCKER_TLV_RX_MAX
+ 1];
745 struct sk_buff
*skb
= rocker_desc_cookie_ptr_get(desc_info
);
749 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_RX_MAX
, desc_info
);
750 rocker_dma_rx_ring_skb_unmap(rocker
, attrs
);
751 dev_kfree_skb_any(skb
);
754 static int rocker_dma_rx_ring_skbs_alloc(const struct rocker_port
*rocker_port
)
756 const struct rocker_dma_ring_info
*rx_ring
= &rocker_port
->rx_ring
;
757 const struct rocker
*rocker
= rocker_port
->rocker
;
761 for (i
= 0; i
< rx_ring
->size
; i
++) {
762 err
= rocker_dma_rx_ring_skb_alloc(rocker_port
,
763 &rx_ring
->desc_info
[i
]);
770 for (i
--; i
>= 0; i
--)
771 rocker_dma_rx_ring_skb_free(rocker
, &rx_ring
->desc_info
[i
]);
775 static void rocker_dma_rx_ring_skbs_free(const struct rocker_port
*rocker_port
)
777 const struct rocker_dma_ring_info
*rx_ring
= &rocker_port
->rx_ring
;
778 const struct rocker
*rocker
= rocker_port
->rocker
;
781 for (i
= 0; i
< rx_ring
->size
; i
++)
782 rocker_dma_rx_ring_skb_free(rocker
, &rx_ring
->desc_info
[i
]);
785 static int rocker_port_dma_rings_init(struct rocker_port
*rocker_port
)
787 struct rocker
*rocker
= rocker_port
->rocker
;
790 err
= rocker_dma_ring_create(rocker
,
791 ROCKER_DMA_TX(rocker_port
->port_number
),
792 ROCKER_DMA_TX_DEFAULT_SIZE
,
793 &rocker_port
->tx_ring
);
795 netdev_err(rocker_port
->dev
, "failed to create tx dma ring\n");
799 err
= rocker_dma_ring_bufs_alloc(rocker
, &rocker_port
->tx_ring
,
801 ROCKER_DMA_TX_DESC_SIZE
);
803 netdev_err(rocker_port
->dev
, "failed to alloc tx dma ring buffers\n");
804 goto err_dma_tx_ring_bufs_alloc
;
807 err
= rocker_dma_ring_create(rocker
,
808 ROCKER_DMA_RX(rocker_port
->port_number
),
809 ROCKER_DMA_RX_DEFAULT_SIZE
,
810 &rocker_port
->rx_ring
);
812 netdev_err(rocker_port
->dev
, "failed to create rx dma ring\n");
813 goto err_dma_rx_ring_create
;
816 err
= rocker_dma_ring_bufs_alloc(rocker
, &rocker_port
->rx_ring
,
817 PCI_DMA_BIDIRECTIONAL
,
818 ROCKER_DMA_RX_DESC_SIZE
);
820 netdev_err(rocker_port
->dev
, "failed to alloc rx dma ring buffers\n");
821 goto err_dma_rx_ring_bufs_alloc
;
824 err
= rocker_dma_rx_ring_skbs_alloc(rocker_port
);
826 netdev_err(rocker_port
->dev
, "failed to alloc rx dma ring skbs\n");
827 goto err_dma_rx_ring_skbs_alloc
;
829 rocker_dma_ring_pass_to_producer(rocker
, &rocker_port
->rx_ring
);
833 err_dma_rx_ring_skbs_alloc
:
834 rocker_dma_ring_bufs_free(rocker
, &rocker_port
->rx_ring
,
835 PCI_DMA_BIDIRECTIONAL
);
836 err_dma_rx_ring_bufs_alloc
:
837 rocker_dma_ring_destroy(rocker
, &rocker_port
->rx_ring
);
838 err_dma_rx_ring_create
:
839 rocker_dma_ring_bufs_free(rocker
, &rocker_port
->tx_ring
,
841 err_dma_tx_ring_bufs_alloc
:
842 rocker_dma_ring_destroy(rocker
, &rocker_port
->tx_ring
);
846 static void rocker_port_dma_rings_fini(struct rocker_port
*rocker_port
)
848 struct rocker
*rocker
= rocker_port
->rocker
;
850 rocker_dma_rx_ring_skbs_free(rocker_port
);
851 rocker_dma_ring_bufs_free(rocker
, &rocker_port
->rx_ring
,
852 PCI_DMA_BIDIRECTIONAL
);
853 rocker_dma_ring_destroy(rocker
, &rocker_port
->rx_ring
);
854 rocker_dma_ring_bufs_free(rocker
, &rocker_port
->tx_ring
,
856 rocker_dma_ring_destroy(rocker
, &rocker_port
->tx_ring
);
859 static void rocker_port_set_enable(const struct rocker_port
*rocker_port
,
862 u64 val
= rocker_read64(rocker_port
->rocker
, PORT_PHYS_ENABLE
);
865 val
|= 1ULL << rocker_port
->pport
;
867 val
&= ~(1ULL << rocker_port
->pport
);
868 rocker_write64(rocker_port
->rocker
, PORT_PHYS_ENABLE
, val
);
871 /********************************
872 * Interrupt handler and helpers
873 ********************************/
875 static irqreturn_t
rocker_cmd_irq_handler(int irq
, void *dev_id
)
877 struct rocker
*rocker
= dev_id
;
878 const struct rocker_desc_info
*desc_info
;
879 struct rocker_wait
*wait
;
882 spin_lock(&rocker
->cmd_ring_lock
);
883 while ((desc_info
= rocker_desc_tail_get(&rocker
->cmd_ring
))) {
884 wait
= rocker_desc_cookie_ptr_get(desc_info
);
886 rocker_desc_gen_clear(desc_info
);
888 rocker_wait_wake_up(wait
);
892 spin_unlock(&rocker
->cmd_ring_lock
);
893 rocker_dma_ring_credits_set(rocker
, &rocker
->cmd_ring
, credits
);
898 static void rocker_port_link_up(const struct rocker_port
*rocker_port
)
900 netif_carrier_on(rocker_port
->dev
);
901 netdev_info(rocker_port
->dev
, "Link is up\n");
904 static void rocker_port_link_down(const struct rocker_port
*rocker_port
)
906 netif_carrier_off(rocker_port
->dev
);
907 netdev_info(rocker_port
->dev
, "Link is down\n");
910 static int rocker_event_link_change(const struct rocker
*rocker
,
911 const struct rocker_tlv
*info
)
913 const struct rocker_tlv
*attrs
[ROCKER_TLV_EVENT_LINK_CHANGED_MAX
+ 1];
914 unsigned int port_number
;
916 struct rocker_port
*rocker_port
;
918 rocker_tlv_parse_nested(attrs
, ROCKER_TLV_EVENT_LINK_CHANGED_MAX
, info
);
919 if (!attrs
[ROCKER_TLV_EVENT_LINK_CHANGED_PPORT
] ||
920 !attrs
[ROCKER_TLV_EVENT_LINK_CHANGED_LINKUP
])
923 rocker_tlv_get_u32(attrs
[ROCKER_TLV_EVENT_LINK_CHANGED_PPORT
]) - 1;
924 link_up
= rocker_tlv_get_u8(attrs
[ROCKER_TLV_EVENT_LINK_CHANGED_LINKUP
]);
926 if (port_number
>= rocker
->port_count
)
929 rocker_port
= rocker
->ports
[port_number
];
930 if (netif_carrier_ok(rocker_port
->dev
) != link_up
) {
932 rocker_port_link_up(rocker_port
);
934 rocker_port_link_down(rocker_port
);
940 static int rocker_world_port_ev_mac_vlan_seen(struct rocker_port
*rocker_port
,
941 const unsigned char *addr
,
944 static int rocker_event_mac_vlan_seen(const struct rocker
*rocker
,
945 const struct rocker_tlv
*info
)
947 const struct rocker_tlv
*attrs
[ROCKER_TLV_EVENT_MAC_VLAN_MAX
+ 1];
948 unsigned int port_number
;
949 struct rocker_port
*rocker_port
;
950 const unsigned char *addr
;
953 rocker_tlv_parse_nested(attrs
, ROCKER_TLV_EVENT_MAC_VLAN_MAX
, info
);
954 if (!attrs
[ROCKER_TLV_EVENT_MAC_VLAN_PPORT
] ||
955 !attrs
[ROCKER_TLV_EVENT_MAC_VLAN_MAC
] ||
956 !attrs
[ROCKER_TLV_EVENT_MAC_VLAN_VLAN_ID
])
959 rocker_tlv_get_u32(attrs
[ROCKER_TLV_EVENT_MAC_VLAN_PPORT
]) - 1;
960 addr
= rocker_tlv_data(attrs
[ROCKER_TLV_EVENT_MAC_VLAN_MAC
]);
961 vlan_id
= rocker_tlv_get_be16(attrs
[ROCKER_TLV_EVENT_MAC_VLAN_VLAN_ID
]);
963 if (port_number
>= rocker
->port_count
)
966 rocker_port
= rocker
->ports
[port_number
];
967 return rocker_world_port_ev_mac_vlan_seen(rocker_port
, addr
, vlan_id
);
970 static int rocker_event_process(const struct rocker
*rocker
,
971 const struct rocker_desc_info
*desc_info
)
973 const struct rocker_tlv
*attrs
[ROCKER_TLV_EVENT_MAX
+ 1];
974 const struct rocker_tlv
*info
;
977 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_EVENT_MAX
, desc_info
);
978 if (!attrs
[ROCKER_TLV_EVENT_TYPE
] ||
979 !attrs
[ROCKER_TLV_EVENT_INFO
])
982 type
= rocker_tlv_get_u16(attrs
[ROCKER_TLV_EVENT_TYPE
]);
983 info
= attrs
[ROCKER_TLV_EVENT_INFO
];
986 case ROCKER_TLV_EVENT_TYPE_LINK_CHANGED
:
987 return rocker_event_link_change(rocker
, info
);
988 case ROCKER_TLV_EVENT_TYPE_MAC_VLAN_SEEN
:
989 return rocker_event_mac_vlan_seen(rocker
, info
);
995 static irqreturn_t
rocker_event_irq_handler(int irq
, void *dev_id
)
997 struct rocker
*rocker
= dev_id
;
998 const struct pci_dev
*pdev
= rocker
->pdev
;
999 const struct rocker_desc_info
*desc_info
;
1003 while ((desc_info
= rocker_desc_tail_get(&rocker
->event_ring
))) {
1004 err
= rocker_desc_err(desc_info
);
1006 dev_err(&pdev
->dev
, "event desc received with err %d\n",
1009 err
= rocker_event_process(rocker
, desc_info
);
1011 dev_err(&pdev
->dev
, "event processing failed with err %d\n",
1014 rocker_desc_gen_clear(desc_info
);
1015 rocker_desc_head_set(rocker
, &rocker
->event_ring
, desc_info
);
1018 rocker_dma_ring_credits_set(rocker
, &rocker
->event_ring
, credits
);
1023 static irqreturn_t
rocker_tx_irq_handler(int irq
, void *dev_id
)
1025 struct rocker_port
*rocker_port
= dev_id
;
1027 napi_schedule(&rocker_port
->napi_tx
);
1031 static irqreturn_t
rocker_rx_irq_handler(int irq
, void *dev_id
)
1033 struct rocker_port
*rocker_port
= dev_id
;
1035 napi_schedule(&rocker_port
->napi_rx
);
1039 /********************
1041 ********************/
1043 int rocker_cmd_exec(struct rocker_port
*rocker_port
, bool nowait
,
1044 rocker_cmd_prep_cb_t prepare
, void *prepare_priv
,
1045 rocker_cmd_proc_cb_t process
, void *process_priv
)
1047 struct rocker
*rocker
= rocker_port
->rocker
;
1048 struct rocker_desc_info
*desc_info
;
1049 struct rocker_wait
*wait
;
1050 unsigned long lock_flags
;
1053 spin_lock_irqsave(&rocker
->cmd_ring_lock
, lock_flags
);
1055 desc_info
= rocker_desc_head_get(&rocker
->cmd_ring
);
1057 spin_unlock_irqrestore(&rocker
->cmd_ring_lock
, lock_flags
);
1061 wait
= rocker_desc_cookie_ptr_get(desc_info
);
1062 rocker_wait_init(wait
);
1063 wait
->nowait
= nowait
;
1065 err
= prepare(rocker_port
, desc_info
, prepare_priv
);
1067 spin_unlock_irqrestore(&rocker
->cmd_ring_lock
, lock_flags
);
1071 rocker_desc_head_set(rocker
, &rocker
->cmd_ring
, desc_info
);
1073 spin_unlock_irqrestore(&rocker
->cmd_ring_lock
, lock_flags
);
1078 if (!rocker_wait_event_timeout(wait
, HZ
/ 10))
1081 err
= rocker_desc_err(desc_info
);
1086 err
= process(rocker_port
, desc_info
, process_priv
);
1088 rocker_desc_gen_clear(desc_info
);
1093 rocker_cmd_get_port_settings_prep(const struct rocker_port
*rocker_port
,
1094 struct rocker_desc_info
*desc_info
,
1097 struct rocker_tlv
*cmd_info
;
1099 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_CMD_TYPE
,
1100 ROCKER_TLV_CMD_TYPE_GET_PORT_SETTINGS
))
1102 cmd_info
= rocker_tlv_nest_start(desc_info
, ROCKER_TLV_CMD_INFO
);
1105 if (rocker_tlv_put_u32(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
,
1106 rocker_port
->pport
))
1108 rocker_tlv_nest_end(desc_info
, cmd_info
);
1113 rocker_cmd_get_port_settings_ethtool_proc(const struct rocker_port
*rocker_port
,
1114 const struct rocker_desc_info
*desc_info
,
1117 struct ethtool_cmd
*ecmd
= priv
;
1118 const struct rocker_tlv
*attrs
[ROCKER_TLV_CMD_MAX
+ 1];
1119 const struct rocker_tlv
*info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_MAX
+ 1];
1124 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_CMD_MAX
, desc_info
);
1125 if (!attrs
[ROCKER_TLV_CMD_INFO
])
1128 rocker_tlv_parse_nested(info_attrs
, ROCKER_TLV_CMD_PORT_SETTINGS_MAX
,
1129 attrs
[ROCKER_TLV_CMD_INFO
]);
1130 if (!info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
] ||
1131 !info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
] ||
1132 !info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
])
1135 speed
= rocker_tlv_get_u32(info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
]);
1136 duplex
= rocker_tlv_get_u8(info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
]);
1137 autoneg
= rocker_tlv_get_u8(info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
]);
1139 ecmd
->transceiver
= XCVR_INTERNAL
;
1140 ecmd
->supported
= SUPPORTED_TP
;
1141 ecmd
->phy_address
= 0xff;
1142 ecmd
->port
= PORT_TP
;
1143 ethtool_cmd_speed_set(ecmd
, speed
);
1144 ecmd
->duplex
= duplex
? DUPLEX_FULL
: DUPLEX_HALF
;
1145 ecmd
->autoneg
= autoneg
? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
1151 rocker_cmd_get_port_settings_macaddr_proc(const struct rocker_port
*rocker_port
,
1152 const struct rocker_desc_info
*desc_info
,
1155 unsigned char *macaddr
= priv
;
1156 const struct rocker_tlv
*attrs
[ROCKER_TLV_CMD_MAX
+ 1];
1157 const struct rocker_tlv
*info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_MAX
+ 1];
1158 const struct rocker_tlv
*attr
;
1160 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_CMD_MAX
, desc_info
);
1161 if (!attrs
[ROCKER_TLV_CMD_INFO
])
1164 rocker_tlv_parse_nested(info_attrs
, ROCKER_TLV_CMD_PORT_SETTINGS_MAX
,
1165 attrs
[ROCKER_TLV_CMD_INFO
]);
1166 attr
= info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
];
1170 if (rocker_tlv_len(attr
) != ETH_ALEN
)
1173 ether_addr_copy(macaddr
, rocker_tlv_data(attr
));
1178 rocker_cmd_get_port_settings_mode_proc(const struct rocker_port
*rocker_port
,
1179 const struct rocker_desc_info
*desc_info
,
1183 const struct rocker_tlv
*attrs
[ROCKER_TLV_CMD_MAX
+ 1];
1184 const struct rocker_tlv
*info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_MAX
+ 1];
1185 const struct rocker_tlv
*attr
;
1187 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_CMD_MAX
, desc_info
);
1188 if (!attrs
[ROCKER_TLV_CMD_INFO
])
1191 rocker_tlv_parse_nested(info_attrs
, ROCKER_TLV_CMD_PORT_SETTINGS_MAX
,
1192 attrs
[ROCKER_TLV_CMD_INFO
]);
1193 attr
= info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_MODE
];
1197 *p_mode
= rocker_tlv_get_u8(info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_MODE
]);
1207 rocker_cmd_get_port_settings_phys_name_proc(const struct rocker_port
*rocker_port
,
1208 const struct rocker_desc_info
*desc_info
,
1211 const struct rocker_tlv
*info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_MAX
+ 1];
1212 const struct rocker_tlv
*attrs
[ROCKER_TLV_CMD_MAX
+ 1];
1213 struct port_name
*name
= priv
;
1214 const struct rocker_tlv
*attr
;
1218 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_CMD_MAX
, desc_info
);
1219 if (!attrs
[ROCKER_TLV_CMD_INFO
])
1222 rocker_tlv_parse_nested(info_attrs
, ROCKER_TLV_CMD_PORT_SETTINGS_MAX
,
1223 attrs
[ROCKER_TLV_CMD_INFO
]);
1224 attr
= info_attrs
[ROCKER_TLV_CMD_PORT_SETTINGS_PHYS_NAME
];
1228 len
= min_t(size_t, rocker_tlv_len(attr
), name
->len
);
1229 str
= rocker_tlv_data(attr
);
1231 /* make sure name only contains alphanumeric characters */
1232 for (i
= j
= 0; i
< len
; ++i
) {
1233 if (isalnum(str
[i
])) {
1234 name
->buf
[j
] = str
[i
];
1242 name
->buf
[j
] = '\0';
1248 rocker_cmd_set_port_settings_ethtool_prep(const struct rocker_port
*rocker_port
,
1249 struct rocker_desc_info
*desc_info
,
1252 struct ethtool_cmd
*ecmd
= priv
;
1253 struct rocker_tlv
*cmd_info
;
1255 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_CMD_TYPE
,
1256 ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS
))
1258 cmd_info
= rocker_tlv_nest_start(desc_info
, ROCKER_TLV_CMD_INFO
);
1261 if (rocker_tlv_put_u32(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
,
1262 rocker_port
->pport
))
1264 if (rocker_tlv_put_u32(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_SPEED
,
1265 ethtool_cmd_speed(ecmd
)))
1267 if (rocker_tlv_put_u8(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX
,
1270 if (rocker_tlv_put_u8(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG
,
1273 rocker_tlv_nest_end(desc_info
, cmd_info
);
1278 rocker_cmd_set_port_settings_macaddr_prep(const struct rocker_port
*rocker_port
,
1279 struct rocker_desc_info
*desc_info
,
1282 const unsigned char *macaddr
= priv
;
1283 struct rocker_tlv
*cmd_info
;
1285 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_CMD_TYPE
,
1286 ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS
))
1288 cmd_info
= rocker_tlv_nest_start(desc_info
, ROCKER_TLV_CMD_INFO
);
1291 if (rocker_tlv_put_u32(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
,
1292 rocker_port
->pport
))
1294 if (rocker_tlv_put(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR
,
1297 rocker_tlv_nest_end(desc_info
, cmd_info
);
1302 rocker_cmd_set_port_settings_mtu_prep(const struct rocker_port
*rocker_port
,
1303 struct rocker_desc_info
*desc_info
,
1306 int mtu
= *(int *)priv
;
1307 struct rocker_tlv
*cmd_info
;
1309 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_CMD_TYPE
,
1310 ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS
))
1312 cmd_info
= rocker_tlv_nest_start(desc_info
, ROCKER_TLV_CMD_INFO
);
1315 if (rocker_tlv_put_u32(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
,
1316 rocker_port
->pport
))
1318 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_MTU
,
1321 rocker_tlv_nest_end(desc_info
, cmd_info
);
1326 rocker_cmd_set_port_learning_prep(const struct rocker_port
*rocker_port
,
1327 struct rocker_desc_info
*desc_info
,
1330 bool learning
= *(bool *)priv
;
1331 struct rocker_tlv
*cmd_info
;
1333 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_CMD_TYPE
,
1334 ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS
))
1336 cmd_info
= rocker_tlv_nest_start(desc_info
, ROCKER_TLV_CMD_INFO
);
1339 if (rocker_tlv_put_u32(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_PPORT
,
1340 rocker_port
->pport
))
1342 if (rocker_tlv_put_u8(desc_info
, ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING
,
1345 rocker_tlv_nest_end(desc_info
, cmd_info
);
1349 static int rocker_cmd_get_port_settings_ethtool(struct rocker_port
*rocker_port
,
1350 struct ethtool_cmd
*ecmd
)
1352 return rocker_cmd_exec(rocker_port
, false,
1353 rocker_cmd_get_port_settings_prep
, NULL
,
1354 rocker_cmd_get_port_settings_ethtool_proc
,
1358 static int rocker_cmd_get_port_settings_macaddr(struct rocker_port
*rocker_port
,
1359 unsigned char *macaddr
)
1361 return rocker_cmd_exec(rocker_port
, false,
1362 rocker_cmd_get_port_settings_prep
, NULL
,
1363 rocker_cmd_get_port_settings_macaddr_proc
,
1367 static int rocker_cmd_get_port_settings_mode(struct rocker_port
*rocker_port
,
1370 return rocker_cmd_exec(rocker_port
, false,
1371 rocker_cmd_get_port_settings_prep
, NULL
,
1372 rocker_cmd_get_port_settings_mode_proc
, p_mode
);
1375 static int rocker_cmd_set_port_settings_ethtool(struct rocker_port
*rocker_port
,
1376 struct ethtool_cmd
*ecmd
)
1378 return rocker_cmd_exec(rocker_port
, false,
1379 rocker_cmd_set_port_settings_ethtool_prep
,
1383 static int rocker_cmd_set_port_settings_macaddr(struct rocker_port
*rocker_port
,
1384 unsigned char *macaddr
)
1386 return rocker_cmd_exec(rocker_port
, false,
1387 rocker_cmd_set_port_settings_macaddr_prep
,
1388 macaddr
, NULL
, NULL
);
1391 static int rocker_cmd_set_port_settings_mtu(struct rocker_port
*rocker_port
,
1394 return rocker_cmd_exec(rocker_port
, false,
1395 rocker_cmd_set_port_settings_mtu_prep
,
1399 int rocker_port_set_learning(struct rocker_port
*rocker_port
,
1402 return rocker_cmd_exec(rocker_port
, false,
1403 rocker_cmd_set_port_learning_prep
,
1404 &learning
, NULL
, NULL
);
1407 /**********************
1408 * Worlds manipulation
1409 **********************/
1411 static struct rocker_world_ops
*rocker_world_ops
[] = {
1415 #define ROCKER_WORLD_OPS_LEN ARRAY_SIZE(rocker_world_ops)
1417 static struct rocker_world_ops
*rocker_world_ops_find(u8 mode
)
1421 for (i
= 0; i
< ROCKER_WORLD_OPS_LEN
; i
++)
1422 if (rocker_world_ops
[i
]->mode
== mode
)
1423 return rocker_world_ops
[i
];
1427 static int rocker_world_init(struct rocker
*rocker
, u8 mode
)
1429 struct rocker_world_ops
*wops
;
1432 wops
= rocker_world_ops_find(mode
);
1434 dev_err(&rocker
->pdev
->dev
, "port mode \"%d\" is not supported\n",
1438 rocker
->wops
= wops
;
1439 rocker
->wpriv
= kzalloc(wops
->priv_size
, GFP_KERNEL
);
1444 err
= wops
->init(rocker
);
1446 kfree(rocker
->wpriv
);
1450 static void rocker_world_fini(struct rocker
*rocker
)
1452 struct rocker_world_ops
*wops
= rocker
->wops
;
1454 if (!wops
|| !wops
->fini
)
1457 kfree(rocker
->wpriv
);
1460 static int rocker_world_check_init(struct rocker_port
*rocker_port
)
1462 struct rocker
*rocker
= rocker_port
->rocker
;
1466 err
= rocker_cmd_get_port_settings_mode(rocker_port
, &mode
);
1468 dev_err(&rocker
->pdev
->dev
, "failed to get port mode\n");
1472 if (rocker
->wops
->mode
!= mode
) {
1473 dev_err(&rocker
->pdev
->dev
, "hardware has ports in different worlds, which is not supported\n");
1478 return rocker_world_init(rocker
, mode
);
1481 static int rocker_world_port_pre_init(struct rocker_port
*rocker_port
)
1483 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1486 rocker_port
->wpriv
= kzalloc(wops
->port_priv_size
, GFP_KERNEL
);
1487 if (!rocker_port
->wpriv
)
1489 if (!wops
->port_pre_init
)
1491 err
= wops
->port_pre_init(rocker_port
);
1493 kfree(rocker_port
->wpriv
);
1497 static int rocker_world_port_init(struct rocker_port
*rocker_port
)
1499 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1501 if (!wops
->port_init
)
1503 return wops
->port_init(rocker_port
);
1506 static void rocker_world_port_fini(struct rocker_port
*rocker_port
)
1508 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1510 if (!wops
->port_fini
)
1512 wops
->port_fini(rocker_port
);
1515 static void rocker_world_port_post_fini(struct rocker_port
*rocker_port
)
1517 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1519 if (!wops
->port_post_fini
)
1521 wops
->port_post_fini(rocker_port
);
1522 kfree(rocker_port
->wpriv
);
1525 static int rocker_world_port_open(struct rocker_port
*rocker_port
)
1527 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1529 if (!wops
->port_open
)
1531 return wops
->port_open(rocker_port
);
1534 static void rocker_world_port_stop(struct rocker_port
*rocker_port
)
1536 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1538 if (!wops
->port_stop
)
1540 wops
->port_stop(rocker_port
);
1543 static int rocker_world_port_attr_stp_state_set(struct rocker_port
*rocker_port
,
1545 struct switchdev_trans
*trans
)
1547 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1549 if (!wops
->port_attr_stp_state_set
)
1551 return wops
->port_attr_stp_state_set(rocker_port
, state
, trans
);
1555 rocker_world_port_attr_bridge_flags_set(struct rocker_port
*rocker_port
,
1556 unsigned long brport_flags
,
1557 struct switchdev_trans
*trans
)
1559 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1561 if (!wops
->port_attr_bridge_flags_set
)
1563 return wops
->port_attr_bridge_flags_set(rocker_port
, brport_flags
,
1568 rocker_world_port_attr_bridge_flags_get(const struct rocker_port
*rocker_port
,
1569 unsigned long *p_brport_flags
)
1571 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1573 if (!wops
->port_attr_bridge_flags_get
)
1575 return wops
->port_attr_bridge_flags_get(rocker_port
, p_brport_flags
);
1579 rocker_world_port_attr_bridge_ageing_time_set(struct rocker_port
*rocker_port
,
1581 struct switchdev_trans
*trans
)
1584 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1586 if (!wops
->port_attr_bridge_ageing_time_set
)
1588 return wops
->port_attr_bridge_ageing_time_set(rocker_port
, ageing_time
,
1593 rocker_world_port_obj_vlan_add(struct rocker_port
*rocker_port
,
1594 const struct switchdev_obj_port_vlan
*vlan
,
1595 struct switchdev_trans
*trans
)
1597 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1599 if (!wops
->port_obj_vlan_add
)
1601 return wops
->port_obj_vlan_add(rocker_port
, vlan
, trans
);
1605 rocker_world_port_obj_vlan_del(struct rocker_port
*rocker_port
,
1606 const struct switchdev_obj_port_vlan
*vlan
)
1608 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1610 if (!wops
->port_obj_vlan_del
)
1612 return wops
->port_obj_vlan_del(rocker_port
, vlan
);
1616 rocker_world_port_obj_vlan_dump(const struct rocker_port
*rocker_port
,
1617 struct switchdev_obj_port_vlan
*vlan
,
1618 switchdev_obj_dump_cb_t
*cb
)
1620 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1622 if (!wops
->port_obj_vlan_dump
)
1624 return wops
->port_obj_vlan_dump(rocker_port
, vlan
, cb
);
1628 rocker_world_port_obj_fib4_add(struct rocker_port
*rocker_port
,
1629 const struct switchdev_obj_ipv4_fib
*fib4
,
1630 struct switchdev_trans
*trans
)
1632 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1634 if (!wops
->port_obj_fib4_add
)
1636 return wops
->port_obj_fib4_add(rocker_port
, fib4
, trans
);
1640 rocker_world_port_obj_fib4_del(struct rocker_port
*rocker_port
,
1641 const struct switchdev_obj_ipv4_fib
*fib4
)
1643 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1645 if (!wops
->port_obj_fib4_del
)
1647 return wops
->port_obj_fib4_del(rocker_port
, fib4
);
1651 rocker_world_port_obj_fdb_add(struct rocker_port
*rocker_port
,
1652 const struct switchdev_obj_port_fdb
*fdb
,
1653 struct switchdev_trans
*trans
)
1655 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1657 if (!wops
->port_obj_fdb_add
)
1659 return wops
->port_obj_fdb_add(rocker_port
, fdb
, trans
);
1663 rocker_world_port_obj_fdb_del(struct rocker_port
*rocker_port
,
1664 const struct switchdev_obj_port_fdb
*fdb
)
1666 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1668 if (!wops
->port_obj_fdb_del
)
1670 return wops
->port_obj_fdb_del(rocker_port
, fdb
);
1674 rocker_world_port_obj_fdb_dump(const struct rocker_port
*rocker_port
,
1675 struct switchdev_obj_port_fdb
*fdb
,
1676 switchdev_obj_dump_cb_t
*cb
)
1678 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1680 if (!wops
->port_obj_fdb_dump
)
1682 return wops
->port_obj_fdb_dump(rocker_port
, fdb
, cb
);
1685 static int rocker_world_port_master_linked(struct rocker_port
*rocker_port
,
1686 struct net_device
*master
)
1688 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1690 if (!wops
->port_master_linked
)
1692 return wops
->port_master_linked(rocker_port
, master
);
1695 static int rocker_world_port_master_unlinked(struct rocker_port
*rocker_port
,
1696 struct net_device
*master
)
1698 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1700 if (!wops
->port_master_unlinked
)
1702 return wops
->port_master_unlinked(rocker_port
, master
);
1705 static int rocker_world_port_neigh_update(struct rocker_port
*rocker_port
,
1706 struct neighbour
*n
)
1708 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1710 if (!wops
->port_neigh_update
)
1712 return wops
->port_neigh_update(rocker_port
, n
);
1715 static int rocker_world_port_neigh_destroy(struct rocker_port
*rocker_port
,
1716 struct neighbour
*n
)
1718 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1720 if (!wops
->port_neigh_destroy
)
1722 return wops
->port_neigh_destroy(rocker_port
, n
);
1725 static int rocker_world_port_ev_mac_vlan_seen(struct rocker_port
*rocker_port
,
1726 const unsigned char *addr
,
1729 struct rocker_world_ops
*wops
= rocker_port
->rocker
->wops
;
1731 if (!wops
->port_ev_mac_vlan_seen
)
1733 return wops
->port_ev_mac_vlan_seen(rocker_port
, addr
, vlan_id
);
1740 static int rocker_port_open(struct net_device
*dev
)
1742 struct rocker_port
*rocker_port
= netdev_priv(dev
);
1745 err
= rocker_port_dma_rings_init(rocker_port
);
1749 err
= request_irq(rocker_msix_tx_vector(rocker_port
),
1750 rocker_tx_irq_handler
, 0,
1751 rocker_driver_name
, rocker_port
);
1753 netdev_err(rocker_port
->dev
, "cannot assign tx irq\n");
1754 goto err_request_tx_irq
;
1757 err
= request_irq(rocker_msix_rx_vector(rocker_port
),
1758 rocker_rx_irq_handler
, 0,
1759 rocker_driver_name
, rocker_port
);
1761 netdev_err(rocker_port
->dev
, "cannot assign rx irq\n");
1762 goto err_request_rx_irq
;
1765 err
= rocker_world_port_open(rocker_port
);
1767 netdev_err(rocker_port
->dev
, "cannot open port in world\n");
1768 goto err_world_port_open
;
1771 napi_enable(&rocker_port
->napi_tx
);
1772 napi_enable(&rocker_port
->napi_rx
);
1773 if (!dev
->proto_down
)
1774 rocker_port_set_enable(rocker_port
, true);
1775 netif_start_queue(dev
);
1778 err_world_port_open
:
1779 free_irq(rocker_msix_rx_vector(rocker_port
), rocker_port
);
1781 free_irq(rocker_msix_tx_vector(rocker_port
), rocker_port
);
1783 rocker_port_dma_rings_fini(rocker_port
);
1787 static int rocker_port_stop(struct net_device
*dev
)
1789 struct rocker_port
*rocker_port
= netdev_priv(dev
);
1791 netif_stop_queue(dev
);
1792 rocker_port_set_enable(rocker_port
, false);
1793 napi_disable(&rocker_port
->napi_rx
);
1794 napi_disable(&rocker_port
->napi_tx
);
1795 rocker_world_port_stop(rocker_port
);
1796 free_irq(rocker_msix_rx_vector(rocker_port
), rocker_port
);
1797 free_irq(rocker_msix_tx_vector(rocker_port
), rocker_port
);
1798 rocker_port_dma_rings_fini(rocker_port
);
1803 static void rocker_tx_desc_frags_unmap(const struct rocker_port
*rocker_port
,
1804 const struct rocker_desc_info
*desc_info
)
1806 const struct rocker
*rocker
= rocker_port
->rocker
;
1807 struct pci_dev
*pdev
= rocker
->pdev
;
1808 const struct rocker_tlv
*attrs
[ROCKER_TLV_TX_MAX
+ 1];
1809 struct rocker_tlv
*attr
;
1812 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_TX_MAX
, desc_info
);
1813 if (!attrs
[ROCKER_TLV_TX_FRAGS
])
1815 rocker_tlv_for_each_nested(attr
, attrs
[ROCKER_TLV_TX_FRAGS
], rem
) {
1816 const struct rocker_tlv
*frag_attrs
[ROCKER_TLV_TX_FRAG_ATTR_MAX
+ 1];
1817 dma_addr_t dma_handle
;
1820 if (rocker_tlv_type(attr
) != ROCKER_TLV_TX_FRAG
)
1822 rocker_tlv_parse_nested(frag_attrs
, ROCKER_TLV_TX_FRAG_ATTR_MAX
,
1824 if (!frag_attrs
[ROCKER_TLV_TX_FRAG_ATTR_ADDR
] ||
1825 !frag_attrs
[ROCKER_TLV_TX_FRAG_ATTR_LEN
])
1827 dma_handle
= rocker_tlv_get_u64(frag_attrs
[ROCKER_TLV_TX_FRAG_ATTR_ADDR
]);
1828 len
= rocker_tlv_get_u16(frag_attrs
[ROCKER_TLV_TX_FRAG_ATTR_LEN
]);
1829 pci_unmap_single(pdev
, dma_handle
, len
, DMA_TO_DEVICE
);
1833 static int rocker_tx_desc_frag_map_put(const struct rocker_port
*rocker_port
,
1834 struct rocker_desc_info
*desc_info
,
1835 char *buf
, size_t buf_len
)
1837 const struct rocker
*rocker
= rocker_port
->rocker
;
1838 struct pci_dev
*pdev
= rocker
->pdev
;
1839 dma_addr_t dma_handle
;
1840 struct rocker_tlv
*frag
;
1842 dma_handle
= pci_map_single(pdev
, buf
, buf_len
, DMA_TO_DEVICE
);
1843 if (unlikely(pci_dma_mapping_error(pdev
, dma_handle
))) {
1844 if (net_ratelimit())
1845 netdev_err(rocker_port
->dev
, "failed to dma map tx frag\n");
1848 frag
= rocker_tlv_nest_start(desc_info
, ROCKER_TLV_TX_FRAG
);
1851 if (rocker_tlv_put_u64(desc_info
, ROCKER_TLV_TX_FRAG_ATTR_ADDR
,
1854 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_TX_FRAG_ATTR_LEN
,
1857 rocker_tlv_nest_end(desc_info
, frag
);
1861 rocker_tlv_nest_cancel(desc_info
, frag
);
1863 pci_unmap_single(pdev
, dma_handle
, buf_len
, DMA_TO_DEVICE
);
1867 static netdev_tx_t
rocker_port_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1869 struct rocker_port
*rocker_port
= netdev_priv(dev
);
1870 struct rocker
*rocker
= rocker_port
->rocker
;
1871 struct rocker_desc_info
*desc_info
;
1872 struct rocker_tlv
*frags
;
1876 desc_info
= rocker_desc_head_get(&rocker_port
->tx_ring
);
1877 if (unlikely(!desc_info
)) {
1878 if (net_ratelimit())
1879 netdev_err(dev
, "tx ring full when queue awake\n");
1880 return NETDEV_TX_BUSY
;
1883 rocker_desc_cookie_ptr_set(desc_info
, skb
);
1885 frags
= rocker_tlv_nest_start(desc_info
, ROCKER_TLV_TX_FRAGS
);
1888 err
= rocker_tx_desc_frag_map_put(rocker_port
, desc_info
,
1889 skb
->data
, skb_headlen(skb
));
1892 if (skb_shinfo(skb
)->nr_frags
> ROCKER_TX_FRAGS_MAX
) {
1893 err
= skb_linearize(skb
);
1898 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1899 const skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1901 err
= rocker_tx_desc_frag_map_put(rocker_port
, desc_info
,
1902 skb_frag_address(frag
),
1903 skb_frag_size(frag
));
1907 rocker_tlv_nest_end(desc_info
, frags
);
1909 rocker_desc_gen_clear(desc_info
);
1910 rocker_desc_head_set(rocker
, &rocker_port
->tx_ring
, desc_info
);
1912 desc_info
= rocker_desc_head_get(&rocker_port
->tx_ring
);
1914 netif_stop_queue(dev
);
1916 return NETDEV_TX_OK
;
1919 rocker_tx_desc_frags_unmap(rocker_port
, desc_info
);
1921 rocker_tlv_nest_cancel(desc_info
, frags
);
1924 dev
->stats
.tx_dropped
++;
1926 return NETDEV_TX_OK
;
1929 static int rocker_port_set_mac_address(struct net_device
*dev
, void *p
)
1931 struct sockaddr
*addr
= p
;
1932 struct rocker_port
*rocker_port
= netdev_priv(dev
);
1935 if (!is_valid_ether_addr(addr
->sa_data
))
1936 return -EADDRNOTAVAIL
;
1938 err
= rocker_cmd_set_port_settings_macaddr(rocker_port
, addr
->sa_data
);
1941 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1945 static int rocker_port_change_mtu(struct net_device
*dev
, int new_mtu
)
1947 struct rocker_port
*rocker_port
= netdev_priv(dev
);
1948 int running
= netif_running(dev
);
1951 #define ROCKER_PORT_MIN_MTU 68
1952 #define ROCKER_PORT_MAX_MTU 9000
1954 if (new_mtu
< ROCKER_PORT_MIN_MTU
|| new_mtu
> ROCKER_PORT_MAX_MTU
)
1958 rocker_port_stop(dev
);
1960 netdev_info(dev
, "MTU change from %d to %d\n", dev
->mtu
, new_mtu
);
1963 err
= rocker_cmd_set_port_settings_mtu(rocker_port
, new_mtu
);
1968 err
= rocker_port_open(dev
);
1973 static int rocker_port_get_phys_port_name(struct net_device
*dev
,
1974 char *buf
, size_t len
)
1976 struct rocker_port
*rocker_port
= netdev_priv(dev
);
1977 struct port_name name
= { .buf
= buf
, .len
= len
};
1980 err
= rocker_cmd_exec(rocker_port
, false,
1981 rocker_cmd_get_port_settings_prep
, NULL
,
1982 rocker_cmd_get_port_settings_phys_name_proc
,
1985 return err
? -EOPNOTSUPP
: 0;
1988 static int rocker_port_change_proto_down(struct net_device
*dev
,
1991 struct rocker_port
*rocker_port
= netdev_priv(dev
);
1993 if (rocker_port
->dev
->flags
& IFF_UP
)
1994 rocker_port_set_enable(rocker_port
, !proto_down
);
1995 rocker_port
->dev
->proto_down
= proto_down
;
1999 static void rocker_port_neigh_destroy(struct net_device
*dev
,
2000 struct neighbour
*n
)
2002 struct rocker_port
*rocker_port
= netdev_priv(n
->dev
);
2005 err
= rocker_world_port_neigh_destroy(rocker_port
, n
);
2007 netdev_warn(rocker_port
->dev
, "failed to handle neigh destroy (err %d)\n",
2011 static const struct net_device_ops rocker_port_netdev_ops
= {
2012 .ndo_open
= rocker_port_open
,
2013 .ndo_stop
= rocker_port_stop
,
2014 .ndo_start_xmit
= rocker_port_xmit
,
2015 .ndo_set_mac_address
= rocker_port_set_mac_address
,
2016 .ndo_change_mtu
= rocker_port_change_mtu
,
2017 .ndo_bridge_getlink
= switchdev_port_bridge_getlink
,
2018 .ndo_bridge_setlink
= switchdev_port_bridge_setlink
,
2019 .ndo_bridge_dellink
= switchdev_port_bridge_dellink
,
2020 .ndo_fdb_add
= switchdev_port_fdb_add
,
2021 .ndo_fdb_del
= switchdev_port_fdb_del
,
2022 .ndo_fdb_dump
= switchdev_port_fdb_dump
,
2023 .ndo_get_phys_port_name
= rocker_port_get_phys_port_name
,
2024 .ndo_change_proto_down
= rocker_port_change_proto_down
,
2025 .ndo_neigh_destroy
= rocker_port_neigh_destroy
,
2028 /********************
2030 ********************/
2032 static int rocker_port_attr_get(struct net_device
*dev
,
2033 struct switchdev_attr
*attr
)
2035 const struct rocker_port
*rocker_port
= netdev_priv(dev
);
2036 const struct rocker
*rocker
= rocker_port
->rocker
;
2040 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID
:
2041 attr
->u
.ppid
.id_len
= sizeof(rocker
->hw
.id
);
2042 memcpy(&attr
->u
.ppid
.id
, &rocker
->hw
.id
, attr
->u
.ppid
.id_len
);
2044 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS
:
2045 err
= rocker_world_port_attr_bridge_flags_get(rocker_port
,
2046 &attr
->u
.brport_flags
);
2055 static int rocker_port_attr_set(struct net_device
*dev
,
2056 const struct switchdev_attr
*attr
,
2057 struct switchdev_trans
*trans
)
2059 struct rocker_port
*rocker_port
= netdev_priv(dev
);
2063 case SWITCHDEV_ATTR_ID_PORT_STP_STATE
:
2064 err
= rocker_world_port_attr_stp_state_set(rocker_port
,
2068 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS
:
2069 err
= rocker_world_port_attr_bridge_flags_set(rocker_port
,
2070 attr
->u
.brport_flags
,
2073 case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME
:
2074 err
= rocker_world_port_attr_bridge_ageing_time_set(rocker_port
,
2075 attr
->u
.ageing_time
,
2086 static int rocker_port_obj_add(struct net_device
*dev
,
2087 const struct switchdev_obj
*obj
,
2088 struct switchdev_trans
*trans
)
2090 struct rocker_port
*rocker_port
= netdev_priv(dev
);
2094 case SWITCHDEV_OBJ_ID_PORT_VLAN
:
2095 err
= rocker_world_port_obj_vlan_add(rocker_port
,
2096 SWITCHDEV_OBJ_PORT_VLAN(obj
),
2099 case SWITCHDEV_OBJ_ID_IPV4_FIB
:
2100 err
= rocker_world_port_obj_fib4_add(rocker_port
,
2101 SWITCHDEV_OBJ_IPV4_FIB(obj
),
2104 case SWITCHDEV_OBJ_ID_PORT_FDB
:
2105 err
= rocker_world_port_obj_fdb_add(rocker_port
,
2106 SWITCHDEV_OBJ_PORT_FDB(obj
),
2117 static int rocker_port_obj_del(struct net_device
*dev
,
2118 const struct switchdev_obj
*obj
)
2120 struct rocker_port
*rocker_port
= netdev_priv(dev
);
2124 case SWITCHDEV_OBJ_ID_PORT_VLAN
:
2125 err
= rocker_world_port_obj_vlan_del(rocker_port
,
2126 SWITCHDEV_OBJ_PORT_VLAN(obj
));
2128 case SWITCHDEV_OBJ_ID_IPV4_FIB
:
2129 err
= rocker_world_port_obj_fib4_del(rocker_port
,
2130 SWITCHDEV_OBJ_IPV4_FIB(obj
));
2132 case SWITCHDEV_OBJ_ID_PORT_FDB
:
2133 err
= rocker_world_port_obj_fdb_del(rocker_port
,
2134 SWITCHDEV_OBJ_PORT_FDB(obj
));
2144 static int rocker_port_obj_dump(struct net_device
*dev
,
2145 struct switchdev_obj
*obj
,
2146 switchdev_obj_dump_cb_t
*cb
)
2148 const struct rocker_port
*rocker_port
= netdev_priv(dev
);
2152 case SWITCHDEV_OBJ_ID_PORT_FDB
:
2153 err
= rocker_world_port_obj_fdb_dump(rocker_port
,
2154 SWITCHDEV_OBJ_PORT_FDB(obj
),
2157 case SWITCHDEV_OBJ_ID_PORT_VLAN
:
2158 err
= rocker_world_port_obj_vlan_dump(rocker_port
,
2159 SWITCHDEV_OBJ_PORT_VLAN(obj
),
2170 static const struct switchdev_ops rocker_port_switchdev_ops
= {
2171 .switchdev_port_attr_get
= rocker_port_attr_get
,
2172 .switchdev_port_attr_set
= rocker_port_attr_set
,
2173 .switchdev_port_obj_add
= rocker_port_obj_add
,
2174 .switchdev_port_obj_del
= rocker_port_obj_del
,
2175 .switchdev_port_obj_dump
= rocker_port_obj_dump
,
2178 /********************
2180 ********************/
2182 static int rocker_port_get_settings(struct net_device
*dev
,
2183 struct ethtool_cmd
*ecmd
)
2185 struct rocker_port
*rocker_port
= netdev_priv(dev
);
2187 return rocker_cmd_get_port_settings_ethtool(rocker_port
, ecmd
);
2190 static int rocker_port_set_settings(struct net_device
*dev
,
2191 struct ethtool_cmd
*ecmd
)
2193 struct rocker_port
*rocker_port
= netdev_priv(dev
);
2195 return rocker_cmd_set_port_settings_ethtool(rocker_port
, ecmd
);
2198 static void rocker_port_get_drvinfo(struct net_device
*dev
,
2199 struct ethtool_drvinfo
*drvinfo
)
2201 strlcpy(drvinfo
->driver
, rocker_driver_name
, sizeof(drvinfo
->driver
));
2202 strlcpy(drvinfo
->version
, UTS_RELEASE
, sizeof(drvinfo
->version
));
2205 static struct rocker_port_stats
{
2206 char str
[ETH_GSTRING_LEN
];
2208 } rocker_port_stats
[] = {
2209 { "rx_packets", ROCKER_TLV_CMD_PORT_STATS_RX_PKTS
, },
2210 { "rx_bytes", ROCKER_TLV_CMD_PORT_STATS_RX_BYTES
, },
2211 { "rx_dropped", ROCKER_TLV_CMD_PORT_STATS_RX_DROPPED
, },
2212 { "rx_errors", ROCKER_TLV_CMD_PORT_STATS_RX_ERRORS
, },
2214 { "tx_packets", ROCKER_TLV_CMD_PORT_STATS_TX_PKTS
, },
2215 { "tx_bytes", ROCKER_TLV_CMD_PORT_STATS_TX_BYTES
, },
2216 { "tx_dropped", ROCKER_TLV_CMD_PORT_STATS_TX_DROPPED
, },
2217 { "tx_errors", ROCKER_TLV_CMD_PORT_STATS_TX_ERRORS
, },
2220 #define ROCKER_PORT_STATS_LEN ARRAY_SIZE(rocker_port_stats)
2222 static void rocker_port_get_strings(struct net_device
*netdev
, u32 stringset
,
2228 switch (stringset
) {
2230 for (i
= 0; i
< ARRAY_SIZE(rocker_port_stats
); i
++) {
2231 memcpy(p
, rocker_port_stats
[i
].str
, ETH_GSTRING_LEN
);
2232 p
+= ETH_GSTRING_LEN
;
2239 rocker_cmd_get_port_stats_prep(const struct rocker_port
*rocker_port
,
2240 struct rocker_desc_info
*desc_info
,
2243 struct rocker_tlv
*cmd_stats
;
2245 if (rocker_tlv_put_u16(desc_info
, ROCKER_TLV_CMD_TYPE
,
2246 ROCKER_TLV_CMD_TYPE_GET_PORT_STATS
))
2249 cmd_stats
= rocker_tlv_nest_start(desc_info
, ROCKER_TLV_CMD_INFO
);
2253 if (rocker_tlv_put_u32(desc_info
, ROCKER_TLV_CMD_PORT_STATS_PPORT
,
2254 rocker_port
->pport
))
2257 rocker_tlv_nest_end(desc_info
, cmd_stats
);
2263 rocker_cmd_get_port_stats_ethtool_proc(const struct rocker_port
*rocker_port
,
2264 const struct rocker_desc_info
*desc_info
,
2267 const struct rocker_tlv
*attrs
[ROCKER_TLV_CMD_MAX
+ 1];
2268 const struct rocker_tlv
*stats_attrs
[ROCKER_TLV_CMD_PORT_STATS_MAX
+ 1];
2269 const struct rocker_tlv
*pattr
;
2274 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_CMD_MAX
, desc_info
);
2276 if (!attrs
[ROCKER_TLV_CMD_INFO
])
2279 rocker_tlv_parse_nested(stats_attrs
, ROCKER_TLV_CMD_PORT_STATS_MAX
,
2280 attrs
[ROCKER_TLV_CMD_INFO
]);
2282 if (!stats_attrs
[ROCKER_TLV_CMD_PORT_STATS_PPORT
])
2285 pport
= rocker_tlv_get_u32(stats_attrs
[ROCKER_TLV_CMD_PORT_STATS_PPORT
]);
2286 if (pport
!= rocker_port
->pport
)
2289 for (i
= 0; i
< ARRAY_SIZE(rocker_port_stats
); i
++) {
2290 pattr
= stats_attrs
[rocker_port_stats
[i
].type
];
2294 data
[i
] = rocker_tlv_get_u64(pattr
);
2300 static int rocker_cmd_get_port_stats_ethtool(struct rocker_port
*rocker_port
,
2303 return rocker_cmd_exec(rocker_port
, false,
2304 rocker_cmd_get_port_stats_prep
, NULL
,
2305 rocker_cmd_get_port_stats_ethtool_proc
,
2309 static void rocker_port_get_stats(struct net_device
*dev
,
2310 struct ethtool_stats
*stats
, u64
*data
)
2312 struct rocker_port
*rocker_port
= netdev_priv(dev
);
2314 if (rocker_cmd_get_port_stats_ethtool(rocker_port
, data
) != 0) {
2317 for (i
= 0; i
< ARRAY_SIZE(rocker_port_stats
); ++i
)
2322 static int rocker_port_get_sset_count(struct net_device
*netdev
, int sset
)
2326 return ROCKER_PORT_STATS_LEN
;
2332 static const struct ethtool_ops rocker_port_ethtool_ops
= {
2333 .get_settings
= rocker_port_get_settings
,
2334 .set_settings
= rocker_port_set_settings
,
2335 .get_drvinfo
= rocker_port_get_drvinfo
,
2336 .get_link
= ethtool_op_get_link
,
2337 .get_strings
= rocker_port_get_strings
,
2338 .get_ethtool_stats
= rocker_port_get_stats
,
2339 .get_sset_count
= rocker_port_get_sset_count
,
2346 static struct rocker_port
*rocker_port_napi_tx_get(struct napi_struct
*napi
)
2348 return container_of(napi
, struct rocker_port
, napi_tx
);
2351 static int rocker_port_poll_tx(struct napi_struct
*napi
, int budget
)
2353 struct rocker_port
*rocker_port
= rocker_port_napi_tx_get(napi
);
2354 const struct rocker
*rocker
= rocker_port
->rocker
;
2355 const struct rocker_desc_info
*desc_info
;
2359 /* Cleanup tx descriptors */
2360 while ((desc_info
= rocker_desc_tail_get(&rocker_port
->tx_ring
))) {
2361 struct sk_buff
*skb
;
2363 err
= rocker_desc_err(desc_info
);
2364 if (err
&& net_ratelimit())
2365 netdev_err(rocker_port
->dev
, "tx desc received with err %d\n",
2367 rocker_tx_desc_frags_unmap(rocker_port
, desc_info
);
2369 skb
= rocker_desc_cookie_ptr_get(desc_info
);
2371 rocker_port
->dev
->stats
.tx_packets
++;
2372 rocker_port
->dev
->stats
.tx_bytes
+= skb
->len
;
2374 rocker_port
->dev
->stats
.tx_errors
++;
2377 dev_kfree_skb_any(skb
);
2381 if (credits
&& netif_queue_stopped(rocker_port
->dev
))
2382 netif_wake_queue(rocker_port
->dev
);
2384 napi_complete(napi
);
2385 rocker_dma_ring_credits_set(rocker
, &rocker_port
->tx_ring
, credits
);
2390 static int rocker_port_rx_proc(const struct rocker
*rocker
,
2391 const struct rocker_port
*rocker_port
,
2392 struct rocker_desc_info
*desc_info
)
2394 const struct rocker_tlv
*attrs
[ROCKER_TLV_RX_MAX
+ 1];
2395 struct sk_buff
*skb
= rocker_desc_cookie_ptr_get(desc_info
);
2402 rocker_tlv_parse_desc(attrs
, ROCKER_TLV_RX_MAX
, desc_info
);
2403 if (!attrs
[ROCKER_TLV_RX_FRAG_LEN
])
2405 if (attrs
[ROCKER_TLV_RX_FLAGS
])
2406 rx_flags
= rocker_tlv_get_u16(attrs
[ROCKER_TLV_RX_FLAGS
]);
2408 rocker_dma_rx_ring_skb_unmap(rocker
, attrs
);
2410 rx_len
= rocker_tlv_get_u16(attrs
[ROCKER_TLV_RX_FRAG_LEN
]);
2411 skb_put(skb
, rx_len
);
2412 skb
->protocol
= eth_type_trans(skb
, rocker_port
->dev
);
2414 if (rx_flags
& ROCKER_RX_FLAGS_FWD_OFFLOAD
)
2415 skb
->offload_fwd_mark
= rocker_port
->dev
->offload_fwd_mark
;
2417 rocker_port
->dev
->stats
.rx_packets
++;
2418 rocker_port
->dev
->stats
.rx_bytes
+= skb
->len
;
2420 netif_receive_skb(skb
);
2422 return rocker_dma_rx_ring_skb_alloc(rocker_port
, desc_info
);
2425 static struct rocker_port
*rocker_port_napi_rx_get(struct napi_struct
*napi
)
2427 return container_of(napi
, struct rocker_port
, napi_rx
);
2430 static int rocker_port_poll_rx(struct napi_struct
*napi
, int budget
)
2432 struct rocker_port
*rocker_port
= rocker_port_napi_rx_get(napi
);
2433 const struct rocker
*rocker
= rocker_port
->rocker
;
2434 struct rocker_desc_info
*desc_info
;
2438 /* Process rx descriptors */
2439 while (credits
< budget
&&
2440 (desc_info
= rocker_desc_tail_get(&rocker_port
->rx_ring
))) {
2441 err
= rocker_desc_err(desc_info
);
2443 if (net_ratelimit())
2444 netdev_err(rocker_port
->dev
, "rx desc received with err %d\n",
2447 err
= rocker_port_rx_proc(rocker
, rocker_port
,
2449 if (err
&& net_ratelimit())
2450 netdev_err(rocker_port
->dev
, "rx processing failed with err %d\n",
2454 rocker_port
->dev
->stats
.rx_errors
++;
2456 rocker_desc_gen_clear(desc_info
);
2457 rocker_desc_head_set(rocker
, &rocker_port
->rx_ring
, desc_info
);
2461 if (credits
< budget
)
2462 napi_complete(napi
);
2464 rocker_dma_ring_credits_set(rocker
, &rocker_port
->rx_ring
, credits
);
2473 static void rocker_carrier_init(const struct rocker_port
*rocker_port
)
2475 const struct rocker
*rocker
= rocker_port
->rocker
;
2476 u64 link_status
= rocker_read64(rocker
, PORT_PHYS_LINK_STATUS
);
2479 link_up
= link_status
& (1 << rocker_port
->pport
);
2481 netif_carrier_on(rocker_port
->dev
);
2483 netif_carrier_off(rocker_port
->dev
);
2486 static void rocker_remove_ports(struct rocker
*rocker
)
2488 struct rocker_port
*rocker_port
;
2491 for (i
= 0; i
< rocker
->port_count
; i
++) {
2492 rocker_port
= rocker
->ports
[i
];
2495 rocker_world_port_fini(rocker_port
);
2496 unregister_netdev(rocker_port
->dev
);
2497 rocker_world_port_post_fini(rocker_port
);
2498 free_netdev(rocker_port
->dev
);
2500 rocker_world_fini(rocker
);
2501 kfree(rocker
->ports
);
2504 static void rocker_port_dev_addr_init(struct rocker_port
*rocker_port
)
2506 const struct rocker
*rocker
= rocker_port
->rocker
;
2507 const struct pci_dev
*pdev
= rocker
->pdev
;
2510 err
= rocker_cmd_get_port_settings_macaddr(rocker_port
,
2511 rocker_port
->dev
->dev_addr
);
2513 dev_warn(&pdev
->dev
, "failed to get mac address, using random\n");
2514 eth_hw_addr_random(rocker_port
->dev
);
2518 static int rocker_probe_port(struct rocker
*rocker
, unsigned int port_number
)
2520 const struct pci_dev
*pdev
= rocker
->pdev
;
2521 struct rocker_port
*rocker_port
;
2522 struct net_device
*dev
;
2525 dev
= alloc_etherdev(sizeof(struct rocker_port
));
2528 rocker_port
= netdev_priv(dev
);
2529 rocker_port
->dev
= dev
;
2530 rocker_port
->rocker
= rocker
;
2531 rocker_port
->port_number
= port_number
;
2532 rocker_port
->pport
= port_number
+ 1;
2534 err
= rocker_world_check_init(rocker_port
);
2536 dev_err(&pdev
->dev
, "world init failed\n");
2537 goto err_world_check_init
;
2540 rocker_port_dev_addr_init(rocker_port
);
2541 dev
->netdev_ops
= &rocker_port_netdev_ops
;
2542 dev
->ethtool_ops
= &rocker_port_ethtool_ops
;
2543 dev
->switchdev_ops
= &rocker_port_switchdev_ops
;
2544 netif_tx_napi_add(dev
, &rocker_port
->napi_tx
, rocker_port_poll_tx
,
2546 netif_napi_add(dev
, &rocker_port
->napi_rx
, rocker_port_poll_rx
,
2548 rocker_carrier_init(rocker_port
);
2550 dev
->features
|= NETIF_F_NETNS_LOCAL
| NETIF_F_SG
;
2552 err
= rocker_world_port_pre_init(rocker_port
);
2554 dev_err(&pdev
->dev
, "port world pre-init failed\n");
2555 goto err_world_port_pre_init
;
2557 err
= register_netdev(dev
);
2559 dev_err(&pdev
->dev
, "register_netdev failed\n");
2560 goto err_register_netdev
;
2562 rocker
->ports
[port_number
] = rocker_port
;
2564 err
= rocker_world_port_init(rocker_port
);
2566 dev_err(&pdev
->dev
, "port world init failed\n");
2567 goto err_world_port_init
;
2572 err_world_port_init
:
2573 rocker
->ports
[port_number
] = NULL
;
2574 unregister_netdev(dev
);
2575 err_register_netdev
:
2576 rocker_world_port_post_fini(rocker_port
);
2577 err_world_port_pre_init
:
2578 err_world_check_init
:
2583 static int rocker_probe_ports(struct rocker
*rocker
)
2589 alloc_size
= sizeof(struct rocker_port
*) * rocker
->port_count
;
2590 rocker
->ports
= kzalloc(alloc_size
, GFP_KERNEL
);
2593 for (i
= 0; i
< rocker
->port_count
; i
++) {
2594 err
= rocker_probe_port(rocker
, i
);
2601 rocker_remove_ports(rocker
);
2605 static int rocker_msix_init(struct rocker
*rocker
)
2607 struct pci_dev
*pdev
= rocker
->pdev
;
2612 msix_entries
= pci_msix_vec_count(pdev
);
2613 if (msix_entries
< 0)
2614 return msix_entries
;
2616 if (msix_entries
!= ROCKER_MSIX_VEC_COUNT(rocker
->port_count
))
2619 rocker
->msix_entries
= kmalloc_array(msix_entries
,
2620 sizeof(struct msix_entry
),
2622 if (!rocker
->msix_entries
)
2625 for (i
= 0; i
< msix_entries
; i
++)
2626 rocker
->msix_entries
[i
].entry
= i
;
2628 err
= pci_enable_msix_exact(pdev
, rocker
->msix_entries
, msix_entries
);
2630 goto err_enable_msix
;
2635 kfree(rocker
->msix_entries
);
2639 static void rocker_msix_fini(const struct rocker
*rocker
)
2641 pci_disable_msix(rocker
->pdev
);
2642 kfree(rocker
->msix_entries
);
2645 static int rocker_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
2647 struct rocker
*rocker
;
2650 rocker
= kzalloc(sizeof(*rocker
), GFP_KERNEL
);
2654 err
= pci_enable_device(pdev
);
2656 dev_err(&pdev
->dev
, "pci_enable_device failed\n");
2657 goto err_pci_enable_device
;
2660 err
= pci_request_regions(pdev
, rocker_driver_name
);
2662 dev_err(&pdev
->dev
, "pci_request_regions failed\n");
2663 goto err_pci_request_regions
;
2666 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
2668 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64));
2670 dev_err(&pdev
->dev
, "pci_set_consistent_dma_mask failed\n");
2671 goto err_pci_set_dma_mask
;
2674 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
2676 dev_err(&pdev
->dev
, "pci_set_dma_mask failed\n");
2677 goto err_pci_set_dma_mask
;
2681 if (pci_resource_len(pdev
, 0) < ROCKER_PCI_BAR0_SIZE
) {
2682 dev_err(&pdev
->dev
, "invalid PCI region size\n");
2684 goto err_pci_resource_len_check
;
2687 rocker
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
2688 pci_resource_len(pdev
, 0));
2689 if (!rocker
->hw_addr
) {
2690 dev_err(&pdev
->dev
, "ioremap failed\n");
2694 pci_set_master(pdev
);
2696 rocker
->pdev
= pdev
;
2697 pci_set_drvdata(pdev
, rocker
);
2699 rocker
->port_count
= rocker_read32(rocker
, PORT_PHYS_COUNT
);
2701 err
= rocker_msix_init(rocker
);
2703 dev_err(&pdev
->dev
, "MSI-X init failed\n");
2707 err
= rocker_basic_hw_test(rocker
);
2709 dev_err(&pdev
->dev
, "basic hw test failed\n");
2710 goto err_basic_hw_test
;
2713 rocker_write32(rocker
, CONTROL
, ROCKER_CONTROL_RESET
);
2715 err
= rocker_dma_rings_init(rocker
);
2717 goto err_dma_rings_init
;
2719 err
= request_irq(rocker_msix_vector(rocker
, ROCKER_MSIX_VEC_CMD
),
2720 rocker_cmd_irq_handler
, 0,
2721 rocker_driver_name
, rocker
);
2723 dev_err(&pdev
->dev
, "cannot assign cmd irq\n");
2724 goto err_request_cmd_irq
;
2727 err
= request_irq(rocker_msix_vector(rocker
, ROCKER_MSIX_VEC_EVENT
),
2728 rocker_event_irq_handler
, 0,
2729 rocker_driver_name
, rocker
);
2731 dev_err(&pdev
->dev
, "cannot assign event irq\n");
2732 goto err_request_event_irq
;
2735 rocker
->hw
.id
= rocker_read64(rocker
, SWITCH_ID
);
2737 err
= rocker_probe_ports(rocker
);
2739 dev_err(&pdev
->dev
, "failed to probe ports\n");
2740 goto err_probe_ports
;
2743 dev_info(&pdev
->dev
, "Rocker switch with id %*phN\n",
2744 (int)sizeof(rocker
->hw
.id
), &rocker
->hw
.id
);
2749 free_irq(rocker_msix_vector(rocker
, ROCKER_MSIX_VEC_EVENT
), rocker
);
2750 err_request_event_irq
:
2751 free_irq(rocker_msix_vector(rocker
, ROCKER_MSIX_VEC_CMD
), rocker
);
2752 err_request_cmd_irq
:
2753 rocker_dma_rings_fini(rocker
);
2756 rocker_msix_fini(rocker
);
2758 iounmap(rocker
->hw_addr
);
2760 err_pci_resource_len_check
:
2761 err_pci_set_dma_mask
:
2762 pci_release_regions(pdev
);
2763 err_pci_request_regions
:
2764 pci_disable_device(pdev
);
2765 err_pci_enable_device
:
2770 static void rocker_remove(struct pci_dev
*pdev
)
2772 struct rocker
*rocker
= pci_get_drvdata(pdev
);
2774 rocker_write32(rocker
, CONTROL
, ROCKER_CONTROL_RESET
);
2775 rocker_remove_ports(rocker
);
2776 free_irq(rocker_msix_vector(rocker
, ROCKER_MSIX_VEC_EVENT
), rocker
);
2777 free_irq(rocker_msix_vector(rocker
, ROCKER_MSIX_VEC_CMD
), rocker
);
2778 rocker_dma_rings_fini(rocker
);
2779 rocker_msix_fini(rocker
);
2780 iounmap(rocker
->hw_addr
);
2781 pci_release_regions(rocker
->pdev
);
2782 pci_disable_device(rocker
->pdev
);
2786 static struct pci_driver rocker_pci_driver
= {
2787 .name
= rocker_driver_name
,
2788 .id_table
= rocker_pci_id_table
,
2789 .probe
= rocker_probe
,
2790 .remove
= rocker_remove
,
2793 /************************************
2794 * Net device notifier event handler
2795 ************************************/
2797 static bool rocker_port_dev_check(const struct net_device
*dev
)
2799 return dev
->netdev_ops
== &rocker_port_netdev_ops
;
2802 static int rocker_netdevice_event(struct notifier_block
*unused
,
2803 unsigned long event
, void *ptr
)
2805 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
2806 struct netdev_notifier_changeupper_info
*info
;
2807 struct rocker_port
*rocker_port
;
2810 if (!rocker_port_dev_check(dev
))
2814 case NETDEV_CHANGEUPPER
:
2818 rocker_port
= netdev_priv(dev
);
2819 if (info
->linking
) {
2820 err
= rocker_world_port_master_linked(rocker_port
,
2823 netdev_warn(dev
, "failed to reflect master linked (err %d)\n",
2826 err
= rocker_world_port_master_unlinked(rocker_port
,
2829 netdev_warn(dev
, "failed to reflect master unlinked (err %d)\n",
2837 static struct notifier_block rocker_netdevice_nb __read_mostly
= {
2838 .notifier_call
= rocker_netdevice_event
,
2841 /************************************
2842 * Net event notifier event handler
2843 ************************************/
2845 static int rocker_netevent_event(struct notifier_block
*unused
,
2846 unsigned long event
, void *ptr
)
2848 struct rocker_port
*rocker_port
;
2849 struct net_device
*dev
;
2850 struct neighbour
*n
= ptr
;
2854 case NETEVENT_NEIGH_UPDATE
:
2855 if (n
->tbl
!= &arp_tbl
)
2858 if (!rocker_port_dev_check(dev
))
2860 rocker_port
= netdev_priv(dev
);
2861 err
= rocker_world_port_neigh_update(rocker_port
, n
);
2863 netdev_warn(dev
, "failed to handle neigh update (err %d)\n",
2871 static struct notifier_block rocker_netevent_nb __read_mostly
= {
2872 .notifier_call
= rocker_netevent_event
,
2875 /***********************
2876 * Module init and exit
2877 ***********************/
2879 static int __init
rocker_module_init(void)
2883 register_netdevice_notifier(&rocker_netdevice_nb
);
2884 register_netevent_notifier(&rocker_netevent_nb
);
2885 err
= pci_register_driver(&rocker_pci_driver
);
2887 goto err_pci_register_driver
;
2890 err_pci_register_driver
:
2891 unregister_netevent_notifier(&rocker_netevent_nb
);
2892 unregister_netdevice_notifier(&rocker_netdevice_nb
);
2896 static void __exit
rocker_module_exit(void)
2898 unregister_netevent_notifier(&rocker_netevent_nb
);
2899 unregister_netdevice_notifier(&rocker_netdevice_nb
);
2900 pci_unregister_driver(&rocker_pci_driver
);
2903 module_init(rocker_module_init
);
2904 module_exit(rocker_module_exit
);
2906 MODULE_LICENSE("GPL v2");
2907 MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
2908 MODULE_AUTHOR("Scott Feldman <sfeldma@gmail.com>");
2909 MODULE_DESCRIPTION("Rocker switch device driver");
2910 MODULE_DEVICE_TABLE(pci
, rocker_pci_id_table
);