blob: 4440086aaef184cb2b1ded18abd8eb275fe80c55 [file] [log] [blame]
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001/**********************************************************************
2* Author: Cavium, Inc.
3*
4* Contact: support@cavium.com
5* Please include "LiquidIO" in the subject.
6*
7* Copyright (c) 2003-2015 Cavium, Inc.
8*
9* This file is free software; you can redistribute it and/or modify
10* it under the terms of the GNU General Public License, Version 2, as
11* published by the Free Software Foundation.
12*
13* This file is distributed in the hope that it will be useful, but
14* AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16* NONINFRINGEMENT. See the GNU General Public License for more
17* details.
18*
19* This file may also be available under a different license from Cavium.
20* Contact Cavium, Inc. for more information
21**********************************************************************/
22#include <linux/version.h>
23#include <linux/module.h>
24#include <linux/crc32.h>
25#include <linux/dma-mapping.h>
26#include <linux/pci.h>
27#include <linux/pci_ids.h>
28#include <linux/ip.h>
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -070029#include <net/ip.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070030#include <linux/ipv6.h>
31#include <linux/net_tstamp.h>
32#include <linux/if_vlan.h>
33#include <linux/firmware.h>
34#include <linux/ethtool.h>
35#include <linux/ptp_clock_kernel.h>
36#include <linux/types.h>
37#include <linux/list.h>
38#include <linux/workqueue.h>
39#include <linux/interrupt.h>
40#include "octeon_config.h"
41#include "liquidio_common.h"
42#include "octeon_droq.h"
43#include "octeon_iq.h"
44#include "response_manager.h"
45#include "octeon_device.h"
46#include "octeon_nic.h"
47#include "octeon_main.h"
48#include "octeon_network.h"
49#include "cn66xx_regs.h"
50#include "cn66xx_device.h"
51#include "cn68xx_regs.h"
52#include "cn68xx_device.h"
53#include "liquidio_image.h"
54
55MODULE_AUTHOR("Cavium Networks, <support@cavium.com>");
56MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Driver");
57MODULE_LICENSE("GPL");
58MODULE_VERSION(LIQUIDIO_VERSION);
59MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210SV_NAME LIO_FW_NAME_SUFFIX);
60MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210NV_NAME LIO_FW_NAME_SUFFIX);
61MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_410NV_NAME LIO_FW_NAME_SUFFIX);
62
63static int ddr_timeout = 10000;
64module_param(ddr_timeout, int, 0644);
65MODULE_PARM_DESC(ddr_timeout,
66 "Number of milliseconds to wait for DDR initialization. 0 waits for ddr_timeout to be set to non-zero value before starting to check");
67
68static u32 console_bitmask;
69module_param(console_bitmask, int, 0644);
70MODULE_PARM_DESC(console_bitmask,
71 "Bitmask indicating which consoles have debug output redirected to syslog.");
72
73#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
74
75static int debug = -1;
76module_param(debug, int, 0644);
77MODULE_PARM_DESC(debug, "NETIF_MSG debug bits");
78
79static char fw_type[LIO_MAX_FW_TYPE_LEN];
80module_param_string(fw_type, fw_type, sizeof(fw_type), 0000);
81MODULE_PARM_DESC(fw_type, "Type of firmware to be loaded. Default \"nic\"");
82
83static int conf_type;
84module_param(conf_type, int, 0);
85MODULE_PARM_DESC(conf_type, "select octeon configuration 0 default 1 ovs");
86
Raghu Vatsavayia5b37882016-06-14 16:54:48 -070087static int ptp_enable = 1;
88
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070089/* Bit mask values for lio->ifstate */
90#define LIO_IFSTATE_DROQ_OPS 0x01
91#define LIO_IFSTATE_REGISTERED 0x02
92#define LIO_IFSTATE_RUNNING 0x04
93#define LIO_IFSTATE_RX_TIMESTAMP_ENABLED 0x08
94
95/* Polling interval for determining when NIC application is alive */
96#define LIQUIDIO_STARTER_POLL_INTERVAL_MS 100
97
98/* runtime link query interval */
99#define LIQUIDIO_LINK_QUERY_INTERVAL_MS 1000
100
101struct liquidio_if_cfg_context {
102 int octeon_id;
103
104 wait_queue_head_t wc;
105
106 int cond;
107};
108
109struct liquidio_if_cfg_resp {
110 u64 rh;
111 struct liquidio_if_cfg_info cfg_info;
112 u64 status;
113};
114
115struct oct_link_status_resp {
116 u64 rh;
117 struct oct_link_info link_info;
118 u64 status;
119};
120
121struct oct_timestamp_resp {
122 u64 rh;
123 u64 timestamp;
124 u64 status;
125};
126
127#define OCT_TIMESTAMP_RESP_SIZE (sizeof(struct oct_timestamp_resp))
128
129union tx_info {
130 u64 u64;
131 struct {
132#ifdef __BIG_ENDIAN_BITFIELD
133 u16 gso_size;
134 u16 gso_segs;
135 u32 reserved;
136#else
137 u32 reserved;
138 u16 gso_segs;
139 u16 gso_size;
140#endif
141 } s;
142};
143
144/** Octeon device properties to be used by the NIC module.
145 * Each octeon device in the system will be represented
146 * by this structure in the NIC module.
147 */
148
149#define OCTNIC_MAX_SG (MAX_SKB_FRAGS)
150
151#define OCTNIC_GSO_MAX_HEADER_SIZE 128
152#define OCTNIC_GSO_MAX_SIZE (GSO_MAX_SIZE - OCTNIC_GSO_MAX_HEADER_SIZE)
153
154/** Structure of a node in list of gather components maintained by
155 * NIC driver for each network device.
156 */
157struct octnic_gather {
158 /** List manipulation. Next and prev pointers. */
159 struct list_head list;
160
161 /** Size of the gather component at sg in bytes. */
162 int sg_size;
163
164 /** Number of bytes that sg was adjusted to make it 8B-aligned. */
165 int adjust;
166
167 /** Gather component that can accommodate max sized fragment list
168 * received from the IP layer.
169 */
170 struct octeon_sg_entry *sg;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700171
172 u64 sg_dma_ptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700173};
174
175/** This structure is used by NIC driver to store information required
176 * to free the sk_buff when the packet has been fetched by Octeon.
177 * Bytes offset below assume worst-case of a 64-bit system.
178 */
179struct octnet_buf_free_info {
180 /** Bytes 1-8. Pointer to network device private structure. */
181 struct lio *lio;
182
183 /** Bytes 9-16. Pointer to sk_buff. */
184 struct sk_buff *skb;
185
186 /** Bytes 17-24. Pointer to gather list. */
187 struct octnic_gather *g;
188
189 /** Bytes 25-32. Physical address of skb->data or gather list. */
190 u64 dptr;
191
192 /** Bytes 33-47. Piggybacked soft command, if any */
193 struct octeon_soft_command *sc;
194};
195
196struct handshake {
197 struct completion init;
198 struct completion started;
199 struct pci_dev *pci_dev;
200 int init_ok;
201 int started_ok;
202};
203
204struct octeon_device_priv {
205 /** Tasklet structures for this device. */
206 struct tasklet_struct droq_tasklet;
207 unsigned long napi_mask;
208};
209
210static int octeon_device_init(struct octeon_device *);
211static void liquidio_remove(struct pci_dev *pdev);
212static int liquidio_probe(struct pci_dev *pdev,
213 const struct pci_device_id *ent);
214
215static struct handshake handshake[MAX_OCTEON_DEVICES];
216static struct completion first_stage;
217
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700218static void octeon_droq_bh(unsigned long pdev)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700219{
220 int q_no;
221 int reschedule = 0;
222 struct octeon_device *oct = (struct octeon_device *)pdev;
223 struct octeon_device_priv *oct_priv =
224 (struct octeon_device_priv *)oct->priv;
225
226 /* for (q_no = 0; q_no < oct->num_oqs; q_no++) { */
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700227 for (q_no = 0; q_no < MAX_OCTEON_OUTPUT_QUEUES(oct); q_no++) {
228 if (!(oct->io_qmask.oq & (1ULL << q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700229 continue;
230 reschedule |= octeon_droq_process_packets(oct, oct->droq[q_no],
231 MAX_PACKET_BUDGET);
232 }
233
234 if (reschedule)
235 tasklet_schedule(&oct_priv->droq_tasklet);
236}
237
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700238static int lio_wait_for_oq_pkts(struct octeon_device *oct)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700239{
240 struct octeon_device_priv *oct_priv =
241 (struct octeon_device_priv *)oct->priv;
242 int retry = 100, pkt_cnt = 0, pending_pkts = 0;
243 int i;
244
245 do {
246 pending_pkts = 0;
247
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700248 for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
249 if (!(oct->io_qmask.oq & (1ULL << i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700250 continue;
251 pkt_cnt += octeon_droq_check_hw_for_pkts(oct,
252 oct->droq[i]);
253 }
254 if (pkt_cnt > 0) {
255 pending_pkts += pkt_cnt;
256 tasklet_schedule(&oct_priv->droq_tasklet);
257 }
258 pkt_cnt = 0;
259 schedule_timeout_uninterruptible(1);
260
261 } while (retry-- && pending_pkts);
262
263 return pkt_cnt;
264}
265
266void octeon_report_tx_completion_to_bql(void *txq, unsigned int pkts_compl,
267 unsigned int bytes_compl)
268{
269 struct netdev_queue *netdev_queue = txq;
270
271 netdev_tx_completed_queue(netdev_queue, pkts_compl, bytes_compl);
272}
273
274void octeon_update_tx_completion_counters(void *buf, int reqtype,
275 unsigned int *pkts_compl,
276 unsigned int *bytes_compl)
277{
278 struct octnet_buf_free_info *finfo;
279 struct sk_buff *skb = NULL;
280 struct octeon_soft_command *sc;
281
282 switch (reqtype) {
283 case REQTYPE_NORESP_NET:
284 case REQTYPE_NORESP_NET_SG:
285 finfo = buf;
286 skb = finfo->skb;
287 break;
288
289 case REQTYPE_RESP_NET_SG:
290 case REQTYPE_RESP_NET:
291 sc = buf;
292 skb = sc->callback_arg;
293 break;
294
295 default:
296 return;
297 }
298
299 (*pkts_compl)++;
300 *bytes_compl += skb->len;
301}
302
303void octeon_report_sent_bytes_to_bql(void *buf, int reqtype)
304{
305 struct octnet_buf_free_info *finfo;
306 struct sk_buff *skb;
307 struct octeon_soft_command *sc;
308 struct netdev_queue *txq;
309
310 switch (reqtype) {
311 case REQTYPE_NORESP_NET:
312 case REQTYPE_NORESP_NET_SG:
313 finfo = buf;
314 skb = finfo->skb;
315 break;
316
317 case REQTYPE_RESP_NET_SG:
318 case REQTYPE_RESP_NET:
319 sc = buf;
320 skb = sc->callback_arg;
321 break;
322
323 default:
324 return;
325 }
326
327 txq = netdev_get_tx_queue(skb->dev, skb_get_queue_mapping(skb));
328 netdev_tx_sent_queue(txq, skb->len);
329}
330
331int octeon_console_debug_enabled(u32 console)
332{
333 return (console_bitmask >> (console)) & 0x1;
334}
335
336/**
337 * \brief Forces all IO queues off on a given device
338 * @param oct Pointer to Octeon device
339 */
340static void force_io_queues_off(struct octeon_device *oct)
341{
342 if ((oct->chip_id == OCTEON_CN66XX) ||
343 (oct->chip_id == OCTEON_CN68XX)) {
344 /* Reset the Enable bits for Input Queues. */
345 octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
346
347 /* Reset the Enable bits for Output Queues. */
348 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
349 }
350}
351
352/**
353 * \brief wait for all pending requests to complete
354 * @param oct Pointer to Octeon device
355 *
356 * Called during shutdown sequence
357 */
358static int wait_for_pending_requests(struct octeon_device *oct)
359{
360 int i, pcount = 0;
361
362 for (i = 0; i < 100; i++) {
363 pcount =
364 atomic_read(&oct->response_list
365 [OCTEON_ORDERED_SC_LIST].pending_req_count);
366 if (pcount)
367 schedule_timeout_uninterruptible(HZ / 10);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -0700368 else
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700369 break;
370 }
371
372 if (pcount)
373 return 1;
374
375 return 0;
376}
377
378/**
379 * \brief Cause device to go quiet so it can be safely removed/reset/etc
380 * @param oct Pointer to Octeon device
381 */
382static inline void pcierror_quiesce_device(struct octeon_device *oct)
383{
384 int i;
385
386 /* Disable the input and output queues now. No more packets will
387 * arrive from Octeon, but we should wait for all packet processing
388 * to finish.
389 */
390 force_io_queues_off(oct);
391
392 /* To allow for in-flight requests */
393 schedule_timeout_uninterruptible(100);
394
395 if (wait_for_pending_requests(oct))
396 dev_err(&oct->pci_dev->dev, "There were pending requests\n");
397
398 /* Force all requests waiting to be fetched by OCTEON to complete. */
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700399 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700400 struct octeon_instr_queue *iq;
401
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700402 if (!(oct->io_qmask.iq & (1ULL << i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700403 continue;
404 iq = oct->instr_queue[i];
405
406 if (atomic_read(&iq->instr_pending)) {
407 spin_lock_bh(&iq->lock);
408 iq->fill_cnt = 0;
409 iq->octeon_read_index = iq->host_write_index;
410 iq->stats.instr_processed +=
411 atomic_read(&iq->instr_pending);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -0700412 lio_process_iq_request_list(oct, iq, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700413 spin_unlock_bh(&iq->lock);
414 }
415 }
416
417 /* Force all pending ordered list requests to time out. */
418 lio_process_ordered_list(oct, 1);
419
420 /* We do not need to wait for output queue packets to be processed. */
421}
422
423/**
424 * \brief Cleanup PCI AER uncorrectable error status
425 * @param dev Pointer to PCI device
426 */
427static void cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
428{
429 int pos = 0x100;
430 u32 status, mask;
431
432 pr_info("%s :\n", __func__);
433
434 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
435 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
436 if (dev->error_state == pci_channel_io_normal)
437 status &= ~mask; /* Clear corresponding nonfatal bits */
438 else
439 status &= mask; /* Clear corresponding fatal bits */
440 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
441}
442
443/**
444 * \brief Stop all PCI IO to a given device
445 * @param dev Pointer to Octeon device
446 */
447static void stop_pci_io(struct octeon_device *oct)
448{
449 /* No more instructions will be forwarded. */
450 atomic_set(&oct->status, OCT_DEV_IN_RESET);
451
452 pci_disable_device(oct->pci_dev);
453
454 /* Disable interrupts */
455 oct->fn_list.disable_interrupt(oct->chip);
456
457 pcierror_quiesce_device(oct);
458
459 /* Release the interrupt line */
460 free_irq(oct->pci_dev->irq, oct);
461
462 if (oct->flags & LIO_FLAG_MSI_ENABLED)
463 pci_disable_msi(oct->pci_dev);
464
465 dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
466 lio_get_state_string(&oct->status));
467
468 /* cn63xx_cleanup_aer_uncorrect_error_status(oct->pci_dev); */
469 /* making it a common function for all OCTEON models */
470 cleanup_aer_uncorrect_error_status(oct->pci_dev);
471}
472
473/**
474 * \brief called when PCI error is detected
475 * @param pdev Pointer to PCI device
476 * @param state The current pci connection state
477 *
478 * This function is called after a PCI bus error affecting
479 * this device has been detected.
480 */
481static pci_ers_result_t liquidio_pcie_error_detected(struct pci_dev *pdev,
482 pci_channel_state_t state)
483{
484 struct octeon_device *oct = pci_get_drvdata(pdev);
485
486 /* Non-correctable Non-fatal errors */
487 if (state == pci_channel_io_normal) {
488 dev_err(&oct->pci_dev->dev, "Non-correctable non-fatal error reported:\n");
489 cleanup_aer_uncorrect_error_status(oct->pci_dev);
490 return PCI_ERS_RESULT_CAN_RECOVER;
491 }
492
493 /* Non-correctable Fatal errors */
494 dev_err(&oct->pci_dev->dev, "Non-correctable FATAL reported by PCI AER driver\n");
495 stop_pci_io(oct);
496
497 /* Always return a DISCONNECT. There is no support for recovery but only
498 * for a clean shutdown.
499 */
500 return PCI_ERS_RESULT_DISCONNECT;
501}
502
503/**
504 * \brief mmio handler
505 * @param pdev Pointer to PCI device
506 */
507static pci_ers_result_t liquidio_pcie_mmio_enabled(struct pci_dev *pdev)
508{
509 /* We should never hit this since we never ask for a reset for a Fatal
510 * Error. We always return DISCONNECT in io_error above.
511 * But play safe and return RECOVERED for now.
512 */
513 return PCI_ERS_RESULT_RECOVERED;
514}
515
516/**
517 * \brief called after the pci bus has been reset.
518 * @param pdev Pointer to PCI device
519 *
520 * Restart the card from scratch, as if from a cold-boot. Implementation
521 * resembles the first-half of the octeon_resume routine.
522 */
523static pci_ers_result_t liquidio_pcie_slot_reset(struct pci_dev *pdev)
524{
525 /* We should never hit this since we never ask for a reset for a Fatal
526 * Error. We always return DISCONNECT in io_error above.
527 * But play safe and return RECOVERED for now.
528 */
529 return PCI_ERS_RESULT_RECOVERED;
530}
531
532/**
533 * \brief called when traffic can start flowing again.
534 * @param pdev Pointer to PCI device
535 *
536 * This callback is called when the error recovery driver tells us that
537 * its OK to resume normal operation. Implementation resembles the
538 * second-half of the octeon_resume routine.
539 */
540static void liquidio_pcie_resume(struct pci_dev *pdev)
541{
542 /* Nothing to be done here. */
543}
544
545#ifdef CONFIG_PM
546/**
547 * \brief called when suspending
548 * @param pdev Pointer to PCI device
549 * @param state state to suspend to
550 */
551static int liquidio_suspend(struct pci_dev *pdev, pm_message_t state)
552{
553 return 0;
554}
555
556/**
557 * \brief called when resuming
558 * @param pdev Pointer to PCI device
559 */
560static int liquidio_resume(struct pci_dev *pdev)
561{
562 return 0;
563}
564#endif
565
566/* For PCI-E Advanced Error Recovery (AER) Interface */
Julia Lawall166e2362015-11-14 11:06:53 +0100567static const struct pci_error_handlers liquidio_err_handler = {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700568 .error_detected = liquidio_pcie_error_detected,
569 .mmio_enabled = liquidio_pcie_mmio_enabled,
570 .slot_reset = liquidio_pcie_slot_reset,
571 .resume = liquidio_pcie_resume,
572};
573
574static const struct pci_device_id liquidio_pci_tbl[] = {
575 { /* 68xx */
576 PCI_VENDOR_ID_CAVIUM, 0x91, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
577 },
578 { /* 66xx */
579 PCI_VENDOR_ID_CAVIUM, 0x92, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
580 },
581 {
582 0, 0, 0, 0, 0, 0, 0
583 }
584};
585MODULE_DEVICE_TABLE(pci, liquidio_pci_tbl);
586
587static struct pci_driver liquidio_pci_driver = {
588 .name = "LiquidIO",
589 .id_table = liquidio_pci_tbl,
590 .probe = liquidio_probe,
591 .remove = liquidio_remove,
592 .err_handler = &liquidio_err_handler, /* For AER */
593
594#ifdef CONFIG_PM
595 .suspend = liquidio_suspend,
596 .resume = liquidio_resume,
597#endif
598
599};
600
601/**
602 * \brief register PCI driver
603 */
604static int liquidio_init_pci(void)
605{
606 return pci_register_driver(&liquidio_pci_driver);
607}
608
609/**
610 * \brief unregister PCI driver
611 */
612static void liquidio_deinit_pci(void)
613{
614 pci_unregister_driver(&liquidio_pci_driver);
615}
616
617/**
618 * \brief check interface state
619 * @param lio per-network private data
620 * @param state_flag flag state to check
621 */
622static inline int ifstate_check(struct lio *lio, int state_flag)
623{
624 return atomic_read(&lio->ifstate) & state_flag;
625}
626
627/**
628 * \brief set interface state
629 * @param lio per-network private data
630 * @param state_flag flag state to set
631 */
632static inline void ifstate_set(struct lio *lio, int state_flag)
633{
634 atomic_set(&lio->ifstate, (atomic_read(&lio->ifstate) | state_flag));
635}
636
637/**
638 * \brief clear interface state
639 * @param lio per-network private data
640 * @param state_flag flag state to clear
641 */
642static inline void ifstate_reset(struct lio *lio, int state_flag)
643{
644 atomic_set(&lio->ifstate, (atomic_read(&lio->ifstate) & ~(state_flag)));
645}
646
647/**
648 * \brief Stop Tx queues
649 * @param netdev network device
650 */
651static inline void txqs_stop(struct net_device *netdev)
652{
653 if (netif_is_multiqueue(netdev)) {
654 int i;
655
656 for (i = 0; i < netdev->num_tx_queues; i++)
657 netif_stop_subqueue(netdev, i);
658 } else {
659 netif_stop_queue(netdev);
660 }
661}
662
663/**
664 * \brief Start Tx queues
665 * @param netdev network device
666 */
667static inline void txqs_start(struct net_device *netdev)
668{
669 if (netif_is_multiqueue(netdev)) {
670 int i;
671
672 for (i = 0; i < netdev->num_tx_queues; i++)
673 netif_start_subqueue(netdev, i);
674 } else {
675 netif_start_queue(netdev);
676 }
677}
678
679/**
680 * \brief Wake Tx queues
681 * @param netdev network device
682 */
683static inline void txqs_wake(struct net_device *netdev)
684{
685 if (netif_is_multiqueue(netdev)) {
686 int i;
687
688 for (i = 0; i < netdev->num_tx_queues; i++)
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700689 if (__netif_subqueue_stopped(netdev, i))
690 netif_wake_subqueue(netdev, i);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700691 } else {
692 netif_wake_queue(netdev);
693 }
694}
695
696/**
697 * \brief Stop Tx queue
698 * @param netdev network device
699 */
700static void stop_txq(struct net_device *netdev)
701{
702 txqs_stop(netdev);
703}
704
705/**
706 * \brief Start Tx queue
707 * @param netdev network device
708 */
709static void start_txq(struct net_device *netdev)
710{
711 struct lio *lio = GET_LIO(netdev);
712
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700713 if (lio->linfo.link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700714 txqs_start(netdev);
715 return;
716 }
717}
718
719/**
720 * \brief Wake a queue
721 * @param netdev network device
722 * @param q which queue to wake
723 */
724static inline void wake_q(struct net_device *netdev, int q)
725{
726 if (netif_is_multiqueue(netdev))
727 netif_wake_subqueue(netdev, q);
728 else
729 netif_wake_queue(netdev);
730}
731
732/**
733 * \brief Stop a queue
734 * @param netdev network device
735 * @param q which queue to stop
736 */
737static inline void stop_q(struct net_device *netdev, int q)
738{
739 if (netif_is_multiqueue(netdev))
740 netif_stop_subqueue(netdev, q);
741 else
742 netif_stop_queue(netdev);
743}
744
745/**
746 * \brief Check Tx queue status, and take appropriate action
747 * @param lio per-network private data
748 * @returns 0 if full, number of queues woken up otherwise
749 */
750static inline int check_txq_status(struct lio *lio)
751{
752 int ret_val = 0;
753
754 if (netif_is_multiqueue(lio->netdev)) {
755 int numqs = lio->netdev->num_tx_queues;
756 int q, iq = 0;
757
758 /* check each sub-queue state */
759 for (q = 0; q < numqs; q++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700760 iq = lio->linfo.txpciq[q %
761 (lio->linfo.num_txpciq)].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700762 if (octnet_iq_is_full(lio->oct_dev, iq))
763 continue;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700764 if (__netif_subqueue_stopped(lio->netdev, q)) {
765 wake_q(lio->netdev, q);
766 ret_val++;
767 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700768 }
769 } else {
770 if (octnet_iq_is_full(lio->oct_dev, lio->txq))
771 return 0;
772 wake_q(lio->netdev, lio->txq);
773 ret_val = 1;
774 }
775 return ret_val;
776}
777
778/**
779 * Remove the node at the head of the list. The list would be empty at
780 * the end of this call if there are no more nodes in the list.
781 */
782static inline struct list_head *list_delete_head(struct list_head *root)
783{
784 struct list_head *node;
785
786 if ((root->prev == root) && (root->next == root))
787 node = NULL;
788 else
789 node = root->next;
790
791 if (node)
792 list_del(node);
793
794 return node;
795}
796
797/**
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700798 * \brief Delete gather lists
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700799 * @param lio per-network private data
800 */
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700801static void delete_glists(struct lio *lio)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700802{
803 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700804 int i;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700805
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700806 if (!lio->glist)
807 return;
808
809 for (i = 0; i < lio->linfo.num_txpciq; i++) {
810 do {
811 g = (struct octnic_gather *)
812 list_delete_head(&lio->glist[i]);
813 if (g) {
814 if (g->sg) {
815 dma_unmap_single(&lio->oct_dev->
816 pci_dev->dev,
817 g->sg_dma_ptr,
818 g->sg_size,
819 DMA_TO_DEVICE);
820 kfree((void *)((unsigned long)g->sg -
821 g->adjust));
822 }
823 kfree(g);
824 }
825 } while (g);
826 }
827
828 kfree((void *)lio->glist);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700829}
830
831/**
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700832 * \brief Setup gather lists
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700833 * @param lio per-network private data
834 */
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700835static int setup_glists(struct octeon_device *oct, struct lio *lio, int num_iqs)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700836{
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700837 int i, j;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700838 struct octnic_gather *g;
839
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700840 lio->glist_lock = kcalloc(num_iqs, sizeof(*lio->glist_lock),
841 GFP_KERNEL);
842 if (!lio->glist_lock)
843 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700844
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700845 lio->glist = kcalloc(num_iqs, sizeof(*lio->glist),
846 GFP_KERNEL);
847 if (!lio->glist) {
848 kfree((void *)lio->glist_lock);
849 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700850 }
851
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700852 for (i = 0; i < num_iqs; i++) {
853 int numa_node = cpu_to_node(i % num_online_cpus());
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700854
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700855 spin_lock_init(&lio->glist_lock[i]);
856
857 INIT_LIST_HEAD(&lio->glist[i]);
858
859 for (j = 0; j < lio->tx_qsize; j++) {
860 g = kzalloc_node(sizeof(*g), GFP_KERNEL,
861 numa_node);
862 if (!g)
863 g = kzalloc(sizeof(*g), GFP_KERNEL);
864 if (!g)
865 break;
866
867 g->sg_size = ((ROUNDUP4(OCTNIC_MAX_SG) >> 2) *
868 OCT_SG_ENTRY_SIZE);
869
870 g->sg = kmalloc_node(g->sg_size + 8,
871 GFP_KERNEL, numa_node);
872 if (!g->sg)
873 g->sg = kmalloc(g->sg_size + 8, GFP_KERNEL);
874 if (!g->sg) {
875 kfree(g);
876 break;
877 }
878
879 /* The gather component should be aligned on 64-bit
880 * boundary
881 */
882 if (((unsigned long)g->sg) & 7) {
883 g->adjust = 8 - (((unsigned long)g->sg) & 7);
884 g->sg = (struct octeon_sg_entry *)
885 ((unsigned long)g->sg + g->adjust);
886 }
887 g->sg_dma_ptr = dma_map_single(&oct->pci_dev->dev,
888 g->sg, g->sg_size,
889 DMA_TO_DEVICE);
890 if (dma_mapping_error(&oct->pci_dev->dev,
891 g->sg_dma_ptr)) {
892 kfree((void *)((unsigned long)g->sg -
893 g->adjust));
894 kfree(g);
895 break;
896 }
897
898 list_add_tail(&g->list, &lio->glist[i]);
899 }
900
901 if (j != lio->tx_qsize) {
902 delete_glists(lio);
903 return 1;
904 }
905 }
906
907 return 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700908}
909
910/**
911 * \brief Print link information
912 * @param netdev network device
913 */
914static void print_link_info(struct net_device *netdev)
915{
916 struct lio *lio = GET_LIO(netdev);
917
918 if (atomic_read(&lio->ifstate) & LIO_IFSTATE_REGISTERED) {
919 struct oct_link_info *linfo = &lio->linfo;
920
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700921 if (linfo->link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700922 netif_info(lio, link, lio->netdev, "%d Mbps %s Duplex UP\n",
923 linfo->link.s.speed,
924 (linfo->link.s.duplex) ? "Full" : "Half");
925 } else {
926 netif_info(lio, link, lio->netdev, "Link Down\n");
927 }
928 }
929}
930
931/**
932 * \brief Update link status
933 * @param netdev network device
934 * @param ls link status structure
935 *
936 * Called on receipt of a link status response from the core application to
937 * update each interface's link status.
938 */
939static inline void update_link_status(struct net_device *netdev,
940 union oct_link_status *ls)
941{
942 struct lio *lio = GET_LIO(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700943 int changed = (lio->linfo.link.u64 != ls->u64);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700944
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700945 lio->linfo.link.u64 = ls->u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700946
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700947 if ((lio->intf_open) && (changed)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700948 print_link_info(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700949 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700950
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700951 if (lio->linfo.link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700952 netif_carrier_on(netdev);
953 /* start_txq(netdev); */
954 txqs_wake(netdev);
955 } else {
956 netif_carrier_off(netdev);
957 stop_txq(netdev);
958 }
959 }
960}
961
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -0700962/* Runs in interrupt context. */
963static void update_txq_status(struct octeon_device *oct, int iq_num)
964{
965 struct net_device *netdev;
966 struct lio *lio;
967 struct octeon_instr_queue *iq = oct->instr_queue[iq_num];
968
969 /*octeon_update_iq_read_idx(oct, iq);*/
970
971 netdev = oct->props[iq->ifidx].netdev;
972
973 /* This is needed because the first IQ does not have
974 * a netdev associated with it.
975 */
976 if (!netdev)
977 return;
978
979 lio = GET_LIO(netdev);
980 if (netif_is_multiqueue(netdev)) {
981 if (__netif_subqueue_stopped(netdev, iq->q_index) &&
982 lio->linfo.link.s.link_up &&
983 (!octnet_iq_is_full(oct, iq_num))) {
984 netif_wake_subqueue(netdev, iq->q_index);
985 } else {
986 if (!octnet_iq_is_full(oct, lio->txq))
987 wake_q(netdev, lio->txq);
988 }
989 }
990}
991
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700992/**
993 * \brief Droq packet processor sceduler
994 * @param oct octeon device
995 */
996static
997void liquidio_schedule_droq_pkt_handlers(struct octeon_device *oct)
998{
999 struct octeon_device_priv *oct_priv =
1000 (struct octeon_device_priv *)oct->priv;
1001 u64 oq_no;
1002 struct octeon_droq *droq;
1003
1004 if (oct->int_status & OCT_DEV_INTR_PKT_DATA) {
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001005 for (oq_no = 0; oq_no < MAX_OCTEON_OUTPUT_QUEUES(oct);
1006 oq_no++) {
1007 if (!(oct->droq_intr & (1ULL << oq_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001008 continue;
1009
1010 droq = oct->droq[oq_no];
1011
1012 if (droq->ops.poll_mode) {
1013 droq->ops.napi_fn(droq);
1014 oct_priv->napi_mask |= (1 << oq_no);
1015 } else {
1016 tasklet_schedule(&oct_priv->droq_tasklet);
1017 }
1018 }
1019 }
1020}
1021
1022/**
1023 * \brief Interrupt handler for octeon
1024 * @param irq unused
1025 * @param dev octeon device
1026 */
1027static
1028irqreturn_t liquidio_intr_handler(int irq __attribute__((unused)), void *dev)
1029{
1030 struct octeon_device *oct = (struct octeon_device *)dev;
1031 irqreturn_t ret;
1032
1033 /* Disable our interrupts for the duration of ISR */
1034 oct->fn_list.disable_interrupt(oct->chip);
1035
1036 ret = oct->fn_list.process_interrupt_regs(oct);
1037
1038 if (ret == IRQ_HANDLED)
1039 liquidio_schedule_droq_pkt_handlers(oct);
1040
1041 /* Re-enable our interrupts */
1042 if (!(atomic_read(&oct->status) == OCT_DEV_IN_RESET))
1043 oct->fn_list.enable_interrupt(oct->chip);
1044
1045 return ret;
1046}
1047
1048/**
1049 * \brief Setup interrupt for octeon device
1050 * @param oct octeon device
1051 *
1052 * Enable interrupt in Octeon device as given in the PCI interrupt mask.
1053 */
1054static int octeon_setup_interrupt(struct octeon_device *oct)
1055{
1056 int irqret, err;
1057
1058 err = pci_enable_msi(oct->pci_dev);
1059 if (err)
1060 dev_warn(&oct->pci_dev->dev, "Reverting to legacy interrupts. Error: %d\n",
1061 err);
1062 else
1063 oct->flags |= LIO_FLAG_MSI_ENABLED;
1064
1065 irqret = request_irq(oct->pci_dev->irq, liquidio_intr_handler,
1066 IRQF_SHARED, "octeon", oct);
1067 if (irqret) {
1068 if (oct->flags & LIO_FLAG_MSI_ENABLED)
1069 pci_disable_msi(oct->pci_dev);
1070 dev_err(&oct->pci_dev->dev, "Request IRQ failed with code: %d\n",
1071 irqret);
1072 return 1;
1073 }
1074
1075 return 0;
1076}
1077
1078/**
1079 * \brief PCI probe handler
1080 * @param pdev PCI device structure
1081 * @param ent unused
1082 */
1083static int liquidio_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1084{
1085 struct octeon_device *oct_dev = NULL;
1086 struct handshake *hs;
1087
1088 oct_dev = octeon_allocate_device(pdev->device,
1089 sizeof(struct octeon_device_priv));
1090 if (!oct_dev) {
1091 dev_err(&pdev->dev, "Unable to allocate device\n");
1092 return -ENOMEM;
1093 }
1094
1095 dev_info(&pdev->dev, "Initializing device %x:%x.\n",
1096 (u32)pdev->vendor, (u32)pdev->device);
1097
1098 /* Assign octeon_device for this device to the private data area. */
1099 pci_set_drvdata(pdev, oct_dev);
1100
1101 /* set linux specific device pointer */
1102 oct_dev->pci_dev = (void *)pdev;
1103
1104 hs = &handshake[oct_dev->octeon_id];
1105 init_completion(&hs->init);
1106 init_completion(&hs->started);
1107 hs->pci_dev = pdev;
1108
1109 if (oct_dev->octeon_id == 0)
1110 /* first LiquidIO NIC is detected */
1111 complete(&first_stage);
1112
1113 if (octeon_device_init(oct_dev)) {
1114 liquidio_remove(pdev);
1115 return -ENOMEM;
1116 }
1117
1118 dev_dbg(&oct_dev->pci_dev->dev, "Device is ready\n");
1119
1120 return 0;
1121}
1122
1123/**
1124 *\brief Destroy resources associated with octeon device
1125 * @param pdev PCI device structure
1126 * @param ent unused
1127 */
1128static void octeon_destroy_resources(struct octeon_device *oct)
1129{
1130 int i;
1131 struct octeon_device_priv *oct_priv =
1132 (struct octeon_device_priv *)oct->priv;
1133
1134 struct handshake *hs;
1135
1136 switch (atomic_read(&oct->status)) {
1137 case OCT_DEV_RUNNING:
1138 case OCT_DEV_CORE_OK:
1139
1140 /* No more instructions will be forwarded. */
1141 atomic_set(&oct->status, OCT_DEV_IN_RESET);
1142
1143 oct->app_mode = CVM_DRV_INVALID_APP;
1144 dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
1145 lio_get_state_string(&oct->status));
1146
1147 schedule_timeout_uninterruptible(HZ / 10);
1148
1149 /* fallthrough */
1150 case OCT_DEV_HOST_OK:
1151
1152 /* fallthrough */
1153 case OCT_DEV_CONSOLE_INIT_DONE:
1154 /* Remove any consoles */
1155 octeon_remove_consoles(oct);
1156
1157 /* fallthrough */
1158 case OCT_DEV_IO_QUEUES_DONE:
1159 if (wait_for_pending_requests(oct))
1160 dev_err(&oct->pci_dev->dev, "There were pending requests\n");
1161
1162 if (lio_wait_for_instr_fetch(oct))
1163 dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
1164
1165 /* Disable the input and output queues now. No more packets will
1166 * arrive from Octeon, but we should wait for all packet
1167 * processing to finish.
1168 */
1169 oct->fn_list.disable_io_queues(oct);
1170
1171 if (lio_wait_for_oq_pkts(oct))
1172 dev_err(&oct->pci_dev->dev, "OQ had pending packets\n");
1173
1174 /* Disable interrupts */
1175 oct->fn_list.disable_interrupt(oct->chip);
1176
1177 /* Release the interrupt line */
1178 free_irq(oct->pci_dev->irq, oct);
1179
1180 if (oct->flags & LIO_FLAG_MSI_ENABLED)
1181 pci_disable_msi(oct->pci_dev);
1182
1183 /* Soft reset the octeon device before exiting */
1184 oct->fn_list.soft_reset(oct);
1185
1186 /* Disable the device, releasing the PCI INT */
1187 pci_disable_device(oct->pci_dev);
1188
1189 /* fallthrough */
1190 case OCT_DEV_IN_RESET:
1191 case OCT_DEV_DROQ_INIT_DONE:
1192 /*atomic_set(&oct->status, OCT_DEV_DROQ_INIT_DONE);*/
1193 mdelay(100);
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001194 for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
1195 if (!(oct->io_qmask.oq & (1ULL << i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001196 continue;
1197 octeon_delete_droq(oct, i);
1198 }
1199
1200 /* Force any pending handshakes to complete */
1201 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
1202 hs = &handshake[i];
1203
1204 if (hs->pci_dev) {
1205 handshake[oct->octeon_id].init_ok = 0;
1206 complete(&handshake[oct->octeon_id].init);
1207 handshake[oct->octeon_id].started_ok = 0;
1208 complete(&handshake[oct->octeon_id].started);
1209 }
1210 }
1211
1212 /* fallthrough */
1213 case OCT_DEV_RESP_LIST_INIT_DONE:
1214 octeon_delete_response_list(oct);
1215
1216 /* fallthrough */
1217 case OCT_DEV_SC_BUFF_POOL_INIT_DONE:
1218 octeon_free_sc_buffer_pool(oct);
1219
1220 /* fallthrough */
1221 case OCT_DEV_INSTR_QUEUE_INIT_DONE:
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001222 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
1223 if (!(oct->io_qmask.iq & (1ULL << i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001224 continue;
1225 octeon_delete_instr_queue(oct, i);
1226 }
1227
1228 /* fallthrough */
1229 case OCT_DEV_DISPATCH_INIT_DONE:
1230 octeon_delete_dispatch_list(oct);
1231 cancel_delayed_work_sync(&oct->nic_poll_work.work);
1232
1233 /* fallthrough */
1234 case OCT_DEV_PCI_MAP_DONE:
1235 octeon_unmap_pci_barx(oct, 0);
1236 octeon_unmap_pci_barx(oct, 1);
1237
1238 /* fallthrough */
1239 case OCT_DEV_BEGIN_STATE:
1240 /* Nothing to be done here either */
1241 break;
1242 } /* end switch(oct->status) */
1243
1244 tasklet_kill(&oct_priv->droq_tasklet);
1245}
1246
1247/**
1248 * \brief Send Rx control command
1249 * @param lio per-network private data
1250 * @param start_stop whether to start or stop
1251 */
1252static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
1253{
1254 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001255
1256 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
1257
1258 nctrl.ncmd.s.cmd = OCTNET_CMD_RX_CTL;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07001259 nctrl.ncmd.s.param1 = start_stop;
1260 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001261 nctrl.netpndev = (u64)lio->netdev;
1262
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07001263 if (octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl) < 0)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001264 netif_info(lio, rx_err, lio->netdev, "Failed to send RX Control message\n");
1265}
1266
1267/**
1268 * \brief Destroy NIC device interface
1269 * @param oct octeon device
1270 * @param ifidx which interface to destroy
1271 *
1272 * Cleanup associated with each interface for an Octeon device when NIC
1273 * module is being unloaded or if initialization fails during load.
1274 */
1275static void liquidio_destroy_nic_device(struct octeon_device *oct, int ifidx)
1276{
1277 struct net_device *netdev = oct->props[ifidx].netdev;
1278 struct lio *lio;
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07001279 struct napi_struct *napi, *n;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001280
1281 if (!netdev) {
1282 dev_err(&oct->pci_dev->dev, "%s No netdevice ptr for index %d\n",
1283 __func__, ifidx);
1284 return;
1285 }
1286
1287 lio = GET_LIO(netdev);
1288
1289 dev_dbg(&oct->pci_dev->dev, "NIC device cleanup\n");
1290
1291 send_rx_ctrl_cmd(lio, 0);
1292
1293 if (atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING)
1294 txqs_stop(netdev);
1295
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07001296 if (oct->props[lio->ifidx].napi_enabled == 1) {
1297 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
1298 napi_disable(napi);
1299
1300 oct->props[lio->ifidx].napi_enabled = 0;
1301 }
1302
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001303 if (atomic_read(&lio->ifstate) & LIO_IFSTATE_REGISTERED)
1304 unregister_netdev(netdev);
1305
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001306 delete_glists(lio);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001307
1308 free_netdev(netdev);
1309
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07001310 oct->props[ifidx].gmxport = -1;
1311
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001312 oct->props[ifidx].netdev = NULL;
1313}
1314
1315/**
1316 * \brief Stop complete NIC functionality
1317 * @param oct octeon device
1318 */
1319static int liquidio_stop_nic_module(struct octeon_device *oct)
1320{
1321 int i, j;
1322 struct lio *lio;
1323
1324 dev_dbg(&oct->pci_dev->dev, "Stopping network interfaces\n");
1325 if (!oct->ifcount) {
1326 dev_err(&oct->pci_dev->dev, "Init for Octeon was not completed\n");
1327 return 1;
1328 }
1329
Raghu Vatsavayi60441882016-06-21 22:53:08 -07001330 spin_lock_bh(&oct->cmd_resp_wqlock);
1331 oct->cmd_resp_state = OCT_DRV_OFFLINE;
1332 spin_unlock_bh(&oct->cmd_resp_wqlock);
1333
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001334 for (i = 0; i < oct->ifcount; i++) {
1335 lio = GET_LIO(oct->props[i].netdev);
1336 for (j = 0; j < lio->linfo.num_rxpciq; j++)
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001337 octeon_unregister_droq_ops(oct,
1338 lio->linfo.rxpciq[j].s.q_no);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001339 }
1340
1341 for (i = 0; i < oct->ifcount; i++)
1342 liquidio_destroy_nic_device(oct, i);
1343
1344 dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n");
1345 return 0;
1346}
1347
1348/**
1349 * \brief Cleans up resources at unload time
1350 * @param pdev PCI device structure
1351 */
1352static void liquidio_remove(struct pci_dev *pdev)
1353{
1354 struct octeon_device *oct_dev = pci_get_drvdata(pdev);
1355
1356 dev_dbg(&oct_dev->pci_dev->dev, "Stopping device\n");
1357
1358 if (oct_dev->app_mode && (oct_dev->app_mode == CVM_DRV_NIC_APP))
1359 liquidio_stop_nic_module(oct_dev);
1360
1361 /* Reset the octeon device and cleanup all memory allocated for
1362 * the octeon device by driver.
1363 */
1364 octeon_destroy_resources(oct_dev);
1365
1366 dev_info(&oct_dev->pci_dev->dev, "Device removed\n");
1367
1368 /* This octeon device has been removed. Update the global
1369 * data structure to reflect this. Free the device structure.
1370 */
1371 octeon_free_device_mem(oct_dev);
1372}
1373
1374/**
1375 * \brief Identify the Octeon device and to map the BAR address space
1376 * @param oct octeon device
1377 */
1378static int octeon_chip_specific_setup(struct octeon_device *oct)
1379{
1380 u32 dev_id, rev_id;
1381 int ret = 1;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001382 char *s;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001383
1384 pci_read_config_dword(oct->pci_dev, 0, &dev_id);
1385 pci_read_config_dword(oct->pci_dev, 8, &rev_id);
1386 oct->rev_id = rev_id & 0xff;
1387
1388 switch (dev_id) {
1389 case OCTEON_CN68XX_PCIID:
1390 oct->chip_id = OCTEON_CN68XX;
1391 ret = lio_setup_cn68xx_octeon_device(oct);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001392 s = "CN68XX";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001393 break;
1394
1395 case OCTEON_CN66XX_PCIID:
1396 oct->chip_id = OCTEON_CN66XX;
1397 ret = lio_setup_cn66xx_octeon_device(oct);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001398 s = "CN66XX";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001399 break;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001400
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001401 default:
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001402 s = "?";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001403 dev_err(&oct->pci_dev->dev, "Unknown device found (dev_id: %x)\n",
1404 dev_id);
1405 }
1406
1407 if (!ret)
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001408 dev_info(&oct->pci_dev->dev, "%s PASS%d.%d %s Version: %s\n", s,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001409 OCTEON_MAJOR_REV(oct),
1410 OCTEON_MINOR_REV(oct),
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001411 octeon_get_conf(oct)->card_name,
1412 LIQUIDIO_VERSION);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001413
1414 return ret;
1415}
1416
1417/**
1418 * \brief PCI initialization for each Octeon device.
1419 * @param oct octeon device
1420 */
1421static int octeon_pci_os_setup(struct octeon_device *oct)
1422{
1423 /* setup PCI stuff first */
1424 if (pci_enable_device(oct->pci_dev)) {
1425 dev_err(&oct->pci_dev->dev, "pci_enable_device failed\n");
1426 return 1;
1427 }
1428
1429 if (dma_set_mask_and_coherent(&oct->pci_dev->dev, DMA_BIT_MASK(64))) {
1430 dev_err(&oct->pci_dev->dev, "Unexpected DMA device capability\n");
1431 return 1;
1432 }
1433
1434 /* Enable PCI DMA Master. */
1435 pci_set_master(oct->pci_dev);
1436
1437 return 0;
1438}
1439
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001440static inline int skb_iq(struct lio *lio, struct sk_buff *skb)
1441{
1442 int q = 0;
1443
1444 if (netif_is_multiqueue(lio->netdev))
1445 q = skb->queue_mapping % lio->linfo.num_txpciq;
1446
1447 return q;
1448}
1449
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001450/**
1451 * \brief Check Tx queue state for a given network buffer
1452 * @param lio per-network private data
1453 * @param skb network buffer
1454 */
1455static inline int check_txq_state(struct lio *lio, struct sk_buff *skb)
1456{
1457 int q = 0, iq = 0;
1458
1459 if (netif_is_multiqueue(lio->netdev)) {
1460 q = skb->queue_mapping;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001461 iq = lio->linfo.txpciq[(q % (lio->linfo.num_txpciq))].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001462 } else {
1463 iq = lio->txq;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001464 q = iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001465 }
1466
1467 if (octnet_iq_is_full(lio->oct_dev, iq))
1468 return 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001469
1470 if (__netif_subqueue_stopped(lio->netdev, q))
1471 wake_q(lio->netdev, q);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001472 return 1;
1473}
1474
1475/**
1476 * \brief Unmap and free network buffer
1477 * @param buf buffer
1478 */
1479static void free_netbuf(void *buf)
1480{
1481 struct sk_buff *skb;
1482 struct octnet_buf_free_info *finfo;
1483 struct lio *lio;
1484
1485 finfo = (struct octnet_buf_free_info *)buf;
1486 skb = finfo->skb;
1487 lio = finfo->lio;
1488
1489 dma_unmap_single(&lio->oct_dev->pci_dev->dev, finfo->dptr, skb->len,
1490 DMA_TO_DEVICE);
1491
1492 check_txq_state(lio, skb);
1493
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07001494 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001495}
1496
1497/**
1498 * \brief Unmap and free gather buffer
1499 * @param buf buffer
1500 */
1501static void free_netsgbuf(void *buf)
1502{
1503 struct octnet_buf_free_info *finfo;
1504 struct sk_buff *skb;
1505 struct lio *lio;
1506 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001507 int i, frags, iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001508
1509 finfo = (struct octnet_buf_free_info *)buf;
1510 skb = finfo->skb;
1511 lio = finfo->lio;
1512 g = finfo->g;
1513 frags = skb_shinfo(skb)->nr_frags;
1514
1515 dma_unmap_single(&lio->oct_dev->pci_dev->dev,
1516 g->sg[0].ptr[0], (skb->len - skb->data_len),
1517 DMA_TO_DEVICE);
1518
1519 i = 1;
1520 while (frags--) {
1521 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
1522
1523 pci_unmap_page((lio->oct_dev)->pci_dev,
1524 g->sg[(i >> 2)].ptr[(i & 3)],
1525 frag->size, DMA_TO_DEVICE);
1526 i++;
1527 }
1528
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001529 dma_sync_single_for_cpu(&lio->oct_dev->pci_dev->dev,
1530 g->sg_dma_ptr, g->sg_size, DMA_TO_DEVICE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001531
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001532 iq = skb_iq(lio, skb);
1533 spin_lock(&lio->glist_lock[iq]);
1534 list_add_tail(&g->list, &lio->glist[iq]);
1535 spin_unlock(&lio->glist_lock[iq]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001536
1537 check_txq_state(lio, skb); /* mq support: sub-queue state check */
1538
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07001539 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001540}
1541
1542/**
1543 * \brief Unmap and free gather buffer with response
1544 * @param buf buffer
1545 */
1546static void free_netsgbuf_with_resp(void *buf)
1547{
1548 struct octeon_soft_command *sc;
1549 struct octnet_buf_free_info *finfo;
1550 struct sk_buff *skb;
1551 struct lio *lio;
1552 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001553 int i, frags, iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001554
1555 sc = (struct octeon_soft_command *)buf;
1556 skb = (struct sk_buff *)sc->callback_arg;
1557 finfo = (struct octnet_buf_free_info *)&skb->cb;
1558
1559 lio = finfo->lio;
1560 g = finfo->g;
1561 frags = skb_shinfo(skb)->nr_frags;
1562
1563 dma_unmap_single(&lio->oct_dev->pci_dev->dev,
1564 g->sg[0].ptr[0], (skb->len - skb->data_len),
1565 DMA_TO_DEVICE);
1566
1567 i = 1;
1568 while (frags--) {
1569 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
1570
1571 pci_unmap_page((lio->oct_dev)->pci_dev,
1572 g->sg[(i >> 2)].ptr[(i & 3)],
1573 frag->size, DMA_TO_DEVICE);
1574 i++;
1575 }
1576
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001577 dma_sync_single_for_cpu(&lio->oct_dev->pci_dev->dev,
1578 g->sg_dma_ptr, g->sg_size, DMA_TO_DEVICE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001579
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001580 iq = skb_iq(lio, skb);
1581
1582 spin_lock(&lio->glist_lock[iq]);
1583 list_add_tail(&g->list, &lio->glist[iq]);
1584 spin_unlock(&lio->glist_lock[iq]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001585
1586 /* Don't free the skb yet */
1587
1588 check_txq_state(lio, skb);
1589}
1590
1591/**
1592 * \brief Adjust ptp frequency
1593 * @param ptp PTP clock info
1594 * @param ppb how much to adjust by, in parts-per-billion
1595 */
1596static int liquidio_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
1597{
1598 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1599 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1600 u64 comp, delta;
1601 unsigned long flags;
1602 bool neg_adj = false;
1603
1604 if (ppb < 0) {
1605 neg_adj = true;
1606 ppb = -ppb;
1607 }
1608
1609 /* The hardware adds the clock compensation value to the
1610 * PTP clock on every coprocessor clock cycle, so we
1611 * compute the delta in terms of coprocessor clocks.
1612 */
1613 delta = (u64)ppb << 32;
1614 do_div(delta, oct->coproc_clock_rate);
1615
1616 spin_lock_irqsave(&lio->ptp_lock, flags);
1617 comp = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_COMP);
1618 if (neg_adj)
1619 comp -= delta;
1620 else
1621 comp += delta;
1622 lio_pci_writeq(oct, comp, CN6XXX_MIO_PTP_CLOCK_COMP);
1623 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1624
1625 return 0;
1626}
1627
1628/**
1629 * \brief Adjust ptp time
1630 * @param ptp PTP clock info
1631 * @param delta how much to adjust by, in nanosecs
1632 */
1633static int liquidio_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
1634{
1635 unsigned long flags;
1636 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1637
1638 spin_lock_irqsave(&lio->ptp_lock, flags);
1639 lio->ptp_adjust += delta;
1640 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1641
1642 return 0;
1643}
1644
1645/**
1646 * \brief Get hardware clock time, including any adjustment
1647 * @param ptp PTP clock info
1648 * @param ts timespec
1649 */
1650static int liquidio_ptp_gettime(struct ptp_clock_info *ptp,
1651 struct timespec64 *ts)
1652{
1653 u64 ns;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001654 unsigned long flags;
1655 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1656 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1657
1658 spin_lock_irqsave(&lio->ptp_lock, flags);
1659 ns = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_HI);
1660 ns += lio->ptp_adjust;
1661 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1662
Kefeng Wang286af312016-01-27 17:34:37 +08001663 *ts = ns_to_timespec64(ns);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001664
1665 return 0;
1666}
1667
1668/**
1669 * \brief Set hardware clock time. Reset adjustment
1670 * @param ptp PTP clock info
1671 * @param ts timespec
1672 */
1673static int liquidio_ptp_settime(struct ptp_clock_info *ptp,
1674 const struct timespec64 *ts)
1675{
1676 u64 ns;
1677 unsigned long flags;
1678 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1679 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1680
1681 ns = timespec_to_ns(ts);
1682
1683 spin_lock_irqsave(&lio->ptp_lock, flags);
1684 lio_pci_writeq(oct, ns, CN6XXX_MIO_PTP_CLOCK_HI);
1685 lio->ptp_adjust = 0;
1686 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1687
1688 return 0;
1689}
1690
1691/**
1692 * \brief Check if PTP is enabled
1693 * @param ptp PTP clock info
1694 * @param rq request
1695 * @param on is it on
1696 */
1697static int liquidio_ptp_enable(struct ptp_clock_info *ptp,
1698 struct ptp_clock_request *rq, int on)
1699{
1700 return -EOPNOTSUPP;
1701}
1702
1703/**
1704 * \brief Open PTP clock source
1705 * @param netdev network device
1706 */
1707static void oct_ptp_open(struct net_device *netdev)
1708{
1709 struct lio *lio = GET_LIO(netdev);
1710 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1711
1712 spin_lock_init(&lio->ptp_lock);
1713
1714 snprintf(lio->ptp_info.name, 16, "%s", netdev->name);
1715 lio->ptp_info.owner = THIS_MODULE;
1716 lio->ptp_info.max_adj = 250000000;
1717 lio->ptp_info.n_alarm = 0;
1718 lio->ptp_info.n_ext_ts = 0;
1719 lio->ptp_info.n_per_out = 0;
1720 lio->ptp_info.pps = 0;
1721 lio->ptp_info.adjfreq = liquidio_ptp_adjfreq;
1722 lio->ptp_info.adjtime = liquidio_ptp_adjtime;
1723 lio->ptp_info.gettime64 = liquidio_ptp_gettime;
1724 lio->ptp_info.settime64 = liquidio_ptp_settime;
1725 lio->ptp_info.enable = liquidio_ptp_enable;
1726
1727 lio->ptp_adjust = 0;
1728
1729 lio->ptp_clock = ptp_clock_register(&lio->ptp_info,
1730 &oct->pci_dev->dev);
1731
1732 if (IS_ERR(lio->ptp_clock))
1733 lio->ptp_clock = NULL;
1734}
1735
1736/**
1737 * \brief Init PTP clock
1738 * @param oct octeon device
1739 */
1740static void liquidio_ptp_init(struct octeon_device *oct)
1741{
1742 u64 clock_comp, cfg;
1743
1744 clock_comp = (u64)NSEC_PER_SEC << 32;
1745 do_div(clock_comp, oct->coproc_clock_rate);
1746 lio_pci_writeq(oct, clock_comp, CN6XXX_MIO_PTP_CLOCK_COMP);
1747
1748 /* Enable */
1749 cfg = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_CFG);
1750 lio_pci_writeq(oct, cfg | 0x01, CN6XXX_MIO_PTP_CLOCK_CFG);
1751}
1752
1753/**
1754 * \brief Load firmware to device
1755 * @param oct octeon device
1756 *
1757 * Maps device to firmware filename, requests firmware, and downloads it
1758 */
1759static int load_firmware(struct octeon_device *oct)
1760{
1761 int ret = 0;
1762 const struct firmware *fw;
1763 char fw_name[LIO_MAX_FW_FILENAME_LEN];
1764 char *tmp_fw_type;
1765
1766 if (strncmp(fw_type, LIO_FW_NAME_TYPE_NONE,
1767 sizeof(LIO_FW_NAME_TYPE_NONE)) == 0) {
1768 dev_info(&oct->pci_dev->dev, "Skipping firmware load\n");
1769 return ret;
1770 }
1771
1772 if (fw_type[0] == '\0')
1773 tmp_fw_type = LIO_FW_NAME_TYPE_NIC;
1774 else
1775 tmp_fw_type = fw_type;
1776
1777 sprintf(fw_name, "%s%s%s_%s%s", LIO_FW_DIR, LIO_FW_BASE_NAME,
1778 octeon_get_conf(oct)->card_name, tmp_fw_type,
1779 LIO_FW_NAME_SUFFIX);
1780
1781 ret = request_firmware(&fw, fw_name, &oct->pci_dev->dev);
1782 if (ret) {
1783 dev_err(&oct->pci_dev->dev, "Request firmware failed. Could not find file %s.\n.",
1784 fw_name);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001785 release_firmware(fw);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001786 return ret;
1787 }
1788
1789 ret = octeon_download_firmware(oct, fw->data, fw->size);
1790
1791 release_firmware(fw);
1792
1793 return ret;
1794}
1795
1796/**
1797 * \brief Setup output queue
1798 * @param oct octeon device
1799 * @param q_no which queue
1800 * @param num_descs how many descriptors
1801 * @param desc_size size of each descriptor
1802 * @param app_ctx application context
1803 */
1804static int octeon_setup_droq(struct octeon_device *oct, int q_no, int num_descs,
1805 int desc_size, void *app_ctx)
1806{
1807 int ret_val = 0;
1808
1809 dev_dbg(&oct->pci_dev->dev, "Creating Droq: %d\n", q_no);
1810 /* droq creation and local register settings. */
1811 ret_val = octeon_create_droq(oct, q_no, num_descs, desc_size, app_ctx);
Amitoj Kaur Chawla08a965e2016-02-04 19:25:13 +05301812 if (ret_val < 0)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001813 return ret_val;
1814
1815 if (ret_val == 1) {
1816 dev_dbg(&oct->pci_dev->dev, "Using default droq %d\n", q_no);
1817 return 0;
1818 }
1819 /* tasklet creation for the droq */
1820
1821 /* Enable the droq queues */
1822 octeon_set_droq_pkt_op(oct, q_no, 1);
1823
1824 /* Send Credit for Octeon Output queues. Credits are always
1825 * sent after the output queue is enabled.
1826 */
1827 writel(oct->droq[q_no]->max_count,
1828 oct->droq[q_no]->pkts_credit_reg);
1829
1830 return ret_val;
1831}
1832
1833/**
1834 * \brief Callback for getting interface configuration
1835 * @param status status of request
1836 * @param buf pointer to resp structure
1837 */
1838static void if_cfg_callback(struct octeon_device *oct,
1839 u32 status,
1840 void *buf)
1841{
1842 struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
1843 struct liquidio_if_cfg_resp *resp;
1844 struct liquidio_if_cfg_context *ctx;
1845
1846 resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
1847 ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
1848
1849 oct = lio_get_device(ctx->octeon_id);
1850 if (resp->status)
1851 dev_err(&oct->pci_dev->dev, "nic if cfg instruction failed. Status: %llx\n",
1852 CVM_CAST64(resp->status));
1853 ACCESS_ONCE(ctx->cond) = 1;
1854
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001855 snprintf(oct->fw_info.liquidio_firmware_version, 32, "%s",
1856 resp->cfg_info.liquidio_firmware_version);
1857
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001858 /* This barrier is required to be sure that the response has been
1859 * written fully before waking up the handler
1860 */
1861 wmb();
1862
1863 wake_up_interruptible(&ctx->wc);
1864}
1865
1866/**
1867 * \brief Select queue based on hash
1868 * @param dev Net device
1869 * @param skb sk_buff structure
1870 * @returns selected queue number
1871 */
1872static u16 select_q(struct net_device *dev, struct sk_buff *skb,
1873 void *accel_priv, select_queue_fallback_t fallback)
1874{
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001875 u32 qindex = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001876 struct lio *lio;
1877
1878 lio = GET_LIO(dev);
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001879 qindex = skb_tx_hash(dev, skb);
1880
1881 return (u16)(qindex % (lio->linfo.num_txpciq));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001882}
1883
1884/** Routine to push packets arriving on Octeon interface upto network layer.
1885 * @param oct_id - octeon device id.
1886 * @param skbuff - skbuff struct to be passed to network layer.
1887 * @param len - size of total data received.
1888 * @param rh - Control header associated with the packet
1889 * @param param - additional control data with the packet
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07001890 * @param arg - farg registered in droq_ops
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001891 */
1892static void
1893liquidio_push_packet(u32 octeon_id,
1894 void *skbuff,
1895 u32 len,
1896 union octeon_rh *rh,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07001897 void *param,
1898 void *arg)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001899{
1900 struct napi_struct *napi = param;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001901 struct sk_buff *skb = (struct sk_buff *)skbuff;
1902 struct skb_shared_hwtstamps *shhwtstamps;
1903 u64 ns;
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07001904 u16 vtag = 0;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07001905 struct net_device *netdev = (struct net_device *)arg;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001906 struct octeon_droq *droq = container_of(param, struct octeon_droq,
1907 napi);
1908 if (netdev) {
1909 int packet_was_received;
1910 struct lio *lio = GET_LIO(netdev);
Raghu Vatsavayia5b37882016-06-14 16:54:48 -07001911 struct octeon_device *oct = lio->oct_dev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001912
1913 /* Do not proceed if the interface is not in RUNNING state. */
1914 if (!ifstate_check(lio, LIO_IFSTATE_RUNNING)) {
1915 recv_buffer_free(skb);
1916 droq->stats.rx_dropped++;
1917 return;
1918 }
1919
1920 skb->dev = netdev;
1921
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001922 skb_record_rx_queue(skb, droq->q_no);
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07001923 if (likely(len > MIN_SKB_SIZE)) {
1924 struct octeon_skb_page_info *pg_info;
1925 unsigned char *va;
1926
1927 pg_info = ((struct octeon_skb_page_info *)(skb->cb));
1928 if (pg_info->page) {
1929 /* For Paged allocation use the frags */
1930 va = page_address(pg_info->page) +
1931 pg_info->page_offset;
1932 memcpy(skb->data, va, MIN_SKB_SIZE);
1933 skb_put(skb, MIN_SKB_SIZE);
1934 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
1935 pg_info->page,
1936 pg_info->page_offset +
1937 MIN_SKB_SIZE,
1938 len - MIN_SKB_SIZE,
1939 LIO_RXBUFFER_SZ);
1940 }
1941 } else {
1942 struct octeon_skb_page_info *pg_info =
1943 ((struct octeon_skb_page_info *)(skb->cb));
1944 skb_copy_to_linear_data(skb, page_address(pg_info->page)
1945 + pg_info->page_offset, len);
1946 skb_put(skb, len);
1947 put_page(pg_info->page);
1948 }
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001949
Raghu Vatsavayia5b37882016-06-14 16:54:48 -07001950 if (((oct->chip_id == OCTEON_CN66XX) ||
1951 (oct->chip_id == OCTEON_CN68XX)) &&
1952 ptp_enable) {
1953 if (rh->r_dh.has_hwtstamp) {
1954 /* timestamp is included from the hardware at
1955 * the beginning of the packet.
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001956 */
Raghu Vatsavayia5b37882016-06-14 16:54:48 -07001957 if (ifstate_check
1958 (lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED)) {
1959 /* Nanoseconds are in the first 64-bits
1960 * of the packet.
1961 */
1962 memcpy(&ns, (skb->data), sizeof(ns));
1963 shhwtstamps = skb_hwtstamps(skb);
1964 shhwtstamps->hwtstamp =
1965 ns_to_ktime(ns +
1966 lio->ptp_adjust);
1967 }
1968 skb_pull(skb, sizeof(ns));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001969 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001970 }
1971
1972 skb->protocol = eth_type_trans(skb, skb->dev);
1973
1974 if ((netdev->features & NETIF_F_RXCSUM) &&
1975 (rh->r_dh.csum_verified == CNNIC_CSUM_VERIFIED))
1976 /* checksum has already been verified */
1977 skb->ip_summed = CHECKSUM_UNNECESSARY;
1978 else
1979 skb->ip_summed = CHECKSUM_NONE;
1980
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07001981 /* inbound VLAN tag */
1982 if ((netdev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
1983 (rh->r_dh.vlan != 0)) {
1984 u16 vid = rh->r_dh.vlan;
1985 u16 priority = rh->r_dh.priority;
1986
1987 vtag = priority << 13 | vid;
1988 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vtag);
1989 }
1990
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001991 packet_was_received = napi_gro_receive(napi, skb) != GRO_DROP;
1992
1993 if (packet_was_received) {
1994 droq->stats.rx_bytes_received += len;
1995 droq->stats.rx_pkts_received++;
1996 netdev->last_rx = jiffies;
1997 } else {
1998 droq->stats.rx_dropped++;
1999 netif_info(lio, rx_err, lio->netdev,
2000 "droq:%d error rx_dropped:%llu\n",
2001 droq->q_no, droq->stats.rx_dropped);
2002 }
2003
2004 } else {
2005 recv_buffer_free(skb);
2006 }
2007}
2008
2009/**
2010 * \brief wrapper for calling napi_schedule
2011 * @param param parameters to pass to napi_schedule
2012 *
2013 * Used when scheduling on different CPUs
2014 */
2015static void napi_schedule_wrapper(void *param)
2016{
2017 struct napi_struct *napi = param;
2018
2019 napi_schedule(napi);
2020}
2021
2022/**
2023 * \brief callback when receive interrupt occurs and we are in NAPI mode
2024 * @param arg pointer to octeon output queue
2025 */
2026static void liquidio_napi_drv_callback(void *arg)
2027{
2028 struct octeon_droq *droq = arg;
2029 int this_cpu = smp_processor_id();
2030
2031 if (droq->cpu_id == this_cpu) {
2032 napi_schedule(&droq->napi);
2033 } else {
2034 struct call_single_data *csd = &droq->csd;
2035
2036 csd->func = napi_schedule_wrapper;
2037 csd->info = &droq->napi;
2038 csd->flags = 0;
2039
2040 smp_call_function_single_async(droq->cpu_id, csd);
2041 }
2042}
2043
2044/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002045 * \brief Entry point for NAPI polling
2046 * @param napi NAPI structure
2047 * @param budget maximum number of items to process
2048 */
2049static int liquidio_napi_poll(struct napi_struct *napi, int budget)
2050{
2051 struct octeon_droq *droq;
2052 int work_done;
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002053 int tx_done = 0, iq_no;
2054 struct octeon_instr_queue *iq;
2055 struct octeon_device *oct;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002056
2057 droq = container_of(napi, struct octeon_droq, napi);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002058 oct = droq->oct_dev;
2059 iq_no = droq->q_no;
2060 /* Handle Droq descriptors */
2061 work_done = octeon_process_droq_poll_cmd(oct, droq->q_no,
2062 POLL_EVENT_PROCESS_PKTS,
2063 budget);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002064
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002065 /* Flush the instruction queue */
2066 iq = oct->instr_queue[iq_no];
2067 if (iq) {
2068 /* Process iq buffers with in the budget limits */
2069 tx_done = octeon_flush_iq(oct, iq, 1, budget);
2070 /* Update iq read-index rather than waiting for next interrupt.
2071 * Return back if tx_done is false.
2072 */
2073 update_txq_status(oct, iq_no);
2074 /*tx_done = (iq->flush_index == iq->octeon_read_index);*/
2075 } else {
2076 dev_err(&oct->pci_dev->dev, "%s: iq (%d) num invalid\n",
2077 __func__, iq_no);
2078 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002079
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002080 if ((work_done < budget) && (tx_done)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002081 napi_complete(napi);
2082 octeon_process_droq_poll_cmd(droq->oct_dev, droq->q_no,
2083 POLL_EVENT_ENABLE_INTR, 0);
2084 return 0;
2085 }
2086
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002087 return (!tx_done) ? (budget) : (work_done);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002088}
2089
2090/**
2091 * \brief Setup input and output queues
2092 * @param octeon_dev octeon device
2093 * @param net_device Net device
2094 *
2095 * Note: Queues are with respect to the octeon device. Thus
2096 * an input queue is for egress packets, and output queues
2097 * are for ingress packets.
2098 */
2099static inline int setup_io_queues(struct octeon_device *octeon_dev,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002100 int ifidx)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002101{
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002102 struct octeon_droq_ops droq_ops;
2103 struct net_device *netdev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002104 static int cpu_id;
2105 static int cpu_id_modulus;
2106 struct octeon_droq *droq;
2107 struct napi_struct *napi;
2108 int q, q_no, retval = 0;
2109 struct lio *lio;
2110 int num_tx_descs;
2111
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002112 netdev = octeon_dev->props[ifidx].netdev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002113
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002114 lio = GET_LIO(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002115
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002116 memset(&droq_ops, 0, sizeof(struct octeon_droq_ops));
2117
2118 droq_ops.fptr = liquidio_push_packet;
2119 droq_ops.farg = (void *)netdev;
2120
2121 droq_ops.poll_mode = 1;
2122 droq_ops.napi_fn = liquidio_napi_drv_callback;
2123 cpu_id = 0;
2124 cpu_id_modulus = num_present_cpus();
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002125
2126 /* set up DROQs. */
2127 for (q = 0; q < lio->linfo.num_rxpciq; q++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002128 q_no = lio->linfo.rxpciq[q].s.q_no;
2129 dev_dbg(&octeon_dev->pci_dev->dev,
2130 "setup_io_queues index:%d linfo.rxpciq.s.q_no:%d\n",
2131 q, q_no);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002132 retval = octeon_setup_droq(octeon_dev, q_no,
2133 CFG_GET_NUM_RX_DESCS_NIC_IF
2134 (octeon_get_conf(octeon_dev),
2135 lio->ifidx),
2136 CFG_GET_NUM_RX_BUF_SIZE_NIC_IF
2137 (octeon_get_conf(octeon_dev),
2138 lio->ifidx), NULL);
2139 if (retval) {
2140 dev_err(&octeon_dev->pci_dev->dev,
2141 " %s : Runtime DROQ(RxQ) creation failed.\n",
2142 __func__);
2143 return 1;
2144 }
2145
2146 droq = octeon_dev->droq[q_no];
2147 napi = &droq->napi;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002148 dev_dbg(&octeon_dev->pci_dev->dev,
2149 "netif_napi_add netdev:%llx oct:%llx\n",
2150 (u64)netdev,
2151 (u64)octeon_dev);
2152 netif_napi_add(netdev, napi, liquidio_napi_poll, 64);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002153
2154 /* designate a CPU for this droq */
2155 droq->cpu_id = cpu_id;
2156 cpu_id++;
2157 if (cpu_id >= cpu_id_modulus)
2158 cpu_id = 0;
2159
2160 octeon_register_droq_ops(octeon_dev, q_no, &droq_ops);
2161 }
2162
2163 /* set up IQs. */
2164 for (q = 0; q < lio->linfo.num_txpciq; q++) {
2165 num_tx_descs = CFG_GET_NUM_TX_DESCS_NIC_IF(octeon_get_conf
2166 (octeon_dev),
2167 lio->ifidx);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002168 retval = octeon_setup_iq(octeon_dev, ifidx, q,
2169 lio->linfo.txpciq[q], num_tx_descs,
2170 netdev_get_tx_queue(netdev, q));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002171 if (retval) {
2172 dev_err(&octeon_dev->pci_dev->dev,
2173 " %s : Runtime IQ(TxQ) creation failed.\n",
2174 __func__);
2175 return 1;
2176 }
2177 }
2178
2179 return 0;
2180}
2181
2182/**
2183 * \brief Poll routine for checking transmit queue status
2184 * @param work work_struct data structure
2185 */
2186static void octnet_poll_check_txq_status(struct work_struct *work)
2187{
2188 struct cavium_wk *wk = (struct cavium_wk *)work;
2189 struct lio *lio = (struct lio *)wk->ctxptr;
2190
2191 if (!ifstate_check(lio, LIO_IFSTATE_RUNNING))
2192 return;
2193
2194 check_txq_status(lio);
2195 queue_delayed_work(lio->txq_status_wq.wq,
2196 &lio->txq_status_wq.wk.work, msecs_to_jiffies(1));
2197}
2198
2199/**
2200 * \brief Sets up the txq poll check
2201 * @param netdev network device
2202 */
2203static inline void setup_tx_poll_fn(struct net_device *netdev)
2204{
2205 struct lio *lio = GET_LIO(netdev);
2206 struct octeon_device *oct = lio->oct_dev;
2207
Bhaktipriya Shridhar292b9da2016-06-08 01:47:59 +05302208 lio->txq_status_wq.wq = alloc_workqueue("txq-status",
2209 WQ_MEM_RECLAIM, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002210 if (!lio->txq_status_wq.wq) {
2211 dev_err(&oct->pci_dev->dev, "unable to create cavium txq status wq\n");
2212 return;
2213 }
2214 INIT_DELAYED_WORK(&lio->txq_status_wq.wk.work,
2215 octnet_poll_check_txq_status);
2216 lio->txq_status_wq.wk.ctxptr = lio;
2217 queue_delayed_work(lio->txq_status_wq.wq,
2218 &lio->txq_status_wq.wk.work, msecs_to_jiffies(1));
2219}
2220
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002221static inline void cleanup_tx_poll_fn(struct net_device *netdev)
2222{
2223 struct lio *lio = GET_LIO(netdev);
2224
2225 cancel_delayed_work_sync(&lio->txq_status_wq.wk.work);
2226 destroy_workqueue(lio->txq_status_wq.wq);
2227}
2228
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002229/**
2230 * \brief Net device open for LiquidIO
2231 * @param netdev network device
2232 */
2233static int liquidio_open(struct net_device *netdev)
2234{
2235 struct lio *lio = GET_LIO(netdev);
2236 struct octeon_device *oct = lio->oct_dev;
2237 struct napi_struct *napi, *n;
2238
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002239 if (oct->props[lio->ifidx].napi_enabled == 0) {
2240 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
2241 napi_enable(napi);
2242
2243 oct->props[lio->ifidx].napi_enabled = 1;
2244 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002245
2246 oct_ptp_open(netdev);
2247
2248 ifstate_set(lio, LIO_IFSTATE_RUNNING);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002249
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002250 setup_tx_poll_fn(netdev);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002251
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002252 start_txq(netdev);
2253
2254 netif_info(lio, ifup, lio->netdev, "Interface Open, ready for traffic\n");
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002255
2256 /* tell Octeon to start forwarding packets to host */
2257 send_rx_ctrl_cmd(lio, 1);
2258
2259 /* Ready for link status updates */
2260 lio->intf_open = 1;
2261
2262 dev_info(&oct->pci_dev->dev, "%s interface is opened\n",
2263 netdev->name);
2264
2265 return 0;
2266}
2267
2268/**
2269 * \brief Net device stop for LiquidIO
2270 * @param netdev network device
2271 */
2272static int liquidio_stop(struct net_device *netdev)
2273{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002274 struct lio *lio = GET_LIO(netdev);
2275 struct octeon_device *oct = lio->oct_dev;
2276
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002277 ifstate_reset(lio, LIO_IFSTATE_RUNNING);
2278
2279 netif_tx_disable(netdev);
2280
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002281 /* Inform that netif carrier is down */
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002282 netif_carrier_off(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002283 lio->intf_open = 0;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002284 lio->linfo.link.s.link_up = 0;
2285 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002286
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002287 /* Pause for a moment and wait for Octeon to flush out (to the wire) any
2288 * egress packets that are in-flight.
2289 */
2290 set_current_state(TASK_INTERRUPTIBLE);
2291 schedule_timeout(msecs_to_jiffies(100));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002292
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002293 /* Now it should be safe to tell Octeon that nic interface is down. */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002294 send_rx_ctrl_cmd(lio, 0);
2295
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002296 cleanup_tx_poll_fn(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002297
2298 if (lio->ptp_clock) {
2299 ptp_clock_unregister(lio->ptp_clock);
2300 lio->ptp_clock = NULL;
2301 }
2302
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002303 dev_info(&oct->pci_dev->dev, "%s interface is stopped\n", netdev->name);
2304 module_put(THIS_MODULE);
2305
2306 return 0;
2307}
2308
2309void liquidio_link_ctrl_cmd_completion(void *nctrl_ptr)
2310{
2311 struct octnic_ctrl_pkt *nctrl = (struct octnic_ctrl_pkt *)nctrl_ptr;
2312 struct net_device *netdev = (struct net_device *)nctrl->netpndev;
2313 struct lio *lio = GET_LIO(netdev);
2314 struct octeon_device *oct = lio->oct_dev;
2315
2316 switch (nctrl->ncmd.s.cmd) {
2317 case OCTNET_CMD_CHANGE_DEVFLAGS:
2318 case OCTNET_CMD_SET_MULTI_LIST:
2319 break;
2320
2321 case OCTNET_CMD_CHANGE_MACADDR:
2322 /* If command is successful, change the MACADDR. */
2323 netif_info(lio, probe, lio->netdev, " MACAddr changed to 0x%llx\n",
2324 CVM_CAST64(nctrl->udd[0]));
2325 dev_info(&oct->pci_dev->dev, "%s MACAddr changed to 0x%llx\n",
2326 netdev->name, CVM_CAST64(nctrl->udd[0]));
2327 memcpy(netdev->dev_addr, ((u8 *)&nctrl->udd[0]) + 2, ETH_ALEN);
2328 break;
2329
2330 case OCTNET_CMD_CHANGE_MTU:
2331 /* If command is successful, change the MTU. */
2332 netif_info(lio, probe, lio->netdev, " MTU Changed from %d to %d\n",
2333 netdev->mtu, nctrl->ncmd.s.param2);
2334 dev_info(&oct->pci_dev->dev, "%s MTU Changed from %d to %d\n",
2335 netdev->name, netdev->mtu,
2336 nctrl->ncmd.s.param2);
2337 netdev->mtu = nctrl->ncmd.s.param2;
2338 break;
2339
2340 case OCTNET_CMD_GPIO_ACCESS:
2341 netif_info(lio, probe, lio->netdev, "LED Flashing visual identification\n");
2342
2343 break;
2344
2345 case OCTNET_CMD_LRO_ENABLE:
2346 dev_info(&oct->pci_dev->dev, "%s LRO Enabled\n", netdev->name);
2347 break;
2348
2349 case OCTNET_CMD_LRO_DISABLE:
2350 dev_info(&oct->pci_dev->dev, "%s LRO Disabled\n",
2351 netdev->name);
2352 break;
2353
2354 case OCTNET_CMD_VERBOSE_ENABLE:
2355 dev_info(&oct->pci_dev->dev, "%s LRO Enabled\n", netdev->name);
2356 break;
2357
2358 case OCTNET_CMD_VERBOSE_DISABLE:
2359 dev_info(&oct->pci_dev->dev, "%s LRO Disabled\n",
2360 netdev->name);
2361 break;
2362
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07002363 case OCTNET_CMD_ENABLE_VLAN_FILTER:
2364 dev_info(&oct->pci_dev->dev, "%s VLAN filter enabled\n",
2365 netdev->name);
2366 break;
2367
2368 case OCTNET_CMD_ADD_VLAN_FILTER:
2369 dev_info(&oct->pci_dev->dev, "%s VLAN filter %d added\n",
2370 netdev->name, nctrl->ncmd.s.param1);
2371 break;
2372
2373 case OCTNET_CMD_DEL_VLAN_FILTER:
2374 dev_info(&oct->pci_dev->dev, "%s VLAN filter %d removed\n",
2375 netdev->name, nctrl->ncmd.s.param1);
2376 break;
2377
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002378 case OCTNET_CMD_SET_SETTINGS:
2379 dev_info(&oct->pci_dev->dev, "%s settings changed\n",
2380 netdev->name);
2381
2382 break;
2383
2384 default:
2385 dev_err(&oct->pci_dev->dev, "%s Unknown cmd %d\n", __func__,
2386 nctrl->ncmd.s.cmd);
2387 }
2388}
2389
2390/**
2391 * \brief Converts a mask based on net device flags
2392 * @param netdev network device
2393 *
2394 * This routine generates a octnet_ifflags mask from the net device flags
2395 * received from the OS.
2396 */
2397static inline enum octnet_ifflags get_new_flags(struct net_device *netdev)
2398{
2399 enum octnet_ifflags f = OCTNET_IFFLAG_UNICAST;
2400
2401 if (netdev->flags & IFF_PROMISC)
2402 f |= OCTNET_IFFLAG_PROMISC;
2403
2404 if (netdev->flags & IFF_ALLMULTI)
2405 f |= OCTNET_IFFLAG_ALLMULTI;
2406
2407 if (netdev->flags & IFF_MULTICAST) {
2408 f |= OCTNET_IFFLAG_MULTICAST;
2409
2410 /* Accept all multicast addresses if there are more than we
2411 * can handle
2412 */
2413 if (netdev_mc_count(netdev) > MAX_OCTEON_MULTICAST_ADDR)
2414 f |= OCTNET_IFFLAG_ALLMULTI;
2415 }
2416
2417 if (netdev->flags & IFF_BROADCAST)
2418 f |= OCTNET_IFFLAG_BROADCAST;
2419
2420 return f;
2421}
2422
2423/**
2424 * \brief Net device set_multicast_list
2425 * @param netdev network device
2426 */
2427static void liquidio_set_mcast_list(struct net_device *netdev)
2428{
2429 struct lio *lio = GET_LIO(netdev);
2430 struct octeon_device *oct = lio->oct_dev;
2431 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002432 struct netdev_hw_addr *ha;
2433 u64 *mc;
2434 int ret, i;
2435 int mc_count = min(netdev_mc_count(netdev), MAX_OCTEON_MULTICAST_ADDR);
2436
2437 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2438
2439 /* Create a ctrl pkt command to be sent to core app. */
2440 nctrl.ncmd.u64 = 0;
2441 nctrl.ncmd.s.cmd = OCTNET_CMD_SET_MULTI_LIST;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002442 nctrl.ncmd.s.param1 = get_new_flags(netdev);
2443 nctrl.ncmd.s.param2 = mc_count;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002444 nctrl.ncmd.s.more = mc_count;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002445 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002446 nctrl.netpndev = (u64)netdev;
2447 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2448
2449 /* copy all the addresses into the udd */
2450 i = 0;
2451 mc = &nctrl.udd[0];
2452 netdev_for_each_mc_addr(ha, netdev) {
2453 *mc = 0;
2454 memcpy(((u8 *)mc) + 2, ha->addr, ETH_ALEN);
2455 /* no need to swap bytes */
2456
2457 if (++mc > &nctrl.udd[mc_count])
2458 break;
2459 }
2460
2461 /* Apparently, any activity in this call from the kernel has to
2462 * be atomic. So we won't wait for response.
2463 */
2464 nctrl.wait_time = 0;
2465
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002466 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002467 if (ret < 0) {
2468 dev_err(&oct->pci_dev->dev, "DEVFLAGS change failed in core (ret: 0x%x)\n",
2469 ret);
2470 }
2471}
2472
2473/**
2474 * \brief Net device set_mac_address
2475 * @param netdev network device
2476 */
2477static int liquidio_set_mac(struct net_device *netdev, void *p)
2478{
2479 int ret = 0;
2480 struct lio *lio = GET_LIO(netdev);
2481 struct octeon_device *oct = lio->oct_dev;
2482 struct sockaddr *addr = (struct sockaddr *)p;
2483 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002484
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002485 if (!is_valid_ether_addr(addr->sa_data))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002486 return -EADDRNOTAVAIL;
2487
2488 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2489
2490 nctrl.ncmd.u64 = 0;
2491 nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002492 nctrl.ncmd.s.param1 = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002493 nctrl.ncmd.s.more = 1;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002494 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002495 nctrl.netpndev = (u64)netdev;
2496 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2497 nctrl.wait_time = 100;
2498
2499 nctrl.udd[0] = 0;
2500 /* The MAC Address is presented in network byte order. */
2501 memcpy((u8 *)&nctrl.udd[0] + 2, addr->sa_data, ETH_ALEN);
2502
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002503 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002504 if (ret < 0) {
2505 dev_err(&oct->pci_dev->dev, "MAC Address change failed\n");
2506 return -ENOMEM;
2507 }
2508 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2509 memcpy(((u8 *)&lio->linfo.hw_addr) + 2, addr->sa_data, ETH_ALEN);
2510
2511 return 0;
2512}
2513
2514/**
2515 * \brief Net device get_stats
2516 * @param netdev network device
2517 */
2518static struct net_device_stats *liquidio_get_stats(struct net_device *netdev)
2519{
2520 struct lio *lio = GET_LIO(netdev);
2521 struct net_device_stats *stats = &netdev->stats;
2522 struct octeon_device *oct;
2523 u64 pkts = 0, drop = 0, bytes = 0;
2524 struct oct_droq_stats *oq_stats;
2525 struct oct_iq_stats *iq_stats;
2526 int i, iq_no, oq_no;
2527
2528 oct = lio->oct_dev;
2529
2530 for (i = 0; i < lio->linfo.num_txpciq; i++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002531 iq_no = lio->linfo.txpciq[i].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002532 iq_stats = &oct->instr_queue[iq_no]->stats;
2533 pkts += iq_stats->tx_done;
2534 drop += iq_stats->tx_dropped;
2535 bytes += iq_stats->tx_tot_bytes;
2536 }
2537
2538 stats->tx_packets = pkts;
2539 stats->tx_bytes = bytes;
2540 stats->tx_dropped = drop;
2541
2542 pkts = 0;
2543 drop = 0;
2544 bytes = 0;
2545
2546 for (i = 0; i < lio->linfo.num_rxpciq; i++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002547 oq_no = lio->linfo.rxpciq[i].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002548 oq_stats = &oct->droq[oq_no]->stats;
2549 pkts += oq_stats->rx_pkts_received;
2550 drop += (oq_stats->rx_dropped +
2551 oq_stats->dropped_nodispatch +
2552 oq_stats->dropped_toomany +
2553 oq_stats->dropped_nomem);
2554 bytes += oq_stats->rx_bytes_received;
2555 }
2556
2557 stats->rx_bytes = bytes;
2558 stats->rx_packets = pkts;
2559 stats->rx_dropped = drop;
2560
2561 return stats;
2562}
2563
2564/**
2565 * \brief Net device change_mtu
2566 * @param netdev network device
2567 */
2568static int liquidio_change_mtu(struct net_device *netdev, int new_mtu)
2569{
2570 struct lio *lio = GET_LIO(netdev);
2571 struct octeon_device *oct = lio->oct_dev;
2572 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002573 int max_frm_size = new_mtu + OCTNET_FRM_HEADER_SIZE;
2574 int ret = 0;
2575
2576 /* Limit the MTU to make sure the ethernet packets are between 64 bytes
2577 * and 65535 bytes
2578 */
2579 if ((max_frm_size < OCTNET_MIN_FRM_SIZE) ||
2580 (max_frm_size > OCTNET_MAX_FRM_SIZE)) {
2581 dev_err(&oct->pci_dev->dev, "Invalid MTU: %d\n", new_mtu);
2582 dev_err(&oct->pci_dev->dev, "Valid range %d and %d\n",
2583 (OCTNET_MIN_FRM_SIZE - OCTNET_FRM_HEADER_SIZE),
2584 (OCTNET_MAX_FRM_SIZE - OCTNET_FRM_HEADER_SIZE));
2585 return -EINVAL;
2586 }
2587
2588 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2589
2590 nctrl.ncmd.u64 = 0;
2591 nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MTU;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002592 nctrl.ncmd.s.param1 = new_mtu;
2593 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002594 nctrl.wait_time = 100;
2595 nctrl.netpndev = (u64)netdev;
2596 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2597
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002598 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002599 if (ret < 0) {
2600 dev_err(&oct->pci_dev->dev, "Failed to set MTU\n");
2601 return -1;
2602 }
2603
2604 lio->mtu = new_mtu;
2605
2606 return 0;
2607}
2608
2609/**
2610 * \brief Handler for SIOCSHWTSTAMP ioctl
2611 * @param netdev network device
2612 * @param ifr interface request
2613 * @param cmd command
2614 */
2615static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2616{
2617 struct hwtstamp_config conf;
2618 struct lio *lio = GET_LIO(netdev);
2619
2620 if (copy_from_user(&conf, ifr->ifr_data, sizeof(conf)))
2621 return -EFAULT;
2622
2623 if (conf.flags)
2624 return -EINVAL;
2625
2626 switch (conf.tx_type) {
2627 case HWTSTAMP_TX_ON:
2628 case HWTSTAMP_TX_OFF:
2629 break;
2630 default:
2631 return -ERANGE;
2632 }
2633
2634 switch (conf.rx_filter) {
2635 case HWTSTAMP_FILTER_NONE:
2636 break;
2637 case HWTSTAMP_FILTER_ALL:
2638 case HWTSTAMP_FILTER_SOME:
2639 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2640 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2641 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2642 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2643 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2644 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2645 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2646 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2647 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2648 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2649 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2650 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
2651 conf.rx_filter = HWTSTAMP_FILTER_ALL;
2652 break;
2653 default:
2654 return -ERANGE;
2655 }
2656
2657 if (conf.rx_filter == HWTSTAMP_FILTER_ALL)
2658 ifstate_set(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
2659
2660 else
2661 ifstate_reset(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
2662
2663 return copy_to_user(ifr->ifr_data, &conf, sizeof(conf)) ? -EFAULT : 0;
2664}
2665
2666/**
2667 * \brief ioctl handler
2668 * @param netdev network device
2669 * @param ifr interface request
2670 * @param cmd command
2671 */
2672static int liquidio_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2673{
2674 switch (cmd) {
2675 case SIOCSHWTSTAMP:
2676 return hwtstamp_ioctl(netdev, ifr, cmd);
2677 default:
2678 return -EOPNOTSUPP;
2679 }
2680}
2681
2682/**
2683 * \brief handle a Tx timestamp response
2684 * @param status response status
2685 * @param buf pointer to skb
2686 */
2687static void handle_timestamp(struct octeon_device *oct,
2688 u32 status,
2689 void *buf)
2690{
2691 struct octnet_buf_free_info *finfo;
2692 struct octeon_soft_command *sc;
2693 struct oct_timestamp_resp *resp;
2694 struct lio *lio;
2695 struct sk_buff *skb = (struct sk_buff *)buf;
2696
2697 finfo = (struct octnet_buf_free_info *)skb->cb;
2698 lio = finfo->lio;
2699 sc = finfo->sc;
2700 oct = lio->oct_dev;
2701 resp = (struct oct_timestamp_resp *)sc->virtrptr;
2702
2703 if (status != OCTEON_REQUEST_DONE) {
2704 dev_err(&oct->pci_dev->dev, "Tx timestamp instruction failed. Status: %llx\n",
2705 CVM_CAST64(status));
2706 resp->timestamp = 0;
2707 }
2708
2709 octeon_swap_8B_data(&resp->timestamp, 1);
2710
Colin Ian King19a6d152016-02-05 16:30:39 +00002711 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) != 0)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002712 struct skb_shared_hwtstamps ts;
2713 u64 ns = resp->timestamp;
2714
2715 netif_info(lio, tx_done, lio->netdev,
2716 "Got resulting SKBTX_HW_TSTAMP skb=%p ns=%016llu\n",
2717 skb, (unsigned long long)ns);
2718 ts.hwtstamp = ns_to_ktime(ns + lio->ptp_adjust);
2719 skb_tstamp_tx(skb, &ts);
2720 }
2721
2722 octeon_free_soft_command(oct, sc);
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07002723 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002724}
2725
2726/* \brief Send a data packet that will be timestamped
2727 * @param oct octeon device
2728 * @param ndata pointer to network data
2729 * @param finfo pointer to private network data
2730 */
2731static inline int send_nic_timestamp_pkt(struct octeon_device *oct,
2732 struct octnic_data_pkt *ndata,
2733 struct octnet_buf_free_info *finfo,
2734 int xmit_more)
2735{
2736 int retval;
2737 struct octeon_soft_command *sc;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002738 struct lio *lio;
2739 int ring_doorbell;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002740 u32 len;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002741
2742 lio = finfo->lio;
2743
2744 sc = octeon_alloc_soft_command_resp(oct, &ndata->cmd,
2745 sizeof(struct oct_timestamp_resp));
2746 finfo->sc = sc;
2747
2748 if (!sc) {
2749 dev_err(&oct->pci_dev->dev, "No memory for timestamped data packet\n");
2750 return IQ_SEND_FAILED;
2751 }
2752
2753 if (ndata->reqtype == REQTYPE_NORESP_NET)
2754 ndata->reqtype = REQTYPE_RESP_NET;
2755 else if (ndata->reqtype == REQTYPE_NORESP_NET_SG)
2756 ndata->reqtype = REQTYPE_RESP_NET_SG;
2757
2758 sc->callback = handle_timestamp;
2759 sc->callback_arg = finfo->skb;
2760 sc->iq_no = ndata->q_no;
2761
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002762 len = (u32)((struct octeon_instr_ih2 *)(&sc->cmd.cmd2.ih2))->dlengsz;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002763
2764 ring_doorbell = !xmit_more;
2765 retval = octeon_send_command(oct, sc->iq_no, ring_doorbell, &sc->cmd,
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002766 sc, len, ndata->reqtype);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002767
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -07002768 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002769 dev_err(&oct->pci_dev->dev, "timestamp data packet failed status: %x\n",
2770 retval);
2771 octeon_free_soft_command(oct, sc);
2772 } else {
2773 netif_info(lio, tx_queued, lio->netdev, "Queued timestamp packet\n");
2774 }
2775
2776 return retval;
2777}
2778
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002779/** \brief Transmit networks packets to the Octeon interface
2780 * @param skbuff skbuff struct to be passed to network layer.
2781 * @param netdev pointer to network device
2782 * @returns whether the packet was transmitted to the device okay or not
2783 * (NETDEV_TX_OK or NETDEV_TX_BUSY)
2784 */
2785static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
2786{
2787 struct lio *lio;
2788 struct octnet_buf_free_info *finfo;
2789 union octnic_cmd_setup cmdsetup;
2790 struct octnic_data_pkt ndata;
2791 struct octeon_device *oct;
2792 struct oct_iq_stats *stats;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002793 struct octeon_instr_irh *irh;
2794 union tx_info *tx_info;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002795 int status = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002796 int q_idx = 0, iq_no = 0;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002797 int xmit_more, j;
2798 u64 dptr = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002799 u32 tag = 0;
2800
2801 lio = GET_LIO(netdev);
2802 oct = lio->oct_dev;
2803
2804 if (netif_is_multiqueue(netdev)) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002805 q_idx = skb->queue_mapping;
2806 q_idx = (q_idx % (lio->linfo.num_txpciq));
2807 tag = q_idx;
2808 iq_no = lio->linfo.txpciq[q_idx].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002809 } else {
2810 iq_no = lio->txq;
2811 }
2812
2813 stats = &oct->instr_queue[iq_no]->stats;
2814
2815 /* Check for all conditions in which the current packet cannot be
2816 * transmitted.
2817 */
2818 if (!(atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING) ||
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002819 (!lio->linfo.link.s.link_up) ||
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002820 (skb->len <= 0)) {
2821 netif_info(lio, tx_err, lio->netdev,
2822 "Transmit failed link_status : %d\n",
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002823 lio->linfo.link.s.link_up);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002824 goto lio_xmit_failed;
2825 }
2826
2827 /* Use space in skb->cb to store info used to unmap and
2828 * free the buffers.
2829 */
2830 finfo = (struct octnet_buf_free_info *)skb->cb;
2831 finfo->lio = lio;
2832 finfo->skb = skb;
2833 finfo->sc = NULL;
2834
2835 /* Prepare the attributes for the data to be passed to OSI. */
2836 memset(&ndata, 0, sizeof(struct octnic_data_pkt));
2837
2838 ndata.buf = (void *)finfo;
2839
2840 ndata.q_no = iq_no;
2841
2842 if (netif_is_multiqueue(netdev)) {
2843 if (octnet_iq_is_full(oct, ndata.q_no)) {
2844 /* defer sending if queue is full */
2845 netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
2846 ndata.q_no);
2847 stats->tx_iq_busy++;
2848 return NETDEV_TX_BUSY;
2849 }
2850 } else {
2851 if (octnet_iq_is_full(oct, lio->txq)) {
2852 /* defer sending if queue is full */
2853 stats->tx_iq_busy++;
2854 netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
2855 ndata.q_no);
2856 return NETDEV_TX_BUSY;
2857 }
2858 }
2859 /* pr_info(" XMIT - valid Qs: %d, 1st Q no: %d, cpu: %d, q_no:%d\n",
2860 * lio->linfo.num_txpciq, lio->txq, cpu, ndata.q_no );
2861 */
2862
2863 ndata.datasize = skb->len;
2864
2865 cmdsetup.u64 = 0;
Raghu Vatsavayi7275ebf2016-06-14 16:54:49 -07002866 cmdsetup.s.iq_no = iq_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002867
Raghu Vatsavayi7275ebf2016-06-14 16:54:49 -07002868 if (skb->ip_summed == CHECKSUM_PARTIAL)
2869 cmdsetup.s.transport_csum = 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002870
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002871 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
2872 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
2873 cmdsetup.s.timestamp = 1;
2874 }
2875
2876 if (skb_shinfo(skb)->nr_frags == 0) {
2877 cmdsetup.s.u.datasize = skb->len;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002878 octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002879 /* Offload checksum calculation for TCP/UDP packets */
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002880 dptr = dma_map_single(&oct->pci_dev->dev,
2881 skb->data,
2882 skb->len,
2883 DMA_TO_DEVICE);
2884 if (dma_mapping_error(&oct->pci_dev->dev, dptr)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002885 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 1\n",
2886 __func__);
2887 return NETDEV_TX_BUSY;
2888 }
2889
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002890 ndata.cmd.cmd2.dptr = dptr;
2891 finfo->dptr = dptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002892 ndata.reqtype = REQTYPE_NORESP_NET;
2893
2894 } else {
2895 int i, frags;
2896 struct skb_frag_struct *frag;
2897 struct octnic_gather *g;
2898
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002899 spin_lock(&lio->glist_lock[q_idx]);
2900 g = (struct octnic_gather *)
2901 list_delete_head(&lio->glist[q_idx]);
2902 spin_unlock(&lio->glist_lock[q_idx]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002903
2904 if (!g) {
2905 netif_info(lio, tx_err, lio->netdev,
2906 "Transmit scatter gather: glist null!\n");
2907 goto lio_xmit_failed;
2908 }
2909
2910 cmdsetup.s.gather = 1;
2911 cmdsetup.s.u.gatherptrs = (skb_shinfo(skb)->nr_frags + 1);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002912 octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002913
2914 memset(g->sg, 0, g->sg_size);
2915
2916 g->sg[0].ptr[0] = dma_map_single(&oct->pci_dev->dev,
2917 skb->data,
2918 (skb->len - skb->data_len),
2919 DMA_TO_DEVICE);
2920 if (dma_mapping_error(&oct->pci_dev->dev, g->sg[0].ptr[0])) {
2921 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 2\n",
2922 __func__);
2923 return NETDEV_TX_BUSY;
2924 }
2925 add_sg_size(&g->sg[0], (skb->len - skb->data_len), 0);
2926
2927 frags = skb_shinfo(skb)->nr_frags;
2928 i = 1;
2929 while (frags--) {
2930 frag = &skb_shinfo(skb)->frags[i - 1];
2931
2932 g->sg[(i >> 2)].ptr[(i & 3)] =
2933 dma_map_page(&oct->pci_dev->dev,
2934 frag->page.p,
2935 frag->page_offset,
2936 frag->size,
2937 DMA_TO_DEVICE);
2938
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002939 if (dma_mapping_error(&oct->pci_dev->dev,
2940 g->sg[i >> 2].ptr[i & 3])) {
2941 dma_unmap_single(&oct->pci_dev->dev,
2942 g->sg[0].ptr[0],
2943 skb->len - skb->data_len,
2944 DMA_TO_DEVICE);
2945 for (j = 1; j < i; j++) {
2946 frag = &skb_shinfo(skb)->frags[j - 1];
2947 dma_unmap_page(&oct->pci_dev->dev,
2948 g->sg[j >> 2].ptr[j & 3],
2949 frag->size,
2950 DMA_TO_DEVICE);
2951 }
2952 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 3\n",
2953 __func__);
2954 return NETDEV_TX_BUSY;
2955 }
2956
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002957 add_sg_size(&g->sg[(i >> 2)], frag->size, (i & 3));
2958 i++;
2959 }
2960
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002961 dma_sync_single_for_device(&oct->pci_dev->dev, g->sg_dma_ptr,
2962 g->sg_size, DMA_TO_DEVICE);
2963 dptr = g->sg_dma_ptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002964
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002965 ndata.cmd.cmd2.dptr = dptr;
2966 finfo->dptr = dptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002967 finfo->g = g;
2968
2969 ndata.reqtype = REQTYPE_NORESP_NET_SG;
2970 }
2971
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002972 irh = (struct octeon_instr_irh *)&ndata.cmd.cmd2.irh;
2973 tx_info = (union tx_info *)&ndata.cmd.cmd2.ossp[0];
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002974
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002975 if (skb_shinfo(skb)->gso_size) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002976 tx_info->s.gso_size = skb_shinfo(skb)->gso_size;
2977 tx_info->s.gso_segs = skb_shinfo(skb)->gso_segs;
2978 }
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07002979 /* HW insert VLAN tag */
2980 if (skb_vlan_tag_present(skb)) {
2981 irh->priority = skb_vlan_tag_get(skb) >> 13;
2982 irh->vlan = skb_vlan_tag_get(skb) & 0xfff;
2983 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002984
2985 xmit_more = skb->xmit_more;
2986
2987 if (unlikely(cmdsetup.s.timestamp))
2988 status = send_nic_timestamp_pkt(oct, &ndata, finfo, xmit_more);
2989 else
2990 status = octnet_send_nic_data_pkt(oct, &ndata, xmit_more);
2991 if (status == IQ_SEND_FAILED)
2992 goto lio_xmit_failed;
2993
2994 netif_info(lio, tx_queued, lio->netdev, "Transmit queued successfully\n");
2995
2996 if (status == IQ_SEND_STOP)
2997 stop_q(lio->netdev, q_idx);
2998
Florian Westphal860e9532016-05-03 16:33:13 +02002999 netif_trans_update(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003000
3001 stats->tx_done++;
3002 stats->tx_tot_bytes += skb->len;
3003
3004 return NETDEV_TX_OK;
3005
3006lio_xmit_failed:
3007 stats->tx_dropped++;
3008 netif_info(lio, tx_err, lio->netdev, "IQ%d Transmit dropped:%llu\n",
3009 iq_no, stats->tx_dropped);
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07003010 if (dptr)
3011 dma_unmap_single(&oct->pci_dev->dev, dptr,
3012 ndata.datasize, DMA_TO_DEVICE);
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07003013 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003014 return NETDEV_TX_OK;
3015}
3016
3017/** \brief Network device Tx timeout
3018 * @param netdev pointer to network device
3019 */
3020static void liquidio_tx_timeout(struct net_device *netdev)
3021{
3022 struct lio *lio;
3023
3024 lio = GET_LIO(netdev);
3025
3026 netif_info(lio, tx_err, lio->netdev,
3027 "Transmit timeout tx_dropped:%ld, waking up queues now!!\n",
3028 netdev->stats.tx_dropped);
Florian Westphal860e9532016-05-03 16:33:13 +02003029 netif_trans_update(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003030 txqs_wake(netdev);
3031}
3032
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003033static int liquidio_vlan_rx_add_vid(struct net_device *netdev,
3034 __be16 proto __attribute__((unused)),
3035 u16 vid)
3036{
3037 struct lio *lio = GET_LIO(netdev);
3038 struct octeon_device *oct = lio->oct_dev;
3039 struct octnic_ctrl_pkt nctrl;
3040 int ret = 0;
3041
3042 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3043
3044 nctrl.ncmd.u64 = 0;
3045 nctrl.ncmd.s.cmd = OCTNET_CMD_ADD_VLAN_FILTER;
3046 nctrl.ncmd.s.param1 = vid;
3047 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3048 nctrl.wait_time = 100;
3049 nctrl.netpndev = (u64)netdev;
3050 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
3051
3052 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
3053 if (ret < 0) {
3054 dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
3055 ret);
3056 }
3057
3058 return ret;
3059}
3060
3061static int liquidio_vlan_rx_kill_vid(struct net_device *netdev,
3062 __be16 proto __attribute__((unused)),
3063 u16 vid)
3064{
3065 struct lio *lio = GET_LIO(netdev);
3066 struct octeon_device *oct = lio->oct_dev;
3067 struct octnic_ctrl_pkt nctrl;
3068 int ret = 0;
3069
3070 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3071
3072 nctrl.ncmd.u64 = 0;
3073 nctrl.ncmd.s.cmd = OCTNET_CMD_DEL_VLAN_FILTER;
3074 nctrl.ncmd.s.param1 = vid;
3075 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3076 nctrl.wait_time = 100;
3077 nctrl.netpndev = (u64)netdev;
3078 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
3079
3080 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
3081 if (ret < 0) {
3082 dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
3083 ret);
3084 }
3085 return ret;
3086}
3087
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003088int liquidio_set_feature(struct net_device *netdev, int cmd, u16 param1)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003089{
3090 struct lio *lio = GET_LIO(netdev);
3091 struct octeon_device *oct = lio->oct_dev;
3092 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003093 int ret = 0;
3094
3095 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3096
3097 nctrl.ncmd.u64 = 0;
3098 nctrl.ncmd.s.cmd = cmd;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003099 nctrl.ncmd.s.param1 = param1;
3100 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003101 nctrl.wait_time = 100;
3102 nctrl.netpndev = (u64)netdev;
3103 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
3104
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003105 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003106 if (ret < 0) {
3107 dev_err(&oct->pci_dev->dev, "Feature change failed in core (ret: 0x%x)\n",
3108 ret);
3109 }
3110 return ret;
3111}
3112
3113/** \brief Net device fix features
3114 * @param netdev pointer to network device
3115 * @param request features requested
3116 * @returns updated features list
3117 */
3118static netdev_features_t liquidio_fix_features(struct net_device *netdev,
3119 netdev_features_t request)
3120{
3121 struct lio *lio = netdev_priv(netdev);
3122
3123 if ((request & NETIF_F_RXCSUM) &&
3124 !(lio->dev_capability & NETIF_F_RXCSUM))
3125 request &= ~NETIF_F_RXCSUM;
3126
3127 if ((request & NETIF_F_HW_CSUM) &&
3128 !(lio->dev_capability & NETIF_F_HW_CSUM))
3129 request &= ~NETIF_F_HW_CSUM;
3130
3131 if ((request & NETIF_F_TSO) && !(lio->dev_capability & NETIF_F_TSO))
3132 request &= ~NETIF_F_TSO;
3133
3134 if ((request & NETIF_F_TSO6) && !(lio->dev_capability & NETIF_F_TSO6))
3135 request &= ~NETIF_F_TSO6;
3136
3137 if ((request & NETIF_F_LRO) && !(lio->dev_capability & NETIF_F_LRO))
3138 request &= ~NETIF_F_LRO;
3139
3140 /*Disable LRO if RXCSUM is off */
3141 if (!(request & NETIF_F_RXCSUM) && (netdev->features & NETIF_F_LRO) &&
3142 (lio->dev_capability & NETIF_F_LRO))
3143 request &= ~NETIF_F_LRO;
3144
3145 return request;
3146}
3147
3148/** \brief Net device set features
3149 * @param netdev pointer to network device
3150 * @param features features to enable/disable
3151 */
3152static int liquidio_set_features(struct net_device *netdev,
3153 netdev_features_t features)
3154{
3155 struct lio *lio = netdev_priv(netdev);
3156
3157 if (!((netdev->features ^ features) & NETIF_F_LRO))
3158 return 0;
3159
3160 if ((features & NETIF_F_LRO) && (lio->dev_capability & NETIF_F_LRO))
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003161 liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE,
3162 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003163 else if (!(features & NETIF_F_LRO) &&
3164 (lio->dev_capability & NETIF_F_LRO))
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003165 liquidio_set_feature(netdev, OCTNET_CMD_LRO_DISABLE,
3166 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003167
3168 return 0;
3169}
3170
3171static struct net_device_ops lionetdevops = {
3172 .ndo_open = liquidio_open,
3173 .ndo_stop = liquidio_stop,
3174 .ndo_start_xmit = liquidio_xmit,
3175 .ndo_get_stats = liquidio_get_stats,
3176 .ndo_set_mac_address = liquidio_set_mac,
3177 .ndo_set_rx_mode = liquidio_set_mcast_list,
3178 .ndo_tx_timeout = liquidio_tx_timeout,
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003179
3180 .ndo_vlan_rx_add_vid = liquidio_vlan_rx_add_vid,
3181 .ndo_vlan_rx_kill_vid = liquidio_vlan_rx_kill_vid,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003182 .ndo_change_mtu = liquidio_change_mtu,
3183 .ndo_do_ioctl = liquidio_ioctl,
3184 .ndo_fix_features = liquidio_fix_features,
3185 .ndo_set_features = liquidio_set_features,
3186};
3187
3188/** \brief Entry point for the liquidio module
3189 */
3190static int __init liquidio_init(void)
3191{
3192 int i;
3193 struct handshake *hs;
3194
3195 init_completion(&first_stage);
3196
3197 octeon_init_device_list(conf_type);
3198
3199 if (liquidio_init_pci())
3200 return -EINVAL;
3201
3202 wait_for_completion_timeout(&first_stage, msecs_to_jiffies(1000));
3203
3204 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
3205 hs = &handshake[i];
3206 if (hs->pci_dev) {
3207 wait_for_completion(&hs->init);
3208 if (!hs->init_ok) {
3209 /* init handshake failed */
3210 dev_err(&hs->pci_dev->dev,
3211 "Failed to init device\n");
3212 liquidio_deinit_pci();
3213 return -EIO;
3214 }
3215 }
3216 }
3217
3218 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
3219 hs = &handshake[i];
3220 if (hs->pci_dev) {
3221 wait_for_completion_timeout(&hs->started,
3222 msecs_to_jiffies(30000));
3223 if (!hs->started_ok) {
3224 /* starter handshake failed */
3225 dev_err(&hs->pci_dev->dev,
3226 "Firmware failed to start\n");
3227 liquidio_deinit_pci();
3228 return -EIO;
3229 }
3230 }
3231 }
3232
3233 return 0;
3234}
3235
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07003236static int lio_nic_info(struct octeon_recv_info *recv_info, void *buf)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003237{
3238 struct octeon_device *oct = (struct octeon_device *)buf;
3239 struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003240 int gmxport = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003241 union oct_link_status *ls;
3242 int i;
3243
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003244 if (recv_pkt->buffer_size[0] != sizeof(*ls)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003245 dev_err(&oct->pci_dev->dev, "Malformed NIC_INFO, len=%d, ifidx=%d\n",
3246 recv_pkt->buffer_size[0],
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003247 recv_pkt->rh.r_nic_info.gmxport);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003248 goto nic_info_err;
3249 }
3250
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003251 gmxport = recv_pkt->rh.r_nic_info.gmxport;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003252 ls = (union oct_link_status *)get_rbd(recv_pkt->buffer_ptr[0]);
3253
3254 octeon_swap_8B_data((u64 *)ls, (sizeof(union oct_link_status)) >> 3);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003255 for (i = 0; i < oct->ifcount; i++) {
3256 if (oct->props[i].gmxport == gmxport) {
3257 update_link_status(oct->props[i].netdev, ls);
3258 break;
3259 }
3260 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003261
3262nic_info_err:
3263 for (i = 0; i < recv_pkt->buffer_count; i++)
3264 recv_buffer_free(recv_pkt->buffer_ptr[i]);
3265 octeon_free_recv_info(recv_info);
3266 return 0;
3267}
3268
3269/**
3270 * \brief Setup network interfaces
3271 * @param octeon_dev octeon device
3272 *
3273 * Called during init time for each device. It assumes the NIC
3274 * is already up and running. The link information for each
3275 * interface is passed in link_info.
3276 */
3277static int setup_nic_devices(struct octeon_device *octeon_dev)
3278{
3279 struct lio *lio = NULL;
3280 struct net_device *netdev;
3281 u8 mac[6], i, j;
3282 struct octeon_soft_command *sc;
3283 struct liquidio_if_cfg_context *ctx;
3284 struct liquidio_if_cfg_resp *resp;
3285 struct octdev_props *props;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003286 int retval, num_iqueues, num_oqueues;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003287 int num_cpus = num_online_cpus();
3288 union oct_nic_if_cfg if_cfg;
3289 unsigned int base_queue;
3290 unsigned int gmx_port_id;
3291 u32 resp_size, ctx_size;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003292 u32 ifidx_or_pfnum;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003293
3294 /* This is to handle link status changes */
3295 octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
3296 OPCODE_NIC_INFO,
3297 lio_nic_info, octeon_dev);
3298
3299 /* REQTYPE_RESP_NET and REQTYPE_SOFT_COMMAND do not have free functions.
3300 * They are handled directly.
3301 */
3302 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET,
3303 free_netbuf);
3304
3305 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET_SG,
3306 free_netsgbuf);
3307
3308 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_RESP_NET_SG,
3309 free_netsgbuf_with_resp);
3310
3311 for (i = 0; i < octeon_dev->ifcount; i++) {
3312 resp_size = sizeof(struct liquidio_if_cfg_resp);
3313 ctx_size = sizeof(struct liquidio_if_cfg_context);
3314 sc = (struct octeon_soft_command *)
3315 octeon_alloc_soft_command(octeon_dev, 0,
3316 resp_size, ctx_size);
3317 resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
3318 ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
3319
3320 num_iqueues =
3321 CFG_GET_NUM_TXQS_NIC_IF(octeon_get_conf(octeon_dev), i);
3322 num_oqueues =
3323 CFG_GET_NUM_RXQS_NIC_IF(octeon_get_conf(octeon_dev), i);
3324 base_queue =
3325 CFG_GET_BASE_QUE_NIC_IF(octeon_get_conf(octeon_dev), i);
3326 gmx_port_id =
3327 CFG_GET_GMXID_NIC_IF(octeon_get_conf(octeon_dev), i);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003328 ifidx_or_pfnum = i;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003329 if (num_iqueues > num_cpus)
3330 num_iqueues = num_cpus;
3331 if (num_oqueues > num_cpus)
3332 num_oqueues = num_cpus;
3333 dev_dbg(&octeon_dev->pci_dev->dev,
3334 "requesting config for interface %d, iqs %d, oqs %d\n",
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003335 ifidx_or_pfnum, num_iqueues, num_oqueues);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003336 ACCESS_ONCE(ctx->cond) = 0;
3337 ctx->octeon_id = lio_get_device_id(octeon_dev);
3338 init_waitqueue_head(&ctx->wc);
3339
3340 if_cfg.u64 = 0;
3341 if_cfg.s.num_iqueues = num_iqueues;
3342 if_cfg.s.num_oqueues = num_oqueues;
3343 if_cfg.s.base_queue = base_queue;
3344 if_cfg.s.gmx_port_id = gmx_port_id;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003345
3346 sc->iq_no = 0;
3347
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003348 octeon_prepare_soft_command(octeon_dev, sc, OPCODE_NIC,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003349 OPCODE_NIC_IF_CFG, 0,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003350 if_cfg.u64, 0);
3351
3352 sc->callback = if_cfg_callback;
3353 sc->callback_arg = sc;
3354 sc->wait_time = 1000;
3355
3356 retval = octeon_send_soft_command(octeon_dev, sc);
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -07003357 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003358 dev_err(&octeon_dev->pci_dev->dev,
3359 "iq/oq config failed status: %x\n",
3360 retval);
3361 /* Soft instr is freed by driver in case of failure. */
3362 goto setup_nic_dev_fail;
3363 }
3364
3365 /* Sleep on a wait queue till the cond flag indicates that the
3366 * response arrived or timed-out.
3367 */
3368 sleep_cond(&ctx->wc, &ctx->cond);
3369 retval = resp->status;
3370 if (retval) {
3371 dev_err(&octeon_dev->pci_dev->dev, "iq/oq config failed\n");
3372 goto setup_nic_dev_fail;
3373 }
3374
3375 octeon_swap_8B_data((u64 *)(&resp->cfg_info),
3376 (sizeof(struct liquidio_if_cfg_info)) >> 3);
3377
3378 num_iqueues = hweight64(resp->cfg_info.iqmask);
3379 num_oqueues = hweight64(resp->cfg_info.oqmask);
3380
3381 if (!(num_iqueues) || !(num_oqueues)) {
3382 dev_err(&octeon_dev->pci_dev->dev,
3383 "Got bad iqueues (%016llx) or oqueues (%016llx) from firmware.\n",
3384 resp->cfg_info.iqmask,
3385 resp->cfg_info.oqmask);
3386 goto setup_nic_dev_fail;
3387 }
3388 dev_dbg(&octeon_dev->pci_dev->dev,
3389 "interface %d, iqmask %016llx, oqmask %016llx, numiqueues %d, numoqueues %d\n",
3390 i, resp->cfg_info.iqmask, resp->cfg_info.oqmask,
3391 num_iqueues, num_oqueues);
3392 netdev = alloc_etherdev_mq(LIO_SIZE, num_iqueues);
3393
3394 if (!netdev) {
3395 dev_err(&octeon_dev->pci_dev->dev, "Device allocation failed\n");
3396 goto setup_nic_dev_fail;
3397 }
3398
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003399 SET_NETDEV_DEV(netdev, &octeon_dev->pci_dev->dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003400
3401 if (num_iqueues > 1)
3402 lionetdevops.ndo_select_queue = select_q;
3403
3404 /* Associate the routines that will handle different
3405 * netdev tasks.
3406 */
3407 netdev->netdev_ops = &lionetdevops;
3408
3409 lio = GET_LIO(netdev);
3410
3411 memset(lio, 0, sizeof(struct lio));
3412
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003413 lio->ifidx = ifidx_or_pfnum;
3414
3415 props = &octeon_dev->props[i];
3416 props->gmxport = resp->cfg_info.linfo.gmxport;
3417 props->netdev = netdev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003418
3419 lio->linfo.num_rxpciq = num_oqueues;
3420 lio->linfo.num_txpciq = num_iqueues;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003421 for (j = 0; j < num_oqueues; j++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003422 lio->linfo.rxpciq[j].u64 =
3423 resp->cfg_info.linfo.rxpciq[j].u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003424 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003425 for (j = 0; j < num_iqueues; j++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003426 lio->linfo.txpciq[j].u64 =
3427 resp->cfg_info.linfo.txpciq[j].u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003428 }
3429 lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
3430 lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
3431 lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
3432
3433 lio->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
3434
3435 lio->dev_capability = NETIF_F_HIGHDMA
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003436 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
3437 | NETIF_F_SG | NETIF_F_RXCSUM
3438 | NETIF_F_GRO
3439 | NETIF_F_TSO | NETIF_F_TSO6
3440 | NETIF_F_LRO;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003441 netif_set_gso_max_size(netdev, OCTNIC_GSO_MAX_SIZE);
3442
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003443 netdev->vlan_features = lio->dev_capability;
3444 /* Add any unchangeable hw features */
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003445 lio->dev_capability |= NETIF_F_HW_VLAN_CTAG_FILTER |
3446 NETIF_F_HW_VLAN_CTAG_RX |
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003447 NETIF_F_HW_VLAN_CTAG_TX;
3448
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003449 netdev->features = (lio->dev_capability & ~NETIF_F_LRO);
3450
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003451 netdev->hw_features = lio->dev_capability;
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003452 /*HW_VLAN_RX and HW_VLAN_FILTER is always on*/
3453 netdev->hw_features = netdev->hw_features &
3454 ~NETIF_F_HW_VLAN_CTAG_RX;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003455
3456 /* Point to the properties for octeon device to which this
3457 * interface belongs.
3458 */
3459 lio->oct_dev = octeon_dev;
3460 lio->octprops = props;
3461 lio->netdev = netdev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003462
3463 dev_dbg(&octeon_dev->pci_dev->dev,
3464 "if%d gmx: %d hw_addr: 0x%llx\n", i,
3465 lio->linfo.gmxport, CVM_CAST64(lio->linfo.hw_addr));
3466
3467 /* 64-bit swap required on LE machines */
3468 octeon_swap_8B_data(&lio->linfo.hw_addr, 1);
3469 for (j = 0; j < 6; j++)
3470 mac[j] = *((u8 *)(((u8 *)&lio->linfo.hw_addr) + 2 + j));
3471
3472 /* Copy MAC Address to OS network device structure */
3473
3474 ether_addr_copy(netdev->dev_addr, mac);
3475
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003476 /* By default all interfaces on a single Octeon uses the same
3477 * tx and rx queues
3478 */
3479 lio->txq = lio->linfo.txpciq[0].s.q_no;
3480 lio->rxq = lio->linfo.rxpciq[0].s.q_no;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003481 if (setup_io_queues(octeon_dev, i)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003482 dev_err(&octeon_dev->pci_dev->dev, "I/O queues creation failed\n");
3483 goto setup_nic_dev_fail;
3484 }
3485
3486 ifstate_set(lio, LIO_IFSTATE_DROQ_OPS);
3487
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003488 lio->tx_qsize = octeon_get_tx_qsize(octeon_dev, lio->txq);
3489 lio->rx_qsize = octeon_get_rx_qsize(octeon_dev, lio->rxq);
3490
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07003491 if (setup_glists(octeon_dev, lio, num_iqueues)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003492 dev_err(&octeon_dev->pci_dev->dev,
3493 "Gather list allocation failed\n");
3494 goto setup_nic_dev_fail;
3495 }
3496
3497 /* Register ethtool support */
3498 liquidio_set_ethtool_ops(netdev);
3499
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003500 if (netdev->features & NETIF_F_LRO)
3501 liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE,
3502 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003503
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003504 liquidio_set_feature(netdev, OCTNET_CMD_ENABLE_VLAN_FILTER, 0);
3505
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003506 if ((debug != -1) && (debug & NETIF_MSG_HW))
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003507 liquidio_set_feature(netdev,
3508 OCTNET_CMD_VERBOSE_ENABLE, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003509
3510 /* Register the network device with the OS */
3511 if (register_netdev(netdev)) {
3512 dev_err(&octeon_dev->pci_dev->dev, "Device registration failed\n");
3513 goto setup_nic_dev_fail;
3514 }
3515
3516 dev_dbg(&octeon_dev->pci_dev->dev,
3517 "Setup NIC ifidx:%d mac:%02x%02x%02x%02x%02x%02x\n",
3518 i, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
3519 netif_carrier_off(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003520 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003521
3522 ifstate_set(lio, LIO_IFSTATE_REGISTERED);
3523
3524 dev_dbg(&octeon_dev->pci_dev->dev,
3525 "NIC ifidx:%d Setup successful\n", i);
3526
3527 octeon_free_soft_command(octeon_dev, sc);
3528 }
3529
3530 return 0;
3531
3532setup_nic_dev_fail:
3533
3534 octeon_free_soft_command(octeon_dev, sc);
3535
3536 while (i--) {
3537 dev_err(&octeon_dev->pci_dev->dev,
3538 "NIC ifidx:%d Setup failed\n", i);
3539 liquidio_destroy_nic_device(octeon_dev, i);
3540 }
3541 return -ENODEV;
3542}
3543
3544/**
3545 * \brief initialize the NIC
3546 * @param oct octeon device
3547 *
3548 * This initialization routine is called once the Octeon device application is
3549 * up and running
3550 */
3551static int liquidio_init_nic_module(struct octeon_device *oct)
3552{
3553 struct oct_intrmod_cfg *intrmod_cfg;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003554 int i, retval = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003555 int num_nic_ports = CFG_GET_NUM_NIC_PORTS(octeon_get_conf(oct));
3556
3557 dev_dbg(&oct->pci_dev->dev, "Initializing network interfaces\n");
3558
3559 /* only default iq and oq were initialized
3560 * initialize the rest as well
3561 */
3562 /* run port_config command for each port */
3563 oct->ifcount = num_nic_ports;
3564
3565 memset(oct->props, 0,
3566 sizeof(struct octdev_props) * num_nic_ports);
3567
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003568 for (i = 0; i < MAX_OCTEON_LINKS; i++)
3569 oct->props[i].gmxport = -1;
3570
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003571 retval = setup_nic_devices(oct);
3572 if (retval) {
3573 dev_err(&oct->pci_dev->dev, "Setup NIC devices failed\n");
3574 goto octnet_init_failure;
3575 }
3576
3577 liquidio_ptp_init(oct);
3578
3579 /* Initialize interrupt moderation params */
3580 intrmod_cfg = &((struct octeon_device *)oct)->intrmod;
3581 intrmod_cfg->intrmod_enable = 1;
3582 intrmod_cfg->intrmod_check_intrvl = LIO_INTRMOD_CHECK_INTERVAL;
3583 intrmod_cfg->intrmod_maxpkt_ratethr = LIO_INTRMOD_MAXPKT_RATETHR;
3584 intrmod_cfg->intrmod_minpkt_ratethr = LIO_INTRMOD_MINPKT_RATETHR;
3585 intrmod_cfg->intrmod_maxcnt_trigger = LIO_INTRMOD_MAXCNT_TRIGGER;
3586 intrmod_cfg->intrmod_maxtmr_trigger = LIO_INTRMOD_MAXTMR_TRIGGER;
3587 intrmod_cfg->intrmod_mintmr_trigger = LIO_INTRMOD_MINTMR_TRIGGER;
3588 intrmod_cfg->intrmod_mincnt_trigger = LIO_INTRMOD_MINCNT_TRIGGER;
3589
3590 dev_dbg(&oct->pci_dev->dev, "Network interfaces ready\n");
3591
3592 return retval;
3593
3594octnet_init_failure:
3595
3596 oct->ifcount = 0;
3597
3598 return retval;
3599}
3600
3601/**
3602 * \brief starter callback that invokes the remaining initialization work after
3603 * the NIC is up and running.
3604 * @param octptr work struct work_struct
3605 */
3606static void nic_starter(struct work_struct *work)
3607{
3608 struct octeon_device *oct;
3609 struct cavium_wk *wk = (struct cavium_wk *)work;
3610
3611 oct = (struct octeon_device *)wk->ctxptr;
3612
3613 if (atomic_read(&oct->status) == OCT_DEV_RUNNING)
3614 return;
3615
3616 /* If the status of the device is CORE_OK, the core
3617 * application has reported its application type. Call
3618 * any registered handlers now and move to the RUNNING
3619 * state.
3620 */
3621 if (atomic_read(&oct->status) != OCT_DEV_CORE_OK) {
3622 schedule_delayed_work(&oct->nic_poll_work.work,
3623 LIQUIDIO_STARTER_POLL_INTERVAL_MS);
3624 return;
3625 }
3626
3627 atomic_set(&oct->status, OCT_DEV_RUNNING);
3628
3629 if (oct->app_mode && oct->app_mode == CVM_DRV_NIC_APP) {
3630 dev_dbg(&oct->pci_dev->dev, "Starting NIC module\n");
3631
3632 if (liquidio_init_nic_module(oct))
3633 dev_err(&oct->pci_dev->dev, "NIC initialization failed\n");
3634 else
3635 handshake[oct->octeon_id].started_ok = 1;
3636 } else {
3637 dev_err(&oct->pci_dev->dev,
3638 "Unexpected application running on NIC (%d). Check firmware.\n",
3639 oct->app_mode);
3640 }
3641
3642 complete(&handshake[oct->octeon_id].started);
3643}
3644
3645/**
3646 * \brief Device initialization for each Octeon device that is probed
3647 * @param octeon_dev octeon device
3648 */
3649static int octeon_device_init(struct octeon_device *octeon_dev)
3650{
3651 int j, ret;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07003652 char bootcmd[] = "\n";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003653 struct octeon_device_priv *oct_priv =
3654 (struct octeon_device_priv *)octeon_dev->priv;
3655 atomic_set(&octeon_dev->status, OCT_DEV_BEGIN_STATE);
3656
3657 /* Enable access to the octeon device and make its DMA capability
3658 * known to the OS.
3659 */
3660 if (octeon_pci_os_setup(octeon_dev))
3661 return 1;
3662
3663 /* Identify the Octeon type and map the BAR address space. */
3664 if (octeon_chip_specific_setup(octeon_dev)) {
3665 dev_err(&octeon_dev->pci_dev->dev, "Chip specific setup failed\n");
3666 return 1;
3667 }
3668
3669 atomic_set(&octeon_dev->status, OCT_DEV_PCI_MAP_DONE);
3670
3671 octeon_dev->app_mode = CVM_DRV_INVALID_APP;
3672
3673 /* Do a soft reset of the Octeon device. */
3674 if (octeon_dev->fn_list.soft_reset(octeon_dev))
3675 return 1;
3676
3677 /* Initialize the dispatch mechanism used to push packets arriving on
3678 * Octeon Output queues.
3679 */
3680 if (octeon_init_dispatch_list(octeon_dev))
3681 return 1;
3682
3683 octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
3684 OPCODE_NIC_CORE_DRV_ACTIVE,
3685 octeon_core_drv_init,
3686 octeon_dev);
3687
3688 INIT_DELAYED_WORK(&octeon_dev->nic_poll_work.work, nic_starter);
3689 octeon_dev->nic_poll_work.ctxptr = (void *)octeon_dev;
3690 schedule_delayed_work(&octeon_dev->nic_poll_work.work,
3691 LIQUIDIO_STARTER_POLL_INTERVAL_MS);
3692
3693 atomic_set(&octeon_dev->status, OCT_DEV_DISPATCH_INIT_DONE);
3694
3695 octeon_set_io_queues_off(octeon_dev);
3696
3697 /* Setup the data structures that manage this Octeon's Input queues. */
3698 if (octeon_setup_instr_queues(octeon_dev)) {
3699 dev_err(&octeon_dev->pci_dev->dev,
3700 "instruction queue initialization failed\n");
3701 /* On error, release any previously allocated queues */
3702 for (j = 0; j < octeon_dev->num_iqs; j++)
3703 octeon_delete_instr_queue(octeon_dev, j);
3704 return 1;
3705 }
3706 atomic_set(&octeon_dev->status, OCT_DEV_INSTR_QUEUE_INIT_DONE);
3707
3708 /* Initialize soft command buffer pool
3709 */
3710 if (octeon_setup_sc_buffer_pool(octeon_dev)) {
3711 dev_err(&octeon_dev->pci_dev->dev, "sc buffer pool allocation failed\n");
3712 return 1;
3713 }
3714 atomic_set(&octeon_dev->status, OCT_DEV_SC_BUFF_POOL_INIT_DONE);
3715
3716 /* Initialize lists to manage the requests of different types that
3717 * arrive from user & kernel applications for this octeon device.
3718 */
3719 if (octeon_setup_response_list(octeon_dev)) {
3720 dev_err(&octeon_dev->pci_dev->dev, "Response list allocation failed\n");
3721 return 1;
3722 }
3723 atomic_set(&octeon_dev->status, OCT_DEV_RESP_LIST_INIT_DONE);
3724
3725 if (octeon_setup_output_queues(octeon_dev)) {
3726 dev_err(&octeon_dev->pci_dev->dev, "Output queue initialization failed\n");
3727 /* Release any previously allocated queues */
3728 for (j = 0; j < octeon_dev->num_oqs; j++)
3729 octeon_delete_droq(octeon_dev, j);
3730 }
3731
3732 atomic_set(&octeon_dev->status, OCT_DEV_DROQ_INIT_DONE);
3733
3734 /* The input and output queue registers were setup earlier (the queues
3735 * were not enabled). Any additional registers that need to be
3736 * programmed should be done now.
3737 */
3738 ret = octeon_dev->fn_list.setup_device_regs(octeon_dev);
3739 if (ret) {
3740 dev_err(&octeon_dev->pci_dev->dev,
3741 "Failed to configure device registers\n");
3742 return ret;
3743 }
3744
3745 /* Initialize the tasklet that handles output queue packet processing.*/
3746 dev_dbg(&octeon_dev->pci_dev->dev, "Initializing droq tasklet\n");
3747 tasklet_init(&oct_priv->droq_tasklet, octeon_droq_bh,
3748 (unsigned long)octeon_dev);
3749
3750 /* Setup the interrupt handler and record the INT SUM register address
3751 */
3752 octeon_setup_interrupt(octeon_dev);
3753
3754 /* Enable Octeon device interrupts */
3755 octeon_dev->fn_list.enable_interrupt(octeon_dev->chip);
3756
3757 /* Enable the input and output queues for this Octeon device */
3758 octeon_dev->fn_list.enable_io_queues(octeon_dev);
3759
3760 atomic_set(&octeon_dev->status, OCT_DEV_IO_QUEUES_DONE);
3761
3762 dev_dbg(&octeon_dev->pci_dev->dev, "Waiting for DDR initialization...\n");
3763
3764 if (ddr_timeout == 0) {
3765 dev_info(&octeon_dev->pci_dev->dev,
3766 "WAITING. Set ddr_timeout to non-zero value to proceed with initialization.\n");
3767 }
3768
3769 schedule_timeout_uninterruptible(HZ * LIO_RESET_SECS);
3770
3771 /* Wait for the octeon to initialize DDR after the soft-reset. */
3772 ret = octeon_wait_for_ddr_init(octeon_dev, &ddr_timeout);
3773 if (ret) {
3774 dev_err(&octeon_dev->pci_dev->dev,
3775 "DDR not initialized. Please confirm that board is configured to boot from Flash, ret: %d\n",
3776 ret);
3777 return 1;
3778 }
3779
3780 if (octeon_wait_for_bootloader(octeon_dev, 1000) != 0) {
3781 dev_err(&octeon_dev->pci_dev->dev, "Board not responding\n");
3782 return 1;
3783 }
3784
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07003785 /* Divert uboot to take commands from host instead. */
3786 ret = octeon_console_send_cmd(octeon_dev, bootcmd, 50);
3787
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003788 dev_dbg(&octeon_dev->pci_dev->dev, "Initializing consoles\n");
3789 ret = octeon_init_consoles(octeon_dev);
3790 if (ret) {
3791 dev_err(&octeon_dev->pci_dev->dev, "Could not access board consoles\n");
3792 return 1;
3793 }
3794 ret = octeon_add_console(octeon_dev, 0);
3795 if (ret) {
3796 dev_err(&octeon_dev->pci_dev->dev, "Could not access board console\n");
3797 return 1;
3798 }
3799
3800 atomic_set(&octeon_dev->status, OCT_DEV_CONSOLE_INIT_DONE);
3801
3802 dev_dbg(&octeon_dev->pci_dev->dev, "Loading firmware\n");
3803 ret = load_firmware(octeon_dev);
3804 if (ret) {
3805 dev_err(&octeon_dev->pci_dev->dev, "Could not load firmware to board\n");
3806 return 1;
3807 }
3808
3809 handshake[octeon_dev->octeon_id].init_ok = 1;
3810 complete(&handshake[octeon_dev->octeon_id].init);
3811
3812 atomic_set(&octeon_dev->status, OCT_DEV_HOST_OK);
3813
3814 /* Send Credit for Octeon Output queues. Credits are always sent after
3815 * the output queue is enabled.
3816 */
3817 for (j = 0; j < octeon_dev->num_oqs; j++)
3818 writel(octeon_dev->droq[j]->max_count,
3819 octeon_dev->droq[j]->pkts_credit_reg);
3820
3821 /* Packets can start arriving on the output queues from this point. */
3822
3823 return 0;
3824}
3825
3826/**
3827 * \brief Exits the module
3828 */
3829static void __exit liquidio_exit(void)
3830{
3831 liquidio_deinit_pci();
3832
3833 pr_info("LiquidIO network module is now unloaded\n");
3834}
3835
3836module_init(liquidio_init);
3837module_exit(liquidio_exit);