Commit afd4aea0 authored by Ben Hutchings's avatar Ben Hutchings Committed by David S. Miller
Browse files

sfc: Add support for SFC9000 family (1)



This adds support for the SFC9000 family of 10G Ethernet controllers
and LAN-on-motherboard chips, starting with the SFL9021 'Siena' and
SFC9020 'Bethpage'.

The SFC9000 family is based on the SFC4000 'Falcon' architecture, but
with some significant changes:

- Two ports are associated with two independent PCI functions
  (except SFC9010)
- Integrated 10GBASE-T PHY(s) (SFL9021/9022)
- MAC, PHY and board peripherals are managed by firmware
  - Driver does not require board-specific code
  - Firmware supports wake-on-LAN and lights-out management through NC-SI
- IPv6 checksum offload and RSS
- Filtering by MAC address and VLAN (not included in this code)
- PCI SR-IOV (not included in this code)

Credit for this code is largely due to my colleagues at Solarflare:

   Guido Barzini
   Steve Hodgson
   Kieran Mansley
   Matthew Slattery
   Neil Turton

Signed-off-by: default avatarBen Hutchings <bhutchings@solarflare.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f0d37f42
Loading
Loading
Loading
Loading

drivers/net/sfc/mcdi.c

0 → 100644
+1112 −0

File added.

Preview size limit exceeded, changes collapsed.

drivers/net/sfc/mcdi.h

0 → 100644
+130 −0
Original line number Diff line number Diff line
/****************************************************************************
 * Driver for Solarflare Solarstorm network controllers and boards
 * Copyright 2008-2009 Solarflare Communications Inc.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation, incorporated herein by reference.
 */

#ifndef EFX_MCDI_H
#define EFX_MCDI_H

/**
 * enum efx_mcdi_state
 * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the
 *	mcdi_lock then they are able to move to MCDI_STATE_RUNNING
 * @MCDI_STATE_RUNNING: There is an MCDI request pending. Only the thread that
 *	moved into this state is allowed to move out of it.
 * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread
 *	has not yet consumed the result. For all other threads, equivalent to
 *	MCDI_STATE_RUNNING.
 */
enum efx_mcdi_state {
	MCDI_STATE_QUIESCENT,
	MCDI_STATE_RUNNING,
	MCDI_STATE_COMPLETED,
};

enum efx_mcdi_mode {
	MCDI_MODE_POLL,
	MCDI_MODE_EVENTS,
};

/**
 * struct efx_mcdi_iface
 * @state: Interface state. Waited for by mcdi_wq.
 * @wq: Wait queue for threads waiting for state != STATE_RUNNING
 * @iface_lock: Protects @credits, @seqno, @resprc, @resplen
 * @mode: Poll for mcdi completion, or wait for an mcdi_event.
 *	Serialised by @lock
 * @seqno: The next sequence number to use for mcdi requests.
 *	Serialised by @lock
 * @credits: Number of spurious MCDI completion events allowed before we
 *	trigger a fatal error. Protected by @lock
 * @resprc: Returned MCDI completion
 * @resplen: Returned payload length
 */
struct efx_mcdi_iface {
	atomic_t state;
	wait_queue_head_t wq;
	spinlock_t iface_lock;
	enum efx_mcdi_mode mode;
	unsigned int credits;
	unsigned int seqno;
	unsigned int resprc;
	size_t resplen;
};

extern void efx_mcdi_init(struct efx_nic *efx);

extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, const u8 *inbuf,
			size_t inlen, u8 *outbuf, size_t outlen,
			size_t *outlen_actual);

extern int efx_mcdi_poll_reboot(struct efx_nic *efx);
extern void efx_mcdi_mode_poll(struct efx_nic *efx);
extern void efx_mcdi_mode_event(struct efx_nic *efx);

extern void efx_mcdi_process_event(struct efx_channel *channel,
				   efx_qword_t *event);

#define MCDI_PTR2(_buf, _ofst)						\
	(((u8 *)_buf) + _ofst)
#define MCDI_SET_DWORD2(_buf, _ofst, _value)				\
	EFX_POPULATE_DWORD_1(*((efx_dword_t *)MCDI_PTR2(_buf, _ofst)),	\
			     EFX_DWORD_0, _value)
#define MCDI_DWORD2(_buf, _ofst)					\
	EFX_DWORD_FIELD(*((efx_dword_t *)MCDI_PTR2(_buf, _ofst)),	\
			EFX_DWORD_0)
#define MCDI_QWORD2(_buf, _ofst)					\
	EFX_QWORD_FIELD64(*((efx_qword_t *)MCDI_PTR2(_buf, _ofst)),	\
			  EFX_QWORD_0)

#define MCDI_PTR(_buf, _ofst)						\
	MCDI_PTR2(_buf, MC_CMD_ ## _ofst ## _OFST)
#define MCDI_SET_DWORD(_buf, _ofst, _value)				\
	MCDI_SET_DWORD2(_buf, MC_CMD_ ## _ofst ## _OFST, _value)
#define MCDI_DWORD(_buf, _ofst)						\
	MCDI_DWORD2(_buf, MC_CMD_ ## _ofst ## _OFST)
#define MCDI_QWORD(_buf, _ofst)						\
	MCDI_QWORD2(_buf, MC_CMD_ ## _ofst ## _OFST)

#define MCDI_EVENT_FIELD(_ev, _field)			\
	EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)

extern int efx_mcdi_fwver(struct efx_nic *efx, u64 *version, u32 *build);
extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
			       bool *was_attached_out);
extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
				  u16 *fw_subtype_list);
extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart,
			     u32 dest_evq);
extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
			       size_t *size_out, size_t *erase_size_out,
			       bool *protected_out);
extern int efx_mcdi_nvram_update_start(struct efx_nic *efx,
				       unsigned int type);
extern int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
			       loff_t offset, u8 *buffer, size_t length);
extern int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
				loff_t offset, const u8 *buffer,
				size_t length);
extern int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
				loff_t offset, size_t length);
extern int efx_mcdi_nvram_update_finish(struct efx_nic *efx,
					unsigned int type);
extern int efx_mcdi_handle_assertion(struct efx_nic *efx);
extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
extern int efx_mcdi_reset_port(struct efx_nic *efx);
extern int efx_mcdi_reset_mc(struct efx_nic *efx);
extern int efx_mcdi_wol_filter_set(struct efx_nic *efx, u32 type,
				   const u8 *mac, int *id_out);
extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx,
					 const u8 *mac, int *id_out);
extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx);

#endif /* EFX_MCDI_H */
+152 −0
Original line number Diff line number Diff line
/****************************************************************************
 * Driver for Solarflare Solarstorm network controllers and boards
 * Copyright 2009 Solarflare Communications Inc.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation, incorporated herein by reference.
 */

#include "net_driver.h"
#include "efx.h"
#include "mac.h"
#include "mcdi.h"
#include "mcdi_pcol.h"

static int efx_mcdi_set_mac(struct efx_nic *efx)
{
	u32 reject, fcntl;
	u8 cmdbytes[MC_CMD_SET_MAC_IN_LEN];

	memcpy(cmdbytes + MC_CMD_SET_MAC_IN_ADDR_OFST,
	       efx->net_dev->dev_addr, ETH_ALEN);

	MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU,
			EFX_MAX_FRAME_LEN(efx->net_dev->mtu));
	MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_DRAIN, 0);

	/* The MCDI command provides for controlling accept/reject
	 * of broadcast packets too, but the driver doesn't currently
	 * expose this. */
	reject = (efx->promiscuous) ? 0 :
		(1 << MC_CMD_SET_MAC_IN_REJECT_UNCST_LBN);
	MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_REJECT, reject);

	switch (efx->wanted_fc) {
	case EFX_FC_RX | EFX_FC_TX:
		fcntl = MC_CMD_FCNTL_BIDIR;
		break;
	case EFX_FC_RX:
		fcntl = MC_CMD_FCNTL_RESPOND;
		break;
	default:
		fcntl = MC_CMD_FCNTL_OFF;
		break;
	}
	if (efx->wanted_fc & EFX_FC_AUTO)
		fcntl = MC_CMD_FCNTL_AUTO;

	MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl);

	return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes),
			    NULL, 0, NULL);
}

static int efx_mcdi_get_mac_faults(struct efx_nic *efx, u32 *faults)
{
	u8 outbuf[MC_CMD_GET_LINK_OUT_LEN];
	size_t outlength;
	int rc;

	BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);

	rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
			  outbuf, sizeof(outbuf), &outlength);
	if (rc)
		goto fail;

	*faults = MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT);
	return 0;

fail:
	EFX_ERR(efx, "%s: failed rc=%d\n",
		__func__, rc);
	return rc;
}

int efx_mcdi_mac_stats(struct efx_nic *efx, dma_addr_t dma_addr,
		       u32 dma_len, int enable, int clear)
{
	u8 inbuf[MC_CMD_MAC_STATS_IN_LEN];
	int rc;
	efx_dword_t *cmd_ptr;
	int period = 1000;
	u32 addr_hi;
	u32 addr_lo;

	BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_LEN != 0);

	addr_lo = ((u64)dma_addr) >> 0;
	addr_hi = ((u64)dma_addr) >> 32;

	MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_LO, addr_lo);
	MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_ADDR_HI, addr_hi);
	cmd_ptr = (efx_dword_t *)MCDI_PTR(inbuf, MAC_STATS_IN_CMD);
	if (enable)
		EFX_POPULATE_DWORD_6(*cmd_ptr,
				     MC_CMD_MAC_STATS_CMD_DMA, 1,
				     MC_CMD_MAC_STATS_CMD_CLEAR, clear,
				     MC_CMD_MAC_STATS_CMD_PERIODIC_CHANGE, 1,
				     MC_CMD_MAC_STATS_CMD_PERIODIC_ENABLE, 1,
				     MC_CMD_MAC_STATS_CMD_PERIODIC_CLEAR, 0,
				     MC_CMD_MAC_STATS_CMD_PERIOD_MS, period);
	else
		EFX_POPULATE_DWORD_5(*cmd_ptr,
				     MC_CMD_MAC_STATS_CMD_DMA, 0,
				     MC_CMD_MAC_STATS_CMD_CLEAR, clear,
				     MC_CMD_MAC_STATS_CMD_PERIODIC_CHANGE, 1,
				     MC_CMD_MAC_STATS_CMD_PERIODIC_ENABLE, 0,
				     MC_CMD_MAC_STATS_CMD_PERIODIC_CLEAR, 0);
	MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);

	rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
			  NULL, 0, NULL);
	if (rc)
		goto fail;

	return 0;

fail:
	EFX_ERR(efx, "%s: %s failed rc=%d\n",
		__func__, enable ? "enable" : "disable", rc);
	return rc;
}

static int efx_mcdi_mac_reconfigure(struct efx_nic *efx)
{
	int rc;

	rc = efx_mcdi_set_mac(efx);
	if (rc != 0)
		return rc;

	/* Restore the multicast hash registers. */
	efx->type->push_multicast_hash(efx);

	return 0;
}


static bool efx_mcdi_mac_check_fault(struct efx_nic *efx)
{
	u32 faults;
	int rc = efx_mcdi_get_mac_faults(efx, &faults);
	return (rc != 0) || (faults != 0);
}


struct efx_mac_operations efx_mcdi_mac_operations = {
	.reconfigure	= efx_mcdi_mac_reconfigure,
	.update_stats	= efx_port_dummy_op_void,
	.check_fault 	= efx_mcdi_mac_check_fault,
};
+597 −0

File added.

Preview size limit exceeded, changes collapsed.

+604 −0

File added.

Preview size limit exceeded, changes collapsed.