Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b42f2074 authored by David Kilroy's avatar David Kilroy Committed by John W. Linville
Browse files

orinoco: add hermes_ops



Pave the way for introducing USB alternative functions.

Force callers to dereference ops instead of providing wrappers.

Signed-off-by: default avatarDavid Kilroy <kilroyd@googlemail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent f7c65594
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
	ssleep(1);

	/* Reset it before we get the interrupt */
	hermes_init(hw);
	hw->ops->init(hw);

	if (request_irq(card->irq, orinoco_interrupt, 0, DRIVER_NAME, priv)) {
		printk(KERN_ERR PFX "Couldn't get IRQ %d\n", card->irq);
+1 −1
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ static int orinoco_set_channel(struct wiphy *wiphy,
	if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
		/* Fast channel change - no commit if successful */
		hermes_t *hw = &priv->hw;
		err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
		err = hw->ops->cmd_wait(hw, HERMES_CMD_TEST |
					    HERMES_TEST_SET_CHANNEL,
					channel, NULL);
	}
+1 −1
Original line number Diff line number Diff line
@@ -259,7 +259,7 @@ symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
	}

	/* Reset hermes chip and make sure it responds */
	ret = hermes_init(hw);
	ret = hw->ops->init(hw);

	/* hermes_reset() should return 0 with the secondary firmware */
	if (secondary && ret != 0)
+29 −23
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@

#endif /* ! HERMES_DEBUG */

static const struct hermes_ops hermes_ops_local;

/*
 * Internal functions
@@ -111,7 +112,7 @@ static int hermes_issue_cmd(hermes_t *hw, u16 cmd, u16 param0,
 */

/* For doing cmds that wipe the magic constant in SWSUPPORT0 */
int hermes_doicmd_wait(hermes_t *hw, u16 cmd,
static int hermes_doicmd_wait(hermes_t *hw, u16 cmd,
			      u16 parm0, u16 parm1, u16 parm2,
			      struct hermes_response *resp)
{
@@ -163,17 +164,17 @@ int hermes_doicmd_wait(hermes_t *hw, u16 cmd,
out:
	return err;
}
EXPORT_SYMBOL(hermes_doicmd_wait);

void hermes_struct_init(hermes_t *hw, void __iomem *address, int reg_spacing)
{
	hw->iobase = address;
	hw->reg_spacing = reg_spacing;
	hw->inten = 0x0;
	hw->ops = &hermes_ops_local;
}
EXPORT_SYMBOL(hermes_struct_init);

int hermes_init(hermes_t *hw)
static int hermes_init(hermes_t *hw)
{
	u16 reg;
	int err = 0;
@@ -217,7 +218,6 @@ int hermes_init(hermes_t *hw)

	return err;
}
EXPORT_SYMBOL(hermes_init);

/* Issue a command to the chip, and (busy!) wait for it to
 * complete.
@@ -228,7 +228,7 @@ EXPORT_SYMBOL(hermes_init);
 *     > 0 on error returned by the firmware
 *
 * Callable from any context, but locking is your problem. */
int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0,
static int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0,
			     struct hermes_response *resp)
{
	int err;
@@ -291,9 +291,8 @@ int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0,
 out:
	return err;
}
EXPORT_SYMBOL(hermes_docmd_wait);

int hermes_allocate(hermes_t *hw, u16 size, u16 *fid)
static int hermes_allocate(hermes_t *hw, u16 size, u16 *fid)
{
	int err = 0;
	int k;
@@ -333,7 +332,6 @@ int hermes_allocate(hermes_t *hw, u16 size, u16 *fid)

	return 0;
}
EXPORT_SYMBOL(hermes_allocate);

/* Set up a BAP to read a particular chunk of data from card's internal buffer.
 *
@@ -403,7 +401,7 @@ static int hermes_bap_seek(hermes_t *hw, int bap, u16 id, u16 offset)
 *       0 on success
 *     > 0 on error from firmware
 */
int hermes_bap_pread(hermes_t *hw, int bap, void *buf, int len,
static int hermes_bap_pread(hermes_t *hw, int bap, void *buf, int len,
			    u16 id, u16 offset)
{
	int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
@@ -422,7 +420,6 @@ int hermes_bap_pread(hermes_t *hw, int bap, void *buf, int len,
 out:
	return err;
}
EXPORT_SYMBOL(hermes_bap_pread);

/* Write a block of data to the chip's buffer, via the
 * BAP. Synchronization/serialization is the caller's problem.
@@ -432,7 +429,7 @@ EXPORT_SYMBOL(hermes_bap_pread);
 *       0 on success
 *     > 0 on error from firmware
 */
int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, int len,
static int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, int len,
			     u16 id, u16 offset)
{
	int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
@@ -451,7 +448,6 @@ int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, int len,
 out:
	return err;
}
EXPORT_SYMBOL(hermes_bap_pwrite);

/* Read a Length-Type-Value record from the card.
 *
@@ -461,7 +457,7 @@ EXPORT_SYMBOL(hermes_bap_pwrite);
 * practice.
 *
 * Callable from user or bh context.  */
int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned bufsize,
static int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned bufsize,
			   u16 *length, void *buf)
{
	int err = 0;
@@ -505,9 +501,8 @@ int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned bufsize,

	return 0;
}
EXPORT_SYMBOL(hermes_read_ltv);

int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
static int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
			    u16 length, const void *value)
{
	int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
@@ -533,4 +528,15 @@ int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,

	return err;
}
EXPORT_SYMBOL(hermes_write_ltv);

/* Hermes operations for local buses */
static const struct hermes_ops hermes_ops_local = {
	.init = hermes_init,
	.cmd_wait = hermes_docmd_wait,
	.init_cmd_wait = hermes_doicmd_wait,
	.allocate = hermes_allocate,
	.read_ltv = hermes_read_ltv,
	.write_ltv = hermes_write_ltv,
	.bap_pread = hermes_bap_pread,
	.bap_pwrite = hermes_bap_pwrite
};
+28 −22
Original line number Diff line number Diff line
@@ -374,6 +374,27 @@ struct hermes_multicast {
/* Timeouts */
#define HERMES_BAP_BUSY_TIMEOUT (10000) /* In iterations of ~1us */

struct hermes;

/* Functions to access hardware */
struct hermes_ops {
	int (*init)(struct hermes *hw);
	int (*cmd_wait)(struct hermes *hw, u16 cmd, u16 parm0,
			struct hermes_response *resp);
	int (*init_cmd_wait)(struct hermes *hw, u16 cmd,
			     u16 parm0, u16 parm1, u16 parm2,
			     struct hermes_response *resp);
	int (*allocate)(struct hermes *hw, u16 size, u16 *fid);
	int (*read_ltv)(struct hermes *hw, int bap, u16 rid, unsigned buflen,
			u16 *length, void *buf);
	int (*write_ltv)(struct hermes *hw, int bap, u16 rid,
			 u16 length, const void *value);
	int (*bap_pread)(struct hermes *hw, int bap, void *buf, int len,
			 u16 id, u16 offset);
	int (*bap_pwrite)(struct hermes *hw, int bap, const void *buf,
			  int len, u16 id, u16 offset);
};

/* Basic control structure */
typedef struct hermes {
	void __iomem *iobase;
@@ -381,6 +402,7 @@ typedef struct hermes {
#define HERMES_16BIT_REGSPACING	0
#define HERMES_32BIT_REGSPACING	1
	u16 inten; /* Which interrupts should be enabled? */
	const struct hermes_ops *ops;
} hermes_t;

/* Register access convenience macros */
@@ -394,22 +416,6 @@ typedef struct hermes {

/* Function prototypes */
void hermes_struct_init(hermes_t *hw, void __iomem *address, int reg_spacing);
int hermes_init(hermes_t *hw);
int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0,
		      struct hermes_response *resp);
int hermes_doicmd_wait(hermes_t *hw, u16 cmd,
		       u16 parm0, u16 parm1, u16 parm2,
		       struct hermes_response *resp);
int hermes_allocate(hermes_t *hw, u16 size, u16 *fid);

int hermes_bap_pread(hermes_t *hw, int bap, void *buf, int len,
		       u16 id, u16 offset);
int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, int len,
			u16 id, u16 offset);
int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned buflen,
		    u16 *length, void *buf);
int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
		      u16 length, const void *value);

/* Inline functions */

@@ -426,13 +432,13 @@ static inline void hermes_set_irqmask(hermes_t *hw, u16 events)

static inline int hermes_enable_port(hermes_t *hw, int port)
{
	return hermes_docmd_wait(hw, HERMES_CMD_ENABLE | (port << 8),
	return hw->ops->cmd_wait(hw, HERMES_CMD_ENABLE | (port << 8),
				 0, NULL);
}

static inline int hermes_disable_port(hermes_t *hw, int port)
{
	return hermes_docmd_wait(hw, HERMES_CMD_DISABLE | (port << 8),
	return hw->ops->cmd_wait(hw, HERMES_CMD_DISABLE | (port << 8),
				 0, NULL);
}

@@ -440,7 +446,7 @@ static inline int hermes_disable_port(hermes_t *hw, int port)
 * information frame in __orinoco_ev_info() */
static inline int hermes_inquire(hermes_t *hw, u16 rid)
{
	return hermes_docmd_wait(hw, HERMES_CMD_INQUIRE, rid, NULL);
	return hw->ops->cmd_wait(hw, HERMES_CMD_INQUIRE, rid, NULL);
}

#define HERMES_BYTES_TO_RECLEN(n) ((((n)+1)/2) + 1)
@@ -475,9 +481,9 @@ static inline void hermes_clear_words(struct hermes *hw, int off,
}

#define HERMES_READ_RECORD(hw, bap, rid, buf) \
	(hermes_read_ltv((hw), (bap), (rid), sizeof(*buf), NULL, (buf)))
	(hw->ops->read_ltv((hw), (bap), (rid), sizeof(*buf), NULL, (buf)))
#define HERMES_WRITE_RECORD(hw, bap, rid, buf) \
	(hermes_write_ltv((hw), (bap), (rid), \
	(hw->ops->write_ltv((hw), (bap), (rid), \
			    HERMES_BYTES_TO_RECLEN(sizeof(*buf)), (buf)))

static inline int hermes_read_wordrec(hermes_t *hw, int bap, u16 rid, u16 *word)
Loading