iPXE
efx_common.h
Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * GPL common net driver for Solarflare network cards
00004  *
00005  * Written by Michael Brown <mbrown@fensystems.co.uk>
00006  *
00007  * Copyright Fen Systems Ltd. 2005
00008  * Copyright Level 5 Networks Inc. 2005
00009  * Copyright Solarflare Communications Inc. 2013-2017
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License as
00013  * published by the Free Software Foundation; either version 2 of the
00014  * License, or any later version.
00015  *
00016  * You can also choose to distribute this program under the terms of
00017  * the Unmodified Binary Distribution Licence (as given in the file
00018  * COPYING.UBDL), provided that you have satisfied its requirements.
00019  *
00020  ***************************************************************************/
00021 #ifndef EFX_COMMON_H
00022 #define EFX_COMMON_H
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #define __packed    __attribute__((__packed__))
00027 #define __force     /*nothing*/
00028 
00029 typedef uint16_t    __le16;
00030 typedef uint32_t    __le32;
00031 typedef uint64_t    __le64;
00032 
00033 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct{int: -!!(e); }))
00034 #define BUILD_BUG_ON(e) ((void)BUILD_BUG_ON_ZERO(e))
00035 
00036 #include <stdbool.h>
00037 #include <ipxe/io.h>
00038 #include <ipxe/netdevice.h>
00039 #include "efx_bitfield.h"
00040 #include "mcdi.h"
00041 
00042 #ifndef ARRAY_SIZE
00043 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
00044 #endif
00045 
00046 /**************************************************************************
00047  *
00048  * Hardware data structures and sizing
00049  *
00050  ***************************************************************************/
00051 typedef efx_qword_t efx_rx_desc_t;
00052 typedef efx_qword_t efx_tx_desc_t;
00053 typedef efx_qword_t efx_event_t;
00054 
00055 #define EFX_BUF_ALIGN           4096
00056 #define EFX_RXD_SIZE            512
00057 #define EFX_RXD_MASK            (EFX_RXD_SIZE - 1)
00058 #define EFX_TXD_SIZE            512
00059 #define EFX_TXD_MASK            (EFX_TXD_SIZE - 1)
00060 #define EFX_EVQ_SIZE            512
00061 #define EFX_EVQ_MASK            (EFX_EVQ_SIZE - 1)
00062 
00063 /* There is space for 512 rx descriptors available. This number can be
00064  * anything between 1 and 512 in powers of 2. This value will affect the
00065  * network performance. During a test we were able to push 239 descriptors
00066  * before we ran out of space.
00067  */
00068 #define EFX_NUM_RX_DESC         64
00069 #define EFX_NUM_RX_DESC_MASK    (EFX_NUM_RX_DESC - 1)
00070 
00071 /* The packet size is usually 1500 bytes hence we choose 1600 as the buf size,
00072  * which is (1500+metadata)
00073  */
00074 #define EFX_RX_BUF_SIZE         1600
00075 
00076 /* Settings for the state field in efx_nic.
00077  */
00078 #define EFX_STATE_POLLING       1
00079 
00080 typedef unsigned long long dma_addr_t;
00081 
00082 /** A buffer table allocation backing a tx dma, rx dma or eventq */
00083 struct efx_special_buffer {
00084         dma_addr_t dma_addr;
00085         int id;
00086 };
00087 
00088 /** A transmit queue */
00089 struct efx_tx_queue {
00090         /* The hardware ring */
00091         efx_tx_desc_t *ring;
00092 
00093         /* The software ring storing io_buffers. */
00094         struct io_buffer *buf[EFX_TXD_SIZE];
00095 
00096         /* The buffer table reservation pushed to hardware */
00097         struct efx_special_buffer entry;
00098 
00099         /* Software descriptor write ptr */
00100         unsigned int write_ptr;
00101 
00102         /* Hardware descriptor read ptr */
00103         unsigned int read_ptr;
00104 };
00105 
00106 /** A receive queue */
00107 struct efx_rx_queue {
00108         /* The hardware ring */
00109         efx_rx_desc_t *ring;
00110 
00111         /* The software ring storing io_buffers */
00112         struct io_buffer *buf[EFX_NUM_RX_DESC];
00113 
00114         /* The buffer table reservation pushed to hardware */
00115         struct efx_special_buffer entry;
00116 
00117         /* Descriptor write ptr, into both the hardware and software rings */
00118         unsigned int write_ptr;
00119 
00120         /* Hardware completion ptr */
00121         unsigned int read_ptr;
00122 
00123         /* The value of RX_CONT in the previous RX event */
00124         unsigned int rx_cont_prev;
00125 };
00126 
00127 /** An event queue */
00128 struct efx_ev_queue {
00129         /* The hardware ring to push to hardware.
00130          * Must be the first entry in the structure.
00131          */
00132         efx_event_t *ring;
00133 
00134         /* The buffer table reservation pushed to hardware */
00135         struct efx_special_buffer entry;
00136 
00137         /* Pointers into the ring */
00138         unsigned int read_ptr;
00139 };
00140 
00141 /* Hardware revisions */
00142 enum efx_revision {
00143         EFX_HUNTINGTON,
00144 };
00145 
00146 /** Hardware access */
00147 struct efx_nic {
00148         struct net_device *netdev;
00149         enum efx_revision revision;
00150         const struct efx_nic_type *type;
00151 
00152         int port;
00153         u32 state;
00154 
00155         /** Memory and IO base */
00156         void *membase;
00157         unsigned long mmio_start;
00158         unsigned long mmio_len;
00159 
00160         /* Buffer table allocation head */
00161         int buffer_head;
00162 
00163         /* Queues */
00164         struct efx_rx_queue rxq;
00165         struct efx_tx_queue txq;
00166         struct efx_ev_queue evq;
00167 
00168         unsigned int rx_prefix_size;
00169 
00170         /** INT_REG_KER */
00171         int int_en;
00172         efx_oword_t int_ker __aligned;
00173 
00174         /* Set to true if firmware supports the workaround for bug35388 */
00175         bool workaround_35388;
00176 
00177 };
00178 
00179 
00180 /** Efx device type definition */
00181 struct efx_nic_type {
00182         int (*mcdi_rpc)(struct efx_nic *efx, unsigned int cmd,
00183                         const efx_dword_t *inbuf, size_t inlen,
00184                         efx_dword_t *outbuf, size_t outlen,
00185                         size_t *outlen_actual, bool quiet);
00186 };
00187 
00188 extern const struct efx_nic_type hunt_nic_type;
00189 
00190 #define EFX_MAC_FRAME_LEN(_mtu)                                 \
00191         (((_mtu)                                                \
00192           + /* EtherII already included */                      \
00193           + 4 /* FCS */                                         \
00194           /* No VLAN supported */                               \
00195           + 16 /* bug16772 */                                   \
00196           + 7) & ~7)
00197 
00198 /*******************************************************************************
00199  *
00200  *
00201  * Hardware API
00202  *
00203  *
00204  ******************************************************************************/
00205 static inline void _efx_writel(struct efx_nic *efx, uint32_t value,
00206                                unsigned int reg)
00207 {
00208         writel((value), (efx)->membase + (reg));
00209 }
00210 
00211 static inline uint32_t _efx_readl(struct efx_nic *efx, unsigned int reg)
00212 {
00213         return readl((efx)->membase + (reg));
00214 }
00215 
00216 #define efx_writel_table(efx, value, index, reg)                \
00217         efx_writel(efx, value, (reg) + ((index) * reg##_STEP))
00218 
00219 #define efx_writel_page(efx, value, index, reg)                 \
00220         efx_writel(efx, value, (reg) + ((index) * 0x2000))
00221 
00222 /* Hardware access */
00223 extern void efx_writel(struct efx_nic *efx, efx_dword_t *value,
00224                        unsigned int reg);
00225 extern void efx_readl(struct efx_nic *efx, efx_dword_t *value,
00226                       unsigned int reg);
00227 
00228 /* Initialisation */
00229 extern void efx_probe(struct net_device *netdev, enum efx_revision rev);
00230 extern void efx_remove(struct net_device *netdev);
00231 
00232 #endif /* EFX_COMMON_H */