Skip to content

Commit

Permalink
orinoco: add hermes_ops
Browse files Browse the repository at this point in the history
Pave the way for introducing USB alternative functions.

Force callers to dereference ops instead of providing wrappers.

Signed-off-by: David Kilroy <kilroyd@googlemail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
David Kilroy authored and John W. Linville committed May 3, 2010
1 parent f7c6559 commit b42f207
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 140 deletions.
2 changes: 1 addition & 1 deletion drivers/net/wireless/orinoco/airport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/orinoco/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/orinoco/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 29 additions & 23 deletions drivers/net/wireless/orinoco/hermes.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

#endif /* ! HERMES_DEBUG */

static const struct hermes_ops hermes_ops_local;

/*
* Internal functions
Expand Down Expand Up @@ -111,9 +112,9 @@ 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,
u16 parm0, u16 parm1, u16 parm2,
struct hermes_response *resp)
static int hermes_doicmd_wait(hermes_t *hw, u16 cmd,
u16 parm0, u16 parm1, u16 parm2,
struct hermes_response *resp)
{
int err = 0;
int k;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -228,8 +228,8 @@ 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,
struct hermes_response *resp)
static int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0,
struct hermes_response *resp)
{
int err;
int k;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -403,8 +401,8 @@ 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,
u16 id, u16 offset)
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;
int err = 0;
Expand All @@ -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.
Expand All @@ -432,8 +429,8 @@ 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,
u16 id, u16 offset)
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;
int err = 0;
Expand All @@ -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.
*
Expand All @@ -461,8 +457,8 @@ 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,
u16 *length, void *buf)
static int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned bufsize,
u16 *length, void *buf)
{
int err = 0;
int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
Expand Down Expand Up @@ -505,10 +501,9 @@ 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,
u16 length, const void *value)
static int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
u16 length, const void *value)
{
int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
int err = 0;
Expand All @@ -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
};
50 changes: 28 additions & 22 deletions drivers/net/wireless/orinoco/hermes.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,35 @@ 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;
int reg_spacing;
#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 */
Expand All @@ -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 */

Expand All @@ -426,21 +432,21 @@ 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);
}

/* Initiate an INQUIRE command (tallies or scan). The result will come as an
* 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)
Expand Down Expand Up @@ -475,10 +481,10 @@ 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), \
HERMES_BYTES_TO_RECLEN(sizeof(*buf)), (buf)))
(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)
{
Expand Down
34 changes: 17 additions & 17 deletions drivers/net/wireless/orinoco/hermes_dld.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ int hermes_read_pda(hermes_t *hw,
/* PDA of spectrum symbol is in eeprom */

/* Issue command to read EEPROM */
ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
ret = hw->ops->cmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
if (ret)
return ret;
} else {
Expand Down Expand Up @@ -408,16 +408,16 @@ int hermesi_program_init(hermes_t *hw, u32 offset)
/* Acknowledge any outstanding command */
hermes_write_regn(hw, EVACK, 0xFFFF);

/* Using doicmd_wait rather than docmd_wait */
err = hermes_doicmd_wait(hw,
0x0100 | HERMES_CMD_INIT,
0, 0, 0, NULL);
/* Using init_cmd_wait rather than cmd_wait */
err = hw->ops->init_cmd_wait(hw,
0x0100 | HERMES_CMD_INIT,
0, 0, 0, NULL);
if (err)
return err;

err = hermes_doicmd_wait(hw,
0x0000 | HERMES_CMD_INIT,
0, 0, 0, NULL);
err = hw->ops->init_cmd_wait(hw,
0x0000 | HERMES_CMD_INIT,
0, 0, 0, NULL);
if (err)
return err;

Expand All @@ -428,12 +428,12 @@ int hermesi_program_init(hermes_t *hw, u32 offset)
return err;

pr_debug(PFX "Enabling volatile, EP 0x%08x\n", offset);
err = hermes_doicmd_wait(hw,
HERMES_PROGRAM_ENABLE_VOLATILE,
offset & 0xFFFFu,
offset >> 16,
0,
NULL);
err = hw->ops->init_cmd_wait(hw,
HERMES_PROGRAM_ENABLE_VOLATILE,
offset & 0xFFFFu,
offset >> 16,
0,
NULL);
pr_debug(PFX "PROGRAM_ENABLE returned %d\n", err);

return err;
Expand All @@ -451,7 +451,7 @@ int hermesi_program_end(hermes_t *hw)
int rc = 0;
int err;

rc = hermes_docmd_wait(hw, HERMES_PROGRAM_DISABLE, 0, &resp);
rc = hw->ops->cmd_wait(hw, HERMES_PROGRAM_DISABLE, 0, &resp);

pr_debug(PFX "PROGRAM_DISABLE returned %d, "
"r0 0x%04x, r1 0x%04x, r2 0x%04x\n",
Expand All @@ -468,8 +468,8 @@ int hermesi_program_end(hermes_t *hw)
hermes_write_regn(hw, EVACK, 0xFFFF);

/* Reinitialise, ignoring return */
(void) hermes_doicmd_wait(hw, 0x0000 | HERMES_CMD_INIT,
0, 0, 0, NULL);
(void) hw->ops->init_cmd_wait(hw, 0x0000 | HERMES_CMD_INIT,
0, 0, 0, NULL);

return rc ? rc : err;
}
Expand Down
Loading

0 comments on commit b42f207

Please sign in to comment.