Skip to content

Commit

Permalink
Merge branch 'master' of https://git.ipxe.org/ipxe
Browse files Browse the repository at this point in the history
Conflicts:
	src/config/general.h
  • Loading branch information
Jarrod Johnson committed Aug 20, 2013
2 parents dde0935 + 6d72b49 commit 6dd2497
Show file tree
Hide file tree
Showing 12 changed files with 571 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/config/config.c
Expand Up @@ -263,6 +263,9 @@ REQUIRE_OBJECT ( nslookup_cmd );
#ifdef PCI_CMD
REQUIRE_OBJECT ( pci_cmd );
#endif
#ifdef PARAM_CMD
REQUIRE_OBJECT ( param_cmd );
#endif

/*
* Drag in miscellaneous objects
Expand Down
165 changes: 165 additions & 0 deletions src/core/params.c
@@ -0,0 +1,165 @@
/*
* Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

FILE_LICENCE ( GPL2_OR_LATER );

/** @file
*
* Form parameters
*
*/

#include <stdlib.h>
#include <string.h>
#include <ipxe/params.h>

/** List of all parameter lists */
static LIST_HEAD ( parameters );

/**
* Find form parameter list by name
*
* @v name Parameter list name (may be NULL)
* @ret params Parameter list, or NULL if not found
*/
struct parameters * find_parameters ( const char *name ) {
struct parameters *params;

list_for_each_entry ( params, &parameters, list ) {
if ( ( params->name == name ) ||
( strcmp ( params->name, name ) == 0 ) ) {
return params;
}
}
return NULL;
}

/**
* Create form parameter list
*
* @v name Parameter list name (may be NULL)
* @ret params Parameter list, or NULL on failure
*/
struct parameters * create_parameters ( const char *name ) {
struct parameters *params;
size_t name_len;
char *name_copy;

/* Destroy any existing parameter list of this name */
params = find_parameters ( name );
if ( params )
destroy_parameters ( params );

/* Allocate parameter list */
name_len = ( name ? ( strlen ( name ) + 1 /* NUL */ ) : 0 );
params = zalloc ( sizeof ( *params ) + name_len );
if ( ! params )
return NULL;
name_copy = ( ( void * ) ( params + 1 ) );

/* Populate parameter list */
if ( name ) {
strcpy ( name_copy, name );
params->name = name_copy;
}
INIT_LIST_HEAD ( &params->entries );

/* Add to list of parameter lists */
list_add_tail ( &params->list, &parameters );

DBGC ( params, "PARAMS \"%s\" created\n", params->name );
return params;
}

/**
* Add form parameter
*
* @v params Parameter list
* @v key Parameter key
* @v value Parameter value
* @ret param Parameter, or NULL on failure
*/
struct parameter * add_parameter ( struct parameters *params,
const char *key, const char *value ) {
struct parameter *param;
size_t key_len;
size_t value_len;
char *key_copy;
char *value_copy;

/* Allocate parameter */
key_len = ( strlen ( key ) + 1 /* NUL */ );
value_len = ( strlen ( value ) + 1 /* NUL */ );
param = zalloc ( sizeof ( *param ) + key_len + value_len );
if ( ! param )
return NULL;
key_copy = ( ( void * ) ( param + 1 ) );
value_copy = ( key_copy + key_len );

/* Populate parameter */
strcpy ( key_copy, key );
param->key = key_copy;
strcpy ( value_copy, value );
param->value = value_copy;

/* Add to list of parameters */
list_add_tail ( &param->list, &params->entries );

DBGC ( params, "PARAMS \"%s\" added \"%s\"=\"%s\"\n",
params->name, param->key, param->value );
return param;
}

/**
* Destroy form parameter list
*
* @v params Parameter list
*/
void destroy_parameters ( struct parameters *params ) {
struct parameter *param;
struct parameter *tmp;

DBGC ( params, "PARAMS \"%s\" destroyed\n", params->name );

/* Free all parameters */
list_for_each_entry_safe ( param, tmp, &params->entries, list ) {
list_del ( &param->list );
free ( param );
}

/* Free parameter list */
list_del ( &params->list );
free ( params );
}

/**
* Claim ownership of form parameter list
*
* @v params Parameter list
*/
void claim_parameters ( struct parameters *params ) {

DBGC ( params, "PARAMS \"%s\" claimed\n", params->name );

/* Remove from list of parameter lists */
list_del ( &params->list );

/* Reinitialise list to allow for subsequent destroy_parameters() */
INIT_LIST_HEAD ( &params->list );
}
24 changes: 24 additions & 0 deletions src/core/parseopt.c
Expand Up @@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/netdevice.h>
#include <ipxe/menu.h>
#include <ipxe/settings.h>
#include <ipxe/params.h>
#include <ipxe/parseopt.h>

/** @file
Expand Down Expand Up @@ -250,6 +251,29 @@ int parse_autovivified_setting ( char *text, struct named_setting *setting ) {
return parse_setting ( text, setting, autovivify_child_settings );
}

/**
* Parse form parameter list name
*
* @v text Text
* @ret params Parameter list
* @ret rc Return status code
*/
int parse_parameters ( char *text, struct parameters **params ) {

/* Find parameter list */
*params = find_parameters ( text );
if ( ! *params ) {
if ( text ) {
printf ( "\"%s\": no such parameter list\n", text );
} else {
printf ( "No default parameter list\n" );
}
return -ENOENT;
}

return 0;
}

/**
* Print command usage message
*
Expand Down
31 changes: 30 additions & 1 deletion src/core/uri.c
Expand Up @@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <libgen.h>
#include <ctype.h>
#include <ipxe/vsprintf.h>
#include <ipxe/params.h>
#include <ipxe/uri.h>

/**
Expand Down Expand Up @@ -59,6 +60,21 @@ static void dump_uri ( struct uri *uri ) {
DBG ( " query \"%s\"", uri->query );
if ( uri->fragment )
DBG ( " fragment \"%s\"", uri->fragment );
if ( uri->params )
DBG ( " params \"%s\"", uri->params->name );
}

/**
* Free URI
*
* @v refcnt Reference count
*/
static void free_uri ( struct refcnt *refcnt ) {
struct uri *uri = container_of ( refcnt, struct uri, refcnt );

if ( uri->params )
destroy_parameters ( uri->params );
free ( uri );
}

/**
Expand All @@ -85,12 +101,25 @@ struct uri * parse_uri ( const char *uri_string ) {
uri = zalloc ( sizeof ( *uri ) + raw_len );
if ( ! uri )
return NULL;
ref_init ( &uri->refcnt, free_uri );
raw = ( ( ( char * ) uri ) + sizeof ( *uri ) );

/* Copy in the raw string */
memcpy ( raw, uri_string, raw_len );

/* Start by chopping off the fragment, if it exists */
/* Identify the parameter list, if present */
if ( ( tmp = strstr ( raw, "##params" ) ) ) {
*tmp = '\0';
tmp += 8 /* "##params" */;
uri->params = find_parameters ( *tmp ? ( tmp + 1 ) : NULL );
if ( uri->params ) {
claim_parameters ( uri->params );
} else {
/* Ignore non-existent submission blocks */
}
}

/* Chop off the fragment, if it exists */
if ( ( tmp = strchr ( raw, '#' ) ) ) {
*(tmp++) = '\0';
uri->fragment = tmp;
Expand Down
15 changes: 12 additions & 3 deletions src/drivers/net/3c90x.c
Expand Up @@ -346,11 +346,12 @@ static int a3c90x_transmit(struct net_device *netdev,
tx_cur_desc->DnNextPtr = 0;

/* FrameStartHeader differs in 90x and >= 90xB
* It contains length in 90x and a round up boundary and packet ID for
* 90xB and 90xC. We can leave this to 0 for 90xB and 90xC.
* It contains the packet length in 90x and a round up boundary and
* packet ID for 90xB and 90xC. Disable packet length round-up on the
* later revisions.
*/
tx_cur_desc->FrameStartHeader =
fshTxIndicate | (inf_3c90x->isBrev ? 0x00 : len);
fshTxIndicate | (inf_3c90x->isBrev ? fshRndupDefeat : len);

tx_cur_desc->DataAddr = virt_to_bus(iob->data);
tx_cur_desc->DataLength = len | downLastFrag;
Expand Down Expand Up @@ -813,10 +814,18 @@ static int a3c90x_open(struct net_device *netdev)
goto error;
}

a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdStallCtl, upStall);

/* send rx_ring address to NIC */
outl(virt_to_bus(inf_3c90x->rx_ring),
inf_3c90x->IOAddr + regUpListPtr_l);

a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdStallCtl, upUnStall);

/* set maximum allowed receive packet length */
a3c90x_internal_SetWindow(inf_3c90x, winTxRxOptions3);
outl(RX_BUF_SIZE, inf_3c90x->IOAddr + regMaxPktSize_3_w);

/* enable packet transmission and reception */
a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdTxEnable, 0);
a3c90x_internal_IssueCommand(inf_3c90x->IOAddr, cmdRxEnable, 0);
Expand Down
1 change: 1 addition & 0 deletions src/drivers/net/3c90x.h
Expand Up @@ -202,6 +202,7 @@ enum GlobalResetParams {
enum FrameStartHeader {
fshTxIndicate = 0x8000,
fshDnComplete = 0x10000,
fshRndupDefeat = 0x10000000,
};

enum UpDownDesc {
Expand Down

0 comments on commit 6dd2497

Please sign in to comment.