1 // SPDX-License-Identifier: GPL-2.0
2 /* Marvell Octeon EP (EndPoint) Ethernet Driver
4 * Copyright (C) 2020 Marvell.
8 #include <linux/types.h>
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/netdevice.h>
12 #include <linux/etherdevice.h>
13 #include <linux/rtnetlink.h>
14 #include <linux/vmalloc.h>
16 #include "octep_config.h"
17 #include "octep_main.h"
18 #include "octep_ctrl_net.h"
19 #include "octep_pfvf_mbox.h"
21 #define OCTEP_INTR_POLL_TIME_MSECS 100
22 struct workqueue_struct *octep_wq;
24 /* Supported Devices */
25 static const struct pci_device_id octep_pci_id_tbl[] = {
26 {PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, OCTEP_PCI_DEVICE_ID_CN98_PF)},
27 {PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, OCTEP_PCI_DEVICE_ID_CN93_PF)},
28 {PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, OCTEP_PCI_DEVICE_ID_CNF95N_PF)},
29 {PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, OCTEP_PCI_DEVICE_ID_CN10KA_PF)},
30 {PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, OCTEP_PCI_DEVICE_ID_CNF10KA_PF)},
31 {PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, OCTEP_PCI_DEVICE_ID_CNF10KB_PF)},
32 {PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, OCTEP_PCI_DEVICE_ID_CN10KB_PF)},
35 MODULE_DEVICE_TABLE(pci, octep_pci_id_tbl);
37 MODULE_AUTHOR("Veerasenareddy Burru <vburru@marvell.com>");
38 MODULE_DESCRIPTION(OCTEP_DRV_STRING);
39 MODULE_LICENSE("GPL");
42 * octep_alloc_ioq_vectors() - Allocate Tx/Rx Queue interrupt info.
44 * @oct: Octeon device private data structure.
46 * Allocate resources to hold per Tx/Rx queue interrupt info.
47 * This is the information passed to interrupt handler, from which napi poll
48 * is scheduled and includes quick access to private data of Tx/Rx queue
49 * corresponding to the interrupt being handled.
51 * Return: 0, on successful allocation of resources for all queue interrupts.
52 * -1, if failed to allocate any resource.
54 static int octep_alloc_ioq_vectors(struct octep_device *oct)
57 struct octep_ioq_vector *ioq_vector;
59 for (i = 0; i < oct->num_oqs; i++) {
60 oct->ioq_vector[i] = vzalloc(sizeof(*oct->ioq_vector[i]));
61 if (!oct->ioq_vector[i])
64 ioq_vector = oct->ioq_vector[i];
65 ioq_vector->iq = oct->iq[i];
66 ioq_vector->oq = oct->oq[i];
67 ioq_vector->octep_dev = oct;
70 dev_info(&oct->pdev->dev, "Allocated %d IOQ vectors\n", oct->num_oqs);
76 vfree(oct->ioq_vector[i]);
77 oct->ioq_vector[i] = NULL;
83 * octep_free_ioq_vectors() - Free Tx/Rx Queue interrupt vector info.
85 * @oct: Octeon device private data structure.
87 static void octep_free_ioq_vectors(struct octep_device *oct)
91 for (i = 0; i < oct->num_oqs; i++) {
92 if (oct->ioq_vector[i]) {
93 vfree(oct->ioq_vector[i]);
94 oct->ioq_vector[i] = NULL;
97 netdev_info(oct->netdev, "Freed IOQ Vectors\n");
101 * octep_enable_msix_range() - enable MSI-x interrupts.
103 * @oct: Octeon device private data structure.
105 * Allocate and enable all MSI-x interrupts (queue and non-queue interrupts)
106 * for the Octeon device.
108 * Return: 0, on successfully enabling all MSI-x interrupts.
109 * -1, if failed to enable any MSI-x interrupt.
111 static int octep_enable_msix_range(struct octep_device *oct)
113 int num_msix, msix_allocated;
116 /* Generic interrupts apart from input/output queues */
117 num_msix = oct->num_oqs + CFG_GET_NON_IOQ_MSIX(oct->conf);
118 oct->msix_entries = kcalloc(num_msix,
119 sizeof(struct msix_entry), GFP_KERNEL);
120 if (!oct->msix_entries)
123 for (i = 0; i < num_msix; i++)
124 oct->msix_entries[i].entry = i;
126 msix_allocated = pci_enable_msix_range(oct->pdev, oct->msix_entries,
128 if (msix_allocated != num_msix) {
129 dev_err(&oct->pdev->dev,
130 "Failed to enable %d msix irqs; got only %d\n",
131 num_msix, msix_allocated);
132 goto enable_msix_err;
134 oct->num_irqs = msix_allocated;
135 dev_info(&oct->pdev->dev, "MSI-X enabled successfully\n");
140 if (msix_allocated > 0)
141 pci_disable_msix(oct->pdev);
142 kfree(oct->msix_entries);
143 oct->msix_entries = NULL;
149 * octep_disable_msix() - disable MSI-x interrupts.
151 * @oct: Octeon device private data structure.
153 * Disable MSI-x on the Octeon device.
155 static void octep_disable_msix(struct octep_device *oct)
157 pci_disable_msix(oct->pdev);
158 kfree(oct->msix_entries);
159 oct->msix_entries = NULL;
160 dev_info(&oct->pdev->dev, "Disabled MSI-X\n");
164 * octep_mbox_intr_handler() - common handler for pfvf mbox interrupts.
166 * @irq: Interrupt number.
167 * @data: interrupt data.
169 * this is common handler for pfvf mbox interrupts.
171 static irqreturn_t octep_mbox_intr_handler(int irq, void *data)
173 struct octep_device *oct = data;
175 return oct->hw_ops.mbox_intr_handler(oct);
179 * octep_oei_intr_handler() - common handler for output endpoint interrupts.
181 * @irq: Interrupt number.
182 * @data: interrupt data.
184 * this is common handler for all output endpoint interrupts.
186 static irqreturn_t octep_oei_intr_handler(int irq, void *data)
188 struct octep_device *oct = data;
190 return oct->hw_ops.oei_intr_handler(oct);
194 * octep_ire_intr_handler() - common handler for input ring error interrupts.
196 * @irq: Interrupt number.
197 * @data: interrupt data.
199 * this is common handler for input ring error interrupts.
201 static irqreturn_t octep_ire_intr_handler(int irq, void *data)
203 struct octep_device *oct = data;
205 return oct->hw_ops.ire_intr_handler(oct);
209 * octep_ore_intr_handler() - common handler for output ring error interrupts.
211 * @irq: Interrupt number.
212 * @data: interrupt data.
214 * this is common handler for output ring error interrupts.
216 static irqreturn_t octep_ore_intr_handler(int irq, void *data)
218 struct octep_device *oct = data;
220 return oct->hw_ops.ore_intr_handler(oct);
224 * octep_vfire_intr_handler() - common handler for vf input ring error interrupts.
226 * @irq: Interrupt number.
227 * @data: interrupt data.
229 * this is common handler for vf input ring error interrupts.
231 static irqreturn_t octep_vfire_intr_handler(int irq, void *data)
233 struct octep_device *oct = data;
235 return oct->hw_ops.vfire_intr_handler(oct);
239 * octep_vfore_intr_handler() - common handler for vf output ring error interrupts.
241 * @irq: Interrupt number.
242 * @data: interrupt data.
244 * this is common handler for vf output ring error interrupts.
246 static irqreturn_t octep_vfore_intr_handler(int irq, void *data)
248 struct octep_device *oct = data;
250 return oct->hw_ops.vfore_intr_handler(oct);
254 * octep_dma_intr_handler() - common handler for dpi dma related interrupts.
256 * @irq: Interrupt number.
257 * @data: interrupt data.
259 * this is common handler for dpi dma related interrupts.
261 static irqreturn_t octep_dma_intr_handler(int irq, void *data)
263 struct octep_device *oct = data;
265 return oct->hw_ops.dma_intr_handler(oct);
269 * octep_dma_vf_intr_handler() - common handler for dpi dma transaction error interrupts for VFs.
271 * @irq: Interrupt number.
272 * @data: interrupt data.
274 * this is common handler for dpi dma transaction error interrupts for VFs.
276 static irqreturn_t octep_dma_vf_intr_handler(int irq, void *data)
278 struct octep_device *oct = data;
280 return oct->hw_ops.dma_vf_intr_handler(oct);
284 * octep_pp_vf_intr_handler() - common handler for pp transaction error interrupts for VFs.
286 * @irq: Interrupt number.
287 * @data: interrupt data.
289 * this is common handler for pp transaction error interrupts for VFs.
291 static irqreturn_t octep_pp_vf_intr_handler(int irq, void *data)
293 struct octep_device *oct = data;
295 return oct->hw_ops.pp_vf_intr_handler(oct);
299 * octep_misc_intr_handler() - common handler for mac related interrupts.
301 * @irq: Interrupt number.
302 * @data: interrupt data.
304 * this is common handler for mac related interrupts.
306 static irqreturn_t octep_misc_intr_handler(int irq, void *data)
308 struct octep_device *oct = data;
310 return oct->hw_ops.misc_intr_handler(oct);
314 * octep_rsvd_intr_handler() - common handler for reserved interrupts (future use).
316 * @irq: Interrupt number.
317 * @data: interrupt data.
319 * this is common handler for all reserved interrupts.
321 static irqreturn_t octep_rsvd_intr_handler(int irq, void *data)
323 struct octep_device *oct = data;
325 return oct->hw_ops.rsvd_intr_handler(oct);
329 * octep_ioq_intr_handler() - handler for all Tx/Rx queue interrupts.
331 * @irq: Interrupt number.
332 * @data: interrupt data contains pointers to Tx/Rx queue private data
333 * and correspong NAPI context.
335 * this is common handler for all non-queue (generic) interrupts.
337 static irqreturn_t octep_ioq_intr_handler(int irq, void *data)
339 struct octep_ioq_vector *ioq_vector = data;
340 struct octep_device *oct = ioq_vector->octep_dev;
342 return oct->hw_ops.ioq_intr_handler(ioq_vector);
346 * octep_request_irqs() - Register interrupt handlers.
348 * @oct: Octeon device private data structure.
350 * Register handlers for all queue and non-queue interrupts.
352 * Return: 0, on successful registration of all interrupt handlers.
355 static int octep_request_irqs(struct octep_device *oct)
357 struct net_device *netdev = oct->netdev;
358 struct octep_ioq_vector *ioq_vector;
359 struct msix_entry *msix_entry;
360 char **non_ioq_msix_names;
361 int num_non_ioq_msix;
364 num_non_ioq_msix = CFG_GET_NON_IOQ_MSIX(oct->conf);
365 non_ioq_msix_names = CFG_GET_NON_IOQ_MSIX_NAMES(oct->conf);
367 oct->non_ioq_irq_names = kcalloc(num_non_ioq_msix,
368 OCTEP_MSIX_NAME_SIZE, GFP_KERNEL);
369 if (!oct->non_ioq_irq_names)
372 /* First few MSI-X interrupts are non-queue interrupts */
373 for (i = 0; i < num_non_ioq_msix; i++) {
376 irq_name = &oct->non_ioq_irq_names[i * OCTEP_MSIX_NAME_SIZE];
377 msix_entry = &oct->msix_entries[i];
379 snprintf(irq_name, OCTEP_MSIX_NAME_SIZE,
380 "%s-%s", netdev->name, non_ioq_msix_names[i]);
381 if (!strncmp(non_ioq_msix_names[i], "epf_mbox_rint", strlen("epf_mbox_rint"))) {
382 ret = request_irq(msix_entry->vector,
383 octep_mbox_intr_handler, 0,
385 } else if (!strncmp(non_ioq_msix_names[i], "epf_oei_rint",
386 strlen("epf_oei_rint"))) {
387 ret = request_irq(msix_entry->vector,
388 octep_oei_intr_handler, 0,
390 } else if (!strncmp(non_ioq_msix_names[i], "epf_ire_rint",
391 strlen("epf_ire_rint"))) {
392 ret = request_irq(msix_entry->vector,
393 octep_ire_intr_handler, 0,
395 } else if (!strncmp(non_ioq_msix_names[i], "epf_ore_rint",
396 strlen("epf_ore_rint"))) {
397 ret = request_irq(msix_entry->vector,
398 octep_ore_intr_handler, 0,
400 } else if (!strncmp(non_ioq_msix_names[i], "epf_vfire_rint",
401 strlen("epf_vfire_rint"))) {
402 ret = request_irq(msix_entry->vector,
403 octep_vfire_intr_handler, 0,
405 } else if (!strncmp(non_ioq_msix_names[i], "epf_vfore_rint",
406 strlen("epf_vfore_rint"))) {
407 ret = request_irq(msix_entry->vector,
408 octep_vfore_intr_handler, 0,
410 } else if (!strncmp(non_ioq_msix_names[i], "epf_dma_rint",
411 strlen("epf_dma_rint"))) {
412 ret = request_irq(msix_entry->vector,
413 octep_dma_intr_handler, 0,
415 } else if (!strncmp(non_ioq_msix_names[i], "epf_dma_vf_rint",
416 strlen("epf_dma_vf_rint"))) {
417 ret = request_irq(msix_entry->vector,
418 octep_dma_vf_intr_handler, 0,
420 } else if (!strncmp(non_ioq_msix_names[i], "epf_pp_vf_rint",
421 strlen("epf_pp_vf_rint"))) {
422 ret = request_irq(msix_entry->vector,
423 octep_pp_vf_intr_handler, 0,
425 } else if (!strncmp(non_ioq_msix_names[i], "epf_misc_rint",
426 strlen("epf_misc_rint"))) {
427 ret = request_irq(msix_entry->vector,
428 octep_misc_intr_handler, 0,
431 ret = request_irq(msix_entry->vector,
432 octep_rsvd_intr_handler, 0,
438 "request_irq failed for %s; err=%d",
440 goto non_ioq_irq_err;
444 /* Request IRQs for Tx/Rx queues */
445 for (j = 0; j < oct->num_oqs; j++) {
446 ioq_vector = oct->ioq_vector[j];
447 msix_entry = &oct->msix_entries[j + num_non_ioq_msix];
449 snprintf(ioq_vector->name, sizeof(ioq_vector->name),
450 "%s-q%d", netdev->name, j);
451 ret = request_irq(msix_entry->vector,
452 octep_ioq_intr_handler, 0,
453 ioq_vector->name, ioq_vector);
456 "request_irq failed for Q-%d; err=%d",
461 cpumask_set_cpu(j % num_online_cpus(),
462 &ioq_vector->affinity_mask);
463 irq_set_affinity_hint(msix_entry->vector,
464 &ioq_vector->affinity_mask);
471 ioq_vector = oct->ioq_vector[j];
472 msix_entry = &oct->msix_entries[j + num_non_ioq_msix];
474 irq_set_affinity_hint(msix_entry->vector, NULL);
475 free_irq(msix_entry->vector, ioq_vector);
480 free_irq(oct->msix_entries[i].vector, oct);
482 kfree(oct->non_ioq_irq_names);
483 oct->non_ioq_irq_names = NULL;
489 * octep_free_irqs() - free all registered interrupts.
491 * @oct: Octeon device private data structure.
493 * Free all queue and non-queue interrupts of the Octeon device.
495 static void octep_free_irqs(struct octep_device *oct)
499 /* First few MSI-X interrupts are non queue interrupts; free them */
500 for (i = 0; i < CFG_GET_NON_IOQ_MSIX(oct->conf); i++)
501 free_irq(oct->msix_entries[i].vector, oct);
502 kfree(oct->non_ioq_irq_names);
504 /* Free IRQs for Input/Output (Tx/Rx) queues */
505 for (i = CFG_GET_NON_IOQ_MSIX(oct->conf); i < oct->num_irqs; i++) {
506 irq_set_affinity_hint(oct->msix_entries[i].vector, NULL);
507 free_irq(oct->msix_entries[i].vector,
508 oct->ioq_vector[i - CFG_GET_NON_IOQ_MSIX(oct->conf)]);
510 netdev_info(oct->netdev, "IRQs freed\n");
514 * octep_setup_irqs() - setup interrupts for the Octeon device.
516 * @oct: Octeon device private data structure.
518 * Allocate data structures to hold per interrupt information, allocate/enable
519 * MSI-x interrupt and register interrupt handlers.
521 * Return: 0, on successful allocation and registration of all interrupts.
524 static int octep_setup_irqs(struct octep_device *oct)
526 if (octep_alloc_ioq_vectors(oct))
529 if (octep_enable_msix_range(oct))
530 goto enable_msix_err;
532 if (octep_request_irqs(oct))
533 goto request_irq_err;
538 octep_disable_msix(oct);
540 octep_free_ioq_vectors(oct);
546 * octep_clean_irqs() - free all interrupts and its resources.
548 * @oct: Octeon device private data structure.
550 static void octep_clean_irqs(struct octep_device *oct)
552 octep_free_irqs(oct);
553 octep_disable_msix(oct);
554 octep_free_ioq_vectors(oct);
558 * octep_enable_ioq_irq() - Enable MSI-x interrupt of a Tx/Rx queue.
560 * @iq: Octeon Tx queue data structure.
561 * @oq: Octeon Rx queue data structure.
563 static void octep_enable_ioq_irq(struct octep_iq *iq, struct octep_oq *oq)
565 u32 pkts_pend = oq->pkts_pending;
567 netdev_dbg(iq->netdev, "enabling intr for Q-%u\n", iq->q_no);
568 if (iq->pkts_processed) {
569 writel(iq->pkts_processed, iq->inst_cnt_reg);
570 iq->pkt_in_done -= iq->pkts_processed;
571 iq->pkts_processed = 0;
573 if (oq->last_pkt_count - pkts_pend) {
574 writel(oq->last_pkt_count - pkts_pend, oq->pkts_sent_reg);
575 oq->last_pkt_count = pkts_pend;
578 /* Flush the previous wrties before writing to RESEND bit */
580 writeq(1UL << OCTEP_OQ_INTR_RESEND_BIT, oq->pkts_sent_reg);
581 writeq(1UL << OCTEP_IQ_INTR_RESEND_BIT, iq->inst_cnt_reg);
585 * octep_napi_poll() - NAPI poll function for Tx/Rx.
587 * @napi: pointer to napi context.
588 * @budget: max number of packets to be processed in single invocation.
590 static int octep_napi_poll(struct napi_struct *napi, int budget)
592 struct octep_ioq_vector *ioq_vector =
593 container_of(napi, struct octep_ioq_vector, napi);
594 u32 tx_pending, rx_done;
596 tx_pending = octep_iq_process_completions(ioq_vector->iq, budget);
597 rx_done = octep_oq_process_rx(ioq_vector->oq, budget);
599 /* need more polling if tx completion processing is still pending or
600 * processed at least 'budget' number of rx packets.
602 if (tx_pending || rx_done >= budget)
606 octep_enable_ioq_irq(ioq_vector->iq, ioq_vector->oq);
611 * octep_napi_add() - Add NAPI poll for all Tx/Rx queues.
613 * @oct: Octeon device private data structure.
615 static void octep_napi_add(struct octep_device *oct)
619 for (i = 0; i < oct->num_oqs; i++) {
620 netdev_dbg(oct->netdev, "Adding NAPI on Q-%d\n", i);
621 netif_napi_add(oct->netdev, &oct->ioq_vector[i]->napi,
623 oct->oq[i]->napi = &oct->ioq_vector[i]->napi;
628 * octep_napi_delete() - delete NAPI poll callback for all Tx/Rx queues.
630 * @oct: Octeon device private data structure.
632 static void octep_napi_delete(struct octep_device *oct)
636 for (i = 0; i < oct->num_oqs; i++) {
637 netdev_dbg(oct->netdev, "Deleting NAPI on Q-%d\n", i);
638 netif_napi_del(&oct->ioq_vector[i]->napi);
639 oct->oq[i]->napi = NULL;
644 * octep_napi_enable() - enable NAPI for all Tx/Rx queues.
646 * @oct: Octeon device private data structure.
648 static void octep_napi_enable(struct octep_device *oct)
652 for (i = 0; i < oct->num_oqs; i++) {
653 netdev_dbg(oct->netdev, "Enabling NAPI on Q-%d\n", i);
654 napi_enable(&oct->ioq_vector[i]->napi);
659 * octep_napi_disable() - disable NAPI for all Tx/Rx queues.
661 * @oct: Octeon device private data structure.
663 static void octep_napi_disable(struct octep_device *oct)
667 for (i = 0; i < oct->num_oqs; i++) {
668 netdev_dbg(oct->netdev, "Disabling NAPI on Q-%d\n", i);
669 napi_disable(&oct->ioq_vector[i]->napi);
673 static void octep_link_up(struct net_device *netdev)
675 netif_carrier_on(netdev);
676 netif_tx_start_all_queues(netdev);
680 * octep_open() - start the octeon network device.
682 * @netdev: pointer to kernel network device.
684 * setup Tx/Rx queues, interrupts and enable hardware operation of Tx/Rx queues
687 * Return: 0, on successfully setting up device and bring it up.
690 static int octep_open(struct net_device *netdev)
692 struct octep_device *oct = netdev_priv(netdev);
695 netdev_info(netdev, "Starting netdev ...\n");
696 netif_carrier_off(netdev);
698 oct->hw_ops.reset_io_queues(oct);
700 if (octep_setup_iqs(oct))
702 if (octep_setup_oqs(oct))
704 if (octep_setup_irqs(oct))
707 err = netif_set_real_num_tx_queues(netdev, oct->num_oqs);
710 err = netif_set_real_num_rx_queues(netdev, oct->num_iqs);
715 octep_napi_enable(oct);
717 oct->link_info.admin_up = 1;
718 octep_ctrl_net_set_rx_state(oct, OCTEP_CTRL_NET_INVALID_VFID, true,
720 octep_ctrl_net_set_link_status(oct, OCTEP_CTRL_NET_INVALID_VFID, true,
722 oct->poll_non_ioq_intr = false;
724 /* Enable the input and output queues for this Octeon device */
725 oct->hw_ops.enable_io_queues(oct);
727 /* Enable Octeon device interrupts */
728 oct->hw_ops.enable_interrupts(oct);
730 octep_oq_dbell_init(oct);
732 ret = octep_ctrl_net_get_link_status(oct, OCTEP_CTRL_NET_INVALID_VFID);
734 octep_link_up(netdev);
739 octep_clean_irqs(oct);
749 * octep_stop() - stop the octeon network device.
751 * @netdev: pointer to kernel network device.
753 * stop the device Tx/Rx operations, bring down the link and
754 * free up all resources allocated for Tx/Rx queues and interrupts.
756 static int octep_stop(struct net_device *netdev)
758 struct octep_device *oct = netdev_priv(netdev);
760 netdev_info(netdev, "Stopping the device ...\n");
762 octep_ctrl_net_set_link_status(oct, OCTEP_CTRL_NET_INVALID_VFID, false,
764 octep_ctrl_net_set_rx_state(oct, OCTEP_CTRL_NET_INVALID_VFID, false,
767 /* Stop Tx from stack */
768 netif_tx_stop_all_queues(netdev);
769 netif_carrier_off(netdev);
770 netif_tx_disable(netdev);
772 oct->link_info.admin_up = 0;
773 oct->link_info.oper_up = 0;
775 oct->hw_ops.disable_interrupts(oct);
776 octep_napi_disable(oct);
777 octep_napi_delete(oct);
779 octep_clean_irqs(oct);
780 octep_clean_iqs(oct);
782 oct->hw_ops.disable_io_queues(oct);
783 oct->hw_ops.reset_io_queues(oct);
787 oct->poll_non_ioq_intr = true;
788 queue_delayed_work(octep_wq, &oct->intr_poll_task,
789 msecs_to_jiffies(OCTEP_INTR_POLL_TIME_MSECS));
791 netdev_info(netdev, "Device stopped !!\n");
796 * octep_iq_full_check() - check if a Tx queue is full.
798 * @iq: Octeon Tx queue data structure.
800 * Return: 0, if the Tx queue is not full.
801 * 1, if the Tx queue is full.
803 static inline int octep_iq_full_check(struct octep_iq *iq)
805 if (likely((IQ_INSTR_SPACE(iq)) >
806 OCTEP_WAKE_QUEUE_THRESHOLD))
809 /* Stop the queue if unable to send */
810 netif_stop_subqueue(iq->netdev, iq->q_no);
812 /* Allow for pending updates in write index
813 * from iq_process_completion in other cpus
814 * to reflect, in case queue gets free
819 /* check again and restart the queue, in case NAPI has just freed
820 * enough Tx ring entries.
822 if (unlikely(IQ_INSTR_SPACE(iq) >
823 OCTEP_WAKE_QUEUE_THRESHOLD)) {
824 netif_start_subqueue(iq->netdev, iq->q_no);
825 iq->stats.restart_cnt++;
833 * octep_start_xmit() - Enqueue packet to Octoen hardware Tx Queue.
835 * @skb: packet skbuff pointer.
836 * @netdev: kernel network device.
838 * Return: NETDEV_TX_BUSY, if Tx Queue is full.
839 * NETDEV_TX_OK, if successfully enqueued to hardware Tx queue.
841 static netdev_tx_t octep_start_xmit(struct sk_buff *skb,
842 struct net_device *netdev)
844 struct octep_device *oct = netdev_priv(netdev);
845 netdev_features_t feat = netdev->features;
846 struct octep_tx_sglist_desc *sglist;
847 struct octep_tx_buffer *tx_buffer;
848 struct octep_tx_desc_hw *hw_desc;
849 struct skb_shared_info *shinfo;
850 struct octep_instr_hdr *ih;
857 if (skb_put_padto(skb, ETH_ZLEN))
860 q_no = skb_get_queue_mapping(skb);
861 if (q_no >= oct->num_iqs) {
862 netdev_err(netdev, "Invalid Tx skb->queue_mapping=%d\n", q_no);
863 q_no = q_no % oct->num_iqs;
868 shinfo = skb_shinfo(skb);
869 nr_frags = shinfo->nr_frags;
871 wi = iq->host_write_index;
872 hw_desc = &iq->desc_ring[wi];
875 tx_buffer = iq->buff_info + wi;
876 tx_buffer->skb = skb;
879 ih->pkind = oct->conf->fw_info.pkind;
880 ih->fsz = oct->conf->fw_info.fsz;
881 ih->tlen = skb->len + ih->fsz;
884 tx_buffer->gather = 0;
885 tx_buffer->dma = dma_map_single(iq->dev, skb->data,
886 skb->len, DMA_TO_DEVICE);
887 if (dma_mapping_error(iq->dev, tx_buffer->dma))
889 hw_desc->dptr = tx_buffer->dma;
895 sglist = tx_buffer->sglist;
897 ih->gsz = nr_frags + 1;
899 tx_buffer->gather = 1;
901 len = skb_headlen(skb);
902 dma = dma_map_single(iq->dev, skb->data, len, DMA_TO_DEVICE);
903 if (dma_mapping_error(iq->dev, dma))
906 memset(sglist, 0, OCTEP_SGLIST_SIZE_PER_PKT);
907 sglist[0].len[3] = len;
908 sglist[0].dma_ptr[0] = dma;
910 si = 1; /* entry 0 is main skb, mapped above */
911 frag = &shinfo->frags[0];
913 len = skb_frag_size(frag);
914 dma = skb_frag_dma_map(iq->dev, frag, 0,
916 if (dma_mapping_error(iq->dev, dma))
919 sglist[si >> 2].len[3 - (si & 3)] = len;
920 sglist[si >> 2].dma_ptr[si & 3] = dma;
925 hw_desc->dptr = tx_buffer->sglist_dma;
928 if (oct->conf->fw_info.tx_ol_flags) {
929 if ((feat & (NETIF_F_TSO)) && (skb_is_gso(skb))) {
930 hw_desc->txm.ol_flags = OCTEP_TX_OFFLOAD_CKSUM;
931 hw_desc->txm.ol_flags |= OCTEP_TX_OFFLOAD_TSO;
932 hw_desc->txm.gso_size = skb_shinfo(skb)->gso_size;
933 hw_desc->txm.gso_segs = skb_shinfo(skb)->gso_segs;
934 } else if (feat & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) {
935 hw_desc->txm.ol_flags = OCTEP_TX_OFFLOAD_CKSUM;
937 /* due to ESR txm will be swapped by hw */
938 hw_desc->txm64[0] = (__force u64)cpu_to_be64(hw_desc->txm64[0]);
941 xmit_more = netdev_xmit_more();
943 __netdev_tx_sent_queue(iq->netdev_q, skb->len, xmit_more);
945 skb_tx_timestamp(skb);
948 iq->host_write_index = wi & iq->ring_size_mask;
950 /* octep_iq_full_check stops the queue and returns
951 * true if so, in case the queue has become full
952 * by inserting current packet. If so, we can
953 * go ahead and ring doorbell.
955 if (!octep_iq_full_check(iq) && xmit_more &&
956 iq->fill_cnt < iq->fill_threshold)
959 /* Flush the hw descriptor before writing to doorbell */
961 /* Ring Doorbell to notify the NIC of new packets */
962 writel(iq->fill_cnt, iq->doorbell_reg);
963 iq->stats.instr_posted += iq->fill_cnt;
969 dma_unmap_single(iq->dev, sglist[0].dma_ptr[0],
970 sglist[0].len[3], DMA_TO_DEVICE);
971 sglist[0].len[3] = 0;
974 dma_unmap_page(iq->dev, sglist[si >> 2].dma_ptr[si & 3],
975 sglist[si >> 2].len[3 - (si & 3)], DMA_TO_DEVICE);
976 sglist[si >> 2].len[3 - (si & 3)] = 0;
979 tx_buffer->gather = 0;
981 dev_kfree_skb_any(skb);
986 * octep_get_stats64() - Get Octeon network device statistics.
988 * @netdev: kernel network device.
989 * @stats: pointer to stats structure to be filled in.
991 static void octep_get_stats64(struct net_device *netdev,
992 struct rtnl_link_stats64 *stats)
994 u64 tx_packets, tx_bytes, rx_packets, rx_bytes;
995 struct octep_device *oct = netdev_priv(netdev);
998 if (netif_running(netdev))
999 octep_ctrl_net_get_if_stats(oct,
1000 OCTEP_CTRL_NET_INVALID_VFID,
1001 &oct->iface_rx_stats,
1002 &oct->iface_tx_stats);
1008 for (q = 0; q < oct->num_oqs; q++) {
1009 struct octep_iq *iq = oct->iq[q];
1010 struct octep_oq *oq = oct->oq[q];
1012 tx_packets += iq->stats.instr_completed;
1013 tx_bytes += iq->stats.bytes_sent;
1014 rx_packets += oq->stats.packets;
1015 rx_bytes += oq->stats.bytes;
1017 stats->tx_packets = tx_packets;
1018 stats->tx_bytes = tx_bytes;
1019 stats->rx_packets = rx_packets;
1020 stats->rx_bytes = rx_bytes;
1021 stats->multicast = oct->iface_rx_stats.mcast_pkts;
1022 stats->rx_errors = oct->iface_rx_stats.err_pkts;
1023 stats->collisions = oct->iface_tx_stats.xscol;
1024 stats->tx_fifo_errors = oct->iface_tx_stats.undflw;
1028 * octep_tx_timeout_task - work queue task to Handle Tx queue timeout.
1030 * @work: pointer to Tx queue timeout work_struct
1032 * Stop and start the device so that it frees up all queue resources
1033 * and restarts the queues, that potentially clears a Tx queue timeout
1036 static void octep_tx_timeout_task(struct work_struct *work)
1038 struct octep_device *oct = container_of(work, struct octep_device,
1040 struct net_device *netdev = oct->netdev;
1043 if (netif_running(netdev)) {
1051 * octep_tx_timeout() - Handle Tx Queue timeout.
1053 * @netdev: pointer to kernel network device.
1054 * @txqueue: Timed out Tx queue number.
1056 * Schedule a work to handle Tx queue timeout.
1058 static void octep_tx_timeout(struct net_device *netdev, unsigned int txqueue)
1060 struct octep_device *oct = netdev_priv(netdev);
1062 queue_work(octep_wq, &oct->tx_timeout_task);
1065 static int octep_set_mac(struct net_device *netdev, void *p)
1067 struct octep_device *oct = netdev_priv(netdev);
1068 struct sockaddr *addr = (struct sockaddr *)p;
1071 if (!is_valid_ether_addr(addr->sa_data))
1072 return -EADDRNOTAVAIL;
1074 err = octep_ctrl_net_set_mac_addr(oct, OCTEP_CTRL_NET_INVALID_VFID,
1075 addr->sa_data, true);
1079 memcpy(oct->mac_addr, addr->sa_data, ETH_ALEN);
1080 eth_hw_addr_set(netdev, addr->sa_data);
1085 static int octep_change_mtu(struct net_device *netdev, int new_mtu)
1087 struct octep_device *oct = netdev_priv(netdev);
1088 struct octep_iface_link_info *link_info;
1091 link_info = &oct->link_info;
1092 if (link_info->mtu == new_mtu)
1095 err = octep_ctrl_net_set_mtu(oct, OCTEP_CTRL_NET_INVALID_VFID, new_mtu,
1098 oct->link_info.mtu = new_mtu;
1099 netdev->mtu = new_mtu;
1105 static int octep_set_features(struct net_device *dev, netdev_features_t features)
1107 struct octep_ctrl_net_offloads offloads = { 0 };
1108 struct octep_device *oct = netdev_priv(dev);
1111 /* We only support features received from firmware */
1112 if ((features & dev->hw_features) != features)
1115 if (features & NETIF_F_TSO)
1116 offloads.tx_offloads |= OCTEP_TX_OFFLOAD_TSO;
1118 if (features & NETIF_F_TSO6)
1119 offloads.tx_offloads |= OCTEP_TX_OFFLOAD_TSO;
1121 if (features & NETIF_F_IP_CSUM)
1122 offloads.tx_offloads |= OCTEP_TX_OFFLOAD_CKSUM;
1124 if (features & NETIF_F_IPV6_CSUM)
1125 offloads.tx_offloads |= OCTEP_TX_OFFLOAD_CKSUM;
1127 if (features & NETIF_F_RXCSUM)
1128 offloads.rx_offloads |= OCTEP_RX_OFFLOAD_CKSUM;
1130 err = octep_ctrl_net_set_offloads(oct,
1131 OCTEP_CTRL_NET_INVALID_VFID,
1135 dev->features = features;
1140 static const struct net_device_ops octep_netdev_ops = {
1141 .ndo_open = octep_open,
1142 .ndo_stop = octep_stop,
1143 .ndo_start_xmit = octep_start_xmit,
1144 .ndo_get_stats64 = octep_get_stats64,
1145 .ndo_tx_timeout = octep_tx_timeout,
1146 .ndo_set_mac_address = octep_set_mac,
1147 .ndo_change_mtu = octep_change_mtu,
1148 .ndo_set_features = octep_set_features,
1152 * octep_intr_poll_task - work queue task to process non-ioq interrupts.
1154 * @work: pointer to mbox work_struct
1156 * Process non-ioq interrupts to handle control mailbox, pfvf mailbox.
1158 static void octep_intr_poll_task(struct work_struct *work)
1160 struct octep_device *oct = container_of(work, struct octep_device,
1161 intr_poll_task.work);
1163 if (!oct->poll_non_ioq_intr) {
1164 dev_info(&oct->pdev->dev, "Interrupt poll task stopped.\n");
1168 oct->hw_ops.poll_non_ioq_interrupts(oct);
1169 queue_delayed_work(octep_wq, &oct->intr_poll_task,
1170 msecs_to_jiffies(OCTEP_INTR_POLL_TIME_MSECS));
1174 * octep_hb_timeout_task - work queue task to check firmware heartbeat.
1176 * @work: pointer to hb work_struct
1178 * Check for heartbeat miss count. Uninitialize oct device if miss count
1179 * exceeds configured max heartbeat miss count.
1182 static void octep_hb_timeout_task(struct work_struct *work)
1184 struct octep_device *oct = container_of(work, struct octep_device,
1189 miss_cnt = atomic_inc_return(&oct->hb_miss_cnt);
1190 if (miss_cnt < oct->conf->fw_info.hb_miss_count) {
1191 queue_delayed_work(octep_wq, &oct->hb_task,
1192 msecs_to_jiffies(oct->conf->fw_info.hb_interval));
1196 dev_err(&oct->pdev->dev, "Missed %u heartbeats. Uninitializing\n",
1199 if (netif_running(oct->netdev))
1200 octep_stop(oct->netdev);
1205 * octep_ctrl_mbox_task - work queue task to handle ctrl mbox messages.
1207 * @work: pointer to ctrl mbox work_struct
1209 * Poll ctrl mbox message queue and handle control messages from firmware.
1211 static void octep_ctrl_mbox_task(struct work_struct *work)
1213 struct octep_device *oct = container_of(work, struct octep_device,
1216 octep_ctrl_net_recv_fw_messages(oct);
1219 static const char *octep_devid_to_str(struct octep_device *oct)
1221 switch (oct->chip_id) {
1222 case OCTEP_PCI_DEVICE_ID_CN98_PF:
1224 case OCTEP_PCI_DEVICE_ID_CN93_PF:
1226 case OCTEP_PCI_DEVICE_ID_CNF95N_PF:
1228 case OCTEP_PCI_DEVICE_ID_CN10KA_PF:
1230 case OCTEP_PCI_DEVICE_ID_CNF10KA_PF:
1232 case OCTEP_PCI_DEVICE_ID_CNF10KB_PF:
1234 case OCTEP_PCI_DEVICE_ID_CN10KB_PF:
1237 return "Unsupported";
1242 * octep_device_setup() - Setup Octeon Device.
1244 * @oct: Octeon device private data structure.
1246 * Setup Octeon device hardware operations, configuration, etc ...
1248 int octep_device_setup(struct octep_device *oct)
1250 struct pci_dev *pdev = oct->pdev;
1253 /* allocate memory for oct->conf */
1254 oct->conf = kzalloc(sizeof(*oct->conf), GFP_KERNEL);
1258 /* Map BAR regions */
1259 for (i = 0; i < OCTEP_MMIO_REGIONS; i++) {
1260 oct->mmio[i].hw_addr =
1261 ioremap(pci_resource_start(oct->pdev, i * 2),
1262 pci_resource_len(oct->pdev, i * 2));
1263 if (!oct->mmio[i].hw_addr)
1266 oct->mmio[i].mapped = 1;
1269 oct->chip_id = pdev->device;
1270 oct->rev_id = pdev->revision;
1271 dev_info(&pdev->dev, "chip_id = 0x%x\n", pdev->device);
1273 switch (oct->chip_id) {
1274 case OCTEP_PCI_DEVICE_ID_CN98_PF:
1275 case OCTEP_PCI_DEVICE_ID_CN93_PF:
1276 case OCTEP_PCI_DEVICE_ID_CNF95N_PF:
1277 dev_info(&pdev->dev, "Setting up OCTEON %s PF PASS%d.%d\n",
1278 octep_devid_to_str(oct), OCTEP_MAJOR_REV(oct),
1279 OCTEP_MINOR_REV(oct));
1280 octep_device_setup_cn93_pf(oct);
1282 case OCTEP_PCI_DEVICE_ID_CNF10KA_PF:
1283 case OCTEP_PCI_DEVICE_ID_CN10KA_PF:
1284 case OCTEP_PCI_DEVICE_ID_CNF10KB_PF:
1285 case OCTEP_PCI_DEVICE_ID_CN10KB_PF:
1286 dev_info(&pdev->dev, "Setting up OCTEON %s PF PASS%d.%d\n",
1287 octep_devid_to_str(oct), OCTEP_MAJOR_REV(oct), OCTEP_MINOR_REV(oct));
1288 octep_device_setup_cnxk_pf(oct);
1292 "%s: unsupported device\n", __func__);
1293 goto unsupported_dev;
1297 ret = octep_ctrl_net_init(oct);
1301 INIT_WORK(&oct->tx_timeout_task, octep_tx_timeout_task);
1302 INIT_WORK(&oct->ctrl_mbox_task, octep_ctrl_mbox_task);
1303 INIT_DELAYED_WORK(&oct->intr_poll_task, octep_intr_poll_task);
1304 oct->poll_non_ioq_intr = true;
1305 queue_delayed_work(octep_wq, &oct->intr_poll_task,
1306 msecs_to_jiffies(OCTEP_INTR_POLL_TIME_MSECS));
1308 atomic_set(&oct->hb_miss_cnt, 0);
1309 INIT_DELAYED_WORK(&oct->hb_task, octep_hb_timeout_task);
1314 i = OCTEP_MMIO_REGIONS;
1317 iounmap(oct->mmio[i].hw_addr);
1324 * octep_device_cleanup() - Cleanup Octeon Device.
1326 * @oct: Octeon device private data structure.
1328 * Cleanup Octeon device allocated resources.
1330 static void octep_device_cleanup(struct octep_device *oct)
1334 oct->poll_non_ioq_intr = false;
1335 cancel_delayed_work_sync(&oct->intr_poll_task);
1336 cancel_work_sync(&oct->ctrl_mbox_task);
1338 dev_info(&oct->pdev->dev, "Cleaning up Octeon Device ...\n");
1340 for (i = 0; i < OCTEP_MAX_VF; i++) {
1341 vfree(oct->mbox[i]);
1342 oct->mbox[i] = NULL;
1345 octep_delete_pfvf_mbox(oct);
1346 octep_ctrl_net_uninit(oct);
1347 cancel_delayed_work_sync(&oct->hb_task);
1349 oct->hw_ops.soft_reset(oct);
1350 for (i = 0; i < OCTEP_MMIO_REGIONS; i++) {
1351 if (oct->mmio[i].mapped)
1352 iounmap(oct->mmio[i].hw_addr);
1359 static bool get_fw_ready_status(struct pci_dev *pdev)
1365 while ((pos = pci_find_next_ext_capability(pdev, pos,
1366 PCI_EXT_CAP_ID_VNDR))) {
1367 pci_read_config_word(pdev, pos + 4, &vsec_id);
1368 #define FW_STATUS_VSEC_ID 0xA3
1369 if (vsec_id != FW_STATUS_VSEC_ID)
1372 pci_read_config_byte(pdev, (pos + 8), &status);
1373 dev_info(&pdev->dev, "Firmware ready status = %u\n", status);
1374 #define FW_STATUS_READY 1ULL
1375 return status == FW_STATUS_READY;
1381 * octep_probe() - Octeon PCI device probe handler.
1383 * @pdev: PCI device structure.
1384 * @ent: entry in Octeon PCI device ID table.
1386 * Initializes and enables the Octeon PCI device for network operations.
1387 * Initializes Octeon private data structure and registers a network device.
1389 static int octep_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1391 struct octep_device *octep_dev = NULL;
1392 struct net_device *netdev;
1396 err = pci_enable_device(pdev);
1398 dev_err(&pdev->dev, "Failed to enable PCI device\n");
1402 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
1404 dev_err(&pdev->dev, "Failed to set DMA mask !!\n");
1408 err = pci_request_mem_regions(pdev, OCTEP_DRV_NAME);
1410 dev_err(&pdev->dev, "Failed to map PCI memory regions\n");
1411 goto err_pci_regions;
1414 pci_set_master(pdev);
1416 if (!get_fw_ready_status(pdev)) {
1417 dev_notice(&pdev->dev, "Firmware not ready; defer probe.\n");
1418 err = -EPROBE_DEFER;
1419 goto err_alloc_netdev;
1422 netdev = alloc_etherdev_mq(sizeof(struct octep_device),
1425 dev_err(&pdev->dev, "Failed to allocate netdev\n");
1427 goto err_alloc_netdev;
1429 SET_NETDEV_DEV(netdev, &pdev->dev);
1431 octep_dev = netdev_priv(netdev);
1432 octep_dev->netdev = netdev;
1433 octep_dev->pdev = pdev;
1434 octep_dev->dev = &pdev->dev;
1435 pci_set_drvdata(pdev, octep_dev);
1437 err = octep_device_setup(octep_dev);
1439 dev_err(&pdev->dev, "Device setup failed\n");
1440 goto err_octep_config;
1443 err = octep_setup_pfvf_mbox(octep_dev);
1445 dev_err(&pdev->dev, "PF-VF mailbox setup failed\n");
1446 goto register_dev_err;
1449 err = octep_ctrl_net_get_info(octep_dev, OCTEP_CTRL_NET_INVALID_VFID,
1450 &octep_dev->conf->fw_info);
1452 dev_err(&pdev->dev, "Failed to get firmware info\n");
1453 goto register_dev_err;
1455 dev_info(&octep_dev->pdev->dev, "Heartbeat interval %u msecs Heartbeat miss count %u\n",
1456 octep_dev->conf->fw_info.hb_interval,
1457 octep_dev->conf->fw_info.hb_miss_count);
1458 queue_delayed_work(octep_wq, &octep_dev->hb_task,
1459 msecs_to_jiffies(octep_dev->conf->fw_info.hb_interval));
1461 netdev->netdev_ops = &octep_netdev_ops;
1462 octep_set_ethtool_ops(netdev);
1463 netif_carrier_off(netdev);
1465 netdev->hw_features = NETIF_F_SG;
1466 if (OCTEP_TX_IP_CSUM(octep_dev->conf->fw_info.tx_ol_flags))
1467 netdev->hw_features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
1469 if (OCTEP_RX_IP_CSUM(octep_dev->conf->fw_info.rx_ol_flags))
1470 netdev->hw_features |= NETIF_F_RXCSUM;
1472 max_rx_pktlen = octep_ctrl_net_get_mtu(octep_dev, OCTEP_CTRL_NET_INVALID_VFID);
1473 if (max_rx_pktlen < 0) {
1474 dev_err(&octep_dev->pdev->dev,
1475 "Failed to get max receive packet size; err = %d\n", max_rx_pktlen);
1476 err = max_rx_pktlen;
1477 goto register_dev_err;
1479 netdev->min_mtu = OCTEP_MIN_MTU;
1480 netdev->max_mtu = max_rx_pktlen - (ETH_HLEN + ETH_FCS_LEN);
1481 netdev->mtu = OCTEP_DEFAULT_MTU;
1483 if (OCTEP_TX_TSO(octep_dev->conf->fw_info.tx_ol_flags)) {
1484 netdev->hw_features |= NETIF_F_TSO;
1485 netif_set_tso_max_size(netdev, netdev->max_mtu);
1488 netdev->features |= netdev->hw_features;
1489 err = octep_ctrl_net_get_mac_addr(octep_dev, OCTEP_CTRL_NET_INVALID_VFID,
1490 octep_dev->mac_addr);
1492 dev_err(&pdev->dev, "Failed to get mac address\n");
1493 goto register_dev_err;
1495 eth_hw_addr_set(netdev, octep_dev->mac_addr);
1497 err = register_netdev(netdev);
1499 dev_err(&pdev->dev, "Failed to register netdev\n");
1500 goto register_dev_err;
1502 dev_info(&pdev->dev, "Device probe successful\n");
1506 octep_device_cleanup(octep_dev);
1508 free_netdev(netdev);
1510 pci_release_mem_regions(pdev);
1513 pci_disable_device(pdev);
1517 static int octep_sriov_disable(struct octep_device *oct)
1519 struct pci_dev *pdev = oct->pdev;
1521 if (pci_vfs_assigned(oct->pdev)) {
1522 dev_warn(&pdev->dev, "Can't disable SRIOV while VFs are assigned\n");
1526 pci_disable_sriov(pdev);
1527 CFG_GET_ACTIVE_VFS(oct->conf) = 0;
1533 * octep_remove() - Remove Octeon PCI device from driver control.
1535 * @pdev: PCI device structure of the Octeon device.
1537 * Cleanup all resources allocated for the Octeon device.
1538 * Unregister from network device and disable the PCI device.
1540 static void octep_remove(struct pci_dev *pdev)
1542 struct octep_device *oct = pci_get_drvdata(pdev);
1543 struct net_device *netdev;
1548 netdev = oct->netdev;
1549 octep_sriov_disable(oct);
1550 if (netdev->reg_state == NETREG_REGISTERED)
1551 unregister_netdev(netdev);
1553 cancel_work_sync(&oct->tx_timeout_task);
1554 octep_device_cleanup(oct);
1555 pci_release_mem_regions(pdev);
1556 free_netdev(netdev);
1557 pci_disable_device(pdev);
1560 static int octep_sriov_enable(struct octep_device *oct, int num_vfs)
1562 struct pci_dev *pdev = oct->pdev;
1565 CFG_GET_ACTIVE_VFS(oct->conf) = num_vfs;
1566 err = pci_enable_sriov(pdev, num_vfs);
1568 dev_warn(&pdev->dev, "Failed to enable SRIOV err=%d\n", err);
1569 CFG_GET_ACTIVE_VFS(oct->conf) = 0;
1576 static int octep_sriov_configure(struct pci_dev *pdev, int num_vfs)
1578 struct octep_device *oct = pci_get_drvdata(pdev);
1582 return octep_sriov_disable(oct);
1584 max_nvfs = CFG_GET_MAX_VFS(oct->conf);
1586 if (num_vfs > max_nvfs) {
1587 dev_err(&pdev->dev, "Invalid VF count Max supported VFs = %d\n",
1592 return octep_sriov_enable(oct, num_vfs);
1595 static struct pci_driver octep_driver = {
1596 .name = OCTEP_DRV_NAME,
1597 .id_table = octep_pci_id_tbl,
1598 .probe = octep_probe,
1599 .remove = octep_remove,
1600 .sriov_configure = octep_sriov_configure,
1604 * octep_init_module() - Module initialiation.
1606 * create common resource for the driver and register PCI driver.
1608 static int __init octep_init_module(void)
1612 pr_info("%s: Loading %s ...\n", OCTEP_DRV_NAME, OCTEP_DRV_STRING);
1614 /* work queue for all deferred tasks */
1615 octep_wq = create_singlethread_workqueue(OCTEP_DRV_NAME);
1617 pr_err("%s: Failed to create common workqueue\n",
1622 ret = pci_register_driver(&octep_driver);
1624 pr_err("%s: Failed to register PCI driver; err=%d\n",
1625 OCTEP_DRV_NAME, ret);
1626 destroy_workqueue(octep_wq);
1630 pr_info("%s: Loaded successfully !\n", OCTEP_DRV_NAME);
1636 * octep_exit_module() - Module exit routine.
1638 * unregister the driver with PCI subsystem and cleanup common resources.
1640 static void __exit octep_exit_module(void)
1642 pr_info("%s: Unloading ...\n", OCTEP_DRV_NAME);
1644 pci_unregister_driver(&octep_driver);
1645 destroy_workqueue(octep_wq);
1647 pr_info("%s: Unloading complete\n", OCTEP_DRV_NAME);
1650 module_init(octep_init_module);
1651 module_exit(octep_exit_module);