1 /**********************************************************************
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
7 * Copyright (c) 2003-2015 Cavium, Inc.
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.
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
19 * This file may also be available under a different license from Cavium.
20 * Contact Cavium, Inc. for more information
21 **********************************************************************/
23 /*! \file octeon_network.h
24 * \brief Host NIC Driver: Structure and Macro definitions used by NIC Module.
27 #ifndef __OCTEON_NETWORK_H__
28 #define __OCTEON_NETWORK_H__
29 #include <linux/version.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/ptp_clock_kernel.h>
33 /** LiquidIO per-interface network private data */
35 /** State of the interface. Rx/Tx happens only in the RUNNING state. */
38 /** Octeon Interface index number. This device will be represented as
39 * oct<ifidx> in the system.
43 /** Octeon Input queue to use to transmit for this network interface. */
46 /** Octeon Output queue from which pkts arrive
47 * for this network interface.
51 /** Guards the glist */
54 /** Linked list of gather components */
55 struct list_head glist;
57 /** Pointer to the NIC properties for the Octeon device this network
58 * interface is associated with.
60 struct octdev_props *octprops;
62 /** Pointer to the octeon device structure. */
63 struct octeon_device *oct_dev;
65 struct net_device *netdev;
67 /** Link information sent by the core application for this interface. */
68 struct oct_link_info linfo;
70 /** Size of Tx queue for this octeon device. */
73 /** Size of Rx queue for this octeon device. */
76 /** Size of MTU this octeon device. */
79 /** msg level flag per interface. */
82 /** Copy of Interface capabilities: TSO, TSO6, LRO, Chescksums . */
85 /** Copy of beacaon reg in phy */
88 /** Copy of ctrl reg in phy */
91 /* PTP clock information */
92 struct ptp_clock_info ptp_info;
93 struct ptp_clock *ptp_clock;
96 /* for atomic access to Octeon PTP reg and data struct */
102 /* work queue for txq status */
103 struct cavium_wq txq_status_wq;
107 #define LIO_SIZE (sizeof(struct lio))
108 #define GET_LIO(netdev) ((struct lio *)netdev_priv(netdev))
111 * \brief Enable or disable feature
112 * @param netdev pointer to network device
113 * @param cmd Command that just requires acknowledgment
115 int liquidio_set_feature(struct net_device *netdev, int cmd);
118 * \brief Link control command completion callback
119 * @param nctrl_ptr pointer to control packet structure
121 * This routine is called by the callback function when a ctrl pkt sent to
122 * core app completes. The nctrl_ptr contains a copy of the command type
123 * and data sent to the core app. This routine is only called if the ctrl
124 * pkt was sent successfully to the core app.
126 void liquidio_link_ctrl_cmd_completion(void *nctrl_ptr);
129 * \brief Register ethtool operations
130 * @param netdev pointer to network device
132 void liquidio_set_ethtool_ops(struct net_device *netdev);
135 *recv_buffer_alloc(struct octeon_device *oct __attribute__((unused)),
136 u32 q_no __attribute__((unused)), u32 size)
138 #define SKB_ADJ_MASK 0x3F
139 #define SKB_ADJ (SKB_ADJ_MASK + 1)
141 struct sk_buff *skb = dev_alloc_skb(size + SKB_ADJ);
143 if ((unsigned long)skb->data & SKB_ADJ_MASK) {
144 u32 r = SKB_ADJ - ((unsigned long)skb->data & SKB_ADJ_MASK);
152 static inline void recv_buffer_free(void *buffer)
154 dev_kfree_skb_any((struct sk_buff *)buffer);
157 #define lio_dma_alloc(oct, size, dma_addr) \
158 dma_alloc_coherent(&oct->pci_dev->dev, size, dma_addr, GFP_KERNEL)
159 #define lio_dma_free(oct, size, virt_addr, dma_addr) \
160 dma_free_coherent(&oct->pci_dev->dev, size, virt_addr, dma_addr)
162 #define get_rbd(ptr) (((struct sk_buff *)(ptr))->data)
165 lio_map_ring_info(struct octeon_droq *droq, u32 i)
168 struct octeon_device *oct = droq->oct_dev;
170 dma_addr = dma_map_single(&oct->pci_dev->dev, &droq->info_list[i],
171 OCT_DROQ_INFO_SIZE, DMA_FROM_DEVICE);
173 BUG_ON(dma_mapping_error(&oct->pci_dev->dev, dma_addr));
175 return (u64)dma_addr;
179 lio_unmap_ring_info(struct pci_dev *pci_dev,
180 u64 info_ptr, u32 size)
182 dma_unmap_single(&pci_dev->dev, info_ptr, size, DMA_FROM_DEVICE);
186 lio_map_ring(struct pci_dev *pci_dev,
191 dma_addr = dma_map_single(&pci_dev->dev, get_rbd(buf), size,
194 BUG_ON(dma_mapping_error(&pci_dev->dev, dma_addr));
196 return (u64)dma_addr;
200 lio_unmap_ring(struct pci_dev *pci_dev,
201 u64 buf_ptr, u32 size)
203 dma_unmap_single(&pci_dev->dev,
208 static inline void *octeon_fast_packet_alloc(struct octeon_device *oct,
209 struct octeon_droq *droq,
212 return recv_buffer_alloc(oct, q_no, size);
215 static inline void octeon_fast_packet_next(struct octeon_droq *droq,
216 struct sk_buff *nicbuf,
220 memcpy(skb_put(nicbuf, copy_len),
221 get_rbd(droq->recv_buf_list[idx].buffer), copy_len);