hermes.h 15.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* hermes.h
 *
 * Driver core for the "Hermes" wireless MAC controller, as used in
 * the Lucent Orinoco and Cabletron RoamAbout cards. It should also
 * work on the hfa3841 and hfa3842 MAC controller chips used in the
 * Prism I & II chipsets.
 *
 * This is not a complete driver, just low-level access routines for
 * the MAC controller itself.
 *
 * Based on the prism2 driver from Absolute Value Systems' linux-wlan
 * project, the Linux wvlan_cs driver, Lucent's HCF-Light
 * (wvlan_hcf.c) library, and the NetBSD wireless driver.
 *
 * Copyright (C) 2000, David Gibson, Linuxcare Australia.
 * (C) Copyright David Gibson, IBM Corp. 2001-2003.
 *
A
Andrey Borzenkov 已提交
18 19
 * Portions taken from hfa384x.h.
 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
L
Linus Torvalds 已提交
20 21 22 23 24 25 26 27 28 29 30
 *
 * This file distributed under the GPL, version 2.
 */

#ifndef _HERMES_H
#define _HERMES_H

/* Notes on locking:
 *
 * As a module of low level hardware access routines, there is no
 * locking. Users of this module should ensure that they serialize
31
 * access to the hermes structure, and to the hardware
L
Linus Torvalds 已提交
32 33 34
*/

#include <linux/if_ether.h>
A
Andrey Borzenkov 已提交
35
#include <linux/io.h>
L
Linus Torvalds 已提交
36 37 38 39 40 41 42 43 44 45

/*
 * Limits and constants
 */
#define		HERMES_ALLOC_LEN_MIN		(4)
#define		HERMES_ALLOC_LEN_MAX		(2400)
#define		HERMES_LTV_LEN_MAX		(34)
#define		HERMES_BAP_DATALEN_MAX		(4096)
#define		HERMES_BAP_OFFSET_MAX		(4096)
#define		HERMES_PORTID_MAX		(7)
46
#define		HERMES_NUMPORTS_MAX		(HERMES_PORTID_MAX + 1)
L
Linus Torvalds 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
#define		HERMES_PDR_LEN_MAX		(260)	/* in bytes, from EK */
#define		HERMES_PDA_RECS_MAX		(200)	/* a guess */
#define		HERMES_PDA_LEN_MAX		(1024)	/* in bytes, from EK */
#define		HERMES_SCANRESULT_MAX		(35)
#define		HERMES_CHINFORESULT_MAX		(8)
#define		HERMES_MAX_MULTICAST		(16)
#define		HERMES_MAGIC			(0x7d1f)

/*
 * Hermes register offsets
 */
#define		HERMES_CMD			(0x00)
#define		HERMES_PARAM0			(0x02)
#define		HERMES_PARAM1			(0x04)
#define		HERMES_PARAM2			(0x06)
#define		HERMES_STATUS			(0x08)
#define		HERMES_RESP0			(0x0A)
#define		HERMES_RESP1			(0x0C)
#define		HERMES_RESP2			(0x0E)
#define		HERMES_INFOFID			(0x10)
#define		HERMES_RXFID			(0x20)
#define		HERMES_ALLOCFID			(0x22)
#define		HERMES_TXCOMPLFID		(0x24)
#define		HERMES_SELECT0			(0x18)
#define		HERMES_OFFSET0			(0x1C)
#define		HERMES_DATA0			(0x36)
#define		HERMES_SELECT1			(0x1A)
#define		HERMES_OFFSET1			(0x1E)
#define		HERMES_DATA1			(0x38)
#define		HERMES_EVSTAT			(0x30)
#define		HERMES_INTEN			(0x32)
#define		HERMES_EVACK			(0x34)
#define		HERMES_CONTROL			(0x14)
#define		HERMES_SWSUPPORT0		(0x28)
#define		HERMES_SWSUPPORT1		(0x2A)
#define		HERMES_SWSUPPORT2		(0x2C)
#define		HERMES_AUXPAGE			(0x3A)
#define		HERMES_AUXOFFSET		(0x3C)
#define		HERMES_AUXDATA			(0x3E)

/*
 * CMD register bitmasks
 */
#define		HERMES_CMD_BUSY			(0x8000)
#define		HERMES_CMD_AINFO		(0x7f00)
#define		HERMES_CMD_MACPORT		(0x0700)
#define		HERMES_CMD_RECL			(0x0100)
#define		HERMES_CMD_WRITE		(0x0100)
#define		HERMES_CMD_PROGMODE		(0x0300)
#define		HERMES_CMD_CMDCODE		(0x003f)

/*
 * STATUS register bitmasks
 */
#define		HERMES_STATUS_RESULT		(0x7f00)
#define		HERMES_STATUS_CMDCODE		(0x003f)

/*
 * OFFSET register bitmasks
 */
#define		HERMES_OFFSET_BUSY		(0x8000)
#define		HERMES_OFFSET_ERR		(0x4000)
#define		HERMES_OFFSET_DATAOFF		(0x0ffe)

/*
 * Event register bitmasks (INTEN, EVSTAT, EVACK)
 */
#define		HERMES_EV_TICK			(0x8000)
#define		HERMES_EV_WTERR			(0x4000)
#define		HERMES_EV_INFDROP		(0x2000)
#define		HERMES_EV_INFO			(0x0080)
#define		HERMES_EV_DTIM			(0x0020)
#define		HERMES_EV_CMD			(0x0010)
#define		HERMES_EV_ALLOC			(0x0008)
#define		HERMES_EV_TXEXC			(0x0004)
#define		HERMES_EV_TX			(0x0002)
#define		HERMES_EV_RX			(0x0001)

/*
 * Command codes
 */
/*--- Controller Commands ----------------------------*/
#define		HERMES_CMD_INIT			(0x0000)
#define		HERMES_CMD_ENABLE		(0x0001)
#define		HERMES_CMD_DISABLE		(0x0002)
#define		HERMES_CMD_DIAG			(0x0003)

/*--- Buffer Mgmt Commands ---------------------------*/
#define		HERMES_CMD_ALLOC		(0x000A)
#define		HERMES_CMD_TX			(0x000B)

/*--- Regulate Commands ------------------------------*/
#define		HERMES_CMD_NOTIFY		(0x0010)
#define		HERMES_CMD_INQUIRE		(0x0011)

/*--- Configure Commands -----------------------------*/
#define		HERMES_CMD_ACCESS		(0x0021)
#define		HERMES_CMD_DOWNLD		(0x0022)

/*--- Serial I/O Commands ----------------------------*/
#define		HERMES_CMD_READMIF		(0x0030)
#define		HERMES_CMD_WRITEMIF		(0x0031)

/*--- Debugging Commands -----------------------------*/
151
#define		HERMES_CMD_TEST			(0x0038)
L
Linus Torvalds 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180


/* Test command arguments */
#define		HERMES_TEST_SET_CHANNEL		0x0800
#define		HERMES_TEST_MONITOR		0x0b00
#define		HERMES_TEST_STOP		0x0f00

/* Authentication algorithms */
#define		HERMES_AUTH_OPEN		1
#define		HERMES_AUTH_SHARED_KEY		2

/* WEP settings */
#define		HERMES_WEP_PRIVACY_INVOKED	0x0001
#define		HERMES_WEP_EXCL_UNENCRYPTED	0x0002
#define		HERMES_WEP_HOST_ENCRYPT		0x0010
#define		HERMES_WEP_HOST_DECRYPT		0x0080

/* Symbol hostscan options */
#define		HERMES_HOSTSCAN_SYMBOL_5SEC	0x0001
#define		HERMES_HOSTSCAN_SYMBOL_ONCE	0x0002
#define		HERMES_HOSTSCAN_SYMBOL_PASSIVE	0x0040
#define		HERMES_HOSTSCAN_SYMBOL_BCAST	0x0080

/*
 * Frame structures and constants
 */

#define HERMES_DESCRIPTOR_OFFSET	0
#define HERMES_802_11_OFFSET		(14)
181 182
#define HERMES_802_3_OFFSET		(14 + 32)
#define HERMES_802_2_OFFSET		(14 + 32 + 14)
183
#define HERMES_TXCNTL2_OFFSET		(HERMES_802_3_OFFSET - 2)
L
Linus Torvalds 已提交
184 185 186 187

#define HERMES_RXSTAT_ERR		(0x0003)
#define	HERMES_RXSTAT_BADCRC		(0x0001)
#define	HERMES_RXSTAT_UNDECRYPTABLE	(0x0002)
188
#define	HERMES_RXSTAT_MIC		(0x0010)	/* Frame contains MIC */
L
Linus Torvalds 已提交
189 190
#define	HERMES_RXSTAT_MACPORT		(0x0700)
#define HERMES_RXSTAT_PCF		(0x1000)	/* Frame was received in CF period */
191
#define	HERMES_RXSTAT_MIC_KEY_ID	(0x1800)	/* MIC key used */
L
Linus Torvalds 已提交
192 193 194 195 196
#define	HERMES_RXSTAT_MSGTYPE		(0xE000)
#define	HERMES_RXSTAT_1042		(0x2000)	/* RFC-1042 frame */
#define	HERMES_RXSTAT_TUNNEL		(0x4000)	/* bridge-tunnel encoded frame */
#define	HERMES_RXSTAT_WMP		(0x6000)	/* Wavelan-II Management Protocol frame */

197 198 199
/* Shift amount for key ID in RXSTAT and TXCTRL */
#define	HERMES_MIC_KEY_ID_SHIFT		11

L
Linus Torvalds 已提交
200
struct hermes_tx_descriptor {
201 202 203 204
	__le16 status;
	__le16 reserved1;
	__le16 reserved2;
	__le32 sw_support;
L
Linus Torvalds 已提交
205 206
	u8 retry_count;
	u8 tx_rate;
A
Andrey Borzenkov 已提交
207
	__le16 tx_control;
208
} __packed;
L
Linus Torvalds 已提交
209 210 211 212 213 214 215 216 217

#define HERMES_TXSTAT_RETRYERR		(0x0001)
#define HERMES_TXSTAT_AGEDERR		(0x0002)
#define HERMES_TXSTAT_DISCON		(0x0004)
#define HERMES_TXSTAT_FORMERR		(0x0008)

#define HERMES_TXCTRL_TX_OK		(0x0002)	/* ?? interrupt on Tx complete */
#define HERMES_TXCTRL_TX_EX		(0x0004)	/* ?? interrupt on Tx exception */
#define HERMES_TXCTRL_802_11		(0x0008)	/* We supply 802.11 header */
218 219
#define HERMES_TXCTRL_MIC		(0x0010)	/* 802.3 + TKIP */
#define HERMES_TXCTRL_MIC_KEY_ID	(0x1800)	/* MIC Key ID mask */
L
Linus Torvalds 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232
#define HERMES_TXCTRL_ALT_RTRY		(0x0020)

/* Inquiry constants and data types */

#define HERMES_INQ_TALLIES		(0xF100)
#define HERMES_INQ_SCAN			(0xF101)
#define HERMES_INQ_CHANNELINFO		(0xF102)
#define HERMES_INQ_HOSTSCAN		(0xF103)
#define HERMES_INQ_HOSTSCAN_SYMBOL	(0xF104)
#define HERMES_INQ_LINKSTATUS		(0xF200)
#define HERMES_INQ_SEC_STAT_AGERE	(0xF202)

struct hermes_tallies_frame {
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
	__le16 TxUnicastFrames;
	__le16 TxMulticastFrames;
	__le16 TxFragments;
	__le16 TxUnicastOctets;
	__le16 TxMulticastOctets;
	__le16 TxDeferredTransmissions;
	__le16 TxSingleRetryFrames;
	__le16 TxMultipleRetryFrames;
	__le16 TxRetryLimitExceeded;
	__le16 TxDiscards;
	__le16 RxUnicastFrames;
	__le16 RxMulticastFrames;
	__le16 RxFragments;
	__le16 RxUnicastOctets;
	__le16 RxMulticastOctets;
	__le16 RxFCSErrors;
	__le16 RxDiscards_NoBuffer;
	__le16 TxDiscardsWrongSA;
	__le16 RxWEPUndecryptable;
	__le16 RxMsgInMsgFragments;
	__le16 RxMsgInBadMsgFragments;
L
Linus Torvalds 已提交
254
	/* Those last are probably not available in very old firmwares */
255 256
	__le16 RxDiscards_WEPICVError;
	__le16 RxDiscards_WEPExcluded;
257
} __packed;
L
Linus Torvalds 已提交
258 259 260 261 262

/* Grabbed from wlan-ng - Thanks Mark... - Jean II
 * This is the result of a scan inquiry command */
/* Structure describing info about an Access Point */
struct prism2_scan_apinfo {
263 264 265
	__le16 channel;		/* Channel where the AP sits */
	__le16 noise;		/* Noise level */
	__le16 level;		/* Signal level */
L
Linus Torvalds 已提交
266
	u8 bssid[ETH_ALEN];	/* MAC address of the Access Point */
267 268 269
	__le16 beacon_interv;	/* Beacon interval */
	__le16 capabilities;	/* Capabilities */
	__le16 essid_len;	/* ESSID length */
L
Linus Torvalds 已提交
270 271
	u8 essid[32];		/* ESSID of the network */
	u8 rates[10];		/* Bit rate supported */
272 273
	__le16 proberesp_rate;	/* Data rate of the response frame */
	__le16 atim;		/* ATIM window time, Kus (hostscan only) */
274
} __packed;
L
Linus Torvalds 已提交
275 276 277 278

/* Same stuff for the Lucent/Agere card.
 * Thanks to h1kari <h1kari AT dachb0den.com> - Jean II */
struct agere_scan_apinfo {
279 280 281
	__le16 channel;		/* Channel where the AP sits */
	__le16 noise;		/* Noise level */
	__le16 level;		/* Signal level */
L
Linus Torvalds 已提交
282
	u8 bssid[ETH_ALEN];	/* MAC address of the Access Point */
283 284
	__le16 beacon_interv;	/* Beacon interval */
	__le16 capabilities;	/* Capabilities */
L
Linus Torvalds 已提交
285
	/* bits: 0-ess, 1-ibss, 4-privacy [wep] */
286
	__le16 essid_len;	/* ESSID length */
L
Linus Torvalds 已提交
287
	u8 essid[32];		/* ESSID of the network */
288
} __packed;
L
Linus Torvalds 已提交
289 290 291 292 293

/* Moustafa: Scan structure for Symbol cards */
struct symbol_scan_apinfo {
	u8 channel;		/* Channel where the AP sits */
	u8 unknown1;		/* 8 in 2.9x and 3.9x f/w, 0 otherwise */
294 295
	__le16 noise;		/* Noise level */
	__le16 level;		/* Signal level */
L
Linus Torvalds 已提交
296
	u8 bssid[ETH_ALEN];	/* MAC address of the Access Point */
297 298
	__le16 beacon_interv;	/* Beacon interval */
	__le16 capabilities;	/* Capabilities */
L
Linus Torvalds 已提交
299
	/* bits: 0-ess, 1-ibss, 4-privacy [wep] */
300
	__le16 essid_len;	/* ESSID length */
L
Linus Torvalds 已提交
301
	u8 essid[32];		/* ESSID of the network */
A
Andrey Borzenkov 已提交
302
	__le16 rates[5];	/* Bit rate supported */
303
	__le16 basic_rates;	/* Basic rates bitmask */
L
Linus Torvalds 已提交
304 305
	u8 unknown2[6];		/* Always FF:FF:FF:FF:00:00 */
	u8 unknown3[8];		/* Always 0, appeared in f/w 3.91-68 */
306
} __packed;
L
Linus Torvalds 已提交
307 308 309 310 311 312 313

union hermes_scan_info {
	struct agere_scan_apinfo	a;
	struct prism2_scan_apinfo	p;
	struct symbol_scan_apinfo	s;
};

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
/* Extended scan struct for HERMES_INQ_CHANNELINFO.
 * wl_lkm calls this an ACS scan (Automatic Channel Select).
 * Keep out of union hermes_scan_info because it is much bigger than
 * the older scan structures. */
struct agere_ext_scan_info {
	__le16	reserved0;

	u8	noise;
	u8	level;
	u8	rx_flow;
	u8	rate;
	__le16	reserved1[2];

	__le16	frame_control;
	__le16	dur_id;
	u8	addr1[ETH_ALEN];
	u8	addr2[ETH_ALEN];
	u8	bssid[ETH_ALEN];
	__le16	sequence;
	u8	addr4[ETH_ALEN];

	__le16	data_length;

	/* Next 3 fields do not get filled in. */
	u8	daddr[ETH_ALEN];
	u8	saddr[ETH_ALEN];
	__le16	len_type;

	__le64	timestamp;
	__le16	beacon_interval;
	__le16	capabilities;
345
	u8	data[0];
346
} __packed;
347

A
Andrey Borzenkov 已提交
348
#define HERMES_LINKSTATUS_NOT_CONNECTED   (0x0000)
L
Linus Torvalds 已提交
349 350 351 352 353 354
#define HERMES_LINKSTATUS_CONNECTED       (0x0001)
#define HERMES_LINKSTATUS_DISCONNECTED    (0x0002)
#define HERMES_LINKSTATUS_AP_CHANGE       (0x0003)
#define HERMES_LINKSTATUS_AP_OUT_OF_RANGE (0x0004)
#define HERMES_LINKSTATUS_AP_IN_RANGE     (0x0005)
#define HERMES_LINKSTATUS_ASSOC_FAILED    (0x0006)
A
Andrey Borzenkov 已提交
355

L
Linus Torvalds 已提交
356
struct hermes_linkstatus {
357
	__le16 linkstatus;         /* Link status */
358
} __packed;
L
Linus Torvalds 已提交
359 360 361 362 363 364 365

struct hermes_response {
	u16 status, resp0, resp1, resp2;
};

/* "ID" structure - used for ESSID and station nickname */
struct hermes_idstring {
366 367
	__le16 len;
	__le16 val[16];
368
} __packed;
L
Linus Torvalds 已提交
369 370 371

struct hermes_multicast {
	u8 addr[HERMES_MAX_MULTICAST][ETH_ALEN];
372
} __packed;
L
Linus Torvalds 已提交
373 374 375 376

/* Timeouts */
#define HERMES_BAP_BUSY_TIMEOUT (10000) /* In iterations of ~1us */

D
David Kilroy 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
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);
396 397 398 399 400 401
	int (*read_pda)(struct hermes *hw, __le16 *pda,
			u32 pda_addr, u16 pda_len);
	int (*program_init)(struct hermes *hw, u32 entry_point);
	int (*program_end)(struct hermes *hw);
	int (*program)(struct hermes *hw, const char *buf,
		       u32 addr, u32 len);
402 403 404 405
	void (*lock_irqsave)(spinlock_t *lock, unsigned long *flags);
	void (*unlock_irqrestore)(spinlock_t *lock, unsigned long *flags);
	void (*lock_irq)(spinlock_t *lock);
	void (*unlock_irq)(spinlock_t *lock);
D
David Kilroy 已提交
406 407
};

L
Linus Torvalds 已提交
408
/* Basic control structure */
409
struct hermes {
L
Linus Torvalds 已提交
410 411 412 413 414
	void __iomem *iobase;
	int reg_spacing;
#define HERMES_16BIT_REGSPACING	0
#define HERMES_32BIT_REGSPACING	1
	u16 inten; /* Which interrupts should be enabled? */
415
	bool eeprom_pda;
D
David Kilroy 已提交
416
	const struct hermes_ops *ops;
D
David Kilroy 已提交
417
	void *priv;
418
};
L
Linus Torvalds 已提交
419 420 421

/* Register access convenience macros */
#define hermes_read_reg(hw, off) \
A
Andrey Borzenkov 已提交
422
	(ioread16((hw)->iobase + ((off) << (hw)->reg_spacing)))
L
Linus Torvalds 已提交
423 424 425
#define hermes_write_reg(hw, off, val) \
	(iowrite16((val), (hw)->iobase + ((off) << (hw)->reg_spacing)))
#define hermes_read_regn(hw, name) hermes_read_reg((hw), HERMES_##name)
A
Andrey Borzenkov 已提交
426 427
#define hermes_write_regn(hw, name, val) \
	hermes_write_reg((hw), HERMES_##name, (val))
L
Linus Torvalds 已提交
428 429

/* Function prototypes */
430 431
void hermes_struct_init(struct hermes *hw, void __iomem *address,
			int reg_spacing);
L
Linus Torvalds 已提交
432 433 434

/* Inline functions */

435
static inline int hermes_present(struct hermes *hw)
L
Linus Torvalds 已提交
436 437 438 439
{
	return hermes_read_regn(hw, SWSUPPORT0) == HERMES_MAGIC;
}

440
static inline void hermes_set_irqmask(struct hermes *hw, u16 events)
L
Linus Torvalds 已提交
441 442 443 444 445
{
	hw->inten = events;
	hermes_write_regn(hw, INTEN, events);
}

446
static inline int hermes_enable_port(struct hermes *hw, int port)
L
Linus Torvalds 已提交
447
{
D
David Kilroy 已提交
448
	return hw->ops->cmd_wait(hw, HERMES_CMD_ENABLE | (port << 8),
L
Linus Torvalds 已提交
449 450 451
				 0, NULL);
}

452
static inline int hermes_disable_port(struct hermes *hw, int port)
L
Linus Torvalds 已提交
453
{
D
David Kilroy 已提交
454
	return hw->ops->cmd_wait(hw, HERMES_CMD_DISABLE | (port << 8),
L
Linus Torvalds 已提交
455 456 457 458 459
				 0, NULL);
}

/* Initiate an INQUIRE command (tallies or scan).  The result will come as an
 * information frame in __orinoco_ev_info() */
460
static inline int hermes_inquire(struct hermes *hw, u16 rid)
L
Linus Torvalds 已提交
461
{
D
David Kilroy 已提交
462
	return hw->ops->cmd_wait(hw, HERMES_CMD_INQUIRE, rid, NULL);
L
Linus Torvalds 已提交
463 464
}

465 466
#define HERMES_BYTES_TO_RECLEN(n) ((((n) + 1) / 2) + 1)
#define HERMES_RECLEN_TO_BYTES(n) (((n) - 1) * 2)
L
Linus Torvalds 已提交
467 468

/* Note that for the next two, the count is in 16-bit words, not bytes */
A
Andrey Borzenkov 已提交
469 470
static inline void hermes_read_words(struct hermes *hw, int off,
				     void *buf, unsigned count)
L
Linus Torvalds 已提交
471 472 473 474 475
{
	off = off << hw->reg_spacing;
	ioread16_rep(hw->iobase + off, buf, count);
}

476 477
static inline void hermes_write_bytes(struct hermes *hw, int off,
				      const char *buf, unsigned count)
L
Linus Torvalds 已提交
478 479
{
	off = off << hw->reg_spacing;
480 481 482
	iowrite16_rep(hw->iobase + off, buf, count >> 1);
	if (unlikely(count & 1))
		iowrite8(buf[count - 1], hw->iobase + off);
L
Linus Torvalds 已提交
483 484
}

A
Andrey Borzenkov 已提交
485 486
static inline void hermes_clear_words(struct hermes *hw, int off,
				      unsigned count)
L
Linus Torvalds 已提交
487 488 489 490 491 492 493 494 495 496
{
	unsigned i;

	off = off << hw->reg_spacing;

	for (i = 0; i < count; i++)
		iowrite16(0, hw->iobase + off);
}

#define HERMES_READ_RECORD(hw, bap, rid, buf) \
D
David Kilroy 已提交
497
	(hw->ops->read_ltv((hw), (bap), (rid), sizeof(*buf), NULL, (buf)))
L
Linus Torvalds 已提交
498
#define HERMES_WRITE_RECORD(hw, bap, rid, buf) \
D
David Kilroy 已提交
499 500
	(hw->ops->write_ltv((hw), (bap), (rid), \
			    HERMES_BYTES_TO_RECLEN(sizeof(*buf)), (buf)))
L
Linus Torvalds 已提交
501

502 503
static inline int hermes_read_wordrec(struct hermes *hw, int bap, u16 rid,
				      u16 *word)
L
Linus Torvalds 已提交
504
{
505
	__le16 rec;
L
Linus Torvalds 已提交
506 507 508 509 510 511 512
	int err;

	err = HERMES_READ_RECORD(hw, bap, rid, &rec);
	*word = le16_to_cpu(rec);
	return err;
}

513 514
static inline int hermes_write_wordrec(struct hermes *hw, int bap, u16 rid,
				       u16 word)
L
Linus Torvalds 已提交
515
{
516
	__le16 rec = cpu_to_le16(word);
L
Linus Torvalds 已提交
517 518 519 520
	return HERMES_WRITE_RECORD(hw, bap, rid, &rec);
}

#endif  /* _HERMES_H */