aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/pcmcia/Kconfig9
-rw-r--r--drivers/char/pcmcia/Makefile2
-rw-r--r--drivers/char/pcmcia/ipwireless/Makefile10
-rw-r--r--drivers/char/pcmcia/ipwireless/hardware.c1787
-rw-r--r--drivers/char/pcmcia/ipwireless/hardware.h64
-rw-r--r--drivers/char/pcmcia/ipwireless/main.c501
-rw-r--r--drivers/char/pcmcia/ipwireless/main.h70
-rw-r--r--drivers/char/pcmcia/ipwireless/network.c512
-rw-r--r--drivers/char/pcmcia/ipwireless/network.h55
-rw-r--r--drivers/char/pcmcia/ipwireless/setup_protocol.h108
-rw-r--r--drivers/char/pcmcia/ipwireless/tty.c688
-rw-r--r--drivers/char/pcmcia/ipwireless/tty.h48
-rw-r--r--drivers/firmware/dmi_scan.c62
-rw-r--r--drivers/hwmon/Kconfig30
-rw-r--r--drivers/hwmon/Makefile2
-rw-r--r--drivers/hwmon/abituguru3.c1
-rw-r--r--drivers/hwmon/adm1021.c1
-rw-r--r--drivers/hwmon/adm1025.c393
-rw-r--r--drivers/hwmon/adm1026.c632
-rw-r--r--drivers/hwmon/adm1031.c501
-rw-r--r--drivers/hwmon/adm9240.c27
-rw-r--r--drivers/hwmon/ads7828.c297
-rw-r--r--drivers/hwmon/adt7470.c100
-rw-r--r--drivers/hwmon/asb100.c395
-rw-r--r--drivers/hwmon/dme1737.c23
-rw-r--r--drivers/hwmon/ds1621.c1
-rw-r--r--drivers/hwmon/f71805f.c6
-rw-r--r--drivers/hwmon/f71882fg.c6
-rw-r--r--drivers/hwmon/fscher.c1
-rw-r--r--drivers/hwmon/fschmd.c94
-rw-r--r--drivers/hwmon/fscpos.c1
-rw-r--r--drivers/hwmon/gl518sm.c269
-rw-r--r--drivers/hwmon/gl520sm.c648
-rw-r--r--drivers/hwmon/it87.c88
-rw-r--r--drivers/hwmon/lm75.c1
-rw-r--r--drivers/hwmon/lm77.c20
-rw-r--r--drivers/hwmon/lm78.c7
-rw-r--r--drivers/hwmon/lm80.c328
-rw-r--r--drivers/hwmon/lm83.c1
-rw-r--r--drivers/hwmon/lm85.c64
-rw-r--r--drivers/hwmon/lm87.c29
-rw-r--r--drivers/hwmon/lm90.c27
-rw-r--r--drivers/hwmon/lm92.c1
-rw-r--r--drivers/hwmon/pc87360.c6
-rw-r--r--drivers/hwmon/pc87427.c6
-rw-r--r--drivers/hwmon/smsc47b397.c6
-rw-r--r--drivers/hwmon/smsc47m1.c6
-rw-r--r--drivers/hwmon/smsc47m192.c3
-rw-r--r--drivers/hwmon/vt1211.c8
-rw-r--r--drivers/hwmon/vt8231.c2
-rw-r--r--drivers/hwmon/w83627ehf.c29
-rw-r--r--drivers/hwmon/w83627hf.c225
-rw-r--r--drivers/hwmon/w83781d.c49
-rw-r--r--drivers/hwmon/w83791d.c6
-rw-r--r--drivers/hwmon/w83793.c13
-rw-r--r--drivers/hwmon/w83l785ts.c1
-rw-r--r--drivers/hwmon/w83l786ng.c821
-rw-r--r--drivers/i2c/chips/eeprom.c1
-rw-r--r--drivers/i2c/chips/pcf8574.c1
-rw-r--r--drivers/i2c/chips/pcf8591.c1
-rw-r--r--drivers/misc/Kconfig9
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/enclosure.c484
-rw-r--r--drivers/scsi/Kconfig93
-rw-r--r--drivers/scsi/Makefile12
-rw-r--r--drivers/scsi/NCR53C9x.c3654
-rw-r--r--drivers/scsi/NCR53C9x.h668
-rw-r--r--drivers/scsi/aacraid/aachba.c81
-rw-r--r--drivers/scsi/aacraid/commctrl.c26
-rw-r--r--drivers/scsi/aacraid/linit.c28
-rw-r--r--drivers/scsi/advansys.c6
-rw-r--r--drivers/scsi/arcmsr/arcmsr.h4
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c87
-rw-r--r--drivers/scsi/arm/acornscsi.c14
-rw-r--r--drivers/scsi/arm/scsi.h87
-rw-r--r--drivers/scsi/blz1230.c353
-rw-r--r--drivers/scsi/blz2060.c306
-rw-r--r--drivers/scsi/cyberstorm.c377
-rw-r--r--drivers/scsi/cyberstormII.c314
-rw-r--r--drivers/scsi/dc395x.c2
-rw-r--r--drivers/scsi/dec_esp.c687
-rw-r--r--drivers/scsi/fastlane.c421
-rw-r--r--drivers/scsi/iscsi_tcp.c57
-rw-r--r--drivers/scsi/libiscsi.c137
-rw-r--r--drivers/scsi/mac_esp.c751
-rw-r--r--drivers/scsi/mca_53c9x.c520
-rw-r--r--drivers/scsi/oktagon_esp.c606
-rw-r--r--drivers/scsi/oktagon_io.S194
-rw-r--r--drivers/scsi/ps3rom.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c24
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h2
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h1
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c87
-rw-r--r--drivers/scsi/qla2xxx/qla_inline.h7
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c27
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c404
-rw-r--r--drivers/scsi/qla2xxx/qla_sup.c36
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h2
-rw-r--r--drivers/scsi/qla4xxx/ql4_init.c1
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c75
-rw-r--r--drivers/scsi/scsi.c5
-rw-r--r--drivers/scsi/scsi_lib.c1
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c238
-rw-r--r--drivers/scsi/sd.c34
-rw-r--r--drivers/scsi/ses.c689
-rw-r--r--drivers/scsi/sg.c23
-rw-r--r--drivers/scsi/sr.c49
-rw-r--r--drivers/scsi/sr.h1
-rw-r--r--drivers/scsi/sr_ioctl.c3
-rw-r--r--drivers/scsi/sun3x_esp.c546
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.c2
-rw-r--r--drivers/scsi/u14-34f.c2
113 files changed, 9667 insertions, 11669 deletions
diff --git a/drivers/char/pcmcia/Kconfig b/drivers/char/pcmcia/Kconfig
index f25facd97bb4..00b8a84b0319 100644
--- a/drivers/char/pcmcia/Kconfig
+++ b/drivers/char/pcmcia/Kconfig
@@ -43,5 +43,14 @@ config CARDMAN_4040
43 (http://www.omnikey.com/), or a current development version of OpenCT 43 (http://www.omnikey.com/), or a current development version of OpenCT
44 (http://www.opensc.org/). 44 (http://www.opensc.org/).
45 45
46config IPWIRELESS
47 tristate "IPWireless 3G UMTS PCMCIA card support"
48 depends on PCMCIA
49 select PPP
50 help
51 This is a driver for 3G UMTS PCMCIA card from IPWireless company. In
52 some countries (for example Czech Republic, T-Mobile ISP) this card
53 is shipped for service called UMTS 4G.
54
46endmenu 55endmenu
47 56
diff --git a/drivers/char/pcmcia/Makefile b/drivers/char/pcmcia/Makefile
index 0aae20985d57..be8f287aa398 100644
--- a/drivers/char/pcmcia/Makefile
+++ b/drivers/char/pcmcia/Makefile
@@ -4,6 +4,8 @@
4# Makefile for the Linux PCMCIA char device drivers. 4# Makefile for the Linux PCMCIA char device drivers.
5# 5#
6 6
7obj-y += ipwireless/
8
7obj-$(CONFIG_SYNCLINK_CS) += synclink_cs.o 9obj-$(CONFIG_SYNCLINK_CS) += synclink_cs.o
8obj-$(CONFIG_CARDMAN_4000) += cm4000_cs.o 10obj-$(CONFIG_CARDMAN_4000) += cm4000_cs.o
9obj-$(CONFIG_CARDMAN_4040) += cm4040_cs.o 11obj-$(CONFIG_CARDMAN_4040) += cm4040_cs.o
diff --git a/drivers/char/pcmcia/ipwireless/Makefile b/drivers/char/pcmcia/ipwireless/Makefile
new file mode 100644
index 000000000000..b71eb593643d
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/Makefile
@@ -0,0 +1,10 @@
1#
2# drivers/char/pcmcia/ipwireless/Makefile
3#
4# Makefile for the IPWireless driver
5#
6
7obj-$(CONFIG_IPWIRELESS) += ipwireless.o
8
9ipwireless-objs := hardware.o main.o network.o tty.o
10
diff --git a/drivers/char/pcmcia/ipwireless/hardware.c b/drivers/char/pcmcia/ipwireless/hardware.c
new file mode 100644
index 000000000000..1f978ff87fa8
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/hardware.c
@@ -0,0 +1,1787 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#include <linux/interrupt.h>
19#include <linux/io.h>
20#include <linux/irq.h>
21#include <linux/kernel.h>
22#include <linux/list.h>
23#include <linux/slab.h>
24
25#include "hardware.h"
26#include "setup_protocol.h"
27#include "network.h"
28#include "main.h"
29
30static void ipw_send_setup_packet(struct ipw_hardware *hw);
31static void handle_received_SETUP_packet(struct ipw_hardware *ipw,
32 unsigned int address,
33 unsigned char *data, int len,
34 int is_last);
35static void ipwireless_setup_timer(unsigned long data);
36static void handle_received_CTRL_packet(struct ipw_hardware *hw,
37 unsigned int channel_idx, unsigned char *data, int len);
38
39/*#define TIMING_DIAGNOSTICS*/
40
41#ifdef TIMING_DIAGNOSTICS
42
43static struct timing_stats {
44 unsigned long last_report_time;
45 unsigned long read_time;
46 unsigned long write_time;
47 unsigned long read_bytes;
48 unsigned long write_bytes;
49 unsigned long start_time;
50};
51
52static void start_timing(void)
53{
54 timing_stats.start_time = jiffies;
55}
56
57static void end_read_timing(unsigned length)
58{
59 timing_stats.read_time += (jiffies - start_time);
60 timing_stats.read_bytes += length + 2;
61 report_timing();
62}
63
64static void end_write_timing(unsigned length)
65{
66 timing_stats.write_time += (jiffies - start_time);
67 timing_stats.write_bytes += length + 2;
68 report_timing();
69}
70
71static void report_timing(void)
72{
73 unsigned long since = jiffies - timing_stats.last_report_time;
74
75 /* If it's been more than one second... */
76 if (since >= HZ) {
77 int first = (timing_stats.last_report_time == 0);
78
79 timing_stats.last_report_time = jiffies;
80 if (!first)
81 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
82 ": %u us elapsed - read %lu bytes in %u us, "
83 "wrote %lu bytes in %u us\n",
84 jiffies_to_usecs(since),
85 timing_stats.read_bytes,
86 jiffies_to_usecs(timing_stats.read_time),
87 timing_stats.write_bytes,
88 jiffies_to_usecs(timing_stats.write_time));
89
90 timing_stats.read_time = 0;
91 timing_stats.write_time = 0;
92 timing_stats.read_bytes = 0;
93 timing_stats.write_bytes = 0;
94 }
95}
96#else
97static void start_timing(void) { }
98static void end_read_timing(unsigned length) { }
99static void end_write_timing(unsigned length) { }
100#endif
101
102/* Imported IPW definitions */
103
104#define LL_MTU_V1 318
105#define LL_MTU_V2 250
106#define LL_MTU_MAX (LL_MTU_V1 > LL_MTU_V2 ? LL_MTU_V1 : LL_MTU_V2)
107
108#define PRIO_DATA 2
109#define PRIO_CTRL 1
110#define PRIO_SETUP 0
111
112/* Addresses */
113#define ADDR_SETUP_PROT 0
114
115/* Protocol ids */
116enum {
117 /* Identifier for the Com Data protocol */
118 TL_PROTOCOLID_COM_DATA = 0,
119
120 /* Identifier for the Com Control protocol */
121 TL_PROTOCOLID_COM_CTRL = 1,
122
123 /* Identifier for the Setup protocol */
124 TL_PROTOCOLID_SETUP = 2
125};
126
127/* Number of bytes in NL packet header (cannot do
128 * sizeof(nl_packet_header) since it's a bitfield) */
129#define NL_FIRST_PACKET_HEADER_SIZE 3
130
131/* Number of bytes in NL packet header (cannot do
132 * sizeof(nl_packet_header) since it's a bitfield) */
133#define NL_FOLLOWING_PACKET_HEADER_SIZE 1
134
135struct nl_first_packet_header {
136#if defined(__BIG_ENDIAN_BITFIELD)
137 unsigned char packet_rank:2;
138 unsigned char address:3;
139 unsigned char protocol:3;
140#else
141 unsigned char protocol:3;
142 unsigned char address:3;
143 unsigned char packet_rank:2;
144#endif
145 unsigned char length_lsb;
146 unsigned char length_msb;
147};
148
149struct nl_packet_header {
150#if defined(__BIG_ENDIAN_BITFIELD)
151 unsigned char packet_rank:2;
152 unsigned char address:3;
153 unsigned char protocol:3;
154#else
155 unsigned char protocol:3;
156 unsigned char address:3;
157 unsigned char packet_rank:2;
158#endif
159};
160
161/* Value of 'packet_rank' above */
162#define NL_INTERMEDIATE_PACKET 0x0
163#define NL_LAST_PACKET 0x1
164#define NL_FIRST_PACKET 0x2
165
166union nl_packet {
167 /* Network packet header of the first packet (a special case) */
168 struct nl_first_packet_header hdr_first;
169 /* Network packet header of the following packets (if any) */
170 struct nl_packet_header hdr;
171 /* Complete network packet (header + data) */
172 unsigned char rawpkt[LL_MTU_MAX];
173} __attribute__ ((__packed__));
174
175#define HW_VERSION_UNKNOWN -1
176#define HW_VERSION_1 1
177#define HW_VERSION_2 2
178
179/* IPW I/O ports */
180#define IOIER 0x00 /* Interrupt Enable Register */
181#define IOIR 0x02 /* Interrupt Source/ACK register */
182#define IODCR 0x04 /* Data Control Register */
183#define IODRR 0x06 /* Data Read Register */
184#define IODWR 0x08 /* Data Write Register */
185#define IOESR 0x0A /* Embedded Driver Status Register */
186#define IORXR 0x0C /* Rx Fifo Register (Host to Embedded) */
187#define IOTXR 0x0E /* Tx Fifo Register (Embedded to Host) */
188
189/* I/O ports and bit definitions for version 1 of the hardware */
190
191/* IER bits*/
192#define IER_RXENABLED 0x1
193#define IER_TXENABLED 0x2
194
195/* ISR bits */
196#define IR_RXINTR 0x1
197#define IR_TXINTR 0x2
198
199/* DCR bits */
200#define DCR_RXDONE 0x1
201#define DCR_TXDONE 0x2
202#define DCR_RXRESET 0x4
203#define DCR_TXRESET 0x8
204
205/* I/O ports and bit definitions for version 2 of the hardware */
206
207struct MEMCCR {
208 unsigned short reg_config_option; /* PCCOR: Configuration Option Register */
209 unsigned short reg_config_and_status; /* PCCSR: Configuration and Status Register */
210 unsigned short reg_pin_replacement; /* PCPRR: Pin Replacemant Register */
211 unsigned short reg_socket_and_copy; /* PCSCR: Socket and Copy Register */
212 unsigned short reg_ext_status; /* PCESR: Extendend Status Register */
213 unsigned short reg_io_base; /* PCIOB: I/O Base Register */
214};
215
216struct MEMINFREG {
217 unsigned short memreg_tx_old; /* TX Register (R/W) */
218 unsigned short pad1;
219 unsigned short memreg_rx_done; /* RXDone Register (R/W) */
220 unsigned short pad2;
221 unsigned short memreg_rx; /* RX Register (R/W) */
222 unsigned short pad3;
223 unsigned short memreg_pc_interrupt_ack; /* PC intr Ack Register (W) */
224 unsigned short pad4;
225 unsigned long memreg_card_present;/* Mask for Host to check (R) for
226 * CARD_PRESENT_VALUE */
227 unsigned short memreg_tx_new; /* TX2 (new) Register (R/W) */
228};
229
230#define IODMADPR 0x00 /* DMA Data Port Register (R/W) */
231
232#define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
233
234#define MEMTX_TX 0x0001
235#define MEMRX_RX 0x0001
236#define MEMRX_RX_DONE 0x0001
237#define MEMRX_PCINTACKK 0x0001
238#define MEMRX_MEMSPURIOUSINT 0x0001
239
240#define NL_NUM_OF_PRIORITIES 3
241#define NL_NUM_OF_PROTOCOLS 3
242#define NL_NUM_OF_ADDRESSES NO_OF_IPW_CHANNELS
243
244struct ipw_hardware {
245 unsigned int base_port;
246 short hw_version;
247 unsigned short ll_mtu;
248 spinlock_t spinlock;
249
250 int initializing;
251 int init_loops;
252 struct timer_list setup_timer;
253
254 int tx_ready;
255 struct list_head tx_queue[NL_NUM_OF_PRIORITIES];
256 /* True if any packets are queued for transmission */
257 int tx_queued;
258
259 int rx_bytes_queued;
260 struct list_head rx_queue;
261 /* Pool of rx_packet structures that are not currently used. */
262 struct list_head rx_pool;
263 int rx_pool_size;
264 /* True if reception of data is blocked while userspace processes it. */
265 int blocking_rx;
266 /* True if there is RX data ready on the hardware. */
267 int rx_ready;
268 unsigned short last_memtx_serial;
269 /*
270 * Newer versions of the V2 card firmware send serial numbers in the
271 * MemTX register. 'serial_number_detected' is set true when we detect
272 * a non-zero serial number (indicating the new firmware). Thereafter,
273 * the driver can safely ignore the Timer Recovery re-sends to avoid
274 * out-of-sync problems.
275 */
276 int serial_number_detected;
277 struct work_struct work_rx;
278
279 /* True if we are to send the set-up data to the hardware. */
280 int to_setup;
281
282 /* Card has been removed */
283 int removed;
284 /* Saved irq value when we disable the interrupt. */
285 int irq;
286 /* True if this driver is shutting down. */
287 int shutting_down;
288 /* Modem control lines */
289 unsigned int control_lines[NL_NUM_OF_ADDRESSES];
290 struct ipw_rx_packet *packet_assembler[NL_NUM_OF_ADDRESSES];
291
292 struct tasklet_struct tasklet;
293
294 /* The handle for the network layer, for the sending of events to it. */
295 struct ipw_network *network;
296 struct MEMINFREG __iomem *memory_info_regs;
297 struct MEMCCR __iomem *memregs_CCR;
298 void (*reboot_callback) (void *data);
299 void *reboot_callback_data;
300
301 unsigned short __iomem *memreg_tx;
302};
303
304/*
305 * Packet info structure for tx packets.
306 * Note: not all the fields defined here are required for all protocols
307 */
308struct ipw_tx_packet {
309 struct list_head queue;
310 /* channel idx + 1 */
311 unsigned char dest_addr;
312 /* SETUP, CTRL or DATA */
313 unsigned char protocol;
314 /* Length of data block, which starts at the end of this structure */
315 unsigned short length;
316 /* Sending state */
317 /* Offset of where we've sent up to so far */
318 unsigned long offset;
319 /* Count of packet fragments, starting at 0 */
320 int fragment_count;
321
322 /* Called after packet is sent and before is freed */
323 void (*packet_callback) (void *cb_data, unsigned int packet_length);
324 void *callback_data;
325};
326
327/* Signals from DTE */
328#define COMCTRL_RTS 0
329#define COMCTRL_DTR 1
330
331/* Signals from DCE */
332#define COMCTRL_CTS 2
333#define COMCTRL_DCD 3
334#define COMCTRL_DSR 4
335#define COMCTRL_RI 5
336
337struct ipw_control_packet_body {
338 /* DTE signal or DCE signal */
339 unsigned char sig_no;
340 /* 0: set signal, 1: clear signal */
341 unsigned char value;
342} __attribute__ ((__packed__));
343
344struct ipw_control_packet {
345 struct ipw_tx_packet header;
346 struct ipw_control_packet_body body;
347};
348
349struct ipw_rx_packet {
350 struct list_head queue;
351 unsigned int capacity;
352 unsigned int length;
353 unsigned int protocol;
354 unsigned int channel_idx;
355};
356
357#ifdef IPWIRELESS_STATE_DEBUG
358int ipwireless_dump_hardware_state(char *p, size_t limit,
359 struct ipw_hardware *hw)
360{
361 return snprintf(p, limit,
362 "debug: initializing=%d\n"
363 "debug: tx_ready=%d\n"
364 "debug: tx_queued=%d\n"
365 "debug: rx_ready=%d\n"
366 "debug: rx_bytes_queued=%d\n"
367 "debug: blocking_rx=%d\n"
368 "debug: removed=%d\n"
369 "debug: hardware.shutting_down=%d\n"
370 "debug: to_setup=%d\n",
371 hw->initializing,
372 hw->tx_ready,
373 hw->tx_queued,
374 hw->rx_ready,
375 hw->rx_bytes_queued,
376 hw->blocking_rx,
377 hw->removed,
378 hw->shutting_down,
379 hw->to_setup);
380}
381#endif
382
383static char *data_type(const unsigned char *buf, unsigned length)
384{
385 struct nl_packet_header *hdr = (struct nl_packet_header *) buf;
386
387 if (length == 0)
388 return " ";
389
390 if (hdr->packet_rank & NL_FIRST_PACKET) {
391 switch (hdr->protocol) {
392 case TL_PROTOCOLID_COM_DATA: return "DATA ";
393 case TL_PROTOCOLID_COM_CTRL: return "CTRL ";
394 case TL_PROTOCOLID_SETUP: return "SETUP";
395 default: return "???? ";
396 }
397 } else
398 return " ";
399}
400
401#define DUMP_MAX_BYTES 64
402
403static void dump_data_bytes(const char *type, const unsigned char *data,
404 unsigned length)
405{
406 char prefix[56];
407
408 sprintf(prefix, IPWIRELESS_PCCARD_NAME ": %s %s ",
409 type, data_type(data, length));
410 print_hex_dump_bytes(prefix, 0, (void *)data,
411 length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES);
412}
413
414static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
415 unsigned length)
416{
417 int i;
418 unsigned long flags;
419
420 start_timing();
421
422 if (length == 0)
423 return 0;
424
425 if (length > hw->ll_mtu)
426 return -1;
427
428 if (ipwireless_debug)
429 dump_data_bytes("send", data, length);
430
431 spin_lock_irqsave(&hw->spinlock, flags);
432
433 if (hw->hw_version == HW_VERSION_1) {
434 outw((unsigned short) length, hw->base_port + IODWR);
435
436 for (i = 0; i < length; i += 2) {
437 unsigned short d = data[i];
438 __le16 raw_data;
439
440 if (likely(i + 1 < length))
441 d |= data[i + 1] << 8;
442 raw_data = cpu_to_le16(d);
443 outw(raw_data, hw->base_port + IODWR);
444 }
445
446 outw(DCR_TXDONE, hw->base_port + IODCR);
447 } else if (hw->hw_version == HW_VERSION_2) {
448 outw((unsigned short) length, hw->base_port + IODMADPR);
449
450 for (i = 0; i < length; i += 2) {
451 unsigned short d = data[i];
452 __le16 raw_data;
453
454 if ((i + 1 < length))
455 d |= data[i + 1] << 8;
456 raw_data = cpu_to_le16(d);
457 outw(raw_data, hw->base_port + IODMADPR);
458 }
459 while ((i & 3) != 2) {
460 outw((unsigned short) 0xDEAD, hw->base_port + IODMADPR);
461 i += 2;
462 }
463 writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
464 }
465
466 spin_unlock_irqrestore(&hw->spinlock, flags);
467
468 end_write_timing(length);
469
470 return 0;
471}
472
473static int do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
474{
475 unsigned short fragment_data_len;
476 unsigned short data_left = packet->length - packet->offset;
477 unsigned short header_size;
478 union nl_packet pkt;
479
480 header_size =
481 (packet->fragment_count == 0)
482 ? NL_FIRST_PACKET_HEADER_SIZE
483 : NL_FOLLOWING_PACKET_HEADER_SIZE;
484 fragment_data_len = hw->ll_mtu - header_size;
485 if (data_left < fragment_data_len)
486 fragment_data_len = data_left;
487
488 pkt.hdr_first.protocol = packet->protocol;
489 pkt.hdr_first.address = packet->dest_addr;
490 pkt.hdr_first.packet_rank = 0;
491
492 /* First packet? */
493 if (packet->fragment_count == 0) {
494 pkt.hdr_first.packet_rank |= NL_FIRST_PACKET;
495 pkt.hdr_first.length_lsb = (unsigned char) packet->length;
496 pkt.hdr_first.length_msb =
497 (unsigned char) (packet->length >> 8);
498 }
499
500 memcpy(pkt.rawpkt + header_size,
501 ((unsigned char *) packet) + sizeof(struct ipw_tx_packet) +
502 packet->offset, fragment_data_len);
503 packet->offset += fragment_data_len;
504 packet->fragment_count++;
505
506 /* Last packet? (May also be first packet.) */
507 if (packet->offset == packet->length)
508 pkt.hdr_first.packet_rank |= NL_LAST_PACKET;
509 do_send_fragment(hw, pkt.rawpkt, header_size + fragment_data_len);
510
511 /* If this packet has unsent data, then re-queue it. */
512 if (packet->offset < packet->length) {
513 /*
514 * Re-queue it at the head of the highest priority queue so
515 * it goes before all other packets
516 */
517 unsigned long flags;
518
519 spin_lock_irqsave(&hw->spinlock, flags);
520 list_add(&packet->queue, &hw->tx_queue[0]);
521 spin_unlock_irqrestore(&hw->spinlock, flags);
522 } else {
523 if (packet->packet_callback)
524 packet->packet_callback(packet->callback_data,
525 packet->length);
526 kfree(packet);
527 }
528
529 return 0;
530}
531
532static void ipw_setup_hardware(struct ipw_hardware *hw)
533{
534 unsigned long flags;
535
536 spin_lock_irqsave(&hw->spinlock, flags);
537 if (hw->hw_version == HW_VERSION_1) {
538 /* Reset RX FIFO */
539 outw(DCR_RXRESET, hw->base_port + IODCR);
540 /* SB: Reset TX FIFO */
541 outw(DCR_TXRESET, hw->base_port + IODCR);
542
543 /* Enable TX and RX interrupts. */
544 outw(IER_TXENABLED | IER_RXENABLED, hw->base_port + IOIER);
545 } else {
546 /*
547 * Set INTRACK bit (bit 0), which means we must explicitly
548 * acknowledge interrupts by clearing bit 2 of reg_config_and_status.
549 */
550 unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
551
552 csr |= 1;
553 writew(csr, &hw->memregs_CCR->reg_config_and_status);
554 }
555 spin_unlock_irqrestore(&hw->spinlock, flags);
556}
557
558/*
559 * If 'packet' is NULL, then this function allocates a new packet, setting its
560 * length to 0 and ensuring it has the specified minimum amount of free space.
561 *
562 * If 'packet' is not NULL, then this function enlarges it if it doesn't
563 * have the specified minimum amount of free space.
564 *
565 */
566static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
567 struct ipw_rx_packet *packet,
568 int minimum_free_space)
569{
570
571 if (!packet) {
572 unsigned long flags;
573
574 /*
575 * If this is the first fragment, then we will need to fetch a
576 * packet to put it in.
577 */
578 spin_lock_irqsave(&hw->spinlock, flags);
579 /* If we have one in our pool, then pull it out. */
580 if (!list_empty(&hw->rx_pool)) {
581 packet = list_first_entry(&hw->rx_pool,
582 struct ipw_rx_packet, queue);
583 list_del(&packet->queue);
584 hw->rx_pool_size--;
585 spin_unlock_irqrestore(&hw->spinlock, flags);
586 } else {
587 /* Otherwise allocate a new one. */
588 static int min_capacity = 256;
589 int new_capacity;
590
591 spin_unlock_irqrestore(&hw->spinlock, flags);
592 new_capacity =
593 minimum_free_space > min_capacity
594 ? minimum_free_space
595 : min_capacity;
596 packet = kmalloc(sizeof(struct ipw_rx_packet)
597 + new_capacity, GFP_ATOMIC);
598 if (!packet)
599 return NULL;
600 packet->capacity = new_capacity;
601 }
602 packet->length = 0;
603 }
604
605 /*
606 * If this packet does not have sufficient capacity for the data we
607 * want to add, then make it bigger.
608 */
609 if (packet->length + minimum_free_space > packet->capacity) {
610 struct ipw_rx_packet *old_packet = packet;
611
612 packet = kmalloc(sizeof(struct ipw_rx_packet) +
613 old_packet->length + minimum_free_space,
614 GFP_ATOMIC);
615 if (!packet)
616 return NULL;
617 memcpy(packet, old_packet,
618 sizeof(struct ipw_rx_packet)
619 + old_packet->length);
620 packet->capacity = old_packet->length + minimum_free_space;
621 kfree(old_packet);
622 }
623
624 return packet;
625}
626
627static void pool_free(struct ipw_hardware *hw, struct ipw_rx_packet *packet)
628{
629 if (hw->rx_pool_size > 6)
630 kfree(packet);
631 else {
632 hw->rx_pool_size++;
633 list_add_tail(&packet->queue, &hw->rx_pool);
634 }
635}
636
637static void queue_received_packet(struct ipw_hardware *hw,
638 unsigned int protocol, unsigned int address,
639 unsigned char *data, int length, int is_last)
640{
641 unsigned int channel_idx = address - 1;
642 struct ipw_rx_packet *packet = NULL;
643 unsigned long flags;
644
645 /* Discard packet if channel index is out of range. */
646 if (channel_idx >= NL_NUM_OF_ADDRESSES) {
647 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
648 ": data packet has bad address %u\n", address);
649 return;
650 }
651
652 /*
653 * ->packet_assembler is safe to touch unlocked, this is the only place
654 */
655 if (protocol == TL_PROTOCOLID_COM_DATA) {
656 struct ipw_rx_packet **assem =
657 &hw->packet_assembler[channel_idx];
658
659 /*
660 * Create a new packet, or assembler already contains one
661 * enlarge it by 'length' bytes.
662 */
663 (*assem) = pool_allocate(hw, *assem, length);
664 if (!(*assem)) {
665 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
666 ": no memory for incomming data packet, dropped!\n");
667 return;
668 }
669 (*assem)->protocol = protocol;
670 (*assem)->channel_idx = channel_idx;
671
672 /* Append this packet data onto existing data. */
673 memcpy((unsigned char *)(*assem) +
674 sizeof(struct ipw_rx_packet)
675 + (*assem)->length, data, length);
676 (*assem)->length += length;
677 if (is_last) {
678 packet = *assem;
679 *assem = NULL;
680 /* Count queued DATA bytes only */
681 spin_lock_irqsave(&hw->spinlock, flags);
682 hw->rx_bytes_queued += packet->length;
683 spin_unlock_irqrestore(&hw->spinlock, flags);
684 }
685 } else {
686 /* If it's a CTRL packet, don't assemble, just queue it. */
687 packet = pool_allocate(hw, NULL, length);
688 if (!packet) {
689 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
690 ": no memory for incomming ctrl packet, dropped!\n");
691 return;
692 }
693 packet->protocol = protocol;
694 packet->channel_idx = channel_idx;
695 memcpy((unsigned char *)packet + sizeof(struct ipw_rx_packet),
696 data, length);
697 packet->length = length;
698 }
699
700 /*
701 * If this is the last packet, then send the assembled packet on to the
702 * network layer.
703 */
704 if (packet) {
705 spin_lock_irqsave(&hw->spinlock, flags);
706 list_add_tail(&packet->queue, &hw->rx_queue);
707 /* Block reception of incoming packets if queue is full. */
708 hw->blocking_rx =
709 hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
710
711 spin_unlock_irqrestore(&hw->spinlock, flags);
712 schedule_work(&hw->work_rx);
713 }
714}
715
716/*
717 * Workqueue callback
718 */
719static void ipw_receive_data_work(struct work_struct *work_rx)
720{
721 struct ipw_hardware *hw =
722 container_of(work_rx, struct ipw_hardware, work_rx);
723 unsigned long flags;
724
725 spin_lock_irqsave(&hw->spinlock, flags);
726 while (!list_empty(&hw->rx_queue)) {
727 struct ipw_rx_packet *packet =
728 list_first_entry(&hw->rx_queue,
729 struct ipw_rx_packet, queue);
730
731 if (hw->shutting_down)
732 break;
733 list_del(&packet->queue);
734
735 /*
736 * Note: ipwireless_network_packet_received must be called in a
737 * process context (i.e. via schedule_work) because the tty
738 * output code can sleep in the tty_flip_buffer_push call.
739 */
740 if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
741 if (hw->network != NULL) {
742 /* If the network hasn't been disconnected. */
743 spin_unlock_irqrestore(&hw->spinlock, flags);
744 /*
745 * This must run unlocked due to tty processing
746 * and mutex locking
747 */
748 ipwireless_network_packet_received(
749 hw->network,
750 packet->channel_idx,
751 (unsigned char *)packet
752 + sizeof(struct ipw_rx_packet),
753 packet->length);
754 spin_lock_irqsave(&hw->spinlock, flags);
755 }
756 /* Count queued DATA bytes only */
757 hw->rx_bytes_queued -= packet->length;
758 } else {
759 /*
760 * This is safe to be called locked, callchain does
761 * not block
762 */
763 handle_received_CTRL_packet(hw, packet->channel_idx,
764 (unsigned char *)packet
765 + sizeof(struct ipw_rx_packet),
766 packet->length);
767 }
768 pool_free(hw, packet);
769 /*
770 * Unblock reception of incoming packets if queue is no longer
771 * full.
772 */
773 hw->blocking_rx =
774 hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
775 if (hw->shutting_down)
776 break;
777 }
778 spin_unlock_irqrestore(&hw->spinlock, flags);
779}
780
781static void handle_received_CTRL_packet(struct ipw_hardware *hw,
782 unsigned int channel_idx,
783 unsigned char *data, int len)
784{
785 struct ipw_control_packet_body *body =
786 (struct ipw_control_packet_body *) data;
787 unsigned int changed_mask;
788
789 if (len != sizeof(struct ipw_control_packet_body)) {
790 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
791 ": control packet was %d bytes - wrong size!\n",
792 len);
793 return;
794 }
795
796 switch (body->sig_no) {
797 case COMCTRL_CTS:
798 changed_mask = IPW_CONTROL_LINE_CTS;
799 break;
800 case COMCTRL_DCD:
801 changed_mask = IPW_CONTROL_LINE_DCD;
802 break;
803 case COMCTRL_DSR:
804 changed_mask = IPW_CONTROL_LINE_DSR;
805 break;
806 case COMCTRL_RI:
807 changed_mask = IPW_CONTROL_LINE_RI;
808 break;
809 default:
810 changed_mask = 0;
811 }
812
813 if (changed_mask != 0) {
814 if (body->value)
815 hw->control_lines[channel_idx] |= changed_mask;
816 else
817 hw->control_lines[channel_idx] &= ~changed_mask;
818 if (hw->network)
819 ipwireless_network_notify_control_line_change(
820 hw->network,
821 channel_idx,
822 hw->control_lines[channel_idx],
823 changed_mask);
824 }
825}
826
827static void handle_received_packet(struct ipw_hardware *hw,
828 union nl_packet *packet,
829 unsigned short len)
830{
831 unsigned int protocol = packet->hdr.protocol;
832 unsigned int address = packet->hdr.address;
833 unsigned int header_length;
834 unsigned char *data;
835 unsigned int data_len;
836 int is_last = packet->hdr.packet_rank & NL_LAST_PACKET;
837
838 if (packet->hdr.packet_rank & NL_FIRST_PACKET)
839 header_length = NL_FIRST_PACKET_HEADER_SIZE;
840 else
841 header_length = NL_FOLLOWING_PACKET_HEADER_SIZE;
842
843 data = packet->rawpkt + header_length;
844 data_len = len - header_length;
845 switch (protocol) {
846 case TL_PROTOCOLID_COM_DATA:
847 case TL_PROTOCOLID_COM_CTRL:
848 queue_received_packet(hw, protocol, address, data, data_len,
849 is_last);
850 break;
851 case TL_PROTOCOLID_SETUP:
852 handle_received_SETUP_packet(hw, address, data, data_len,
853 is_last);
854 break;
855 }
856}
857
858static void acknowledge_data_read(struct ipw_hardware *hw)
859{
860 if (hw->hw_version == HW_VERSION_1)
861 outw(DCR_RXDONE, hw->base_port + IODCR);
862 else
863 writew(MEMRX_PCINTACKK,
864 &hw->memory_info_regs->memreg_pc_interrupt_ack);
865}
866
867/*
868 * Retrieve a packet from the IPW hardware.
869 */
870static void do_receive_packet(struct ipw_hardware *hw)
871{
872 unsigned len;
873 unsigned int i;
874 unsigned char pkt[LL_MTU_MAX];
875
876 start_timing();
877
878 if (hw->hw_version == HW_VERSION_1) {
879 len = inw(hw->base_port + IODRR);
880 if (len > hw->ll_mtu) {
881 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
882 ": received a packet of %u bytes - "
883 "longer than the MTU!\n", len);
884 outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR);
885 return;
886 }
887
888 for (i = 0; i < len; i += 2) {
889 __le16 raw_data = inw(hw->base_port + IODRR);
890 unsigned short data = le16_to_cpu(raw_data);
891
892 pkt[i] = (unsigned char) data;
893 pkt[i + 1] = (unsigned char) (data >> 8);
894 }
895 } else {
896 len = inw(hw->base_port + IODMADPR);
897 if (len > hw->ll_mtu) {
898 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
899 ": received a packet of %u bytes - "
900 "longer than the MTU!\n", len);
901 writew(MEMRX_PCINTACKK,
902 &hw->memory_info_regs->memreg_pc_interrupt_ack);
903 return;
904 }
905
906 for (i = 0; i < len; i += 2) {
907 __le16 raw_data = inw(hw->base_port + IODMADPR);
908 unsigned short data = le16_to_cpu(raw_data);
909
910 pkt[i] = (unsigned char) data;
911 pkt[i + 1] = (unsigned char) (data >> 8);
912 }
913
914 while ((i & 3) != 2) {
915 inw(hw->base_port + IODMADPR);
916 i += 2;
917 }
918 }
919
920 acknowledge_data_read(hw);
921
922 if (ipwireless_debug)
923 dump_data_bytes("recv", pkt, len);
924
925 handle_received_packet(hw, (union nl_packet *) pkt, len);
926
927 end_read_timing(len);
928}
929
930static int get_current_packet_priority(struct ipw_hardware *hw)
931{
932 /*
933 * If we're initializing, don't send anything of higher priority than
934 * PRIO_SETUP. The network layer therefore need not care about
935 * hardware initialization - any of its stuff will simply be queued
936 * until setup is complete.
937 */
938 return (hw->to_setup || hw->initializing
939 ? PRIO_SETUP + 1 :
940 NL_NUM_OF_PRIORITIES);
941}
942
943/*
944 * return 1 if something has been received from hw
945 */
946static int get_packets_from_hw(struct ipw_hardware *hw)
947{
948 int received = 0;
949 unsigned long flags;
950
951 spin_lock_irqsave(&hw->spinlock, flags);
952 while (hw->rx_ready && !hw->blocking_rx) {
953 received = 1;
954 hw->rx_ready--;
955 spin_unlock_irqrestore(&hw->spinlock, flags);
956
957 do_receive_packet(hw);
958
959 spin_lock_irqsave(&hw->spinlock, flags);
960 }
961 spin_unlock_irqrestore(&hw->spinlock, flags);
962
963 return received;
964}
965
966/*
967 * Send pending packet up to given priority, prioritize SETUP data until
968 * hardware is fully setup.
969 *
970 * return 1 if more packets can be sent
971 */
972static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
973{
974 int more_to_send = 0;
975 unsigned long flags;
976
977 spin_lock_irqsave(&hw->spinlock, flags);
978 if (hw->tx_queued && hw->tx_ready != 0) {
979 int priority;
980 struct ipw_tx_packet *packet = NULL;
981
982 hw->tx_ready--;
983
984 /* Pick a packet */
985 for (priority = 0; priority < priority_limit; priority++) {
986 if (!list_empty(&hw->tx_queue[priority])) {
987 packet = list_first_entry(
988 &hw->tx_queue[priority],
989 struct ipw_tx_packet,
990 queue);
991
992 list_del(&packet->queue);
993
994 break;
995 }
996 }
997 if (!packet) {
998 hw->tx_queued = 0;
999 spin_unlock_irqrestore(&hw->spinlock, flags);
1000 return 0;
1001 }
1002 spin_unlock_irqrestore(&hw->spinlock, flags);
1003
1004 /* Send */
1005 do_send_packet(hw, packet);
1006
1007 /* Check if more to send */
1008 spin_lock_irqsave(&hw->spinlock, flags);
1009 for (priority = 0; priority < priority_limit; priority++)
1010 if (!list_empty(&hw->tx_queue[priority])) {
1011 more_to_send = 1;
1012 break;
1013 }
1014
1015 if (!more_to_send)
1016 hw->tx_queued = 0;
1017 }
1018 spin_unlock_irqrestore(&hw->spinlock, flags);
1019
1020 return more_to_send;
1021}
1022
1023/*
1024 * Send and receive all queued packets.
1025 */
1026static void ipwireless_do_tasklet(unsigned long hw_)
1027{
1028 struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
1029 unsigned long flags;
1030
1031 spin_lock_irqsave(&hw->spinlock, flags);
1032 if (hw->shutting_down) {
1033 spin_unlock_irqrestore(&hw->spinlock, flags);
1034 return;
1035 }
1036
1037 if (hw->to_setup == 1) {
1038 /*
1039 * Initial setup data sent to hardware
1040 */
1041 hw->to_setup = 2;
1042 spin_unlock_irqrestore(&hw->spinlock, flags);
1043
1044 ipw_setup_hardware(hw);
1045 ipw_send_setup_packet(hw);
1046
1047 send_pending_packet(hw, PRIO_SETUP + 1);
1048 get_packets_from_hw(hw);
1049 } else {
1050 int priority_limit = get_current_packet_priority(hw);
1051 int again;
1052
1053 spin_unlock_irqrestore(&hw->spinlock, flags);
1054
1055 do {
1056 again = send_pending_packet(hw, priority_limit);
1057 again |= get_packets_from_hw(hw);
1058 } while (again);
1059 }
1060}
1061
1062/*
1063 * return true if the card is physically present.
1064 */
1065static int is_card_present(struct ipw_hardware *hw)
1066{
1067 if (hw->hw_version == HW_VERSION_1)
1068 return inw(hw->base_port + IOIR) != 0xFFFF;
1069 else
1070 return readl(&hw->memory_info_regs->memreg_card_present) ==
1071 CARD_PRESENT_VALUE;
1072}
1073
1074static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
1075 struct ipw_hardware *hw)
1076{
1077 unsigned short irqn;
1078
1079 irqn = inw(hw->base_port + IOIR);
1080
1081 /* Check if card is present */
1082 if (irqn == 0xFFFF)
1083 return IRQ_NONE;
1084 else if (irqn != 0) {
1085 unsigned short ack = 0;
1086 unsigned long flags;
1087
1088 /* Transmit complete. */
1089 if (irqn & IR_TXINTR) {
1090 ack |= IR_TXINTR;
1091 spin_lock_irqsave(&hw->spinlock, flags);
1092 hw->tx_ready++;
1093 spin_unlock_irqrestore(&hw->spinlock, flags);
1094 }
1095 /* Received data */
1096 if (irqn & IR_RXINTR) {
1097 ack |= IR_RXINTR;
1098 spin_lock_irqsave(&hw->spinlock, flags);
1099 hw->rx_ready++;
1100 spin_unlock_irqrestore(&hw->spinlock, flags);
1101 }
1102 if (ack != 0) {
1103 outw(ack, hw->base_port + IOIR);
1104 tasklet_schedule(&hw->tasklet);
1105 }
1106 return IRQ_HANDLED;
1107 }
1108 return IRQ_NONE;
1109}
1110
1111static void acknowledge_pcmcia_interrupt(struct ipw_hardware *hw)
1112{
1113 unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
1114
1115 csr &= 0xfffd;
1116 writew(csr, &hw->memregs_CCR->reg_config_and_status);
1117}
1118
1119static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
1120 struct ipw_hardware *hw)
1121{
1122 int tx = 0;
1123 int rx = 0;
1124 int rx_repeat = 0;
1125 int try_mem_tx_old;
1126 unsigned long flags;
1127
1128 do {
1129
1130 unsigned short memtx = readw(hw->memreg_tx);
1131 unsigned short memtx_serial;
1132 unsigned short memrxdone =
1133 readw(&hw->memory_info_regs->memreg_rx_done);
1134
1135 try_mem_tx_old = 0;
1136
1137 /* check whether the interrupt was generated by ipwireless card */
1138 if (!(memtx & MEMTX_TX) && !(memrxdone & MEMRX_RX_DONE)) {
1139
1140 /* check if the card uses memreg_tx_old register */
1141 if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
1142 memtx = readw(&hw->memory_info_regs->memreg_tx_old);
1143 if (memtx & MEMTX_TX) {
1144 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1145 ": Using memreg_tx_old\n");
1146 hw->memreg_tx =
1147 &hw->memory_info_regs->memreg_tx_old;
1148 } else {
1149 return IRQ_NONE;
1150 }
1151 } else {
1152 return IRQ_NONE;
1153 }
1154 }
1155
1156 /*
1157 * See if the card is physically present. Note that while it is
1158 * powering up, it appears not to be present.
1159 */
1160 if (!is_card_present(hw)) {
1161 acknowledge_pcmcia_interrupt(hw);
1162 return IRQ_HANDLED;
1163 }
1164
1165 memtx_serial = memtx & (unsigned short) 0xff00;
1166 if (memtx & MEMTX_TX) {
1167 writew(memtx_serial, hw->memreg_tx);
1168
1169 if (hw->serial_number_detected) {
1170 if (memtx_serial != hw->last_memtx_serial) {
1171 hw->last_memtx_serial = memtx_serial;
1172 spin_lock_irqsave(&hw->spinlock, flags);
1173 hw->rx_ready++;
1174 spin_unlock_irqrestore(&hw->spinlock, flags);
1175 rx = 1;
1176 } else
1177 /* Ignore 'Timer Recovery' duplicates. */
1178 rx_repeat = 1;
1179 } else {
1180 /*
1181 * If a non-zero serial number is seen, then enable
1182 * serial number checking.
1183 */
1184 if (memtx_serial != 0) {
1185 hw->serial_number_detected = 1;
1186 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1187 ": memreg_tx serial num detected\n");
1188
1189 spin_lock_irqsave(&hw->spinlock, flags);
1190 hw->rx_ready++;
1191 spin_unlock_irqrestore(&hw->spinlock, flags);
1192 }
1193 rx = 1;
1194 }
1195 }
1196 if (memrxdone & MEMRX_RX_DONE) {
1197 writew(0, &hw->memory_info_regs->memreg_rx_done);
1198 spin_lock_irqsave(&hw->spinlock, flags);
1199 hw->tx_ready++;
1200 spin_unlock_irqrestore(&hw->spinlock, flags);
1201 tx = 1;
1202 }
1203 if (tx)
1204 writew(MEMRX_PCINTACKK,
1205 &hw->memory_info_regs->memreg_pc_interrupt_ack);
1206
1207 acknowledge_pcmcia_interrupt(hw);
1208
1209 if (tx || rx)
1210 tasklet_schedule(&hw->tasklet);
1211 else if (!rx_repeat) {
1212 if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
1213 if (hw->serial_number_detected)
1214 printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
1215 ": spurious interrupt - new_tx mode\n");
1216 else {
1217 printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
1218 ": no valid memreg_tx value - "
1219 "switching to the old memreg_tx\n");
1220 hw->memreg_tx =
1221 &hw->memory_info_regs->memreg_tx_old;
1222 try_mem_tx_old = 1;
1223 }
1224 } else
1225 printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
1226 ": spurious interrupt - old_tx mode\n");
1227 }
1228
1229 } while (try_mem_tx_old == 1);
1230
1231 return IRQ_HANDLED;
1232}
1233
1234irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1235{
1236 struct ipw_hardware *hw = dev_id;
1237
1238 if (hw->hw_version == HW_VERSION_1)
1239 return ipwireless_handle_v1_interrupt(irq, hw);
1240 else
1241 return ipwireless_handle_v2_v3_interrupt(irq, hw);
1242}
1243
1244static void flush_packets_to_hw(struct ipw_hardware *hw)
1245{
1246 int priority_limit;
1247 unsigned long flags;
1248
1249 spin_lock_irqsave(&hw->spinlock, flags);
1250 priority_limit = get_current_packet_priority(hw);
1251 spin_unlock_irqrestore(&hw->spinlock, flags);
1252
1253 while (send_pending_packet(hw, priority_limit));
1254}
1255
1256static void send_packet(struct ipw_hardware *hw, int priority,
1257 struct ipw_tx_packet *packet)
1258{
1259 unsigned long flags;
1260
1261 spin_lock_irqsave(&hw->spinlock, flags);
1262 list_add_tail(&packet->queue, &hw->tx_queue[priority]);
1263 hw->tx_queued = 1;
1264 spin_unlock_irqrestore(&hw->spinlock, flags);
1265
1266 flush_packets_to_hw(hw);
1267}
1268
1269/* Create data packet, non-atomic allocation */
1270static void *alloc_data_packet(int data_size,
1271 unsigned char dest_addr,
1272 unsigned char protocol)
1273{
1274 struct ipw_tx_packet *packet = kzalloc(
1275 sizeof(struct ipw_tx_packet) + data_size,
1276 GFP_ATOMIC);
1277
1278 if (!packet)
1279 return NULL;
1280
1281 INIT_LIST_HEAD(&packet->queue);
1282 packet->dest_addr = dest_addr;
1283 packet->protocol = protocol;
1284 packet->length = data_size;
1285
1286 return packet;
1287}
1288
1289static void *alloc_ctrl_packet(int header_size,
1290 unsigned char dest_addr,
1291 unsigned char protocol,
1292 unsigned char sig_no)
1293{
1294 /*
1295 * sig_no is located right after ipw_tx_packet struct in every
1296 * CTRL or SETUP packets, we can use ipw_control_packet as a
1297 * common struct
1298 */
1299 struct ipw_control_packet *packet = kzalloc(header_size, GFP_ATOMIC);
1300
1301 if (!packet)
1302 return NULL;
1303
1304 INIT_LIST_HEAD(&packet->header.queue);
1305 packet->header.dest_addr = dest_addr;
1306 packet->header.protocol = protocol;
1307 packet->header.length = header_size - sizeof(struct ipw_tx_packet);
1308 packet->body.sig_no = sig_no;
1309
1310 return packet;
1311}
1312
1313int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
1314 unsigned char *data, unsigned int length,
1315 void (*callback) (void *cb, unsigned int length),
1316 void *callback_data)
1317{
1318 struct ipw_tx_packet *packet;
1319
1320 packet = alloc_data_packet(length,
1321 (unsigned char) (channel_idx + 1),
1322 TL_PROTOCOLID_COM_DATA);
1323 if (!packet)
1324 return -ENOMEM;
1325 packet->packet_callback = callback;
1326 packet->callback_data = callback_data;
1327 memcpy((unsigned char *) packet +
1328 sizeof(struct ipw_tx_packet), data, length);
1329
1330 send_packet(hw, PRIO_DATA, packet);
1331 return 0;
1332}
1333
1334static int set_control_line(struct ipw_hardware *hw, int prio,
1335 unsigned int channel_idx, int line, int state)
1336{
1337 struct ipw_control_packet *packet;
1338 int protocolid = TL_PROTOCOLID_COM_CTRL;
1339
1340 if (prio == PRIO_SETUP)
1341 protocolid = TL_PROTOCOLID_SETUP;
1342
1343 packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
1344 (unsigned char) (channel_idx + 1),
1345 protocolid, line);
1346 if (!packet)
1347 return -ENOMEM;
1348 packet->header.length = sizeof(struct ipw_control_packet_body);
1349 packet->body.value = (unsigned char) (state == 0 ? 0 : 1);
1350 send_packet(hw, prio, &packet->header);
1351 return 0;
1352}
1353
1354
1355static int set_DTR(struct ipw_hardware *hw, int priority,
1356 unsigned int channel_idx, int state)
1357{
1358 if (state != 0)
1359 hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_DTR;
1360 else
1361 hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_DTR;
1362
1363 return set_control_line(hw, priority, channel_idx, COMCTRL_DTR, state);
1364}
1365
1366static int set_RTS(struct ipw_hardware *hw, int priority,
1367 unsigned int channel_idx, int state)
1368{
1369 if (state != 0)
1370 hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_RTS;
1371 else
1372 hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_RTS;
1373
1374 return set_control_line(hw, priority, channel_idx, COMCTRL_RTS, state);
1375}
1376
1377int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
1378 int state)
1379{
1380 return set_DTR(hw, PRIO_CTRL, channel_idx, state);
1381}
1382
1383int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
1384 int state)
1385{
1386 return set_RTS(hw, PRIO_CTRL, channel_idx, state);
1387}
1388
1389struct ipw_setup_get_version_query_packet {
1390 struct ipw_tx_packet header;
1391 struct tl_setup_get_version_qry body;
1392};
1393
1394struct ipw_setup_config_packet {
1395 struct ipw_tx_packet header;
1396 struct tl_setup_config_msg body;
1397};
1398
1399struct ipw_setup_config_done_packet {
1400 struct ipw_tx_packet header;
1401 struct tl_setup_config_done_msg body;
1402};
1403
1404struct ipw_setup_open_packet {
1405 struct ipw_tx_packet header;
1406 struct tl_setup_open_msg body;
1407};
1408
1409struct ipw_setup_info_packet {
1410 struct ipw_tx_packet header;
1411 struct tl_setup_info_msg body;
1412};
1413
1414struct ipw_setup_reboot_msg_ack {
1415 struct ipw_tx_packet header;
1416 struct TlSetupRebootMsgAck body;
1417};
1418
1419/* This handles the actual initialization of the card */
1420static void __handle_setup_get_version_rsp(struct ipw_hardware *hw)
1421{
1422 struct ipw_setup_config_packet *config_packet;
1423 struct ipw_setup_config_done_packet *config_done_packet;
1424 struct ipw_setup_open_packet *open_packet;
1425 struct ipw_setup_info_packet *info_packet;
1426 int port;
1427 unsigned int channel_idx;
1428
1429 /* generate config packet */
1430 for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
1431 config_packet = alloc_ctrl_packet(
1432 sizeof(struct ipw_setup_config_packet),
1433 ADDR_SETUP_PROT,
1434 TL_PROTOCOLID_SETUP,
1435 TL_SETUP_SIGNO_CONFIG_MSG);
1436 if (!config_packet)
1437 goto exit_nomem;
1438 config_packet->header.length = sizeof(struct tl_setup_config_msg);
1439 config_packet->body.port_no = port;
1440 config_packet->body.prio_data = PRIO_DATA;
1441 config_packet->body.prio_ctrl = PRIO_CTRL;
1442 send_packet(hw, PRIO_SETUP, &config_packet->header);
1443 }
1444 config_done_packet = alloc_ctrl_packet(
1445 sizeof(struct ipw_setup_config_done_packet),
1446 ADDR_SETUP_PROT,
1447 TL_PROTOCOLID_SETUP,
1448 TL_SETUP_SIGNO_CONFIG_DONE_MSG);
1449 if (!config_done_packet)
1450 goto exit_nomem;
1451 config_done_packet->header.length = sizeof(struct tl_setup_config_done_msg);
1452 send_packet(hw, PRIO_SETUP, &config_done_packet->header);
1453
1454 /* generate open packet */
1455 for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
1456 open_packet = alloc_ctrl_packet(
1457 sizeof(struct ipw_setup_open_packet),
1458 ADDR_SETUP_PROT,
1459 TL_PROTOCOLID_SETUP,
1460 TL_SETUP_SIGNO_OPEN_MSG);
1461 if (!open_packet)
1462 goto exit_nomem;
1463 open_packet->header.length = sizeof(struct tl_setup_open_msg);
1464 open_packet->body.port_no = port;
1465 send_packet(hw, PRIO_SETUP, &open_packet->header);
1466 }
1467 for (channel_idx = 0;
1468 channel_idx < NL_NUM_OF_ADDRESSES; channel_idx++) {
1469 int ret;
1470
1471 ret = set_DTR(hw, PRIO_SETUP, channel_idx,
1472 (hw->control_lines[channel_idx] &
1473 IPW_CONTROL_LINE_DTR) != 0);
1474 if (ret) {
1475 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
1476 ": error setting DTR (%d)\n", ret);
1477 return;
1478 }
1479
1480 set_RTS(hw, PRIO_SETUP, channel_idx,
1481 (hw->control_lines [channel_idx] &
1482 IPW_CONTROL_LINE_RTS) != 0);
1483 if (ret) {
1484 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
1485 ": error setting RTS (%d)\n", ret);
1486 return;
1487 }
1488 }
1489 /*
1490 * For NDIS we assume that we are using sync PPP frames, for COM async.
1491 * This driver uses NDIS mode too. We don't bother with translation
1492 * from async -> sync PPP.
1493 */
1494 info_packet = alloc_ctrl_packet(sizeof(struct ipw_setup_info_packet),
1495 ADDR_SETUP_PROT,
1496 TL_PROTOCOLID_SETUP,
1497 TL_SETUP_SIGNO_INFO_MSG);
1498 if (!info_packet)
1499 goto exit_nomem;
1500 info_packet->header.length = sizeof(struct tl_setup_info_msg);
1501 info_packet->body.driver_type = NDISWAN_DRIVER;
1502 info_packet->body.major_version = NDISWAN_DRIVER_MAJOR_VERSION;
1503 info_packet->body.minor_version = NDISWAN_DRIVER_MINOR_VERSION;
1504 send_packet(hw, PRIO_SETUP, &info_packet->header);
1505
1506 /* Initialization is now complete, so we clear the 'to_setup' flag */
1507 hw->to_setup = 0;
1508
1509 return;
1510
1511exit_nomem:
1512 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
1513 ": not enough memory to alloc control packet\n");
1514 hw->to_setup = -1;
1515}
1516
1517static void handle_setup_get_version_rsp(struct ipw_hardware *hw,
1518 unsigned char vers_no)
1519{
1520 del_timer(&hw->setup_timer);
1521 hw->initializing = 0;
1522 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": card is ready.\n");
1523
1524 if (vers_no == TL_SETUP_VERSION)
1525 __handle_setup_get_version_rsp(hw);
1526 else
1527 printk(KERN_ERR
1528 IPWIRELESS_PCCARD_NAME
1529 ": invalid hardware version no %u\n",
1530 (unsigned int) vers_no);
1531}
1532
1533static void ipw_send_setup_packet(struct ipw_hardware *hw)
1534{
1535 struct ipw_setup_get_version_query_packet *ver_packet;
1536
1537 ver_packet = alloc_ctrl_packet(
1538 sizeof(struct ipw_setup_get_version_query_packet),
1539 ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
1540 TL_SETUP_SIGNO_GET_VERSION_QRY);
1541 ver_packet->header.length = sizeof(struct tl_setup_get_version_qry);
1542
1543 /*
1544 * Response is handled in handle_received_SETUP_packet
1545 */
1546 send_packet(hw, PRIO_SETUP, &ver_packet->header);
1547}
1548
1549static void handle_received_SETUP_packet(struct ipw_hardware *hw,
1550 unsigned int address,
1551 unsigned char *data, int len,
1552 int is_last)
1553{
1554 union ipw_setup_rx_msg *rx_msg = (union ipw_setup_rx_msg *) data;
1555
1556 if (address != ADDR_SETUP_PROT) {
1557 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1558 ": setup packet has bad address %d\n", address);
1559 return;
1560 }
1561
1562 switch (rx_msg->sig_no) {
1563 case TL_SETUP_SIGNO_GET_VERSION_RSP:
1564 if (hw->to_setup)
1565 handle_setup_get_version_rsp(hw,
1566 rx_msg->version_rsp_msg.version);
1567 break;
1568
1569 case TL_SETUP_SIGNO_OPEN_MSG:
1570 if (ipwireless_debug) {
1571 unsigned int channel_idx = rx_msg->open_msg.port_no - 1;
1572
1573 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1574 ": OPEN_MSG [channel %u] reply received\n",
1575 channel_idx);
1576 }
1577 break;
1578
1579 case TL_SETUP_SIGNO_INFO_MSG_ACK:
1580 if (ipwireless_debug)
1581 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1582 ": card successfully configured as NDISWAN\n");
1583 break;
1584
1585 case TL_SETUP_SIGNO_REBOOT_MSG:
1586 if (hw->to_setup)
1587 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1588 ": Setup not completed - ignoring reboot msg\n");
1589 else {
1590 struct ipw_setup_reboot_msg_ack *packet;
1591
1592 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
1593 ": Acknowledging REBOOT message\n");
1594 packet = alloc_ctrl_packet(
1595 sizeof(struct ipw_setup_reboot_msg_ack),
1596 ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
1597 TL_SETUP_SIGNO_REBOOT_MSG_ACK);
1598 packet->header.length =
1599 sizeof(struct TlSetupRebootMsgAck);
1600 send_packet(hw, PRIO_SETUP, &packet->header);
1601 if (hw->reboot_callback)
1602 hw->reboot_callback(hw->reboot_callback_data);
1603 }
1604 break;
1605
1606 default:
1607 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1608 ": unknown setup message %u received\n",
1609 (unsigned int) rx_msg->sig_no);
1610 }
1611}
1612
1613static void do_close_hardware(struct ipw_hardware *hw)
1614{
1615 unsigned int irqn;
1616
1617 if (hw->hw_version == HW_VERSION_1) {
1618 /* Disable TX and RX interrupts. */
1619 outw(0, hw->base_port + IOIER);
1620
1621 /* Acknowledge any outstanding interrupt requests */
1622 irqn = inw(hw->base_port + IOIR);
1623 if (irqn & IR_TXINTR)
1624 outw(IR_TXINTR, hw->base_port + IOIR);
1625 if (irqn & IR_RXINTR)
1626 outw(IR_RXINTR, hw->base_port + IOIR);
1627
1628 synchronize_irq(hw->irq);
1629 }
1630}
1631
1632struct ipw_hardware *ipwireless_hardware_create(void)
1633{
1634 int i;
1635 struct ipw_hardware *hw =
1636 kzalloc(sizeof(struct ipw_hardware), GFP_KERNEL);
1637
1638 if (!hw)
1639 return NULL;
1640
1641 hw->irq = -1;
1642 hw->initializing = 1;
1643 hw->tx_ready = 1;
1644 hw->rx_bytes_queued = 0;
1645 hw->rx_pool_size = 0;
1646 hw->last_memtx_serial = (unsigned short) 0xffff;
1647 for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
1648 INIT_LIST_HEAD(&hw->tx_queue[i]);
1649
1650 INIT_LIST_HEAD(&hw->rx_queue);
1651 INIT_LIST_HEAD(&hw->rx_pool);
1652 spin_lock_init(&hw->spinlock);
1653 tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
1654 INIT_WORK(&hw->work_rx, ipw_receive_data_work);
1655 setup_timer(&hw->setup_timer, ipwireless_setup_timer,
1656 (unsigned long) hw);
1657
1658 return hw;
1659}
1660
1661void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
1662 unsigned int base_port,
1663 void __iomem *attr_memory,
1664 void __iomem *common_memory,
1665 int is_v2_card,
1666 void (*reboot_callback) (void *data),
1667 void *reboot_callback_data)
1668{
1669 if (hw->removed) {
1670 hw->removed = 0;
1671 enable_irq(hw->irq);
1672 }
1673 hw->base_port = base_port;
1674 hw->hw_version = is_v2_card ? HW_VERSION_2 : HW_VERSION_1;
1675 hw->ll_mtu = hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2;
1676 hw->memregs_CCR = (struct MEMCCR __iomem *)
1677 ((unsigned short __iomem *) attr_memory + 0x200);
1678 hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
1679 hw->memreg_tx = &hw->memory_info_regs->memreg_tx_new;
1680 hw->reboot_callback = reboot_callback;
1681 hw->reboot_callback_data = reboot_callback_data;
1682}
1683
1684void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw)
1685{
1686 hw->initializing = 1;
1687 hw->init_loops = 0;
1688 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1689 ": waiting for card to start up...\n");
1690 ipwireless_setup_timer((unsigned long) hw);
1691}
1692
1693static void ipwireless_setup_timer(unsigned long data)
1694{
1695 struct ipw_hardware *hw = (struct ipw_hardware *) data;
1696
1697 hw->init_loops++;
1698
1699 if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY &&
1700 hw->hw_version == HW_VERSION_2 &&
1701 hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
1702 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1703 ": failed to startup using TX2, trying TX\n");
1704
1705 hw->memreg_tx = &hw->memory_info_regs->memreg_tx_old;
1706 hw->init_loops = 0;
1707 }
1708 /* Give up after a certain number of retries */
1709 if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY) {
1710 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
1711 ": card failed to start up!\n");
1712 hw->initializing = 0;
1713 } else {
1714 /* Do not attempt to write to the board if it is not present. */
1715 if (is_card_present(hw)) {
1716 unsigned long flags;
1717
1718 spin_lock_irqsave(&hw->spinlock, flags);
1719 hw->to_setup = 1;
1720 hw->tx_ready = 1;
1721 spin_unlock_irqrestore(&hw->spinlock, flags);
1722 tasklet_schedule(&hw->tasklet);
1723 }
1724
1725 mod_timer(&hw->setup_timer,
1726 jiffies + msecs_to_jiffies(TL_SETUP_VERSION_QRY_TMO));
1727 }
1728}
1729
1730/*
1731 * Stop any interrupts from executing so that, once this function returns,
1732 * other layers of the driver can be sure they won't get any more callbacks.
1733 * Thus must be called on a proper process context.
1734 */
1735void ipwireless_stop_interrupts(struct ipw_hardware *hw)
1736{
1737 if (!hw->shutting_down) {
1738 /* Tell everyone we are going down. */
1739 hw->shutting_down = 1;
1740 del_timer(&hw->setup_timer);
1741
1742 /* Prevent the hardware from sending any more interrupts */
1743 do_close_hardware(hw);
1744 }
1745}
1746
1747void ipwireless_hardware_free(struct ipw_hardware *hw)
1748{
1749 int i;
1750 struct ipw_rx_packet *rp, *rq;
1751 struct ipw_tx_packet *tp, *tq;
1752
1753 ipwireless_stop_interrupts(hw);
1754
1755 flush_scheduled_work();
1756
1757 for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
1758 if (hw->packet_assembler[i] != NULL)
1759 kfree(hw->packet_assembler[i]);
1760
1761 for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
1762 list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) {
1763 list_del(&tp->queue);
1764 kfree(tp);
1765 }
1766
1767 list_for_each_entry_safe(rp, rq, &hw->rx_queue, queue) {
1768 list_del(&rp->queue);
1769 kfree(rp);
1770 }
1771
1772 list_for_each_entry_safe(rp, rq, &hw->rx_pool, queue) {
1773 list_del(&rp->queue);
1774 kfree(rp);
1775 }
1776 kfree(hw);
1777}
1778
1779/*
1780 * Associate the specified network with this hardware, so it will receive events
1781 * from it.
1782 */
1783void ipwireless_associate_network(struct ipw_hardware *hw,
1784 struct ipw_network *network)
1785{
1786 hw->network = network;
1787}
diff --git a/drivers/char/pcmcia/ipwireless/hardware.h b/drivers/char/pcmcia/ipwireless/hardware.h
new file mode 100644
index 000000000000..c83190ffb0e7
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/hardware.h
@@ -0,0 +1,64 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#ifndef _IPWIRELESS_CS_HARDWARE_H_
19#define _IPWIRELESS_CS_HARDWARE_H_
20
21#include <linux/types.h>
22#include <linux/sched.h>
23#include <linux/interrupt.h>
24
25#define IPW_CONTROL_LINE_CTS 0x0001
26#define IPW_CONTROL_LINE_DCD 0x0002
27#define IPW_CONTROL_LINE_DSR 0x0004
28#define IPW_CONTROL_LINE_RI 0x0008
29#define IPW_CONTROL_LINE_DTR 0x0010
30#define IPW_CONTROL_LINE_RTS 0x0020
31
32struct ipw_hardware;
33struct ipw_network;
34
35struct ipw_hardware *ipwireless_hardware_create(void);
36void ipwireless_hardware_free(struct ipw_hardware *hw);
37irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs);
38int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
39 int state);
40int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
41 int state);
42int ipwireless_send_packet(struct ipw_hardware *hw,
43 unsigned int channel_idx,
44 unsigned char *data,
45 unsigned int length,
46 void (*packet_sent_callback) (void *cb,
47 unsigned int length),
48 void *sent_cb_data);
49void ipwireless_associate_network(struct ipw_hardware *hw,
50 struct ipw_network *net);
51void ipwireless_stop_interrupts(struct ipw_hardware *hw);
52void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
53 unsigned int base_port,
54 void __iomem *attr_memory,
55 void __iomem *common_memory,
56 int is_v2_card,
57 void (*reboot_cb) (void *data),
58 void *reboot_cb_data);
59void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw);
60void ipwireless_sleep(unsigned int tenths);
61int ipwireless_dump_hardware_state(char *p, size_t limit,
62 struct ipw_hardware *hw);
63
64#endif
diff --git a/drivers/char/pcmcia/ipwireless/main.c b/drivers/char/pcmcia/ipwireless/main.c
new file mode 100644
index 000000000000..00c7f8407e3e
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/main.c
@@ -0,0 +1,501 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#include "hardware.h"
19#include "network.h"
20#include "main.h"
21#include "tty.h"
22
23#include <linux/delay.h>
24#include <linux/init.h>
25#include <linux/io.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <linux/slab.h>
30
31#include <pcmcia/version.h>
32#include <pcmcia/cisreg.h>
33#include <pcmcia/device_id.h>
34#include <pcmcia/ss.h>
35#include <pcmcia/ds.h>
36#include <pcmcia/cs.h>
37
38static struct pcmcia_device_id ipw_ids[] = {
39 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
40 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200),
41 PCMCIA_DEVICE_NULL
42};
43MODULE_DEVICE_TABLE(pcmcia, ipw_ids);
44
45static void ipwireless_detach(struct pcmcia_device *link);
46
47/*
48 * Module params
49 */
50/* Debug mode: more verbose, print sent/recv bytes */
51int ipwireless_debug;
52int ipwireless_loopback;
53int ipwireless_out_queue = 1;
54
55module_param_named(debug, ipwireless_debug, int, 0);
56module_param_named(loopback, ipwireless_loopback, int, 0);
57module_param_named(out_queue, ipwireless_out_queue, int, 0);
58MODULE_PARM_DESC(debug, "switch on debug messages [0]");
59MODULE_PARM_DESC(loopback,
60 "debug: enable ras_raw channel [0]");
61MODULE_PARM_DESC(out_queue, "debug: set size of outgoing queue [1]");
62
63/* Executes in process context. */
64static void signalled_reboot_work(struct work_struct *work_reboot)
65{
66 struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
67 work_reboot);
68 struct pcmcia_device *link = ipw->link;
69 int ret = pccard_reset_card(link->socket);
70
71 if (ret != CS_SUCCESS)
72 cs_error(link, ResetCard, ret);
73}
74
75static void signalled_reboot_callback(void *callback_data)
76{
77 struct ipw_dev *ipw = (struct ipw_dev *) callback_data;
78
79 /* Delegate to process context. */
80 schedule_work(&ipw->work_reboot);
81}
82
83static int config_ipwireless(struct ipw_dev *ipw)
84{
85 struct pcmcia_device *link = ipw->link;
86 int ret;
87 config_info_t conf;
88 tuple_t tuple;
89 unsigned short buf[64];
90 cisparse_t parse;
91 unsigned short cor_value;
92 win_req_t request_attr_memory;
93 win_req_t request_common_memory;
94 memreq_t memreq_attr_memory;
95 memreq_t memreq_common_memory;
96
97 ipw->is_v2_card = 0;
98
99 tuple.Attributes = 0;
100 tuple.TupleData = (cisdata_t *) buf;
101 tuple.TupleDataMax = sizeof(buf);
102 tuple.TupleOffset = 0;
103
104 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
105
106 ret = pcmcia_get_first_tuple(link, &tuple);
107
108 while (ret == 0) {
109 ret = pcmcia_get_tuple_data(link, &tuple);
110
111 if (ret != CS_SUCCESS) {
112 cs_error(link, GetTupleData, ret);
113 goto exit0;
114 }
115 ret = pcmcia_get_next_tuple(link, &tuple);
116 }
117
118 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
119
120 ret = pcmcia_get_first_tuple(link, &tuple);
121
122 if (ret != CS_SUCCESS) {
123 cs_error(link, GetFirstTuple, ret);
124 goto exit0;
125 }
126
127 ret = pcmcia_get_tuple_data(link, &tuple);
128
129 if (ret != CS_SUCCESS) {
130 cs_error(link, GetTupleData, ret);
131 goto exit0;
132 }
133
134 ret = pcmcia_parse_tuple(link, &tuple, &parse);
135
136 if (ret != CS_SUCCESS) {
137 cs_error(link, ParseTuple, ret);
138 goto exit0;
139 }
140
141 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
142 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
143 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
144 link->io.IOAddrLines = 16;
145
146 link->irq.IRQInfo1 = parse.cftable_entry.irq.IRQInfo1;
147
148 /* 0x40 causes it to generate level mode interrupts. */
149 /* 0x04 enables IREQ pin. */
150 cor_value = parse.cftable_entry.index | 0x44;
151 link->conf.ConfigIndex = cor_value;
152
153 /* IRQ and I/O settings */
154 tuple.DesiredTuple = CISTPL_CONFIG;
155
156 ret = pcmcia_get_first_tuple(link, &tuple);
157
158 if (ret != CS_SUCCESS) {
159 cs_error(link, GetFirstTuple, ret);
160 goto exit0;
161 }
162
163 ret = pcmcia_get_tuple_data(link, &tuple);
164
165 if (ret != CS_SUCCESS) {
166 cs_error(link, GetTupleData, ret);
167 goto exit0;
168 }
169
170 ret = pcmcia_parse_tuple(link, &tuple, &parse);
171
172 if (ret != CS_SUCCESS) {
173 cs_error(link, GetTupleData, ret);
174 goto exit0;
175 }
176 link->conf.Attributes = CONF_ENABLE_IRQ;
177 link->conf.ConfigBase = parse.config.base;
178 link->conf.Present = parse.config.rmask[0];
179 link->conf.IntType = INT_MEMORY_AND_IO;
180
181 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
182 link->irq.Handler = ipwireless_interrupt;
183 link->irq.Instance = ipw->hardware;
184
185 ret = pcmcia_request_io(link, &link->io);
186
187 if (ret != CS_SUCCESS) {
188 cs_error(link, RequestIO, ret);
189 goto exit0;
190 }
191
192 /* memory settings */
193
194 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
195
196 ret = pcmcia_get_first_tuple(link, &tuple);
197
198 if (ret != CS_SUCCESS) {
199 cs_error(link, GetFirstTuple, ret);
200 goto exit1;
201 }
202
203 ret = pcmcia_get_tuple_data(link, &tuple);
204
205 if (ret != CS_SUCCESS) {
206 cs_error(link, GetTupleData, ret);
207 goto exit1;
208 }
209
210 ret = pcmcia_parse_tuple(link, &tuple, &parse);
211
212 if (ret != CS_SUCCESS) {
213 cs_error(link, ParseTuple, ret);
214 goto exit1;
215 }
216
217 if (parse.cftable_entry.mem.nwin > 0) {
218 request_common_memory.Attributes =
219 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
220 request_common_memory.Base =
221 parse.cftable_entry.mem.win[0].host_addr;
222 request_common_memory.Size = parse.cftable_entry.mem.win[0].len;
223 if (request_common_memory.Size < 0x1000)
224 request_common_memory.Size = 0x1000;
225 request_common_memory.AccessSpeed = 0;
226
227 ret = pcmcia_request_window(&link, &request_common_memory,
228 &ipw->handle_common_memory);
229
230 if (ret != CS_SUCCESS) {
231 cs_error(link, RequestWindow, ret);
232 goto exit1;
233 }
234
235 memreq_common_memory.CardOffset =
236 parse.cftable_entry.mem.win[0].card_addr;
237 memreq_common_memory.Page = 0;
238
239 ret = pcmcia_map_mem_page(ipw->handle_common_memory,
240 &memreq_common_memory);
241
242 if (ret != CS_SUCCESS) {
243 cs_error(link, MapMemPage, ret);
244 goto exit1;
245 }
246
247 ipw->is_v2_card =
248 parse.cftable_entry.mem.win[0].len == 0x100;
249
250 ipw->common_memory = ioremap(request_common_memory.Base,
251 request_common_memory.Size);
252
253 request_attr_memory.Attributes =
254 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
255 request_attr_memory.Base = 0;
256 request_attr_memory.Size = 0; /* this used to be 0x1000 */
257 request_attr_memory.AccessSpeed = 0;
258
259 ret = pcmcia_request_window(&link, &request_attr_memory,
260 &ipw->handle_attr_memory);
261
262 if (ret != CS_SUCCESS) {
263 cs_error(link, RequestWindow, ret);
264 goto exit2;
265 }
266
267 memreq_attr_memory.CardOffset = 0;
268 memreq_attr_memory.Page = 0;
269
270 ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
271 &memreq_attr_memory);
272
273 if (ret != CS_SUCCESS) {
274 cs_error(link, MapMemPage, ret);
275 goto exit2;
276 }
277
278 ipw->attr_memory = ioremap(request_attr_memory.Base,
279 request_attr_memory.Size);
280 }
281
282 INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
283
284 ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
285 ipw->attr_memory, ipw->common_memory,
286 ipw->is_v2_card, signalled_reboot_callback,
287 ipw);
288
289 ret = pcmcia_request_irq(link, &link->irq);
290
291 if (ret != CS_SUCCESS) {
292 cs_error(link, RequestIRQ, ret);
293 goto exit3;
294 }
295
296 /* Look up current Vcc */
297
298 ret = pcmcia_get_configuration_info(link, &conf);
299
300 if (ret != CS_SUCCESS) {
301 cs_error(link, GetConfigurationInfo, ret);
302 goto exit4;
303 }
304
305 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
306 ipw->is_v2_card ? "V2/V3" : "V1");
307 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
308 ": I/O ports 0x%04x-0x%04x, irq %d\n",
309 (unsigned int) link->io.BasePort1,
310 (unsigned int) (link->io.BasePort1 +
311 link->io.NumPorts1 - 1),
312 (unsigned int) link->irq.AssignedIRQ);
313 if (ipw->attr_memory && ipw->common_memory)
314 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
315 ": attr memory 0x%08lx-0x%08lx, "
316 "common memory 0x%08lx-0x%08lx\n",
317 request_attr_memory.Base,
318 request_attr_memory.Base
319 + request_attr_memory.Size - 1,
320 request_common_memory.Base,
321 request_common_memory.Base
322 + request_common_memory.Size - 1);
323
324 ipw->network = ipwireless_network_create(ipw->hardware);
325 if (!ipw->network)
326 goto exit3;
327
328 ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
329 ipw->nodes);
330 if (!ipw->tty)
331 goto exit3;
332
333 ipwireless_init_hardware_v2_v3(ipw->hardware);
334
335 /*
336 * Do the RequestConfiguration last, because it enables interrupts.
337 * Then we don't get any interrupts before we're ready for them.
338 */
339 ret = pcmcia_request_configuration(link, &link->conf);
340
341 if (ret != CS_SUCCESS) {
342 cs_error(link, RequestConfiguration, ret);
343 goto exit4;
344 }
345
346 link->dev_node = &ipw->nodes[0];
347
348 return 0;
349
350exit4:
351 pcmcia_disable_device(link);
352exit3:
353 if (ipw->attr_memory) {
354 iounmap(ipw->attr_memory);
355 pcmcia_release_window(ipw->handle_attr_memory);
356 pcmcia_disable_device(link);
357 }
358exit2:
359 if (ipw->common_memory) {
360 iounmap(ipw->common_memory);
361 pcmcia_release_window(ipw->handle_common_memory);
362 }
363exit1:
364 pcmcia_disable_device(link);
365exit0:
366 return -1;
367}
368
369static void release_ipwireless(struct ipw_dev *ipw)
370{
371 struct pcmcia_device *link = ipw->link;
372
373 pcmcia_disable_device(link);
374
375 if (ipw->common_memory)
376 iounmap(ipw->common_memory);
377 if (ipw->attr_memory)
378 iounmap(ipw->attr_memory);
379 if (ipw->common_memory)
380 pcmcia_release_window(ipw->handle_common_memory);
381 if (ipw->attr_memory)
382 pcmcia_release_window(ipw->handle_attr_memory);
383 pcmcia_disable_device(link);
384}
385
386/*
387 * ipwireless_attach() creates an "instance" of the driver, allocating
388 * local data structures for one device (one interface). The device
389 * is registered with Card Services.
390 *
391 * The pcmcia_device structure is initialized, but we don't actually
392 * configure the card at this point -- we wait until we receive a
393 * card insertion event.
394 */
395static int ipwireless_attach(struct pcmcia_device *link)
396{
397 struct ipw_dev *ipw;
398 int ret;
399
400 ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
401 if (!ipw)
402 return -ENOMEM;
403
404 ipw->link = link;
405 link->priv = ipw;
406 link->irq.Instance = ipw;
407
408 /* Link this device into our device list. */
409 link->dev_node = &ipw->nodes[0];
410
411 ipw->hardware = ipwireless_hardware_create();
412 if (!ipw->hardware) {
413 kfree(ipw);
414 return -ENOMEM;
415 }
416 /* RegisterClient will call config_ipwireless */
417
418 ret = config_ipwireless(ipw);
419
420 if (ret != 0) {
421 cs_error(link, RegisterClient, ret);
422 ipwireless_detach(link);
423 return ret;
424 }
425
426 return 0;
427}
428
429/*
430 * This deletes a driver "instance". The device is de-registered with
431 * Card Services. If it has been released, all local data structures
432 * are freed. Otherwise, the structures will be freed when the device
433 * is released.
434 */
435static void ipwireless_detach(struct pcmcia_device *link)
436{
437 struct ipw_dev *ipw = link->priv;
438
439 release_ipwireless(ipw);
440
441 /* Break the link with Card Services */
442 if (link)
443 pcmcia_disable_device(link);
444
445 if (ipw->tty != NULL)
446 ipwireless_tty_free(ipw->tty);
447 if (ipw->network != NULL)
448 ipwireless_network_free(ipw->network);
449 if (ipw->hardware != NULL)
450 ipwireless_hardware_free(ipw->hardware);
451 kfree(ipw);
452}
453
454static struct pcmcia_driver me = {
455 .owner = THIS_MODULE,
456 .probe = ipwireless_attach,
457 .remove = ipwireless_detach,
458 .drv = { .name = IPWIRELESS_PCCARD_NAME },
459 .id_table = ipw_ids
460};
461
462/*
463 * Module insertion : initialisation of the module.
464 * Register the card with cardmgr...
465 */
466static int __init init_ipwireless(void)
467{
468 int ret;
469
470 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
471 IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
472
473 ret = ipwireless_tty_init();
474 if (ret != 0)
475 return ret;
476
477 ret = pcmcia_register_driver(&me);
478 if (ret != 0)
479 ipwireless_tty_release();
480
481 return ret;
482}
483
484/*
485 * Module removal
486 */
487static void __exit exit_ipwireless(void)
488{
489 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
490 IPWIRELESS_PCMCIA_VERSION " removed\n");
491
492 pcmcia_unregister_driver(&me);
493 ipwireless_tty_release();
494}
495
496module_init(init_ipwireless);
497module_exit(exit_ipwireless);
498
499MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
500MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
501MODULE_LICENSE("GPL");
diff --git a/drivers/char/pcmcia/ipwireless/main.h b/drivers/char/pcmcia/ipwireless/main.h
new file mode 100644
index 000000000000..1bfdcc8d47d6
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/main.h
@@ -0,0 +1,70 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#ifndef _IPWIRELESS_CS_H_
19#define _IPWIRELESS_CS_H_
20
21#include <linux/sched.h>
22#include <linux/types.h>
23
24#include <pcmcia/cs_types.h>
25#include <pcmcia/cs.h>
26#include <pcmcia/cistpl.h>
27#include <pcmcia/ds.h>
28
29#include "hardware.h"
30
31#define IPWIRELESS_PCCARD_NAME "ipwireless"
32#define IPWIRELESS_PCMCIA_VERSION "1.1"
33#define IPWIRELESS_PCMCIA_AUTHOR \
34 "Stephen Blackheath, Ben Martel, Jiri Kosina and David Sterba"
35
36#define IPWIRELESS_TX_QUEUE_SIZE 262144
37#define IPWIRELESS_RX_QUEUE_SIZE 262144
38
39#define IPWIRELESS_STATE_DEBUG
40
41struct ipw_hardware;
42struct ipw_network;
43struct ipw_tty;
44
45struct ipw_dev {
46 struct pcmcia_device *link;
47 int is_v2_card;
48 window_handle_t handle_attr_memory;
49 void __iomem *attr_memory;
50 window_handle_t handle_common_memory;
51 void __iomem *common_memory;
52 dev_node_t nodes[2];
53 /* Reference to attribute memory, containing CIS data */
54 void *attribute_memory;
55
56 /* Hardware context */
57 struct ipw_hardware *hardware;
58 /* Network layer context */
59 struct ipw_network *network;
60 /* TTY device context */
61 struct ipw_tty *tty;
62 struct work_struct work_reboot;
63};
64
65/* Module parametres */
66extern int ipwireless_debug;
67extern int ipwireless_loopback;
68extern int ipwireless_out_queue;
69
70#endif
diff --git a/drivers/char/pcmcia/ipwireless/network.c b/drivers/char/pcmcia/ipwireless/network.c
new file mode 100644
index 000000000000..ff35230058d3
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/network.c
@@ -0,0 +1,512 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#include <linux/interrupt.h>
19#include <linux/kernel.h>
20#include <linux/mutex.h>
21#include <linux/netdevice.h>
22#include <linux/ppp_channel.h>
23#include <linux/ppp_defs.h>
24#include <linux/if_ppp.h>
25#include <linux/skbuff.h>
26
27#include "network.h"
28#include "hardware.h"
29#include "main.h"
30#include "tty.h"
31
32#define MAX_OUTGOING_PACKETS_QUEUED ipwireless_out_queue
33#define MAX_ASSOCIATED_TTYS 2
34
35#define SC_RCV_BITS (SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP)
36
37struct ipw_network {
38 /* Hardware context, used for calls to hardware layer. */
39 struct ipw_hardware *hardware;
40 /* Context for kernel 'generic_ppp' functionality */
41 struct ppp_channel *ppp_channel;
42 /* tty context connected with IPW console */
43 struct ipw_tty *associated_ttys[NO_OF_IPW_CHANNELS][MAX_ASSOCIATED_TTYS];
44 /* True if ppp needs waking up once we're ready to xmit */
45 int ppp_blocked;
46 /* Number of packets queued up in hardware module. */
47 int outgoing_packets_queued;
48 /* Spinlock to avoid interrupts during shutdown */
49 spinlock_t spinlock;
50 struct mutex close_lock;
51
52 /* PPP ioctl data, not actually used anywere */
53 unsigned int flags;
54 unsigned int rbits;
55 u32 xaccm[8];
56 u32 raccm;
57 int mru;
58
59 int shutting_down;
60 unsigned int ras_control_lines;
61
62 struct work_struct work_go_online;
63 struct work_struct work_go_offline;
64};
65
66
67#ifdef IPWIRELESS_STATE_DEBUG
68int ipwireless_dump_network_state(char *p, size_t limit,
69 struct ipw_network *network)
70{
71 return snprintf(p, limit,
72 "debug: ppp_blocked=%d\n"
73 "debug: outgoing_packets_queued=%d\n"
74 "debug: network.shutting_down=%d\n",
75 network->ppp_blocked,
76 network->outgoing_packets_queued,
77 network->shutting_down);
78}
79#endif
80
81static void notify_packet_sent(void *callback_data, unsigned int packet_length)
82{
83 struct ipw_network *network = callback_data;
84 unsigned long flags;
85
86 spin_lock_irqsave(&network->spinlock, flags);
87 network->outgoing_packets_queued--;
88 if (network->ppp_channel != NULL) {
89 if (network->ppp_blocked) {
90 network->ppp_blocked = 0;
91 spin_unlock_irqrestore(&network->spinlock, flags);
92 ppp_output_wakeup(network->ppp_channel);
93 if (ipwireless_debug)
94 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
95 ": ppp unblocked\n");
96 } else
97 spin_unlock_irqrestore(&network->spinlock, flags);
98 } else
99 spin_unlock_irqrestore(&network->spinlock, flags);
100}
101
102/*
103 * Called by the ppp system when it has a packet to send to the hardware.
104 */
105static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
106 struct sk_buff *skb)
107{
108 struct ipw_network *network = ppp_channel->private;
109 unsigned long flags;
110
111 spin_lock_irqsave(&network->spinlock, flags);
112 if (network->outgoing_packets_queued < MAX_OUTGOING_PACKETS_QUEUED) {
113 unsigned char *buf;
114 static unsigned char header[] = {
115 PPP_ALLSTATIONS, /* 0xff */
116 PPP_UI, /* 0x03 */
117 };
118 int ret;
119
120 network->outgoing_packets_queued++;
121 spin_unlock_irqrestore(&network->spinlock, flags);
122
123 /*
124 * If we have the requested amount of headroom in the skb we
125 * were handed, then we can add the header efficiently.
126 */
127 if (skb_headroom(skb) >= 2) {
128 memcpy(skb_push(skb, 2), header, 2);
129 ret = ipwireless_send_packet(network->hardware,
130 IPW_CHANNEL_RAS, skb->data,
131 skb->len,
132 notify_packet_sent,
133 network);
134 if (ret == -1) {
135 skb_pull(skb, 2);
136 return 0;
137 }
138 } else {
139 /* Otherwise (rarely) we do it inefficiently. */
140 buf = kmalloc(skb->len + 2, GFP_ATOMIC);
141 if (!buf)
142 return 0;
143 memcpy(buf + 2, skb->data, skb->len);
144 memcpy(buf, header, 2);
145 ret = ipwireless_send_packet(network->hardware,
146 IPW_CHANNEL_RAS, buf,
147 skb->len + 2,
148 notify_packet_sent,
149 network);
150 kfree(buf);
151 if (ret == -1)
152 return 0;
153 }
154 kfree_skb(skb);
155 return 1;
156 } else {
157 /*
158 * Otherwise reject the packet, and flag that the ppp system
159 * needs to be unblocked once we are ready to send.
160 */
161 network->ppp_blocked = 1;
162 spin_unlock_irqrestore(&network->spinlock, flags);
163 return 0;
164 }
165}
166
167/* Handle an ioctl call that has come in via ppp. (copy of ppp_async_ioctl() */
168static int ipwireless_ppp_ioctl(struct ppp_channel *ppp_channel,
169 unsigned int cmd, unsigned long arg)
170{
171 struct ipw_network *network = ppp_channel->private;
172 int err, val;
173 u32 accm[8];
174 int __user *user_arg = (int __user *) arg;
175
176 err = -EFAULT;
177 switch (cmd) {
178 case PPPIOCGFLAGS:
179 val = network->flags | network->rbits;
180 if (put_user(val, user_arg))
181 break;
182 err = 0;
183 break;
184
185 case PPPIOCSFLAGS:
186 if (get_user(val, user_arg))
187 break;
188 network->flags = val & ~SC_RCV_BITS;
189 network->rbits = val & SC_RCV_BITS;
190 err = 0;
191 break;
192
193 case PPPIOCGASYNCMAP:
194 if (put_user(network->xaccm[0], user_arg))
195 break;
196 err = 0;
197 break;
198
199 case PPPIOCSASYNCMAP:
200 if (get_user(network->xaccm[0], user_arg))
201 break;
202 err = 0;
203 break;
204
205 case PPPIOCGRASYNCMAP:
206 if (put_user(network->raccm, user_arg))
207 break;
208 err = 0;
209 break;
210
211 case PPPIOCSRASYNCMAP:
212 if (get_user(network->raccm, user_arg))
213 break;
214 err = 0;
215 break;
216
217 case PPPIOCGXASYNCMAP:
218 if (copy_to_user((void __user *) arg, network->xaccm,
219 sizeof(network->xaccm)))
220 break;
221 err = 0;
222 break;
223
224 case PPPIOCSXASYNCMAP:
225 if (copy_from_user(accm, (void __user *) arg, sizeof(accm)))
226 break;
227 accm[2] &= ~0x40000000U; /* can't escape 0x5e */
228 accm[3] |= 0x60000000U; /* must escape 0x7d, 0x7e */
229 memcpy(network->xaccm, accm, sizeof(network->xaccm));
230 err = 0;
231 break;
232
233 case PPPIOCGMRU:
234 if (put_user(network->mru, user_arg))
235 break;
236 err = 0;
237 break;
238
239 case PPPIOCSMRU:
240 if (get_user(val, user_arg))
241 break;
242 if (val < PPP_MRU)
243 val = PPP_MRU;
244 network->mru = val;
245 err = 0;
246 break;
247
248 default:
249 err = -ENOTTY;
250 }
251
252 return err;
253}
254
255static struct ppp_channel_ops ipwireless_ppp_channel_ops = {
256 .start_xmit = ipwireless_ppp_start_xmit,
257 .ioctl = ipwireless_ppp_ioctl
258};
259
260static void do_go_online(struct work_struct *work_go_online)
261{
262 struct ipw_network *network =
263 container_of(work_go_online, struct ipw_network,
264 work_go_online);
265 unsigned long flags;
266
267 spin_lock_irqsave(&network->spinlock, flags);
268 if (!network->ppp_channel) {
269 struct ppp_channel *channel;
270
271 spin_unlock_irqrestore(&network->spinlock, flags);
272 channel = kzalloc(sizeof(struct ppp_channel), GFP_KERNEL);
273 if (!channel) {
274 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
275 ": unable to allocate PPP channel\n");
276 return;
277 }
278 channel->private = network;
279 channel->mtu = 16384; /* Wild guess */
280 channel->hdrlen = 2;
281 channel->ops = &ipwireless_ppp_channel_ops;
282
283 network->flags = 0;
284 network->rbits = 0;
285 network->mru = PPP_MRU;
286 memset(network->xaccm, 0, sizeof(network->xaccm));
287 network->xaccm[0] = ~0U;
288 network->xaccm[3] = 0x60000000U;
289 network->raccm = ~0U;
290 ppp_register_channel(channel);
291 spin_lock_irqsave(&network->spinlock, flags);
292 network->ppp_channel = channel;
293 }
294 spin_unlock_irqrestore(&network->spinlock, flags);
295}
296
297static void do_go_offline(struct work_struct *work_go_offline)
298{
299 struct ipw_network *network =
300 container_of(work_go_offline, struct ipw_network,
301 work_go_offline);
302 unsigned long flags;
303
304 mutex_lock(&network->close_lock);
305 spin_lock_irqsave(&network->spinlock, flags);
306 if (network->ppp_channel != NULL) {
307 struct ppp_channel *channel = network->ppp_channel;
308
309 network->ppp_channel = NULL;
310 spin_unlock_irqrestore(&network->spinlock, flags);
311 mutex_unlock(&network->close_lock);
312 ppp_unregister_channel(channel);
313 } else {
314 spin_unlock_irqrestore(&network->spinlock, flags);
315 mutex_unlock(&network->close_lock);
316 }
317}
318
319void ipwireless_network_notify_control_line_change(struct ipw_network *network,
320 unsigned int channel_idx,
321 unsigned int control_lines,
322 unsigned int changed_mask)
323{
324 int i;
325
326 if (channel_idx == IPW_CHANNEL_RAS)
327 network->ras_control_lines = control_lines;
328
329 for (i = 0; i < MAX_ASSOCIATED_TTYS; i++) {
330 struct ipw_tty *tty =
331 network->associated_ttys[channel_idx][i];
332
333 /*
334 * If it's associated with a tty (other than the RAS channel
335 * when we're online), then send the data to that tty. The RAS
336 * channel's data is handled above - it always goes through
337 * ppp_generic.
338 */
339 if (tty)
340 ipwireless_tty_notify_control_line_change(tty,
341 channel_idx,
342 control_lines,
343 changed_mask);
344 }
345}
346
347/*
348 * Some versions of firmware stuff packets with 0xff 0x03 (PPP: ALLSTATIONS, UI)
349 * bytes, which are required on sent packet, but not always present on received
350 * packets
351 */
352static struct sk_buff *ipw_packet_received_skb(unsigned char *data,
353 unsigned int length)
354{
355 struct sk_buff *skb;
356
357 if (length > 2 && data[0] == PPP_ALLSTATIONS && data[1] == PPP_UI) {
358 length -= 2;
359 data += 2;
360 }
361
362 skb = dev_alloc_skb(length + 4);
363 skb_reserve(skb, 2);
364 memcpy(skb_put(skb, length), data, length);
365
366 return skb;
367}
368
369void ipwireless_network_packet_received(struct ipw_network *network,
370 unsigned int channel_idx,
371 unsigned char *data,
372 unsigned int length)
373{
374 int i;
375 unsigned long flags;
376
377 for (i = 0; i < MAX_ASSOCIATED_TTYS; i++) {
378 struct ipw_tty *tty = network->associated_ttys[channel_idx][i];
379
380 /*
381 * If it's associated with a tty (other than the RAS channel
382 * when we're online), then send the data to that tty. The RAS
383 * channel's data is handled above - it always goes through
384 * ppp_generic.
385 */
386 if (tty && channel_idx == IPW_CHANNEL_RAS
387 && (network->ras_control_lines &
388 IPW_CONTROL_LINE_DCD) != 0
389 && ipwireless_tty_is_modem(tty)) {
390 /*
391 * If data came in on the RAS channel and this tty is
392 * the modem tty, and we are online, then we send it to
393 * the PPP layer.
394 */
395 mutex_lock(&network->close_lock);
396 spin_lock_irqsave(&network->spinlock, flags);
397 if (network->ppp_channel != NULL) {
398 struct sk_buff *skb;
399
400 spin_unlock_irqrestore(&network->spinlock,
401 flags);
402
403 /* Send the data to the ppp_generic module. */
404 skb = ipw_packet_received_skb(data, length);
405 ppp_input(network->ppp_channel, skb);
406 } else
407 spin_unlock_irqrestore(&network->spinlock,
408 flags);
409 mutex_unlock(&network->close_lock);
410 }
411 /* Otherwise we send it out the tty. */
412 else
413 ipwireless_tty_received(tty, data, length);
414 }
415}
416
417struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw)
418{
419 struct ipw_network *network =
420 kzalloc(sizeof(struct ipw_network), GFP_ATOMIC);
421
422 if (!network)
423 return NULL;
424
425 spin_lock_init(&network->spinlock);
426 mutex_init(&network->close_lock);
427
428 network->hardware = hw;
429
430 INIT_WORK(&network->work_go_online, do_go_online);
431 INIT_WORK(&network->work_go_offline, do_go_offline);
432
433 ipwireless_associate_network(hw, network);
434
435 return network;
436}
437
438void ipwireless_network_free(struct ipw_network *network)
439{
440 network->shutting_down = 1;
441
442 ipwireless_ppp_close(network);
443 flush_scheduled_work();
444
445 ipwireless_stop_interrupts(network->hardware);
446 ipwireless_associate_network(network->hardware, NULL);
447
448 kfree(network);
449}
450
451void ipwireless_associate_network_tty(struct ipw_network *network,
452 unsigned int channel_idx,
453 struct ipw_tty *tty)
454{
455 int i;
456
457 for (i = 0; i < MAX_ASSOCIATED_TTYS; i++)
458 if (network->associated_ttys[channel_idx][i] == NULL) {
459 network->associated_ttys[channel_idx][i] = tty;
460 break;
461 }
462}
463
464void ipwireless_disassociate_network_ttys(struct ipw_network *network,
465 unsigned int channel_idx)
466{
467 int i;
468
469 for (i = 0; i < MAX_ASSOCIATED_TTYS; i++)
470 network->associated_ttys[channel_idx][i] = NULL;
471}
472
473void ipwireless_ppp_open(struct ipw_network *network)
474{
475 if (ipwireless_debug)
476 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME ": online\n");
477 schedule_work(&network->work_go_online);
478}
479
480void ipwireless_ppp_close(struct ipw_network *network)
481{
482 /* Disconnect from the wireless network. */
483 if (ipwireless_debug)
484 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME ": offline\n");
485 schedule_work(&network->work_go_offline);
486}
487
488int ipwireless_ppp_channel_index(struct ipw_network *network)
489{
490 int ret = -1;
491 unsigned long flags;
492
493 spin_lock_irqsave(&network->spinlock, flags);
494 if (network->ppp_channel != NULL)
495 ret = ppp_channel_index(network->ppp_channel);
496 spin_unlock_irqrestore(&network->spinlock, flags);
497
498 return ret;
499}
500
501int ipwireless_ppp_unit_number(struct ipw_network *network)
502{
503 int ret = -1;
504 unsigned long flags;
505
506 spin_lock_irqsave(&network->spinlock, flags);
507 if (network->ppp_channel != NULL)
508 ret = ppp_unit_number(network->ppp_channel);
509 spin_unlock_irqrestore(&network->spinlock, flags);
510
511 return ret;
512}
diff --git a/drivers/char/pcmcia/ipwireless/network.h b/drivers/char/pcmcia/ipwireless/network.h
new file mode 100644
index 000000000000..b0e1e952fd14
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/network.h
@@ -0,0 +1,55 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#ifndef _IPWIRELESS_CS_NETWORK_H_
19#define _IPWIRELESS_CS_NETWORK_H_
20
21#include <linux/types.h>
22
23struct ipw_network;
24struct ipw_tty;
25struct ipw_hardware;
26
27/* Definitions of the different channels on the PCMCIA UE */
28#define IPW_CHANNEL_RAS 0
29#define IPW_CHANNEL_DIALLER 1
30#define IPW_CHANNEL_CONSOLE 2
31#define NO_OF_IPW_CHANNELS 5
32
33void ipwireless_network_notify_control_line_change(struct ipw_network *net,
34 unsigned int channel_idx, unsigned int control_lines,
35 unsigned int control_mask);
36void ipwireless_network_packet_received(struct ipw_network *net,
37 unsigned int channel_idx, unsigned char *data,
38 unsigned int length);
39struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw);
40void ipwireless_network_free(struct ipw_network *net);
41void ipwireless_associate_network_tty(struct ipw_network *net,
42 unsigned int channel_idx, struct ipw_tty *tty);
43void ipwireless_disassociate_network_ttys(struct ipw_network *net,
44 unsigned int channel_idx);
45
46void ipwireless_ppp_open(struct ipw_network *net);
47
48void ipwireless_ppp_close(struct ipw_network *net);
49int ipwireless_ppp_channel_index(struct ipw_network *net);
50int ipwireless_ppp_unit_number(struct ipw_network *net);
51
52int ipwireless_dump_network_state(char *p, size_t limit,
53 struct ipw_network *net);
54
55#endif
diff --git a/drivers/char/pcmcia/ipwireless/setup_protocol.h b/drivers/char/pcmcia/ipwireless/setup_protocol.h
new file mode 100644
index 000000000000..9d6bcc77c73c
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/setup_protocol.h
@@ -0,0 +1,108 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#ifndef _IPWIRELESS_CS_SETUP_PROTOCOL_H_
19#define _IPWIRELESS_CS_SETUP_PROTOCOL_H_
20
21/* Version of the setup protocol and transport protocols */
22#define TL_SETUP_VERSION 1
23
24#define TL_SETUP_VERSION_QRY_TMO 1000
25#define TL_SETUP_MAX_VERSION_QRY 30
26
27/* Message numbers 0-9 are obsoleted and must not be reused! */
28#define TL_SETUP_SIGNO_GET_VERSION_QRY 10
29#define TL_SETUP_SIGNO_GET_VERSION_RSP 11
30#define TL_SETUP_SIGNO_CONFIG_MSG 12
31#define TL_SETUP_SIGNO_CONFIG_DONE_MSG 13
32#define TL_SETUP_SIGNO_OPEN_MSG 14
33#define TL_SETUP_SIGNO_CLOSE_MSG 15
34
35#define TL_SETUP_SIGNO_INFO_MSG 20
36#define TL_SETUP_SIGNO_INFO_MSG_ACK 21
37
38#define TL_SETUP_SIGNO_REBOOT_MSG 22
39#define TL_SETUP_SIGNO_REBOOT_MSG_ACK 23
40
41/* Synchronous start-messages */
42struct tl_setup_get_version_qry {
43 unsigned char sig_no; /* TL_SETUP_SIGNO_GET_VERSION_QRY */
44} __attribute__ ((__packed__));
45
46struct tl_setup_get_version_rsp {
47 unsigned char sig_no; /* TL_SETUP_SIGNO_GET_VERSION_RSP */
48 unsigned char version; /* TL_SETUP_VERSION */
49} __attribute__ ((__packed__));
50
51struct tl_setup_config_msg {
52 unsigned char sig_no; /* TL_SETUP_SIGNO_CONFIG_MSG */
53 unsigned char port_no;
54 unsigned char prio_data;
55 unsigned char prio_ctrl;
56} __attribute__ ((__packed__));
57
58struct tl_setup_config_done_msg {
59 unsigned char sig_no; /* TL_SETUP_SIGNO_CONFIG_DONE_MSG */
60} __attribute__ ((__packed__));
61
62/* Asyncronous messages */
63struct tl_setup_open_msg {
64 unsigned char sig_no; /* TL_SETUP_SIGNO_OPEN_MSG */
65 unsigned char port_no;
66} __attribute__ ((__packed__));
67
68struct tl_setup_close_msg {
69 unsigned char sig_no; /* TL_SETUP_SIGNO_CLOSE_MSG */
70 unsigned char port_no;
71} __attribute__ ((__packed__));
72
73/* Driver type - for use in tl_setup_info_msg.driver_type */
74#define COMM_DRIVER 0
75#define NDISWAN_DRIVER 1
76#define NDISWAN_DRIVER_MAJOR_VERSION 2
77#define NDISWAN_DRIVER_MINOR_VERSION 0
78
79/*
80 * It should not matter when this message comes over as we just store the
81 * results and send the ACK.
82 */
83struct tl_setup_info_msg {
84 unsigned char sig_no; /* TL_SETUP_SIGNO_INFO_MSG */
85 unsigned char driver_type;
86 unsigned char major_version;
87 unsigned char minor_version;
88} __attribute__ ((__packed__));
89
90struct tl_setup_info_msgAck {
91 unsigned char sig_no; /* TL_SETUP_SIGNO_INFO_MSG_ACK */
92} __attribute__ ((__packed__));
93
94struct TlSetupRebootMsgAck {
95 unsigned char sig_no; /* TL_SETUP_SIGNO_REBOOT_MSG_ACK */
96} __attribute__ ((__packed__));
97
98/* Define a union of all the msgs that the driver can receive from the card.*/
99union ipw_setup_rx_msg {
100 unsigned char sig_no;
101 struct tl_setup_get_version_rsp version_rsp_msg;
102 struct tl_setup_open_msg open_msg;
103 struct tl_setup_close_msg close_msg;
104 struct tl_setup_info_msg InfoMsg;
105 struct tl_setup_info_msgAck info_msg_ack;
106} __attribute__ ((__packed__));
107
108#endif /* _IPWIRELESS_CS_SETUP_PROTOCOL_H_ */
diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
new file mode 100644
index 000000000000..42f3815c5ce3
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/tty.c
@@ -0,0 +1,688 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/mutex.h>
22#include <linux/ppp_defs.h>
23#include <linux/if.h>
24#include <linux/if_ppp.h>
25#include <linux/sched.h>
26#include <linux/serial.h>
27#include <linux/slab.h>
28#include <linux/tty.h>
29#include <linux/tty_driver.h>
30#include <linux/tty_flip.h>
31#include <linux/uaccess.h>
32#include <linux/version.h>
33
34#include "tty.h"
35#include "network.h"
36#include "hardware.h"
37#include "main.h"
38
39#define IPWIRELESS_PCMCIA_START (0)
40#define IPWIRELESS_PCMCIA_MINORS (24)
41#define IPWIRELESS_PCMCIA_MINOR_RANGE (8)
42
43#define TTYTYPE_MODEM (0)
44#define TTYTYPE_MONITOR (1)
45#define TTYTYPE_RAS_RAW (2)
46
47struct ipw_tty {
48 int index;
49 struct ipw_hardware *hardware;
50 unsigned int channel_idx;
51 unsigned int secondary_channel_idx;
52 int tty_type;
53 struct ipw_network *network;
54 struct tty_struct *linux_tty;
55 int open_count;
56 unsigned int control_lines;
57 struct mutex ipw_tty_mutex;
58 int tx_bytes_queued;
59 int closing;
60};
61
62static struct ipw_tty *ttys[IPWIRELESS_PCMCIA_MINORS];
63
64static struct tty_driver *ipw_tty_driver;
65
66static char *tty_type_name(int tty_type)
67{
68 static char *channel_names[] = {
69 "modem",
70 "monitor",
71 "RAS-raw"
72 };
73
74 return channel_names[tty_type];
75}
76
77static void report_registering(struct ipw_tty *tty)
78{
79 char *iftype = tty_type_name(tty->tty_type);
80
81 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
82 ": registering %s device ttyIPWp%d\n", iftype, tty->index);
83}
84
85static void report_deregistering(struct ipw_tty *tty)
86{
87 char *iftype = tty_type_name(tty->tty_type);
88
89 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
90 ": deregistering %s device ttyIPWp%d\n", iftype,
91 tty->index);
92}
93
94static struct ipw_tty *get_tty(int minor)
95{
96 if (minor < ipw_tty_driver->minor_start
97 || minor >= ipw_tty_driver->minor_start +
98 IPWIRELESS_PCMCIA_MINORS)
99 return NULL;
100 else {
101 int minor_offset = minor - ipw_tty_driver->minor_start;
102
103 /*
104 * The 'ras_raw' channel is only available when 'loopback' mode
105 * is enabled.
106 * Number of minor starts with 16 (_RANGE * _RAS_RAW).
107 */
108 if (!ipwireless_loopback &&
109 minor_offset >=
110 IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW)
111 return NULL;
112
113 return ttys[minor_offset];
114 }
115}
116
117static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
118{
119 int minor = linux_tty->index;
120 struct ipw_tty *tty = get_tty(minor);
121
122 if (!tty)
123 return -ENODEV;
124
125 mutex_lock(&tty->ipw_tty_mutex);
126
127 if (tty->closing) {
128 mutex_unlock(&tty->ipw_tty_mutex);
129 return -ENODEV;
130 }
131 if (tty->open_count == 0)
132 tty->tx_bytes_queued = 0;
133
134 tty->open_count++;
135
136 tty->linux_tty = linux_tty;
137 linux_tty->driver_data = tty;
138 linux_tty->low_latency = 1;
139
140 if (tty->tty_type == TTYTYPE_MODEM)
141 ipwireless_ppp_open(tty->network);
142
143 mutex_unlock(&tty->ipw_tty_mutex);
144
145 return 0;
146}
147
148static void do_ipw_close(struct ipw_tty *tty)
149{
150 tty->open_count--;
151
152 if (tty->open_count == 0) {
153 struct tty_struct *linux_tty = tty->linux_tty;
154
155 if (linux_tty != NULL) {
156 tty->linux_tty = NULL;
157 linux_tty->driver_data = NULL;
158
159 if (tty->tty_type == TTYTYPE_MODEM)
160 ipwireless_ppp_close(tty->network);
161 }
162 }
163}
164
165static void ipw_hangup(struct tty_struct *linux_tty)
166{
167 struct ipw_tty *tty = linux_tty->driver_data;
168
169 if (!tty)
170 return;
171
172 mutex_lock(&tty->ipw_tty_mutex);
173 if (tty->open_count == 0) {
174 mutex_unlock(&tty->ipw_tty_mutex);
175 return;
176 }
177
178 do_ipw_close(tty);
179
180 mutex_unlock(&tty->ipw_tty_mutex);
181}
182
183static void ipw_close(struct tty_struct *linux_tty, struct file *filp)
184{
185 ipw_hangup(linux_tty);
186}
187
188/* Take data received from hardware, and send it out the tty */
189void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
190 unsigned int length)
191{
192 struct tty_struct *linux_tty;
193 int work = 0;
194
195 mutex_lock(&tty->ipw_tty_mutex);
196 linux_tty = tty->linux_tty;
197 if (linux_tty == NULL) {
198 mutex_unlock(&tty->ipw_tty_mutex);
199 return;
200 }
201
202 if (!tty->open_count) {
203 mutex_unlock(&tty->ipw_tty_mutex);
204 return;
205 }
206 mutex_unlock(&tty->ipw_tty_mutex);
207
208 work = tty_insert_flip_string(linux_tty, data, length);
209
210 if (work != length)
211 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
212 ": %d chars not inserted to flip buffer!\n",
213 length - work);
214
215 /*
216 * This may sleep if ->low_latency is set
217 */
218 if (work)
219 tty_flip_buffer_push(linux_tty);
220}
221
222static void ipw_write_packet_sent_callback(void *callback_data,
223 unsigned int packet_length)
224{
225 struct ipw_tty *tty = callback_data;
226
227 /*
228 * Packet has been sent, so we subtract the number of bytes from our
229 * tally of outstanding TX bytes.
230 */
231 tty->tx_bytes_queued -= packet_length;
232}
233
234static int ipw_write(struct tty_struct *linux_tty,
235 const unsigned char *buf, int count)
236{
237 struct ipw_tty *tty = linux_tty->driver_data;
238 int room, ret;
239
240 if (!tty)
241 return -ENODEV;
242
243 mutex_lock(&tty->ipw_tty_mutex);
244 if (!tty->open_count) {
245 mutex_unlock(&tty->ipw_tty_mutex);
246 return -EINVAL;
247 }
248
249 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
250 if (room < 0)
251 room = 0;
252 /* Don't allow caller to write any more than we have room for */
253 if (count > room)
254 count = room;
255
256 if (count == 0) {
257 mutex_unlock(&tty->ipw_tty_mutex);
258 return 0;
259 }
260
261 ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
262 (unsigned char *) buf, count,
263 ipw_write_packet_sent_callback, tty);
264 if (ret == -1) {
265 mutex_unlock(&tty->ipw_tty_mutex);
266 return 0;
267 }
268
269 tty->tx_bytes_queued += count;
270 mutex_unlock(&tty->ipw_tty_mutex);
271
272 return count;
273}
274
275static int ipw_write_room(struct tty_struct *linux_tty)
276{
277 struct ipw_tty *tty = linux_tty->driver_data;
278 int room;
279
280 if (!tty)
281 return -ENODEV;
282
283 if (!tty->open_count)
284 return -EINVAL;
285
286 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
287 if (room < 0)
288 room = 0;
289
290 return room;
291}
292
293static int ipwireless_get_serial_info(struct ipw_tty *tty,
294 struct serial_struct __user *retinfo)
295{
296 struct serial_struct tmp;
297
298 if (!retinfo)
299 return (-EFAULT);
300
301 memset(&tmp, 0, sizeof(tmp));
302 tmp.type = PORT_UNKNOWN;
303 tmp.line = tty->index;
304 tmp.port = 0;
305 tmp.irq = 0;
306 tmp.flags = 0;
307 tmp.baud_base = 115200;
308 tmp.close_delay = 0;
309 tmp.closing_wait = 0;
310 tmp.custom_divisor = 0;
311 tmp.hub6 = 0;
312 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
313 return -EFAULT;
314
315 return 0;
316}
317
318static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
319{
320 struct ipw_tty *tty = linux_tty->driver_data;
321
322 if (!tty)
323 return -ENODEV;
324
325 if (!tty->open_count)
326 return -EINVAL;
327
328 return tty->tx_bytes_queued;
329}
330
331static int get_control_lines(struct ipw_tty *tty)
332{
333 unsigned int my = tty->control_lines;
334 unsigned int out = 0;
335
336 if (my & IPW_CONTROL_LINE_RTS)
337 out |= TIOCM_RTS;
338 if (my & IPW_CONTROL_LINE_DTR)
339 out |= TIOCM_DTR;
340 if (my & IPW_CONTROL_LINE_CTS)
341 out |= TIOCM_CTS;
342 if (my & IPW_CONTROL_LINE_DSR)
343 out |= TIOCM_DSR;
344 if (my & IPW_CONTROL_LINE_DCD)
345 out |= TIOCM_CD;
346
347 return out;
348}
349
350static int set_control_lines(struct ipw_tty *tty, unsigned int set,
351 unsigned int clear)
352{
353 int ret;
354
355 if (set & TIOCM_RTS) {
356 ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 1);
357 if (ret)
358 return ret;
359 if (tty->secondary_channel_idx != -1) {
360 ret = ipwireless_set_RTS(tty->hardware,
361 tty->secondary_channel_idx, 1);
362 if (ret)
363 return ret;
364 }
365 }
366 if (set & TIOCM_DTR) {
367 ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 1);
368 if (ret)
369 return ret;
370 if (tty->secondary_channel_idx != -1) {
371 ret = ipwireless_set_DTR(tty->hardware,
372 tty->secondary_channel_idx, 1);
373 if (ret)
374 return ret;
375 }
376 }
377 if (clear & TIOCM_RTS) {
378 ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 0);
379 if (tty->secondary_channel_idx != -1) {
380 ret = ipwireless_set_RTS(tty->hardware,
381 tty->secondary_channel_idx, 0);
382 if (ret)
383 return ret;
384 }
385 }
386 if (clear & TIOCM_DTR) {
387 ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 0);
388 if (tty->secondary_channel_idx != -1) {
389 ret = ipwireless_set_DTR(tty->hardware,
390 tty->secondary_channel_idx, 0);
391 if (ret)
392 return ret;
393 }
394 }
395 return 0;
396}
397
398static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
399{
400 struct ipw_tty *tty = linux_tty->driver_data;
401
402 if (!tty)
403 return -ENODEV;
404
405 if (!tty->open_count)
406 return -EINVAL;
407
408 return get_control_lines(tty);
409}
410
411static int
412ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
413 unsigned int set, unsigned int clear)
414{
415 struct ipw_tty *tty = linux_tty->driver_data;
416
417 if (!tty)
418 return -ENODEV;
419
420 if (!tty->open_count)
421 return -EINVAL;
422
423 return set_control_lines(tty, set, clear);
424}
425
426static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
427 unsigned int cmd, unsigned long arg)
428{
429 struct ipw_tty *tty = linux_tty->driver_data;
430
431 if (!tty)
432 return -ENODEV;
433
434 if (!tty->open_count)
435 return -EINVAL;
436
437 switch (cmd) {
438 case TIOCGSERIAL:
439 return ipwireless_get_serial_info(tty, (void __user *) arg);
440
441 case TIOCSSERIAL:
442 return 0; /* Keeps the PCMCIA scripts happy. */
443 }
444
445 if (tty->tty_type == TTYTYPE_MODEM) {
446 switch (cmd) {
447 case PPPIOCGCHAN:
448 {
449 int chan = ipwireless_ppp_channel_index(
450 tty->network);
451
452 if (chan < 0)
453 return -ENODEV;
454 if (put_user(chan, (int __user *) arg))
455 return -EFAULT;
456 }
457 return 0;
458
459 case PPPIOCGUNIT:
460 {
461 int unit = ipwireless_ppp_unit_number(
462 tty->network);
463
464 if (unit < 0)
465 return -ENODEV;
466 if (put_user(unit, (int __user *) arg))
467 return -EFAULT;
468 }
469 return 0;
470
471 case TCGETS:
472 case TCGETA:
473 return n_tty_ioctl(linux_tty, file, cmd, arg);
474
475 case TCFLSH:
476 return n_tty_ioctl(linux_tty, file, cmd, arg);
477
478 case FIONREAD:
479 {
480 int val = 0;
481
482 if (put_user(val, (int __user *) arg))
483 return -EFAULT;
484 }
485 return 0;
486 }
487 }
488
489 return -ENOIOCTLCMD;
490}
491
492static int add_tty(dev_node_t *nodesp, int j,
493 struct ipw_hardware *hardware,
494 struct ipw_network *network, int channel_idx,
495 int secondary_channel_idx, int tty_type)
496{
497 ttys[j] = kzalloc(sizeof(struct ipw_tty), GFP_KERNEL);
498 if (!ttys[j])
499 return -ENOMEM;
500 ttys[j]->index = j;
501 ttys[j]->hardware = hardware;
502 ttys[j]->channel_idx = channel_idx;
503 ttys[j]->secondary_channel_idx = secondary_channel_idx;
504 ttys[j]->network = network;
505 ttys[j]->tty_type = tty_type;
506 mutex_init(&ttys[j]->ipw_tty_mutex);
507
508 tty_register_device(ipw_tty_driver, j, NULL);
509 ipwireless_associate_network_tty(network, channel_idx, ttys[j]);
510
511 if (secondary_channel_idx != -1)
512 ipwireless_associate_network_tty(network,
513 secondary_channel_idx,
514 ttys[j]);
515 if (nodesp != NULL) {
516 sprintf(nodesp->dev_name, "ttyIPWp%d", j);
517 nodesp->major = ipw_tty_driver->major;
518 nodesp->minor = j + ipw_tty_driver->minor_start;
519 }
520 if (get_tty(j + ipw_tty_driver->minor_start) == ttys[j])
521 report_registering(ttys[j]);
522 return 0;
523}
524
525struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hardware,
526 struct ipw_network *network,
527 dev_node_t *nodes)
528{
529 int i, j;
530
531 for (i = 0; i < IPWIRELESS_PCMCIA_MINOR_RANGE; i++) {
532 int allfree = 1;
533
534 for (j = i; j < IPWIRELESS_PCMCIA_MINORS;
535 j += IPWIRELESS_PCMCIA_MINOR_RANGE)
536 if (ttys[j] != NULL) {
537 allfree = 0;
538 break;
539 }
540
541 if (allfree) {
542 j = i;
543
544 if (add_tty(&nodes[0], j, hardware, network,
545 IPW_CHANNEL_DIALLER, IPW_CHANNEL_RAS,
546 TTYTYPE_MODEM))
547 return NULL;
548
549 j += IPWIRELESS_PCMCIA_MINOR_RANGE;
550 if (add_tty(&nodes[1], j, hardware, network,
551 IPW_CHANNEL_DIALLER, -1,
552 TTYTYPE_MONITOR))
553 return NULL;
554
555 j += IPWIRELESS_PCMCIA_MINOR_RANGE;
556 if (add_tty(NULL, j, hardware, network,
557 IPW_CHANNEL_RAS, -1,
558 TTYTYPE_RAS_RAW))
559 return NULL;
560
561 nodes[0].next = &nodes[1];
562 nodes[1].next = NULL;
563
564 return ttys[i];
565 }
566 }
567 return NULL;
568}
569
570/*
571 * Must be called before ipwireless_network_free().
572 */
573void ipwireless_tty_free(struct ipw_tty *tty)
574{
575 int j;
576 struct ipw_network *network = ttys[tty->index]->network;
577
578 for (j = tty->index; j < IPWIRELESS_PCMCIA_MINORS;
579 j += IPWIRELESS_PCMCIA_MINOR_RANGE) {
580 struct ipw_tty *ttyj = ttys[j];
581
582 if (ttyj) {
583 mutex_lock(&ttyj->ipw_tty_mutex);
584 if (get_tty(j + ipw_tty_driver->minor_start) == ttyj)
585 report_deregistering(ttyj);
586 ttyj->closing = 1;
587 if (ttyj->linux_tty != NULL) {
588 mutex_unlock(&ttyj->ipw_tty_mutex);
589 tty_hangup(ttyj->linux_tty);
590 /* Wait till the tty_hangup has completed */
591 flush_scheduled_work();
592 mutex_lock(&ttyj->ipw_tty_mutex);
593 }
594 while (ttyj->open_count)
595 do_ipw_close(ttyj);
596 ipwireless_disassociate_network_ttys(network,
597 ttyj->channel_idx);
598 tty_unregister_device(ipw_tty_driver, j);
599 ttys[j] = NULL;
600 mutex_unlock(&ttyj->ipw_tty_mutex);
601 kfree(ttyj);
602 }
603 }
604}
605
606static struct tty_operations tty_ops = {
607 .open = ipw_open,
608 .close = ipw_close,
609 .hangup = ipw_hangup,
610 .write = ipw_write,
611 .write_room = ipw_write_room,
612 .ioctl = ipw_ioctl,
613 .chars_in_buffer = ipw_chars_in_buffer,
614 .tiocmget = ipw_tiocmget,
615 .tiocmset = ipw_tiocmset,
616};
617
618int ipwireless_tty_init(void)
619{
620 int result;
621
622 ipw_tty_driver = alloc_tty_driver(IPWIRELESS_PCMCIA_MINORS);
623 if (!ipw_tty_driver)
624 return -ENOMEM;
625
626 ipw_tty_driver->owner = THIS_MODULE;
627 ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME;
628 ipw_tty_driver->name = "ttyIPWp";
629 ipw_tty_driver->major = 0;
630 ipw_tty_driver->minor_start = IPWIRELESS_PCMCIA_START;
631 ipw_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
632 ipw_tty_driver->subtype = SERIAL_TYPE_NORMAL;
633 ipw_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
634 ipw_tty_driver->init_termios = tty_std_termios;
635 ipw_tty_driver->init_termios.c_cflag =
636 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
637 ipw_tty_driver->init_termios.c_ispeed = 9600;
638 ipw_tty_driver->init_termios.c_ospeed = 9600;
639 tty_set_operations(ipw_tty_driver, &tty_ops);
640 result = tty_register_driver(ipw_tty_driver);
641 if (result) {
642 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
643 ": failed to register tty driver\n");
644 put_tty_driver(ipw_tty_driver);
645 return result;
646 }
647
648 return 0;
649}
650
651void ipwireless_tty_release(void)
652{
653 int ret;
654
655 ret = tty_unregister_driver(ipw_tty_driver);
656 put_tty_driver(ipw_tty_driver);
657 if (ret != 0)
658 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
659 ": tty_unregister_driver failed with code %d\n", ret);
660}
661
662int ipwireless_tty_is_modem(struct ipw_tty *tty)
663{
664 return tty->tty_type == TTYTYPE_MODEM;
665}
666
667void
668ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
669 unsigned int channel_idx,
670 unsigned int control_lines,
671 unsigned int changed_mask)
672{
673 unsigned int old_control_lines = tty->control_lines;
674
675 tty->control_lines = (tty->control_lines & ~changed_mask)
676 | (control_lines & changed_mask);
677
678 /*
679 * If DCD is de-asserted, we close the tty so pppd can tell that we
680 * have gone offline.
681 */
682 if ((old_control_lines & IPW_CONTROL_LINE_DCD)
683 && !(tty->control_lines & IPW_CONTROL_LINE_DCD)
684 && tty->linux_tty) {
685 tty_hangup(tty->linux_tty);
686 }
687}
688
diff --git a/drivers/char/pcmcia/ipwireless/tty.h b/drivers/char/pcmcia/ipwireless/tty.h
new file mode 100644
index 000000000000..b0deb9168b6b
--- /dev/null
+++ b/drivers/char/pcmcia/ipwireless/tty.h
@@ -0,0 +1,48 @@
1/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#ifndef _IPWIRELESS_CS_TTY_H_
19#define _IPWIRELESS_CS_TTY_H_
20
21#include <linux/types.h>
22#include <linux/sched.h>
23
24#include <pcmcia/cs_types.h>
25#include <pcmcia/cs.h>
26#include <pcmcia/cistpl.h>
27#include <pcmcia/ds.h>
28
29struct ipw_tty;
30struct ipw_network;
31struct ipw_hardware;
32
33int ipwireless_tty_init(void);
34void ipwireless_tty_release(void);
35
36struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hw,
37 struct ipw_network *net,
38 dev_node_t *nodes);
39void ipwireless_tty_free(struct ipw_tty *tty);
40void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
41 unsigned int length);
42int ipwireless_tty_is_modem(struct ipw_tty *tty);
43void ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
44 unsigned int channel_idx,
45 unsigned int control_lines,
46 unsigned int changed_mask);
47
48#endif
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index e0bade732376..1412d7bcdbd1 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -43,18 +43,12 @@ static char * __init dmi_string(const struct dmi_header *dm, u8 s)
43 * We have to be cautious here. We have seen BIOSes with DMI pointers 43 * We have to be cautious here. We have seen BIOSes with DMI pointers
44 * pointing to completely the wrong place for example 44 * pointing to completely the wrong place for example
45 */ 45 */
46static int __init dmi_table(u32 base, int len, int num, 46static void dmi_table(u8 *buf, int len, int num,
47 void (*decode)(const struct dmi_header *)) 47 void (*decode)(const struct dmi_header *))
48{ 48{
49 u8 *buf, *data; 49 u8 *data = buf;
50 int i = 0; 50 int i = 0;
51 51
52 buf = dmi_ioremap(base, len);
53 if (buf == NULL)
54 return -1;
55
56 data = buf;
57
58 /* 52 /*
59 * Stop when we see all the items the table claimed to have 53 * Stop when we see all the items the table claimed to have
60 * OR we run off the end of the table (also happens) 54 * OR we run off the end of the table (also happens)
@@ -75,7 +69,23 @@ static int __init dmi_table(u32 base, int len, int num,
75 data += 2; 69 data += 2;
76 i++; 70 i++;
77 } 71 }
78 dmi_iounmap(buf, len); 72}
73
74static u32 dmi_base;
75static u16 dmi_len;
76static u16 dmi_num;
77
78static int __init dmi_walk_early(void (*decode)(const struct dmi_header *))
79{
80 u8 *buf;
81
82 buf = dmi_ioremap(dmi_base, dmi_len);
83 if (buf == NULL)
84 return -1;
85
86 dmi_table(buf, dmi_len, dmi_num, decode);
87
88 dmi_iounmap(buf, dmi_len);
79 return 0; 89 return 0;
80} 90}
81 91
@@ -291,9 +301,9 @@ static int __init dmi_present(const char __iomem *p)
291 301
292 memcpy_fromio(buf, p, 15); 302 memcpy_fromio(buf, p, 15);
293 if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) { 303 if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
294 u16 num = (buf[13] << 8) | buf[12]; 304 dmi_num = (buf[13] << 8) | buf[12];
295 u16 len = (buf[7] << 8) | buf[6]; 305 dmi_len = (buf[7] << 8) | buf[6];
296 u32 base = (buf[11] << 24) | (buf[10] << 16) | 306 dmi_base = (buf[11] << 24) | (buf[10] << 16) |
297 (buf[9] << 8) | buf[8]; 307 (buf[9] << 8) | buf[8];
298 308
299 /* 309 /*
@@ -305,7 +315,7 @@ static int __init dmi_present(const char __iomem *p)
305 buf[14] >> 4, buf[14] & 0xF); 315 buf[14] >> 4, buf[14] & 0xF);
306 else 316 else
307 printk(KERN_INFO "DMI present.\n"); 317 printk(KERN_INFO "DMI present.\n");
308 if (dmi_table(base,len, num, dmi_decode) == 0) 318 if (dmi_walk_early(dmi_decode) == 0)
309 return 0; 319 return 0;
310 } 320 }
311 return 1; 321 return 1;
@@ -489,3 +499,27 @@ int dmi_get_year(int field)
489 499
490 return year; 500 return year;
491} 501}
502
503/**
504 * dmi_walk - Walk the DMI table and get called back for every record
505 * @decode: Callback function
506 *
507 * Returns -1 when the DMI table can't be reached, 0 on success.
508 */
509int dmi_walk(void (*decode)(const struct dmi_header *))
510{
511 u8 *buf;
512
513 if (!dmi_available)
514 return -1;
515
516 buf = ioremap(dmi_base, dmi_len);
517 if (buf == NULL)
518 return -1;
519
520 dmi_table(buf, dmi_len, dmi_num, decode);
521
522 iounmap(buf);
523 return 0;
524}
525EXPORT_SYMBOL_GPL(dmi_walk);
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a0445bea9f75..410ffe4e9d80 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -433,12 +433,12 @@ config SENSORS_LM85
433 will be called lm85. 433 will be called lm85.
434 434
435config SENSORS_LM87 435config SENSORS_LM87
436 tristate "National Semiconductor LM87" 436 tristate "National Semiconductor LM87 and compatibles"
437 depends on I2C 437 depends on I2C
438 select HWMON_VID 438 select HWMON_VID
439 help 439 help
440 If you say yes here you get support for National Semiconductor LM87 440 If you say yes here you get support for National Semiconductor LM87
441 sensor chips. 441 and Analog Devices ADM1024 sensor chips.
442 442
443 This driver can also be built as a module. If so, the module 443 This driver can also be built as a module. If so, the module
444 will be called lm87. 444 will be called lm87.
@@ -588,6 +588,16 @@ config SENSORS_SMSC47B397
588 This driver can also be built as a module. If so, the module 588 This driver can also be built as a module. If so, the module
589 will be called smsc47b397. 589 will be called smsc47b397.
590 590
591config SENSORS_ADS7828
592 tristate "Texas Instruments ADS7828"
593 depends on I2C
594 help
595 If you say yes here you get support for Texas Instruments ADS7828
596 12-bit 8-channel ADC device.
597
598 This driver can also be built as a module. If so, the module
599 will be called ads7828.
600
591config SENSORS_THMC50 601config SENSORS_THMC50
592 tristate "Texas Instruments THMC50 / Analog Devices ADM1022" 602 tristate "Texas Instruments THMC50 / Analog Devices ADM1022"
593 depends on I2C && EXPERIMENTAL 603 depends on I2C && EXPERIMENTAL
@@ -631,13 +641,13 @@ config SENSORS_VT8231
631 will be called vt8231. 641 will be called vt8231.
632 642
633config SENSORS_W83781D 643config SENSORS_W83781D
634 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F" 644 tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F"
635 depends on I2C 645 depends on I2C
636 select HWMON_VID 646 select HWMON_VID
637 help 647 help
638 If you say yes here you get support for the Winbond W8378x series 648 If you say yes here you get support for the Winbond W8378x series
639 of sensor chips: the W83781D, W83782D, W83783S and W83627HF, 649 of sensor chips: the W83781D, W83782D and W83783S, and the similar
640 and the similar Asus AS99127F. 650 Asus AS99127F.
641 651
642 This driver can also be built as a module. If so, the module 652 This driver can also be built as a module. If so, the module
643 will be called w83781d. 653 will be called w83781d.
@@ -683,6 +693,16 @@ config SENSORS_W83L785TS
683 This driver can also be built as a module. If so, the module 693 This driver can also be built as a module. If so, the module
684 will be called w83l785ts. 694 will be called w83l785ts.
685 695
696config SENSORS_W83L786NG
697 tristate "Winbond W83L786NG, W83L786NR"
698 depends on I2C && EXPERIMENTAL
699 help
700 If you say yes here you get support for the Winbond W83L786NG
701 and W83L786NR sensor chips.
702
703 This driver can also be built as a module. If so, the module
704 will be called w83l786ng.
705
686config SENSORS_W83627HF 706config SENSORS_W83627HF
687 tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF" 707 tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF"
688 select HWMON_VID 708 select HWMON_VID
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 55595f6e1aa6..824161337f1c 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
22obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o 22obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o
23obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 23obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
24obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 24obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
25obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o
25obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o 26obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o
26obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o 27obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
27obj-$(CONFIG_SENSORS_AMS) += ams/ 28obj-$(CONFIG_SENSORS_AMS) += ams/
@@ -68,6 +69,7 @@ obj-$(CONFIG_SENSORS_VT1211) += vt1211.o
68obj-$(CONFIG_SENSORS_VT8231) += vt8231.o 69obj-$(CONFIG_SENSORS_VT8231) += vt8231.o
69obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o 70obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o
70obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o 71obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o
72obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
71 73
72ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y) 74ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y)
73EXTRA_CFLAGS += -DDEBUG 75EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
index d9f04ce90327..ed33fddc4dee 100644
--- a/drivers/hwmon/abituguru3.c
+++ b/drivers/hwmon/abituguru3.c
@@ -528,6 +528,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = {
528 { "AUX1 Fan", 33, 2, 60, 1, 0 }, 528 { "AUX1 Fan", 33, 2, 60, 1, 0 },
529 { "AUX2 Fan", 35, 2, 60, 1, 0 }, 529 { "AUX2 Fan", 35, 2, 60, 1, 0 },
530 { "AUX3 Fan", 36, 2, 60, 1, 0 }, 530 { "AUX3 Fan", 36, 2, 60, 1, 0 },
531 { "AUX4 Fan", 37, 2, 60, 1, 0 },
531 { NULL, 0, 0, 0, 0, 0 } } 532 { NULL, 0, 0, 0, 0, 0 } }
532 }, 533 },
533 { 0x001B, "unknown", { 534 { 0x001B, "unknown", {
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index ebdc6d7db231..b96be772e498 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -115,7 +115,6 @@ static struct i2c_driver adm1021_driver = {
115 .driver = { 115 .driver = {
116 .name = "adm1021", 116 .name = "adm1021",
117 }, 117 },
118 .id = I2C_DRIVERID_ADM1021,
119 .attach_adapter = adm1021_attach_adapter, 118 .attach_adapter = adm1021_attach_adapter,
120 .detach_client = adm1021_detach_client, 119 .detach_client = adm1021_detach_client,
121}; 120};
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 041ecb0bdf48..e96c3725203d 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -51,6 +51,7 @@
51#include <linux/jiffies.h> 51#include <linux/jiffies.h>
52#include <linux/i2c.h> 52#include <linux/i2c.h>
53#include <linux/hwmon.h> 53#include <linux/hwmon.h>
54#include <linux/hwmon-sysfs.h>
54#include <linux/hwmon-vid.h> 55#include <linux/hwmon-vid.h>
55#include <linux/err.h> 56#include <linux/err.h>
56#include <linux/mutex.h> 57#include <linux/mutex.h>
@@ -74,7 +75,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
74 */ 75 */
75 76
76#define ADM1025_REG_MAN_ID 0x3E 77#define ADM1025_REG_MAN_ID 0x3E
77#define ADM1025_REG_CHIP_ID 0x3F 78#define ADM1025_REG_CHIP_ID 0x3F
78#define ADM1025_REG_CONFIG 0x40 79#define ADM1025_REG_CONFIG 0x40
79#define ADM1025_REG_STATUS1 0x41 80#define ADM1025_REG_STATUS1 0x41
80#define ADM1025_REG_STATUS2 0x42 81#define ADM1025_REG_STATUS2 0x42
@@ -92,7 +93,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
92 * The ADM1025 uses signed 8-bit values for temperatures. 93 * The ADM1025 uses signed 8-bit values for temperatures.
93 */ 94 */
94 95
95static int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 }; 96static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
96 97
97#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192) 98#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
98#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \ 99#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \
@@ -122,7 +123,6 @@ static struct i2c_driver adm1025_driver = {
122 .driver = { 123 .driver = {
123 .name = "adm1025", 124 .name = "adm1025",
124 }, 125 },
125 .id = I2C_DRIVERID_ADM1025,
126 .attach_adapter = adm1025_attach_adapter, 126 .attach_adapter = adm1025_attach_adapter,
127 .detach_client = adm1025_detach_client, 127 .detach_client = adm1025_detach_client,
128}; 128};
@@ -153,86 +153,96 @@ struct adm1025_data {
153 * Sysfs stuff 153 * Sysfs stuff
154 */ 154 */
155 155
156#define show_in(offset) \ 156static ssize_t
157static ssize_t show_in##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 157show_in(struct device *dev, struct device_attribute *attr, char *buf)
158{ \ 158{
159 struct adm1025_data *data = adm1025_update_device(dev); \ 159 int index = to_sensor_dev_attr(attr)->index;
160 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ 160 struct adm1025_data *data = adm1025_update_device(dev);
161 in_scale[offset])); \ 161 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[index],
162} \ 162 in_scale[index]));
163static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 163}
164{ \ 164
165 struct adm1025_data *data = adm1025_update_device(dev); \ 165static ssize_t
166 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \ 166show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
167 in_scale[offset])); \ 167{
168} \ 168 int index = to_sensor_dev_attr(attr)->index;
169static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ 169 struct adm1025_data *data = adm1025_update_device(dev);
170{ \ 170 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[index],
171 struct adm1025_data *data = adm1025_update_device(dev); \ 171 in_scale[index]));
172 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \ 172}
173 in_scale[offset])); \ 173
174} \ 174static ssize_t
175static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); 175show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
176show_in(0); 176{
177show_in(1); 177 int index = to_sensor_dev_attr(attr)->index;
178show_in(2); 178 struct adm1025_data *data = adm1025_update_device(dev);
179show_in(3); 179 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[index],
180show_in(4); 180 in_scale[index]));
181show_in(5); 181}
182 182
183#define show_temp(offset) \ 183static ssize_t
184static ssize_t show_temp##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 184show_temp(struct device *dev, struct device_attribute *attr, char *buf)
185{ \ 185{
186 struct adm1025_data *data = adm1025_update_device(dev); \ 186 int index = to_sensor_dev_attr(attr)->index;
187 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ 187 struct adm1025_data *data = adm1025_update_device(dev);
188} \ 188 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[index]));
189static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 189}
190{ \ 190
191 struct adm1025_data *data = adm1025_update_device(dev); \ 191static ssize_t
192 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \ 192show_temp_min(struct device *dev, struct device_attribute *attr, char *buf)
193} \ 193{
194static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ 194 int index = to_sensor_dev_attr(attr)->index;
195{ \ 195 struct adm1025_data *data = adm1025_update_device(dev);
196 struct adm1025_data *data = adm1025_update_device(dev); \ 196 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[index]));
197 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \ 197}
198}\ 198
199static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp##offset, NULL); 199static ssize_t
200show_temp(1); 200show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
201show_temp(2); 201{
202 int index = to_sensor_dev_attr(attr)->index;
203 struct adm1025_data *data = adm1025_update_device(dev);
204 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
205}
206
207static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
208 const char *buf, size_t count)
209{
210 int index = to_sensor_dev_attr(attr)->index;
211 struct i2c_client *client = to_i2c_client(dev);
212 struct adm1025_data *data = i2c_get_clientdata(client);
213 long val = simple_strtol(buf, NULL, 10);
214
215 mutex_lock(&data->update_lock);
216 data->in_min[index] = IN_TO_REG(val, in_scale[index]);
217 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(index),
218 data->in_min[index]);
219 mutex_unlock(&data->update_lock);
220 return count;
221}
222
223static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
224 const char *buf, size_t count)
225{
226 int index = to_sensor_dev_attr(attr)->index;
227 struct i2c_client *client = to_i2c_client(dev);
228 struct adm1025_data *data = i2c_get_clientdata(client);
229 long val = simple_strtol(buf, NULL, 10);
230
231 mutex_lock(&data->update_lock);
232 data->in_max[index] = IN_TO_REG(val, in_scale[index]);
233 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(index),
234 data->in_max[index]);
235 mutex_unlock(&data->update_lock);
236 return count;
237}
202 238
203#define set_in(offset) \ 239#define set_in(offset) \
204static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 240static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
205 size_t count) \ 241 show_in, NULL, offset); \
206{ \ 242static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
207 struct i2c_client *client = to_i2c_client(dev); \ 243 show_in_min, set_in_min, offset); \
208 struct adm1025_data *data = i2c_get_clientdata(client); \ 244static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
209 long val = simple_strtol(buf, NULL, 10); \ 245 show_in_max, set_in_max, offset)
210 \
211 mutex_lock(&data->update_lock); \
212 data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
213 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
214 data->in_min[offset]); \
215 mutex_unlock(&data->update_lock); \
216 return count; \
217} \
218static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
219 size_t count) \
220{ \
221 struct i2c_client *client = to_i2c_client(dev); \
222 struct adm1025_data *data = i2c_get_clientdata(client); \
223 long val = simple_strtol(buf, NULL, 10); \
224 \
225 mutex_lock(&data->update_lock); \
226 data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
227 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
228 data->in_max[offset]); \
229 mutex_unlock(&data->update_lock); \
230 return count; \
231} \
232static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
233 show_in##offset##_min, set_in##offset##_min); \
234static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
235 show_in##offset##_max, set_in##offset##_max);
236set_in(0); 246set_in(0);
237set_in(1); 247set_in(1);
238set_in(2); 248set_in(2);
@@ -240,65 +250,91 @@ set_in(3);
240set_in(4); 250set_in(4);
241set_in(5); 251set_in(5);
242 252
253static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
254 const char *buf, size_t count)
255{
256 int index = to_sensor_dev_attr(attr)->index;
257 struct i2c_client *client = to_i2c_client(dev);
258 struct adm1025_data *data = i2c_get_clientdata(client);
259 long val = simple_strtol(buf, NULL, 10);
260
261 mutex_lock(&data->update_lock);
262 data->temp_min[index] = TEMP_TO_REG(val);
263 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(index),
264 data->temp_min[index]);
265 mutex_unlock(&data->update_lock);
266 return count;
267}
268
269static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
270 const char *buf, size_t count)
271{
272 int index = to_sensor_dev_attr(attr)->index;
273 struct i2c_client *client = to_i2c_client(dev);
274 struct adm1025_data *data = i2c_get_clientdata(client);
275 long val = simple_strtol(buf, NULL, 10);
276
277 mutex_lock(&data->update_lock);
278 data->temp_max[index] = TEMP_TO_REG(val);
279 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(index),
280 data->temp_max[index]);
281 mutex_unlock(&data->update_lock);
282 return count;
283}
284
243#define set_temp(offset) \ 285#define set_temp(offset) \
244static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 286static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
245 size_t count) \ 287 show_temp, NULL, offset - 1); \
246{ \ 288static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
247 struct i2c_client *client = to_i2c_client(dev); \ 289 show_temp_min, set_temp_min, offset - 1); \
248 struct adm1025_data *data = i2c_get_clientdata(client); \ 290static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
249 long val = simple_strtol(buf, NULL, 10); \ 291 show_temp_max, set_temp_max, offset - 1)
250 \
251 mutex_lock(&data->update_lock); \
252 data->temp_min[offset-1] = TEMP_TO_REG(val); \
253 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
254 data->temp_min[offset-1]); \
255 mutex_unlock(&data->update_lock); \
256 return count; \
257} \
258static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
259 size_t count) \
260{ \
261 struct i2c_client *client = to_i2c_client(dev); \
262 struct adm1025_data *data = i2c_get_clientdata(client); \
263 long val = simple_strtol(buf, NULL, 10); \
264 \
265 mutex_lock(&data->update_lock); \
266 data->temp_max[offset-1] = TEMP_TO_REG(val); \
267 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
268 data->temp_max[offset-1]); \
269 mutex_unlock(&data->update_lock); \
270 return count; \
271} \
272static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
273 show_temp##offset##_min, set_temp##offset##_min); \
274static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
275 show_temp##offset##_max, set_temp##offset##_max);
276set_temp(1); 292set_temp(1);
277set_temp(2); 293set_temp(2);
278 294
279static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 295static ssize_t
296show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
280{ 297{
281 struct adm1025_data *data = adm1025_update_device(dev); 298 struct adm1025_data *data = adm1025_update_device(dev);
282 return sprintf(buf, "%u\n", data->alarms); 299 return sprintf(buf, "%u\n", data->alarms);
283} 300}
284static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 301static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
285 302
286static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 303static ssize_t
304show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
305{
306 int bitnr = to_sensor_dev_attr(attr)->index;
307 struct adm1025_data *data = adm1025_update_device(dev);
308 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
309}
310static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
311static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
312static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
313static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
314static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
315static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
316static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 5);
317static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
318static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
319
320static ssize_t
321show_vid(struct device *dev, struct device_attribute *attr, char *buf)
287{ 322{
288 struct adm1025_data *data = adm1025_update_device(dev); 323 struct adm1025_data *data = adm1025_update_device(dev);
289 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 324 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
290} 325}
291static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 326static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
292 327
293static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 328static ssize_t
329show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
294{ 330{
295 struct adm1025_data *data = dev_get_drvdata(dev); 331 struct adm1025_data *data = dev_get_drvdata(dev);
296 return sprintf(buf, "%u\n", data->vrm); 332 return sprintf(buf, "%u\n", data->vrm);
297} 333}
298static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 334static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
335 const char *buf, size_t count)
299{ 336{
300 struct i2c_client *client = to_i2c_client(dev); 337 struct adm1025_data *data = dev_get_drvdata(dev);
301 struct adm1025_data *data = i2c_get_clientdata(client);
302 data->vrm = simple_strtoul(buf, NULL, 10); 338 data->vrm = simple_strtoul(buf, NULL, 10);
303 return count; 339 return count;
304} 340}
@@ -316,27 +352,35 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter)
316} 352}
317 353
318static struct attribute *adm1025_attributes[] = { 354static struct attribute *adm1025_attributes[] = {
319 &dev_attr_in0_input.attr, 355 &sensor_dev_attr_in0_input.dev_attr.attr,
320 &dev_attr_in1_input.attr, 356 &sensor_dev_attr_in1_input.dev_attr.attr,
321 &dev_attr_in2_input.attr, 357 &sensor_dev_attr_in2_input.dev_attr.attr,
322 &dev_attr_in3_input.attr, 358 &sensor_dev_attr_in3_input.dev_attr.attr,
323 &dev_attr_in5_input.attr, 359 &sensor_dev_attr_in5_input.dev_attr.attr,
324 &dev_attr_in0_min.attr, 360 &sensor_dev_attr_in0_min.dev_attr.attr,
325 &dev_attr_in1_min.attr, 361 &sensor_dev_attr_in1_min.dev_attr.attr,
326 &dev_attr_in2_min.attr, 362 &sensor_dev_attr_in2_min.dev_attr.attr,
327 &dev_attr_in3_min.attr, 363 &sensor_dev_attr_in3_min.dev_attr.attr,
328 &dev_attr_in5_min.attr, 364 &sensor_dev_attr_in5_min.dev_attr.attr,
329 &dev_attr_in0_max.attr, 365 &sensor_dev_attr_in0_max.dev_attr.attr,
330 &dev_attr_in1_max.attr, 366 &sensor_dev_attr_in1_max.dev_attr.attr,
331 &dev_attr_in2_max.attr, 367 &sensor_dev_attr_in2_max.dev_attr.attr,
332 &dev_attr_in3_max.attr, 368 &sensor_dev_attr_in3_max.dev_attr.attr,
333 &dev_attr_in5_max.attr, 369 &sensor_dev_attr_in5_max.dev_attr.attr,
334 &dev_attr_temp1_input.attr, 370 &sensor_dev_attr_in0_alarm.dev_attr.attr,
335 &dev_attr_temp2_input.attr, 371 &sensor_dev_attr_in1_alarm.dev_attr.attr,
336 &dev_attr_temp1_min.attr, 372 &sensor_dev_attr_in2_alarm.dev_attr.attr,
337 &dev_attr_temp2_min.attr, 373 &sensor_dev_attr_in3_alarm.dev_attr.attr,
338 &dev_attr_temp1_max.attr, 374 &sensor_dev_attr_in5_alarm.dev_attr.attr,
339 &dev_attr_temp2_max.attr, 375 &sensor_dev_attr_temp1_input.dev_attr.attr,
376 &sensor_dev_attr_temp2_input.dev_attr.attr,
377 &sensor_dev_attr_temp1_min.dev_attr.attr,
378 &sensor_dev_attr_temp2_min.dev_attr.attr,
379 &sensor_dev_attr_temp1_max.dev_attr.attr,
380 &sensor_dev_attr_temp2_max.dev_attr.attr,
381 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
382 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
383 &sensor_dev_attr_temp1_fault.dev_attr.attr,
340 &dev_attr_alarms.attr, 384 &dev_attr_alarms.attr,
341 &dev_attr_cpu0_vid.attr, 385 &dev_attr_cpu0_vid.attr,
342 &dev_attr_vrm.attr, 386 &dev_attr_vrm.attr,
@@ -347,15 +391,16 @@ static const struct attribute_group adm1025_group = {
347 .attrs = adm1025_attributes, 391 .attrs = adm1025_attributes,
348}; 392};
349 393
350static struct attribute *adm1025_attributes_opt[] = { 394static struct attribute *adm1025_attributes_in4[] = {
351 &dev_attr_in4_input.attr, 395 &sensor_dev_attr_in4_input.dev_attr.attr,
352 &dev_attr_in4_min.attr, 396 &sensor_dev_attr_in4_min.dev_attr.attr,
353 &dev_attr_in4_max.attr, 397 &sensor_dev_attr_in4_max.dev_attr.attr,
398 &sensor_dev_attr_in4_alarm.dev_attr.attr,
354 NULL 399 NULL
355}; 400};
356 401
357static const struct attribute_group adm1025_group_opt = { 402static const struct attribute_group adm1025_group_in4 = {
358 .attrs = adm1025_attributes_opt, 403 .attrs = adm1025_attributes_in4,
359}; 404};
360 405
361/* 406/*
@@ -364,7 +409,7 @@ static const struct attribute_group adm1025_group_opt = {
364 */ 409 */
365static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) 410static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
366{ 411{
367 struct i2c_client *new_client; 412 struct i2c_client *client;
368 struct adm1025_data *data; 413 struct adm1025_data *data;
369 int err = 0; 414 int err = 0;
370 const char *name = ""; 415 const char *name = "";
@@ -378,14 +423,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
378 goto exit; 423 goto exit;
379 } 424 }
380 425
381 /* The common I2C client data is placed right before the 426 client = &data->client;
382 ADM1025-specific data. */ 427 i2c_set_clientdata(client, data);
383 new_client = &data->client; 428 client->addr = address;
384 i2c_set_clientdata(new_client, data); 429 client->adapter = adapter;
385 new_client->addr = address; 430 client->driver = &adm1025_driver;
386 new_client->adapter = adapter;
387 new_client->driver = &adm1025_driver;
388 new_client->flags = 0;
389 431
390 /* 432 /*
391 * Now we do the remaining detection. A negative kind means that 433 * Now we do the remaining detection. A negative kind means that
@@ -397,12 +439,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
397 * requested, so both the detection and the identification steps 439 * requested, so both the detection and the identification steps
398 * are skipped. 440 * are skipped.
399 */ 441 */
400 config = i2c_smbus_read_byte_data(new_client, ADM1025_REG_CONFIG); 442 config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
401 if (kind < 0) { /* detection */ 443 if (kind < 0) { /* detection */
402 if ((config & 0x80) != 0x00 444 if ((config & 0x80) != 0x00
403 || (i2c_smbus_read_byte_data(new_client, 445 || (i2c_smbus_read_byte_data(client,
404 ADM1025_REG_STATUS1) & 0xC0) != 0x00 446 ADM1025_REG_STATUS1) & 0xC0) != 0x00
405 || (i2c_smbus_read_byte_data(new_client, 447 || (i2c_smbus_read_byte_data(client,
406 ADM1025_REG_STATUS2) & 0xBC) != 0x00) { 448 ADM1025_REG_STATUS2) & 0xBC) != 0x00) {
407 dev_dbg(&adapter->dev, 449 dev_dbg(&adapter->dev,
408 "ADM1025 detection failed at 0x%02x.\n", 450 "ADM1025 detection failed at 0x%02x.\n",
@@ -414,11 +456,9 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
414 if (kind <= 0) { /* identification */ 456 if (kind <= 0) { /* identification */
415 u8 man_id, chip_id; 457 u8 man_id, chip_id;
416 458
417 man_id = i2c_smbus_read_byte_data(new_client, 459 man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID);
418 ADM1025_REG_MAN_ID); 460 chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);
419 chip_id = i2c_smbus_read_byte_data(new_client, 461
420 ADM1025_REG_CHIP_ID);
421
422 if (man_id == 0x41) { /* Analog Devices */ 462 if (man_id == 0x41) { /* Analog Devices */
423 if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */ 463 if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */
424 kind = adm1025; 464 kind = adm1025;
@@ -446,33 +486,28 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
446 } 486 }
447 487
448 /* We can fill in the remaining client fields */ 488 /* We can fill in the remaining client fields */
449 strlcpy(new_client->name, name, I2C_NAME_SIZE); 489 strlcpy(client->name, name, I2C_NAME_SIZE);
450 data->valid = 0;
451 mutex_init(&data->update_lock); 490 mutex_init(&data->update_lock);
452 491
453 /* Tell the I2C layer a new client has arrived */ 492 /* Tell the I2C layer a new client has arrived */
454 if ((err = i2c_attach_client(new_client))) 493 if ((err = i2c_attach_client(client)))
455 goto exit_free; 494 goto exit_free;
456 495
457 /* Initialize the ADM1025 chip */ 496 /* Initialize the ADM1025 chip */
458 adm1025_init_client(new_client); 497 adm1025_init_client(client);
459 498
460 /* Register sysfs hooks */ 499 /* Register sysfs hooks */
461 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1025_group))) 500 if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group)))
462 goto exit_detach; 501 goto exit_detach;
463 502
464 /* Pin 11 is either in4 (+12V) or VID4 */ 503 /* Pin 11 is either in4 (+12V) or VID4 */
465 if (!(config & 0x20)) { 504 if (!(config & 0x20)) {
466 if ((err = device_create_file(&new_client->dev, 505 if ((err = sysfs_create_group(&client->dev.kobj,
467 &dev_attr_in4_input)) 506 &adm1025_group_in4)))
468 || (err = device_create_file(&new_client->dev,
469 &dev_attr_in4_min))
470 || (err = device_create_file(&new_client->dev,
471 &dev_attr_in4_max)))
472 goto exit_remove; 507 goto exit_remove;
473 } 508 }
474 509
475 data->hwmon_dev = hwmon_device_register(&new_client->dev); 510 data->hwmon_dev = hwmon_device_register(&client->dev);
476 if (IS_ERR(data->hwmon_dev)) { 511 if (IS_ERR(data->hwmon_dev)) {
477 err = PTR_ERR(data->hwmon_dev); 512 err = PTR_ERR(data->hwmon_dev);
478 goto exit_remove; 513 goto exit_remove;
@@ -481,10 +516,10 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
481 return 0; 516 return 0;
482 517
483exit_remove: 518exit_remove:
484 sysfs_remove_group(&new_client->dev.kobj, &adm1025_group); 519 sysfs_remove_group(&client->dev.kobj, &adm1025_group);
485 sysfs_remove_group(&new_client->dev.kobj, &adm1025_group_opt); 520 sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
486exit_detach: 521exit_detach:
487 i2c_detach_client(new_client); 522 i2c_detach_client(client);
488exit_free: 523exit_free:
489 kfree(data); 524 kfree(data);
490exit: 525exit:
@@ -540,7 +575,7 @@ static int adm1025_detach_client(struct i2c_client *client)
540 575
541 hwmon_device_unregister(data->hwmon_dev); 576 hwmon_device_unregister(data->hwmon_dev);
542 sysfs_remove_group(&client->dev.kobj, &adm1025_group); 577 sysfs_remove_group(&client->dev.kobj, &adm1025_group);
543 sysfs_remove_group(&client->dev.kobj, &adm1025_group_opt); 578 sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
544 579
545 if ((err = i2c_detach_client(client))) 580 if ((err = i2c_detach_client(client)))
546 return err; 581 return err;
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 3e63c1486770..8002f68240c4 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -40,8 +40,8 @@ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
40/* Insmod parameters */ 40/* Insmod parameters */
41I2C_CLIENT_INSMOD_1(adm1026); 41I2C_CLIENT_INSMOD_1(adm1026);
42 42
43static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, 43static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
44 -1, -1, -1, -1, -1, -1, -1, -1 }; 44 -1, -1, -1, -1, -1, -1, -1, -1 };
45static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, 45static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
46 -1, -1, -1, -1, -1, -1, -1, -1 }; 46 -1, -1, -1, -1, -1, -1, -1, -1 };
47static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, 47static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -49,46 +49,49 @@ static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
49static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, 49static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
50 -1, -1, -1, -1, -1, -1, -1, -1 }; 50 -1, -1, -1, -1, -1, -1, -1, -1 };
51static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; 51static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
52module_param_array(gpio_input,int,NULL,0); 52module_param_array(gpio_input, int, NULL, 0);
53MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs"); 53MODULE_PARM_DESC(gpio_input, "List of GPIO pins (0-16) to program as inputs");
54module_param_array(gpio_output,int,NULL,0); 54module_param_array(gpio_output, int, NULL, 0);
55MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as " 55MODULE_PARM_DESC(gpio_output, "List of GPIO pins (0-16) to program as "
56 "outputs"); 56 "outputs");
57module_param_array(gpio_inverted,int,NULL,0); 57module_param_array(gpio_inverted, int, NULL, 0);
58MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as " 58MODULE_PARM_DESC(gpio_inverted, "List of GPIO pins (0-16) to program as "
59 "inverted"); 59 "inverted");
60module_param_array(gpio_normal,int,NULL,0); 60module_param_array(gpio_normal, int, NULL, 0);
61MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as " 61MODULE_PARM_DESC(gpio_normal, "List of GPIO pins (0-16) to program as "
62 "normal/non-inverted"); 62 "normal/non-inverted");
63module_param_array(gpio_fan,int,NULL,0); 63module_param_array(gpio_fan, int, NULL, 0);
64MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs"); 64MODULE_PARM_DESC(gpio_fan, "List of GPIO pins (0-7) to program as fan tachs");
65 65
66/* Many ADM1026 constants specified below */ 66/* Many ADM1026 constants specified below */
67 67
68/* The ADM1026 registers */ 68/* The ADM1026 registers */
69#define ADM1026_REG_CONFIG1 0x00 69#define ADM1026_REG_CONFIG1 0x00
70#define CFG1_MONITOR 0x01 70#define CFG1_MONITOR 0x01
71#define CFG1_INT_ENABLE 0x02 71#define CFG1_INT_ENABLE 0x02
72#define CFG1_INT_CLEAR 0x04 72#define CFG1_INT_CLEAR 0x04
73#define CFG1_AIN8_9 0x08 73#define CFG1_AIN8_9 0x08
74#define CFG1_THERM_HOT 0x10 74#define CFG1_THERM_HOT 0x10
75#define CFG1_DAC_AFC 0x20 75#define CFG1_DAC_AFC 0x20
76#define CFG1_PWM_AFC 0x40 76#define CFG1_PWM_AFC 0x40
77#define CFG1_RESET 0x80 77#define CFG1_RESET 0x80
78#define ADM1026_REG_CONFIG2 0x01 78
79#define ADM1026_REG_CONFIG2 0x01
79/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */ 80/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
80#define ADM1026_REG_CONFIG3 0x07 81
81#define CFG3_GPIO16_ENABLE 0x01 82#define ADM1026_REG_CONFIG3 0x07
82#define CFG3_CI_CLEAR 0x02 83#define CFG3_GPIO16_ENABLE 0x01
83#define CFG3_VREF_250 0x04 84#define CFG3_CI_CLEAR 0x02
84#define CFG3_GPIO16_DIR 0x40 85#define CFG3_VREF_250 0x04
85#define CFG3_GPIO16_POL 0x80 86#define CFG3_GPIO16_DIR 0x40
86#define ADM1026_REG_E2CONFIG 0x13 87#define CFG3_GPIO16_POL 0x80
87#define E2CFG_READ 0x01 88
88#define E2CFG_WRITE 0x02 89#define ADM1026_REG_E2CONFIG 0x13
89#define E2CFG_ERASE 0x04 90#define E2CFG_READ 0x01
90#define E2CFG_ROM 0x08 91#define E2CFG_WRITE 0x02
91#define E2CFG_CLK_EXT 0x80 92#define E2CFG_ERASE 0x04
93#define E2CFG_ROM 0x08
94#define E2CFG_CLK_EXT 0x80
92 95
93/* There are 10 general analog inputs and 7 dedicated inputs 96/* There are 10 general analog inputs and 7 dedicated inputs
94 * They are: 97 * They are:
@@ -129,48 +132,48 @@ static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
129static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f }; 132static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
130static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f }; 133static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
131 134
132#define ADM1026_REG_FAN(nr) (0x38 + (nr)) 135#define ADM1026_REG_FAN(nr) (0x38 + (nr))
133#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr)) 136#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
134#define ADM1026_REG_FAN_DIV_0_3 0x02 137#define ADM1026_REG_FAN_DIV_0_3 0x02
135#define ADM1026_REG_FAN_DIV_4_7 0x03 138#define ADM1026_REG_FAN_DIV_4_7 0x03
136 139
137#define ADM1026_REG_DAC 0x04 140#define ADM1026_REG_DAC 0x04
138#define ADM1026_REG_PWM 0x05 141#define ADM1026_REG_PWM 0x05
139 142
140#define ADM1026_REG_GPIO_CFG_0_3 0x08 143#define ADM1026_REG_GPIO_CFG_0_3 0x08
141#define ADM1026_REG_GPIO_CFG_4_7 0x09 144#define ADM1026_REG_GPIO_CFG_4_7 0x09
142#define ADM1026_REG_GPIO_CFG_8_11 0x0a 145#define ADM1026_REG_GPIO_CFG_8_11 0x0a
143#define ADM1026_REG_GPIO_CFG_12_15 0x0b 146#define ADM1026_REG_GPIO_CFG_12_15 0x0b
144/* CFG_16 in REG_CFG3 */ 147/* CFG_16 in REG_CFG3 */
145#define ADM1026_REG_GPIO_STATUS_0_7 0x24 148#define ADM1026_REG_GPIO_STATUS_0_7 0x24
146#define ADM1026_REG_GPIO_STATUS_8_15 0x25 149#define ADM1026_REG_GPIO_STATUS_8_15 0x25
147/* STATUS_16 in REG_STATUS4 */ 150/* STATUS_16 in REG_STATUS4 */
148#define ADM1026_REG_GPIO_MASK_0_7 0x1c 151#define ADM1026_REG_GPIO_MASK_0_7 0x1c
149#define ADM1026_REG_GPIO_MASK_8_15 0x1d 152#define ADM1026_REG_GPIO_MASK_8_15 0x1d
150/* MASK_16 in REG_MASK4 */ 153/* MASK_16 in REG_MASK4 */
151 154
152#define ADM1026_REG_COMPANY 0x16 155#define ADM1026_REG_COMPANY 0x16
153#define ADM1026_REG_VERSTEP 0x17 156#define ADM1026_REG_VERSTEP 0x17
154/* These are the recognized values for the above regs */ 157/* These are the recognized values for the above regs */
155#define ADM1026_COMPANY_ANALOG_DEV 0x41 158#define ADM1026_COMPANY_ANALOG_DEV 0x41
156#define ADM1026_VERSTEP_GENERIC 0x40 159#define ADM1026_VERSTEP_GENERIC 0x40
157#define ADM1026_VERSTEP_ADM1026 0x44 160#define ADM1026_VERSTEP_ADM1026 0x44
158 161
159#define ADM1026_REG_MASK1 0x18 162#define ADM1026_REG_MASK1 0x18
160#define ADM1026_REG_MASK2 0x19 163#define ADM1026_REG_MASK2 0x19
161#define ADM1026_REG_MASK3 0x1a 164#define ADM1026_REG_MASK3 0x1a
162#define ADM1026_REG_MASK4 0x1b 165#define ADM1026_REG_MASK4 0x1b
163 166
164#define ADM1026_REG_STATUS1 0x20 167#define ADM1026_REG_STATUS1 0x20
165#define ADM1026_REG_STATUS2 0x21 168#define ADM1026_REG_STATUS2 0x21
166#define ADM1026_REG_STATUS3 0x22 169#define ADM1026_REG_STATUS3 0x22
167#define ADM1026_REG_STATUS4 0x23 170#define ADM1026_REG_STATUS4 0x23
168 171
169#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6 172#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
170#define ADM1026_FAN_CONTROL_TEMP_RANGE 20 173#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
171#define ADM1026_PWM_MAX 255 174#define ADM1026_PWM_MAX 255
172 175
173/* Conversions. Rounding and limit checking is only done on the TO_REG 176/* Conversions. Rounding and limit checking is only done on the TO_REG
174 * variants. Note that you should be a bit careful with which arguments 177 * variants. Note that you should be a bit careful with which arguments
175 * these macros are called: arguments may be evaluated more than once. 178 * these macros are called: arguments may be evaluated more than once.
176 */ 179 */
@@ -186,52 +189,49 @@ static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
186 * The values in this table are based on Table II, page 15 of the 189 * The values in this table are based on Table II, page 15 of the
187 * datasheet. 190 * datasheet.
188 */ 191 */
189static int adm1026_scaling[] = { /* .001 Volts */ 192static int adm1026_scaling[] = { /* .001 Volts */
190 2250, 2250, 2250, 2250, 2250, 2250, 193 2250, 2250, 2250, 2250, 2250, 2250,
191 1875, 1875, 1875, 1875, 3000, 3330, 194 1875, 1875, 1875, 1875, 3000, 3330,
192 3330, 4995, 2250, 12000, 13875 195 3330, 4995, 2250, 12000, 13875
193 }; 196 };
194#define NEG12_OFFSET 16000 197#define NEG12_OFFSET 16000
195#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from)) 198#define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from))
196#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\ 199#define INS_TO_REG(n, val) (SENSORS_LIMIT(SCALE(val, adm1026_scaling[n], 192),\
197 0,255)) 200 0, 255))
198#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n])) 201#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))
199 202
200/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses 203/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
201 * and we assume a 2 pulse-per-rev fan tach signal 204 * and we assume a 2 pulse-per-rev fan tach signal
202 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000 205 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
203 */ 206 */
204#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\ 207#define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \
205 (div)),1,254)) 208 SENSORS_LIMIT(1350000/((val)*(div)), 1, 254))
206#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\ 209#define FAN_FROM_REG(val, div) ((val) == 0 ? -1:(val) == 0xff ? 0 : \
207 (div))) 210 1350000/((val)*(div)))
208#define DIV_FROM_REG(val) (1<<(val)) 211#define DIV_FROM_REG(val) (1<<(val))
209#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0) 212#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)
210 213
211/* Temperature is reported in 1 degC increments */ 214/* Temperature is reported in 1 degC increments */
212#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\ 215#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
213 -127,127)) 216 -127, 127))
214#define TEMP_FROM_REG(val) ((val) * 1000) 217#define TEMP_FROM_REG(val) ((val) * 1000)
215#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\ 218#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
216 -127,127)) 219 -127, 127))
217#define OFFSET_FROM_REG(val) ((val) * 1000) 220#define OFFSET_FROM_REG(val) ((val) * 1000)
218 221
219#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255)) 222#define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255))
220#define PWM_FROM_REG(val) (val) 223#define PWM_FROM_REG(val) (val)
221 224
222#define PWM_MIN_TO_REG(val) ((val) & 0xf0) 225#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
223#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4)) 226#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
224 227
225/* Analog output is a voltage, and scaled to millivolts. The datasheet 228/* Analog output is a voltage, and scaled to millivolts. The datasheet
226 * indicates that the DAC could be used to drive the fans, but in our 229 * indicates that the DAC could be used to drive the fans, but in our
227 * example board (Arima HDAMA) it isn't connected to the fans at all. 230 * example board (Arima HDAMA) it isn't connected to the fans at all.
228 */ 231 */
229#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255)) 232#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500), 0, 255))
230#define DAC_FROM_REG(val) (((val)*2500)/255) 233#define DAC_FROM_REG(val) (((val)*2500)/255)
231 234
232/* Typically used with systems using a v9.1 VRM spec ? */
233#define ADM1026_INIT_VRM 91
234
235/* Chip sampling rates 235/* Chip sampling rates
236 * 236 *
237 * Some sensors are not updated more frequently than once per second 237 * Some sensors are not updated more frequently than once per second
@@ -243,8 +243,8 @@ static int adm1026_scaling[] = { /* .001 Volts */
243 * So, we keep the config data up to date in the cache 243 * So, we keep the config data up to date in the cache
244 * when it is written and only sample it once every 5 *minutes* 244 * when it is written and only sample it once every 5 *minutes*
245 */ 245 */
246#define ADM1026_DATA_INTERVAL (1 * HZ) 246#define ADM1026_DATA_INTERVAL (1 * HZ)
247#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ) 247#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
248 248
249/* We allow for multiple chips in a single system. 249/* We allow for multiple chips in a single system.
250 * 250 *
@@ -261,37 +261,36 @@ struct pwm_data {
261struct adm1026_data { 261struct adm1026_data {
262 struct i2c_client client; 262 struct i2c_client client;
263 struct device *hwmon_dev; 263 struct device *hwmon_dev;
264 enum chips type;
265 264
266 struct mutex update_lock; 265 struct mutex update_lock;
267 int valid; /* !=0 if following fields are valid */ 266 int valid; /* !=0 if following fields are valid */
268 unsigned long last_reading; /* In jiffies */ 267 unsigned long last_reading; /* In jiffies */
269 unsigned long last_config; /* In jiffies */ 268 unsigned long last_config; /* In jiffies */
270 269
271 u8 in[17]; /* Register value */ 270 u8 in[17]; /* Register value */
272 u8 in_max[17]; /* Register value */ 271 u8 in_max[17]; /* Register value */
273 u8 in_min[17]; /* Register value */ 272 u8 in_min[17]; /* Register value */
274 s8 temp[3]; /* Register value */ 273 s8 temp[3]; /* Register value */
275 s8 temp_min[3]; /* Register value */ 274 s8 temp_min[3]; /* Register value */
276 s8 temp_max[3]; /* Register value */ 275 s8 temp_max[3]; /* Register value */
277 s8 temp_tmin[3]; /* Register value */ 276 s8 temp_tmin[3]; /* Register value */
278 s8 temp_crit[3]; /* Register value */ 277 s8 temp_crit[3]; /* Register value */
279 s8 temp_offset[3]; /* Register value */ 278 s8 temp_offset[3]; /* Register value */
280 u8 fan[8]; /* Register value */ 279 u8 fan[8]; /* Register value */
281 u8 fan_min[8]; /* Register value */ 280 u8 fan_min[8]; /* Register value */
282 u8 fan_div[8]; /* Decoded value */ 281 u8 fan_div[8]; /* Decoded value */
283 struct pwm_data pwm1; /* Pwm control values */ 282 struct pwm_data pwm1; /* Pwm control values */
284 int vid; /* Decoded value */ 283 int vid; /* Decoded value */
285 u8 vrm; /* VRM version */ 284 u8 vrm; /* VRM version */
286 u8 analog_out; /* Register value (DAC) */ 285 u8 analog_out; /* Register value (DAC) */
287 long alarms; /* Register encoding, combined */ 286 long alarms; /* Register encoding, combined */
288 long alarm_mask; /* Register encoding, combined */ 287 long alarm_mask; /* Register encoding, combined */
289 long gpio; /* Register encoding, combined */ 288 long gpio; /* Register encoding, combined */
290 long gpio_mask; /* Register encoding, combined */ 289 long gpio_mask; /* Register encoding, combined */
291 u8 gpio_config[17]; /* Decoded value */ 290 u8 gpio_config[17]; /* Decoded value */
292 u8 config1; /* Register value */ 291 u8 config1; /* Register value */
293 u8 config2; /* Register value */ 292 u8 config2; /* Register value */
294 u8 config3; /* Register value */ 293 u8 config3; /* Register value */
295}; 294};
296 295
297static int adm1026_attach_adapter(struct i2c_adapter *adapter); 296static int adm1026_attach_adapter(struct i2c_adapter *adapter);
@@ -301,7 +300,7 @@ static int adm1026_detach_client(struct i2c_client *client);
301static int adm1026_read_value(struct i2c_client *client, u8 reg); 300static int adm1026_read_value(struct i2c_client *client, u8 reg);
302static int adm1026_write_value(struct i2c_client *client, u8 reg, int value); 301static int adm1026_write_value(struct i2c_client *client, u8 reg, int value);
303static void adm1026_print_gpio(struct i2c_client *client); 302static void adm1026_print_gpio(struct i2c_client *client);
304static void adm1026_fixup_gpio(struct i2c_client *client); 303static void adm1026_fixup_gpio(struct i2c_client *client);
305static struct adm1026_data *adm1026_update_device(struct device *dev); 304static struct adm1026_data *adm1026_update_device(struct device *dev);
306static void adm1026_init_client(struct i2c_client *client); 305static void adm1026_init_client(struct i2c_client *client);
307 306
@@ -311,7 +310,7 @@ static struct i2c_driver adm1026_driver = {
311 .name = "adm1026", 310 .name = "adm1026",
312 }, 311 },
313 .attach_adapter = adm1026_attach_adapter, 312 .attach_adapter = adm1026_attach_adapter,
314 .detach_client = adm1026_detach_client, 313 .detach_client = adm1026_detach_client,
315}; 314};
316 315
317static int adm1026_attach_adapter(struct i2c_adapter *adapter) 316static int adm1026_attach_adapter(struct i2c_adapter *adapter)
@@ -355,7 +354,7 @@ static void adm1026_init_client(struct i2c_client *client)
355 int value, i; 354 int value, i;
356 struct adm1026_data *data = i2c_get_clientdata(client); 355 struct adm1026_data *data = i2c_get_clientdata(client);
357 356
358 dev_dbg(&client->dev, "Initializing device\n"); 357 dev_dbg(&client->dev, "Initializing device\n");
359 /* Read chip config */ 358 /* Read chip config */
360 data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1); 359 data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
361 data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2); 360 data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
@@ -384,7 +383,6 @@ static void adm1026_init_client(struct i2c_client *client)
384 "and temp limits enabled.\n"); 383 "and temp limits enabled.\n");
385 } 384 }
386 385
387 value = data->config3;
388 if (data->config3 & CFG3_GPIO16_ENABLE) { 386 if (data->config3 & CFG3_GPIO16_ENABLE) {
389 dev_dbg(&client->dev, "GPIO16 enabled. THERM " 387 dev_dbg(&client->dev, "GPIO16 enabled. THERM "
390 "pin disabled.\n"); 388 "pin disabled.\n");
@@ -426,10 +424,10 @@ static void adm1026_init_client(struct i2c_client *client)
426 * configured, we don't want to mess with them. 424 * configured, we don't want to mess with them.
427 * If they weren't, the default is 100% PWM, no 425 * If they weren't, the default is 100% PWM, no
428 * control and will suffice until 'sensors -s' 426 * control and will suffice until 'sensors -s'
429 * can be run by the user. We DO set the default 427 * can be run by the user. We DO set the default
430 * value for pwm1.auto_pwm_min to its maximum 428 * value for pwm1.auto_pwm_min to its maximum
431 * so that enabling automatic pwm fan control 429 * so that enabling automatic pwm fan control
432 * without first setting a value for pwm1.auto_pwm_min 430 * without first setting a value for pwm1.auto_pwm_min
433 * will not result in potentially dangerous fan speed decrease. 431 * will not result in potentially dangerous fan speed decrease.
434 */ 432 */
435 data->pwm1.auto_pwm_min=255; 433 data->pwm1.auto_pwm_min=255;
@@ -453,7 +451,7 @@ static void adm1026_init_client(struct i2c_client *client)
453static void adm1026_print_gpio(struct i2c_client *client) 451static void adm1026_print_gpio(struct i2c_client *client)
454{ 452{
455 struct adm1026_data *data = i2c_get_clientdata(client); 453 struct adm1026_data *data = i2c_get_clientdata(client);
456 int i; 454 int i;
457 455
458 dev_dbg(&client->dev, "GPIO config is:"); 456 dev_dbg(&client->dev, "GPIO config is:");
459 for (i = 0;i <= 7;++i) { 457 for (i = 0;i <= 7;++i) {
@@ -477,7 +475,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
477 data->gpio_config[16] & 0x02 ? "" : "!", 475 data->gpio_config[16] & 0x02 ? "" : "!",
478 data->gpio_config[16] & 0x01 ? "OUT" : "IN"); 476 data->gpio_config[16] & 0x01 ? "OUT" : "IN");
479 } else { 477 } else {
480 /* GPIO16 is THERM */ 478 /* GPIO16 is THERM */
481 dev_dbg(&client->dev, "\tTHERM\n"); 479 dev_dbg(&client->dev, "\tTHERM\n");
482 } 480 }
483} 481}
@@ -485,8 +483,8 @@ static void adm1026_print_gpio(struct i2c_client *client)
485static void adm1026_fixup_gpio(struct i2c_client *client) 483static void adm1026_fixup_gpio(struct i2c_client *client)
486{ 484{
487 struct adm1026_data *data = i2c_get_clientdata(client); 485 struct adm1026_data *data = i2c_get_clientdata(client);
488 int i; 486 int i;
489 int value; 487 int value;
490 488
491 /* Make the changes requested. */ 489 /* Make the changes requested. */
492 /* We may need to unlock/stop monitoring or soft-reset the 490 /* We may need to unlock/stop monitoring or soft-reset the
@@ -516,14 +514,14 @@ static void adm1026_fixup_gpio(struct i2c_client *client)
516 } 514 }
517 } 515 }
518 516
519 /* Inverted */ 517 /* Inverted */
520 for (i = 0;i <= 16;++i) { 518 for (i = 0;i <= 16;++i) {
521 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) { 519 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
522 data->gpio_config[gpio_inverted[i]] &= ~ 0x02; 520 data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
523 } 521 }
524 } 522 }
525 523
526 /* Normal overrides inverted */ 524 /* Normal overrides inverted */
527 for (i = 0;i <= 16;++i) { 525 for (i = 0;i <= 16;++i) {
528 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) { 526 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
529 data->gpio_config[gpio_normal[i]] |= 0x02; 527 data->gpio_config[gpio_normal[i]] |= 0x02;
@@ -569,7 +567,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
569 if (!data->valid 567 if (!data->valid
570 || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) { 568 || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) {
571 /* Things that change quickly */ 569 /* Things that change quickly */
572 dev_dbg(&client->dev,"Reading sensor values\n"); 570 dev_dbg(&client->dev, "Reading sensor values\n");
573 for (i = 0;i <= 16;++i) { 571 for (i = 0;i <= 16;++i) {
574 data->in[i] = 572 data->in[i] =
575 adm1026_read_value(client, ADM1026_REG_IN[i]); 573 adm1026_read_value(client, ADM1026_REG_IN[i]);
@@ -582,18 +580,18 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
582 580
583 for (i = 0;i <= 2;++i) { 581 for (i = 0;i <= 2;++i) {
584 /* NOTE: temp[] is s8 and we assume 2's complement 582 /* NOTE: temp[] is s8 and we assume 2's complement
585 * "conversion" in the assignment */ 583 * "conversion" in the assignment */
586 data->temp[i] = 584 data->temp[i] =
587 adm1026_read_value(client, ADM1026_REG_TEMP[i]); 585 adm1026_read_value(client, ADM1026_REG_TEMP[i]);
588 } 586 }
589 587
590 data->pwm1.pwm = adm1026_read_value(client, 588 data->pwm1.pwm = adm1026_read_value(client,
591 ADM1026_REG_PWM); 589 ADM1026_REG_PWM);
592 data->analog_out = adm1026_read_value(client, 590 data->analog_out = adm1026_read_value(client,
593 ADM1026_REG_DAC); 591 ADM1026_REG_DAC);
594 /* GPIO16 is MSbit of alarms, move it to gpio */ 592 /* GPIO16 is MSbit of alarms, move it to gpio */
595 alarms = adm1026_read_value(client, ADM1026_REG_STATUS4); 593 alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
596 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */ 594 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
597 alarms &= 0x7f; 595 alarms &= 0x7f;
598 alarms <<= 8; 596 alarms <<= 8;
599 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3); 597 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
@@ -604,24 +602,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
604 data->alarms = alarms; 602 data->alarms = alarms;
605 603
606 /* Read the GPIO values */ 604 /* Read the GPIO values */
607 gpio |= adm1026_read_value(client, 605 gpio |= adm1026_read_value(client,
608 ADM1026_REG_GPIO_STATUS_8_15); 606 ADM1026_REG_GPIO_STATUS_8_15);
609 gpio <<= 8; 607 gpio <<= 8;
610 gpio |= adm1026_read_value(client, 608 gpio |= adm1026_read_value(client,
611 ADM1026_REG_GPIO_STATUS_0_7); 609 ADM1026_REG_GPIO_STATUS_0_7);
612 data->gpio = gpio; 610 data->gpio = gpio;
613 611
614 data->last_reading = jiffies; 612 data->last_reading = jiffies;
615 }; /* last_reading */ 613 }; /* last_reading */
616 614
617 if (!data->valid || 615 if (!data->valid ||
618 time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) { 616 time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
619 /* Things that don't change often */ 617 /* Things that don't change often */
620 dev_dbg(&client->dev, "Reading config values\n"); 618 dev_dbg(&client->dev, "Reading config values\n");
621 for (i = 0;i <= 16;++i) { 619 for (i = 0;i <= 16;++i) {
622 data->in_min[i] = adm1026_read_value(client, 620 data->in_min[i] = adm1026_read_value(client,
623 ADM1026_REG_IN_MIN[i]); 621 ADM1026_REG_IN_MIN[i]);
624 data->in_max[i] = adm1026_read_value(client, 622 data->in_max[i] = adm1026_read_value(client,
625 ADM1026_REG_IN_MAX[i]); 623 ADM1026_REG_IN_MAX[i]);
626 } 624 }
627 625
@@ -629,32 +627,32 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
629 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) 627 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
630 << 8); 628 << 8);
631 for (i = 0;i <= 7;++i) { 629 for (i = 0;i <= 7;++i) {
632 data->fan_min[i] = adm1026_read_value(client, 630 data->fan_min[i] = adm1026_read_value(client,
633 ADM1026_REG_FAN_MIN(i)); 631 ADM1026_REG_FAN_MIN(i));
634 data->fan_div[i] = DIV_FROM_REG(value & 0x03); 632 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
635 value >>= 2; 633 value >>= 2;
636 } 634 }
637 635
638 for (i = 0; i <= 2; ++i) { 636 for (i = 0; i <= 2; ++i) {
639 /* NOTE: temp_xxx[] are s8 and we assume 2's 637 /* NOTE: temp_xxx[] are s8 and we assume 2's
640 * complement "conversion" in the assignment 638 * complement "conversion" in the assignment
641 */ 639 */
642 data->temp_min[i] = adm1026_read_value(client, 640 data->temp_min[i] = adm1026_read_value(client,
643 ADM1026_REG_TEMP_MIN[i]); 641 ADM1026_REG_TEMP_MIN[i]);
644 data->temp_max[i] = adm1026_read_value(client, 642 data->temp_max[i] = adm1026_read_value(client,
645 ADM1026_REG_TEMP_MAX[i]); 643 ADM1026_REG_TEMP_MAX[i]);
646 data->temp_tmin[i] = adm1026_read_value(client, 644 data->temp_tmin[i] = adm1026_read_value(client,
647 ADM1026_REG_TEMP_TMIN[i]); 645 ADM1026_REG_TEMP_TMIN[i]);
648 data->temp_crit[i] = adm1026_read_value(client, 646 data->temp_crit[i] = adm1026_read_value(client,
649 ADM1026_REG_TEMP_THERM[i]); 647 ADM1026_REG_TEMP_THERM[i]);
650 data->temp_offset[i] = adm1026_read_value(client, 648 data->temp_offset[i] = adm1026_read_value(client,
651 ADM1026_REG_TEMP_OFFSET[i]); 649 ADM1026_REG_TEMP_OFFSET[i]);
652 } 650 }
653 651
654 /* Read the STATUS/alarm masks */ 652 /* Read the STATUS/alarm masks */
655 alarms = adm1026_read_value(client, ADM1026_REG_MASK4); 653 alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
656 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */ 654 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
657 alarms = (alarms & 0x7f) << 8; 655 alarms = (alarms & 0x7f) << 8;
658 alarms |= adm1026_read_value(client, ADM1026_REG_MASK3); 656 alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
659 alarms <<= 8; 657 alarms <<= 8;
660 alarms |= adm1026_read_value(client, ADM1026_REG_MASK2); 658 alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
@@ -663,24 +661,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
663 data->alarm_mask = alarms; 661 data->alarm_mask = alarms;
664 662
665 /* Read the GPIO values */ 663 /* Read the GPIO values */
666 gpio |= adm1026_read_value(client, 664 gpio |= adm1026_read_value(client,
667 ADM1026_REG_GPIO_MASK_8_15); 665 ADM1026_REG_GPIO_MASK_8_15);
668 gpio <<= 8; 666 gpio <<= 8;
669 gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7); 667 gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
670 data->gpio_mask = gpio; 668 data->gpio_mask = gpio;
671 669
672 /* Read various values from CONFIG1 */ 670 /* Read various values from CONFIG1 */
673 data->config1 = adm1026_read_value(client, 671 data->config1 = adm1026_read_value(client,
674 ADM1026_REG_CONFIG1); 672 ADM1026_REG_CONFIG1);
675 if (data->config1 & CFG1_PWM_AFC) { 673 if (data->config1 & CFG1_PWM_AFC) {
676 data->pwm1.enable = 2; 674 data->pwm1.enable = 2;
677 data->pwm1.auto_pwm_min = 675 data->pwm1.auto_pwm_min =
678 PWM_MIN_FROM_REG(data->pwm1.pwm); 676 PWM_MIN_FROM_REG(data->pwm1.pwm);
679 } 677 }
680 /* Read the GPIO config */ 678 /* Read the GPIO config */
681 data->config2 = adm1026_read_value(client, 679 data->config2 = adm1026_read_value(client,
682 ADM1026_REG_CONFIG2); 680 ADM1026_REG_CONFIG2);
683 data->config3 = adm1026_read_value(client, 681 data->config3 = adm1026_read_value(client,
684 ADM1026_REG_CONFIG3); 682 ADM1026_REG_CONFIG3);
685 data->gpio_config[16] = (data->config3 >> 6) & 0x03; 683 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
686 684
@@ -695,7 +693,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
695 } 693 }
696 694
697 data->last_config = jiffies; 695 data->last_config = jiffies;
698 }; /* last_config */ 696 }; /* last_config */
699 697
700 dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n"); 698 dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
701 data->vid = (data->gpio >> 11) & 0x1f; 699 data->vid = (data->gpio >> 11) & 0x1f;
@@ -710,15 +708,15 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
710 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 708 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
711 int nr = sensor_attr->index; 709 int nr = sensor_attr->index;
712 struct adm1026_data *data = adm1026_update_device(dev); 710 struct adm1026_data *data = adm1026_update_device(dev);
713 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr])); 711 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in[nr]));
714} 712}
715static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, 713static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
716 char *buf) 714 char *buf)
717{ 715{
718 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 716 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
719 int nr = sensor_attr->index; 717 int nr = sensor_attr->index;
720 struct adm1026_data *data = adm1026_update_device(dev); 718 struct adm1026_data *data = adm1026_update_device(dev);
721 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr])); 719 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
722} 720}
723static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, 721static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
724 const char *buf, size_t count) 722 const char *buf, size_t count)
@@ -733,7 +731,7 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
733 data->in_min[nr] = INS_TO_REG(nr, val); 731 data->in_min[nr] = INS_TO_REG(nr, val);
734 adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]); 732 adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
735 mutex_unlock(&data->update_lock); 733 mutex_unlock(&data->update_lock);
736 return count; 734 return count;
737} 735}
738static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, 736static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
739 char *buf) 737 char *buf)
@@ -741,7 +739,7 @@ static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
741 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 739 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
742 int nr = sensor_attr->index; 740 int nr = sensor_attr->index;
743 struct adm1026_data *data = adm1026_update_device(dev); 741 struct adm1026_data *data = adm1026_update_device(dev);
744 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr])); 742 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
745} 743}
746static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, 744static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
747 const char *buf, size_t count) 745 const char *buf, size_t count)
@@ -788,13 +786,13 @@ in_reg(15);
788static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf) 786static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf)
789{ 787{
790 struct adm1026_data *data = adm1026_update_device(dev); 788 struct adm1026_data *data = adm1026_update_device(dev);
791 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) - 789 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) -
792 NEG12_OFFSET); 790 NEG12_OFFSET);
793} 791}
794static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf) 792static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf)
795{ 793{
796 struct adm1026_data *data = adm1026_update_device(dev); 794 struct adm1026_data *data = adm1026_update_device(dev);
797 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16]) 795 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16])
798 - NEG12_OFFSET); 796 - NEG12_OFFSET);
799} 797}
800static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 798static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
@@ -807,12 +805,12 @@ static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, c
807 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET); 805 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
808 adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]); 806 adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
809 mutex_unlock(&data->update_lock); 807 mutex_unlock(&data->update_lock);
810 return count; 808 return count;
811} 809}
812static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf) 810static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf)
813{ 811{
814 struct adm1026_data *data = adm1026_update_device(dev); 812 struct adm1026_data *data = adm1026_update_device(dev);
815 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16]) 813 return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16])
816 - NEG12_OFFSET); 814 - NEG12_OFFSET);
817} 815}
818static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 816static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
@@ -843,7 +841,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
843 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 841 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
844 int nr = sensor_attr->index; 842 int nr = sensor_attr->index;
845 struct adm1026_data *data = adm1026_update_device(dev); 843 struct adm1026_data *data = adm1026_update_device(dev);
846 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], 844 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
847 data->fan_div[nr])); 845 data->fan_div[nr]));
848} 846}
849static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, 847static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
@@ -852,7 +850,7 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
852 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 850 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
853 int nr = sensor_attr->index; 851 int nr = sensor_attr->index;
854 struct adm1026_data *data = adm1026_update_device(dev); 852 struct adm1026_data *data = adm1026_update_device(dev);
855 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], 853 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
856 data->fan_div[nr])); 854 data->fan_div[nr]));
857} 855}
858static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, 856static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
@@ -872,10 +870,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
872 return count; 870 return count;
873} 871}
874 872
875#define fan_offset(offset) \ 873#define fan_offset(offset) \
876static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL, \ 874static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL, \
877 offset - 1); \ 875 offset - 1); \
878static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 876static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
879 show_fan_min, set_fan_min, offset - 1); 877 show_fan_min, set_fan_min, offset - 1);
880 878
881fan_offset(1); 879fan_offset(1);
@@ -892,8 +890,8 @@ static void fixup_fan_min(struct device *dev, int fan, int old_div)
892{ 890{
893 struct i2c_client *client = to_i2c_client(dev); 891 struct i2c_client *client = to_i2c_client(dev);
894 struct adm1026_data *data = i2c_get_clientdata(client); 892 struct adm1026_data *data = i2c_get_clientdata(client);
895 int new_min; 893 int new_min;
896 int new_div = data->fan_div[fan]; 894 int new_div = data->fan_div[fan];
897 895
898 /* 0 and 0xff are special. Don't adjust them */ 896 /* 0 and 0xff are special. Don't adjust them */
899 if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) { 897 if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
@@ -913,7 +911,7 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
913 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 911 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
914 int nr = sensor_attr->index; 912 int nr = sensor_attr->index;
915 struct adm1026_data *data = adm1026_update_device(dev); 913 struct adm1026_data *data = adm1026_update_device(dev);
916 return sprintf(buf,"%d\n", data->fan_div[nr]); 914 return sprintf(buf, "%d\n", data->fan_div[nr]);
917} 915}
918static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 916static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
919 const char *buf, size_t count) 917 const char *buf, size_t count)
@@ -922,10 +920,10 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
922 int nr = sensor_attr->index; 920 int nr = sensor_attr->index;
923 struct i2c_client *client = to_i2c_client(dev); 921 struct i2c_client *client = to_i2c_client(dev);
924 struct adm1026_data *data = i2c_get_clientdata(client); 922 struct adm1026_data *data = i2c_get_clientdata(client);
925 int val,orig_div,new_div,shift; 923 int val, orig_div, new_div, shift;
926 924
927 val = simple_strtol(buf, NULL, 10); 925 val = simple_strtol(buf, NULL, 10);
928 new_div = DIV_TO_REG(val); 926 new_div = DIV_TO_REG(val);
929 if (new_div == 0) { 927 if (new_div == 0) {
930 return -EINVAL; 928 return -EINVAL;
931 } 929 }
@@ -946,14 +944,14 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
946 } 944 }
947 945
948 if (data->fan_div[nr] != orig_div) { 946 if (data->fan_div[nr] != orig_div) {
949 fixup_fan_min(dev,nr,orig_div); 947 fixup_fan_min(dev, nr, orig_div);
950 } 948 }
951 mutex_unlock(&data->update_lock); 949 mutex_unlock(&data->update_lock);
952 return count; 950 return count;
953} 951}
954 952
955#define fan_offset_div(offset) \ 953#define fan_offset_div(offset) \
956static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 954static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
957 show_fan_div, set_fan_div, offset - 1); 955 show_fan_div, set_fan_div, offset - 1);
958 956
959fan_offset_div(1); 957fan_offset_div(1);
@@ -972,7 +970,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
972 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 970 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
973 int nr = sensor_attr->index; 971 int nr = sensor_attr->index;
974 struct adm1026_data *data = adm1026_update_device(dev); 972 struct adm1026_data *data = adm1026_update_device(dev);
975 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr])); 973 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
976} 974}
977static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, 975static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
978 char *buf) 976 char *buf)
@@ -980,7 +978,7 @@ static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
980 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 978 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
981 int nr = sensor_attr->index; 979 int nr = sensor_attr->index;
982 struct adm1026_data *data = adm1026_update_device(dev); 980 struct adm1026_data *data = adm1026_update_device(dev);
983 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr])); 981 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
984} 982}
985static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, 983static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
986 const char *buf, size_t count) 984 const char *buf, size_t count)
@@ -1004,7 +1002,7 @@ static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
1004 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1002 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1005 int nr = sensor_attr->index; 1003 int nr = sensor_attr->index;
1006 struct adm1026_data *data = adm1026_update_device(dev); 1004 struct adm1026_data *data = adm1026_update_device(dev);
1007 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr])); 1005 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
1008} 1006}
1009static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, 1007static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
1010 const char *buf, size_t count) 1008 const char *buf, size_t count)
@@ -1024,7 +1022,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
1024} 1022}
1025 1023
1026#define temp_reg(offset) \ 1024#define temp_reg(offset) \
1027static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \ 1025static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \
1028 NULL, offset - 1); \ 1026 NULL, offset - 1); \
1029static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ 1027static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
1030 show_temp_min, set_temp_min, offset - 1); \ 1028 show_temp_min, set_temp_min, offset - 1); \
@@ -1042,7 +1040,7 @@ static ssize_t show_temp_offset(struct device *dev,
1042 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1040 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1043 int nr = sensor_attr->index; 1041 int nr = sensor_attr->index;
1044 struct adm1026_data *data = adm1026_update_device(dev); 1042 struct adm1026_data *data = adm1026_update_device(dev);
1045 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr])); 1043 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
1046} 1044}
1047static ssize_t set_temp_offset(struct device *dev, 1045static ssize_t set_temp_offset(struct device *dev,
1048 struct device_attribute *attr, const char *buf, 1046 struct device_attribute *attr, const char *buf,
@@ -1076,7 +1074,7 @@ static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev,
1076 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1074 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1077 int nr = sensor_attr->index; 1075 int nr = sensor_attr->index;
1078 struct adm1026_data *data = adm1026_update_device(dev); 1076 struct adm1026_data *data = adm1026_update_device(dev);
1079 return sprintf(buf,"%d\n", TEMP_FROM_REG( 1077 return sprintf(buf, "%d\n", TEMP_FROM_REG(
1080 ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr])); 1078 ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
1081} 1079}
1082static ssize_t show_temp_auto_point2_temp(struct device *dev, 1080static ssize_t show_temp_auto_point2_temp(struct device *dev,
@@ -1085,7 +1083,7 @@ static ssize_t show_temp_auto_point2_temp(struct device *dev,
1085 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1083 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1086 int nr = sensor_attr->index; 1084 int nr = sensor_attr->index;
1087 struct adm1026_data *data = adm1026_update_device(dev); 1085 struct adm1026_data *data = adm1026_update_device(dev);
1088 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] + 1086 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
1089 ADM1026_FAN_CONTROL_TEMP_RANGE)); 1087 ADM1026_FAN_CONTROL_TEMP_RANGE));
1090} 1088}
1091static ssize_t show_temp_auto_point1_temp(struct device *dev, 1089static ssize_t show_temp_auto_point1_temp(struct device *dev,
@@ -1094,7 +1092,7 @@ static ssize_t show_temp_auto_point1_temp(struct device *dev,
1094 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1092 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1095 int nr = sensor_attr->index; 1093 int nr = sensor_attr->index;
1096 struct adm1026_data *data = adm1026_update_device(dev); 1094 struct adm1026_data *data = adm1026_update_device(dev);
1097 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr])); 1095 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
1098} 1096}
1099static ssize_t set_temp_auto_point1_temp(struct device *dev, 1097static ssize_t set_temp_auto_point1_temp(struct device *dev,
1100 struct device_attribute *attr, const char *buf, size_t count) 1098 struct device_attribute *attr, const char *buf, size_t count)
@@ -1113,13 +1111,13 @@ static ssize_t set_temp_auto_point1_temp(struct device *dev,
1113 return count; 1111 return count;
1114} 1112}
1115 1113
1116#define temp_auto_point(offset) \ 1114#define temp_auto_point(offset) \
1117static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \ 1115static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp, \
1118 show_temp_auto_point1_temp, set_temp_auto_point1_temp, \ 1116 S_IRUGO | S_IWUSR, show_temp_auto_point1_temp, \
1119 offset - 1); \ 1117 set_temp_auto_point1_temp, offset - 1); \
1120static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \ 1118static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO,\
1121 show_temp_auto_point1_temp_hyst, NULL, offset - 1); \ 1119 show_temp_auto_point1_temp_hyst, NULL, offset - 1); \
1122static SENSOR_DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \ 1120static SENSOR_DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
1123 show_temp_auto_point2_temp, NULL, offset - 1); 1121 show_temp_auto_point2_temp, NULL, offset - 1);
1124 1122
1125temp_auto_point(1); 1123temp_auto_point(1);
@@ -1130,7 +1128,7 @@ static ssize_t show_temp_crit_enable(struct device *dev,
1130 struct device_attribute *attr, char *buf) 1128 struct device_attribute *attr, char *buf)
1131{ 1129{
1132 struct adm1026_data *data = adm1026_update_device(dev); 1130 struct adm1026_data *data = adm1026_update_device(dev);
1133 return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4); 1131 return sprintf(buf, "%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
1134} 1132}
1135static ssize_t set_temp_crit_enable(struct device *dev, 1133static ssize_t set_temp_crit_enable(struct device *dev,
1136 struct device_attribute *attr, const char *buf, size_t count) 1134 struct device_attribute *attr, const char *buf, size_t count)
@@ -1142,7 +1140,7 @@ static ssize_t set_temp_crit_enable(struct device *dev,
1142 if ((val == 1) || (val==0)) { 1140 if ((val == 1) || (val==0)) {
1143 mutex_lock(&data->update_lock); 1141 mutex_lock(&data->update_lock);
1144 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4); 1142 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
1145 adm1026_write_value(client, ADM1026_REG_CONFIG1, 1143 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1146 data->config1); 1144 data->config1);
1147 mutex_unlock(&data->update_lock); 1145 mutex_unlock(&data->update_lock);
1148 } 1146 }
@@ -1163,7 +1161,7 @@ static ssize_t show_temp_crit(struct device *dev,
1163 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1161 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1164 int nr = sensor_attr->index; 1162 int nr = sensor_attr->index;
1165 struct adm1026_data *data = adm1026_update_device(dev); 1163 struct adm1026_data *data = adm1026_update_device(dev);
1166 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr])); 1164 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
1167} 1165}
1168static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, 1166static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
1169 const char *buf, size_t count) 1167 const char *buf, size_t count)
@@ -1193,7 +1191,7 @@ temp_crit_reg(3);
1193static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf) 1191static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf)
1194{ 1192{
1195 struct adm1026_data *data = adm1026_update_device(dev); 1193 struct adm1026_data *data = adm1026_update_device(dev);
1196 return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out)); 1194 return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out));
1197} 1195}
1198static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf, 1196static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf,
1199 size_t count) 1197 size_t count)
@@ -1209,26 +1207,25 @@ static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *a
1209 return count; 1207 return count;
1210} 1208}
1211 1209
1212static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg, 1210static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
1213 set_analog_out_reg); 1211 set_analog_out_reg);
1214 1212
1215static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 1213static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
1216{ 1214{
1217 struct adm1026_data *data = adm1026_update_device(dev); 1215 struct adm1026_data *data = adm1026_update_device(dev);
1218 return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm)); 1216 return sprintf(buf, "%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
1219} 1217}
1220static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 1218static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1221 1219
1222static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 1220static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
1223{ 1221{
1224 struct adm1026_data *data = dev_get_drvdata(dev); 1222 struct adm1026_data *data = dev_get_drvdata(dev);
1225 return sprintf(buf,"%d\n", data->vrm); 1223 return sprintf(buf, "%d\n", data->vrm);
1226} 1224}
1227static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, 1225static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
1228 size_t count) 1226 size_t count)
1229{ 1227{
1230 struct i2c_client *client = to_i2c_client(dev); 1228 struct adm1026_data *data = dev_get_drvdata(dev);
1231 struct adm1026_data *data = i2c_get_clientdata(client);
1232 1229
1233 data->vrm = simple_strtol(buf, NULL, 10); 1230 data->vrm = simple_strtol(buf, NULL, 10);
1234 return count; 1231 return count;
@@ -1239,15 +1236,52 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1239static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 1236static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
1240{ 1237{
1241 struct adm1026_data *data = adm1026_update_device(dev); 1238 struct adm1026_data *data = adm1026_update_device(dev);
1242 return sprintf(buf, "%ld\n", (long) (data->alarms)); 1239 return sprintf(buf, "%ld\n", data->alarms);
1243} 1240}
1244 1241
1245static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 1242static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
1246 1243
1244static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1245 char *buf)
1246{
1247 struct adm1026_data *data = adm1026_update_device(dev);
1248 int bitnr = to_sensor_dev_attr(attr)->index;
1249 return sprintf(buf, "%ld\n", (data->alarms >> bitnr) & 1);
1250}
1251
1252static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0);
1253static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 1);
1254static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 1);
1255static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL, 2);
1256static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL, 3);
1257static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL, 4);
1258static SENSOR_DEVICE_ATTR(in14_alarm, S_IRUGO, show_alarm, NULL, 5);
1259static SENSOR_DEVICE_ATTR(in15_alarm, S_IRUGO, show_alarm, NULL, 6);
1260static SENSOR_DEVICE_ATTR(in16_alarm, S_IRUGO, show_alarm, NULL, 7);
1261static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1262static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1263static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1264static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1265static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1266static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1267static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1268static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1269static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16);
1270static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17);
1271static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18);
1272static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 19);
1273static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 20);
1274static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 21);
1275static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL, 22);
1276static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_alarm, NULL, 23);
1277static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 24);
1278static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25);
1279static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26);
1280
1247static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf) 1281static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf)
1248{ 1282{
1249 struct adm1026_data *data = adm1026_update_device(dev); 1283 struct adm1026_data *data = adm1026_update_device(dev);
1250 return sprintf(buf,"%ld\n", data->alarm_mask); 1284 return sprintf(buf, "%ld\n", data->alarm_mask);
1251} 1285}
1252static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf, 1286static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf,
1253 size_t count) 1287 size_t count)
@@ -1283,7 +1317,7 @@ static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
1283static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf) 1317static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf)
1284{ 1318{
1285 struct adm1026_data *data = adm1026_update_device(dev); 1319 struct adm1026_data *data = adm1026_update_device(dev);
1286 return sprintf(buf,"%ld\n", data->gpio); 1320 return sprintf(buf, "%ld\n", data->gpio);
1287} 1321}
1288static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf, 1322static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf,
1289 size_t count) 1323 size_t count)
@@ -1291,16 +1325,16 @@ static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const
1291 struct i2c_client *client = to_i2c_client(dev); 1325 struct i2c_client *client = to_i2c_client(dev);
1292 struct adm1026_data *data = i2c_get_clientdata(client); 1326 struct adm1026_data *data = i2c_get_clientdata(client);
1293 int val = simple_strtol(buf, NULL, 10); 1327 int val = simple_strtol(buf, NULL, 10);
1294 long gpio; 1328 long gpio;
1295 1329
1296 mutex_lock(&data->update_lock); 1330 mutex_lock(&data->update_lock);
1297 data->gpio = val & 0x1ffff; 1331 data->gpio = val & 0x1ffff;
1298 gpio = data->gpio; 1332 gpio = data->gpio;
1299 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff); 1333 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7, gpio & 0xff);
1300 gpio >>= 8; 1334 gpio >>= 8;
1301 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff); 1335 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15, gpio & 0xff);
1302 gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f); 1336 gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
1303 adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff); 1337 adm1026_write_value(client, ADM1026_REG_STATUS4, gpio & 0xff);
1304 mutex_unlock(&data->update_lock); 1338 mutex_unlock(&data->update_lock);
1305 return count; 1339 return count;
1306} 1340}
@@ -1311,7 +1345,7 @@ static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
1311static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf) 1345static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf)
1312{ 1346{
1313 struct adm1026_data *data = adm1026_update_device(dev); 1347 struct adm1026_data *data = adm1026_update_device(dev);
1314 return sprintf(buf,"%ld\n", data->gpio_mask); 1348 return sprintf(buf, "%ld\n", data->gpio_mask);
1315} 1349}
1316static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf, 1350static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf,
1317 size_t count) 1351 size_t count)
@@ -1319,16 +1353,16 @@ static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
1319 struct i2c_client *client = to_i2c_client(dev); 1353 struct i2c_client *client = to_i2c_client(dev);
1320 struct adm1026_data *data = i2c_get_clientdata(client); 1354 struct adm1026_data *data = i2c_get_clientdata(client);
1321 int val = simple_strtol(buf, NULL, 10); 1355 int val = simple_strtol(buf, NULL, 10);
1322 long mask; 1356 long mask;
1323 1357
1324 mutex_lock(&data->update_lock); 1358 mutex_lock(&data->update_lock);
1325 data->gpio_mask = val & 0x1ffff; 1359 data->gpio_mask = val & 0x1ffff;
1326 mask = data->gpio_mask; 1360 mask = data->gpio_mask;
1327 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff); 1361 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7, mask & 0xff);
1328 mask >>= 8; 1362 mask >>= 8;
1329 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff); 1363 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15, mask & 0xff);
1330 mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f); 1364 mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
1331 adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff); 1365 adm1026_write_value(client, ADM1026_REG_MASK1, mask & 0xff);
1332 mutex_unlock(&data->update_lock); 1366 mutex_unlock(&data->update_lock);
1333 return count; 1367 return count;
1334} 1368}
@@ -1338,7 +1372,7 @@ static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
1338static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, char *buf) 1372static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, char *buf)
1339{ 1373{
1340 struct adm1026_data *data = adm1026_update_device(dev); 1374 struct adm1026_data *data = adm1026_update_device(dev);
1341 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm)); 1375 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm));
1342} 1376}
1343static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, const char *buf, 1377static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
1344 size_t count) 1378 size_t count)
@@ -1359,7 +1393,7 @@ static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, co
1359static ssize_t show_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf) 1393static ssize_t show_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf)
1360{ 1394{
1361 struct adm1026_data *data = adm1026_update_device(dev); 1395 struct adm1026_data *data = adm1026_update_device(dev);
1362 return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min); 1396 return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min);
1363} 1397}
1364static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf, 1398static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf,
1365 size_t count) 1399 size_t count)
@@ -1369,10 +1403,10 @@ static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *att
1369 int val = simple_strtol(buf, NULL, 10); 1403 int val = simple_strtol(buf, NULL, 10);
1370 1404
1371 mutex_lock(&data->update_lock); 1405 mutex_lock(&data->update_lock);
1372 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255); 1406 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255);
1373 if (data->pwm1.enable == 2) { /* apply immediately */ 1407 if (data->pwm1.enable == 2) { /* apply immediately */
1374 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | 1408 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1375 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); 1409 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1376 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm); 1410 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1377 } 1411 }
1378 mutex_unlock(&data->update_lock); 1412 mutex_unlock(&data->update_lock);
@@ -1380,12 +1414,12 @@ static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *att
1380} 1414}
1381static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf) 1415static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf)
1382{ 1416{
1383 return sprintf(buf,"%d\n", ADM1026_PWM_MAX); 1417 return sprintf(buf, "%d\n", ADM1026_PWM_MAX);
1384} 1418}
1385static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf) 1419static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
1386{ 1420{
1387 struct adm1026_data *data = adm1026_update_device(dev); 1421 struct adm1026_data *data = adm1026_update_device(dev);
1388 return sprintf(buf,"%d\n", data->pwm1.enable); 1422 return sprintf(buf, "%d\n", data->pwm1.enable);
1389} 1423}
1390static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf, 1424static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf,
1391 size_t count) 1425 size_t count)
@@ -1393,7 +1427,7 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1393 struct i2c_client *client = to_i2c_client(dev); 1427 struct i2c_client *client = to_i2c_client(dev);
1394 struct adm1026_data *data = i2c_get_clientdata(client); 1428 struct adm1026_data *data = i2c_get_clientdata(client);
1395 int val = simple_strtol(buf, NULL, 10); 1429 int val = simple_strtol(buf, NULL, 10);
1396 int old_enable; 1430 int old_enable;
1397 1431
1398 if ((val >= 0) && (val < 3)) { 1432 if ((val >= 0) && (val < 3)) {
1399 mutex_lock(&data->update_lock); 1433 mutex_lock(&data->update_lock);
@@ -1403,15 +1437,15 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1403 | ((val == 2) ? CFG1_PWM_AFC : 0); 1437 | ((val == 2) ? CFG1_PWM_AFC : 0);
1404 adm1026_write_value(client, ADM1026_REG_CONFIG1, 1438 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1405 data->config1); 1439 data->config1);
1406 if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */ 1440 if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
1407 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | 1441 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1408 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); 1442 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1409 adm1026_write_value(client, ADM1026_REG_PWM, 1443 adm1026_write_value(client, ADM1026_REG_PWM,
1410 data->pwm1.pwm); 1444 data->pwm1.pwm);
1411 } else if (!((old_enable == 1) && (val == 1))) { 1445 } else if (!((old_enable == 1) && (val == 1))) {
1412 /* set pwm to safe value */ 1446 /* set pwm to safe value */
1413 data->pwm1.pwm = 255; 1447 data->pwm1.pwm = 255;
1414 adm1026_write_value(client, ADM1026_REG_PWM, 1448 adm1026_write_value(client, ADM1026_REG_PWM,
1415 data->pwm1.pwm); 1449 data->pwm1.pwm);
1416 } 1450 }
1417 mutex_unlock(&data->update_lock); 1451 mutex_unlock(&data->update_lock);
@@ -1420,20 +1454,20 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1420} 1454}
1421 1455
1422/* enable PWM fan control */ 1456/* enable PWM fan control */
1423static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg); 1457static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1424static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg); 1458static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1425static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg); 1459static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1426static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 1460static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1427 set_pwm_enable); 1461 set_pwm_enable);
1428static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 1462static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1429 set_pwm_enable); 1463 set_pwm_enable);
1430static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 1464static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1431 set_pwm_enable); 1465 set_pwm_enable);
1432static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR, 1466static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1433 show_auto_pwm_min, set_auto_pwm_min); 1467 show_auto_pwm_min, set_auto_pwm_min);
1434static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR, 1468static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1435 show_auto_pwm_min, set_auto_pwm_min); 1469 show_auto_pwm_min, set_auto_pwm_min);
1436static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR, 1470static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1437 show_auto_pwm_min, set_auto_pwm_min); 1471 show_auto_pwm_min, set_auto_pwm_min);
1438 1472
1439static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL); 1473static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
@@ -1444,105 +1478,115 @@ static struct attribute *adm1026_attributes[] = {
1444 &sensor_dev_attr_in0_input.dev_attr.attr, 1478 &sensor_dev_attr_in0_input.dev_attr.attr,
1445 &sensor_dev_attr_in0_max.dev_attr.attr, 1479 &sensor_dev_attr_in0_max.dev_attr.attr,
1446 &sensor_dev_attr_in0_min.dev_attr.attr, 1480 &sensor_dev_attr_in0_min.dev_attr.attr,
1481 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1447 &sensor_dev_attr_in1_input.dev_attr.attr, 1482 &sensor_dev_attr_in1_input.dev_attr.attr,
1448 &sensor_dev_attr_in1_max.dev_attr.attr, 1483 &sensor_dev_attr_in1_max.dev_attr.attr,
1449 &sensor_dev_attr_in1_min.dev_attr.attr, 1484 &sensor_dev_attr_in1_min.dev_attr.attr,
1485 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1450 &sensor_dev_attr_in2_input.dev_attr.attr, 1486 &sensor_dev_attr_in2_input.dev_attr.attr,
1451 &sensor_dev_attr_in2_max.dev_attr.attr, 1487 &sensor_dev_attr_in2_max.dev_attr.attr,
1452 &sensor_dev_attr_in2_min.dev_attr.attr, 1488 &sensor_dev_attr_in2_min.dev_attr.attr,
1489 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1453 &sensor_dev_attr_in3_input.dev_attr.attr, 1490 &sensor_dev_attr_in3_input.dev_attr.attr,
1454 &sensor_dev_attr_in3_max.dev_attr.attr, 1491 &sensor_dev_attr_in3_max.dev_attr.attr,
1455 &sensor_dev_attr_in3_min.dev_attr.attr, 1492 &sensor_dev_attr_in3_min.dev_attr.attr,
1493 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1456 &sensor_dev_attr_in4_input.dev_attr.attr, 1494 &sensor_dev_attr_in4_input.dev_attr.attr,
1457 &sensor_dev_attr_in4_max.dev_attr.attr, 1495 &sensor_dev_attr_in4_max.dev_attr.attr,
1458 &sensor_dev_attr_in4_min.dev_attr.attr, 1496 &sensor_dev_attr_in4_min.dev_attr.attr,
1497 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1459 &sensor_dev_attr_in5_input.dev_attr.attr, 1498 &sensor_dev_attr_in5_input.dev_attr.attr,
1460 &sensor_dev_attr_in5_max.dev_attr.attr, 1499 &sensor_dev_attr_in5_max.dev_attr.attr,
1461 &sensor_dev_attr_in5_min.dev_attr.attr, 1500 &sensor_dev_attr_in5_min.dev_attr.attr,
1501 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1462 &sensor_dev_attr_in6_input.dev_attr.attr, 1502 &sensor_dev_attr_in6_input.dev_attr.attr,
1463 &sensor_dev_attr_in6_max.dev_attr.attr, 1503 &sensor_dev_attr_in6_max.dev_attr.attr,
1464 &sensor_dev_attr_in6_min.dev_attr.attr, 1504 &sensor_dev_attr_in6_min.dev_attr.attr,
1505 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1465 &sensor_dev_attr_in7_input.dev_attr.attr, 1506 &sensor_dev_attr_in7_input.dev_attr.attr,
1466 &sensor_dev_attr_in7_max.dev_attr.attr, 1507 &sensor_dev_attr_in7_max.dev_attr.attr,
1467 &sensor_dev_attr_in7_min.dev_attr.attr, 1508 &sensor_dev_attr_in7_min.dev_attr.attr,
1468 &sensor_dev_attr_in8_input.dev_attr.attr, 1509 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1469 &sensor_dev_attr_in8_max.dev_attr.attr,
1470 &sensor_dev_attr_in8_min.dev_attr.attr,
1471 &sensor_dev_attr_in9_input.dev_attr.attr,
1472 &sensor_dev_attr_in9_max.dev_attr.attr,
1473 &sensor_dev_attr_in9_min.dev_attr.attr,
1474 &sensor_dev_attr_in10_input.dev_attr.attr, 1510 &sensor_dev_attr_in10_input.dev_attr.attr,
1475 &sensor_dev_attr_in10_max.dev_attr.attr, 1511 &sensor_dev_attr_in10_max.dev_attr.attr,
1476 &sensor_dev_attr_in10_min.dev_attr.attr, 1512 &sensor_dev_attr_in10_min.dev_attr.attr,
1513 &sensor_dev_attr_in10_alarm.dev_attr.attr,
1477 &sensor_dev_attr_in11_input.dev_attr.attr, 1514 &sensor_dev_attr_in11_input.dev_attr.attr,
1478 &sensor_dev_attr_in11_max.dev_attr.attr, 1515 &sensor_dev_attr_in11_max.dev_attr.attr,
1479 &sensor_dev_attr_in11_min.dev_attr.attr, 1516 &sensor_dev_attr_in11_min.dev_attr.attr,
1517 &sensor_dev_attr_in11_alarm.dev_attr.attr,
1480 &sensor_dev_attr_in12_input.dev_attr.attr, 1518 &sensor_dev_attr_in12_input.dev_attr.attr,
1481 &sensor_dev_attr_in12_max.dev_attr.attr, 1519 &sensor_dev_attr_in12_max.dev_attr.attr,
1482 &sensor_dev_attr_in12_min.dev_attr.attr, 1520 &sensor_dev_attr_in12_min.dev_attr.attr,
1521 &sensor_dev_attr_in12_alarm.dev_attr.attr,
1483 &sensor_dev_attr_in13_input.dev_attr.attr, 1522 &sensor_dev_attr_in13_input.dev_attr.attr,
1484 &sensor_dev_attr_in13_max.dev_attr.attr, 1523 &sensor_dev_attr_in13_max.dev_attr.attr,
1485 &sensor_dev_attr_in13_min.dev_attr.attr, 1524 &sensor_dev_attr_in13_min.dev_attr.attr,
1525 &sensor_dev_attr_in13_alarm.dev_attr.attr,
1486 &sensor_dev_attr_in14_input.dev_attr.attr, 1526 &sensor_dev_attr_in14_input.dev_attr.attr,
1487 &sensor_dev_attr_in14_max.dev_attr.attr, 1527 &sensor_dev_attr_in14_max.dev_attr.attr,
1488 &sensor_dev_attr_in14_min.dev_attr.attr, 1528 &sensor_dev_attr_in14_min.dev_attr.attr,
1529 &sensor_dev_attr_in14_alarm.dev_attr.attr,
1489 &sensor_dev_attr_in15_input.dev_attr.attr, 1530 &sensor_dev_attr_in15_input.dev_attr.attr,
1490 &sensor_dev_attr_in15_max.dev_attr.attr, 1531 &sensor_dev_attr_in15_max.dev_attr.attr,
1491 &sensor_dev_attr_in15_min.dev_attr.attr, 1532 &sensor_dev_attr_in15_min.dev_attr.attr,
1533 &sensor_dev_attr_in15_alarm.dev_attr.attr,
1492 &sensor_dev_attr_in16_input.dev_attr.attr, 1534 &sensor_dev_attr_in16_input.dev_attr.attr,
1493 &sensor_dev_attr_in16_max.dev_attr.attr, 1535 &sensor_dev_attr_in16_max.dev_attr.attr,
1494 &sensor_dev_attr_in16_min.dev_attr.attr, 1536 &sensor_dev_attr_in16_min.dev_attr.attr,
1537 &sensor_dev_attr_in16_alarm.dev_attr.attr,
1495 &sensor_dev_attr_fan1_input.dev_attr.attr, 1538 &sensor_dev_attr_fan1_input.dev_attr.attr,
1496 &sensor_dev_attr_fan1_div.dev_attr.attr, 1539 &sensor_dev_attr_fan1_div.dev_attr.attr,
1497 &sensor_dev_attr_fan1_min.dev_attr.attr, 1540 &sensor_dev_attr_fan1_min.dev_attr.attr,
1541 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1498 &sensor_dev_attr_fan2_input.dev_attr.attr, 1542 &sensor_dev_attr_fan2_input.dev_attr.attr,
1499 &sensor_dev_attr_fan2_div.dev_attr.attr, 1543 &sensor_dev_attr_fan2_div.dev_attr.attr,
1500 &sensor_dev_attr_fan2_min.dev_attr.attr, 1544 &sensor_dev_attr_fan2_min.dev_attr.attr,
1545 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1501 &sensor_dev_attr_fan3_input.dev_attr.attr, 1546 &sensor_dev_attr_fan3_input.dev_attr.attr,
1502 &sensor_dev_attr_fan3_div.dev_attr.attr, 1547 &sensor_dev_attr_fan3_div.dev_attr.attr,
1503 &sensor_dev_attr_fan3_min.dev_attr.attr, 1548 &sensor_dev_attr_fan3_min.dev_attr.attr,
1549 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1504 &sensor_dev_attr_fan4_input.dev_attr.attr, 1550 &sensor_dev_attr_fan4_input.dev_attr.attr,
1505 &sensor_dev_attr_fan4_div.dev_attr.attr, 1551 &sensor_dev_attr_fan4_div.dev_attr.attr,
1506 &sensor_dev_attr_fan4_min.dev_attr.attr, 1552 &sensor_dev_attr_fan4_min.dev_attr.attr,
1553 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1507 &sensor_dev_attr_fan5_input.dev_attr.attr, 1554 &sensor_dev_attr_fan5_input.dev_attr.attr,
1508 &sensor_dev_attr_fan5_div.dev_attr.attr, 1555 &sensor_dev_attr_fan5_div.dev_attr.attr,
1509 &sensor_dev_attr_fan5_min.dev_attr.attr, 1556 &sensor_dev_attr_fan5_min.dev_attr.attr,
1557 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1510 &sensor_dev_attr_fan6_input.dev_attr.attr, 1558 &sensor_dev_attr_fan6_input.dev_attr.attr,
1511 &sensor_dev_attr_fan6_div.dev_attr.attr, 1559 &sensor_dev_attr_fan6_div.dev_attr.attr,
1512 &sensor_dev_attr_fan6_min.dev_attr.attr, 1560 &sensor_dev_attr_fan6_min.dev_attr.attr,
1561 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
1513 &sensor_dev_attr_fan7_input.dev_attr.attr, 1562 &sensor_dev_attr_fan7_input.dev_attr.attr,
1514 &sensor_dev_attr_fan7_div.dev_attr.attr, 1563 &sensor_dev_attr_fan7_div.dev_attr.attr,
1515 &sensor_dev_attr_fan7_min.dev_attr.attr, 1564 &sensor_dev_attr_fan7_min.dev_attr.attr,
1565 &sensor_dev_attr_fan7_alarm.dev_attr.attr,
1516 &sensor_dev_attr_fan8_input.dev_attr.attr, 1566 &sensor_dev_attr_fan8_input.dev_attr.attr,
1517 &sensor_dev_attr_fan8_div.dev_attr.attr, 1567 &sensor_dev_attr_fan8_div.dev_attr.attr,
1518 &sensor_dev_attr_fan8_min.dev_attr.attr, 1568 &sensor_dev_attr_fan8_min.dev_attr.attr,
1569 &sensor_dev_attr_fan8_alarm.dev_attr.attr,
1519 &sensor_dev_attr_temp1_input.dev_attr.attr, 1570 &sensor_dev_attr_temp1_input.dev_attr.attr,
1520 &sensor_dev_attr_temp1_max.dev_attr.attr, 1571 &sensor_dev_attr_temp1_max.dev_attr.attr,
1521 &sensor_dev_attr_temp1_min.dev_attr.attr, 1572 &sensor_dev_attr_temp1_min.dev_attr.attr,
1573 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1522 &sensor_dev_attr_temp2_input.dev_attr.attr, 1574 &sensor_dev_attr_temp2_input.dev_attr.attr,
1523 &sensor_dev_attr_temp2_max.dev_attr.attr, 1575 &sensor_dev_attr_temp2_max.dev_attr.attr,
1524 &sensor_dev_attr_temp2_min.dev_attr.attr, 1576 &sensor_dev_attr_temp2_min.dev_attr.attr,
1525 &sensor_dev_attr_temp3_input.dev_attr.attr, 1577 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1526 &sensor_dev_attr_temp3_max.dev_attr.attr,
1527 &sensor_dev_attr_temp3_min.dev_attr.attr,
1528 &sensor_dev_attr_temp1_offset.dev_attr.attr, 1578 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1529 &sensor_dev_attr_temp2_offset.dev_attr.attr, 1579 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1530 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1531 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, 1580 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
1532 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr, 1581 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
1533 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1534 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr, 1582 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
1535 &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr.attr, 1583 &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr.attr,
1536 &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
1537 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr, 1584 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
1538 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr, 1585 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
1539 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1540 &sensor_dev_attr_temp1_crit.dev_attr.attr, 1586 &sensor_dev_attr_temp1_crit.dev_attr.attr,
1541 &sensor_dev_attr_temp2_crit.dev_attr.attr, 1587 &sensor_dev_attr_temp2_crit.dev_attr.attr,
1542 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1543 &dev_attr_temp1_crit_enable.attr, 1588 &dev_attr_temp1_crit_enable.attr,
1544 &dev_attr_temp2_crit_enable.attr, 1589 &dev_attr_temp2_crit_enable.attr,
1545 &dev_attr_temp3_crit_enable.attr,
1546 &dev_attr_cpu0_vid.attr, 1590 &dev_attr_cpu0_vid.attr,
1547 &dev_attr_vrm.attr, 1591 &dev_attr_vrm.attr,
1548 &dev_attr_alarms.attr, 1592 &dev_attr_alarms.attr,
@@ -1557,10 +1601,8 @@ static struct attribute *adm1026_attributes[] = {
1557 &dev_attr_pwm3_enable.attr, 1601 &dev_attr_pwm3_enable.attr,
1558 &dev_attr_temp1_auto_point1_pwm.attr, 1602 &dev_attr_temp1_auto_point1_pwm.attr,
1559 &dev_attr_temp2_auto_point1_pwm.attr, 1603 &dev_attr_temp2_auto_point1_pwm.attr,
1560 &dev_attr_temp3_auto_point1_pwm.attr,
1561 &dev_attr_temp1_auto_point2_pwm.attr, 1604 &dev_attr_temp1_auto_point2_pwm.attr,
1562 &dev_attr_temp2_auto_point2_pwm.attr, 1605 &dev_attr_temp2_auto_point2_pwm.attr,
1563 &dev_attr_temp3_auto_point2_pwm.attr,
1564 &dev_attr_analog_out.attr, 1606 &dev_attr_analog_out.attr,
1565 NULL 1607 NULL
1566}; 1608};
@@ -1569,11 +1611,45 @@ static const struct attribute_group adm1026_group = {
1569 .attrs = adm1026_attributes, 1611 .attrs = adm1026_attributes,
1570}; 1612};
1571 1613
1614static struct attribute *adm1026_attributes_temp3[] = {
1615 &sensor_dev_attr_temp3_input.dev_attr.attr,
1616 &sensor_dev_attr_temp3_max.dev_attr.attr,
1617 &sensor_dev_attr_temp3_min.dev_attr.attr,
1618 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1619 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1620 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1621 &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
1622 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1623 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1624 &dev_attr_temp3_crit_enable.attr,
1625 &dev_attr_temp3_auto_point1_pwm.attr,
1626 &dev_attr_temp3_auto_point2_pwm.attr,
1627};
1628
1629static const struct attribute_group adm1026_group_temp3 = {
1630 .attrs = adm1026_attributes_temp3,
1631};
1632
1633static struct attribute *adm1026_attributes_in8_9[] = {
1634 &sensor_dev_attr_in8_input.dev_attr.attr,
1635 &sensor_dev_attr_in8_max.dev_attr.attr,
1636 &sensor_dev_attr_in8_min.dev_attr.attr,
1637 &sensor_dev_attr_in8_alarm.dev_attr.attr,
1638 &sensor_dev_attr_in9_input.dev_attr.attr,
1639 &sensor_dev_attr_in9_max.dev_attr.attr,
1640 &sensor_dev_attr_in9_min.dev_attr.attr,
1641 &sensor_dev_attr_in9_alarm.dev_attr.attr,
1642};
1643
1644static const struct attribute_group adm1026_group_in8_9 = {
1645 .attrs = adm1026_attributes_in8_9,
1646};
1647
1572static int adm1026_detect(struct i2c_adapter *adapter, int address, 1648static int adm1026_detect(struct i2c_adapter *adapter, int address,
1573 int kind) 1649 int kind)
1574{ 1650{
1575 int company, verstep; 1651 int company, verstep;
1576 struct i2c_client *new_client; 1652 struct i2c_client *client;
1577 struct adm1026_data *data; 1653 struct adm1026_data *data;
1578 int err = 0; 1654 int err = 0;
1579 const char *type_name = ""; 1655 const char *type_name = "";
@@ -1592,26 +1668,25 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
1592 goto exit; 1668 goto exit;
1593 } 1669 }
1594 1670
1595 new_client = &data->client; 1671 client = &data->client;
1596 i2c_set_clientdata(new_client, data); 1672 i2c_set_clientdata(client, data);
1597 new_client->addr = address; 1673 client->addr = address;
1598 new_client->adapter = adapter; 1674 client->adapter = adapter;
1599 new_client->driver = &adm1026_driver; 1675 client->driver = &adm1026_driver;
1600 new_client->flags = 0;
1601 1676
1602 /* Now, we do the remaining detection. */ 1677 /* Now, we do the remaining detection. */
1603 1678
1604 company = adm1026_read_value(new_client, ADM1026_REG_COMPANY); 1679 company = adm1026_read_value(client, ADM1026_REG_COMPANY);
1605 verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP); 1680 verstep = adm1026_read_value(client, ADM1026_REG_VERSTEP);
1606 1681
1607 dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with" 1682 dev_dbg(&client->dev, "Detecting device at %d,0x%02x with"
1608 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", 1683 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1609 i2c_adapter_id(new_client->adapter), new_client->addr, 1684 i2c_adapter_id(client->adapter), client->addr,
1610 company, verstep); 1685 company, verstep);
1611 1686
1612 /* If auto-detecting, Determine the chip type. */ 1687 /* If auto-detecting, Determine the chip type. */
1613 if (kind <= 0) { 1688 if (kind <= 0) {
1614 dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x " 1689 dev_dbg(&client->dev, "Autodetecting device at %d,0x%02x "
1615 "...\n", i2c_adapter_id(adapter), address); 1690 "...\n", i2c_adapter_id(adapter), address);
1616 if (company == ADM1026_COMPANY_ANALOG_DEV 1691 if (company == ADM1026_COMPANY_ANALOG_DEV
1617 && verstep == ADM1026_VERSTEP_ADM1026) { 1692 && verstep == ADM1026_VERSTEP_ADM1026) {
@@ -1627,16 +1702,15 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
1627 verstep); 1702 verstep);
1628 kind = any_chip; 1703 kind = any_chip;
1629 } else { 1704 } else {
1630 dev_dbg(&new_client->dev, ": Autodetection " 1705 dev_dbg(&client->dev, ": Autodetection "
1631 "failed\n"); 1706 "failed\n");
1632 /* Not an ADM1026 ... */ 1707 /* Not an ADM1026 ... */
1633 if (kind == 0) { /* User used force=x,y */ 1708 if (kind == 0) { /* User used force=x,y */
1634 dev_err(&adapter->dev, "Generic ADM1026 not " 1709 dev_err(&adapter->dev, "Generic ADM1026 not "
1635 "found at %d,0x%02x. Try " 1710 "found at %d,0x%02x. Try "
1636 "force_adm1026.\n", 1711 "force_adm1026.\n",
1637 i2c_adapter_id(adapter), address); 1712 i2c_adapter_id(adapter), address);
1638 } 1713 }
1639 err = 0;
1640 goto exitfree; 1714 goto exitfree;
1641 } 1715 }
1642 } 1716 }
@@ -1655,28 +1729,34 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
1655 err = -EFAULT; 1729 err = -EFAULT;
1656 goto exitfree; 1730 goto exitfree;
1657 } 1731 }
1658 strlcpy(new_client->name, type_name, I2C_NAME_SIZE); 1732 strlcpy(client->name, type_name, I2C_NAME_SIZE);
1659 1733
1660 /* Fill in the remaining client fields */ 1734 /* Fill in the remaining client fields */
1661 data->type = kind;
1662 data->valid = 0;
1663 mutex_init(&data->update_lock); 1735 mutex_init(&data->update_lock);
1664 1736
1665 /* Tell the I2C layer a new client has arrived */ 1737 /* Tell the I2C layer a new client has arrived */
1666 if ((err = i2c_attach_client(new_client))) 1738 if ((err = i2c_attach_client(client)))
1667 goto exitfree; 1739 goto exitfree;
1668 1740
1669 /* Set the VRM version */ 1741 /* Set the VRM version */
1670 data->vrm = vid_which_vrm(); 1742 data->vrm = vid_which_vrm();
1671 1743
1672 /* Initialize the ADM1026 chip */ 1744 /* Initialize the ADM1026 chip */
1673 adm1026_init_client(new_client); 1745 adm1026_init_client(client);
1674 1746
1675 /* Register sysfs hooks */ 1747 /* Register sysfs hooks */
1676 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1026_group))) 1748 if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group)))
1677 goto exitdetach; 1749 goto exitdetach;
1750 if (data->config1 & CFG1_AIN8_9)
1751 err = sysfs_create_group(&client->dev.kobj,
1752 &adm1026_group_in8_9);
1753 else
1754 err = sysfs_create_group(&client->dev.kobj,
1755 &adm1026_group_temp3);
1756 if (err)
1757 goto exitremove;
1678 1758
1679 data->hwmon_dev = hwmon_device_register(&new_client->dev); 1759 data->hwmon_dev = hwmon_device_register(&client->dev);
1680 if (IS_ERR(data->hwmon_dev)) { 1760 if (IS_ERR(data->hwmon_dev)) {
1681 err = PTR_ERR(data->hwmon_dev); 1761 err = PTR_ERR(data->hwmon_dev);
1682 goto exitremove; 1762 goto exitremove;
@@ -1686,9 +1766,13 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
1686 1766
1687 /* Error out and cleanup code */ 1767 /* Error out and cleanup code */
1688exitremove: 1768exitremove:
1689 sysfs_remove_group(&new_client->dev.kobj, &adm1026_group); 1769 sysfs_remove_group(&client->dev.kobj, &adm1026_group);
1770 if (data->config1 & CFG1_AIN8_9)
1771 sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9);
1772 else
1773 sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3);
1690exitdetach: 1774exitdetach:
1691 i2c_detach_client(new_client); 1775 i2c_detach_client(client);
1692exitfree: 1776exitfree:
1693 kfree(data); 1777 kfree(data);
1694exit: 1778exit:
@@ -1700,6 +1784,10 @@ static int adm1026_detach_client(struct i2c_client *client)
1700 struct adm1026_data *data = i2c_get_clientdata(client); 1784 struct adm1026_data *data = i2c_get_clientdata(client);
1701 hwmon_device_unregister(data->hwmon_dev); 1785 hwmon_device_unregister(data->hwmon_dev);
1702 sysfs_remove_group(&client->dev.kobj, &adm1026_group); 1786 sysfs_remove_group(&client->dev.kobj, &adm1026_group);
1787 if (data->config1 & CFG1_AIN8_9)
1788 sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9);
1789 else
1790 sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3);
1703 i2c_detach_client(client); 1791 i2c_detach_client(client);
1704 kfree(data); 1792 kfree(data);
1705 return 0; 1793 return 0;
@@ -1710,14 +1798,14 @@ static int __init sm_adm1026_init(void)
1710 return i2c_add_driver(&adm1026_driver); 1798 return i2c_add_driver(&adm1026_driver);
1711} 1799}
1712 1800
1713static void __exit sm_adm1026_exit(void) 1801static void __exit sm_adm1026_exit(void)
1714{ 1802{
1715 i2c_del_driver(&adm1026_driver); 1803 i2c_del_driver(&adm1026_driver);
1716} 1804}
1717 1805
1718MODULE_LICENSE("GPL"); 1806MODULE_LICENSE("GPL");
1719MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, " 1807MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1720 "Justin Thiessen <jthiessen@penguincomputing.com>"); 1808 "Justin Thiessen <jthiessen@penguincomputing.com>");
1721MODULE_DESCRIPTION("ADM1026 driver"); 1809MODULE_DESCRIPTION("ADM1026 driver");
1722 1810
1723module_init(sm_adm1026_init); 1811module_init(sm_adm1026_init);
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 37cfc101da5e..5aaad3636c98 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -5,7 +5,7 @@
5 Supports adm1030 / adm1031 5 Supports adm1030 / adm1031
6 Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org> 6 Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org>
7 Reworked by Jean Delvare <khali@linux-fr.org> 7 Reworked by Jean Delvare <khali@linux-fr.org>
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or 11 the Free Software Foundation; either version 2 of the License, or
@@ -27,27 +27,28 @@
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/hwmon-sysfs.h>
30#include <linux/err.h> 31#include <linux/err.h>
31#include <linux/mutex.h> 32#include <linux/mutex.h>
32 33
33/* Following macros takes channel parameter starting from 0 to 2 */ 34/* Following macros takes channel parameter starting from 0 to 2 */
34#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) 35#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr))
35#define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) 36#define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr))
36#define ADM1031_REG_PWM (0x22) 37#define ADM1031_REG_PWM (0x22)
37#define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr)) 38#define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr))
38 39
39#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4*(nr)) 40#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr))
40#define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4*(nr)) 41#define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4 * (nr))
41#define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4*(nr)) 42#define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4 * (nr))
42 43
43#define ADM1031_REG_TEMP(nr) (0xa + (nr)) 44#define ADM1031_REG_TEMP(nr) (0x0a + (nr))
44#define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr)) 45#define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr))
45 46
46#define ADM1031_REG_STATUS(nr) (0x2 + (nr)) 47#define ADM1031_REG_STATUS(nr) (0x2 + (nr))
47 48
48#define ADM1031_REG_CONF1 0x0 49#define ADM1031_REG_CONF1 0x00
49#define ADM1031_REG_CONF2 0x1 50#define ADM1031_REG_CONF2 0x01
50#define ADM1031_REG_EXT_TEMP 0x6 51#define ADM1031_REG_EXT_TEMP 0x06
51 52
52#define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */ 53#define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */
53#define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */ 54#define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */
@@ -78,7 +79,7 @@ struct adm1031_data {
78 /* The chan_select_table contains the possible configurations for 79 /* The chan_select_table contains the possible configurations for
79 * auto fan control. 80 * auto fan control.
80 */ 81 */
81 auto_chan_table_t *chan_select_table; 82 const auto_chan_table_t *chan_select_table;
82 u16 alarm; 83 u16 alarm;
83 u8 conf1; 84 u8 conf1;
84 u8 conf2; 85 u8 conf2;
@@ -181,25 +182,25 @@ static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm)
181#define GET_FAN_AUTO_BITFIELD(data, idx) \ 182#define GET_FAN_AUTO_BITFIELD(data, idx) \
182 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2] 183 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2]
183 184
184/* The tables below contains the possible values for the auto fan 185/* The tables below contains the possible values for the auto fan
185 * control bitfields. the index in the table is the register value. 186 * control bitfields. the index in the table is the register value.
186 * MSb is the auto fan control enable bit, so the four first entries 187 * MSb is the auto fan control enable bit, so the four first entries
187 * in the table disables auto fan control when both bitfields are zero. 188 * in the table disables auto fan control when both bitfields are zero.
188 */ 189 */
189static auto_chan_table_t auto_channel_select_table_adm1031 = { 190static const auto_chan_table_t auto_channel_select_table_adm1031 = {
190 {0, 0}, {0, 0}, {0, 0}, {0, 0}, 191 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
191 {2 /*0b010 */ , 4 /*0b100 */ }, 192 { 2 /* 0b010 */ , 4 /* 0b100 */ },
192 {2 /*0b010 */ , 2 /*0b010 */ }, 193 { 2 /* 0b010 */ , 2 /* 0b010 */ },
193 {4 /*0b100 */ , 4 /*0b100 */ }, 194 { 4 /* 0b100 */ , 4 /* 0b100 */ },
194 {7 /*0b111 */ , 7 /*0b111 */ }, 195 { 7 /* 0b111 */ , 7 /* 0b111 */ },
195}; 196};
196 197
197static auto_chan_table_t auto_channel_select_table_adm1030 = { 198static const auto_chan_table_t auto_channel_select_table_adm1030 = {
198 {0, 0}, {0, 0}, {0, 0}, {0, 0}, 199 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
199 {2 /*0b10 */ , 0}, 200 { 2 /* 0b10 */ , 0 },
200 {0xff /*invalid */ , 0}, 201 { 0xff /* invalid */ , 0 },
201 {0xff /*invalid */ , 0}, 202 { 0xff /* invalid */ , 0 },
202 {3 /*0b11 */ , 0}, 203 { 3 /* 0b11 */ , 0 },
203}; 204};
204 205
205/* That function checks if a bitfield is valid and returns the other bitfield 206/* That function checks if a bitfield is valid and returns the other bitfield
@@ -228,8 +229,8 @@ get_fan_auto_nearest(struct adm1031_data *data,
228 break; 229 break;
229 } else if (val == (*data->chan_select_table)[i][chan] && 230 } else if (val == (*data->chan_select_table)[i][chan] &&
230 first_match == -1) { 231 first_match == -1) {
231 /* Save the first match in case of an exact match has not been 232 /* Save the first match in case of an exact match has
232 * found 233 * not been found
233 */ 234 */
234 first_match = i; 235 first_match = i;
235 } 236 }
@@ -245,17 +246,21 @@ get_fan_auto_nearest(struct adm1031_data *data,
245 return 0; 246 return 0;
246} 247}
247 248
248static ssize_t show_fan_auto_channel(struct device *dev, char *buf, int nr) 249static ssize_t show_fan_auto_channel(struct device *dev,
250 struct device_attribute *attr, char *buf)
249{ 251{
252 int nr = to_sensor_dev_attr(attr)->index;
250 struct adm1031_data *data = adm1031_update_device(dev); 253 struct adm1031_data *data = adm1031_update_device(dev);
251 return sprintf(buf, "%d\n", GET_FAN_AUTO_BITFIELD(data, nr)); 254 return sprintf(buf, "%d\n", GET_FAN_AUTO_BITFIELD(data, nr));
252} 255}
253 256
254static ssize_t 257static ssize_t
255set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr) 258set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
259 const char *buf, size_t count)
256{ 260{
257 struct i2c_client *client = to_i2c_client(dev); 261 struct i2c_client *client = to_i2c_client(dev);
258 struct adm1031_data *data = i2c_get_clientdata(client); 262 struct adm1031_data *data = i2c_get_clientdata(client);
263 int nr = to_sensor_dev_attr(attr)->index;
259 int val = simple_strtol(buf, NULL, 10); 264 int val = simple_strtol(buf, NULL, 10);
260 u8 reg; 265 u8 reg;
261 int ret; 266 int ret;
@@ -264,16 +269,17 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
264 old_fan_mode = data->conf1; 269 old_fan_mode = data->conf1;
265 270
266 mutex_lock(&data->update_lock); 271 mutex_lock(&data->update_lock);
267 272
268 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) { 273 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) {
269 mutex_unlock(&data->update_lock); 274 mutex_unlock(&data->update_lock);
270 return ret; 275 return ret;
271 } 276 }
272 if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^ 277 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
278 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^
273 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { 279 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {
274 if (data->conf1 & ADM1031_CONF1_AUTO_MODE){ 280 if (data->conf1 & ADM1031_CONF1_AUTO_MODE){
275 /* Switch to Auto Fan Mode 281 /* Switch to Auto Fan Mode
276 * Save PWM registers 282 * Save PWM registers
277 * Set PWM registers to 33% Both */ 283 * Set PWM registers to 33% Both */
278 data->old_pwm[0] = data->pwm[0]; 284 data->old_pwm[0] = data->pwm[0];
279 data->old_pwm[1] = data->pwm[1]; 285 data->old_pwm[1] = data->pwm[1];
@@ -283,7 +289,7 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
283 data->pwm[0] = data->old_pwm[0]; 289 data->pwm[0] = data->old_pwm[0];
284 data->pwm[1] = data->old_pwm[1]; 290 data->pwm[1] = data->old_pwm[1];
285 /* Restore PWM registers */ 291 /* Restore PWM registers */
286 adm1031_write_value(client, ADM1031_REG_PWM, 292 adm1031_write_value(client, ADM1031_REG_PWM,
287 data->pwm[0] | (data->pwm[1] << 4)); 293 data->pwm[0] | (data->pwm[1] << 4));
288 } 294 }
289 } 295 }
@@ -293,41 +299,35 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
293 return count; 299 return count;
294} 300}
295 301
296#define fan_auto_channel_offset(offset) \ 302static SENSOR_DEVICE_ATTR(auto_fan1_channel, S_IRUGO | S_IWUSR,
297static ssize_t show_fan_auto_channel_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 303 show_fan_auto_channel, set_fan_auto_channel, 0);
298{ \ 304static SENSOR_DEVICE_ATTR(auto_fan2_channel, S_IRUGO | S_IWUSR,
299 return show_fan_auto_channel(dev, buf, offset - 1); \ 305 show_fan_auto_channel, set_fan_auto_channel, 1);
300} \
301static ssize_t set_fan_auto_channel_##offset (struct device *dev, struct device_attribute *attr, \
302 const char *buf, size_t count) \
303{ \
304 return set_fan_auto_channel(dev, buf, count, offset - 1); \
305} \
306static DEVICE_ATTR(auto_fan##offset##_channel, S_IRUGO | S_IWUSR, \
307 show_fan_auto_channel_##offset, \
308 set_fan_auto_channel_##offset)
309
310fan_auto_channel_offset(1);
311fan_auto_channel_offset(2);
312 306
313/* Auto Temps */ 307/* Auto Temps */
314static ssize_t show_auto_temp_off(struct device *dev, char *buf, int nr) 308static ssize_t show_auto_temp_off(struct device *dev,
309 struct device_attribute *attr, char *buf)
315{ 310{
311 int nr = to_sensor_dev_attr(attr)->index;
316 struct adm1031_data *data = adm1031_update_device(dev); 312 struct adm1031_data *data = adm1031_update_device(dev);
317 return sprintf(buf, "%d\n", 313 return sprintf(buf, "%d\n",
318 AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr])); 314 AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr]));
319} 315}
320static ssize_t show_auto_temp_min(struct device *dev, char *buf, int nr) 316static ssize_t show_auto_temp_min(struct device *dev,
317 struct device_attribute *attr, char *buf)
321{ 318{
319 int nr = to_sensor_dev_attr(attr)->index;
322 struct adm1031_data *data = adm1031_update_device(dev); 320 struct adm1031_data *data = adm1031_update_device(dev);
323 return sprintf(buf, "%d\n", 321 return sprintf(buf, "%d\n",
324 AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr])); 322 AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr]));
325} 323}
326static ssize_t 324static ssize_t
327set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr) 325set_auto_temp_min(struct device *dev, struct device_attribute *attr,
326 const char *buf, size_t count)
328{ 327{
329 struct i2c_client *client = to_i2c_client(dev); 328 struct i2c_client *client = to_i2c_client(dev);
330 struct adm1031_data *data = i2c_get_clientdata(client); 329 struct adm1031_data *data = i2c_get_clientdata(client);
330 int nr = to_sensor_dev_attr(attr)->index;
331 int val = simple_strtol(buf, NULL, 10); 331 int val = simple_strtol(buf, NULL, 10);
332 332
333 mutex_lock(&data->update_lock); 333 mutex_lock(&data->update_lock);
@@ -337,17 +337,21 @@ set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr)
337 mutex_unlock(&data->update_lock); 337 mutex_unlock(&data->update_lock);
338 return count; 338 return count;
339} 339}
340static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr) 340static ssize_t show_auto_temp_max(struct device *dev,
341 struct device_attribute *attr, char *buf)
341{ 342{
343 int nr = to_sensor_dev_attr(attr)->index;
342 struct adm1031_data *data = adm1031_update_device(dev); 344 struct adm1031_data *data = adm1031_update_device(dev);
343 return sprintf(buf, "%d\n", 345 return sprintf(buf, "%d\n",
344 AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr])); 346 AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr]));
345} 347}
346static ssize_t 348static ssize_t
347set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr) 349set_auto_temp_max(struct device *dev, struct device_attribute *attr,
350 const char *buf, size_t count)
348{ 351{
349 struct i2c_client *client = to_i2c_client(dev); 352 struct i2c_client *client = to_i2c_client(dev);
350 struct adm1031_data *data = i2c_get_clientdata(client); 353 struct adm1031_data *data = i2c_get_clientdata(client);
354 int nr = to_sensor_dev_attr(attr)->index;
351 int val = simple_strtol(buf, NULL, 10); 355 int val = simple_strtol(buf, NULL, 10);
352 356
353 mutex_lock(&data->update_lock); 357 mutex_lock(&data->update_lock);
@@ -358,56 +362,37 @@ set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr)
358 return count; 362 return count;
359} 363}
360 364
361#define auto_temp_reg(offset) \ 365#define auto_temp_reg(offset) \
362static ssize_t show_auto_temp_##offset##_off (struct device *dev, struct device_attribute *attr, char *buf) \ 366static SENSOR_DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO, \
363{ \ 367 show_auto_temp_off, NULL, offset - 1); \
364 return show_auto_temp_off(dev, buf, offset - 1); \ 368static SENSOR_DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR, \
365} \ 369 show_auto_temp_min, set_auto_temp_min, offset - 1); \
366static ssize_t show_auto_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 370static SENSOR_DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR, \
367{ \ 371 show_auto_temp_max, set_auto_temp_max, offset - 1)
368 return show_auto_temp_min(dev, buf, offset - 1); \
369} \
370static ssize_t show_auto_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
371{ \
372 return show_auto_temp_max(dev, buf, offset - 1); \
373} \
374static ssize_t set_auto_temp_##offset##_min (struct device *dev, struct device_attribute *attr, \
375 const char *buf, size_t count) \
376{ \
377 return set_auto_temp_min(dev, buf, count, offset - 1); \
378} \
379static ssize_t set_auto_temp_##offset##_max (struct device *dev, struct device_attribute *attr, \
380 const char *buf, size_t count) \
381{ \
382 return set_auto_temp_max(dev, buf, count, offset - 1); \
383} \
384static DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO, \
385 show_auto_temp_##offset##_off, NULL); \
386static DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR, \
387 show_auto_temp_##offset##_min, set_auto_temp_##offset##_min);\
388static DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR, \
389 show_auto_temp_##offset##_max, set_auto_temp_##offset##_max)
390 372
391auto_temp_reg(1); 373auto_temp_reg(1);
392auto_temp_reg(2); 374auto_temp_reg(2);
393auto_temp_reg(3); 375auto_temp_reg(3);
394 376
395/* pwm */ 377/* pwm */
396static ssize_t show_pwm(struct device *dev, char *buf, int nr) 378static ssize_t show_pwm(struct device *dev,
379 struct device_attribute *attr, char *buf)
397{ 380{
381 int nr = to_sensor_dev_attr(attr)->index;
398 struct adm1031_data *data = adm1031_update_device(dev); 382 struct adm1031_data *data = adm1031_update_device(dev);
399 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); 383 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
400} 384}
401static ssize_t 385static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
402set_pwm(struct device *dev, const char *buf, size_t count, int nr) 386 const char *buf, size_t count)
403{ 387{
404 struct i2c_client *client = to_i2c_client(dev); 388 struct i2c_client *client = to_i2c_client(dev);
405 struct adm1031_data *data = i2c_get_clientdata(client); 389 struct adm1031_data *data = i2c_get_clientdata(client);
390 int nr = to_sensor_dev_attr(attr)->index;
406 int val = simple_strtol(buf, NULL, 10); 391 int val = simple_strtol(buf, NULL, 10);
407 int reg; 392 int reg;
408 393
409 mutex_lock(&data->update_lock); 394 mutex_lock(&data->update_lock);
410 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && 395 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) &&
411 (((val>>4) & 0xf) != 5)) { 396 (((val>>4) & 0xf) != 5)) {
412 /* In automatic mode, the only PWM accepted is 33% */ 397 /* In automatic mode, the only PWM accepted is 33% */
413 mutex_unlock(&data->update_lock); 398 mutex_unlock(&data->update_lock);
@@ -422,21 +407,12 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
422 return count; 407 return count;
423} 408}
424 409
425#define pwm_reg(offset) \ 410static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
426static ssize_t show_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 411static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
427{ \ 412static SENSOR_DEVICE_ATTR(auto_fan1_min_pwm, S_IRUGO | S_IWUSR,
428 return show_pwm(dev, buf, offset - 1); \ 413 show_pwm, set_pwm, 0);
429} \ 414static SENSOR_DEVICE_ATTR(auto_fan2_min_pwm, S_IRUGO | S_IWUSR,
430static ssize_t set_pwm_##offset (struct device *dev, struct device_attribute *attr, \ 415 show_pwm, set_pwm, 1);
431 const char *buf, size_t count) \
432{ \
433 return set_pwm(dev, buf, count, offset - 1); \
434} \
435static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
436 show_pwm_##offset, set_pwm_##offset)
437
438pwm_reg(1);
439pwm_reg(2);
440 416
441/* Fans */ 417/* Fans */
442 418
@@ -471,7 +447,7 @@ static int trust_fan_readings(struct adm1031_data *data, int chan)
471 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0]) 447 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0])
472 || data->temp[1] >= 448 || data->temp[1] >=
473 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]) 449 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1])
474 || (data->chip_type == adm1031 450 || (data->chip_type == adm1031
475 && data->temp[2] >= 451 && data->temp[2] >=
476 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2])); 452 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2]));
477 break; 453 break;
@@ -483,8 +459,10 @@ static int trust_fan_readings(struct adm1031_data *data, int chan)
483} 459}
484 460
485 461
486static ssize_t show_fan(struct device *dev, char *buf, int nr) 462static ssize_t show_fan(struct device *dev,
463 struct device_attribute *attr, char *buf)
487{ 464{
465 int nr = to_sensor_dev_attr(attr)->index;
488 struct adm1031_data *data = adm1031_update_device(dev); 466 struct adm1031_data *data = adm1031_update_device(dev);
489 int value; 467 int value;
490 468
@@ -493,28 +471,33 @@ static ssize_t show_fan(struct device *dev, char *buf, int nr)
493 return sprintf(buf, "%d\n", value); 471 return sprintf(buf, "%d\n", value);
494} 472}
495 473
496static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 474static ssize_t show_fan_div(struct device *dev,
475 struct device_attribute *attr, char *buf)
497{ 476{
477 int nr = to_sensor_dev_attr(attr)->index;
498 struct adm1031_data *data = adm1031_update_device(dev); 478 struct adm1031_data *data = adm1031_update_device(dev);
499 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr])); 479 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr]));
500} 480}
501static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 481static ssize_t show_fan_min(struct device *dev,
482 struct device_attribute *attr, char *buf)
502{ 483{
484 int nr = to_sensor_dev_attr(attr)->index;
503 struct adm1031_data *data = adm1031_update_device(dev); 485 struct adm1031_data *data = adm1031_update_device(dev);
504 return sprintf(buf, "%d\n", 486 return sprintf(buf, "%d\n",
505 FAN_FROM_REG(data->fan_min[nr], 487 FAN_FROM_REG(data->fan_min[nr],
506 FAN_DIV_FROM_REG(data->fan_div[nr]))); 488 FAN_DIV_FROM_REG(data->fan_div[nr])));
507} 489}
508static ssize_t 490static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
509set_fan_min(struct device *dev, const char *buf, size_t count, int nr) 491 const char *buf, size_t count)
510{ 492{
511 struct i2c_client *client = to_i2c_client(dev); 493 struct i2c_client *client = to_i2c_client(dev);
512 struct adm1031_data *data = i2c_get_clientdata(client); 494 struct adm1031_data *data = i2c_get_clientdata(client);
495 int nr = to_sensor_dev_attr(attr)->index;
513 int val = simple_strtol(buf, NULL, 10); 496 int val = simple_strtol(buf, NULL, 10);
514 497
515 mutex_lock(&data->update_lock); 498 mutex_lock(&data->update_lock);
516 if (val) { 499 if (val) {
517 data->fan_min[nr] = 500 data->fan_min[nr] =
518 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); 501 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr]));
519 } else { 502 } else {
520 data->fan_min[nr] = 0xff; 503 data->fan_min[nr] = 0xff;
@@ -523,11 +506,12 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
523 mutex_unlock(&data->update_lock); 506 mutex_unlock(&data->update_lock);
524 return count; 507 return count;
525} 508}
526static ssize_t 509static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
527set_fan_div(struct device *dev, const char *buf, size_t count, int nr) 510 const char *buf, size_t count)
528{ 511{
529 struct i2c_client *client = to_i2c_client(dev); 512 struct i2c_client *client = to_i2c_client(dev);
530 struct adm1031_data *data = i2c_get_clientdata(client); 513 struct adm1031_data *data = i2c_get_clientdata(client);
514 int nr = to_sensor_dev_attr(attr)->index;
531 int val = simple_strtol(buf, NULL, 10); 515 int val = simple_strtol(buf, NULL, 10);
532 u8 tmp; 516 u8 tmp;
533 int old_div; 517 int old_div;
@@ -535,68 +519,53 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
535 519
536 tmp = val == 8 ? 0xc0 : 520 tmp = val == 8 ? 0xc0 :
537 val == 4 ? 0x80 : 521 val == 4 ? 0x80 :
538 val == 2 ? 0x40 : 522 val == 2 ? 0x40 :
539 val == 1 ? 0x00 : 523 val == 1 ? 0x00 :
540 0xff; 524 0xff;
541 if (tmp == 0xff) 525 if (tmp == 0xff)
542 return -EINVAL; 526 return -EINVAL;
543 527
544 mutex_lock(&data->update_lock); 528 mutex_lock(&data->update_lock);
529 /* Get fresh readings */
530 data->fan_div[nr] = adm1031_read_value(client,
531 ADM1031_REG_FAN_DIV(nr));
532 data->fan_min[nr] = adm1031_read_value(client,
533 ADM1031_REG_FAN_MIN(nr));
534
535 /* Write the new clock divider and fan min */
545 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); 536 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]);
546 data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]); 537 data->fan_div[nr] = tmp | (0x3f & data->fan_div[nr]);
547 new_min = data->fan_min[nr] * old_div / 538 new_min = data->fan_min[nr] * old_div / val;
548 FAN_DIV_FROM_REG(data->fan_div[nr]);
549 data->fan_min[nr] = new_min > 0xff ? 0xff : new_min; 539 data->fan_min[nr] = new_min > 0xff ? 0xff : new_min;
550 data->fan[nr] = data->fan[nr] * old_div /
551 FAN_DIV_FROM_REG(data->fan_div[nr]);
552 540
553 adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr), 541 adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr),
554 data->fan_div[nr]); 542 data->fan_div[nr]);
555 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), 543 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr),
556 data->fan_min[nr]); 544 data->fan_min[nr]);
545
546 /* Invalidate the cache: fan speed is no longer valid */
547 data->valid = 0;
557 mutex_unlock(&data->update_lock); 548 mutex_unlock(&data->update_lock);
558 return count; 549 return count;
559} 550}
560 551
561#define fan_offset(offset) \ 552#define fan_offset(offset) \
562static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 553static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
563{ \ 554 show_fan, NULL, offset - 1); \
564 return show_fan(dev, buf, offset - 1); \ 555static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
565} \ 556 show_fan_min, set_fan_min, offset - 1); \
566static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 557static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
567{ \ 558 show_fan_div, set_fan_div, offset - 1)
568 return show_fan_min(dev, buf, offset - 1); \
569} \
570static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \
571{ \
572 return show_fan_div(dev, buf, offset - 1); \
573} \
574static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
575 const char *buf, size_t count) \
576{ \
577 return set_fan_min(dev, buf, count, offset - 1); \
578} \
579static ssize_t set_fan_##offset##_div (struct device *dev, struct device_attribute *attr, \
580 const char *buf, size_t count) \
581{ \
582 return set_fan_div(dev, buf, count, offset - 1); \
583} \
584static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, \
585 NULL); \
586static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
587 show_fan_##offset##_min, set_fan_##offset##_min); \
588static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
589 show_fan_##offset##_div, set_fan_##offset##_div); \
590static DEVICE_ATTR(auto_fan##offset##_min_pwm, S_IRUGO | S_IWUSR, \
591 show_pwm_##offset, set_pwm_##offset)
592 559
593fan_offset(1); 560fan_offset(1);
594fan_offset(2); 561fan_offset(2);
595 562
596 563
597/* Temps */ 564/* Temps */
598static ssize_t show_temp(struct device *dev, char *buf, int nr) 565static ssize_t show_temp(struct device *dev,
566 struct device_attribute *attr, char *buf)
599{ 567{
568 int nr = to_sensor_dev_attr(attr)->index;
600 struct adm1031_data *data = adm1031_update_device(dev); 569 struct adm1031_data *data = adm1031_update_device(dev);
601 int ext; 570 int ext;
602 ext = nr == 0 ? 571 ext = nr == 0 ?
@@ -604,26 +573,33 @@ static ssize_t show_temp(struct device *dev, char *buf, int nr)
604 (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7)); 573 (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7));
605 return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext)); 574 return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext));
606} 575}
607static ssize_t show_temp_min(struct device *dev, char *buf, int nr) 576static ssize_t show_temp_min(struct device *dev,
577 struct device_attribute *attr, char *buf)
608{ 578{
579 int nr = to_sensor_dev_attr(attr)->index;
609 struct adm1031_data *data = adm1031_update_device(dev); 580 struct adm1031_data *data = adm1031_update_device(dev);
610 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); 581 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
611} 582}
612static ssize_t show_temp_max(struct device *dev, char *buf, int nr) 583static ssize_t show_temp_max(struct device *dev,
584 struct device_attribute *attr, char *buf)
613{ 585{
586 int nr = to_sensor_dev_attr(attr)->index;
614 struct adm1031_data *data = adm1031_update_device(dev); 587 struct adm1031_data *data = adm1031_update_device(dev);
615 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); 588 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
616} 589}
617static ssize_t show_temp_crit(struct device *dev, char *buf, int nr) 590static ssize_t show_temp_crit(struct device *dev,
591 struct device_attribute *attr, char *buf)
618{ 592{
593 int nr = to_sensor_dev_attr(attr)->index;
619 struct adm1031_data *data = adm1031_update_device(dev); 594 struct adm1031_data *data = adm1031_update_device(dev);
620 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr])); 595 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
621} 596}
622static ssize_t 597static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
623set_temp_min(struct device *dev, const char *buf, size_t count, int nr) 598 const char *buf, size_t count)
624{ 599{
625 struct i2c_client *client = to_i2c_client(dev); 600 struct i2c_client *client = to_i2c_client(dev);
626 struct adm1031_data *data = i2c_get_clientdata(client); 601 struct adm1031_data *data = i2c_get_clientdata(client);
602 int nr = to_sensor_dev_attr(attr)->index;
627 int val; 603 int val;
628 604
629 val = simple_strtol(buf, NULL, 10); 605 val = simple_strtol(buf, NULL, 10);
@@ -635,11 +611,12 @@ set_temp_min(struct device *dev, const char *buf, size_t count, int nr)
635 mutex_unlock(&data->update_lock); 611 mutex_unlock(&data->update_lock);
636 return count; 612 return count;
637} 613}
638static ssize_t 614static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
639set_temp_max(struct device *dev, const char *buf, size_t count, int nr) 615 const char *buf, size_t count)
640{ 616{
641 struct i2c_client *client = to_i2c_client(dev); 617 struct i2c_client *client = to_i2c_client(dev);
642 struct adm1031_data *data = i2c_get_clientdata(client); 618 struct adm1031_data *data = i2c_get_clientdata(client);
619 int nr = to_sensor_dev_attr(attr)->index;
643 int val; 620 int val;
644 621
645 val = simple_strtol(buf, NULL, 10); 622 val = simple_strtol(buf, NULL, 10);
@@ -651,11 +628,12 @@ set_temp_max(struct device *dev, const char *buf, size_t count, int nr)
651 mutex_unlock(&data->update_lock); 628 mutex_unlock(&data->update_lock);
652 return count; 629 return count;
653} 630}
654static ssize_t 631static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
655set_temp_crit(struct device *dev, const char *buf, size_t count, int nr) 632 const char *buf, size_t count)
656{ 633{
657 struct i2c_client *client = to_i2c_client(dev); 634 struct i2c_client *client = to_i2c_client(dev);
658 struct adm1031_data *data = i2c_get_clientdata(client); 635 struct adm1031_data *data = i2c_get_clientdata(client);
636 int nr = to_sensor_dev_attr(attr)->index;
659 int val; 637 int val;
660 638
661 val = simple_strtol(buf, NULL, 10); 639 val = simple_strtol(buf, NULL, 10);
@@ -668,46 +646,15 @@ set_temp_crit(struct device *dev, const char *buf, size_t count, int nr)
668 return count; 646 return count;
669} 647}
670 648
671#define temp_reg(offset) \ 649#define temp_reg(offset) \
672static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 650static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
673{ \ 651 show_temp, NULL, offset - 1); \
674 return show_temp(dev, buf, offset - 1); \ 652static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
675} \ 653 show_temp_min, set_temp_min, offset - 1); \
676static ssize_t show_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 654static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
677{ \ 655 show_temp_max, set_temp_max, offset - 1); \
678 return show_temp_min(dev, buf, offset - 1); \ 656static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
679} \ 657 show_temp_crit, set_temp_crit, offset - 1)
680static ssize_t show_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
681{ \
682 return show_temp_max(dev, buf, offset - 1); \
683} \
684static ssize_t show_temp_##offset##_crit (struct device *dev, struct device_attribute *attr, char *buf) \
685{ \
686 return show_temp_crit(dev, buf, offset - 1); \
687} \
688static ssize_t set_temp_##offset##_min (struct device *dev, struct device_attribute *attr, \
689 const char *buf, size_t count) \
690{ \
691 return set_temp_min(dev, buf, count, offset - 1); \
692} \
693static ssize_t set_temp_##offset##_max (struct device *dev, struct device_attribute *attr, \
694 const char *buf, size_t count) \
695{ \
696 return set_temp_max(dev, buf, count, offset - 1); \
697} \
698static ssize_t set_temp_##offset##_crit (struct device *dev, struct device_attribute *attr, \
699 const char *buf, size_t count) \
700{ \
701 return set_temp_crit(dev, buf, count, offset - 1); \
702} \
703static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, \
704 NULL); \
705static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
706 show_temp_##offset##_min, set_temp_##offset##_min); \
707static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
708 show_temp_##offset##_max, set_temp_##offset##_max); \
709static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
710 show_temp_##offset##_crit, set_temp_##offset##_crit)
711 658
712temp_reg(1); 659temp_reg(1);
713temp_reg(2); 660temp_reg(2);
@@ -722,6 +669,29 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
722 669
723static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 670static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
724 671
672static ssize_t show_alarm(struct device *dev,
673 struct device_attribute *attr, char *buf)
674{
675 int bitnr = to_sensor_dev_attr(attr)->index;
676 struct adm1031_data *data = adm1031_update_device(dev);
677 return sprintf(buf, "%d\n", (data->alarm >> bitnr) & 1);
678}
679
680static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
681static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, show_alarm, NULL, 1);
682static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 2);
683static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
684static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 4);
685static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 5);
686static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
687static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 7);
688static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 8);
689static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, show_alarm, NULL, 9);
690static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 10);
691static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11);
692static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12);
693static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13);
694static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
725 695
726static int adm1031_attach_adapter(struct i2c_adapter *adapter) 696static int adm1031_attach_adapter(struct i2c_adapter *adapter)
727{ 697{
@@ -731,29 +701,38 @@ static int adm1031_attach_adapter(struct i2c_adapter *adapter)
731} 701}
732 702
733static struct attribute *adm1031_attributes[] = { 703static struct attribute *adm1031_attributes[] = {
734 &dev_attr_fan1_input.attr, 704 &sensor_dev_attr_fan1_input.dev_attr.attr,
735 &dev_attr_fan1_div.attr, 705 &sensor_dev_attr_fan1_div.dev_attr.attr,
736 &dev_attr_fan1_min.attr, 706 &sensor_dev_attr_fan1_min.dev_attr.attr,
737 &dev_attr_pwm1.attr, 707 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
738 &dev_attr_auto_fan1_channel.attr, 708 &sensor_dev_attr_fan1_fault.dev_attr.attr,
739 &dev_attr_temp1_input.attr, 709 &sensor_dev_attr_pwm1.dev_attr.attr,
740 &dev_attr_temp1_min.attr, 710 &sensor_dev_attr_auto_fan1_channel.dev_attr.attr,
741 &dev_attr_temp1_max.attr, 711 &sensor_dev_attr_temp1_input.dev_attr.attr,
742 &dev_attr_temp1_crit.attr, 712 &sensor_dev_attr_temp1_min.dev_attr.attr,
743 &dev_attr_temp2_input.attr, 713 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
744 &dev_attr_temp2_min.attr, 714 &sensor_dev_attr_temp1_max.dev_attr.attr,
745 &dev_attr_temp2_max.attr, 715 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
746 &dev_attr_temp2_crit.attr, 716 &sensor_dev_attr_temp1_crit.dev_attr.attr,
747 717 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
748 &dev_attr_auto_temp1_off.attr, 718 &sensor_dev_attr_temp2_input.dev_attr.attr,
749 &dev_attr_auto_temp1_min.attr, 719 &sensor_dev_attr_temp2_min.dev_attr.attr,
750 &dev_attr_auto_temp1_max.attr, 720 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
751 721 &sensor_dev_attr_temp2_max.dev_attr.attr,
752 &dev_attr_auto_temp2_off.attr, 722 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
753 &dev_attr_auto_temp2_min.attr, 723 &sensor_dev_attr_temp2_crit.dev_attr.attr,
754 &dev_attr_auto_temp2_max.attr, 724 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
755 725 &sensor_dev_attr_temp2_fault.dev_attr.attr,
756 &dev_attr_auto_fan1_min_pwm.attr, 726
727 &sensor_dev_attr_auto_temp1_off.dev_attr.attr,
728 &sensor_dev_attr_auto_temp1_min.dev_attr.attr,
729 &sensor_dev_attr_auto_temp1_max.dev_attr.attr,
730
731 &sensor_dev_attr_auto_temp2_off.dev_attr.attr,
732 &sensor_dev_attr_auto_temp2_min.dev_attr.attr,
733 &sensor_dev_attr_auto_temp2_max.dev_attr.attr,
734
735 &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr,
757 736
758 &dev_attr_alarms.attr, 737 &dev_attr_alarms.attr,
759 738
@@ -765,19 +744,25 @@ static const struct attribute_group adm1031_group = {
765}; 744};
766 745
767static struct attribute *adm1031_attributes_opt[] = { 746static struct attribute *adm1031_attributes_opt[] = {
768 &dev_attr_fan2_input.attr, 747 &sensor_dev_attr_fan2_input.dev_attr.attr,
769 &dev_attr_fan2_div.attr, 748 &sensor_dev_attr_fan2_div.dev_attr.attr,
770 &dev_attr_fan2_min.attr, 749 &sensor_dev_attr_fan2_min.dev_attr.attr,
771 &dev_attr_pwm2.attr, 750 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
772 &dev_attr_auto_fan2_channel.attr, 751 &sensor_dev_attr_fan2_fault.dev_attr.attr,
773 &dev_attr_temp3_input.attr, 752 &sensor_dev_attr_pwm2.dev_attr.attr,
774 &dev_attr_temp3_min.attr, 753 &sensor_dev_attr_auto_fan2_channel.dev_attr.attr,
775 &dev_attr_temp3_max.attr, 754 &sensor_dev_attr_temp3_input.dev_attr.attr,
776 &dev_attr_temp3_crit.attr, 755 &sensor_dev_attr_temp3_min.dev_attr.attr,
777 &dev_attr_auto_temp3_off.attr, 756 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
778 &dev_attr_auto_temp3_min.attr, 757 &sensor_dev_attr_temp3_max.dev_attr.attr,
779 &dev_attr_auto_temp3_max.attr, 758 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
780 &dev_attr_auto_fan2_min_pwm.attr, 759 &sensor_dev_attr_temp3_crit.dev_attr.attr,
760 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
761 &sensor_dev_attr_temp3_fault.dev_attr.attr,
762 &sensor_dev_attr_auto_temp3_off.dev_attr.attr,
763 &sensor_dev_attr_auto_temp3_min.dev_attr.attr,
764 &sensor_dev_attr_auto_temp3_max.dev_attr.attr,
765 &sensor_dev_attr_auto_fan2_min_pwm.dev_attr.attr,
781 NULL 766 NULL
782}; 767};
783 768
@@ -788,7 +773,7 @@ static const struct attribute_group adm1031_group_opt = {
788/* This function is called by i2c_probe */ 773/* This function is called by i2c_probe */
789static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) 774static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
790{ 775{
791 struct i2c_client *new_client; 776 struct i2c_client *client;
792 struct adm1031_data *data; 777 struct adm1031_data *data;
793 int err = 0; 778 int err = 0;
794 const char *name = ""; 779 const char *name = "";
@@ -801,17 +786,16 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
801 goto exit; 786 goto exit;
802 } 787 }
803 788
804 new_client = &data->client; 789 client = &data->client;
805 i2c_set_clientdata(new_client, data); 790 i2c_set_clientdata(client, data);
806 new_client->addr = address; 791 client->addr = address;
807 new_client->adapter = adapter; 792 client->adapter = adapter;
808 new_client->driver = &adm1031_driver; 793 client->driver = &adm1031_driver;
809 new_client->flags = 0;
810 794
811 if (kind < 0) { 795 if (kind < 0) {
812 int id, co; 796 int id, co;
813 id = i2c_smbus_read_byte_data(new_client, 0x3d); 797 id = i2c_smbus_read_byte_data(client, 0x3d);
814 co = i2c_smbus_read_byte_data(new_client, 0x3e); 798 co = i2c_smbus_read_byte_data(client, 0x3e);
815 799
816 if (!((id == 0x31 || id == 0x30) && co == 0x41)) 800 if (!((id == 0x31 || id == 0x30) && co == 0x41))
817 goto exit_free; 801 goto exit_free;
@@ -832,28 +816,27 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
832 } 816 }
833 data->chip_type = kind; 817 data->chip_type = kind;
834 818
835 strlcpy(new_client->name, name, I2C_NAME_SIZE); 819 strlcpy(client->name, name, I2C_NAME_SIZE);
836 data->valid = 0;
837 mutex_init(&data->update_lock); 820 mutex_init(&data->update_lock);
838 821
839 /* Tell the I2C layer a new client has arrived */ 822 /* Tell the I2C layer a new client has arrived */
840 if ((err = i2c_attach_client(new_client))) 823 if ((err = i2c_attach_client(client)))
841 goto exit_free; 824 goto exit_free;
842 825
843 /* Initialize the ADM1031 chip */ 826 /* Initialize the ADM1031 chip */
844 adm1031_init_client(new_client); 827 adm1031_init_client(client);
845 828
846 /* Register sysfs hooks */ 829 /* Register sysfs hooks */
847 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1031_group))) 830 if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group)))
848 goto exit_detach; 831 goto exit_detach;
849 832
850 if (kind == adm1031) { 833 if (kind == adm1031) {
851 if ((err = sysfs_create_group(&new_client->dev.kobj, 834 if ((err = sysfs_create_group(&client->dev.kobj,
852 &adm1031_group_opt))) 835 &adm1031_group_opt)))
853 goto exit_remove; 836 goto exit_remove;
854 } 837 }
855 838
856 data->hwmon_dev = hwmon_device_register(&new_client->dev); 839 data->hwmon_dev = hwmon_device_register(&client->dev);
857 if (IS_ERR(data->hwmon_dev)) { 840 if (IS_ERR(data->hwmon_dev)) {
858 err = PTR_ERR(data->hwmon_dev); 841 err = PTR_ERR(data->hwmon_dev);
859 goto exit_remove; 842 goto exit_remove;
@@ -862,10 +845,10 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
862 return 0; 845 return 0;
863 846
864exit_remove: 847exit_remove:
865 sysfs_remove_group(&new_client->dev.kobj, &adm1031_group); 848 sysfs_remove_group(&client->dev.kobj, &adm1031_group);
866 sysfs_remove_group(&new_client->dev.kobj, &adm1031_group_opt); 849 sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
867exit_detach: 850exit_detach:
868 i2c_detach_client(new_client); 851 i2c_detach_client(client);
869exit_free: 852exit_free:
870 kfree(data); 853 kfree(data);
871exit: 854exit:
@@ -897,7 +880,7 @@ static void adm1031_init_client(struct i2c_client *client)
897 if (data->chip_type == adm1031) { 880 if (data->chip_type == adm1031) {
898 mask |= (ADM1031_CONF2_PWM2_ENABLE | 881 mask |= (ADM1031_CONF2_PWM2_ENABLE |
899 ADM1031_CONF2_TACH2_ENABLE); 882 ADM1031_CONF2_TACH2_ENABLE);
900 } 883 }
901 /* Initialize the ADM1031 chip (enables fan speed reading ) */ 884 /* Initialize the ADM1031 chip (enables fan speed reading ) */
902 read_val = adm1031_read_value(client, ADM1031_REG_CONF2); 885 read_val = adm1031_read_value(client, ADM1031_REG_CONF2);
903 if ((read_val | mask) != read_val) { 886 if ((read_val | mask) != read_val) {
@@ -976,7 +959,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
976 if (data->chip_type == adm1030) { 959 if (data->chip_type == adm1030) {
977 data->alarm &= 0xc0ff; 960 data->alarm &= 0xc0ff;
978 } 961 }
979 962
980 for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) { 963 for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) {
981 data->fan_div[chan] = 964 data->fan_div[chan] =
982 adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan)); 965 adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan));
@@ -985,7 +968,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
985 data->fan[chan] = 968 data->fan[chan] =
986 adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan)); 969 adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan));
987 data->pwm[chan] = 970 data->pwm[chan] =
988 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >> 971 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >>
989 (4*chan)); 972 (4*chan));
990 } 973 }
991 data->last_updated = jiffies; 974 data->last_updated = jiffies;
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index c17d0b6b3283..7671d2bf7800 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -141,7 +141,6 @@ static struct i2c_driver adm9240_driver = {
141 .driver = { 141 .driver = {
142 .name = "adm9240", 142 .name = "adm9240",
143 }, 143 },
144 .id = I2C_DRIVERID_ADM9240,
145 .attach_adapter = adm9240_attach_adapter, 144 .attach_adapter = adm9240_attach_adapter,
146 .detach_client = adm9240_detach_client, 145 .detach_client = adm9240_detach_client,
147}; 146};
@@ -415,6 +414,23 @@ static ssize_t show_alarms(struct device *dev,
415} 414}
416static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 415static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
417 416
417static ssize_t show_alarm(struct device *dev,
418 struct device_attribute *attr, char *buf)
419{
420 int bitnr = to_sensor_dev_attr(attr)->index;
421 struct adm9240_data *data = adm9240_update_device(dev);
422 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
423}
424static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
425static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
426static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
427static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
428static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
429static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
430static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
431static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
432static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
433
418/* vid */ 434/* vid */
419static ssize_t show_vid(struct device *dev, 435static ssize_t show_vid(struct device *dev,
420 struct device_attribute *attr, char *buf) 436 struct device_attribute *attr, char *buf)
@@ -469,30 +485,39 @@ static struct attribute *adm9240_attributes[] = {
469 &sensor_dev_attr_in0_input.dev_attr.attr, 485 &sensor_dev_attr_in0_input.dev_attr.attr,
470 &sensor_dev_attr_in0_min.dev_attr.attr, 486 &sensor_dev_attr_in0_min.dev_attr.attr,
471 &sensor_dev_attr_in0_max.dev_attr.attr, 487 &sensor_dev_attr_in0_max.dev_attr.attr,
488 &sensor_dev_attr_in0_alarm.dev_attr.attr,
472 &sensor_dev_attr_in1_input.dev_attr.attr, 489 &sensor_dev_attr_in1_input.dev_attr.attr,
473 &sensor_dev_attr_in1_min.dev_attr.attr, 490 &sensor_dev_attr_in1_min.dev_attr.attr,
474 &sensor_dev_attr_in1_max.dev_attr.attr, 491 &sensor_dev_attr_in1_max.dev_attr.attr,
492 &sensor_dev_attr_in1_alarm.dev_attr.attr,
475 &sensor_dev_attr_in2_input.dev_attr.attr, 493 &sensor_dev_attr_in2_input.dev_attr.attr,
476 &sensor_dev_attr_in2_min.dev_attr.attr, 494 &sensor_dev_attr_in2_min.dev_attr.attr,
477 &sensor_dev_attr_in2_max.dev_attr.attr, 495 &sensor_dev_attr_in2_max.dev_attr.attr,
496 &sensor_dev_attr_in2_alarm.dev_attr.attr,
478 &sensor_dev_attr_in3_input.dev_attr.attr, 497 &sensor_dev_attr_in3_input.dev_attr.attr,
479 &sensor_dev_attr_in3_min.dev_attr.attr, 498 &sensor_dev_attr_in3_min.dev_attr.attr,
480 &sensor_dev_attr_in3_max.dev_attr.attr, 499 &sensor_dev_attr_in3_max.dev_attr.attr,
500 &sensor_dev_attr_in3_alarm.dev_attr.attr,
481 &sensor_dev_attr_in4_input.dev_attr.attr, 501 &sensor_dev_attr_in4_input.dev_attr.attr,
482 &sensor_dev_attr_in4_min.dev_attr.attr, 502 &sensor_dev_attr_in4_min.dev_attr.attr,
483 &sensor_dev_attr_in4_max.dev_attr.attr, 503 &sensor_dev_attr_in4_max.dev_attr.attr,
504 &sensor_dev_attr_in4_alarm.dev_attr.attr,
484 &sensor_dev_attr_in5_input.dev_attr.attr, 505 &sensor_dev_attr_in5_input.dev_attr.attr,
485 &sensor_dev_attr_in5_min.dev_attr.attr, 506 &sensor_dev_attr_in5_min.dev_attr.attr,
486 &sensor_dev_attr_in5_max.dev_attr.attr, 507 &sensor_dev_attr_in5_max.dev_attr.attr,
508 &sensor_dev_attr_in5_alarm.dev_attr.attr,
487 &dev_attr_temp1_input.attr, 509 &dev_attr_temp1_input.attr,
488 &sensor_dev_attr_temp1_max.dev_attr.attr, 510 &sensor_dev_attr_temp1_max.dev_attr.attr,
489 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, 511 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
512 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
490 &sensor_dev_attr_fan1_input.dev_attr.attr, 513 &sensor_dev_attr_fan1_input.dev_attr.attr,
491 &sensor_dev_attr_fan1_div.dev_attr.attr, 514 &sensor_dev_attr_fan1_div.dev_attr.attr,
492 &sensor_dev_attr_fan1_min.dev_attr.attr, 515 &sensor_dev_attr_fan1_min.dev_attr.attr,
516 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
493 &sensor_dev_attr_fan2_input.dev_attr.attr, 517 &sensor_dev_attr_fan2_input.dev_attr.attr,
494 &sensor_dev_attr_fan2_div.dev_attr.attr, 518 &sensor_dev_attr_fan2_div.dev_attr.attr,
495 &sensor_dev_attr_fan2_min.dev_attr.attr, 519 &sensor_dev_attr_fan2_min.dev_attr.attr,
520 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
496 &dev_attr_alarms.attr, 521 &dev_attr_alarms.attr,
497 &dev_attr_aout_output.attr, 522 &dev_attr_aout_output.attr,
498 &dev_attr_chassis_clear.attr, 523 &dev_attr_chassis_clear.attr,
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
new file mode 100644
index 000000000000..6b8a73ef404c
--- /dev/null
+++ b/drivers/hwmon/ads7828.c
@@ -0,0 +1,297 @@
1/*
2 ads7828.c - lm_sensors driver for ads7828 12-bit 8-channel ADC
3 (C) 2007 EADS Astrium
4
5 This driver is based on the lm75 and other lm_sensors/hwmon drivers
6
7 Written by Steve Hardy <steve@linuxrealtime.co.uk>
8
9 Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads7828.pdf
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/
25
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/jiffies.h>
30#include <linux/i2c.h>
31#include <linux/hwmon.h>
32#include <linux/hwmon-sysfs.h>
33#include <linux/err.h>
34#include <linux/mutex.h>
35
36/* The ADS7828 registers */
37#define ADS7828_NCH 8 /* 8 channels of 12-bit A-D supported */
38#define ADS7828_CMD_SD_SE 0x80 /* Single ended inputs */
39#define ADS7828_CMD_SD_DIFF 0x00 /* Differential inputs */
40#define ADS7828_CMD_PD0 0x0 /* Power Down between A-D conversions */
41#define ADS7828_CMD_PD1 0x04 /* Internal ref OFF && A-D ON */
42#define ADS7828_CMD_PD2 0x08 /* Internal ref ON && A-D OFF */
43#define ADS7828_CMD_PD3 0x0C /* Internal ref ON && A-D ON */
44#define ADS7828_INT_VREF_MV 2500 /* Internal vref is 2.5V, 2500mV */
45
46/* Addresses to scan */
47static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
48 I2C_CLIENT_END };
49
50/* Insmod parameters */
51I2C_CLIENT_INSMOD_1(ads7828);
52
53/* Other module parameters */
54static int se_input = 1; /* Default is SE, 0 == diff */
55static int int_vref = 1; /* Default is internal ref ON */
56static int vref_mv = ADS7828_INT_VREF_MV; /* set if vref != 2.5V */
57module_param(se_input, bool, S_IRUGO);
58module_param(int_vref, bool, S_IRUGO);
59module_param(vref_mv, int, S_IRUGO);
60
61/* Global Variables */
62static u8 ads7828_cmd_byte; /* cmd byte without channel bits */
63static unsigned int ads7828_lsb_resol; /* resolution of the ADC sample lsb */
64
65/* Each client has this additional data */
66struct ads7828_data {
67 struct i2c_client client;
68 struct device *hwmon_dev;
69 struct mutex update_lock; /* mutex protect updates */
70 char valid; /* !=0 if following fields are valid */
71 unsigned long last_updated; /* In jiffies */
72 u16 adc_input[ADS7828_NCH]; /* ADS7828_NCH 12-bit samples */
73};
74
75/* Function declaration - necessary due to function dependencies */
76static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind);
77
78/* The ADS7828 returns the 12-bit sample in two bytes,
79 these are read as a word then byte-swapped */
80static u16 ads7828_read_value(struct i2c_client *client, u8 reg)
81{
82 return swab16(i2c_smbus_read_word_data(client, reg));
83}
84
85static inline u8 channel_cmd_byte(int ch)
86{
87 /* cmd byte C2,C1,C0 - see datasheet */
88 u8 cmd = (((ch>>1) | (ch&0x01)<<2)<<4);
89 cmd |= ads7828_cmd_byte;
90 return cmd;
91}
92
93/* Update data for the device (all 8 channels) */
94static struct ads7828_data *ads7828_update_device(struct device *dev)
95{
96 struct i2c_client *client = to_i2c_client(dev);
97 struct ads7828_data *data = i2c_get_clientdata(client);
98
99 mutex_lock(&data->update_lock);
100
101 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
102 || !data->valid) {
103 unsigned int ch;
104 dev_dbg(&client->dev, "Starting ads7828 update\n");
105
106 for (ch = 0; ch < ADS7828_NCH; ch++) {
107 u8 cmd = channel_cmd_byte(ch);
108 data->adc_input[ch] = ads7828_read_value(client, cmd);
109 }
110 data->last_updated = jiffies;
111 data->valid = 1;
112 }
113
114 mutex_unlock(&data->update_lock);
115
116 return data;
117}
118
119/* sysfs callback function */
120static ssize_t show_in(struct device *dev, struct device_attribute *da,
121 char *buf)
122{
123 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
124 struct ads7828_data *data = ads7828_update_device(dev);
125 /* Print value (in mV as specified in sysfs-interface documentation) */
126 return sprintf(buf, "%d\n", (data->adc_input[attr->index] *
127 ads7828_lsb_resol)/1000);
128}
129
130#define in_reg(offset)\
131static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in,\
132 NULL, offset)
133
134in_reg(0);
135in_reg(1);
136in_reg(2);
137in_reg(3);
138in_reg(4);
139in_reg(5);
140in_reg(6);
141in_reg(7);
142
143static struct attribute *ads7828_attributes[] = {
144 &sensor_dev_attr_in0_input.dev_attr.attr,
145 &sensor_dev_attr_in1_input.dev_attr.attr,
146 &sensor_dev_attr_in2_input.dev_attr.attr,
147 &sensor_dev_attr_in3_input.dev_attr.attr,
148 &sensor_dev_attr_in4_input.dev_attr.attr,
149 &sensor_dev_attr_in5_input.dev_attr.attr,
150 &sensor_dev_attr_in6_input.dev_attr.attr,
151 &sensor_dev_attr_in7_input.dev_attr.attr,
152 NULL
153};
154
155static const struct attribute_group ads7828_group = {
156 .attrs = ads7828_attributes,
157};
158
159static int ads7828_attach_adapter(struct i2c_adapter *adapter)
160{
161 if (!(adapter->class & I2C_CLASS_HWMON))
162 return 0;
163 return i2c_probe(adapter, &addr_data, ads7828_detect);
164}
165
166static int ads7828_detach_client(struct i2c_client *client)
167{
168 struct ads7828_data *data = i2c_get_clientdata(client);
169 hwmon_device_unregister(data->hwmon_dev);
170 sysfs_remove_group(&client->dev.kobj, &ads7828_group);
171 i2c_detach_client(client);
172 kfree(i2c_get_clientdata(client));
173 return 0;
174}
175
176/* This is the driver that will be inserted */
177static struct i2c_driver ads7828_driver = {
178 .driver = {
179 .name = "ads7828",
180 },
181 .attach_adapter = ads7828_attach_adapter,
182 .detach_client = ads7828_detach_client,
183};
184
185/* This function is called by i2c_probe */
186static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind)
187{
188 struct i2c_client *client;
189 struct ads7828_data *data;
190 int err = 0;
191 const char *name = "";
192
193 /* Check we have a valid client */
194 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA))
195 goto exit;
196
197 /* OK. For now, we presume we have a valid client. We now create the
198 client structure, even though we cannot fill it completely yet.
199 But it allows us to access ads7828_read_value. */
200 data = kzalloc(sizeof(struct ads7828_data), GFP_KERNEL);
201 if (!data) {
202 err = -ENOMEM;
203 goto exit;
204 }
205
206 client = &data->client;
207 i2c_set_clientdata(client, data);
208 client->addr = address;
209 client->adapter = adapter;
210 client->driver = &ads7828_driver;
211
212 /* Now, we do the remaining detection. There is no identification
213 dedicated register so attempt to sanity check using knowledge of
214 the chip
215 - Read from the 8 channel addresses
216 - Check the top 4 bits of each result are not set (12 data bits)
217 */
218 if (kind < 0) {
219 int ch;
220 for (ch = 0; ch < ADS7828_NCH; ch++) {
221 u16 in_data;
222 u8 cmd = channel_cmd_byte(ch);
223 in_data = ads7828_read_value(client, cmd);
224 if (in_data & 0xF000) {
225 printk(KERN_DEBUG
226 "%s : Doesn't look like an ads7828 device\n",
227 __FUNCTION__);
228 goto exit_free;
229 }
230 }
231 }
232
233 /* Determine the chip type - only one kind supported! */
234 if (kind <= 0)
235 kind = ads7828;
236
237 if (kind == ads7828)
238 name = "ads7828";
239
240 /* Fill in the remaining client fields, put it into the global list */
241 strlcpy(client->name, name, I2C_NAME_SIZE);
242
243 mutex_init(&data->update_lock);
244
245 /* Tell the I2C layer a new client has arrived */
246 err = i2c_attach_client(client);
247 if (err)
248 goto exit_free;
249
250 /* Register sysfs hooks */
251 err = sysfs_create_group(&client->dev.kobj, &ads7828_group);
252 if (err)
253 goto exit_detach;
254
255 data->hwmon_dev = hwmon_device_register(&client->dev);
256 if (IS_ERR(data->hwmon_dev)) {
257 err = PTR_ERR(data->hwmon_dev);
258 goto exit_remove;
259 }
260
261 return 0;
262
263exit_remove:
264 sysfs_remove_group(&client->dev.kobj, &ads7828_group);
265exit_detach:
266 i2c_detach_client(client);
267exit_free:
268 kfree(data);
269exit:
270 return err;
271}
272
273static int __init sensors_ads7828_init(void)
274{
275 /* Initialize the command byte according to module parameters */
276 ads7828_cmd_byte = se_input ?
277 ADS7828_CMD_SD_SE : ADS7828_CMD_SD_DIFF;
278 ads7828_cmd_byte |= int_vref ?
279 ADS7828_CMD_PD3 : ADS7828_CMD_PD1;
280
281 /* Calculate the LSB resolution */
282 ads7828_lsb_resol = (vref_mv*1000)/4096;
283
284 return i2c_add_driver(&ads7828_driver);
285}
286
287static void __exit sensors_ads7828_exit(void)
288{
289 i2c_del_driver(&ads7828_driver);
290}
291
292MODULE_AUTHOR("Steve Hardy <steve@linuxrealtime.co.uk>");
293MODULE_DESCRIPTION("ADS7828 driver");
294MODULE_LICENSE("GPL");
295
296module_init(sensors_ads7828_init);
297module_exit(sensors_ads7828_exit);
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 9810aaa0489d..747693ab2ff1 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -48,7 +48,22 @@ I2C_CLIENT_INSMOD_1(adt7470);
48#define ADT7470_REG_CFG 0x40 48#define ADT7470_REG_CFG 0x40
49#define ADT7470_FSPD_MASK 0x04 49#define ADT7470_FSPD_MASK 0x04
50#define ADT7470_REG_ALARM1 0x41 50#define ADT7470_REG_ALARM1 0x41
51#define ADT7470_R1T_ALARM 0x01
52#define ADT7470_R2T_ALARM 0x02
53#define ADT7470_R3T_ALARM 0x04
54#define ADT7470_R4T_ALARM 0x08
55#define ADT7470_R5T_ALARM 0x10
56#define ADT7470_R6T_ALARM 0x20
57#define ADT7470_R7T_ALARM 0x40
58#define ADT7470_OOL_ALARM 0x80
51#define ADT7470_REG_ALARM2 0x42 59#define ADT7470_REG_ALARM2 0x42
60#define ADT7470_R8T_ALARM 0x01
61#define ADT7470_R9T_ALARM 0x02
62#define ADT7470_R10T_ALARM 0x04
63#define ADT7470_FAN1_ALARM 0x10
64#define ADT7470_FAN2_ALARM 0x20
65#define ADT7470_FAN3_ALARM 0x40
66#define ADT7470_FAN4_ALARM 0x80
52#define ADT7470_REG_TEMP_LIMITS_BASE_ADDR 0x44 67#define ADT7470_REG_TEMP_LIMITS_BASE_ADDR 0x44
53#define ADT7470_REG_TEMP_LIMITS_MAX_ADDR 0x57 68#define ADT7470_REG_TEMP_LIMITS_MAX_ADDR 0x57
54#define ADT7470_REG_FAN_MIN_BASE_ADDR 0x58 69#define ADT7470_REG_FAN_MIN_BASE_ADDR 0x58
@@ -97,6 +112,8 @@ I2C_CLIENT_INSMOD_1(adt7470);
97#define ADT7470_REG_PWM_AUTO_TEMP(x) (ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \ 112#define ADT7470_REG_PWM_AUTO_TEMP(x) (ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \
98 ((x) / 2)) 113 ((x) / 2))
99 114
115#define ALARM2(x) ((x) << 8)
116
100#define ADT7470_VENDOR 0x41 117#define ADT7470_VENDOR 0x41
101#define ADT7470_DEVICE 0x70 118#define ADT7470_DEVICE 0x70
102/* datasheet only mentions a revision 2 */ 119/* datasheet only mentions a revision 2 */
@@ -114,8 +131,6 @@ I2C_CLIENT_INSMOD_1(adt7470);
114/* sleep 1s while gathering temperature data */ 131/* sleep 1s while gathering temperature data */
115#define TEMP_COLLECTION_TIME 1000 132#define TEMP_COLLECTION_TIME 1000
116 133
117#define power_of_2(x) (((x) & ((x) - 1)) == 0)
118
119/* datasheet says to divide this number by the fan reading to get fan rpm */ 134/* datasheet says to divide this number by the fan reading to get fan rpm */
120#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) 135#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
121#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM 136#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
@@ -138,7 +153,8 @@ struct adt7470_data {
138 u16 fan[ADT7470_FAN_COUNT]; 153 u16 fan[ADT7470_FAN_COUNT];
139 u16 fan_min[ADT7470_FAN_COUNT]; 154 u16 fan_min[ADT7470_FAN_COUNT];
140 u16 fan_max[ADT7470_FAN_COUNT]; 155 u16 fan_max[ADT7470_FAN_COUNT];
141 u16 alarms, alarms_mask; 156 u16 alarm;
157 u16 alarms_mask;
142 u8 force_pwm_max; 158 u8 force_pwm_max;
143 u8 pwm[ADT7470_PWM_COUNT]; 159 u8 pwm[ADT7470_PWM_COUNT];
144 u8 pwm_max[ADT7470_PWM_COUNT]; 160 u8 pwm_max[ADT7470_PWM_COUNT];
@@ -262,7 +278,10 @@ static struct adt7470_data *adt7470_update_device(struct device *dev)
262 else 278 else
263 data->force_pwm_max = 0; 279 data->force_pwm_max = 0;
264 280
265 data->alarms = adt7470_read_word_data(client, ADT7470_REG_ALARM1); 281 data->alarm = i2c_smbus_read_byte_data(client, ADT7470_REG_ALARM1);
282 if (data->alarm & ADT7470_OOL_ALARM)
283 data->alarm |= ALARM2(i2c_smbus_read_byte_data(client,
284 ADT7470_REG_ALARM2));
266 data->alarms_mask = adt7470_read_word_data(client, 285 data->alarms_mask = adt7470_read_word_data(client,
267 ADT7470_REG_ALARM1_MASK); 286 ADT7470_REG_ALARM1_MASK);
268 287
@@ -370,17 +389,13 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
370 return sprintf(buf, "%d\n", 1000 * data->temp[attr->index]); 389 return sprintf(buf, "%d\n", 1000 * data->temp[attr->index]);
371} 390}
372 391
373static ssize_t show_alarms(struct device *dev, 392static ssize_t show_alarm_mask(struct device *dev,
374 struct device_attribute *devattr, 393 struct device_attribute *devattr,
375 char *buf) 394 char *buf)
376{ 395{
377 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
378 struct adt7470_data *data = adt7470_update_device(dev); 396 struct adt7470_data *data = adt7470_update_device(dev);
379 397
380 if (attr->index) 398 return sprintf(buf, "%x\n", data->alarms_mask);
381 return sprintf(buf, "%x\n", data->alarms);
382 else
383 return sprintf(buf, "%x\n", data->alarms_mask);
384} 399}
385 400
386static ssize_t show_fan_max(struct device *dev, 401static ssize_t show_fan_max(struct device *dev,
@@ -677,7 +692,7 @@ static int cvt_auto_temp(int input)
677{ 692{
678 if (input == ADT7470_PWM_ALL_TEMPS) 693 if (input == ADT7470_PWM_ALL_TEMPS)
679 return 0; 694 return 0;
680 if (input < 1 || !power_of_2(input)) 695 if (input < 1 || !is_power_of_2(input))
681 return -EINVAL; 696 return -EINVAL;
682 return ilog2(input) + 1; 697 return ilog2(input) + 1;
683} 698}
@@ -715,8 +730,20 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
715 return count; 730 return count;
716} 731}
717 732
718static SENSOR_DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL, 0); 733static ssize_t show_alarm(struct device *dev,
719static SENSOR_DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarms, NULL, 1); 734 struct device_attribute *devattr,
735 char *buf)
736{
737 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
738 struct adt7470_data *data = adt7470_update_device(dev);
739
740 if (data->alarm & attr->index)
741 return sprintf(buf, "1\n");
742 else
743 return sprintf(buf, "0\n");
744}
745
746static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
720 747
721static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 748static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
722 set_temp_max, 0); 749 set_temp_max, 0);
@@ -771,6 +798,27 @@ static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7);
771static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8); 798static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8);
772static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp, NULL, 9); 799static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp, NULL, 9);
773 800
801static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
802 ADT7470_R1T_ALARM);
803static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
804 ADT7470_R2T_ALARM);
805static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
806 ADT7470_R3T_ALARM);
807static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
808 ADT7470_R4T_ALARM);
809static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL,
810 ADT7470_R5T_ALARM);
811static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL,
812 ADT7470_R6T_ALARM);
813static SENSOR_DEVICE_ATTR(temp7_alarm, S_IRUGO, show_alarm, NULL,
814 ADT7470_R7T_ALARM);
815static SENSOR_DEVICE_ATTR(temp8_alarm, S_IRUGO, show_alarm, NULL,
816 ALARM2(ADT7470_R8T_ALARM));
817static SENSOR_DEVICE_ATTR(temp9_alarm, S_IRUGO, show_alarm, NULL,
818 ALARM2(ADT7470_R9T_ALARM));
819static SENSOR_DEVICE_ATTR(temp10_alarm, S_IRUGO, show_alarm, NULL,
820 ALARM2(ADT7470_R10T_ALARM));
821
774static SENSOR_DEVICE_ATTR(fan1_max, S_IWUSR | S_IRUGO, show_fan_max, 822static SENSOR_DEVICE_ATTR(fan1_max, S_IWUSR | S_IRUGO, show_fan_max,
775 set_fan_max, 0); 823 set_fan_max, 0);
776static SENSOR_DEVICE_ATTR(fan2_max, S_IWUSR | S_IRUGO, show_fan_max, 824static SENSOR_DEVICE_ATTR(fan2_max, S_IWUSR | S_IRUGO, show_fan_max,
@@ -794,6 +842,15 @@ static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
794static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); 842static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
795static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); 843static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
796 844
845static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
846 ALARM2(ADT7470_FAN1_ALARM));
847static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
848 ALARM2(ADT7470_FAN2_ALARM));
849static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
850 ALARM2(ADT7470_FAN3_ALARM));
851static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
852 ALARM2(ADT7470_FAN4_ALARM));
853
797static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO, 854static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO,
798 show_force_pwm_max, set_force_pwm_max, 0); 855 show_force_pwm_max, set_force_pwm_max, 0);
799 856
@@ -858,8 +915,7 @@ static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
858 915
859static struct attribute *adt7470_attr[] = 916static struct attribute *adt7470_attr[] =
860{ 917{
861 &sensor_dev_attr_alarms.dev_attr.attr, 918 &dev_attr_alarm_mask.attr,
862 &sensor_dev_attr_alarm_mask.dev_attr.attr,
863 &sensor_dev_attr_temp1_max.dev_attr.attr, 919 &sensor_dev_attr_temp1_max.dev_attr.attr,
864 &sensor_dev_attr_temp2_max.dev_attr.attr, 920 &sensor_dev_attr_temp2_max.dev_attr.attr,
865 &sensor_dev_attr_temp3_max.dev_attr.attr, 921 &sensor_dev_attr_temp3_max.dev_attr.attr,
@@ -890,6 +946,16 @@ static struct attribute *adt7470_attr[] =
890 &sensor_dev_attr_temp8_input.dev_attr.attr, 946 &sensor_dev_attr_temp8_input.dev_attr.attr,
891 &sensor_dev_attr_temp9_input.dev_attr.attr, 947 &sensor_dev_attr_temp9_input.dev_attr.attr,
892 &sensor_dev_attr_temp10_input.dev_attr.attr, 948 &sensor_dev_attr_temp10_input.dev_attr.attr,
949 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
950 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
951 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
952 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
953 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
954 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
955 &sensor_dev_attr_temp7_alarm.dev_attr.attr,
956 &sensor_dev_attr_temp8_alarm.dev_attr.attr,
957 &sensor_dev_attr_temp9_alarm.dev_attr.attr,
958 &sensor_dev_attr_temp10_alarm.dev_attr.attr,
893 &sensor_dev_attr_fan1_max.dev_attr.attr, 959 &sensor_dev_attr_fan1_max.dev_attr.attr,
894 &sensor_dev_attr_fan2_max.dev_attr.attr, 960 &sensor_dev_attr_fan2_max.dev_attr.attr,
895 &sensor_dev_attr_fan3_max.dev_attr.attr, 961 &sensor_dev_attr_fan3_max.dev_attr.attr,
@@ -902,6 +968,10 @@ static struct attribute *adt7470_attr[] =
902 &sensor_dev_attr_fan2_input.dev_attr.attr, 968 &sensor_dev_attr_fan2_input.dev_attr.attr,
903 &sensor_dev_attr_fan3_input.dev_attr.attr, 969 &sensor_dev_attr_fan3_input.dev_attr.attr,
904 &sensor_dev_attr_fan4_input.dev_attr.attr, 970 &sensor_dev_attr_fan4_input.dev_attr.attr,
971 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
972 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
973 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
974 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
905 &sensor_dev_attr_force_pwm_max.dev_attr.attr, 975 &sensor_dev_attr_force_pwm_max.dev_attr.attr,
906 &sensor_dev_attr_pwm1.dev_attr.attr, 976 &sensor_dev_attr_pwm1.dev_attr.attr,
907 &sensor_dev_attr_pwm2.dev_attr.attr, 977 &sensor_dev_attr_pwm2.dev_attr.attr,
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index 9460dba4cf74..950cea8d1d65 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -40,6 +40,7 @@
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/i2c.h> 41#include <linux/i2c.h>
42#include <linux/hwmon.h> 42#include <linux/hwmon.h>
43#include <linux/hwmon-sysfs.h>
43#include <linux/hwmon-vid.h> 44#include <linux/hwmon-vid.h>
44#include <linux/err.h> 45#include <linux/err.h>
45#include <linux/init.h> 46#include <linux/init.h>
@@ -47,12 +48,6 @@
47#include <linux/mutex.h> 48#include <linux/mutex.h>
48#include "lm75.h" 49#include "lm75.h"
49 50
50/*
51 HISTORY:
52 2003-12-29 1.0.0 Ported from lm_sensors project for kernel 2.6
53*/
54#define ASB100_VERSION "1.0.0"
55
56/* I2C addresses to scan */ 51/* I2C addresses to scan */
57static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END }; 52static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
58 53
@@ -221,15 +216,16 @@ static struct i2c_driver asb100_driver = {
221 .driver = { 216 .driver = {
222 .name = "asb100", 217 .name = "asb100",
223 }, 218 },
224 .id = I2C_DRIVERID_ASB100,
225 .attach_adapter = asb100_attach_adapter, 219 .attach_adapter = asb100_attach_adapter,
226 .detach_client = asb100_detach_client, 220 .detach_client = asb100_detach_client,
227}; 221};
228 222
229/* 7 Voltages */ 223/* 7 Voltages */
230#define show_in_reg(reg) \ 224#define show_in_reg(reg) \
231static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 225static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
226 char *buf) \
232{ \ 227{ \
228 int nr = to_sensor_dev_attr(attr)->index; \
233 struct asb100_data *data = asb100_update_device(dev); \ 229 struct asb100_data *data = asb100_update_device(dev); \
234 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \ 230 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
235} 231}
@@ -239,9 +235,10 @@ show_in_reg(in_min)
239show_in_reg(in_max) 235show_in_reg(in_max)
240 236
241#define set_in_reg(REG, reg) \ 237#define set_in_reg(REG, reg) \
242static ssize_t set_in_##reg(struct device *dev, const char *buf, \ 238static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \
243 size_t count, int nr) \ 239 const char *buf, size_t count) \
244{ \ 240{ \
241 int nr = to_sensor_dev_attr(attr)->index; \
245 struct i2c_client *client = to_i2c_client(dev); \ 242 struct i2c_client *client = to_i2c_client(dev); \
246 struct asb100_data *data = i2c_get_clientdata(client); \ 243 struct asb100_data *data = i2c_get_clientdata(client); \
247 unsigned long val = simple_strtoul(buf, NULL, 10); \ 244 unsigned long val = simple_strtoul(buf, NULL, 10); \
@@ -258,37 +255,12 @@ set_in_reg(MIN, min)
258set_in_reg(MAX, max) 255set_in_reg(MAX, max)
259 256
260#define sysfs_in(offset) \ 257#define sysfs_in(offset) \
261static ssize_t \ 258static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
262 show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 259 show_in, NULL, offset); \
263{ \ 260static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
264 return show_in(dev, buf, offset); \ 261 show_in_min, set_in_min, offset); \
265} \ 262static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
266static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 263 show_in_max, set_in_max, offset)
267 show_in##offset, NULL); \
268static ssize_t \
269 show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
270{ \
271 return show_in_min(dev, buf, offset); \
272} \
273static ssize_t \
274 show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
275{ \
276 return show_in_max(dev, buf, offset); \
277} \
278static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \
279 const char *buf, size_t count) \
280{ \
281 return set_in_min(dev, buf, count, offset); \
282} \
283static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \
284 const char *buf, size_t count) \
285{ \
286 return set_in_max(dev, buf, count, offset); \
287} \
288static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
289 show_in##offset##_min, set_in##offset##_min); \
290static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
291 show_in##offset##_max, set_in##offset##_max);
292 264
293sysfs_in(0); 265sysfs_in(0);
294sysfs_in(1); 266sysfs_in(1);
@@ -299,29 +271,36 @@ sysfs_in(5);
299sysfs_in(6); 271sysfs_in(6);
300 272
301/* 3 Fans */ 273/* 3 Fans */
302static ssize_t show_fan(struct device *dev, char *buf, int nr) 274static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
275 char *buf)
303{ 276{
277 int nr = to_sensor_dev_attr(attr)->index;
304 struct asb100_data *data = asb100_update_device(dev); 278 struct asb100_data *data = asb100_update_device(dev);
305 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 279 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
306 DIV_FROM_REG(data->fan_div[nr]))); 280 DIV_FROM_REG(data->fan_div[nr])));
307} 281}
308 282
309static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 283static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
284 char *buf)
310{ 285{
286 int nr = to_sensor_dev_attr(attr)->index;
311 struct asb100_data *data = asb100_update_device(dev); 287 struct asb100_data *data = asb100_update_device(dev);
312 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], 288 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
313 DIV_FROM_REG(data->fan_div[nr]))); 289 DIV_FROM_REG(data->fan_div[nr])));
314} 290}
315 291
316static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 292static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
293 char *buf)
317{ 294{
295 int nr = to_sensor_dev_attr(attr)->index;
318 struct asb100_data *data = asb100_update_device(dev); 296 struct asb100_data *data = asb100_update_device(dev);
319 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 297 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
320} 298}
321 299
322static ssize_t set_fan_min(struct device *dev, const char *buf, 300static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
323 size_t count, int nr) 301 const char *buf, size_t count)
324{ 302{
303 int nr = to_sensor_dev_attr(attr)->index;
325 struct i2c_client *client = to_i2c_client(dev); 304 struct i2c_client *client = to_i2c_client(dev);
326 struct asb100_data *data = i2c_get_clientdata(client); 305 struct asb100_data *data = i2c_get_clientdata(client);
327 u32 val = simple_strtoul(buf, NULL, 10); 306 u32 val = simple_strtoul(buf, NULL, 10);
@@ -337,22 +316,23 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
337 determined in part by the fan divisor. This follows the principle of 316 determined in part by the fan divisor. This follows the principle of
338 least surprise; the user doesn't expect the fan minimum to change just 317 least surprise; the user doesn't expect the fan minimum to change just
339 because the divisor changed. */ 318 because the divisor changed. */
340static ssize_t set_fan_div(struct device *dev, const char *buf, 319static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
341 size_t count, int nr) 320 const char *buf, size_t count)
342{ 321{
322 int nr = to_sensor_dev_attr(attr)->index;
343 struct i2c_client *client = to_i2c_client(dev); 323 struct i2c_client *client = to_i2c_client(dev);
344 struct asb100_data *data = i2c_get_clientdata(client); 324 struct asb100_data *data = i2c_get_clientdata(client);
345 unsigned long min; 325 unsigned long min;
346 unsigned long val = simple_strtoul(buf, NULL, 10); 326 unsigned long val = simple_strtoul(buf, NULL, 10);
347 int reg; 327 int reg;
348 328
349 mutex_lock(&data->update_lock); 329 mutex_lock(&data->update_lock);
350 330
351 min = FAN_FROM_REG(data->fan_min[nr], 331 min = FAN_FROM_REG(data->fan_min[nr],
352 DIV_FROM_REG(data->fan_div[nr])); 332 DIV_FROM_REG(data->fan_div[nr]));
353 data->fan_div[nr] = DIV_TO_REG(val); 333 data->fan_div[nr] = DIV_TO_REG(val);
354 334
355 switch(nr) { 335 switch (nr) {
356 case 0: /* fan 1 */ 336 case 0: /* fan 1 */
357 reg = asb100_read_value(client, ASB100_REG_VID_FANDIV); 337 reg = asb100_read_value(client, ASB100_REG_VID_FANDIV);
358 reg = (reg & 0xcf) | (data->fan_div[0] << 4); 338 reg = (reg & 0xcf) | (data->fan_div[0] << 4);
@@ -382,34 +362,12 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
382} 362}
383 363
384#define sysfs_fan(offset) \ 364#define sysfs_fan(offset) \
385static ssize_t show_fan##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 365static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
386{ \ 366 show_fan, NULL, offset - 1); \
387 return show_fan(dev, buf, offset - 1); \ 367static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
388} \ 368 show_fan_min, set_fan_min, offset - 1); \
389static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 369static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
390{ \ 370 show_fan_div, set_fan_div, offset - 1)
391 return show_fan_min(dev, buf, offset - 1); \
392} \
393static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \
394{ \
395 return show_fan_div(dev, buf, offset - 1); \
396} \
397static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
398 size_t count) \
399{ \
400 return set_fan_min(dev, buf, count, offset - 1); \
401} \
402static ssize_t set_fan##offset##_div(struct device *dev, struct device_attribute *attr, const char *buf, \
403 size_t count) \
404{ \
405 return set_fan_div(dev, buf, count, offset - 1); \
406} \
407static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
408 show_fan##offset, NULL); \
409static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
410 show_fan##offset##_min, set_fan##offset##_min); \
411static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
412 show_fan##offset##_div, set_fan##offset##_div);
413 371
414sysfs_fan(1); 372sysfs_fan(1);
415sysfs_fan(2); 373sysfs_fan(2);
@@ -430,10 +388,12 @@ static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
430 } 388 }
431 return ret; 389 return ret;
432} 390}
433 391
434#define show_temp_reg(reg) \ 392#define show_temp_reg(reg) \
435static ssize_t show_##reg(struct device *dev, char *buf, int nr) \ 393static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
394 char *buf) \
436{ \ 395{ \
396 int nr = to_sensor_dev_attr(attr)->index; \
437 struct asb100_data *data = asb100_update_device(dev); \ 397 struct asb100_data *data = asb100_update_device(dev); \
438 return sprintf_temp_from_reg(data->reg[nr], buf, nr); \ 398 return sprintf_temp_from_reg(data->reg[nr], buf, nr); \
439} 399}
@@ -443,9 +403,10 @@ show_temp_reg(temp_max);
443show_temp_reg(temp_hyst); 403show_temp_reg(temp_hyst);
444 404
445#define set_temp_reg(REG, reg) \ 405#define set_temp_reg(REG, reg) \
446static ssize_t set_##reg(struct device *dev, const char *buf, \ 406static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \
447 size_t count, int nr) \ 407 const char *buf, size_t count) \
448{ \ 408{ \
409 int nr = to_sensor_dev_attr(attr)->index; \
449 struct i2c_client *client = to_i2c_client(dev); \ 410 struct i2c_client *client = to_i2c_client(dev); \
450 struct asb100_data *data = i2c_get_clientdata(client); \ 411 struct asb100_data *data = i2c_get_clientdata(client); \
451 long val = simple_strtol(buf, NULL, 10); \ 412 long val = simple_strtol(buf, NULL, 10); \
@@ -469,33 +430,12 @@ set_temp_reg(MAX, temp_max);
469set_temp_reg(HYST, temp_hyst); 430set_temp_reg(HYST, temp_hyst);
470 431
471#define sysfs_temp(num) \ 432#define sysfs_temp(num) \
472static ssize_t show_temp##num(struct device *dev, struct device_attribute *attr, char *buf) \ 433static SENSOR_DEVICE_ATTR(temp##num##_input, S_IRUGO, \
473{ \ 434 show_temp, NULL, num - 1); \
474 return show_temp(dev, buf, num-1); \ 435static SENSOR_DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \
475} \ 436 show_temp_max, set_temp_max, num - 1); \
476static DEVICE_ATTR(temp##num##_input, S_IRUGO, show_temp##num, NULL); \ 437static SENSOR_DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \
477static ssize_t show_temp_max##num(struct device *dev, struct device_attribute *attr, char *buf) \ 438 show_temp_hyst, set_temp_hyst, num - 1)
478{ \
479 return show_temp_max(dev, buf, num-1); \
480} \
481static ssize_t set_temp_max##num(struct device *dev, struct device_attribute *attr, const char *buf, \
482 size_t count) \
483{ \
484 return set_temp_max(dev, buf, count, num-1); \
485} \
486static DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \
487 show_temp_max##num, set_temp_max##num); \
488static ssize_t show_temp_hyst##num(struct device *dev, struct device_attribute *attr, char *buf) \
489{ \
490 return show_temp_hyst(dev, buf, num-1); \
491} \
492static ssize_t set_temp_hyst##num(struct device *dev, struct device_attribute *attr, const char *buf, \
493 size_t count) \
494{ \
495 return set_temp_hyst(dev, buf, count, num-1); \
496} \
497static DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \
498 show_temp_hyst##num, set_temp_hyst##num);
499 439
500sysfs_temp(1); 440sysfs_temp(1);
501sysfs_temp(2); 441sysfs_temp(2);
@@ -503,7 +443,8 @@ sysfs_temp(3);
503sysfs_temp(4); 443sysfs_temp(4);
504 444
505/* VID */ 445/* VID */
506static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 446static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
447 char *buf)
507{ 448{
508 struct asb100_data *data = asb100_update_device(dev); 449 struct asb100_data *data = asb100_update_device(dev);
509 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 450 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
@@ -512,25 +453,26 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
512static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 453static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
513 454
514/* VRM */ 455/* VRM */
515static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 456static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
457 char *buf)
516{ 458{
517 struct asb100_data *data = dev_get_drvdata(dev); 459 struct asb100_data *data = dev_get_drvdata(dev);
518 return sprintf(buf, "%d\n", data->vrm); 460 return sprintf(buf, "%d\n", data->vrm);
519} 461}
520 462
521static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 463static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
464 const char *buf, size_t count)
522{ 465{
523 struct i2c_client *client = to_i2c_client(dev); 466 struct asb100_data *data = dev_get_drvdata(dev);
524 struct asb100_data *data = i2c_get_clientdata(client); 467 data->vrm = simple_strtoul(buf, NULL, 10);
525 unsigned long val = simple_strtoul(buf, NULL, 10);
526 data->vrm = val;
527 return count; 468 return count;
528} 469}
529 470
530/* Alarms */ 471/* Alarms */
531static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 472static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
532 473
533static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 474static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
475 char *buf)
534{ 476{
535 struct asb100_data *data = asb100_update_device(dev); 477 struct asb100_data *data = asb100_update_device(dev);
536 return sprintf(buf, "%u\n", data->alarms); 478 return sprintf(buf, "%u\n", data->alarms);
@@ -538,14 +480,35 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
538 480
539static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 481static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
540 482
483static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
484 char *buf)
485{
486 int bitnr = to_sensor_dev_attr(attr)->index;
487 struct asb100_data *data = asb100_update_device(dev);
488 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
489}
490static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
491static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
492static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
493static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
494static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
495static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
496static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
497static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
498static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
499static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
500static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
501
541/* 1 PWM */ 502/* 1 PWM */
542static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf) 503static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr,
504 char *buf)
543{ 505{
544 struct asb100_data *data = asb100_update_device(dev); 506 struct asb100_data *data = asb100_update_device(dev);
545 return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f)); 507 return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f));
546} 508}
547 509
548static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 510static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr,
511 const char *buf, size_t count)
549{ 512{
550 struct i2c_client *client = to_i2c_client(dev); 513 struct i2c_client *client = to_i2c_client(dev);
551 struct asb100_data *data = i2c_get_clientdata(client); 514 struct asb100_data *data = i2c_get_clientdata(client);
@@ -559,14 +522,15 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const
559 return count; 522 return count;
560} 523}
561 524
562static ssize_t show_pwm_enable1(struct device *dev, struct device_attribute *attr, char *buf) 525static ssize_t show_pwm_enable1(struct device *dev,
526 struct device_attribute *attr, char *buf)
563{ 527{
564 struct asb100_data *data = asb100_update_device(dev); 528 struct asb100_data *data = asb100_update_device(dev);
565 return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0); 529 return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0);
566} 530}
567 531
568static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr, const char *buf, 532static ssize_t set_pwm_enable1(struct device *dev,
569 size_t count) 533 struct device_attribute *attr, const char *buf, size_t count)
570{ 534{
571 struct i2c_client *client = to_i2c_client(dev); 535 struct i2c_client *client = to_i2c_client(dev);
572 struct asb100_data *data = i2c_get_clientdata(client); 536 struct asb100_data *data = i2c_get_clientdata(client);
@@ -585,50 +549,62 @@ static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
585 show_pwm_enable1, set_pwm_enable1); 549 show_pwm_enable1, set_pwm_enable1);
586 550
587static struct attribute *asb100_attributes[] = { 551static struct attribute *asb100_attributes[] = {
588 &dev_attr_in0_input.attr, 552 &sensor_dev_attr_in0_input.dev_attr.attr,
589 &dev_attr_in0_min.attr, 553 &sensor_dev_attr_in0_min.dev_attr.attr,
590 &dev_attr_in0_max.attr, 554 &sensor_dev_attr_in0_max.dev_attr.attr,
591 &dev_attr_in1_input.attr, 555 &sensor_dev_attr_in1_input.dev_attr.attr,
592 &dev_attr_in1_min.attr, 556 &sensor_dev_attr_in1_min.dev_attr.attr,
593 &dev_attr_in1_max.attr, 557 &sensor_dev_attr_in1_max.dev_attr.attr,
594 &dev_attr_in2_input.attr, 558 &sensor_dev_attr_in2_input.dev_attr.attr,
595 &dev_attr_in2_min.attr, 559 &sensor_dev_attr_in2_min.dev_attr.attr,
596 &dev_attr_in2_max.attr, 560 &sensor_dev_attr_in2_max.dev_attr.attr,
597 &dev_attr_in3_input.attr, 561 &sensor_dev_attr_in3_input.dev_attr.attr,
598 &dev_attr_in3_min.attr, 562 &sensor_dev_attr_in3_min.dev_attr.attr,
599 &dev_attr_in3_max.attr, 563 &sensor_dev_attr_in3_max.dev_attr.attr,
600 &dev_attr_in4_input.attr, 564 &sensor_dev_attr_in4_input.dev_attr.attr,
601 &dev_attr_in4_min.attr, 565 &sensor_dev_attr_in4_min.dev_attr.attr,
602 &dev_attr_in4_max.attr, 566 &sensor_dev_attr_in4_max.dev_attr.attr,
603 &dev_attr_in5_input.attr, 567 &sensor_dev_attr_in5_input.dev_attr.attr,
604 &dev_attr_in5_min.attr, 568 &sensor_dev_attr_in5_min.dev_attr.attr,
605 &dev_attr_in5_max.attr, 569 &sensor_dev_attr_in5_max.dev_attr.attr,
606 &dev_attr_in6_input.attr, 570 &sensor_dev_attr_in6_input.dev_attr.attr,
607 &dev_attr_in6_min.attr, 571 &sensor_dev_attr_in6_min.dev_attr.attr,
608 &dev_attr_in6_max.attr, 572 &sensor_dev_attr_in6_max.dev_attr.attr,
609 573
610 &dev_attr_fan1_input.attr, 574 &sensor_dev_attr_fan1_input.dev_attr.attr,
611 &dev_attr_fan1_min.attr, 575 &sensor_dev_attr_fan1_min.dev_attr.attr,
612 &dev_attr_fan1_div.attr, 576 &sensor_dev_attr_fan1_div.dev_attr.attr,
613 &dev_attr_fan2_input.attr, 577 &sensor_dev_attr_fan2_input.dev_attr.attr,
614 &dev_attr_fan2_min.attr, 578 &sensor_dev_attr_fan2_min.dev_attr.attr,
615 &dev_attr_fan2_div.attr, 579 &sensor_dev_attr_fan2_div.dev_attr.attr,
616 &dev_attr_fan3_input.attr, 580 &sensor_dev_attr_fan3_input.dev_attr.attr,
617 &dev_attr_fan3_min.attr, 581 &sensor_dev_attr_fan3_min.dev_attr.attr,
618 &dev_attr_fan3_div.attr, 582 &sensor_dev_attr_fan3_div.dev_attr.attr,
619 583
620 &dev_attr_temp1_input.attr, 584 &sensor_dev_attr_temp1_input.dev_attr.attr,
621 &dev_attr_temp1_max.attr, 585 &sensor_dev_attr_temp1_max.dev_attr.attr,
622 &dev_attr_temp1_max_hyst.attr, 586 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
623 &dev_attr_temp2_input.attr, 587 &sensor_dev_attr_temp2_input.dev_attr.attr,
624 &dev_attr_temp2_max.attr, 588 &sensor_dev_attr_temp2_max.dev_attr.attr,
625 &dev_attr_temp2_max_hyst.attr, 589 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
626 &dev_attr_temp3_input.attr, 590 &sensor_dev_attr_temp3_input.dev_attr.attr,
627 &dev_attr_temp3_max.attr, 591 &sensor_dev_attr_temp3_max.dev_attr.attr,
628 &dev_attr_temp3_max_hyst.attr, 592 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
629 &dev_attr_temp4_input.attr, 593 &sensor_dev_attr_temp4_input.dev_attr.attr,
630 &dev_attr_temp4_max.attr, 594 &sensor_dev_attr_temp4_max.dev_attr.attr,
631 &dev_attr_temp4_max_hyst.attr, 595 &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
596
597 &sensor_dev_attr_in0_alarm.dev_attr.attr,
598 &sensor_dev_attr_in1_alarm.dev_attr.attr,
599 &sensor_dev_attr_in2_alarm.dev_attr.attr,
600 &sensor_dev_attr_in3_alarm.dev_attr.attr,
601 &sensor_dev_attr_in4_alarm.dev_attr.attr,
602 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
603 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
604 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
605 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
606 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
607 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
632 608
633 &dev_attr_cpu0_vid.attr, 609 &dev_attr_cpu0_vid.attr,
634 &dev_attr_vrm.attr, 610 &dev_attr_vrm.attr,
@@ -656,10 +632,10 @@ static int asb100_attach_adapter(struct i2c_adapter *adapter)
656} 632}
657 633
658static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, 634static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
659 int kind, struct i2c_client *new_client) 635 int kind, struct i2c_client *client)
660{ 636{
661 int i, id, err; 637 int i, id, err;
662 struct asb100_data *data = i2c_get_clientdata(new_client); 638 struct asb100_data *data = i2c_get_clientdata(client);
663 639
664 data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 640 data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
665 if (!(data->lm75[0])) { 641 if (!(data->lm75[0])) {
@@ -679,26 +655,26 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
679 for (i = 2; i <= 3; i++) { 655 for (i = 2; i <= 3; i++) {
680 if (force_subclients[i] < 0x48 || 656 if (force_subclients[i] < 0x48 ||
681 force_subclients[i] > 0x4f) { 657 force_subclients[i] > 0x4f) {
682 dev_err(&new_client->dev, "invalid subclient " 658 dev_err(&client->dev, "invalid subclient "
683 "address %d; must be 0x48-0x4f\n", 659 "address %d; must be 0x48-0x4f\n",
684 force_subclients[i]); 660 force_subclients[i]);
685 err = -ENODEV; 661 err = -ENODEV;
686 goto ERROR_SC_2; 662 goto ERROR_SC_2;
687 } 663 }
688 } 664 }
689 asb100_write_value(new_client, ASB100_REG_I2C_SUBADDR, 665 asb100_write_value(client, ASB100_REG_I2C_SUBADDR,
690 (force_subclients[2] & 0x07) | 666 (force_subclients[2] & 0x07) |
691 ((force_subclients[3] & 0x07) <<4)); 667 ((force_subclients[3] & 0x07) << 4));
692 data->lm75[0]->addr = force_subclients[2]; 668 data->lm75[0]->addr = force_subclients[2];
693 data->lm75[1]->addr = force_subclients[3]; 669 data->lm75[1]->addr = force_subclients[3];
694 } else { 670 } else {
695 int val = asb100_read_value(new_client, ASB100_REG_I2C_SUBADDR); 671 int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR);
696 data->lm75[0]->addr = 0x48 + (val & 0x07); 672 data->lm75[0]->addr = 0x48 + (val & 0x07);
697 data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07); 673 data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07);
698 } 674 }
699 675
700 if(data->lm75[0]->addr == data->lm75[1]->addr) { 676 if (data->lm75[0]->addr == data->lm75[1]->addr) {
701 dev_err(&new_client->dev, "duplicate addresses 0x%x " 677 dev_err(&client->dev, "duplicate addresses 0x%x "
702 "for subclients\n", data->lm75[0]->addr); 678 "for subclients\n", data->lm75[0]->addr);
703 err = -ENODEV; 679 err = -ENODEV;
704 goto ERROR_SC_2; 680 goto ERROR_SC_2;
@@ -708,18 +684,17 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
708 i2c_set_clientdata(data->lm75[i], NULL); 684 i2c_set_clientdata(data->lm75[i], NULL);
709 data->lm75[i]->adapter = adapter; 685 data->lm75[i]->adapter = adapter;
710 data->lm75[i]->driver = &asb100_driver; 686 data->lm75[i]->driver = &asb100_driver;
711 data->lm75[i]->flags = 0;
712 strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE); 687 strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE);
713 } 688 }
714 689
715 if ((err = i2c_attach_client(data->lm75[0]))) { 690 if ((err = i2c_attach_client(data->lm75[0]))) {
716 dev_err(&new_client->dev, "subclient %d registration " 691 dev_err(&client->dev, "subclient %d registration "
717 "at address 0x%x failed.\n", i, data->lm75[0]->addr); 692 "at address 0x%x failed.\n", i, data->lm75[0]->addr);
718 goto ERROR_SC_2; 693 goto ERROR_SC_2;
719 } 694 }
720 695
721 if ((err = i2c_attach_client(data->lm75[1]))) { 696 if ((err = i2c_attach_client(data->lm75[1]))) {
722 dev_err(&new_client->dev, "subclient %d registration " 697 dev_err(&client->dev, "subclient %d registration "
723 "at address 0x%x failed.\n", i, data->lm75[1]->addr); 698 "at address 0x%x failed.\n", i, data->lm75[1]->addr);
724 goto ERROR_SC_3; 699 goto ERROR_SC_3;
725 } 700 }
@@ -740,7 +715,7 @@ ERROR_SC_0:
740static int asb100_detect(struct i2c_adapter *adapter, int address, int kind) 715static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
741{ 716{
742 int err; 717 int err;
743 struct i2c_client *new_client; 718 struct i2c_client *client;
744 struct asb100_data *data; 719 struct asb100_data *data;
745 720
746 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 721 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -760,13 +735,12 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
760 goto ERROR0; 735 goto ERROR0;
761 } 736 }
762 737
763 new_client = &data->client; 738 client = &data->client;
764 mutex_init(&data->lock); 739 mutex_init(&data->lock);
765 i2c_set_clientdata(new_client, data); 740 i2c_set_clientdata(client, data);
766 new_client->addr = address; 741 client->addr = address;
767 new_client->adapter = adapter; 742 client->adapter = adapter;
768 new_client->driver = &asb100_driver; 743 client->driver = &asb100_driver;
769 new_client->flags = 0;
770 744
771 /* Now, we do the remaining detection. */ 745 /* Now, we do the remaining detection. */
772 746
@@ -776,15 +750,15 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
776 bank. */ 750 bank. */
777 if (kind < 0) { 751 if (kind < 0) {
778 752
779 int val1 = asb100_read_value(new_client, ASB100_REG_BANK); 753 int val1 = asb100_read_value(client, ASB100_REG_BANK);
780 int val2 = asb100_read_value(new_client, ASB100_REG_CHIPMAN); 754 int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN);
781 755
782 /* If we're in bank 0 */ 756 /* If we're in bank 0 */
783 if ( (!(val1 & 0x07)) && 757 if ((!(val1 & 0x07)) &&
784 /* Check for ASB100 ID (low byte) */ 758 /* Check for ASB100 ID (low byte) */
785 ( ((!(val1 & 0x80)) && (val2 != 0x94)) || 759 (((!(val1 & 0x80)) && (val2 != 0x94)) ||
786 /* Check for ASB100 ID (high byte ) */ 760 /* Check for ASB100 ID (high byte ) */
787 ((val1 & 0x80) && (val2 != 0x06)) ) ) { 761 ((val1 & 0x80) && (val2 != 0x06)))) {
788 pr_debug("asb100.o: detect failed, " 762 pr_debug("asb100.o: detect failed, "
789 "bad chip id 0x%02x!\n", val2); 763 "bad chip id 0x%02x!\n", val2);
790 err = -ENODEV; 764 err = -ENODEV;
@@ -795,19 +769,19 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
795 769
796 /* We have either had a force parameter, or we have already detected 770 /* We have either had a force parameter, or we have already detected
797 Winbond. Put it now into bank 0 and Vendor ID High Byte */ 771 Winbond. Put it now into bank 0 and Vendor ID High Byte */
798 asb100_write_value(new_client, ASB100_REG_BANK, 772 asb100_write_value(client, ASB100_REG_BANK,
799 (asb100_read_value(new_client, ASB100_REG_BANK) & 0x78) | 0x80); 773 (asb100_read_value(client, ASB100_REG_BANK) & 0x78) | 0x80);
800 774
801 /* Determine the chip type. */ 775 /* Determine the chip type. */
802 if (kind <= 0) { 776 if (kind <= 0) {
803 int val1 = asb100_read_value(new_client, ASB100_REG_WCHIPID); 777 int val1 = asb100_read_value(client, ASB100_REG_WCHIPID);
804 int val2 = asb100_read_value(new_client, ASB100_REG_CHIPMAN); 778 int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN);
805 779
806 if ((val1 == 0x31) && (val2 == 0x06)) 780 if ((val1 == 0x31) && (val2 == 0x06))
807 kind = asb100; 781 kind = asb100;
808 else { 782 else {
809 if (kind == 0) 783 if (kind == 0)
810 dev_warn(&new_client->dev, "ignoring " 784 dev_warn(&client->dev, "ignoring "
811 "'force' parameter for unknown chip " 785 "'force' parameter for unknown chip "
812 "at adapter %d, address 0x%02x.\n", 786 "at adapter %d, address 0x%02x.\n",
813 i2c_adapter_id(adapter), address); 787 i2c_adapter_id(adapter), address);
@@ -817,34 +791,32 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
817 } 791 }
818 792
819 /* Fill in remaining client fields and put it into the global list */ 793 /* Fill in remaining client fields and put it into the global list */
820 strlcpy(new_client->name, "asb100", I2C_NAME_SIZE); 794 strlcpy(client->name, "asb100", I2C_NAME_SIZE);
821 data->type = kind; 795 data->type = kind;
822
823 data->valid = 0;
824 mutex_init(&data->update_lock); 796 mutex_init(&data->update_lock);
825 797
826 /* Tell the I2C layer a new client has arrived */ 798 /* Tell the I2C layer a new client has arrived */
827 if ((err = i2c_attach_client(new_client))) 799 if ((err = i2c_attach_client(client)))
828 goto ERROR1; 800 goto ERROR1;
829 801
830 /* Attach secondary lm75 clients */ 802 /* Attach secondary lm75 clients */
831 if ((err = asb100_detect_subclients(adapter, address, kind, 803 if ((err = asb100_detect_subclients(adapter, address, kind,
832 new_client))) 804 client)))
833 goto ERROR2; 805 goto ERROR2;
834 806
835 /* Initialize the chip */ 807 /* Initialize the chip */
836 asb100_init_client(new_client); 808 asb100_init_client(client);
837 809
838 /* A few vars need to be filled upon startup */ 810 /* A few vars need to be filled upon startup */
839 data->fan_min[0] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(0)); 811 data->fan_min[0] = asb100_read_value(client, ASB100_REG_FAN_MIN(0));
840 data->fan_min[1] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(1)); 812 data->fan_min[1] = asb100_read_value(client, ASB100_REG_FAN_MIN(1));
841 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); 813 data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2));
842 814
843 /* Register sysfs hooks */ 815 /* Register sysfs hooks */
844 if ((err = sysfs_create_group(&new_client->dev.kobj, &asb100_group))) 816 if ((err = sysfs_create_group(&client->dev.kobj, &asb100_group)))
845 goto ERROR3; 817 goto ERROR3;
846 818
847 data->hwmon_dev = hwmon_device_register(&new_client->dev); 819 data->hwmon_dev = hwmon_device_register(&client->dev);
848 if (IS_ERR(data->hwmon_dev)) { 820 if (IS_ERR(data->hwmon_dev)) {
849 err = PTR_ERR(data->hwmon_dev); 821 err = PTR_ERR(data->hwmon_dev);
850 goto ERROR4; 822 goto ERROR4;
@@ -853,14 +825,14 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
853 return 0; 825 return 0;
854 826
855ERROR4: 827ERROR4:
856 sysfs_remove_group(&new_client->dev.kobj, &asb100_group); 828 sysfs_remove_group(&client->dev.kobj, &asb100_group);
857ERROR3: 829ERROR3:
858 i2c_detach_client(data->lm75[1]); 830 i2c_detach_client(data->lm75[1]);
859 i2c_detach_client(data->lm75[0]); 831 i2c_detach_client(data->lm75[0]);
860 kfree(data->lm75[1]); 832 kfree(data->lm75[1]);
861 kfree(data->lm75[0]); 833 kfree(data->lm75[0]);
862ERROR2: 834ERROR2:
863 i2c_detach_client(new_client); 835 i2c_detach_client(client);
864ERROR1: 836ERROR1:
865 kfree(data); 837 kfree(data);
866ERROR0: 838ERROR0:
@@ -916,17 +888,17 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
916 /* convert from ISA to LM75 I2C addresses */ 888 /* convert from ISA to LM75 I2C addresses */
917 switch (reg & 0xff) { 889 switch (reg & 0xff) {
918 case 0x50: /* TEMP */ 890 case 0x50: /* TEMP */
919 res = swab16(i2c_smbus_read_word_data (cl, 0)); 891 res = swab16(i2c_smbus_read_word_data(cl, 0));
920 break; 892 break;
921 case 0x52: /* CONFIG */ 893 case 0x52: /* CONFIG */
922 res = i2c_smbus_read_byte_data(cl, 1); 894 res = i2c_smbus_read_byte_data(cl, 1);
923 break; 895 break;
924 case 0x53: /* HYST */ 896 case 0x53: /* HYST */
925 res = swab16(i2c_smbus_read_word_data (cl, 2)); 897 res = swab16(i2c_smbus_read_word_data(cl, 2));
926 break; 898 break;
927 case 0x55: /* MAX */ 899 case 0x55: /* MAX */
928 default: 900 default:
929 res = swab16(i2c_smbus_read_word_data (cl, 3)); 901 res = swab16(i2c_smbus_read_word_data(cl, 3));
930 break; 902 break;
931 } 903 }
932 } 904 }
@@ -989,7 +961,7 @@ static void asb100_init_client(struct i2c_client *client)
989 vid = vid_from_reg(vid, data->vrm); 961 vid = vid_from_reg(vid, data->vrm);
990 962
991 /* Start monitoring */ 963 /* Start monitoring */
992 asb100_write_value(client, ASB100_REG_CONFIG, 964 asb100_write_value(client, ASB100_REG_CONFIG,
993 (asb100_read_value(client, ASB100_REG_CONFIG) & 0xf7) | 0x01); 965 (asb100_read_value(client, ASB100_REG_CONFIG) & 0xf7) | 0x01);
994} 966}
995 967
@@ -1078,4 +1050,3 @@ MODULE_LICENSE("GPL");
1078 1050
1079module_init(asb100_init); 1051module_init(asb100_init);
1080module_exit(asb100_exit); 1052module_exit(asb100_exit);
1081
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index a878c98e252e..ddddd9f34c19 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -44,6 +44,10 @@ static int force_start;
44module_param(force_start, bool, 0); 44module_param(force_start, bool, 0);
45MODULE_PARM_DESC(force_start, "Force the chip to start monitoring inputs"); 45MODULE_PARM_DESC(force_start, "Force the chip to start monitoring inputs");
46 46
47static unsigned short force_id;
48module_param(force_id, ushort, 0);
49MODULE_PARM_DESC(force_id, "Override the detected device ID");
50
47/* Addresses to scan */ 51/* Addresses to scan */
48static unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; 52static unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END};
49 53
@@ -279,14 +283,21 @@ static inline int TEMP_HYST_TO_REG(int val, int ix, int reg)
279/* Fan input RPM */ 283/* Fan input RPM */
280static inline int FAN_FROM_REG(int reg, int tpc) 284static inline int FAN_FROM_REG(int reg, int tpc)
281{ 285{
282 return (reg == 0 || reg == 0xffff) ? 0 : 286 if (tpc) {
283 (tpc == 0) ? 90000 * 60 / reg : tpc * reg; 287 return tpc * reg;
288 } else {
289 return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg;
290 }
284} 291}
285 292
286static inline int FAN_TO_REG(int val, int tpc) 293static inline int FAN_TO_REG(int val, int tpc)
287{ 294{
288 return SENSORS_LIMIT((tpc == 0) ? 90000 * 60 / val : val / tpc, 295 if (tpc) {
289 0, 0xffff); 296 return SENSORS_LIMIT(val / tpc, 0, 0xffff);
297 } else {
298 return (val <= 0) ? 0xffff :
299 SENSORS_LIMIT(90000 * 60 / val, 0, 0xfffe);
300 }
290} 301}
291 302
292/* Fan TPC (tach pulse count) 303/* Fan TPC (tach pulse count)
@@ -2019,7 +2030,7 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
2019 2030
2020 /* Check device ID 2031 /* Check device ID
2021 * The DME1737 can return either 0x78 or 0x77 as its device ID. */ 2032 * The DME1737 can return either 0x78 or 0x77 as its device ID. */
2022 reg = dme1737_sio_inb(sio_cip, 0x20); 2033 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
2023 if (!(reg == 0x77 || reg == 0x78)) { 2034 if (!(reg == 0x77 || reg == 0x78)) {
2024 err = -ENODEV; 2035 err = -ENODEV;
2025 goto exit; 2036 goto exit;
@@ -2191,7 +2202,7 @@ static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
2191 /* Check device ID 2202 /* Check device ID
2192 * We currently know about SCH3112 (0x7c), SCH3114 (0x7d), and 2203 * We currently know about SCH3112 (0x7c), SCH3114 (0x7d), and
2193 * SCH3116 (0x7f). */ 2204 * SCH3116 (0x7f). */
2194 reg = dme1737_sio_inb(sio_cip, 0x20); 2205 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
2195 if (!(reg == 0x7c || reg == 0x7d || reg == 0x7f)) { 2206 if (!(reg == 0x7c || reg == 0x7d || reg == 0x7f)) {
2196 err = -ENODEV; 2207 err = -ENODEV;
2197 goto exit; 2208 goto exit;
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index b7bd000b130f..3f5163de13c1 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -94,7 +94,6 @@ static struct i2c_driver ds1621_driver = {
94 .driver = { 94 .driver = {
95 .name = "ds1621", 95 .name = "ds1621",
96 }, 96 },
97 .id = I2C_DRIVERID_DS1621,
98 .attach_adapter = ds1621_attach_adapter, 97 .attach_adapter = ds1621_attach_adapter,
99 .detach_client = ds1621_detach_client, 98 .detach_client = ds1621_detach_client,
100}; 99};
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index 5d9d5cc816a2..7a14a2dbb752 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -41,6 +41,10 @@
41#include <linux/ioport.h> 41#include <linux/ioport.h>
42#include <asm/io.h> 42#include <asm/io.h>
43 43
44static unsigned short force_id;
45module_param(force_id, ushort, 0);
46MODULE_PARM_DESC(force_id, "Override the detected device ID");
47
44static struct platform_device *pdev; 48static struct platform_device *pdev;
45 49
46#define DRVNAME "f71805f" 50#define DRVNAME "f71805f"
@@ -1497,7 +1501,7 @@ static int __init f71805f_find(int sioaddr, unsigned short *address,
1497 if (devid != SIO_FINTEK_ID) 1501 if (devid != SIO_FINTEK_ID)
1498 goto exit; 1502 goto exit;
1499 1503
1500 devid = superio_inw(sioaddr, SIO_REG_DEVID); 1504 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
1501 switch (devid) { 1505 switch (devid) {
1502 case SIO_F71805F_ID: 1506 case SIO_F71805F_ID:
1503 sio_data->kind = f71805f; 1507 sio_data->kind = f71805f;
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 6db74434a02e..cbeb4984b5c7 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -74,6 +74,10 @@
74 74
75#define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */ 75#define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
76 76
77static unsigned short force_id;
78module_param(force_id, ushort, 0);
79MODULE_PARM_DESC(force_id, "Override the detected device ID");
80
77static struct platform_device *f71882fg_pdev = NULL; 81static struct platform_device *f71882fg_pdev = NULL;
78 82
79/* Super-I/O Function prototypes */ 83/* Super-I/O Function prototypes */
@@ -843,7 +847,7 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address)
843 goto exit; 847 goto exit;
844 } 848 }
845 849
846 devid = superio_inw(sioaddr, SIO_REG_DEVID); 850 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
847 if (devid != SIO_F71882_ID) { 851 if (devid != SIO_F71882_ID) {
848 printk(KERN_INFO DRVNAME ": Unsupported Fintek device\n"); 852 printk(KERN_INFO DRVNAME ": Unsupported Fintek device\n");
849 goto exit; 853 goto exit;
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c
index e67c36953b2d..721c70177b17 100644
--- a/drivers/hwmon/fscher.c
+++ b/drivers/hwmon/fscher.c
@@ -123,7 +123,6 @@ static struct i2c_driver fscher_driver = {
123 .driver = { 123 .driver = {
124 .name = "fscher", 124 .name = "fscher",
125 }, 125 },
126 .id = I2C_DRIVERID_FSCHER,
127 .attach_adapter = fscher_attach_adapter, 126 .attach_adapter = fscher_attach_adapter,
128 .detach_client = fscher_detach_client, 127 .detach_client = fscher_detach_client,
129}; 128};
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index 63a4df0580db..b7c9eef0f928 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -41,6 +41,7 @@
41#include <linux/err.h> 41#include <linux/err.h>
42#include <linux/mutex.h> 42#include <linux/mutex.h>
43#include <linux/sysfs.h> 43#include <linux/sysfs.h>
44#include <linux/dmi.h>
44 45
45/* Addresses to scan */ 46/* Addresses to scan */
46static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; 47static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
@@ -133,7 +134,7 @@ static const u8 FSCHMD_REG_TEMP_STATE[5][5] = {
133 { 0x71, 0x81, 0x91 }, /* her */ 134 { 0x71, 0x81, 0x91 }, /* her */
134 { 0x71, 0xd1, 0x81, 0x91 }, /* scy */ 135 { 0x71, 0xd1, 0x81, 0x91 }, /* scy */
135 { 0x71, 0x81, 0x91 }, /* hrc */ 136 { 0x71, 0x81, 0x91 }, /* hrc */
136 { 0x71, 0x81, 0x91, 0xd1, 0xe1 }, /* hmd */ 137 { 0x71, 0x81, 0x91, 0xd1, 0xe1 }, /* hmd */
137}; 138};
138 139
139/* temperature high limit registers, FSC does not document these. Proven to be 140/* temperature high limit registers, FSC does not document these. Proven to be
@@ -146,7 +147,7 @@ static const u8 FSCHMD_REG_TEMP_LIMIT[5][5] = {
146 { 0x76, 0x86, 0x96 }, /* her */ 147 { 0x76, 0x86, 0x96 }, /* her */
147 { 0x76, 0xd6, 0x86, 0x96 }, /* scy */ 148 { 0x76, 0xd6, 0x86, 0x96 }, /* scy */
148 { 0x76, 0x86, 0x96 }, /* hrc */ 149 { 0x76, 0x86, 0x96 }, /* hrc */
149 { 0x76, 0x86, 0x96, 0xd6, 0xe6 }, /* hmd */ 150 { 0x76, 0x86, 0x96, 0xd6, 0xe6 }, /* hmd */
150}; 151};
151 152
152/* These were found through experimenting with an fscher, currently they are 153/* These were found through experimenting with an fscher, currently they are
@@ -210,6 +211,13 @@ struct fschmd_data {
210 u8 fan_ripple[6]; /* divider for rps */ 211 u8 fan_ripple[6]; /* divider for rps */
211}; 212};
212 213
214/* Global variables to hold information read from special DMI tables, which are
215 available on FSC machines with an fscher or later chip. */
216static int dmi_mult[3] = { 490, 200, 100 };
217static int dmi_offset[3] = { 0, 0, 0 };
218static int dmi_vref = -1;
219
220
213/* 221/*
214 * Sysfs attr show / store functions 222 * Sysfs attr show / store functions
215 */ 223 */
@@ -221,8 +229,13 @@ static ssize_t show_in_value(struct device *dev,
221 int index = to_sensor_dev_attr(devattr)->index; 229 int index = to_sensor_dev_attr(devattr)->index;
222 struct fschmd_data *data = fschmd_update_device(dev); 230 struct fschmd_data *data = fschmd_update_device(dev);
223 231
224 return sprintf(buf, "%d\n", (data->volt[index] * 232 /* fscher / fschrc - 1 as data->kind is an array index, not a chips */
225 max_reading[index] + 128) / 255); 233 if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1))
234 return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
235 dmi_mult[index]) / 255 + dmi_offset[index]);
236 else
237 return sprintf(buf, "%d\n", (data->volt[index] *
238 max_reading[index] + 128) / 255);
226} 239}
227 240
228 241
@@ -525,6 +538,68 @@ static struct sensor_device_attribute fschmd_fan_attr[] = {
525 * Real code 538 * Real code
526 */ 539 */
527 540
541/* DMI decode routine to read voltage scaling factors from special DMI tables,
542 which are available on FSC machines with an fscher or later chip. */
543static void fschmd_dmi_decode(const struct dmi_header *header)
544{
545 int i, mult[3] = { 0 }, offset[3] = { 0 }, vref = 0, found = 0;
546
547 /* dmi code ugliness, we get passed the address of the contents of
548 a complete DMI record, but in the form of a dmi_header pointer, in
549 reality this address holds header->length bytes of which the header
550 are the first 4 bytes */
551 u8 *dmi_data = (u8 *)header;
552
553 /* We are looking for OEM-specific type 185 */
554 if (header->type != 185)
555 return;
556
557 /* we are looking for what Siemens calls "subtype" 19, the subtype
558 is stored in byte 5 of the dmi block */
559 if (header->length < 5 || dmi_data[4] != 19)
560 return;
561
562 /* After the subtype comes 1 unknown byte and then blocks of 5 bytes,
563 consisting of what Siemens calls an "Entity" number, followed by
564 2 16-bit words in LSB first order */
565 for (i = 6; (i + 4) < header->length; i += 5) {
566 /* entity 1 - 3: voltage multiplier and offset */
567 if (dmi_data[i] >= 1 && dmi_data[i] <= 3) {
568 /* Our in sensors order and the DMI order differ */
569 const int shuffle[3] = { 1, 0, 2 };
570 int in = shuffle[dmi_data[i] - 1];
571
572 /* Check for twice the same entity */
573 if (found & (1 << in))
574 return;
575
576 mult[in] = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
577 offset[in] = dmi_data[i + 3] | (dmi_data[i + 4] << 8);
578
579 found |= 1 << in;
580 }
581
582 /* entity 7: reference voltage */
583 if (dmi_data[i] == 7) {
584 /* Check for twice the same entity */
585 if (found & 0x08)
586 return;
587
588 vref = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
589
590 found |= 0x08;
591 }
592 }
593
594 if (found == 0x0F) {
595 for (i = 0; i < 3; i++) {
596 dmi_mult[i] = mult[i] * 10;
597 dmi_offset[i] = offset[i] * 10;
598 }
599 dmi_vref = vref;
600 }
601}
602
528static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind) 603static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
529{ 604{
530 struct i2c_client *client; 605 struct i2c_client *client;
@@ -586,6 +661,17 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
586 data->temp_max[2] = 50 + 128; 661 data->temp_max[2] = 50 + 128;
587 } 662 }
588 663
664 /* Read the special DMI table for fscher and newer chips */
665 if (kind == fscher || kind >= fschrc) {
666 dmi_walk(fschmd_dmi_decode);
667 if (dmi_vref == -1) {
668 printk(KERN_WARNING FSCHMD_NAME
669 ": Couldn't get voltage scaling factors from "
670 "BIOS DMI table, using builtin defaults\n");
671 dmi_vref = 33;
672 }
673 }
674
589 /* i2c kind goes from 1-5, we want from 0-4 to address arrays */ 675 /* i2c kind goes from 1-5, we want from 0-4 to address arrays */
590 data->kind = kind - 1; 676 data->kind = kind - 1;
591 strlcpy(client->name, client_names[data->kind], I2C_NAME_SIZE); 677 strlcpy(client->name, client_names[data->kind], I2C_NAME_SIZE);
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c
index 92c9703d0ac0..2f1075323a1e 100644
--- a/drivers/hwmon/fscpos.c
+++ b/drivers/hwmon/fscpos.c
@@ -105,7 +105,6 @@ static struct i2c_driver fscpos_driver = {
105 .driver = { 105 .driver = {
106 .name = "fscpos", 106 .name = "fscpos",
107 }, 107 },
108 .id = I2C_DRIVERID_FSCPOS,
109 .attach_adapter = fscpos_attach_adapter, 108 .attach_adapter = fscpos_attach_adapter,
110 .detach_client = fscpos_detach_client, 109 .detach_client = fscpos_detach_client,
111}; 110};
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index bb58d9866a37..3b1ac48fce23 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -30,10 +30,6 @@
30 * We did not keep that part of the original driver in the Linux 2.6 30 * We did not keep that part of the original driver in the Linux 2.6
31 * version, since it was making the driver significantly more complex 31 * version, since it was making the driver significantly more complex
32 * with no real benefit. 32 * with no real benefit.
33 *
34 * History:
35 * 2004-01-28 Original port. (Hong-Gunn Chew)
36 * 2004-01-31 Code review and approval. (Jean Delvare)
37 */ 33 */
38 34
39#include <linux/module.h> 35#include <linux/module.h>
@@ -42,6 +38,7 @@
42#include <linux/jiffies.h> 38#include <linux/jiffies.h>
43#include <linux/i2c.h> 39#include <linux/i2c.h>
44#include <linux/hwmon.h> 40#include <linux/hwmon.h>
41#include <linux/hwmon-sysfs.h>
45#include <linux/err.h> 42#include <linux/err.h>
46#include <linux/mutex.h> 43#include <linux/mutex.h>
47#include <linux/sysfs.h> 44#include <linux/sysfs.h>
@@ -99,10 +96,10 @@ static inline u8 FAN_TO_REG(long rpm, int div)
99 long rpmdiv; 96 long rpmdiv;
100 if (rpm == 0) 97 if (rpm == 0)
101 return 0; 98 return 0;
102 rpmdiv = SENSORS_LIMIT(rpm, 1, 1920000) * div; 99 rpmdiv = SENSORS_LIMIT(rpm, 1, 960000) * div;
103 return SENSORS_LIMIT((960000 + rpmdiv / 2) / rpmdiv, 1, 255); 100 return SENSORS_LIMIT((480000 + rpmdiv / 2) / rpmdiv, 1, 255);
104} 101}
105#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (960000/((val)*(div)))) 102#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val)*(div))))
106 103
107#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255)) 104#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255))
108#define IN_FROM_REG(val) ((val)*19) 105#define IN_FROM_REG(val) ((val)*19)
@@ -110,7 +107,6 @@ static inline u8 FAN_TO_REG(long rpm, int div)
110#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255)) 107#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255))
111#define VDD_FROM_REG(val) (((val)*95+2)/4) 108#define VDD_FROM_REG(val) (((val)*95+2)/4)
112 109
113#define DIV_TO_REG(val) ((val)==4?2:(val)==2?1:(val)==1?0:3)
114#define DIV_FROM_REG(val) (1 << (val)) 110#define DIV_FROM_REG(val) (1 << (val))
115 111
116#define BEEP_MASK_TO_REG(val) ((val) & 0x7f & data->alarm_mask) 112#define BEEP_MASK_TO_REG(val) ((val) & 0x7f & data->alarm_mask)
@@ -129,7 +125,6 @@ struct gl518_data {
129 u8 voltage_in[4]; /* Register values; [0] = VDD */ 125 u8 voltage_in[4]; /* Register values; [0] = VDD */
130 u8 voltage_min[4]; /* Register values; [0] = VDD */ 126 u8 voltage_min[4]; /* Register values; [0] = VDD */
131 u8 voltage_max[4]; /* Register values; [0] = VDD */ 127 u8 voltage_max[4]; /* Register values; [0] = VDD */
132 u8 iter_voltage_in[4]; /* Register values; [0] = VDD */
133 u8 fan_in[2]; 128 u8 fan_in[2];
134 u8 fan_min[2]; 129 u8 fan_min[2];
135 u8 fan_div[2]; /* Register encoding, shifted right */ 130 u8 fan_div[2]; /* Register encoding, shifted right */
@@ -138,7 +133,7 @@ struct gl518_data {
138 u8 temp_max; /* Register values */ 133 u8 temp_max; /* Register values */
139 u8 temp_hyst; /* Register values */ 134 u8 temp_hyst; /* Register values */
140 u8 alarms; /* Register value */ 135 u8 alarms; /* Register value */
141 u8 alarm_mask; /* Register value */ 136 u8 alarm_mask;
142 u8 beep_mask; /* Register value */ 137 u8 beep_mask; /* Register value */
143 u8 beep_enable; /* Boolean */ 138 u8 beep_enable; /* Boolean */
144}; 139};
@@ -156,7 +151,6 @@ static struct i2c_driver gl518_driver = {
156 .driver = { 151 .driver = {
157 .name = "gl518sm", 152 .name = "gl518sm",
158 }, 153 },
159 .id = I2C_DRIVERID_GL518,
160 .attach_adapter = gl518_attach_adapter, 154 .attach_adapter = gl518_attach_adapter,
161 .detach_client = gl518_detach_client, 155 .detach_client = gl518_detach_client,
162}; 156};
@@ -172,24 +166,10 @@ static ssize_t show_##suffix(struct device *dev, struct device_attribute *attr,
172 return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \ 166 return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \
173} 167}
174 168
175#define show_fan(suffix, value, index) \
176static ssize_t show_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \
177{ \
178 struct gl518_data *data = gl518_update_device(dev); \
179 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[index], \
180 DIV_FROM_REG(data->fan_div[index]))); \
181}
182
183show(TEMP, temp_input1, temp_in); 169show(TEMP, temp_input1, temp_in);
184show(TEMP, temp_max1, temp_max); 170show(TEMP, temp_max1, temp_max);
185show(TEMP, temp_hyst1, temp_hyst); 171show(TEMP, temp_hyst1, temp_hyst);
186show(BOOL, fan_auto1, fan_auto1); 172show(BOOL, fan_auto1, fan_auto1);
187show_fan(fan_input1, fan_in, 0);
188show_fan(fan_input2, fan_in, 1);
189show_fan(fan_min1, fan_min, 0);
190show_fan(fan_min2, fan_min, 1);
191show(DIV, fan_div1, fan_div[0]);
192show(DIV, fan_div2, fan_div[1]);
193show(VDD, in_input0, voltage_in[0]); 173show(VDD, in_input0, voltage_in[0]);
194show(IN, in_input1, voltage_in[1]); 174show(IN, in_input1, voltage_in[1]);
195show(IN, in_input2, voltage_in[2]); 175show(IN, in_input2, voltage_in[2]);
@@ -206,6 +186,32 @@ show(RAW, alarms, alarms);
206show(BOOL, beep_enable, beep_enable); 186show(BOOL, beep_enable, beep_enable);
207show(BEEP_MASK, beep_mask, beep_mask); 187show(BEEP_MASK, beep_mask, beep_mask);
208 188
189static ssize_t show_fan_input(struct device *dev,
190 struct device_attribute *attr, char *buf)
191{
192 int nr = to_sensor_dev_attr(attr)->index;
193 struct gl518_data *data = gl518_update_device(dev);
194 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_in[nr],
195 DIV_FROM_REG(data->fan_div[nr])));
196}
197
198static ssize_t show_fan_min(struct device *dev,
199 struct device_attribute *attr, char *buf)
200{
201 int nr = to_sensor_dev_attr(attr)->index;
202 struct gl518_data *data = gl518_update_device(dev);
203 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
204 DIV_FROM_REG(data->fan_div[nr])));
205}
206
207static ssize_t show_fan_div(struct device *dev,
208 struct device_attribute *attr, char *buf)
209{
210 int nr = to_sensor_dev_attr(attr)->index;
211 struct gl518_data *data = gl518_update_device(dev);
212 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
213}
214
209#define set(type, suffix, value, reg) \ 215#define set(type, suffix, value, reg) \
210static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 216static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \
211 size_t count) \ 217 size_t count) \
@@ -247,8 +253,6 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c
247set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX); 253set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX);
248set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST); 254set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST);
249set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3); 255set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3);
250set_bits(DIV, fan_div1, fan_div[0], GL518_REG_MISC, 0xc0, 6);
251set_bits(DIV, fan_div2, fan_div[1], GL518_REG_MISC, 0x30, 4);
252set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT); 256set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT);
253set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT); 257set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT);
254set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT); 258set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT);
@@ -260,25 +264,27 @@ set_high(IN, in_max3, voltage_max[3], GL518_REG_VIN3_LIMIT);
260set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2); 264set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2);
261set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM); 265set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM);
262 266
263static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 267static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
268 const char *buf, size_t count)
264{ 269{
265 struct i2c_client *client = to_i2c_client(dev); 270 struct i2c_client *client = to_i2c_client(dev);
266 struct gl518_data *data = i2c_get_clientdata(client); 271 struct gl518_data *data = i2c_get_clientdata(client);
272 int nr = to_sensor_dev_attr(attr)->index;
267 int regvalue; 273 int regvalue;
268 unsigned long val = simple_strtoul(buf, NULL, 10); 274 unsigned long val = simple_strtoul(buf, NULL, 10);
269 275
270 mutex_lock(&data->update_lock); 276 mutex_lock(&data->update_lock);
271 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); 277 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
272 data->fan_min[0] = FAN_TO_REG(val, 278 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
273 DIV_FROM_REG(data->fan_div[0])); 279 regvalue = (regvalue & (0xff << (8 * nr)))
274 regvalue = (regvalue & 0x00ff) | (data->fan_min[0] << 8); 280 | (data->fan_min[nr] << (8 * (1 - nr)));
275 gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue); 281 gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue);
276 282
277 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); 283 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
278 if (data->fan_min[0] == 0) 284 if (data->fan_min[nr] == 0)
279 data->alarm_mask &= ~0x20; 285 data->alarm_mask &= ~(0x20 << nr);
280 else 286 else
281 data->alarm_mask |= 0x20; 287 data->alarm_mask |= (0x20 << nr);
282 data->beep_mask &= data->alarm_mask; 288 data->beep_mask &= data->alarm_mask;
283 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); 289 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
284 290
@@ -286,28 +292,32 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c
286 return count; 292 return count;
287} 293}
288 294
289static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 295static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
296 const char *buf, size_t count)
290{ 297{
291 struct i2c_client *client = to_i2c_client(dev); 298 struct i2c_client *client = to_i2c_client(dev);
292 struct gl518_data *data = i2c_get_clientdata(client); 299 struct gl518_data *data = i2c_get_clientdata(client);
300 int nr = to_sensor_dev_attr(attr)->index;
293 int regvalue; 301 int regvalue;
294 unsigned long val = simple_strtoul(buf, NULL, 10); 302 unsigned long val = simple_strtoul(buf, NULL, 10);
295 303
296 mutex_lock(&data->update_lock); 304 switch (val) {
297 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); 305 case 1: val = 0; break;
298 data->fan_min[1] = FAN_TO_REG(val, 306 case 2: val = 1; break;
299 DIV_FROM_REG(data->fan_div[1])); 307 case 4: val = 2; break;
300 regvalue = (regvalue & 0xff00) | data->fan_min[1]; 308 case 8: val = 3; break;
301 gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue); 309 default:
302 310 dev_err(dev, "Invalid fan clock divider %lu, choose one "
303 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); 311 "of 1, 2, 4 or 8\n", val);
304 if (data->fan_min[1] == 0) 312 return -EINVAL;
305 data->alarm_mask &= ~0x40; 313 }
306 else
307 data->alarm_mask |= 0x40;
308 data->beep_mask &= data->alarm_mask;
309 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
310 314
315 mutex_lock(&data->update_lock);
316 regvalue = gl518_read_value(client, GL518_REG_MISC);
317 data->fan_div[nr] = val;
318 regvalue = (regvalue & ~(0xc0 >> (2 * nr)))
319 | (data->fan_div[nr] << (6 - 2 * nr));
320 gl518_write_value(client, GL518_REG_MISC, regvalue);
311 mutex_unlock(&data->update_lock); 321 mutex_unlock(&data->update_lock);
312 return count; 322 return count;
313} 323}
@@ -317,12 +327,16 @@ static DEVICE_ATTR(temp1_max, S_IWUSR|S_IRUGO, show_temp_max1, set_temp_max1);
317static DEVICE_ATTR(temp1_max_hyst, S_IWUSR|S_IRUGO, 327static DEVICE_ATTR(temp1_max_hyst, S_IWUSR|S_IRUGO,
318 show_temp_hyst1, set_temp_hyst1); 328 show_temp_hyst1, set_temp_hyst1);
319static DEVICE_ATTR(fan1_auto, S_IWUSR|S_IRUGO, show_fan_auto1, set_fan_auto1); 329static DEVICE_ATTR(fan1_auto, S_IWUSR|S_IRUGO, show_fan_auto1, set_fan_auto1);
320static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL); 330static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);
321static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL); 331static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1);
322static DEVICE_ATTR(fan1_min, S_IWUSR|S_IRUGO, show_fan_min1, set_fan_min1); 332static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR|S_IRUGO,
323static DEVICE_ATTR(fan2_min, S_IWUSR|S_IRUGO, show_fan_min2, set_fan_min2); 333 show_fan_min, set_fan_min, 0);
324static DEVICE_ATTR(fan1_div, S_IWUSR|S_IRUGO, show_fan_div1, set_fan_div1); 334static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR|S_IRUGO,
325static DEVICE_ATTR(fan2_div, S_IWUSR|S_IRUGO, show_fan_div2, set_fan_div2); 335 show_fan_min, set_fan_min, 1);
336static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR|S_IRUGO,
337 show_fan_div, set_fan_div, 0);
338static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR|S_IRUGO,
339 show_fan_div, set_fan_div, 1);
326static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL); 340static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL);
327static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL); 341static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL);
328static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL); 342static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL);
@@ -341,10 +355,62 @@ static DEVICE_ATTR(beep_enable, S_IWUSR|S_IRUGO,
341static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO, 355static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO,
342 show_beep_mask, set_beep_mask); 356 show_beep_mask, set_beep_mask);
343 357
358static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
359 char *buf)
360{
361 int bitnr = to_sensor_dev_attr(attr)->index;
362 struct gl518_data *data = gl518_update_device(dev);
363 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
364}
365
366static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
367static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
368static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
369static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
370static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
371static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 5);
372static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 6);
373
374static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
375 char *buf)
376{
377 int bitnr = to_sensor_dev_attr(attr)->index;
378 struct gl518_data *data = gl518_update_device(dev);
379 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
380}
381
382static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
383 const char *buf, size_t count)
384{
385 struct i2c_client *client = to_i2c_client(dev);
386 struct gl518_data *data = i2c_get_clientdata(client);
387 int bitnr = to_sensor_dev_attr(attr)->index;
388 unsigned long bit;
389
390 bit = simple_strtoul(buf, NULL, 10);
391 if (bit & ~1)
392 return -EINVAL;
393
394 mutex_lock(&data->update_lock);
395 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
396 if (bit)
397 data->beep_mask |= (1 << bitnr);
398 else
399 data->beep_mask &= ~(1 << bitnr);
400 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
401 mutex_unlock(&data->update_lock);
402 return count;
403}
404
405static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 0);
406static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 1);
407static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 2);
408static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 3);
409static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 4);
410static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 5);
411static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 6);
412
344static struct attribute *gl518_attributes[] = { 413static struct attribute *gl518_attributes[] = {
345 &dev_attr_in0_input.attr,
346 &dev_attr_in1_input.attr,
347 &dev_attr_in2_input.attr,
348 &dev_attr_in3_input.attr, 414 &dev_attr_in3_input.attr,
349 &dev_attr_in0_min.attr, 415 &dev_attr_in0_min.attr,
350 &dev_attr_in1_min.attr, 416 &dev_attr_in1_min.attr,
@@ -354,18 +420,32 @@ static struct attribute *gl518_attributes[] = {
354 &dev_attr_in1_max.attr, 420 &dev_attr_in1_max.attr,
355 &dev_attr_in2_max.attr, 421 &dev_attr_in2_max.attr,
356 &dev_attr_in3_max.attr, 422 &dev_attr_in3_max.attr,
423 &sensor_dev_attr_in0_alarm.dev_attr.attr,
424 &sensor_dev_attr_in1_alarm.dev_attr.attr,
425 &sensor_dev_attr_in2_alarm.dev_attr.attr,
426 &sensor_dev_attr_in3_alarm.dev_attr.attr,
427 &sensor_dev_attr_in0_beep.dev_attr.attr,
428 &sensor_dev_attr_in1_beep.dev_attr.attr,
429 &sensor_dev_attr_in2_beep.dev_attr.attr,
430 &sensor_dev_attr_in3_beep.dev_attr.attr,
357 431
358 &dev_attr_fan1_auto.attr, 432 &dev_attr_fan1_auto.attr,
359 &dev_attr_fan1_input.attr, 433 &sensor_dev_attr_fan1_input.dev_attr.attr,
360 &dev_attr_fan2_input.attr, 434 &sensor_dev_attr_fan2_input.dev_attr.attr,
361 &dev_attr_fan1_min.attr, 435 &sensor_dev_attr_fan1_min.dev_attr.attr,
362 &dev_attr_fan2_min.attr, 436 &sensor_dev_attr_fan2_min.dev_attr.attr,
363 &dev_attr_fan1_div.attr, 437 &sensor_dev_attr_fan1_div.dev_attr.attr,
364 &dev_attr_fan2_div.attr, 438 &sensor_dev_attr_fan2_div.dev_attr.attr,
439 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
440 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
441 &sensor_dev_attr_fan1_beep.dev_attr.attr,
442 &sensor_dev_attr_fan2_beep.dev_attr.attr,
365 443
366 &dev_attr_temp1_input.attr, 444 &dev_attr_temp1_input.attr,
367 &dev_attr_temp1_max.attr, 445 &dev_attr_temp1_max.attr,
368 &dev_attr_temp1_max_hyst.attr, 446 &dev_attr_temp1_max_hyst.attr,
447 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
448 &sensor_dev_attr_temp1_beep.dev_attr.attr,
369 449
370 &dev_attr_alarms.attr, 450 &dev_attr_alarms.attr,
371 &dev_attr_beep_enable.attr, 451 &dev_attr_beep_enable.attr,
@@ -377,6 +457,17 @@ static const struct attribute_group gl518_group = {
377 .attrs = gl518_attributes, 457 .attrs = gl518_attributes,
378}; 458};
379 459
460static struct attribute *gl518_attributes_r80[] = {
461 &dev_attr_in0_input.attr,
462 &dev_attr_in1_input.attr,
463 &dev_attr_in2_input.attr,
464 NULL
465};
466
467static const struct attribute_group gl518_group_r80 = {
468 .attrs = gl518_attributes_r80,
469};
470
380/* 471/*
381 * Real code 472 * Real code
382 */ 473 */
@@ -391,7 +482,7 @@ static int gl518_attach_adapter(struct i2c_adapter *adapter)
391static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) 482static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
392{ 483{
393 int i; 484 int i;
394 struct i2c_client *new_client; 485 struct i2c_client *client;
395 struct gl518_data *data; 486 struct gl518_data *data;
396 int err = 0; 487 int err = 0;
397 488
@@ -408,25 +499,24 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
408 goto exit; 499 goto exit;
409 } 500 }
410 501
411 new_client = &data->client; 502 client = &data->client;
412 i2c_set_clientdata(new_client, data); 503 i2c_set_clientdata(client, data);
413 504
414 new_client->addr = address; 505 client->addr = address;
415 new_client->adapter = adapter; 506 client->adapter = adapter;
416 new_client->driver = &gl518_driver; 507 client->driver = &gl518_driver;
417 new_client->flags = 0;
418 508
419 /* Now, we do the remaining detection. */ 509 /* Now, we do the remaining detection. */
420 510
421 if (kind < 0) { 511 if (kind < 0) {
422 if ((gl518_read_value(new_client, GL518_REG_CHIP_ID) != 0x80) 512 if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80)
423 || (gl518_read_value(new_client, GL518_REG_CONF) & 0x80)) 513 || (gl518_read_value(client, GL518_REG_CONF) & 0x80))
424 goto exit_free; 514 goto exit_free;
425 } 515 }
426 516
427 /* Determine the chip type. */ 517 /* Determine the chip type. */
428 if (kind <= 0) { 518 if (kind <= 0) {
429 i = gl518_read_value(new_client, GL518_REG_REVISION); 519 i = gl518_read_value(client, GL518_REG_REVISION);
430 if (i == 0x00) { 520 if (i == 0x00) {
431 kind = gl518sm_r00; 521 kind = gl518sm_r00;
432 } else if (i == 0x80) { 522 } else if (i == 0x80) {
@@ -442,25 +532,27 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
442 } 532 }
443 533
444 /* Fill in the remaining client fields */ 534 /* Fill in the remaining client fields */
445 strlcpy(new_client->name, "gl518sm", I2C_NAME_SIZE); 535 strlcpy(client->name, "gl518sm", I2C_NAME_SIZE);
446 data->type = kind; 536 data->type = kind;
447 data->valid = 0;
448 mutex_init(&data->update_lock); 537 mutex_init(&data->update_lock);
449 538
450 /* Tell the I2C layer a new client has arrived */ 539 /* Tell the I2C layer a new client has arrived */
451 if ((err = i2c_attach_client(new_client))) 540 if ((err = i2c_attach_client(client)))
452 goto exit_free; 541 goto exit_free;
453 542
454 /* Initialize the GL518SM chip */ 543 /* Initialize the GL518SM chip */
455 data->alarm_mask = 0xff; 544 data->alarm_mask = 0xff;
456 data->voltage_in[0]=data->voltage_in[1]=data->voltage_in[2]=0; 545 gl518_init_client(client);
457 gl518_init_client((struct i2c_client *) new_client);
458 546
459 /* Register sysfs hooks */ 547 /* Register sysfs hooks */
460 if ((err = sysfs_create_group(&new_client->dev.kobj, &gl518_group))) 548 if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group)))
461 goto exit_detach; 549 goto exit_detach;
550 if (data->type == gl518sm_r80)
551 if ((err = sysfs_create_group(&client->dev.kobj,
552 &gl518_group_r80)))
553 goto exit_remove_files;
462 554
463 data->hwmon_dev = hwmon_device_register(&new_client->dev); 555 data->hwmon_dev = hwmon_device_register(&client->dev);
464 if (IS_ERR(data->hwmon_dev)) { 556 if (IS_ERR(data->hwmon_dev)) {
465 err = PTR_ERR(data->hwmon_dev); 557 err = PTR_ERR(data->hwmon_dev);
466 goto exit_remove_files; 558 goto exit_remove_files;
@@ -469,9 +561,11 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
469 return 0; 561 return 0;
470 562
471exit_remove_files: 563exit_remove_files:
472 sysfs_remove_group(&new_client->dev.kobj, &gl518_group); 564 sysfs_remove_group(&client->dev.kobj, &gl518_group);
565 if (data->type == gl518sm_r80)
566 sysfs_remove_group(&client->dev.kobj, &gl518_group_r80);
473exit_detach: 567exit_detach:
474 i2c_detach_client(new_client); 568 i2c_detach_client(client);
475exit_free: 569exit_free:
476 kfree(data); 570 kfree(data);
477exit: 571exit:
@@ -504,6 +598,8 @@ static int gl518_detach_client(struct i2c_client *client)
504 598
505 hwmon_device_unregister(data->hwmon_dev); 599 hwmon_device_unregister(data->hwmon_dev);
506 sysfs_remove_group(&client->dev.kobj, &gl518_group); 600 sysfs_remove_group(&client->dev.kobj, &gl518_group);
601 if (data->type == gl518sm_r80)
602 sysfs_remove_group(&client->dev.kobj, &gl518_group_r80);
507 603
508 if ((err = i2c_detach_client(client))) 604 if ((err = i2c_detach_client(client)))
509 return err; 605 return err;
@@ -512,9 +608,9 @@ static int gl518_detach_client(struct i2c_client *client)
512 return 0; 608 return 0;
513} 609}
514 610
515/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 611/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
516 GL518 uses a high-byte first convention, which is exactly opposite to 612 GL518 uses a high-byte first convention, which is exactly opposite to
517 the usual practice. */ 613 the SMBus standard. */
518static int gl518_read_value(struct i2c_client *client, u8 reg) 614static int gl518_read_value(struct i2c_client *client, u8 reg)
519{ 615{
520 if ((reg >= 0x07) && (reg <= 0x0c)) 616 if ((reg >= 0x07) && (reg <= 0x0c))
@@ -523,9 +619,6 @@ static int gl518_read_value(struct i2c_client *client, u8 reg)
523 return i2c_smbus_read_byte_data(client, reg); 619 return i2c_smbus_read_byte_data(client, reg);
524} 620}
525 621
526/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
527 GL518 uses a high-byte first convention, which is exactly opposite to
528 the usual practice. */
529static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) 622static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value)
530{ 623{
531 if ((reg >= 0x07) && (reg <= 0x0c)) 624 if ((reg >= 0x07) && (reg <= 0x0c))
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 2d39d8fc2389..03ecdc334764 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -27,6 +27,7 @@
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/hwmon-sysfs.h>
30#include <linux/hwmon-vid.h> 31#include <linux/hwmon-vid.h>
31#include <linux/err.h> 32#include <linux/err.h>
32#include <linux/mutex.h> 33#include <linux/mutex.h>
@@ -43,9 +44,9 @@ static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
43/* Insmod parameters */ 44/* Insmod parameters */
44I2C_CLIENT_INSMOD_1(gl520sm); 45I2C_CLIENT_INSMOD_1(gl520sm);
45 46
46/* Many GL520 constants specified below 47/* Many GL520 constants specified below
47One of the inputs can be configured as either temp or voltage. 48One of the inputs can be configured as either temp or voltage.
48That's why _TEMP2 and _IN4 access the same register 49That's why _TEMP2 and _IN4 access the same register
49*/ 50*/
50 51
51/* The GL520 registers */ 52/* The GL520 registers */
@@ -56,37 +57,14 @@ That's why _TEMP2 and _IN4 access the same register
56 57
57#define GL520_REG_VID_INPUT 0x02 58#define GL520_REG_VID_INPUT 0x02
58 59
59#define GL520_REG_IN0_INPUT 0x15 60static const u8 GL520_REG_IN_INPUT[] = { 0x15, 0x14, 0x13, 0x0d, 0x0e };
60#define GL520_REG_IN0_LIMIT 0x0c 61static const u8 GL520_REG_IN_LIMIT[] = { 0x0c, 0x09, 0x0a, 0x0b };
61#define GL520_REG_IN0_MIN GL520_REG_IN0_LIMIT 62static const u8 GL520_REG_IN_MIN[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x18 };
62#define GL520_REG_IN0_MAX GL520_REG_IN0_LIMIT 63static const u8 GL520_REG_IN_MAX[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x17 };
63 64
64#define GL520_REG_IN1_INPUT 0x14 65static const u8 GL520_REG_TEMP_INPUT[] = { 0x04, 0x0e };
65#define GL520_REG_IN1_LIMIT 0x09 66static const u8 GL520_REG_TEMP_MAX[] = { 0x05, 0x17 };
66#define GL520_REG_IN1_MIN GL520_REG_IN1_LIMIT 67static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 };
67#define GL520_REG_IN1_MAX GL520_REG_IN1_LIMIT
68
69#define GL520_REG_IN2_INPUT 0x13
70#define GL520_REG_IN2_LIMIT 0x0a
71#define GL520_REG_IN2_MIN GL520_REG_IN2_LIMIT
72#define GL520_REG_IN2_MAX GL520_REG_IN2_LIMIT
73
74#define GL520_REG_IN3_INPUT 0x0d
75#define GL520_REG_IN3_LIMIT 0x0b
76#define GL520_REG_IN3_MIN GL520_REG_IN3_LIMIT
77#define GL520_REG_IN3_MAX GL520_REG_IN3_LIMIT
78
79#define GL520_REG_IN4_INPUT 0x0e
80#define GL520_REG_IN4_MAX 0x17
81#define GL520_REG_IN4_MIN 0x18
82
83#define GL520_REG_TEMP1_INPUT 0x04
84#define GL520_REG_TEMP1_MAX 0x05
85#define GL520_REG_TEMP1_MAX_HYST 0x06
86
87#define GL520_REG_TEMP2_INPUT 0x0e
88#define GL520_REG_TEMP2_MAX 0x17
89#define GL520_REG_TEMP2_MAX_HYST 0x18
90 68
91#define GL520_REG_FAN_INPUT 0x07 69#define GL520_REG_FAN_INPUT 0x07
92#define GL520_REG_FAN_MIN 0x08 70#define GL520_REG_FAN_MIN 0x08
@@ -114,7 +92,6 @@ static struct i2c_driver gl520_driver = {
114 .driver = { 92 .driver = {
115 .name = "gl520sm", 93 .name = "gl520sm",
116 }, 94 },
117 .id = I2C_DRIVERID_GL520,
118 .attach_adapter = gl520_attach_adapter, 95 .attach_adapter = gl520_attach_adapter,
119 .detach_client = gl520_detach_client, 96 .detach_client = gl520_detach_client,
120}; 97};
@@ -150,93 +127,13 @@ struct gl520_data {
150 * Sysfs stuff 127 * Sysfs stuff
151 */ 128 */
152 129
153#define sysfs_r(type, n, item, reg) \ 130static ssize_t get_cpu_vid(struct device *dev, struct device_attribute *attr,
154static ssize_t get_##type##item (struct gl520_data *, char *, int); \ 131 char *buf)
155static ssize_t get_##type##n##item (struct device *, struct device_attribute *attr, char *); \
156static ssize_t get_##type##n##item (struct device *dev, struct device_attribute *attr, char *buf) \
157{ \
158 struct gl520_data *data = gl520_update_device(dev); \
159 return get_##type##item(data, buf, (n)); \
160}
161
162#define sysfs_w(type, n, item, reg) \
163static ssize_t set_##type##item (struct i2c_client *, struct gl520_data *, const char *, size_t, int, int); \
164static ssize_t set_##type##n##item (struct device *, struct device_attribute *attr, const char *, size_t); \
165static ssize_t set_##type##n##item (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
166{ \
167 struct i2c_client *client = to_i2c_client(dev); \
168 struct gl520_data *data = i2c_get_clientdata(client); \
169 return set_##type##item(client, data, buf, count, (n), reg); \
170}
171
172#define sysfs_rw_n(type, n, item, reg) \
173sysfs_r(type, n, item, reg) \
174sysfs_w(type, n, item, reg) \
175static DEVICE_ATTR(type##n##item, S_IRUGO | S_IWUSR, get_##type##n##item, set_##type##n##item);
176
177#define sysfs_ro_n(type, n, item, reg) \
178sysfs_r(type, n, item, reg) \
179static DEVICE_ATTR(type##n##item, S_IRUGO, get_##type##n##item, NULL);
180
181#define sysfs_rw(type, item, reg) \
182sysfs_r(type, 0, item, reg) \
183sysfs_w(type, 0, item, reg) \
184static DEVICE_ATTR(type##item, S_IRUGO | S_IWUSR, get_##type##0##item, set_##type##0##item);
185
186#define sysfs_ro(type, item, reg) \
187sysfs_r(type, 0, item, reg) \
188static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
189
190
191#define sysfs_vid(n) \
192sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
193
194#define sysfs_in(n) \
195sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
196sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
197sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \
198
199#define sysfs_fan(n) \
200sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
201sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
202sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
203
204#define sysfs_fan_off(n) \
205sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
206
207#define sysfs_temp(n) \
208sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
209sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
210sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST)
211
212#define sysfs_alarms() \
213sysfs_ro(alarms, , GL520_REG_ALARMS) \
214sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
215sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK)
216
217
218sysfs_vid(0)
219
220sysfs_in(0)
221sysfs_in(1)
222sysfs_in(2)
223sysfs_in(3)
224sysfs_in(4)
225
226sysfs_fan(1)
227sysfs_fan(2)
228sysfs_fan_off(1)
229
230sysfs_temp(1)
231sysfs_temp(2)
232
233sysfs_alarms()
234
235
236static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
237{ 132{
133 struct gl520_data *data = gl520_update_device(dev);
238 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 134 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
239} 135}
136static DEVICE_ATTR(cpu0_vid, S_IRUGO, get_cpu_vid, NULL);
240 137
241#define VDD_FROM_REG(val) (((val)*95+2)/4) 138#define VDD_FROM_REG(val) (((val)*95+2)/4)
242#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255)) 139#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255))
@@ -244,8 +141,11 @@ static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
244#define IN_FROM_REG(val) ((val)*19) 141#define IN_FROM_REG(val) ((val)*19)
245#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255)) 142#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255))
246 143
247static ssize_t get_in_input(struct gl520_data *data, char *buf, int n) 144static ssize_t get_in_input(struct device *dev, struct device_attribute *attr,
145 char *buf)
248{ 146{
147 int n = to_sensor_dev_attr(attr)->index;
148 struct gl520_data *data = gl520_update_device(dev);
249 u8 r = data->in_input[n]; 149 u8 r = data->in_input[n];
250 150
251 if (n == 0) 151 if (n == 0)
@@ -254,8 +154,11 @@ static ssize_t get_in_input(struct gl520_data *data, char *buf, int n)
254 return sprintf(buf, "%d\n", IN_FROM_REG(r)); 154 return sprintf(buf, "%d\n", IN_FROM_REG(r));
255} 155}
256 156
257static ssize_t get_in_min(struct gl520_data *data, char *buf, int n) 157static ssize_t get_in_min(struct device *dev, struct device_attribute *attr,
158 char *buf)
258{ 159{
160 int n = to_sensor_dev_attr(attr)->index;
161 struct gl520_data *data = gl520_update_device(dev);
259 u8 r = data->in_min[n]; 162 u8 r = data->in_min[n];
260 163
261 if (n == 0) 164 if (n == 0)
@@ -264,8 +167,11 @@ static ssize_t get_in_min(struct gl520_data *data, char *buf, int n)
264 return sprintf(buf, "%d\n", IN_FROM_REG(r)); 167 return sprintf(buf, "%d\n", IN_FROM_REG(r));
265} 168}
266 169
267static ssize_t get_in_max(struct gl520_data *data, char *buf, int n) 170static ssize_t get_in_max(struct device *dev, struct device_attribute *attr,
171 char *buf)
268{ 172{
173 int n = to_sensor_dev_attr(attr)->index;
174 struct gl520_data *data = gl520_update_device(dev);
269 u8 r = data->in_max[n]; 175 u8 r = data->in_max[n];
270 176
271 if (n == 0) 177 if (n == 0)
@@ -274,8 +180,12 @@ static ssize_t get_in_max(struct gl520_data *data, char *buf, int n)
274 return sprintf(buf, "%d\n", IN_FROM_REG(r)); 180 return sprintf(buf, "%d\n", IN_FROM_REG(r));
275} 181}
276 182
277static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 183static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
184 const char *buf, size_t count)
278{ 185{
186 struct i2c_client *client = to_i2c_client(dev);
187 struct gl520_data *data = i2c_get_clientdata(client);
188 int n = to_sensor_dev_attr(attr)->index;
279 long v = simple_strtol(buf, NULL, 10); 189 long v = simple_strtol(buf, NULL, 10);
280 u8 r; 190 u8 r;
281 191
@@ -289,16 +199,22 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co
289 data->in_min[n] = r; 199 data->in_min[n] = r;
290 200
291 if (n < 4) 201 if (n < 4)
292 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r); 202 gl520_write_value(client, GL520_REG_IN_MIN[n],
203 (gl520_read_value(client, GL520_REG_IN_MIN[n])
204 & ~0xff) | r);
293 else 205 else
294 gl520_write_value(client, reg, r); 206 gl520_write_value(client, GL520_REG_IN_MIN[n], r);
295 207
296 mutex_unlock(&data->update_lock); 208 mutex_unlock(&data->update_lock);
297 return count; 209 return count;
298} 210}
299 211
300static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 212static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
213 const char *buf, size_t count)
301{ 214{
215 struct i2c_client *client = to_i2c_client(dev);
216 struct gl520_data *data = i2c_get_clientdata(client);
217 int n = to_sensor_dev_attr(attr)->index;
302 long v = simple_strtol(buf, NULL, 10); 218 long v = simple_strtol(buf, NULL, 10);
303 u8 r; 219 u8 r;
304 220
@@ -312,57 +228,109 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co
312 data->in_max[n] = r; 228 data->in_max[n] = r;
313 229
314 if (n < 4) 230 if (n < 4)
315 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8)); 231 gl520_write_value(client, GL520_REG_IN_MAX[n],
232 (gl520_read_value(client, GL520_REG_IN_MAX[n])
233 & ~0xff00) | (r << 8));
316 else 234 else
317 gl520_write_value(client, reg, r); 235 gl520_write_value(client, GL520_REG_IN_MAX[n], r);
318 236
319 mutex_unlock(&data->update_lock); 237 mutex_unlock(&data->update_lock);
320 return count; 238 return count;
321} 239}
322 240
241static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, get_in_input, NULL, 0);
242static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, get_in_input, NULL, 1);
243static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, get_in_input, NULL, 2);
244static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, get_in_input, NULL, 3);
245static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, get_in_input, NULL, 4);
246static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
247 get_in_min, set_in_min, 0);
248static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR,
249 get_in_min, set_in_min, 1);
250static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR,
251 get_in_min, set_in_min, 2);
252static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR,
253 get_in_min, set_in_min, 3);
254static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR,
255 get_in_min, set_in_min, 4);
256static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
257 get_in_max, set_in_max, 0);
258static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
259 get_in_max, set_in_max, 1);
260static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR,
261 get_in_max, set_in_max, 2);
262static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR,
263 get_in_max, set_in_max, 3);
264static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
265 get_in_max, set_in_max, 4);
266
323#define DIV_FROM_REG(val) (1 << (val)) 267#define DIV_FROM_REG(val) (1 << (val))
324#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div)))) 268#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div))))
325#define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255)); 269#define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255));
326 270
327static ssize_t get_fan_input(struct gl520_data *data, char *buf, int n) 271static ssize_t get_fan_input(struct device *dev, struct device_attribute *attr,
272 char *buf)
328{ 273{
329 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n - 1], data->fan_div[n - 1])); 274 int n = to_sensor_dev_attr(attr)->index;
275 struct gl520_data *data = gl520_update_device(dev);
276
277 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n],
278 data->fan_div[n]));
330} 279}
331 280
332static ssize_t get_fan_min(struct gl520_data *data, char *buf, int n) 281static ssize_t get_fan_min(struct device *dev, struct device_attribute *attr,
282 char *buf)
333{ 283{
334 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n - 1], data->fan_div[n - 1])); 284 int n = to_sensor_dev_attr(attr)->index;
285 struct gl520_data *data = gl520_update_device(dev);
286
287 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n],
288 data->fan_div[n]));
335} 289}
336 290
337static ssize_t get_fan_div(struct gl520_data *data, char *buf, int n) 291static ssize_t get_fan_div(struct device *dev, struct device_attribute *attr,
292 char *buf)
338{ 293{
339 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n - 1])); 294 int n = to_sensor_dev_attr(attr)->index;
295 struct gl520_data *data = gl520_update_device(dev);
296
297 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n]));
340} 298}
341 299
342static ssize_t get_fan_off(struct gl520_data *data, char *buf, int n) 300static ssize_t get_fan_off(struct device *dev, struct device_attribute *attr,
301 char *buf)
343{ 302{
303 struct gl520_data *data = gl520_update_device(dev);
344 return sprintf(buf, "%d\n", data->fan_off); 304 return sprintf(buf, "%d\n", data->fan_off);
345} 305}
346 306
347static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 307static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
308 const char *buf, size_t count)
348{ 309{
310 struct i2c_client *client = to_i2c_client(dev);
311 struct gl520_data *data = i2c_get_clientdata(client);
312 int n = to_sensor_dev_attr(attr)->index;
349 unsigned long v = simple_strtoul(buf, NULL, 10); 313 unsigned long v = simple_strtoul(buf, NULL, 10);
350 u8 r; 314 u8 r;
351 315
352 mutex_lock(&data->update_lock); 316 mutex_lock(&data->update_lock);
353 r = FAN_TO_REG(v, data->fan_div[n - 1]); 317 r = FAN_TO_REG(v, data->fan_div[n]);
354 data->fan_min[n - 1] = r; 318 data->fan_min[n] = r;
355 319
356 if (n == 1) 320 if (n == 0)
357 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8)); 321 gl520_write_value(client, GL520_REG_FAN_MIN,
322 (gl520_read_value(client, GL520_REG_FAN_MIN)
323 & ~0xff00) | (r << 8));
358 else 324 else
359 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r); 325 gl520_write_value(client, GL520_REG_FAN_MIN,
326 (gl520_read_value(client, GL520_REG_FAN_MIN)
327 & ~0xff) | r);
360 328
361 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); 329 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
362 if (data->fan_min[n - 1] == 0) 330 if (data->fan_min[n] == 0)
363 data->alarm_mask &= (n == 1) ? ~0x20 : ~0x40; 331 data->alarm_mask &= (n == 0) ? ~0x20 : ~0x40;
364 else 332 else
365 data->alarm_mask |= (n == 1) ? 0x20 : 0x40; 333 data->alarm_mask |= (n == 0) ? 0x20 : 0x40;
366 data->beep_mask &= data->alarm_mask; 334 data->beep_mask &= data->alarm_mask;
367 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); 335 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
368 336
@@ -370,8 +338,12 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c
370 return count; 338 return count;
371} 339}
372 340
373static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 341static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
342 const char *buf, size_t count)
374{ 343{
344 struct i2c_client *client = to_i2c_client(dev);
345 struct gl520_data *data = i2c_get_clientdata(client);
346 int n = to_sensor_dev_attr(attr)->index;
375 unsigned long v = simple_strtoul(buf, NULL, 10); 347 unsigned long v = simple_strtoul(buf, NULL, 10);
376 u8 r; 348 u8 r;
377 349
@@ -386,133 +358,282 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c
386 } 358 }
387 359
388 mutex_lock(&data->update_lock); 360 mutex_lock(&data->update_lock);
389 data->fan_div[n - 1] = r; 361 data->fan_div[n] = r;
390 362
391 if (n == 1) 363 if (n == 0)
392 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xc0) | (r << 6)); 364 gl520_write_value(client, GL520_REG_FAN_DIV,
365 (gl520_read_value(client, GL520_REG_FAN_DIV)
366 & ~0xc0) | (r << 6));
393 else 367 else
394 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4)); 368 gl520_write_value(client, GL520_REG_FAN_DIV,
369 (gl520_read_value(client, GL520_REG_FAN_DIV)
370 & ~0x30) | (r << 4));
395 371
396 mutex_unlock(&data->update_lock); 372 mutex_unlock(&data->update_lock);
397 return count; 373 return count;
398} 374}
399 375
400static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 376static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr,
377 const char *buf, size_t count)
401{ 378{
379 struct i2c_client *client = to_i2c_client(dev);
380 struct gl520_data *data = i2c_get_clientdata(client);
402 u8 r = simple_strtoul(buf, NULL, 10)?1:0; 381 u8 r = simple_strtoul(buf, NULL, 10)?1:0;
403 382
404 mutex_lock(&data->update_lock); 383 mutex_lock(&data->update_lock);
405 data->fan_off = r; 384 data->fan_off = r;
406 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2)); 385 gl520_write_value(client, GL520_REG_FAN_OFF,
386 (gl520_read_value(client, GL520_REG_FAN_OFF)
387 & ~0x0c) | (r << 2));
407 mutex_unlock(&data->update_lock); 388 mutex_unlock(&data->update_lock);
408 return count; 389 return count;
409} 390}
410 391
392static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, get_fan_input, NULL, 0);
393static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, get_fan_input, NULL, 1);
394static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
395 get_fan_min, set_fan_min, 0);
396static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
397 get_fan_min, set_fan_min, 1);
398static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
399 get_fan_div, set_fan_div, 0);
400static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
401 get_fan_div, set_fan_div, 1);
402static DEVICE_ATTR(fan1_off, S_IRUGO | S_IWUSR,
403 get_fan_off, set_fan_off);
404
411#define TEMP_FROM_REG(val) (((val) - 130) * 1000) 405#define TEMP_FROM_REG(val) (((val) - 130) * 1000)
412#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255)) 406#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255))
413 407
414static ssize_t get_temp_input(struct gl520_data *data, char *buf, int n) 408static ssize_t get_temp_input(struct device *dev, struct device_attribute *attr,
409 char *buf)
415{ 410{
416 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n - 1])); 411 int n = to_sensor_dev_attr(attr)->index;
412 struct gl520_data *data = gl520_update_device(dev);
413
414 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n]));
417} 415}
418 416
419static ssize_t get_temp_max(struct gl520_data *data, char *buf, int n) 417static ssize_t get_temp_max(struct device *dev, struct device_attribute *attr,
418 char *buf)
420{ 419{
421 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n - 1])); 420 int n = to_sensor_dev_attr(attr)->index;
421 struct gl520_data *data = gl520_update_device(dev);
422
423 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n]));
422} 424}
423 425
424static ssize_t get_temp_max_hyst(struct gl520_data *data, char *buf, int n) 426static ssize_t get_temp_max_hyst(struct device *dev, struct device_attribute
427 *attr, char *buf)
425{ 428{
426 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n - 1])); 429 int n = to_sensor_dev_attr(attr)->index;
430 struct gl520_data *data = gl520_update_device(dev);
431
432 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n]));
427} 433}
428 434
429static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 435static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
436 const char *buf, size_t count)
430{ 437{
438 struct i2c_client *client = to_i2c_client(dev);
439 struct gl520_data *data = i2c_get_clientdata(client);
440 int n = to_sensor_dev_attr(attr)->index;
431 long v = simple_strtol(buf, NULL, 10); 441 long v = simple_strtol(buf, NULL, 10);
432 442
433 mutex_lock(&data->update_lock); 443 mutex_lock(&data->update_lock);
434 data->temp_max[n - 1] = TEMP_TO_REG(v); 444 data->temp_max[n] = TEMP_TO_REG(v);
435 gl520_write_value(client, reg, data->temp_max[n - 1]); 445 gl520_write_value(client, GL520_REG_TEMP_MAX[n], data->temp_max[n]);
436 mutex_unlock(&data->update_lock); 446 mutex_unlock(&data->update_lock);
437 return count; 447 return count;
438} 448}
439 449
440static ssize_t set_temp_max_hyst(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 450static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute
451 *attr, const char *buf, size_t count)
441{ 452{
453 struct i2c_client *client = to_i2c_client(dev);
454 struct gl520_data *data = i2c_get_clientdata(client);
455 int n = to_sensor_dev_attr(attr)->index;
442 long v = simple_strtol(buf, NULL, 10); 456 long v = simple_strtol(buf, NULL, 10);
443 457
444 mutex_lock(&data->update_lock); 458 mutex_lock(&data->update_lock);
445 data->temp_max_hyst[n - 1] = TEMP_TO_REG(v); 459 data->temp_max_hyst[n] = TEMP_TO_REG(v);
446 gl520_write_value(client, reg, data->temp_max_hyst[n - 1]); 460 gl520_write_value(client, GL520_REG_TEMP_MAX_HYST[n],
461 data->temp_max_hyst[n]);
447 mutex_unlock(&data->update_lock); 462 mutex_unlock(&data->update_lock);
448 return count; 463 return count;
449} 464}
450 465
451static ssize_t get_alarms(struct gl520_data *data, char *buf, int n) 466static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, get_temp_input, NULL, 0);
467static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, get_temp_input, NULL, 1);
468static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
469 get_temp_max, set_temp_max, 0);
470static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
471 get_temp_max, set_temp_max, 1);
472static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
473 get_temp_max_hyst, set_temp_max_hyst, 0);
474static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
475 get_temp_max_hyst, set_temp_max_hyst, 1);
476
477static ssize_t get_alarms(struct device *dev, struct device_attribute *attr,
478 char *buf)
452{ 479{
480 struct gl520_data *data = gl520_update_device(dev);
453 return sprintf(buf, "%d\n", data->alarms); 481 return sprintf(buf, "%d\n", data->alarms);
454} 482}
455 483
456static ssize_t get_beep_enable(struct gl520_data *data, char *buf, int n) 484static ssize_t get_beep_enable(struct device *dev, struct device_attribute
485 *attr, char *buf)
457{ 486{
487 struct gl520_data *data = gl520_update_device(dev);
458 return sprintf(buf, "%d\n", data->beep_enable); 488 return sprintf(buf, "%d\n", data->beep_enable);
459} 489}
460 490
461static ssize_t get_beep_mask(struct gl520_data *data, char *buf, int n) 491static ssize_t get_beep_mask(struct device *dev, struct device_attribute *attr,
492 char *buf)
462{ 493{
494 struct gl520_data *data = gl520_update_device(dev);
463 return sprintf(buf, "%d\n", data->beep_mask); 495 return sprintf(buf, "%d\n", data->beep_mask);
464} 496}
465 497
466static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 498static ssize_t set_beep_enable(struct device *dev, struct device_attribute
499 *attr, const char *buf, size_t count)
467{ 500{
501 struct i2c_client *client = to_i2c_client(dev);
502 struct gl520_data *data = i2c_get_clientdata(client);
468 u8 r = simple_strtoul(buf, NULL, 10)?0:1; 503 u8 r = simple_strtoul(buf, NULL, 10)?0:1;
469 504
470 mutex_lock(&data->update_lock); 505 mutex_lock(&data->update_lock);
471 data->beep_enable = !r; 506 data->beep_enable = !r;
472 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2)); 507 gl520_write_value(client, GL520_REG_BEEP_ENABLE,
508 (gl520_read_value(client, GL520_REG_BEEP_ENABLE)
509 & ~0x04) | (r << 2));
473 mutex_unlock(&data->update_lock); 510 mutex_unlock(&data->update_lock);
474 return count; 511 return count;
475} 512}
476 513
477static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg) 514static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr,
515 const char *buf, size_t count)
478{ 516{
517 struct i2c_client *client = to_i2c_client(dev);
518 struct gl520_data *data = i2c_get_clientdata(client);
479 u8 r = simple_strtoul(buf, NULL, 10); 519 u8 r = simple_strtoul(buf, NULL, 10);
480 520
481 mutex_lock(&data->update_lock); 521 mutex_lock(&data->update_lock);
482 r &= data->alarm_mask; 522 r &= data->alarm_mask;
483 data->beep_mask = r; 523 data->beep_mask = r;
484 gl520_write_value(client, reg, r); 524 gl520_write_value(client, GL520_REG_BEEP_MASK, r);
525 mutex_unlock(&data->update_lock);
526 return count;
527}
528
529static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
530static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
531 get_beep_enable, set_beep_enable);
532static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
533 get_beep_mask, set_beep_mask);
534
535static ssize_t get_alarm(struct device *dev, struct device_attribute *attr,
536 char *buf)
537{
538 int bit_nr = to_sensor_dev_attr(attr)->index;
539 struct gl520_data *data = gl520_update_device(dev);
540
541 return sprintf(buf, "%d\n", (data->alarms >> bit_nr) & 1);
542}
543
544static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, get_alarm, NULL, 0);
545static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, get_alarm, NULL, 1);
546static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, get_alarm, NULL, 2);
547static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, get_alarm, NULL, 3);
548static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, get_alarm, NULL, 4);
549static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, get_alarm, NULL, 5);
550static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, get_alarm, NULL, 6);
551static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, get_alarm, NULL, 7);
552static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, get_alarm, NULL, 7);
553
554static ssize_t get_beep(struct device *dev, struct device_attribute *attr,
555 char *buf)
556{
557 int bitnr = to_sensor_dev_attr(attr)->index;
558 struct gl520_data *data = gl520_update_device(dev);
559
560 return sprintf(buf, "%d\n", (data->beep_mask >> bitnr) & 1);
561}
562
563static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
564 const char *buf, size_t count)
565{
566 struct i2c_client *client = to_i2c_client(dev);
567 struct gl520_data *data = i2c_get_clientdata(client);
568 int bitnr = to_sensor_dev_attr(attr)->index;
569 unsigned long bit;
570
571 bit = simple_strtoul(buf, NULL, 10);
572 if (bit & ~1)
573 return -EINVAL;
574
575 mutex_lock(&data->update_lock);
576 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
577 if (bit)
578 data->beep_mask |= (1 << bitnr);
579 else
580 data->beep_mask &= ~(1 << bitnr);
581 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
485 mutex_unlock(&data->update_lock); 582 mutex_unlock(&data->update_lock);
486 return count; 583 return count;
487} 584}
488 585
586static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 0);
587static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 1);
588static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 2);
589static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 3);
590static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 4);
591static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 5);
592static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 6);
593static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 7);
594static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 7);
595
489static struct attribute *gl520_attributes[] = { 596static struct attribute *gl520_attributes[] = {
490 &dev_attr_cpu0_vid.attr, 597 &dev_attr_cpu0_vid.attr,
491 598
492 &dev_attr_in0_input.attr, 599 &sensor_dev_attr_in0_input.dev_attr.attr,
493 &dev_attr_in0_min.attr, 600 &sensor_dev_attr_in0_min.dev_attr.attr,
494 &dev_attr_in0_max.attr, 601 &sensor_dev_attr_in0_max.dev_attr.attr,
495 &dev_attr_in1_input.attr, 602 &sensor_dev_attr_in0_alarm.dev_attr.attr,
496 &dev_attr_in1_min.attr, 603 &sensor_dev_attr_in0_beep.dev_attr.attr,
497 &dev_attr_in1_max.attr, 604 &sensor_dev_attr_in1_input.dev_attr.attr,
498 &dev_attr_in2_input.attr, 605 &sensor_dev_attr_in1_min.dev_attr.attr,
499 &dev_attr_in2_min.attr, 606 &sensor_dev_attr_in1_max.dev_attr.attr,
500 &dev_attr_in2_max.attr, 607 &sensor_dev_attr_in1_alarm.dev_attr.attr,
501 &dev_attr_in3_input.attr, 608 &sensor_dev_attr_in1_beep.dev_attr.attr,
502 &dev_attr_in3_min.attr, 609 &sensor_dev_attr_in2_input.dev_attr.attr,
503 &dev_attr_in3_max.attr, 610 &sensor_dev_attr_in2_min.dev_attr.attr,
504 611 &sensor_dev_attr_in2_max.dev_attr.attr,
505 &dev_attr_fan1_input.attr, 612 &sensor_dev_attr_in2_alarm.dev_attr.attr,
506 &dev_attr_fan1_min.attr, 613 &sensor_dev_attr_in2_beep.dev_attr.attr,
507 &dev_attr_fan1_div.attr, 614 &sensor_dev_attr_in3_input.dev_attr.attr,
615 &sensor_dev_attr_in3_min.dev_attr.attr,
616 &sensor_dev_attr_in3_max.dev_attr.attr,
617 &sensor_dev_attr_in3_alarm.dev_attr.attr,
618 &sensor_dev_attr_in3_beep.dev_attr.attr,
619
620 &sensor_dev_attr_fan1_input.dev_attr.attr,
621 &sensor_dev_attr_fan1_min.dev_attr.attr,
622 &sensor_dev_attr_fan1_div.dev_attr.attr,
623 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
624 &sensor_dev_attr_fan1_beep.dev_attr.attr,
508 &dev_attr_fan1_off.attr, 625 &dev_attr_fan1_off.attr,
509 &dev_attr_fan2_input.attr, 626 &sensor_dev_attr_fan2_input.dev_attr.attr,
510 &dev_attr_fan2_min.attr, 627 &sensor_dev_attr_fan2_min.dev_attr.attr,
511 &dev_attr_fan2_div.attr, 628 &sensor_dev_attr_fan2_div.dev_attr.attr,
512 629 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
513 &dev_attr_temp1_input.attr, 630 &sensor_dev_attr_fan2_beep.dev_attr.attr,
514 &dev_attr_temp1_max.attr, 631
515 &dev_attr_temp1_max_hyst.attr, 632 &sensor_dev_attr_temp1_input.dev_attr.attr,
633 &sensor_dev_attr_temp1_max.dev_attr.attr,
634 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
635 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
636 &sensor_dev_attr_temp1_beep.dev_attr.attr,
516 637
517 &dev_attr_alarms.attr, 638 &dev_attr_alarms.attr,
518 &dev_attr_beep_enable.attr, 639 &dev_attr_beep_enable.attr,
@@ -525,13 +646,17 @@ static const struct attribute_group gl520_group = {
525}; 646};
526 647
527static struct attribute *gl520_attributes_opt[] = { 648static struct attribute *gl520_attributes_opt[] = {
528 &dev_attr_in4_input.attr, 649 &sensor_dev_attr_in4_input.dev_attr.attr,
529 &dev_attr_in4_min.attr, 650 &sensor_dev_attr_in4_min.dev_attr.attr,
530 &dev_attr_in4_max.attr, 651 &sensor_dev_attr_in4_max.dev_attr.attr,
531 652 &sensor_dev_attr_in4_alarm.dev_attr.attr,
532 &dev_attr_temp2_input.attr, 653 &sensor_dev_attr_in4_beep.dev_attr.attr,
533 &dev_attr_temp2_max.attr, 654
534 &dev_attr_temp2_max_hyst.attr, 655 &sensor_dev_attr_temp2_input.dev_attr.attr,
656 &sensor_dev_attr_temp2_max.dev_attr.attr,
657 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
658 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
659 &sensor_dev_attr_temp2_beep.dev_attr.attr,
535 NULL 660 NULL
536}; 661};
537 662
@@ -553,7 +678,7 @@ static int gl520_attach_adapter(struct i2c_adapter *adapter)
553 678
554static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) 679static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
555{ 680{
556 struct i2c_client *new_client; 681 struct i2c_client *client;
557 struct gl520_data *data; 682 struct gl520_data *data;
558 int err = 0; 683 int err = 0;
559 684
@@ -570,59 +695,65 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
570 goto exit; 695 goto exit;
571 } 696 }
572 697
573 new_client = &data->client; 698 client = &data->client;
574 i2c_set_clientdata(new_client, data); 699 i2c_set_clientdata(client, data);
575 new_client->addr = address; 700 client->addr = address;
576 new_client->adapter = adapter; 701 client->adapter = adapter;
577 new_client->driver = &gl520_driver; 702 client->driver = &gl520_driver;
578 new_client->flags = 0;
579 703
580 /* Determine the chip type. */ 704 /* Determine the chip type. */
581 if (kind < 0) { 705 if (kind < 0) {
582 if ((gl520_read_value(new_client, GL520_REG_CHIP_ID) != 0x20) || 706 if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) ||
583 ((gl520_read_value(new_client, GL520_REG_REVISION) & 0x7f) != 0x00) || 707 ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
584 ((gl520_read_value(new_client, GL520_REG_CONF) & 0x80) != 0x00)) { 708 ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) {
585 dev_dbg(&new_client->dev, "Unknown chip type, skipping\n"); 709 dev_dbg(&client->dev, "Unknown chip type, skipping\n");
586 goto exit_free; 710 goto exit_free;
587 } 711 }
588 } 712 }
589 713
590 /* Fill in the remaining client fields */ 714 /* Fill in the remaining client fields */
591 strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE); 715 strlcpy(client->name, "gl520sm", I2C_NAME_SIZE);
592 data->valid = 0;
593 mutex_init(&data->update_lock); 716 mutex_init(&data->update_lock);
594 717
595 /* Tell the I2C layer a new client has arrived */ 718 /* Tell the I2C layer a new client has arrived */
596 if ((err = i2c_attach_client(new_client))) 719 if ((err = i2c_attach_client(client)))
597 goto exit_free; 720 goto exit_free;
598 721
599 /* Initialize the GL520SM chip */ 722 /* Initialize the GL520SM chip */
600 gl520_init_client(new_client); 723 gl520_init_client(client);
601 724
602 /* Register sysfs hooks */ 725 /* Register sysfs hooks */
603 if ((err = sysfs_create_group(&new_client->dev.kobj, &gl520_group))) 726 if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group)))
604 goto exit_detach; 727 goto exit_detach;
605 728
606 if (data->two_temps) { 729 if (data->two_temps) {
607 if ((err = device_create_file(&new_client->dev, 730 if ((err = device_create_file(&client->dev,
608 &dev_attr_temp2_input)) 731 &sensor_dev_attr_temp2_input.dev_attr))
609 || (err = device_create_file(&new_client->dev, 732 || (err = device_create_file(&client->dev,
610 &dev_attr_temp2_max)) 733 &sensor_dev_attr_temp2_max.dev_attr))
611 || (err = device_create_file(&new_client->dev, 734 || (err = device_create_file(&client->dev,
612 &dev_attr_temp2_max_hyst))) 735 &sensor_dev_attr_temp2_max_hyst.dev_attr))
736 || (err = device_create_file(&client->dev,
737 &sensor_dev_attr_temp2_alarm.dev_attr))
738 || (err = device_create_file(&client->dev,
739 &sensor_dev_attr_temp2_beep.dev_attr)))
613 goto exit_remove_files; 740 goto exit_remove_files;
614 } else { 741 } else {
615 if ((err = device_create_file(&new_client->dev, 742 if ((err = device_create_file(&client->dev,
616 &dev_attr_in4_input)) 743 &sensor_dev_attr_in4_input.dev_attr))
617 || (err = device_create_file(&new_client->dev, 744 || (err = device_create_file(&client->dev,
618 &dev_attr_in4_min)) 745 &sensor_dev_attr_in4_min.dev_attr))
619 || (err = device_create_file(&new_client->dev, 746 || (err = device_create_file(&client->dev,
620 &dev_attr_in4_max))) 747 &sensor_dev_attr_in4_max.dev_attr))
748 || (err = device_create_file(&client->dev,
749 &sensor_dev_attr_in4_alarm.dev_attr))
750 || (err = device_create_file(&client->dev,
751 &sensor_dev_attr_in4_beep.dev_attr)))
621 goto exit_remove_files; 752 goto exit_remove_files;
622 } 753 }
623 754
624 755
625 data->hwmon_dev = hwmon_device_register(&new_client->dev); 756 data->hwmon_dev = hwmon_device_register(&client->dev);
626 if (IS_ERR(data->hwmon_dev)) { 757 if (IS_ERR(data->hwmon_dev)) {
627 err = PTR_ERR(data->hwmon_dev); 758 err = PTR_ERR(data->hwmon_dev);
628 goto exit_remove_files; 759 goto exit_remove_files;
@@ -631,10 +762,10 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
631 return 0; 762 return 0;
632 763
633exit_remove_files: 764exit_remove_files:
634 sysfs_remove_group(&new_client->dev.kobj, &gl520_group); 765 sysfs_remove_group(&client->dev.kobj, &gl520_group);
635 sysfs_remove_group(&new_client->dev.kobj, &gl520_group_opt); 766 sysfs_remove_group(&client->dev.kobj, &gl520_group_opt);
636exit_detach: 767exit_detach:
637 i2c_detach_client(new_client); 768 i2c_detach_client(client);
638exit_free: 769exit_free:
639 kfree(data); 770 kfree(data);
640exit: 771exit:
@@ -697,7 +828,7 @@ static int gl520_detach_client(struct i2c_client *client)
697} 828}
698 829
699 830
700/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 831/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
701 GL520 uses a high-byte first convention */ 832 GL520 uses a high-byte first convention */
702static int gl520_read_value(struct i2c_client *client, u8 reg) 833static int gl520_read_value(struct i2c_client *client, u8 reg)
703{ 834{
@@ -720,7 +851,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
720{ 851{
721 struct i2c_client *client = to_i2c_client(dev); 852 struct i2c_client *client = to_i2c_client(dev);
722 struct gl520_data *data = i2c_get_clientdata(client); 853 struct gl520_data *data = i2c_get_clientdata(client);
723 int val; 854 int val, i;
724 855
725 mutex_lock(&data->update_lock); 856 mutex_lock(&data->update_lock);
726 857
@@ -732,18 +863,13 @@ static struct gl520_data *gl520_update_device(struct device *dev)
732 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); 863 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
733 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f; 864 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f;
734 865
735 val = gl520_read_value(client, GL520_REG_IN0_LIMIT); 866 for (i = 0; i < 4; i++) {
736 data->in_min[0] = val & 0xff; 867 data->in_input[i] = gl520_read_value(client,
737 data->in_max[0] = (val >> 8) & 0xff; 868 GL520_REG_IN_INPUT[i]);
738 val = gl520_read_value(client, GL520_REG_IN1_LIMIT); 869 val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
739 data->in_min[1] = val & 0xff; 870 data->in_min[i] = val & 0xff;
740 data->in_max[1] = (val >> 8) & 0xff; 871 data->in_max[i] = (val >> 8) & 0xff;
741 val = gl520_read_value(client, GL520_REG_IN2_LIMIT); 872 }
742 data->in_min[2] = val & 0xff;
743 data->in_max[2] = (val >> 8) & 0xff;
744 val = gl520_read_value(client, GL520_REG_IN3_LIMIT);
745 data->in_min[3] = val & 0xff;
746 data->in_max[3] = (val >> 8) & 0xff;
747 873
748 val = gl520_read_value(client, GL520_REG_FAN_INPUT); 874 val = gl520_read_value(client, GL520_REG_FAN_INPUT);
749 data->fan_input[0] = (val >> 8) & 0xff; 875 data->fan_input[0] = (val >> 8) & 0xff;
@@ -753,9 +879,12 @@ static struct gl520_data *gl520_update_device(struct device *dev)
753 data->fan_min[0] = (val >> 8) & 0xff; 879 data->fan_min[0] = (val >> 8) & 0xff;
754 data->fan_min[1] = val & 0xff; 880 data->fan_min[1] = val & 0xff;
755 881
756 data->temp_input[0] = gl520_read_value(client, GL520_REG_TEMP1_INPUT); 882 data->temp_input[0] = gl520_read_value(client,
757 data->temp_max[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX); 883 GL520_REG_TEMP_INPUT[0]);
758 data->temp_max_hyst[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX_HYST); 884 data->temp_max[0] = gl520_read_value(client,
885 GL520_REG_TEMP_MAX[0]);
886 data->temp_max_hyst[0] = gl520_read_value(client,
887 GL520_REG_TEMP_MAX_HYST[0]);
759 888
760 val = gl520_read_value(client, GL520_REG_FAN_DIV); 889 val = gl520_read_value(client, GL520_REG_FAN_DIV);
761 data->fan_div[0] = (val >> 6) & 0x03; 890 data->fan_div[0] = (val >> 6) & 0x03;
@@ -767,20 +896,21 @@ static struct gl520_data *gl520_update_device(struct device *dev)
767 val = gl520_read_value(client, GL520_REG_CONF); 896 val = gl520_read_value(client, GL520_REG_CONF);
768 data->beep_enable = !((val >> 2) & 1); 897 data->beep_enable = !((val >> 2) & 1);
769 898
770 data->in_input[0] = gl520_read_value(client, GL520_REG_IN0_INPUT);
771 data->in_input[1] = gl520_read_value(client, GL520_REG_IN1_INPUT);
772 data->in_input[2] = gl520_read_value(client, GL520_REG_IN2_INPUT);
773 data->in_input[3] = gl520_read_value(client, GL520_REG_IN3_INPUT);
774
775 /* Temp1 and Vin4 are the same input */ 899 /* Temp1 and Vin4 are the same input */
776 if (data->two_temps) { 900 if (data->two_temps) {
777 data->temp_input[1] = gl520_read_value(client, GL520_REG_TEMP2_INPUT); 901 data->temp_input[1] = gl520_read_value(client,
778 data->temp_max[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX); 902 GL520_REG_TEMP_INPUT[1]);
779 data->temp_max_hyst[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX_HYST); 903 data->temp_max[1] = gl520_read_value(client,
904 GL520_REG_TEMP_MAX[1]);
905 data->temp_max_hyst[1] = gl520_read_value(client,
906 GL520_REG_TEMP_MAX_HYST[1]);
780 } else { 907 } else {
781 data->in_input[4] = gl520_read_value(client, GL520_REG_IN4_INPUT); 908 data->in_input[4] = gl520_read_value(client,
782 data->in_min[4] = gl520_read_value(client, GL520_REG_IN4_MIN); 909 GL520_REG_IN_INPUT[4]);
783 data->in_max[4] = gl520_read_value(client, GL520_REG_IN4_MAX); 910 data->in_min[4] = gl520_read_value(client,
911 GL520_REG_IN_MIN[4]);
912 data->in_max[4] = gl520_read_value(client,
913 GL520_REG_IN_MAX[4]);
784 } 914 }
785 915
786 data->last_updated = jiffies; 916 data->last_updated = jiffies;
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index ad6c8a319903..e12c132ff83a 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -17,8 +17,8 @@
17 IT8726F Super I/O chip w/LPC interface 17 IT8726F Super I/O chip w/LPC interface
18 Sis950 A clone of the IT8705F 18 Sis950 A clone of the IT8705F
19 19
20 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> 20 Copyright (C) 2001 Chris Gauthron
21 Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org> 21 Copyright (C) 2005-2007 Jean Delvare <khali@linux-fr.org>
22 22
23 This program is free software; you can redistribute it and/or modify 23 This program is free software; you can redistribute it and/or modify
24 it under the terms of the GNU General Public License as published by 24 it under the terms of the GNU General Public License as published by
@@ -52,6 +52,10 @@
52 52
53enum chips { it87, it8712, it8716, it8718 }; 53enum chips { it87, it8712, it8716, it8718 };
54 54
55static unsigned short force_id;
56module_param(force_id, ushort, 0);
57MODULE_PARM_DESC(force_id, "Override the detected device ID");
58
55static struct platform_device *pdev; 59static struct platform_device *pdev;
56 60
57#define REG 0x2e /* The register to read/write */ 61#define REG 0x2e /* The register to read/write */
@@ -776,6 +780,30 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
776} 780}
777static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 781static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
778 782
783static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
784 char *buf)
785{
786 int bitnr = to_sensor_dev_attr(attr)->index;
787 struct it87_data *data = it87_update_device(dev);
788 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
789}
790static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
791static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
792static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
793static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
794static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
795static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
796static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
797static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
798static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
799static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
800static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
801static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
802static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
803static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
804static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
805static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
806
779static ssize_t 807static ssize_t
780show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 808show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
781{ 809{
@@ -837,6 +865,14 @@ static struct attribute *it87_attributes[] = {
837 &sensor_dev_attr_in5_max.dev_attr.attr, 865 &sensor_dev_attr_in5_max.dev_attr.attr,
838 &sensor_dev_attr_in6_max.dev_attr.attr, 866 &sensor_dev_attr_in6_max.dev_attr.attr,
839 &sensor_dev_attr_in7_max.dev_attr.attr, 867 &sensor_dev_attr_in7_max.dev_attr.attr,
868 &sensor_dev_attr_in0_alarm.dev_attr.attr,
869 &sensor_dev_attr_in1_alarm.dev_attr.attr,
870 &sensor_dev_attr_in2_alarm.dev_attr.attr,
871 &sensor_dev_attr_in3_alarm.dev_attr.attr,
872 &sensor_dev_attr_in4_alarm.dev_attr.attr,
873 &sensor_dev_attr_in5_alarm.dev_attr.attr,
874 &sensor_dev_attr_in6_alarm.dev_attr.attr,
875 &sensor_dev_attr_in7_alarm.dev_attr.attr,
840 876
841 &sensor_dev_attr_temp1_input.dev_attr.attr, 877 &sensor_dev_attr_temp1_input.dev_attr.attr,
842 &sensor_dev_attr_temp2_input.dev_attr.attr, 878 &sensor_dev_attr_temp2_input.dev_attr.attr,
@@ -850,6 +886,9 @@ static struct attribute *it87_attributes[] = {
850 &sensor_dev_attr_temp1_type.dev_attr.attr, 886 &sensor_dev_attr_temp1_type.dev_attr.attr,
851 &sensor_dev_attr_temp2_type.dev_attr.attr, 887 &sensor_dev_attr_temp2_type.dev_attr.attr,
852 &sensor_dev_attr_temp3_type.dev_attr.attr, 888 &sensor_dev_attr_temp3_type.dev_attr.attr,
889 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
890 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
891 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
853 892
854 &dev_attr_alarms.attr, 893 &dev_attr_alarms.attr,
855 &dev_attr_name.attr, 894 &dev_attr_name.attr,
@@ -882,12 +921,21 @@ static struct attribute *it87_attributes_opt[] = {
882 &sensor_dev_attr_fan3_min.dev_attr.attr, 921 &sensor_dev_attr_fan3_min.dev_attr.attr,
883 &sensor_dev_attr_fan3_div.dev_attr.attr, 922 &sensor_dev_attr_fan3_div.dev_attr.attr,
884 923
924 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
925 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
926 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
927 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
928 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
929
885 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 930 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
886 &sensor_dev_attr_pwm2_enable.dev_attr.attr, 931 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
887 &sensor_dev_attr_pwm3_enable.dev_attr.attr, 932 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
888 &sensor_dev_attr_pwm1.dev_attr.attr, 933 &sensor_dev_attr_pwm1.dev_attr.attr,
889 &sensor_dev_attr_pwm2.dev_attr.attr, 934 &sensor_dev_attr_pwm2.dev_attr.attr,
890 &sensor_dev_attr_pwm3.dev_attr.attr, 935 &sensor_dev_attr_pwm3.dev_attr.attr,
936 &dev_attr_pwm1_freq.attr,
937 &dev_attr_pwm2_freq.attr,
938 &dev_attr_pwm3_freq.attr,
891 939
892 &dev_attr_vrm.attr, 940 &dev_attr_vrm.attr,
893 &dev_attr_cpu0_vid.attr, 941 &dev_attr_cpu0_vid.attr,
@@ -906,7 +954,7 @@ static int __init it87_find(unsigned short *address,
906 u16 chip_type; 954 u16 chip_type;
907 955
908 superio_enter(); 956 superio_enter();
909 chip_type = superio_inw(DEVID); 957 chip_type = force_id ? force_id : superio_inw(DEVID);
910 958
911 switch (chip_type) { 959 switch (chip_type) {
912 case IT8705F_DEVID: 960 case IT8705F_DEVID:
@@ -1027,35 +1075,45 @@ static int __devinit it87_probe(struct platform_device *pdev)
1027 if ((err = device_create_file(dev, 1075 if ((err = device_create_file(dev,
1028 &sensor_dev_attr_fan1_input16.dev_attr)) 1076 &sensor_dev_attr_fan1_input16.dev_attr))
1029 || (err = device_create_file(dev, 1077 || (err = device_create_file(dev,
1030 &sensor_dev_attr_fan1_min16.dev_attr))) 1078 &sensor_dev_attr_fan1_min16.dev_attr))
1079 || (err = device_create_file(dev,
1080 &sensor_dev_attr_fan1_alarm.dev_attr)))
1031 goto ERROR4; 1081 goto ERROR4;
1032 } 1082 }
1033 if (data->has_fan & (1 << 1)) { 1083 if (data->has_fan & (1 << 1)) {
1034 if ((err = device_create_file(dev, 1084 if ((err = device_create_file(dev,
1035 &sensor_dev_attr_fan2_input16.dev_attr)) 1085 &sensor_dev_attr_fan2_input16.dev_attr))
1036 || (err = device_create_file(dev, 1086 || (err = device_create_file(dev,
1037 &sensor_dev_attr_fan2_min16.dev_attr))) 1087 &sensor_dev_attr_fan2_min16.dev_attr))
1088 || (err = device_create_file(dev,
1089 &sensor_dev_attr_fan2_alarm.dev_attr)))
1038 goto ERROR4; 1090 goto ERROR4;
1039 } 1091 }
1040 if (data->has_fan & (1 << 2)) { 1092 if (data->has_fan & (1 << 2)) {
1041 if ((err = device_create_file(dev, 1093 if ((err = device_create_file(dev,
1042 &sensor_dev_attr_fan3_input16.dev_attr)) 1094 &sensor_dev_attr_fan3_input16.dev_attr))
1043 || (err = device_create_file(dev, 1095 || (err = device_create_file(dev,
1044 &sensor_dev_attr_fan3_min16.dev_attr))) 1096 &sensor_dev_attr_fan3_min16.dev_attr))
1097 || (err = device_create_file(dev,
1098 &sensor_dev_attr_fan3_alarm.dev_attr)))
1045 goto ERROR4; 1099 goto ERROR4;
1046 } 1100 }
1047 if (data->has_fan & (1 << 3)) { 1101 if (data->has_fan & (1 << 3)) {
1048 if ((err = device_create_file(dev, 1102 if ((err = device_create_file(dev,
1049 &sensor_dev_attr_fan4_input16.dev_attr)) 1103 &sensor_dev_attr_fan4_input16.dev_attr))
1050 || (err = device_create_file(dev, 1104 || (err = device_create_file(dev,
1051 &sensor_dev_attr_fan4_min16.dev_attr))) 1105 &sensor_dev_attr_fan4_min16.dev_attr))
1106 || (err = device_create_file(dev,
1107 &sensor_dev_attr_fan4_alarm.dev_attr)))
1052 goto ERROR4; 1108 goto ERROR4;
1053 } 1109 }
1054 if (data->has_fan & (1 << 4)) { 1110 if (data->has_fan & (1 << 4)) {
1055 if ((err = device_create_file(dev, 1111 if ((err = device_create_file(dev,
1056 &sensor_dev_attr_fan5_input16.dev_attr)) 1112 &sensor_dev_attr_fan5_input16.dev_attr))
1057 || (err = device_create_file(dev, 1113 || (err = device_create_file(dev,
1058 &sensor_dev_attr_fan5_min16.dev_attr))) 1114 &sensor_dev_attr_fan5_min16.dev_attr))
1115 || (err = device_create_file(dev,
1116 &sensor_dev_attr_fan5_alarm.dev_attr)))
1059 goto ERROR4; 1117 goto ERROR4;
1060 } 1118 }
1061 } else { 1119 } else {
@@ -1066,7 +1124,9 @@ static int __devinit it87_probe(struct platform_device *pdev)
1066 || (err = device_create_file(dev, 1124 || (err = device_create_file(dev,
1067 &sensor_dev_attr_fan1_min.dev_attr)) 1125 &sensor_dev_attr_fan1_min.dev_attr))
1068 || (err = device_create_file(dev, 1126 || (err = device_create_file(dev,
1069 &sensor_dev_attr_fan1_div.dev_attr))) 1127 &sensor_dev_attr_fan1_div.dev_attr))
1128 || (err = device_create_file(dev,
1129 &sensor_dev_attr_fan1_alarm.dev_attr)))
1070 goto ERROR4; 1130 goto ERROR4;
1071 } 1131 }
1072 if (data->has_fan & (1 << 1)) { 1132 if (data->has_fan & (1 << 1)) {
@@ -1075,7 +1135,9 @@ static int __devinit it87_probe(struct platform_device *pdev)
1075 || (err = device_create_file(dev, 1135 || (err = device_create_file(dev,
1076 &sensor_dev_attr_fan2_min.dev_attr)) 1136 &sensor_dev_attr_fan2_min.dev_attr))
1077 || (err = device_create_file(dev, 1137 || (err = device_create_file(dev,
1078 &sensor_dev_attr_fan2_div.dev_attr))) 1138 &sensor_dev_attr_fan2_div.dev_attr))
1139 || (err = device_create_file(dev,
1140 &sensor_dev_attr_fan2_alarm.dev_attr)))
1079 goto ERROR4; 1141 goto ERROR4;
1080 } 1142 }
1081 if (data->has_fan & (1 << 2)) { 1143 if (data->has_fan & (1 << 2)) {
@@ -1084,7 +1146,9 @@ static int __devinit it87_probe(struct platform_device *pdev)
1084 || (err = device_create_file(dev, 1146 || (err = device_create_file(dev,
1085 &sensor_dev_attr_fan3_min.dev_attr)) 1147 &sensor_dev_attr_fan3_min.dev_attr))
1086 || (err = device_create_file(dev, 1148 || (err = device_create_file(dev,
1087 &sensor_dev_attr_fan3_div.dev_attr))) 1149 &sensor_dev_attr_fan3_div.dev_attr))
1150 || (err = device_create_file(dev,
1151 &sensor_dev_attr_fan3_alarm.dev_attr)))
1088 goto ERROR4; 1152 goto ERROR4;
1089 } 1153 }
1090 } 1154 }
@@ -1488,7 +1552,7 @@ static void __exit sm_it87_exit(void)
1488} 1552}
1489 1553
1490 1554
1491MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, " 1555MODULE_AUTHOR("Chris Gauthron, "
1492 "Jean Delvare <khali@linux-fr.org>"); 1556 "Jean Delvare <khali@linux-fr.org>");
1493MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver"); 1557MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver");
1494module_param(update_vbat, bool, 0); 1558module_param(update_vbat, bool, 0);
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 37a8cc032ffa..e5c35a355a57 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -74,7 +74,6 @@ static struct i2c_driver lm75_driver = {
74 .driver = { 74 .driver = {
75 .name = "lm75", 75 .name = "lm75",
76 }, 76 },
77 .id = I2C_DRIVERID_LM75,
78 .attach_adapter = lm75_attach_adapter, 77 .attach_adapter = lm75_attach_adapter,
79 .detach_client = lm75_detach_client, 78 .detach_client = lm75_detach_client,
80}; 79};
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index cee5c2e8cfad..459b70ad6bee 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -31,6 +31,7 @@
31#include <linux/jiffies.h> 31#include <linux/jiffies.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/hwmon.h> 33#include <linux/hwmon.h>
34#include <linux/hwmon-sysfs.h>
34#include <linux/err.h> 35#include <linux/err.h>
35#include <linux/mutex.h> 36#include <linux/mutex.h>
36 37
@@ -113,7 +114,6 @@ show(temp_input);
113show(temp_crit); 114show(temp_crit);
114show(temp_min); 115show(temp_min);
115show(temp_max); 116show(temp_max);
116show(alarms);
117 117
118/* read routines for hysteresis values */ 118/* read routines for hysteresis values */
119static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf) 119static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf)
@@ -186,6 +186,14 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
186 return count; 186 return count;
187} 187}
188 188
189static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
190 char *buf)
191{
192 int bitnr = to_sensor_dev_attr(attr)->index;
193 struct lm77_data *data = lm77_update_device(dev);
194 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
195}
196
189static DEVICE_ATTR(temp1_input, S_IRUGO, 197static DEVICE_ATTR(temp1_input, S_IRUGO,
190 show_temp_input, NULL); 198 show_temp_input, NULL);
191static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, 199static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO,
@@ -202,8 +210,9 @@ static DEVICE_ATTR(temp1_min_hyst, S_IRUGO,
202static DEVICE_ATTR(temp1_max_hyst, S_IRUGO, 210static DEVICE_ATTR(temp1_max_hyst, S_IRUGO,
203 show_temp_max_hyst, NULL); 211 show_temp_max_hyst, NULL);
204 212
205static DEVICE_ATTR(alarms, S_IRUGO, 213static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2);
206 show_alarms, NULL); 214static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
215static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
207 216
208static int lm77_attach_adapter(struct i2c_adapter *adapter) 217static int lm77_attach_adapter(struct i2c_adapter *adapter)
209{ 218{
@@ -220,8 +229,9 @@ static struct attribute *lm77_attributes[] = {
220 &dev_attr_temp1_crit_hyst.attr, 229 &dev_attr_temp1_crit_hyst.attr,
221 &dev_attr_temp1_min_hyst.attr, 230 &dev_attr_temp1_min_hyst.attr,
222 &dev_attr_temp1_max_hyst.attr, 231 &dev_attr_temp1_max_hyst.attr,
223 &dev_attr_alarms.attr, 232 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
224 233 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
234 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
225 NULL 235 NULL
226}; 236};
227 237
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 3f7055ee679f..0a9eb1f6f4e4 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -37,10 +37,8 @@
37static struct platform_device *pdev; 37static struct platform_device *pdev;
38 38
39/* Addresses to scan */ 39/* Addresses to scan */
40static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 40static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
41 0x25, 0x26, 0x27, 0x28, 0x29, 41 0x2e, 0x2f, I2C_CLIENT_END };
42 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
43 0x2f, I2C_CLIENT_END };
44static unsigned short isa_address = 0x290; 42static unsigned short isa_address = 0x290;
45 43
46/* Insmod parameters */ 44/* Insmod parameters */
@@ -170,7 +168,6 @@ static struct i2c_driver lm78_driver = {
170 .driver = { 168 .driver = {
171 .name = "lm78", 169 .name = "lm78",
172 }, 170 },
173 .id = I2C_DRIVERID_LM78,
174 .attach_adapter = lm78_attach_adapter, 171 .attach_adapter = lm78_attach_adapter,
175 .detach_client = lm78_detach_client, 172 .detach_client = lm78_detach_client,
176}; 173};
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 063cdba00a88..a2ca055f3922 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -27,6 +27,7 @@
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/hwmon-sysfs.h>
30#include <linux/err.h> 31#include <linux/err.h>
31#include <linux/mutex.h> 32#include <linux/mutex.h>
32 33
@@ -127,7 +128,7 @@ struct lm80_data {
127 u16 alarms; /* Register encoding, combined */ 128 u16 alarms; /* Register encoding, combined */
128}; 129};
129 130
130/* 131/*
131 * Functions declaration 132 * Functions declaration
132 */ 133 */
133 134
@@ -147,7 +148,6 @@ static struct i2c_driver lm80_driver = {
147 .driver = { 148 .driver = {
148 .name = "lm80", 149 .name = "lm80",
149 }, 150 },
150 .id = I2C_DRIVERID_LM80,
151 .attach_adapter = lm80_attach_adapter, 151 .attach_adapter = lm80_attach_adapter,
152 .detach_client = lm80_detach_client, 152 .detach_client = lm80_detach_client,
153}; 153};
@@ -159,105 +159,74 @@ static struct i2c_driver lm80_driver = {
159#define show_in(suffix, value) \ 159#define show_in(suffix, value) \
160static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 160static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \
161{ \ 161{ \
162 int nr = to_sensor_dev_attr(attr)->index; \
162 struct lm80_data *data = lm80_update_device(dev); \ 163 struct lm80_data *data = lm80_update_device(dev); \
163 return sprintf(buf, "%d\n", IN_FROM_REG(data->value)); \ 164 return sprintf(buf, "%d\n", IN_FROM_REG(data->value[nr])); \
164} 165}
165show_in(min0, in_min[0]); 166show_in(min, in_min)
166show_in(min1, in_min[1]); 167show_in(max, in_max)
167show_in(min2, in_min[2]); 168show_in(input, in)
168show_in(min3, in_min[3]);
169show_in(min4, in_min[4]);
170show_in(min5, in_min[5]);
171show_in(min6, in_min[6]);
172show_in(max0, in_max[0]);
173show_in(max1, in_max[1]);
174show_in(max2, in_max[2]);
175show_in(max3, in_max[3]);
176show_in(max4, in_max[4]);
177show_in(max5, in_max[5]);
178show_in(max6, in_max[6]);
179show_in(input0, in[0]);
180show_in(input1, in[1]);
181show_in(input2, in[2]);
182show_in(input3, in[3]);
183show_in(input4, in[4]);
184show_in(input5, in[5]);
185show_in(input6, in[6]);
186 169
187#define set_in(suffix, value, reg) \ 170#define set_in(suffix, value, reg) \
188static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 171static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \
189 size_t count) \ 172 size_t count) \
190{ \ 173{ \
174 int nr = to_sensor_dev_attr(attr)->index; \
191 struct i2c_client *client = to_i2c_client(dev); \ 175 struct i2c_client *client = to_i2c_client(dev); \
192 struct lm80_data *data = i2c_get_clientdata(client); \ 176 struct lm80_data *data = i2c_get_clientdata(client); \
193 long val = simple_strtol(buf, NULL, 10); \ 177 long val = simple_strtol(buf, NULL, 10); \
194 \ 178 \
195 mutex_lock(&data->update_lock);\ 179 mutex_lock(&data->update_lock);\
196 data->value = IN_TO_REG(val); \ 180 data->value[nr] = IN_TO_REG(val); \
197 lm80_write_value(client, reg, data->value); \ 181 lm80_write_value(client, reg(nr), data->value[nr]); \
198 mutex_unlock(&data->update_lock);\ 182 mutex_unlock(&data->update_lock);\
199 return count; \ 183 return count; \
200} 184}
201set_in(min0, in_min[0], LM80_REG_IN_MIN(0)); 185set_in(min, in_min, LM80_REG_IN_MIN)
202set_in(min1, in_min[1], LM80_REG_IN_MIN(1)); 186set_in(max, in_max, LM80_REG_IN_MAX)
203set_in(min2, in_min[2], LM80_REG_IN_MIN(2)); 187
204set_in(min3, in_min[3], LM80_REG_IN_MIN(3)); 188#define show_fan(suffix, value) \
205set_in(min4, in_min[4], LM80_REG_IN_MIN(4));
206set_in(min5, in_min[5], LM80_REG_IN_MIN(5));
207set_in(min6, in_min[6], LM80_REG_IN_MIN(6));
208set_in(max0, in_max[0], LM80_REG_IN_MAX(0));
209set_in(max1, in_max[1], LM80_REG_IN_MAX(1));
210set_in(max2, in_max[2], LM80_REG_IN_MAX(2));
211set_in(max3, in_max[3], LM80_REG_IN_MAX(3));
212set_in(max4, in_max[4], LM80_REG_IN_MAX(4));
213set_in(max5, in_max[5], LM80_REG_IN_MAX(5));
214set_in(max6, in_max[6], LM80_REG_IN_MAX(6));
215
216#define show_fan(suffix, value, div) \
217static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 189static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \
218{ \ 190{ \
191 int nr = to_sensor_dev_attr(attr)->index; \
219 struct lm80_data *data = lm80_update_device(dev); \ 192 struct lm80_data *data = lm80_update_device(dev); \
220 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value, \ 193 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \
221 DIV_FROM_REG(data->div))); \ 194 DIV_FROM_REG(data->fan_div[nr]))); \
222} 195}
223show_fan(min1, fan_min[0], fan_div[0]); 196show_fan(min, fan_min)
224show_fan(min2, fan_min[1], fan_div[1]); 197show_fan(input, fan)
225show_fan(input1, fan[0], fan_div[0]);
226show_fan(input2, fan[1], fan_div[1]);
227 198
228#define show_fan_div(suffix, value) \ 199static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
229static ssize_t show_fan_div##suffix(struct device *dev, struct device_attribute *attr, char *buf) \ 200 char *buf)
230{ \ 201{
231 struct lm80_data *data = lm80_update_device(dev); \ 202 int nr = to_sensor_dev_attr(attr)->index;
232 return sprintf(buf, "%d\n", DIV_FROM_REG(data->value)); \ 203 struct lm80_data *data = lm80_update_device(dev);
204 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
233} 205}
234show_fan_div(1, fan_div[0]);
235show_fan_div(2, fan_div[1]);
236 206
237#define set_fan(suffix, value, reg, div) \ 207static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
238static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ 208 const char *buf, size_t count)
239 size_t count) \ 209{
240{ \ 210 int nr = to_sensor_dev_attr(attr)->index;
241 struct i2c_client *client = to_i2c_client(dev); \ 211 struct i2c_client *client = to_i2c_client(dev);
242 struct lm80_data *data = i2c_get_clientdata(client); \ 212 struct lm80_data *data = i2c_get_clientdata(client);
243 long val = simple_strtoul(buf, NULL, 10); \ 213 long val = simple_strtoul(buf, NULL, 10);
244 \ 214
245 mutex_lock(&data->update_lock);\ 215 mutex_lock(&data->update_lock);
246 data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \ 216 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
247 lm80_write_value(client, reg, data->value); \ 217 lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]);
248 mutex_unlock(&data->update_lock);\ 218 mutex_unlock(&data->update_lock);
249 return count; \ 219 return count;
250} 220}
251set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]);
252set_fan(min2, fan_min[1], LM80_REG_FAN_MIN(2), fan_div[1]);
253 221
254/* Note: we save and restore the fan minimum here, because its value is 222/* Note: we save and restore the fan minimum here, because its value is
255 determined in part by the fan divisor. This follows the principle of 223 determined in part by the fan divisor. This follows the principle of
256 least surprise; the user doesn't expect the fan minimum to change just 224 least surprise; the user doesn't expect the fan minimum to change just
257 because the divisor changed. */ 225 because the divisor changed. */
258static ssize_t set_fan_div(struct device *dev, const char *buf, 226static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
259 size_t count, int nr) 227 const char *buf, size_t count)
260{ 228{
229 int nr = to_sensor_dev_attr(attr)->index;
261 struct i2c_client *client = to_i2c_client(dev); 230 struct i2c_client *client = to_i2c_client(dev);
262 struct lm80_data *data = i2c_get_clientdata(client); 231 struct lm80_data *data = i2c_get_clientdata(client);
263 unsigned long min, val = simple_strtoul(buf, NULL, 10); 232 unsigned long min, val = simple_strtoul(buf, NULL, 10);
@@ -292,15 +261,6 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
292 return count; 261 return count;
293} 262}
294 263
295#define set_fan_div(number) \
296static ssize_t set_fan_div##number(struct device *dev, struct device_attribute *attr, const char *buf, \
297 size_t count) \
298{ \
299 return set_fan_div(dev, buf, count, number - 1); \
300}
301set_fan_div(1);
302set_fan_div(2);
303
304static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf) 264static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf)
305{ 265{
306 struct lm80_data *data = lm80_update_device(dev); 266 struct lm80_data *data = lm80_update_device(dev);
@@ -337,41 +297,66 @@ set_temp(hot_hyst, temp_hot_hyst, LM80_REG_TEMP_HOT_HYST);
337set_temp(os_max, temp_os_max, LM80_REG_TEMP_OS_MAX); 297set_temp(os_max, temp_os_max, LM80_REG_TEMP_OS_MAX);
338set_temp(os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST); 298set_temp(os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST);
339 299
340static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 300static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
301 char *buf)
341{ 302{
342 struct lm80_data *data = lm80_update_device(dev); 303 struct lm80_data *data = lm80_update_device(dev);
343 return sprintf(buf, "%u\n", data->alarms); 304 return sprintf(buf, "%u\n", data->alarms);
344} 305}
345 306
346static DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min0, set_in_min0); 307static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
347static DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min1, set_in_min1); 308 char *buf)
348static DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min2, set_in_min2); 309{
349static DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min3, set_in_min3); 310 int bitnr = to_sensor_dev_attr(attr)->index;
350static DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min4, set_in_min4); 311 struct lm80_data *data = lm80_update_device(dev);
351static DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min5, set_in_min5); 312 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
352static DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min6, set_in_min6); 313}
353static DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max0, set_in_max0); 314
354static DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max1, set_in_max1); 315static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO,
355static DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max2, set_in_max2); 316 show_in_min, set_in_min, 0);
356static DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max3, set_in_max3); 317static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
357static DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max4, set_in_max4); 318 show_in_min, set_in_min, 1);
358static DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max5, set_in_max5); 319static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
359static DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max6, set_in_max6); 320 show_in_min, set_in_min, 2);
360static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL); 321static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
361static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL); 322 show_in_min, set_in_min, 3);
362static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL); 323static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
363static DEVICE_ATTR(in3_input, S_IRUGO, show_in_input3, NULL); 324 show_in_min, set_in_min, 4);
364static DEVICE_ATTR(in4_input, S_IRUGO, show_in_input4, NULL); 325static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
365static DEVICE_ATTR(in5_input, S_IRUGO, show_in_input5, NULL); 326 show_in_min, set_in_min, 5);
366static DEVICE_ATTR(in6_input, S_IRUGO, show_in_input6, NULL); 327static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
367static DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min1, 328 show_in_min, set_in_min, 6);
368 set_fan_min1); 329static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO,
369static DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min2, 330 show_in_max, set_in_max, 0);
370 set_fan_min2); 331static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
371static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL); 332 show_in_max, set_in_max, 1);
372static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL); 333static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
373static DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div1, set_fan_div1); 334 show_in_max, set_in_max, 2);
374static DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div2, set_fan_div2); 335static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
336 show_in_max, set_in_max, 3);
337static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
338 show_in_max, set_in_max, 4);
339static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
340 show_in_max, set_in_max, 5);
341static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
342 show_in_max, set_in_max, 6);
343static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0);
344static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1);
345static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2);
346static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3);
347static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4);
348static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5);
349static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6);
350static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
351 show_fan_min, set_fan_min, 0);
352static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
353 show_fan_min, set_fan_min, 1);
354static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);
355static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1);
356static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
357 show_fan_div, set_fan_div, 0);
358static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
359 show_fan_div, set_fan_div, 1);
375static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); 360static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL);
376static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max, 361static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max,
377 set_temp_hot_max); 362 set_temp_hot_max);
@@ -382,6 +367,17 @@ static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_os_max,
382static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_os_hyst, 367static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_os_hyst,
383 set_temp_os_hyst); 368 set_temp_os_hyst);
384static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 369static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
370static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
371static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
372static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
373static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
374static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4);
375static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5);
376static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
377static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
378static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
379static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 8);
380static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 13);
385 381
386/* 382/*
387 * Real code 383 * Real code
@@ -395,40 +391,50 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter)
395} 391}
396 392
397static struct attribute *lm80_attributes[] = { 393static struct attribute *lm80_attributes[] = {
398 &dev_attr_in0_min.attr, 394 &sensor_dev_attr_in0_min.dev_attr.attr,
399 &dev_attr_in1_min.attr, 395 &sensor_dev_attr_in1_min.dev_attr.attr,
400 &dev_attr_in2_min.attr, 396 &sensor_dev_attr_in2_min.dev_attr.attr,
401 &dev_attr_in3_min.attr, 397 &sensor_dev_attr_in3_min.dev_attr.attr,
402 &dev_attr_in4_min.attr, 398 &sensor_dev_attr_in4_min.dev_attr.attr,
403 &dev_attr_in5_min.attr, 399 &sensor_dev_attr_in5_min.dev_attr.attr,
404 &dev_attr_in6_min.attr, 400 &sensor_dev_attr_in6_min.dev_attr.attr,
405 &dev_attr_in0_max.attr, 401 &sensor_dev_attr_in0_max.dev_attr.attr,
406 &dev_attr_in1_max.attr, 402 &sensor_dev_attr_in1_max.dev_attr.attr,
407 &dev_attr_in2_max.attr, 403 &sensor_dev_attr_in2_max.dev_attr.attr,
408 &dev_attr_in3_max.attr, 404 &sensor_dev_attr_in3_max.dev_attr.attr,
409 &dev_attr_in4_max.attr, 405 &sensor_dev_attr_in4_max.dev_attr.attr,
410 &dev_attr_in5_max.attr, 406 &sensor_dev_attr_in5_max.dev_attr.attr,
411 &dev_attr_in6_max.attr, 407 &sensor_dev_attr_in6_max.dev_attr.attr,
412 &dev_attr_in0_input.attr, 408 &sensor_dev_attr_in0_input.dev_attr.attr,
413 &dev_attr_in1_input.attr, 409 &sensor_dev_attr_in1_input.dev_attr.attr,
414 &dev_attr_in2_input.attr, 410 &sensor_dev_attr_in2_input.dev_attr.attr,
415 &dev_attr_in3_input.attr, 411 &sensor_dev_attr_in3_input.dev_attr.attr,
416 &dev_attr_in4_input.attr, 412 &sensor_dev_attr_in4_input.dev_attr.attr,
417 &dev_attr_in5_input.attr, 413 &sensor_dev_attr_in5_input.dev_attr.attr,
418 &dev_attr_in6_input.attr, 414 &sensor_dev_attr_in6_input.dev_attr.attr,
419 &dev_attr_fan1_min.attr, 415 &sensor_dev_attr_fan1_min.dev_attr.attr,
420 &dev_attr_fan2_min.attr, 416 &sensor_dev_attr_fan2_min.dev_attr.attr,
421 &dev_attr_fan1_input.attr, 417 &sensor_dev_attr_fan1_input.dev_attr.attr,
422 &dev_attr_fan2_input.attr, 418 &sensor_dev_attr_fan2_input.dev_attr.attr,
423 &dev_attr_fan1_div.attr, 419 &sensor_dev_attr_fan1_div.dev_attr.attr,
424 &dev_attr_fan2_div.attr, 420 &sensor_dev_attr_fan2_div.dev_attr.attr,
425 &dev_attr_temp1_input.attr, 421 &dev_attr_temp1_input.attr,
426 &dev_attr_temp1_max.attr, 422 &dev_attr_temp1_max.attr,
427 &dev_attr_temp1_max_hyst.attr, 423 &dev_attr_temp1_max_hyst.attr,
428 &dev_attr_temp1_crit.attr, 424 &dev_attr_temp1_crit.attr,
429 &dev_attr_temp1_crit_hyst.attr, 425 &dev_attr_temp1_crit_hyst.attr,
430 &dev_attr_alarms.attr, 426 &dev_attr_alarms.attr,
431 427 &sensor_dev_attr_in0_alarm.dev_attr.attr,
428 &sensor_dev_attr_in1_alarm.dev_attr.attr,
429 &sensor_dev_attr_in2_alarm.dev_attr.attr,
430 &sensor_dev_attr_in3_alarm.dev_attr.attr,
431 &sensor_dev_attr_in4_alarm.dev_attr.attr,
432 &sensor_dev_attr_in5_alarm.dev_attr.attr,
433 &sensor_dev_attr_in6_alarm.dev_attr.attr,
434 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
435 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
436 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
437 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
432 NULL 438 NULL
433}; 439};
434 440
@@ -439,7 +445,7 @@ static const struct attribute_group lm80_group = {
439static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) 445static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
440{ 446{
441 int i, cur; 447 int i, cur;
442 struct i2c_client *new_client; 448 struct i2c_client *client;
443 struct lm80_data *data; 449 struct lm80_data *data;
444 int err = 0; 450 int err = 0;
445 const char *name; 451 const char *name;
@@ -455,21 +461,20 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
455 goto exit; 461 goto exit;
456 } 462 }
457 463
458 new_client = &data->client; 464 client = &data->client;
459 i2c_set_clientdata(new_client, data); 465 i2c_set_clientdata(client, data);
460 new_client->addr = address; 466 client->addr = address;
461 new_client->adapter = adapter; 467 client->adapter = adapter;
462 new_client->driver = &lm80_driver; 468 client->driver = &lm80_driver;
463 new_client->flags = 0;
464 469
465 /* Now, we do the remaining detection. It is lousy. */ 470 /* Now, we do the remaining detection. It is lousy. */
466 if (lm80_read_value(new_client, LM80_REG_ALARM2) & 0xc0) 471 if (lm80_read_value(client, LM80_REG_ALARM2) & 0xc0)
467 goto error_free; 472 goto error_free;
468 for (i = 0x2a; i <= 0x3d; i++) { 473 for (i = 0x2a; i <= 0x3d; i++) {
469 cur = i2c_smbus_read_byte_data(new_client, i); 474 cur = i2c_smbus_read_byte_data(client, i);
470 if ((i2c_smbus_read_byte_data(new_client, i + 0x40) != cur) 475 if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur)
471 || (i2c_smbus_read_byte_data(new_client, i + 0x80) != cur) 476 || (i2c_smbus_read_byte_data(client, i + 0x80) != cur)
472 || (i2c_smbus_read_byte_data(new_client, i + 0xc0) != cur)) 477 || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur))
473 goto error_free; 478 goto error_free;
474 } 479 }
475 480
@@ -477,27 +482,26 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
477 kind = lm80; 482 kind = lm80;
478 name = "lm80"; 483 name = "lm80";
479 484
480 /* Fill in the remaining client fields and put it into the global list */ 485 /* Fill in the remaining client fields */
481 strlcpy(new_client->name, name, I2C_NAME_SIZE); 486 strlcpy(client->name, name, I2C_NAME_SIZE);
482 data->valid = 0;
483 mutex_init(&data->update_lock); 487 mutex_init(&data->update_lock);
484 488
485 /* Tell the I2C layer a new client has arrived */ 489 /* Tell the I2C layer a new client has arrived */
486 if ((err = i2c_attach_client(new_client))) 490 if ((err = i2c_attach_client(client)))
487 goto error_free; 491 goto error_free;
488 492
489 /* Initialize the LM80 chip */ 493 /* Initialize the LM80 chip */
490 lm80_init_client(new_client); 494 lm80_init_client(client);
491 495
492 /* A few vars need to be filled upon startup */ 496 /* A few vars need to be filled upon startup */
493 data->fan_min[0] = lm80_read_value(new_client, LM80_REG_FAN_MIN(1)); 497 data->fan_min[0] = lm80_read_value(client, LM80_REG_FAN_MIN(1));
494 data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2)); 498 data->fan_min[1] = lm80_read_value(client, LM80_REG_FAN_MIN(2));
495 499
496 /* Register sysfs hooks */ 500 /* Register sysfs hooks */
497 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm80_group))) 501 if ((err = sysfs_create_group(&client->dev.kobj, &lm80_group)))
498 goto error_detach; 502 goto error_detach;
499 503
500 data->hwmon_dev = hwmon_device_register(&new_client->dev); 504 data->hwmon_dev = hwmon_device_register(&client->dev);
501 if (IS_ERR(data->hwmon_dev)) { 505 if (IS_ERR(data->hwmon_dev)) {
502 err = PTR_ERR(data->hwmon_dev); 506 err = PTR_ERR(data->hwmon_dev);
503 goto error_remove; 507 goto error_remove;
@@ -506,9 +510,9 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
506 return 0; 510 return 0;
507 511
508error_remove: 512error_remove:
509 sysfs_remove_group(&new_client->dev.kobj, &lm80_group); 513 sysfs_remove_group(&client->dev.kobj, &lm80_group);
510error_detach: 514error_detach:
511 i2c_detach_client(new_client); 515 i2c_detach_client(client);
512error_free: 516error_free:
513 kfree(data); 517 kfree(data);
514exit: 518exit:
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
index 0336b4572a61..6e8903a6e902 100644
--- a/drivers/hwmon/lm83.c
+++ b/drivers/hwmon/lm83.c
@@ -133,7 +133,6 @@ static struct i2c_driver lm83_driver = {
133 .driver = { 133 .driver = {
134 .name = "lm83", 134 .name = "lm83",
135 }, 135 },
136 .id = I2C_DRIVERID_LM83,
137 .attach_adapter = lm83_attach_adapter, 136 .attach_adapter = lm83_attach_adapter,
138 .detach_client = lm83_detach_client, 137 .detach_client = lm83_detach_client,
139}; 138};
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index a02480be65f2..4bb0f291a6b8 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -367,7 +367,6 @@ static struct i2c_driver lm85_driver = {
367 .driver = { 367 .driver = {
368 .name = "lm85", 368 .name = "lm85",
369 }, 369 },
370 .id = I2C_DRIVERID_LM85,
371 .attach_adapter = lm85_attach_adapter, 370 .attach_adapter = lm85_attach_adapter,
372 .detach_client = lm85_detach_client, 371 .detach_client = lm85_detach_client,
373}; 372};
@@ -444,12 +443,8 @@ static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, c
444 443
445static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 444static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
446{ 445{
447 struct i2c_client *client = to_i2c_client(dev); 446 struct lm85_data *data = dev_get_drvdata(dev);
448 struct lm85_data *data = i2c_get_clientdata(client); 447 data->vrm = simple_strtoul(buf, NULL, 10);
449 u32 val;
450
451 val = simple_strtoul(buf, NULL, 10);
452 data->vrm = val;
453 return count; 448 return count;
454} 449}
455 450
@@ -519,17 +514,64 @@ static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
519{ 514{
520 int nr = to_sensor_dev_attr(attr)->index; 515 int nr = to_sensor_dev_attr(attr)->index;
521 struct lm85_data *data = lm85_update_device(dev); 516 struct lm85_data *data = lm85_update_device(dev);
522 int pwm_zone; 517 int pwm_zone, enable;
523 518
524 pwm_zone = ZONE_FROM_REG(data->autofan[nr].config); 519 pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
525 return sprintf(buf,"%d\n", (pwm_zone != 0 && pwm_zone != -1) ); 520 switch (pwm_zone) {
521 case -1: /* PWM is always at 100% */
522 enable = 0;
523 break;
524 case 0: /* PWM is always at 0% */
525 case -2: /* PWM responds to manual control */
526 enable = 1;
527 break;
528 default: /* PWM in automatic mode */
529 enable = 2;
530 }
531 return sprintf(buf, "%d\n", enable);
532}
533
534static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
535 *attr, const char *buf, size_t count)
536{
537 int nr = to_sensor_dev_attr(attr)->index;
538 struct i2c_client *client = to_i2c_client(dev);
539 struct lm85_data *data = i2c_get_clientdata(client);
540 long val = simple_strtol(buf, NULL, 10);
541 u8 config;
542
543 switch (val) {
544 case 0:
545 config = 3;
546 break;
547 case 1:
548 config = 7;
549 break;
550 case 2:
551 /* Here we have to choose arbitrarily one of the 5 possible
552 configurations; I go for the safest */
553 config = 6;
554 break;
555 default:
556 return -EINVAL;
557 }
558
559 mutex_lock(&data->update_lock);
560 data->autofan[nr].config = lm85_read_value(client,
561 LM85_REG_AFAN_CONFIG(nr));
562 data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
563 | (config << 5);
564 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
565 data->autofan[nr].config);
566 mutex_unlock(&data->update_lock);
567 return count;
526} 568}
527 569
528#define show_pwm_reg(offset) \ 570#define show_pwm_reg(offset) \
529static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ 571static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
530 show_pwm, set_pwm, offset - 1); \ 572 show_pwm, set_pwm, offset - 1); \
531static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO, \ 573static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
532 show_pwm_enable, NULL, offset - 1) 574 show_pwm_enable, set_pwm_enable, offset - 1)
533 575
534show_pwm_reg(1); 576show_pwm_reg(1);
535show_pwm_reg(2); 577show_pwm_reg(2);
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 28cdff0c556b..8ee07c5c97a1 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -5,7 +5,7 @@
5 * Philip Edelbrock <phil@netroedge.com> 5 * Philip Edelbrock <phil@netroedge.com>
6 * Stephen Rousset <stephen.rousset@rocketlogix.com> 6 * Stephen Rousset <stephen.rousset@rocketlogix.com>
7 * Dan Eaton <dan.eaton@rocketlogix.com> 7 * Dan Eaton <dan.eaton@rocketlogix.com>
8 * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> 8 * Copyright (C) 2004,2007 Jean Delvare <khali@linux-fr.org>
9 * 9 *
10 * Original port to Linux 2.6 by Jeff Oliver. 10 * Original port to Linux 2.6 by Jeff Oliver.
11 * 11 *
@@ -37,6 +37,11 @@
37 * instead. The LM87 is the only hardware monitoring chipset I know of 37 * instead. The LM87 is the only hardware monitoring chipset I know of
38 * which uses amplitude modulation. Be careful when using this feature. 38 * which uses amplitude modulation. Be careful when using this feature.
39 * 39 *
40 * This driver also supports the ADM1024, a sensor chip made by Analog
41 * Devices. That chip is fully compatible with the LM87. Complete
42 * datasheet can be obtained from Analog's website at:
43 * http://www.analog.com/en/prod/0,2877,ADM1024,00.html
44 *
40 * This program is free software; you can redistribute it and/or modify 45 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License as published by 46 * it under the terms of the GNU General Public License as published by
42 * the Free Software Foundation; either version 2 of the License, or 47 * the Free Software Foundation; either version 2 of the License, or
@@ -74,7 +79,7 @@ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
74 * Insmod parameters 79 * Insmod parameters
75 */ 80 */
76 81
77I2C_CLIENT_INSMOD_1(lm87); 82I2C_CLIENT_INSMOD_2(lm87, adm1024);
78 83
79/* 84/*
80 * The LM87 registers 85 * The LM87 registers
@@ -166,7 +171,6 @@ static struct i2c_driver lm87_driver = {
166 .driver = { 171 .driver = {
167 .name = "lm87", 172 .name = "lm87",
168 }, 173 },
169 .id = I2C_DRIVERID_LM87,
170 .attach_adapter = lm87_attach_adapter, 174 .attach_adapter = lm87_attach_adapter,
171 .detach_client = lm87_detach_client, 175 .detach_client = lm87_detach_client,
172}; 176};
@@ -506,8 +510,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char
506} 510}
507static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 511static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
508{ 512{
509 struct i2c_client *client = to_i2c_client(dev); 513 struct lm87_data *data = dev_get_drvdata(dev);
510 struct lm87_data *data = i2c_get_clientdata(client);
511 data->vrm = simple_strtoul(buf, NULL, 10); 514 data->vrm = simple_strtoul(buf, NULL, 10);
512 return count; 515 return count;
513} 516}
@@ -662,6 +665,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
662 struct i2c_client *new_client; 665 struct i2c_client *new_client;
663 struct lm87_data *data; 666 struct lm87_data *data;
664 int err = 0; 667 int err = 0;
668 static const char *names[] = { "lm87", "adm1024" };
665 669
666 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 670 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
667 goto exit; 671 goto exit;
@@ -686,11 +690,18 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
686 690
687 /* Now, we do the remaining detection. */ 691 /* Now, we do the remaining detection. */
688 if (kind < 0) { 692 if (kind < 0) {
693 u8 cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID);
689 u8 rev = lm87_read_value(new_client, LM87_REG_REVISION); 694 u8 rev = lm87_read_value(new_client, LM87_REG_REVISION);
690 695
691 if (rev < 0x01 || rev > 0x08 696 if (cid == 0x02 /* National Semiconductor */
692 || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80) 697 && (rev >= 0x01 && rev <= 0x08))
693 || lm87_read_value(new_client, LM87_REG_COMPANY_ID) != 0x02) { 698 kind = lm87;
699 else if (cid == 0x41 /* Analog Devices */
700 && (rev & 0xf0) == 0x10)
701 kind = adm1024;
702
703 if (kind < 0
704 || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) {
694 dev_dbg(&adapter->dev, 705 dev_dbg(&adapter->dev,
695 "LM87 detection failed at 0x%02x.\n", 706 "LM87 detection failed at 0x%02x.\n",
696 address); 707 address);
@@ -699,7 +710,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
699 } 710 }
700 711
701 /* We can fill in the remaining client fields */ 712 /* We can fill in the remaining client fields */
702 strlcpy(new_client->name, "lm87", I2C_NAME_SIZE); 713 strlcpy(new_client->name, names[kind - 1], I2C_NAME_SIZE);
703 data->valid = 0; 714 data->valid = 0;
704 mutex_init(&data->update_lock); 715 mutex_init(&data->update_lock);
705 716
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 960df9fa75af..f7ec95bedbf6 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -204,7 +204,6 @@ static struct i2c_driver lm90_driver = {
204 .driver = { 204 .driver = {
205 .name = "lm90", 205 .name = "lm90",
206 }, 206 },
207 .id = I2C_DRIVERID_LM90,
208 .attach_adapter = lm90_attach_adapter, 207 .attach_adapter = lm90_attach_adapter,
209 .detach_client = lm90_detach_client, 208 .detach_client = lm90_detach_client,
210}; 209};
@@ -531,24 +530,24 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
531 kind = lm90; 530 kind = lm90;
532 531
533 if (kind < 0) { /* detection and identification */ 532 if (kind < 0) { /* detection and identification */
534 u8 man_id, chip_id, reg_config1, reg_convrate; 533 int man_id, chip_id, reg_config1, reg_convrate;
535 534
536 if (lm90_read_reg(new_client, LM90_REG_R_MAN_ID, 535 if ((man_id = i2c_smbus_read_byte_data(new_client,
537 &man_id) < 0 536 LM90_REG_R_MAN_ID)) < 0
538 || lm90_read_reg(new_client, LM90_REG_R_CHIP_ID, 537 || (chip_id = i2c_smbus_read_byte_data(new_client,
539 &chip_id) < 0 538 LM90_REG_R_CHIP_ID)) < 0
540 || lm90_read_reg(new_client, LM90_REG_R_CONFIG1, 539 || (reg_config1 = i2c_smbus_read_byte_data(new_client,
541 &reg_config1) < 0 540 LM90_REG_R_CONFIG1)) < 0
542 || lm90_read_reg(new_client, LM90_REG_R_CONVRATE, 541 || (reg_convrate = i2c_smbus_read_byte_data(new_client,
543 &reg_convrate) < 0) 542 LM90_REG_R_CONVRATE)) < 0)
544 goto exit_free; 543 goto exit_free;
545 544
546 if ((address == 0x4C || address == 0x4D) 545 if ((address == 0x4C || address == 0x4D)
547 && man_id == 0x01) { /* National Semiconductor */ 546 && man_id == 0x01) { /* National Semiconductor */
548 u8 reg_config2; 547 int reg_config2;
549 548
550 if (lm90_read_reg(new_client, LM90_REG_R_CONFIG2, 549 if ((reg_config2 = i2c_smbus_read_byte_data(new_client,
551 &reg_config2) < 0) 550 LM90_REG_R_CONFIG2)) < 0)
552 goto exit_free; 551 goto exit_free;
553 552
554 if ((reg_config1 & 0x2A) == 0x00 553 if ((reg_config1 & 0x2A) == 0x00
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 61d1bd1d5b6e..af5c77d568fe 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -428,7 +428,6 @@ static struct i2c_driver lm92_driver = {
428 .driver = { 428 .driver = {
429 .name = "lm92", 429 .name = "lm92",
430 }, 430 },
431 .id = I2C_DRIVERID_LM92,
432 .attach_adapter = lm92_attach_adapter, 431 .attach_adapter = lm92_attach_adapter,
433 .detach_client = lm92_detach_client, 432 .detach_client = lm92_detach_client,
434}; 433};
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index 9d660133d517..9b462bb13fa3 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -59,6 +59,10 @@ MODULE_PARM_DESC(init,
59 " 2: Forcibly enable all voltage and temperature channels, except in9\n" 59 " 2: Forcibly enable all voltage and temperature channels, except in9\n"
60 " 3: Forcibly enable all voltage and temperature channels, including in9"); 60 " 3: Forcibly enable all voltage and temperature channels, including in9");
61 61
62static unsigned short force_id;
63module_param(force_id, ushort, 0);
64MODULE_PARM_DESC(force_id, "Override the detected device ID");
65
62/* 66/*
63 * Super-I/O registers and operations 67 * Super-I/O registers and operations
64 */ 68 */
@@ -826,7 +830,7 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
826 /* No superio_enter */ 830 /* No superio_enter */
827 831
828 /* Identify device */ 832 /* Identify device */
829 val = superio_inb(sioaddr, DEVID); 833 val = force_id ? force_id : superio_inb(sioaddr, DEVID);
830 switch (val) { 834 switch (val) {
831 case 0xE1: /* PC87360 */ 835 case 0xE1: /* PC87360 */
832 case 0xE8: /* PC87363 */ 836 case 0xE8: /* PC87363 */
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
index d40509ad6ae6..7265f22ae5cd 100644
--- a/drivers/hwmon/pc87427.c
+++ b/drivers/hwmon/pc87427.c
@@ -34,6 +34,10 @@
34#include <linux/ioport.h> 34#include <linux/ioport.h>
35#include <asm/io.h> 35#include <asm/io.h>
36 36
37static unsigned short force_id;
38module_param(force_id, ushort, 0);
39MODULE_PARM_DESC(force_id, "Override the detected device ID");
40
37static struct platform_device *pdev; 41static struct platform_device *pdev;
38 42
39#define DRVNAME "pc87427" 43#define DRVNAME "pc87427"
@@ -555,7 +559,7 @@ static int __init pc87427_find(int sioaddr, unsigned short *address)
555 int i, err = 0; 559 int i, err = 0;
556 560
557 /* Identify device */ 561 /* Identify device */
558 val = superio_inb(sioaddr, SIOREG_DEVID); 562 val = force_id ? force_id : superio_inb(sioaddr, SIOREG_DEVID);
559 if (val != 0xf2) { /* PC87427 */ 563 if (val != 0xf2) { /* PC87427 */
560 err = -ENODEV; 564 err = -ENODEV;
561 goto exit; 565 goto exit;
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index 0b57d2ea2cf7..f61d8f4185b2 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -38,6 +38,10 @@
38#include <linux/mutex.h> 38#include <linux/mutex.h>
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41static unsigned short force_id;
42module_param(force_id, ushort, 0);
43MODULE_PARM_DESC(force_id, "Override the detected device ID");
44
41static struct platform_device *pdev; 45static struct platform_device *pdev;
42 46
43#define DRVNAME "smsc47b397" 47#define DRVNAME "smsc47b397"
@@ -333,7 +337,7 @@ static int __init smsc47b397_find(unsigned short *addr)
333 u8 id, rev; 337 u8 id, rev;
334 338
335 superio_enter(); 339 superio_enter();
336 id = superio_inb(SUPERIO_REG_DEVID); 340 id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
337 341
338 if ((id != 0x6f) && (id != 0x81) && (id != 0x85)) { 342 if ((id != 0x6f) && (id != 0x81) && (id != 0x85)) {
339 superio_exit(); 343 superio_exit();
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index a10a380868e2..0d7f0c4d06bb 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -39,6 +39,10 @@
39#include <linux/sysfs.h> 39#include <linux/sysfs.h>
40#include <asm/io.h> 40#include <asm/io.h>
41 41
42static unsigned short force_id;
43module_param(force_id, ushort, 0);
44MODULE_PARM_DESC(force_id, "Override the detected device ID");
45
42static struct platform_device *pdev; 46static struct platform_device *pdev;
43 47
44#define DRVNAME "smsc47m1" 48#define DRVNAME "smsc47m1"
@@ -399,7 +403,7 @@ static int __init smsc47m1_find(unsigned short *addr,
399 u8 val; 403 u8 val;
400 404
401 superio_enter(); 405 superio_enter();
402 val = superio_inb(SUPERIO_REG_DEVID); 406 val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
403 407
404 /* 408 /*
405 * SMSC LPC47M10x/LPC47M112/LPC47M13x (device id 0x59), LPC47M14x 409 * SMSC LPC47M10x/LPC47M112/LPC47M13x (device id 0x59), LPC47M14x
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
index b87552652588..8b0c188e60f6 100644
--- a/drivers/hwmon/smsc47m192.c
+++ b/drivers/hwmon/smsc47m192.c
@@ -341,8 +341,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
341static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, 341static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
342 const char *buf, size_t count) 342 const char *buf, size_t count)
343{ 343{
344 struct i2c_client *client = to_i2c_client(dev); 344 struct smsc47m192_data *data = dev_get_drvdata(dev);
345 struct smsc47m192_data *data = i2c_get_clientdata(client);
346 data->vrm = simple_strtoul(buf, NULL, 10); 345 data->vrm = simple_strtoul(buf, NULL, 10);
347 return count; 346 return count;
348} 347}
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index 7dfcc8dd316d..12b43590fa53 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -42,6 +42,10 @@ static int int_mode = -1;
42module_param(int_mode, int, 0); 42module_param(int_mode, int, 0);
43MODULE_PARM_DESC(int_mode, "Force the temperature interrupt mode"); 43MODULE_PARM_DESC(int_mode, "Force the temperature interrupt mode");
44 44
45static unsigned short force_id;
46module_param(force_id, ushort, 0);
47MODULE_PARM_DESC(force_id, "Override the detected device ID");
48
45static struct platform_device *pdev; 49static struct platform_device *pdev;
46 50
47#define DRVNAME "vt1211" 51#define DRVNAME "vt1211"
@@ -1280,10 +1284,12 @@ EXIT:
1280static int __init vt1211_find(int sio_cip, unsigned short *address) 1284static int __init vt1211_find(int sio_cip, unsigned short *address)
1281{ 1285{
1282 int err = -ENODEV; 1286 int err = -ENODEV;
1287 int devid;
1283 1288
1284 superio_enter(sio_cip); 1289 superio_enter(sio_cip);
1285 1290
1286 if (superio_inb(sio_cip, SIO_VT1211_DEVID) != SIO_VT1211_ID) { 1291 devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID);
1292 if (devid != SIO_VT1211_ID) {
1287 goto EXIT; 1293 goto EXIT;
1288 } 1294 }
1289 1295
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 2196a84603f5..f87661775fe0 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -504,7 +504,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
504 case 4: data->fan_div[nr] = 2; break; 504 case 4: data->fan_div[nr] = 2; break;
505 case 8: data->fan_div[nr] = 3; break; 505 case 8: data->fan_div[nr] = 3; break;
506 default: 506 default:
507 dev_err(dev, "fan_div value %ld not supported." 507 dev_err(dev, "fan_div value %ld not supported. "
508 "Choose one of 1, 2, 4 or 8!\n", val); 508 "Choose one of 1, 2, 4 or 8!\n", val);
509 mutex_unlock(&data->update_lock); 509 mutex_unlock(&data->update_lock);
510 return -EINVAL; 510 return -EINVAL;
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index d5aa25ce5dbd..075164dd65a7 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -59,6 +59,10 @@ static const char * w83627ehf_device_names[] = {
59 "w83627dhg", 59 "w83627dhg",
60}; 60};
61 61
62static unsigned short force_id;
63module_param(force_id, ushort, 0);
64MODULE_PARM_DESC(force_id, "Override the detected device ID");
65
62#define DRVNAME "w83627ehf" 66#define DRVNAME "w83627ehf"
63 67
64/* 68/*
@@ -1198,8 +1202,7 @@ static void w83627ehf_device_remove_files(struct device *dev)
1198 device_remove_file(dev, &sda_temp[i].dev_attr); 1202 device_remove_file(dev, &sda_temp[i].dev_attr);
1199 1203
1200 device_remove_file(dev, &dev_attr_name); 1204 device_remove_file(dev, &dev_attr_name);
1201 if (data->vid != 0x3f) 1205 device_remove_file(dev, &dev_attr_cpu0_vid);
1202 device_remove_file(dev, &dev_attr_cpu0_vid);
1203} 1206}
1204 1207
1205/* Get the monitoring functions started */ 1208/* Get the monitoring functions started */
@@ -1299,11 +1302,16 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
1299 } 1302 }
1300 } 1303 }
1301 1304
1302 data->vid = superio_inb(sio_data->sioreg, SIO_REG_VID_DATA) & 0x3f; 1305 data->vid = superio_inb(sio_data->sioreg, SIO_REG_VID_DATA);
1306 if (sio_data->kind == w83627ehf) /* 6 VID pins only */
1307 data->vid &= 0x3f;
1308
1309 err = device_create_file(dev, &dev_attr_cpu0_vid);
1310 if (err)
1311 goto exit_release;
1303 } else { 1312 } else {
1304 dev_info(dev, "VID pins in output mode, CPU VID not " 1313 dev_info(dev, "VID pins in output mode, CPU VID not "
1305 "available\n"); 1314 "available\n");
1306 data->vid = 0x3f;
1307 } 1315 }
1308 1316
1309 /* fan4 and fan5 share some pins with the GPIO and serial flash */ 1317 /* fan4 and fan5 share some pins with the GPIO and serial flash */
@@ -1386,12 +1394,6 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
1386 if (err) 1394 if (err)
1387 goto exit_remove; 1395 goto exit_remove;
1388 1396
1389 if (data->vid != 0x3f) {
1390 err = device_create_file(dev, &dev_attr_cpu0_vid);
1391 if (err)
1392 goto exit_remove;
1393 }
1394
1395 data->hwmon_dev = hwmon_device_register(dev); 1397 data->hwmon_dev = hwmon_device_register(dev);
1396 if (IS_ERR(data->hwmon_dev)) { 1398 if (IS_ERR(data->hwmon_dev)) {
1397 err = PTR_ERR(data->hwmon_dev); 1399 err = PTR_ERR(data->hwmon_dev);
@@ -1445,8 +1447,11 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
1445 1447
1446 superio_enter(sioaddr); 1448 superio_enter(sioaddr);
1447 1449
1448 val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8) 1450 if (force_id)
1449 | superio_inb(sioaddr, SIO_REG_DEVID + 1); 1451 val = force_id;
1452 else
1453 val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8)
1454 | superio_inb(sioaddr, SIO_REG_DEVID + 1);
1450 switch (val & SIO_ID_MASK) { 1455 switch (val & SIO_ID_MASK) {
1451 case SIO_W83627EHF_ID: 1456 case SIO_W83627EHF_ID:
1452 sio_data->kind = w83627ehf; 1457 sio_data->kind = w83627ehf;
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 879d0a6544cc..9564fb069957 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -75,6 +75,10 @@ static int init = 1;
75module_param(init, bool, 0); 75module_param(init, bool, 0);
76MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization"); 76MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
77 77
78static unsigned short force_id;
79module_param(force_id, ushort, 0);
80MODULE_PARM_DESC(force_id, "Override the detected device ID");
81
78/* modified from kernel/include/traps.c */ 82/* modified from kernel/include/traps.c */
79static int REG; /* The register to read/write */ 83static int REG; /* The register to read/write */
80#define DEV 0x07 /* Register: Logical device select */ 84#define DEV 0x07 /* Register: Logical device select */
@@ -319,10 +323,8 @@ static inline u8 pwm_freq_to_reg(unsigned long val)
319 return (0x80 | (180000UL / (val << 8))); 323 return (0x80 | (180000UL / (val << 8)));
320} 324}
321 325
322#define BEEP_MASK_FROM_REG(val) (val) 326#define BEEP_MASK_FROM_REG(val) ((val) & 0xff7fff)
323#define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) 327#define BEEP_MASK_TO_REG(val) ((val) & 0xff7fff)
324#define BEEP_ENABLE_TO_REG(val) ((val)?1:0)
325#define BEEP_ENABLE_FROM_REG(val) ((val)?1:0)
326 328
327#define DIV_FROM_REG(val) (1 << (val)) 329#define DIV_FROM_REG(val) (1 << (val))
328 330
@@ -363,7 +365,6 @@ struct w83627hf_data {
363 u8 vid; /* Register encoding, combined */ 365 u8 vid; /* Register encoding, combined */
364 u32 alarms; /* Register encoding, combined */ 366 u32 alarms; /* Register encoding, combined */
365 u32 beep_mask; /* Register encoding, combined */ 367 u32 beep_mask; /* Register encoding, combined */
366 u8 beep_enable; /* Boolean */
367 u8 pwm[3]; /* Register value */ 368 u8 pwm[3]; /* Register value */
368 u8 pwm_freq[3]; /* Register value */ 369 u8 pwm_freq[3]; /* Register value */
369 u16 sens[3]; /* 1 = pentium diode; 2 = 3904 diode; 370 u16 sens[3]; /* 1 = pentium diode; 2 = 3904 diode;
@@ -713,65 +714,151 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
713} 714}
714static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 715static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
715 716
716#define show_beep_reg(REG, reg) \ 717static ssize_t
717static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ 718show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
718{ \ 719{
719 struct w83627hf_data *data = w83627hf_update_device(dev); \ 720 struct w83627hf_data *data = w83627hf_update_device(dev);
720 return sprintf(buf,"%ld\n", \ 721 int bitnr = to_sensor_dev_attr(attr)->index;
721 (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \ 722 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
722} 723}
723show_beep_reg(ENABLE, enable) 724static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
724show_beep_reg(MASK, mask) 725static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
726static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
727static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
728static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
729static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
730static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10);
731static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16);
732static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17);
733static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
734static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
735static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
736static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
737static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
738static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
725 739
726#define BEEP_ENABLE 0 /* Store beep_enable */ 740static ssize_t
727#define BEEP_MASK 1 /* Store beep_mask */ 741show_beep_mask(struct device *dev, struct device_attribute *attr, char *buf)
742{
743 struct w83627hf_data *data = w83627hf_update_device(dev);
744 return sprintf(buf, "%ld\n",
745 (long)BEEP_MASK_FROM_REG(data->beep_mask));
746}
728 747
729static ssize_t 748static ssize_t
730store_beep_reg(struct device *dev, const char *buf, size_t count, 749store_beep_mask(struct device *dev, struct device_attribute *attr,
731 int update_mask) 750 const char *buf, size_t count)
732{ 751{
733 struct w83627hf_data *data = dev_get_drvdata(dev); 752 struct w83627hf_data *data = dev_get_drvdata(dev);
734 u32 val, val2; 753 unsigned long val;
735 754
736 val = simple_strtoul(buf, NULL, 10); 755 val = simple_strtoul(buf, NULL, 10);
737 756
738 mutex_lock(&data->update_lock); 757 mutex_lock(&data->update_lock);
739 758
740 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ 759 /* preserve beep enable */
741 data->beep_mask = BEEP_MASK_TO_REG(val); 760 data->beep_mask = (data->beep_mask & 0x8000)
742 w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, 761 | BEEP_MASK_TO_REG(val);
743 data->beep_mask & 0xff); 762 w83627hf_write_value(data, W83781D_REG_BEEP_INTS1,
744 w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, 763 data->beep_mask & 0xff);
745 ((data->beep_mask) >> 16) & 0xff); 764 w83627hf_write_value(data, W83781D_REG_BEEP_INTS3,
746 val2 = (data->beep_mask >> 8) & 0x7f; 765 ((data->beep_mask) >> 16) & 0xff);
747 } else { /* We are storing beep_enable */
748 val2 =
749 w83627hf_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
750 data->beep_enable = BEEP_ENABLE_TO_REG(val);
751 }
752
753 w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, 766 w83627hf_write_value(data, W83781D_REG_BEEP_INTS2,
754 val2 | data->beep_enable << 7); 767 (data->beep_mask >> 8) & 0xff);
755 768
756 mutex_unlock(&data->update_lock); 769 mutex_unlock(&data->update_lock);
757 return count; 770 return count;
758} 771}
759 772
760#define sysfs_beep(REG, reg) \ 773static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
761static ssize_t show_regs_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ 774 show_beep_mask, store_beep_mask);
762{ \ 775
763 return show_beep_##reg(dev, attr, buf); \ 776static ssize_t
764} \ 777show_beep(struct device *dev, struct device_attribute *attr, char *buf)
765static ssize_t \ 778{
766store_regs_beep_##reg (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 779 struct w83627hf_data *data = w83627hf_update_device(dev);
767{ \ 780 int bitnr = to_sensor_dev_attr(attr)->index;
768 return store_beep_reg(dev, buf, count, BEEP_##REG); \ 781 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
769} \ 782}
770static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \ 783
771 show_regs_beep_##reg, store_regs_beep_##reg); 784static ssize_t
785store_beep(struct device *dev, struct device_attribute *attr,
786 const char *buf, size_t count)
787{
788 struct w83627hf_data *data = dev_get_drvdata(dev);
789 int bitnr = to_sensor_dev_attr(attr)->index;
790 unsigned long bit;
791 u8 reg;
792
793 bit = simple_strtoul(buf, NULL, 10);
794 if (bit & ~1)
795 return -EINVAL;
796
797 mutex_lock(&data->update_lock);
798 if (bit)
799 data->beep_mask |= (1 << bitnr);
800 else
801 data->beep_mask &= ~(1 << bitnr);
802
803 if (bitnr < 8) {
804 reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS1);
805 if (bit)
806 reg |= (1 << bitnr);
807 else
808 reg &= ~(1 << bitnr);
809 w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, reg);
810 } else if (bitnr < 16) {
811 reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2);
812 if (bit)
813 reg |= (1 << (bitnr - 8));
814 else
815 reg &= ~(1 << (bitnr - 8));
816 w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, reg);
817 } else {
818 reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS3);
819 if (bit)
820 reg |= (1 << (bitnr - 16));
821 else
822 reg &= ~(1 << (bitnr - 16));
823 w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, reg);
824 }
825 mutex_unlock(&data->update_lock);
826
827 return count;
828}
772 829
773sysfs_beep(ENABLE, enable); 830static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
774sysfs_beep(MASK, mask); 831 show_beep, store_beep, 0);
832static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR,
833 show_beep, store_beep, 1);
834static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR,
835 show_beep, store_beep, 2);
836static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR,
837 show_beep, store_beep, 3);
838static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR,
839 show_beep, store_beep, 8);
840static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR,
841 show_beep, store_beep, 9);
842static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR,
843 show_beep, store_beep, 10);
844static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR,
845 show_beep, store_beep, 16);
846static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR,
847 show_beep, store_beep, 17);
848static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR,
849 show_beep, store_beep, 6);
850static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR,
851 show_beep, store_beep, 7);
852static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR,
853 show_beep, store_beep, 11);
854static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
855 show_beep, store_beep, 4);
856static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
857 show_beep, store_beep, 5);
858static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO | S_IWUSR,
859 show_beep, store_beep, 13);
860static SENSOR_DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
861 show_beep, store_beep, 15);
775 862
776static ssize_t 863static ssize_t
777show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) 864show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
@@ -1014,7 +1101,7 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
1014 VAL = sioaddr + 1; 1101 VAL = sioaddr + 1;
1015 1102
1016 superio_enter(); 1103 superio_enter();
1017 val= superio_inb(DEVID); 1104 val = force_id ? force_id : superio_inb(DEVID);
1018 switch (val) { 1105 switch (val) {
1019 case W627_DEVID: 1106 case W627_DEVID:
1020 sio_data->type = w83627hf; 1107 sio_data->type = w83627hf;
@@ -1073,23 +1160,31 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
1073#define VIN_UNIT_ATTRS(_X_) \ 1160#define VIN_UNIT_ATTRS(_X_) \
1074 &sensor_dev_attr_in##_X_##_input.dev_attr.attr, \ 1161 &sensor_dev_attr_in##_X_##_input.dev_attr.attr, \
1075 &sensor_dev_attr_in##_X_##_min.dev_attr.attr, \ 1162 &sensor_dev_attr_in##_X_##_min.dev_attr.attr, \
1076 &sensor_dev_attr_in##_X_##_max.dev_attr.attr 1163 &sensor_dev_attr_in##_X_##_max.dev_attr.attr, \
1164 &sensor_dev_attr_in##_X_##_alarm.dev_attr.attr, \
1165 &sensor_dev_attr_in##_X_##_beep.dev_attr.attr
1077 1166
1078#define FAN_UNIT_ATTRS(_X_) \ 1167#define FAN_UNIT_ATTRS(_X_) \
1079 &sensor_dev_attr_fan##_X_##_input.dev_attr.attr, \ 1168 &sensor_dev_attr_fan##_X_##_input.dev_attr.attr, \
1080 &sensor_dev_attr_fan##_X_##_min.dev_attr.attr, \ 1169 &sensor_dev_attr_fan##_X_##_min.dev_attr.attr, \
1081 &sensor_dev_attr_fan##_X_##_div.dev_attr.attr 1170 &sensor_dev_attr_fan##_X_##_div.dev_attr.attr, \
1171 &sensor_dev_attr_fan##_X_##_alarm.dev_attr.attr, \
1172 &sensor_dev_attr_fan##_X_##_beep.dev_attr.attr
1082 1173
1083#define TEMP_UNIT_ATTRS(_X_) \ 1174#define TEMP_UNIT_ATTRS(_X_) \
1084 &sensor_dev_attr_temp##_X_##_input.dev_attr.attr, \ 1175 &sensor_dev_attr_temp##_X_##_input.dev_attr.attr, \
1085 &sensor_dev_attr_temp##_X_##_max.dev_attr.attr, \ 1176 &sensor_dev_attr_temp##_X_##_max.dev_attr.attr, \
1086 &sensor_dev_attr_temp##_X_##_max_hyst.dev_attr.attr, \ 1177 &sensor_dev_attr_temp##_X_##_max_hyst.dev_attr.attr, \
1087 &sensor_dev_attr_temp##_X_##_type.dev_attr.attr 1178 &sensor_dev_attr_temp##_X_##_type.dev_attr.attr, \
1179 &sensor_dev_attr_temp##_X_##_alarm.dev_attr.attr, \
1180 &sensor_dev_attr_temp##_X_##_beep.dev_attr.attr
1088 1181
1089static struct attribute *w83627hf_attributes[] = { 1182static struct attribute *w83627hf_attributes[] = {
1090 &dev_attr_in0_input.attr, 1183 &dev_attr_in0_input.attr,
1091 &dev_attr_in0_min.attr, 1184 &dev_attr_in0_min.attr,
1092 &dev_attr_in0_max.attr, 1185 &dev_attr_in0_max.attr,
1186 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1187 &sensor_dev_attr_in0_beep.dev_attr.attr,
1093 VIN_UNIT_ATTRS(2), 1188 VIN_UNIT_ATTRS(2),
1094 VIN_UNIT_ATTRS(3), 1189 VIN_UNIT_ATTRS(3),
1095 VIN_UNIT_ATTRS(4), 1190 VIN_UNIT_ATTRS(4),
@@ -1103,7 +1198,7 @@ static struct attribute *w83627hf_attributes[] = {
1103 TEMP_UNIT_ATTRS(2), 1198 TEMP_UNIT_ATTRS(2),
1104 1199
1105 &dev_attr_alarms.attr, 1200 &dev_attr_alarms.attr,
1106 &dev_attr_beep_enable.attr, 1201 &sensor_dev_attr_beep_enable.dev_attr.attr,
1107 &dev_attr_beep_mask.attr, 1202 &dev_attr_beep_mask.attr,
1108 1203
1109 &sensor_dev_attr_pwm1.dev_attr.attr, 1204 &sensor_dev_attr_pwm1.dev_attr.attr,
@@ -1193,12 +1288,20 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1193 || (err = device_create_file(dev, 1288 || (err = device_create_file(dev,
1194 &sensor_dev_attr_in5_max.dev_attr)) 1289 &sensor_dev_attr_in5_max.dev_attr))
1195 || (err = device_create_file(dev, 1290 || (err = device_create_file(dev,
1291 &sensor_dev_attr_in5_alarm.dev_attr))
1292 || (err = device_create_file(dev,
1293 &sensor_dev_attr_in5_beep.dev_attr))
1294 || (err = device_create_file(dev,
1196 &sensor_dev_attr_in6_input.dev_attr)) 1295 &sensor_dev_attr_in6_input.dev_attr))
1197 || (err = device_create_file(dev, 1296 || (err = device_create_file(dev,
1198 &sensor_dev_attr_in6_min.dev_attr)) 1297 &sensor_dev_attr_in6_min.dev_attr))
1199 || (err = device_create_file(dev, 1298 || (err = device_create_file(dev,
1200 &sensor_dev_attr_in6_max.dev_attr)) 1299 &sensor_dev_attr_in6_max.dev_attr))
1201 || (err = device_create_file(dev, 1300 || (err = device_create_file(dev,
1301 &sensor_dev_attr_in6_alarm.dev_attr))
1302 || (err = device_create_file(dev,
1303 &sensor_dev_attr_in6_beep.dev_attr))
1304 || (err = device_create_file(dev,
1202 &sensor_dev_attr_pwm1_freq.dev_attr)) 1305 &sensor_dev_attr_pwm1_freq.dev_attr))
1203 || (err = device_create_file(dev, 1306 || (err = device_create_file(dev,
1204 &sensor_dev_attr_pwm2_freq.dev_attr))) 1307 &sensor_dev_attr_pwm2_freq.dev_attr)))
@@ -1212,18 +1315,30 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
1212 || (err = device_create_file(dev, 1315 || (err = device_create_file(dev,
1213 &sensor_dev_attr_in1_max.dev_attr)) 1316 &sensor_dev_attr_in1_max.dev_attr))
1214 || (err = device_create_file(dev, 1317 || (err = device_create_file(dev,
1318 &sensor_dev_attr_in1_alarm.dev_attr))
1319 || (err = device_create_file(dev,
1320 &sensor_dev_attr_in1_beep.dev_attr))
1321 || (err = device_create_file(dev,
1215 &sensor_dev_attr_fan3_input.dev_attr)) 1322 &sensor_dev_attr_fan3_input.dev_attr))
1216 || (err = device_create_file(dev, 1323 || (err = device_create_file(dev,
1217 &sensor_dev_attr_fan3_min.dev_attr)) 1324 &sensor_dev_attr_fan3_min.dev_attr))
1218 || (err = device_create_file(dev, 1325 || (err = device_create_file(dev,
1219 &sensor_dev_attr_fan3_div.dev_attr)) 1326 &sensor_dev_attr_fan3_div.dev_attr))
1220 || (err = device_create_file(dev, 1327 || (err = device_create_file(dev,
1328 &sensor_dev_attr_fan3_alarm.dev_attr))
1329 || (err = device_create_file(dev,
1330 &sensor_dev_attr_fan3_beep.dev_attr))
1331 || (err = device_create_file(dev,
1221 &sensor_dev_attr_temp3_input.dev_attr)) 1332 &sensor_dev_attr_temp3_input.dev_attr))
1222 || (err = device_create_file(dev, 1333 || (err = device_create_file(dev,
1223 &sensor_dev_attr_temp3_max.dev_attr)) 1334 &sensor_dev_attr_temp3_max.dev_attr))
1224 || (err = device_create_file(dev, 1335 || (err = device_create_file(dev,
1225 &sensor_dev_attr_temp3_max_hyst.dev_attr)) 1336 &sensor_dev_attr_temp3_max_hyst.dev_attr))
1226 || (err = device_create_file(dev, 1337 || (err = device_create_file(dev,
1338 &sensor_dev_attr_temp3_alarm.dev_attr))
1339 || (err = device_create_file(dev,
1340 &sensor_dev_attr_temp3_beep.dev_attr))
1341 || (err = device_create_file(dev,
1227 &sensor_dev_attr_temp3_type.dev_attr))) 1342 &sensor_dev_attr_temp3_type.dev_attr)))
1228 goto ERROR4; 1343 goto ERROR4;
1229 1344
@@ -1511,6 +1626,11 @@ static void __devinit w83627hf_init_device(struct platform_device *pdev)
1511 (w83627hf_read_value(data, 1626 (w83627hf_read_value(data,
1512 W83781D_REG_CONFIG) & 0xf7) 1627 W83781D_REG_CONFIG) & 0xf7)
1513 | 0x01); 1628 | 0x01);
1629
1630 /* Enable VBAT monitoring if needed */
1631 tmp = w83627hf_read_value(data, W83781D_REG_VBAT);
1632 if (!(tmp & 0x01))
1633 w83627hf_write_value(data, W83781D_REG_VBAT, tmp | 0x01);
1514} 1634}
1515 1635
1516static void w83627hf_update_fan_div(struct w83627hf_data *data) 1636static void w83627hf_update_fan_div(struct w83627hf_data *data)
@@ -1603,8 +1723,7 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1603 (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) | 1723 (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) |
1604 (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16); 1724 (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16);
1605 i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); 1725 i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2);
1606 data->beep_enable = i >> 7; 1726 data->beep_mask = (i << 8) |
1607 data->beep_mask = ((i & 0x7f) << 8) |
1608 w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) | 1727 w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) |
1609 w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16; 1728 w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16;
1610 data->last_updated = jiffies; 1729 data->last_updated = jiffies;
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index e0fa7520400d..7421f6ea53e1 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -28,7 +28,6 @@
28 as99127f 7 3 0 3 0x31 0x12c3 yes no 28 as99127f 7 3 0 3 0x31 0x12c3 yes no
29 as99127f rev.2 (type_name = as99127f) 0x31 0x5ca3 yes no 29 as99127f rev.2 (type_name = as99127f) 0x31 0x5ca3 yes no
30 w83781d 7 3 0 3 0x10-1 0x5ca3 yes yes 30 w83781d 7 3 0 3 0x10-1 0x5ca3 yes yes
31 w83627hf 9 3 2 3 0x21 0x5ca3 yes yes(LPC)
32 w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes 31 w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes
33 w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no 32 w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no
34 33
@@ -54,13 +53,12 @@
54static struct platform_device *pdev; 53static struct platform_device *pdev;
55 54
56/* Addresses to scan */ 55/* Addresses to scan */
57static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 56static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
58 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 57 0x2e, 0x2f, I2C_CLIENT_END };
59 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
60static unsigned short isa_address = 0x290; 58static unsigned short isa_address = 0x290;
61 59
62/* Insmod parameters */ 60/* Insmod parameters */
63I2C_CLIENT_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f); 61I2C_CLIENT_INSMOD_4(w83781d, w83782d, w83783s, as99127f);
64I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " 62I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
65 "{bus, clientaddr, subclientaddr1, subclientaddr2}"); 63 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
66 64
@@ -114,7 +112,7 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
114#define W83781D_REG_ALARM1 0x41 112#define W83781D_REG_ALARM1 0x41
115#define W83781D_REG_ALARM2 0x42 113#define W83781D_REG_ALARM2 0x42
116 114
117/* Real-time status (W83782D, W83783S, W83627HF) */ 115/* Real-time status (W83782D, W83783S) */
118#define W83782D_REG_ALARM1 0x459 116#define W83782D_REG_ALARM1 0x459
119#define W83782D_REG_ALARM2 0x45A 117#define W83782D_REG_ALARM2 0x45A
120#define W83782D_REG_ALARM3 0x45B 118#define W83782D_REG_ALARM3 0x45B
@@ -153,10 +151,6 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
153 151
154#define W83781D_DEFAULT_BETA 3435 152#define W83781D_DEFAULT_BETA 3435
155 153
156/* RT Table registers */
157#define W83781D_REG_RT_IDX 0x50
158#define W83781D_REG_RT_VAL 0x51
159
160/* Conversions */ 154/* Conversions */
161#define IN_TO_REG(val) SENSORS_LIMIT(((val) + 8) / 16, 0, 255) 155#define IN_TO_REG(val) SENSORS_LIMIT(((val) + 8) / 16, 0, 255)
162#define IN_FROM_REG(val) ((val) * 16) 156#define IN_FROM_REG(val) ((val) * 16)
@@ -271,7 +265,6 @@ static struct i2c_driver w83781d_driver = {
271 .driver = { 265 .driver = {
272 .name = "w83781d", 266 .name = "w83781d",
273 }, 267 },
274 .id = I2C_DRIVERID_W83781D,
275 .attach_adapter = w83781d_attach_adapter, 268 .attach_adapter = w83781d_attach_adapter,
276 .detach_client = w83781d_detach_client, 269 .detach_client = w83781d_detach_client,
277}; 270};
@@ -696,7 +689,7 @@ store_fan_div(struct device *dev, struct device_attribute *da,
696 unsigned long val = simple_strtoul(buf, NULL, 10); 689 unsigned long val = simple_strtoul(buf, NULL, 10);
697 690
698 mutex_lock(&data->update_lock); 691 mutex_lock(&data->update_lock);
699 692
700 /* Save fan_min */ 693 /* Save fan_min */
701 min = FAN_FROM_REG(data->fan_min[nr], 694 min = FAN_FROM_REG(data->fan_min[nr],
702 DIV_FROM_REG(data->fan_div[nr])); 695 DIV_FROM_REG(data->fan_div[nr]));
@@ -963,8 +956,6 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
963 client_name = "w83782d subclient"; 956 client_name = "w83782d subclient";
964 else if (kind == w83783s) 957 else if (kind == w83783s)
965 client_name = "w83783s subclient"; 958 client_name = "w83783s subclient";
966 else if (kind == w83627hf)
967 client_name = "w83627hf subclient";
968 else if (kind == as99127f) 959 else if (kind == as99127f)
969 client_name = "as99127f subclient"; 960 client_name = "as99127f subclient";
970 961
@@ -1004,7 +995,7 @@ ERROR_SC_0:
1004#define IN_UNIT_ATTRS(X) \ 995#define IN_UNIT_ATTRS(X) \
1005 &sensor_dev_attr_in##X##_input.dev_attr.attr, \ 996 &sensor_dev_attr_in##X##_input.dev_attr.attr, \
1006 &sensor_dev_attr_in##X##_min.dev_attr.attr, \ 997 &sensor_dev_attr_in##X##_min.dev_attr.attr, \
1007 &sensor_dev_attr_in##X##_max.dev_attr.attr, \ 998 &sensor_dev_attr_in##X##_max.dev_attr.attr, \
1008 &sensor_dev_attr_in##X##_alarm.dev_attr.attr, \ 999 &sensor_dev_attr_in##X##_alarm.dev_attr.attr, \
1009 &sensor_dev_attr_in##X##_beep.dev_attr.attr 1000 &sensor_dev_attr_in##X##_beep.dev_attr.attr
1010 1001
@@ -1268,9 +1259,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1268 kind = w83782d; 1259 kind = w83782d;
1269 else if (val1 == 0x40 && vendid == winbond && address == 0x2d) 1260 else if (val1 == 0x40 && vendid == winbond && address == 0x2d)
1270 kind = w83783s; 1261 kind = w83783s;
1271 else if (val1 == 0x21 && vendid == winbond) 1262 else if (val1 == 0x31)
1272 kind = w83627hf;
1273 else if (val1 == 0x31 && address >= 0x28)
1274 kind = as99127f; 1263 kind = as99127f;
1275 else { 1264 else {
1276 if (kind == 0) 1265 if (kind == 0)
@@ -1288,8 +1277,6 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1288 client_name = "w83782d"; 1277 client_name = "w83782d";
1289 } else if (kind == w83783s) { 1278 } else if (kind == w83783s) {
1290 client_name = "w83783s"; 1279 client_name = "w83783s";
1291 } else if (kind == w83627hf) {
1292 client_name = "w83627hf";
1293 } else if (kind == as99127f) { 1280 } else if (kind == as99127f) {
1294 client_name = "as99127f"; 1281 client_name = "as99127f";
1295 } 1282 }
@@ -1396,10 +1383,6 @@ w83781d_isa_probe(struct platform_device *pdev)
1396 1383
1397 reg = w83781d_read_value(data, W83781D_REG_WCHIPID); 1384 reg = w83781d_read_value(data, W83781D_REG_WCHIPID);
1398 switch (reg) { 1385 switch (reg) {
1399 case 0x21:
1400 data->type = w83627hf;
1401 name = "w83627hf";
1402 break;
1403 case 0x30: 1386 case 0x30:
1404 data->type = w83782d; 1387 data->type = w83782d;
1405 name = "w83782d"; 1388 name = "w83782d";
@@ -1453,9 +1436,9 @@ w83781d_isa_remove(struct platform_device *pdev)
1453} 1436}
1454 1437
1455/* The SMBus locks itself, usually, but nothing may access the Winbond between 1438/* The SMBus locks itself, usually, but nothing may access the Winbond between
1456 bank switches. ISA access must always be locked explicitly! 1439 bank switches. ISA access must always be locked explicitly!
1457 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks, 1440 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1458 would slow down the W83781D access and should not be necessary. 1441 would slow down the W83781D access and should not be necessary.
1459 There are some ugly typecasts here, but the good news is - they should 1442 There are some ugly typecasts here, but the good news is - they should
1460 nowhere else be necessary! */ 1443 nowhere else be necessary! */
1461static int 1444static int
@@ -1599,11 +1582,6 @@ w83781d_init_device(struct device *dev)
1599 int type = data->type; 1582 int type = data->type;
1600 u8 tmp; 1583 u8 tmp;
1601 1584
1602 if (type == w83627hf)
1603 dev_info(dev, "The W83627HF chip is better supported by the "
1604 "w83627hf driver, support will be dropped from the "
1605 "w83781d driver soon\n");
1606
1607 if (reset && type != as99127f) { /* this resets registers we don't have 1585 if (reset && type != as99127f) { /* this resets registers we don't have
1608 documentation for on the as99127f */ 1586 documentation for on the as99127f */
1609 /* Resetting the chip has been the default for a long time, 1587 /* Resetting the chip has been the default for a long time,
@@ -1717,8 +1695,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1717 w83781d_read_value(data, W83781D_REG_IN_MIN(i)); 1695 w83781d_read_value(data, W83781D_REG_IN_MIN(i));
1718 data->in_max[i] = 1696 data->in_max[i] =
1719 w83781d_read_value(data, W83781D_REG_IN_MAX(i)); 1697 w83781d_read_value(data, W83781D_REG_IN_MAX(i));
1720 if ((data->type != w83782d) 1698 if ((data->type != w83782d) && (i == 6))
1721 && (data->type != w83627hf) && (i == 6))
1722 break; 1699 break;
1723 } 1700 }
1724 for (i = 0; i < 3; i++) { 1701 for (i = 0; i < 3; i++) {
@@ -1776,7 +1753,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1776 data->fan_div[1] |= (i >> 4) & 0x04; 1753 data->fan_div[1] |= (i >> 4) & 0x04;
1777 data->fan_div[2] |= (i >> 5) & 0x04; 1754 data->fan_div[2] |= (i >> 5) & 0x04;
1778 } 1755 }
1779 if ((data->type == w83782d) || (data->type == w83627hf)) { 1756 if (data->type == w83782d) {
1780 data->alarms = w83781d_read_value(data, 1757 data->alarms = w83781d_read_value(data,
1781 W83782D_REG_ALARM1) 1758 W83782D_REG_ALARM1)
1782 | (w83781d_read_value(data, 1759 | (w83781d_read_value(data,
@@ -1886,13 +1863,11 @@ w83781d_isa_found(unsigned short address)
1886 outb_p(W83781D_REG_WCHIPID, address + W83781D_ADDR_REG_OFFSET); 1863 outb_p(W83781D_REG_WCHIPID, address + W83781D_ADDR_REG_OFFSET);
1887 val = inb_p(address + W83781D_DATA_REG_OFFSET); 1864 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1888 if ((val & 0xfe) == 0x10 /* W83781D */ 1865 if ((val & 0xfe) == 0x10 /* W83781D */
1889 || val == 0x30 /* W83782D */ 1866 || val == 0x30) /* W83782D */
1890 || val == 0x21) /* W83627HF */
1891 found = 1; 1867 found = 1;
1892 1868
1893 if (found) 1869 if (found)
1894 pr_info("w83781d: Found a %s chip at %#x\n", 1870 pr_info("w83781d: Found a %s chip at %#x\n",
1895 val == 0x21 ? "W83627HF" :
1896 val == 0x30 ? "W83782D" : "W83781D", (int)address); 1871 val == 0x30 ? "W83782D" : "W83781D", (int)address);
1897 1872
1898 release: 1873 release:
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index a9c01a6f0057..85bd21ee3298 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -840,14 +840,12 @@ static ssize_t store_vrm_reg(struct device *dev,
840 struct device_attribute *attr, 840 struct device_attribute *attr,
841 const char *buf, size_t count) 841 const char *buf, size_t count)
842{ 842{
843 struct i2c_client *client = to_i2c_client(dev); 843 struct w83791d_data *data = dev_get_drvdata(dev);
844 struct w83791d_data *data = i2c_get_clientdata(client);
845 unsigned long val = simple_strtoul(buf, NULL, 10);
846 844
847 /* No lock needed as vrm is internal to the driver 845 /* No lock needed as vrm is internal to the driver
848 (not read from a chip register) and so is not 846 (not read from a chip register) and so is not
849 updated in w83791d_update_device() */ 847 updated in w83791d_update_device() */
850 data->vrm = val; 848 data->vrm = simple_strtoul(buf, NULL, 10);
851 849
852 return count; 850 return count;
853} 851}
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 48599e1cc554..3ba1d6b33473 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -131,6 +131,7 @@ static u8 scale_in_add[] = { 0, 0, 0, 0, 0, 0, 0, 150, 150, 0 };
131#define PWM_DUTY 0 131#define PWM_DUTY 0
132#define PWM_START 1 132#define PWM_START 1
133#define PWM_NONSTOP 2 133#define PWM_NONSTOP 2
134#define PWM_STOP_TIME 3
134#define W83793_REG_PWM(index, nr) (((nr) == 0 ? 0xb3 : \ 135#define W83793_REG_PWM(index, nr) (((nr) == 0 ? 0xb3 : \
135 (nr) == 1 ? 0x220 : 0x218) + (index)) 136 (nr) == 1 ? 0x220 : 0x218) + (index))
136 137
@@ -242,9 +243,7 @@ static struct i2c_driver w83793_driver = {
242static ssize_t 243static ssize_t
243show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 244show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
244{ 245{
245 struct i2c_client *client = to_i2c_client(dev); 246 struct w83793_data *data = dev_get_drvdata(dev);
246 struct w83793_data *data = i2c_get_clientdata(client);
247
248 return sprintf(buf, "%d\n", data->vrm); 247 return sprintf(buf, "%d\n", data->vrm);
249} 248}
250 249
@@ -263,9 +262,7 @@ static ssize_t
263store_vrm(struct device *dev, struct device_attribute *attr, 262store_vrm(struct device *dev, struct device_attribute *attr,
264 const char *buf, size_t count) 263 const char *buf, size_t count)
265{ 264{
266 struct i2c_client *client = to_i2c_client(dev); 265 struct w83793_data *data = dev_get_drvdata(dev);
267 struct w83793_data *data = i2c_get_clientdata(client);
268
269 data->vrm = simple_strtoul(buf, NULL, 10); 266 data->vrm = simple_strtoul(buf, NULL, 10);
270 return count; 267 return count;
271} 268}
@@ -407,10 +404,6 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
407 return count; 404 return count;
408} 405}
409 406
410#define PWM_DUTY 0
411#define PWM_START 1
412#define PWM_NONSTOP 2
413#define PWM_STOP_TIME 3
414static ssize_t 407static ssize_t
415show_pwm(struct device *dev, struct device_attribute *attr, char *buf) 408show_pwm(struct device *dev, struct device_attribute *attr, char *buf)
416{ 409{
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index b5db354e2f19..1d6259d29e74 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -96,7 +96,6 @@ static struct i2c_driver w83l785ts_driver = {
96 .driver = { 96 .driver = {
97 .name = "w83l785ts", 97 .name = "w83l785ts",
98 }, 98 },
99 .id = I2C_DRIVERID_W83L785TS,
100 .attach_adapter = w83l785ts_attach_adapter, 99 .attach_adapter = w83l785ts_attach_adapter,
101 .detach_client = w83l785ts_detach_client, 100 .detach_client = w83l785ts_detach_client,
102}; 101};
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
new file mode 100644
index 000000000000..1dbee4fa23ad
--- /dev/null
+++ b/drivers/hwmon/w83l786ng.c
@@ -0,0 +1,821 @@
1/*
2 w83l786ng.c - Linux kernel driver for hardware monitoring
3 Copyright (c) 2007 Kevin Lo <kevlo@kevlo.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation - version 2.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
18*/
19
20/*
21 Supports following chips:
22
23 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
24 w83l786ng 3 2 2 2 0x7b 0x5ca3 yes no
25*/
26
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <linux/i2c.h>
31#include <linux/hwmon.h>
32#include <linux/hwmon-vid.h>
33#include <linux/hwmon-sysfs.h>
34#include <linux/err.h>
35#include <linux/mutex.h>
36
37/* Addresses to scan */
38static unsigned short normal_i2c[] = { 0x2e, 0x2f, I2C_CLIENT_END };
39
40/* Insmod parameters */
41I2C_CLIENT_INSMOD_1(w83l786ng);
42
43static int reset;
44module_param(reset, bool, 0);
45MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
46
47#define W83L786NG_REG_IN_MIN(nr) (0x2C + (nr) * 2)
48#define W83L786NG_REG_IN_MAX(nr) (0x2B + (nr) * 2)
49#define W83L786NG_REG_IN(nr) ((nr) + 0x20)
50
51#define W83L786NG_REG_FAN(nr) ((nr) + 0x28)
52#define W83L786NG_REG_FAN_MIN(nr) ((nr) + 0x3B)
53
54#define W83L786NG_REG_CONFIG 0x40
55#define W83L786NG_REG_ALARM1 0x41
56#define W83L786NG_REG_ALARM2 0x42
57#define W83L786NG_REG_GPIO_EN 0x47
58#define W83L786NG_REG_MAN_ID2 0x4C
59#define W83L786NG_REG_MAN_ID1 0x4D
60#define W83L786NG_REG_CHIP_ID 0x4E
61
62#define W83L786NG_REG_DIODE 0x53
63#define W83L786NG_REG_FAN_DIV 0x54
64#define W83L786NG_REG_FAN_CFG 0x80
65
66#define W83L786NG_REG_TOLERANCE 0x8D
67
68static const u8 W83L786NG_REG_TEMP[2][3] = {
69 { 0x25, /* TEMP 0 in DataSheet */
70 0x35, /* TEMP 0 Over in DataSheet */
71 0x36 }, /* TEMP 0 Hyst in DataSheet */
72 { 0x26, /* TEMP 1 in DataSheet */
73 0x37, /* TEMP 1 Over in DataSheet */
74 0x38 } /* TEMP 1 Hyst in DataSheet */
75};
76
77static const u8 W83L786NG_PWM_MODE_SHIFT[] = {6, 7};
78static const u8 W83L786NG_PWM_ENABLE_SHIFT[] = {2, 4};
79
80/* FAN Duty Cycle, be used to control */
81static const u8 W83L786NG_REG_PWM[] = {0x81, 0x87};
82
83
84static inline u8
85FAN_TO_REG(long rpm, int div)
86{
87 if (rpm == 0)
88 return 255;
89 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
90 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
91}
92
93#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \
94 ((val) == 255 ? 0 : \
95 1350000 / ((val) * (div))))
96
97/* for temp */
98#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \
99 : (val)) / 1000, 0, 0xff))
100#define TEMP_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
101
102/* The analog voltage inputs have 8mV LSB. Since the sysfs output is
103 in mV as would be measured on the chip input pin, need to just
104 multiply/divide by 8 to translate from/to register values. */
105#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 4) / 8), 0, 255))
106#define IN_FROM_REG(val) ((val) * 8)
107
108#define DIV_FROM_REG(val) (1 << (val))
109
110static inline u8
111DIV_TO_REG(long val)
112{
113 int i;
114 val = SENSORS_LIMIT(val, 1, 128) >> 1;
115 for (i = 0; i < 7; i++) {
116 if (val == 0)
117 break;
118 val >>= 1;
119 }
120 return ((u8) i);
121}
122
123struct w83l786ng_data {
124 struct i2c_client client;
125 struct device *hwmon_dev;
126 struct mutex update_lock;
127 char valid; /* !=0 if following fields are valid */
128 unsigned long last_updated; /* In jiffies */
129 unsigned long last_nonvolatile; /* In jiffies, last time we update the
130 nonvolatile registers */
131
132 u8 in[3];
133 u8 in_max[3];
134 u8 in_min[3];
135 u8 fan[2];
136 u8 fan_div[2];
137 u8 fan_min[2];
138 u8 temp_type[2];
139 u8 temp[2][3];
140 u8 pwm[2];
141 u8 pwm_mode[2]; /* 0->DC variable voltage
142 1->PWM variable duty cycle */
143
144 u8 pwm_enable[2]; /* 1->manual
145 2->thermal cruise (also called SmartFan I) */
146 u8 tolerance[2];
147};
148
149static int w83l786ng_attach_adapter(struct i2c_adapter *adapter);
150static int w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind);
151static int w83l786ng_detach_client(struct i2c_client *client);
152static void w83l786ng_init_client(struct i2c_client *client);
153static struct w83l786ng_data *w83l786ng_update_device(struct device *dev);
154
155static struct i2c_driver w83l786ng_driver = {
156 .driver = {
157 .name = "w83l786ng",
158 },
159 .attach_adapter = w83l786ng_attach_adapter,
160 .detach_client = w83l786ng_detach_client,
161};
162
163static u8
164w83l786ng_read_value(struct i2c_client *client, u8 reg)
165{
166 return i2c_smbus_read_byte_data(client, reg);
167}
168
169static int
170w83l786ng_write_value(struct i2c_client *client, u8 reg, u8 value)
171{
172 return i2c_smbus_write_byte_data(client, reg, value);
173}
174
175/* following are the sysfs callback functions */
176#define show_in_reg(reg) \
177static ssize_t \
178show_##reg(struct device *dev, struct device_attribute *attr, \
179 char *buf) \
180{ \
181 int nr = to_sensor_dev_attr(attr)->index; \
182 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
183 return sprintf(buf,"%d\n", IN_FROM_REG(data->reg[nr])); \
184}
185
186show_in_reg(in)
187show_in_reg(in_min)
188show_in_reg(in_max)
189
190#define store_in_reg(REG, reg) \
191static ssize_t \
192store_in_##reg (struct device *dev, struct device_attribute *attr, \
193 const char *buf, size_t count) \
194{ \
195 int nr = to_sensor_dev_attr(attr)->index; \
196 struct i2c_client *client = to_i2c_client(dev); \
197 struct w83l786ng_data *data = i2c_get_clientdata(client); \
198 unsigned long val = simple_strtoul(buf, NULL, 10); \
199 mutex_lock(&data->update_lock); \
200 data->in_##reg[nr] = IN_TO_REG(val); \
201 w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
202 data->in_##reg[nr]); \
203 mutex_unlock(&data->update_lock); \
204 return count; \
205}
206
207store_in_reg(MIN, min)
208store_in_reg(MAX, max)
209
210static struct sensor_device_attribute sda_in_input[] = {
211 SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
212 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
213 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
214};
215
216static struct sensor_device_attribute sda_in_min[] = {
217 SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0),
218 SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1),
219 SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2),
220};
221
222static struct sensor_device_attribute sda_in_max[] = {
223 SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0),
224 SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1),
225 SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
226};
227
228#define show_fan_reg(reg) \
229static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
230 char *buf) \
231{ \
232 int nr = to_sensor_dev_attr(attr)->index; \
233 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
234 return sprintf(buf,"%d\n", \
235 FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr]))); \
236}
237
238show_fan_reg(fan);
239show_fan_reg(fan_min);
240
241static ssize_t
242store_fan_min(struct device *dev, struct device_attribute *attr,
243 const char *buf, size_t count)
244{
245 int nr = to_sensor_dev_attr(attr)->index;
246 struct i2c_client *client = to_i2c_client(dev);
247 struct w83l786ng_data *data = i2c_get_clientdata(client);
248 u32 val;
249
250 val = simple_strtoul(buf, NULL, 10);
251 mutex_lock(&data->update_lock);
252 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
253 w83l786ng_write_value(client, W83L786NG_REG_FAN_MIN(nr),
254 data->fan_min[nr]);
255 mutex_unlock(&data->update_lock);
256
257 return count;
258}
259
260static ssize_t
261show_fan_div(struct device *dev, struct device_attribute *attr,
262 char *buf)
263{
264 int nr = to_sensor_dev_attr(attr)->index;
265 struct w83l786ng_data *data = w83l786ng_update_device(dev);
266 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr]));
267}
268
269/* Note: we save and restore the fan minimum here, because its value is
270 determined in part by the fan divisor. This follows the principle of
271 least surprise; the user doesn't expect the fan minimum to change just
272 because the divisor changed. */
273static ssize_t
274store_fan_div(struct device *dev, struct device_attribute *attr,
275 const char *buf, size_t count)
276{
277 int nr = to_sensor_dev_attr(attr)->index;
278 struct i2c_client *client = to_i2c_client(dev);
279 struct w83l786ng_data *data = i2c_get_clientdata(client);
280
281 unsigned long min;
282 u8 tmp_fan_div;
283 u8 fan_div_reg;
284 u8 keep_mask = 0;
285 u8 new_shift = 0;
286
287 /* Save fan_min */
288 mutex_lock(&data->update_lock);
289 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
290
291 data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10));
292
293 switch (nr) {
294 case 0:
295 keep_mask = 0xf8;
296 new_shift = 0;
297 break;
298 case 1:
299 keep_mask = 0x8f;
300 new_shift = 4;
301 break;
302 }
303
304 fan_div_reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV)
305 & keep_mask;
306
307 tmp_fan_div = (data->fan_div[nr] << new_shift) & ~keep_mask;
308
309 w83l786ng_write_value(client, W83L786NG_REG_FAN_DIV,
310 fan_div_reg | tmp_fan_div);
311
312 /* Restore fan_min */
313 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
314 w83l786ng_write_value(client, W83L786NG_REG_FAN_MIN(nr),
315 data->fan_min[nr]);
316 mutex_unlock(&data->update_lock);
317
318 return count;
319}
320
321static struct sensor_device_attribute sda_fan_input[] = {
322 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
323 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
324};
325
326static struct sensor_device_attribute sda_fan_min[] = {
327 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
328 store_fan_min, 0),
329 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
330 store_fan_min, 1),
331};
332
333static struct sensor_device_attribute sda_fan_div[] = {
334 SENSOR_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div,
335 store_fan_div, 0),
336 SENSOR_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div,
337 store_fan_div, 1),
338};
339
340
341/* read/write the temperature, includes measured value and limits */
342
343static ssize_t
344show_temp(struct device *dev, struct device_attribute *attr, char *buf)
345{
346 struct sensor_device_attribute_2 *sensor_attr =
347 to_sensor_dev_attr_2(attr);
348 int nr = sensor_attr->nr;
349 int index = sensor_attr->index;
350 struct w83l786ng_data *data = w83l786ng_update_device(dev);
351 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
352}
353
354static ssize_t
355store_temp(struct device *dev, struct device_attribute *attr,
356 const char *buf, size_t count)
357{
358 struct sensor_device_attribute_2 *sensor_attr =
359 to_sensor_dev_attr_2(attr);
360 int nr = sensor_attr->nr;
361 int index = sensor_attr->index;
362 struct i2c_client *client = to_i2c_client(dev);
363 struct w83l786ng_data *data = i2c_get_clientdata(client);
364 s32 val;
365
366 val = simple_strtol(buf, NULL, 10);
367 mutex_lock(&data->update_lock);
368 data->temp[nr][index] = TEMP_TO_REG(val);
369 w83l786ng_write_value(client, W83L786NG_REG_TEMP[nr][index],
370 data->temp[nr][index]);
371 mutex_unlock(&data->update_lock);
372
373 return count;
374}
375
376static struct sensor_device_attribute_2 sda_temp_input[] = {
377 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
378 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0),
379};
380
381static struct sensor_device_attribute_2 sda_temp_max[] = {
382 SENSOR_ATTR_2(temp1_max, S_IRUGO | S_IWUSR,
383 show_temp, store_temp, 0, 1),
384 SENSOR_ATTR_2(temp2_max, S_IRUGO | S_IWUSR,
385 show_temp, store_temp, 1, 1),
386};
387
388static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
389 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR,
390 show_temp, store_temp, 0, 2),
391 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR,
392 show_temp, store_temp, 1, 2),
393};
394
395#define show_pwm_reg(reg) \
396static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
397 char *buf) \
398{ \
399 struct w83l786ng_data *data = w83l786ng_update_device(dev); \
400 int nr = to_sensor_dev_attr(attr)->index; \
401 return sprintf(buf, "%d\n", data->reg[nr]); \
402}
403
404show_pwm_reg(pwm_mode)
405show_pwm_reg(pwm_enable)
406show_pwm_reg(pwm)
407
408static ssize_t
409store_pwm_mode(struct device *dev, struct device_attribute *attr,
410 const char *buf, size_t count)
411{
412 int nr = to_sensor_dev_attr(attr)->index;
413 struct i2c_client *client = to_i2c_client(dev);
414 struct w83l786ng_data *data = i2c_get_clientdata(client);
415 u32 val = simple_strtoul(buf, NULL, 10);
416 u8 reg;
417
418 if (val > 1)
419 return -EINVAL;
420 mutex_lock(&data->update_lock);
421 data->pwm_mode[nr] = val;
422 reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
423 reg &= ~(1 << W83L786NG_PWM_MODE_SHIFT[nr]);
424 if (!val)
425 reg |= 1 << W83L786NG_PWM_MODE_SHIFT[nr];
426 w83l786ng_write_value(client, W83L786NG_REG_FAN_CFG, reg);
427 mutex_unlock(&data->update_lock);
428 return count;
429}
430
431static ssize_t
432store_pwm(struct device *dev, struct device_attribute *attr,
433 const char *buf, size_t count)
434{
435 int nr = to_sensor_dev_attr(attr)->index;
436 struct i2c_client *client = to_i2c_client(dev);
437 struct w83l786ng_data *data = i2c_get_clientdata(client);
438 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255);
439
440 mutex_lock(&data->update_lock);
441 data->pwm[nr] = val;
442 w83l786ng_write_value(client, W83L786NG_REG_PWM[nr], val);
443 mutex_unlock(&data->update_lock);
444 return count;
445}
446
447static ssize_t
448store_pwm_enable(struct device *dev, struct device_attribute *attr,
449 const char *buf, size_t count)
450{
451 int nr = to_sensor_dev_attr(attr)->index;
452 struct i2c_client *client = to_i2c_client(dev);
453 struct w83l786ng_data *data = i2c_get_clientdata(client);
454 u32 val = simple_strtoul(buf, NULL, 10);
455
456 u8 reg;
457
458 if (!val || (val > 2)) /* only modes 1 and 2 are supported */
459 return -EINVAL;
460
461 mutex_lock(&data->update_lock);
462 reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
463 data->pwm_enable[nr] = val;
464 reg &= ~(0x02 << W83L786NG_PWM_ENABLE_SHIFT[nr]);
465 reg |= (val - 1) << W83L786NG_PWM_ENABLE_SHIFT[nr];
466 w83l786ng_write_value(client, W83L786NG_REG_FAN_CFG, reg);
467 mutex_unlock(&data->update_lock);
468 return count;
469}
470
471static struct sensor_device_attribute sda_pwm[] = {
472 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
473 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
474};
475
476static struct sensor_device_attribute sda_pwm_mode[] = {
477 SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
478 store_pwm_mode, 0),
479 SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
480 store_pwm_mode, 1),
481};
482
483static struct sensor_device_attribute sda_pwm_enable[] = {
484 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
485 store_pwm_enable, 0),
486 SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
487 store_pwm_enable, 1),
488};
489
490/* For Smart Fan I/Thermal Cruise and Smart Fan II */
491static ssize_t
492show_tolerance(struct device *dev, struct device_attribute *attr, char *buf)
493{
494 int nr = to_sensor_dev_attr(attr)->index;
495 struct w83l786ng_data *data = w83l786ng_update_device(dev);
496 return sprintf(buf, "%ld\n", (long)data->tolerance[nr]);
497}
498
499static ssize_t
500store_tolerance(struct device *dev, struct device_attribute *attr,
501 const char *buf, size_t count)
502{
503 int nr = to_sensor_dev_attr(attr)->index;
504 struct i2c_client *client = to_i2c_client(dev);
505 struct w83l786ng_data *data = i2c_get_clientdata(client);
506 u32 val;
507 u8 tol_tmp, tol_mask;
508
509 val = simple_strtoul(buf, NULL, 10);
510
511 mutex_lock(&data->update_lock);
512 tol_mask = w83l786ng_read_value(client,
513 W83L786NG_REG_TOLERANCE) & ((nr == 1) ? 0x0f : 0xf0);
514 tol_tmp = SENSORS_LIMIT(val, 0, 15);
515 tol_tmp &= 0x0f;
516 data->tolerance[nr] = tol_tmp;
517 if (nr == 1) {
518 tol_tmp <<= 4;
519 }
520
521 w83l786ng_write_value(client, W83L786NG_REG_TOLERANCE,
522 tol_mask | tol_tmp);
523 mutex_unlock(&data->update_lock);
524 return count;
525}
526
527static struct sensor_device_attribute sda_tolerance[] = {
528 SENSOR_ATTR(pwm1_tolerance, S_IWUSR | S_IRUGO,
529 show_tolerance, store_tolerance, 0),
530 SENSOR_ATTR(pwm2_tolerance, S_IWUSR | S_IRUGO,
531 show_tolerance, store_tolerance, 1),
532};
533
534
535#define IN_UNIT_ATTRS(X) \
536 &sda_in_input[X].dev_attr.attr, \
537 &sda_in_min[X].dev_attr.attr, \
538 &sda_in_max[X].dev_attr.attr
539
540#define FAN_UNIT_ATTRS(X) \
541 &sda_fan_input[X].dev_attr.attr, \
542 &sda_fan_min[X].dev_attr.attr, \
543 &sda_fan_div[X].dev_attr.attr
544
545#define TEMP_UNIT_ATTRS(X) \
546 &sda_temp_input[X].dev_attr.attr, \
547 &sda_temp_max[X].dev_attr.attr, \
548 &sda_temp_max_hyst[X].dev_attr.attr
549
550#define PWM_UNIT_ATTRS(X) \
551 &sda_pwm[X].dev_attr.attr, \
552 &sda_pwm_mode[X].dev_attr.attr, \
553 &sda_pwm_enable[X].dev_attr.attr
554
555#define TOLERANCE_UNIT_ATTRS(X) \
556 &sda_tolerance[X].dev_attr.attr
557
558static struct attribute *w83l786ng_attributes[] = {
559 IN_UNIT_ATTRS(0),
560 IN_UNIT_ATTRS(1),
561 IN_UNIT_ATTRS(2),
562 FAN_UNIT_ATTRS(0),
563 FAN_UNIT_ATTRS(1),
564 TEMP_UNIT_ATTRS(0),
565 TEMP_UNIT_ATTRS(1),
566 PWM_UNIT_ATTRS(0),
567 PWM_UNIT_ATTRS(1),
568 TOLERANCE_UNIT_ATTRS(0),
569 TOLERANCE_UNIT_ATTRS(1),
570 NULL
571};
572
573static const struct attribute_group w83l786ng_group = {
574 .attrs = w83l786ng_attributes,
575};
576
577static int
578w83l786ng_attach_adapter(struct i2c_adapter *adapter)
579{
580 if (!(adapter->class & I2C_CLASS_HWMON))
581 return 0;
582 return i2c_probe(adapter, &addr_data, w83l786ng_detect);
583}
584
585static int
586w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind)
587{
588 struct i2c_client *client;
589 struct device *dev;
590 struct w83l786ng_data *data;
591 int i, err = 0;
592 u8 reg_tmp;
593
594 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
595 goto exit;
596 }
597
598 /* OK. For now, we presume we have a valid client. We now create the
599 client structure, even though we cannot fill it completely yet.
600 But it allows us to access w83l786ng_{read,write}_value. */
601
602 if (!(data = kzalloc(sizeof(struct w83l786ng_data), GFP_KERNEL))) {
603 err = -ENOMEM;
604 goto exit;
605 }
606
607 client = &data->client;
608 dev = &client->dev;
609 i2c_set_clientdata(client, data);
610 client->addr = address;
611 client->adapter = adapter;
612 client->driver = &w83l786ng_driver;
613
614 /*
615 * Now we do the remaining detection. A negative kind means that
616 * the driver was loaded with no force parameter (default), so we
617 * must both detect and identify the chip (actually there is only
618 * one possible kind of chip for now, W83L786NG). A zero kind means
619 * that the driver was loaded with the force parameter, the detection
620 * step shall be skipped. A positive kind means that the driver
621 * was loaded with the force parameter and a given kind of chip is
622 * requested, so both the detection and the identification steps
623 * are skipped.
624 */
625 if (kind < 0) { /* detection */
626 if (((w83l786ng_read_value(client,
627 W83L786NG_REG_CONFIG) & 0x80) != 0x00)) {
628 dev_dbg(&adapter->dev,
629 "W83L786NG detection failed at 0x%02x.\n",
630 address);
631 goto exit_free;
632 }
633 }
634
635 if (kind <= 0) { /* identification */
636 u16 man_id;
637 u8 chip_id;
638
639 man_id = (w83l786ng_read_value(client,
640 W83L786NG_REG_MAN_ID1) << 8) +
641 w83l786ng_read_value(client, W83L786NG_REG_MAN_ID2);
642 chip_id = w83l786ng_read_value(client, W83L786NG_REG_CHIP_ID);
643
644 if (man_id == 0x5CA3) { /* Winbond */
645 if (chip_id == 0x80) { /* W83L786NG */
646 kind = w83l786ng;
647 }
648 }
649
650 if (kind <= 0) { /* identification failed */
651 dev_info(&adapter->dev,
652 "Unsupported chip (man_id=0x%04X, "
653 "chip_id=0x%02X).\n", man_id, chip_id);
654 goto exit_free;
655 }
656 }
657
658 /* Fill in the remaining client fields and put into the global list */
659 strlcpy(client->name, "w83l786ng", I2C_NAME_SIZE);
660 mutex_init(&data->update_lock);
661
662 /* Tell the I2C layer a new client has arrived */
663 if ((err = i2c_attach_client(client)))
664 goto exit_free;
665
666 /* Initialize the chip */
667 w83l786ng_init_client(client);
668
669 /* A few vars need to be filled upon startup */
670 for (i = 0; i < 2; i++) {
671 data->fan_min[i] = w83l786ng_read_value(client,
672 W83L786NG_REG_FAN_MIN(i));
673 }
674
675 /* Update the fan divisor */
676 reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV);
677 data->fan_div[0] = reg_tmp & 0x07;
678 data->fan_div[1] = (reg_tmp >> 4) & 0x07;
679
680 /* Register sysfs hooks */
681 if ((err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group)))
682 goto exit_remove;
683
684 data->hwmon_dev = hwmon_device_register(dev);
685 if (IS_ERR(data->hwmon_dev)) {
686 err = PTR_ERR(data->hwmon_dev);
687 goto exit_remove;
688 }
689
690 return 0;
691
692 /* Unregister sysfs hooks */
693
694exit_remove:
695 sysfs_remove_group(&client->dev.kobj, &w83l786ng_group);
696 i2c_detach_client(client);
697exit_free:
698 kfree(data);
699exit:
700 return err;
701}
702
703static int
704w83l786ng_detach_client(struct i2c_client *client)
705{
706 struct w83l786ng_data *data = i2c_get_clientdata(client);
707 int err;
708
709 hwmon_device_unregister(data->hwmon_dev);
710 sysfs_remove_group(&client->dev.kobj, &w83l786ng_group);
711
712 if ((err = i2c_detach_client(client)))
713 return err;
714
715 kfree(data);
716
717 return 0;
718}
719
720static void
721w83l786ng_init_client(struct i2c_client *client)
722{
723 u8 tmp;
724
725 if (reset)
726 w83l786ng_write_value(client, W83L786NG_REG_CONFIG, 0x80);
727
728 /* Start monitoring */
729 tmp = w83l786ng_read_value(client, W83L786NG_REG_CONFIG);
730 if (!(tmp & 0x01))
731 w83l786ng_write_value(client, W83L786NG_REG_CONFIG, tmp | 0x01);
732}
733
734static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
735{
736 struct i2c_client *client = to_i2c_client(dev);
737 struct w83l786ng_data *data = i2c_get_clientdata(client);
738 int i, j;
739 u8 reg_tmp, pwmcfg;
740
741 mutex_lock(&data->update_lock);
742 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
743 || !data->valid) {
744 dev_dbg(&client->dev, "Updating w83l786ng data.\n");
745
746 /* Update the voltages measured value and limits */
747 for (i = 0; i < 3; i++) {
748 data->in[i] = w83l786ng_read_value(client,
749 W83L786NG_REG_IN(i));
750 data->in_min[i] = w83l786ng_read_value(client,
751 W83L786NG_REG_IN_MIN(i));
752 data->in_max[i] = w83l786ng_read_value(client,
753 W83L786NG_REG_IN_MAX(i));
754 }
755
756 /* Update the fan counts and limits */
757 for (i = 0; i < 2; i++) {
758 data->fan[i] = w83l786ng_read_value(client,
759 W83L786NG_REG_FAN(i));
760 data->fan_min[i] = w83l786ng_read_value(client,
761 W83L786NG_REG_FAN_MIN(i));
762 }
763
764 /* Update the fan divisor */
765 reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV);
766 data->fan_div[0] = reg_tmp & 0x07;
767 data->fan_div[1] = (reg_tmp >> 4) & 0x07;
768
769 pwmcfg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
770 for (i = 0; i < 2; i++) {
771 data->pwm_mode[i] =
772 ((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1)
773 ? 0 : 1;
774 data->pwm_enable[i] =
775 ((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 2) + 1;
776 data->pwm[i] = w83l786ng_read_value(client,
777 W83L786NG_REG_PWM[i]);
778 }
779
780
781 /* Update the temperature sensors */
782 for (i = 0; i < 2; i++) {
783 for (j = 0; j < 3; j++) {
784 data->temp[i][j] = w83l786ng_read_value(client,
785 W83L786NG_REG_TEMP[i][j]);
786 }
787 }
788
789 /* Update Smart Fan I/II tolerance */
790 reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_TOLERANCE);
791 data->tolerance[0] = reg_tmp & 0x0f;
792 data->tolerance[1] = (reg_tmp >> 4) & 0x0f;
793
794 data->last_updated = jiffies;
795 data->valid = 1;
796
797 }
798
799 mutex_unlock(&data->update_lock);
800
801 return data;
802}
803
804static int __init
805sensors_w83l786ng_init(void)
806{
807 return i2c_add_driver(&w83l786ng_driver);
808}
809
810static void __exit
811sensors_w83l786ng_exit(void)
812{
813 i2c_del_driver(&w83l786ng_driver);
814}
815
816MODULE_AUTHOR("Kevin Lo");
817MODULE_DESCRIPTION("w83l786ng driver");
818MODULE_LICENSE("GPL");
819
820module_init(sensors_w83l786ng_init);
821module_exit(sensors_w83l786ng_exit);
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index fde297b21ad7..7dee001e5133 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -71,7 +71,6 @@ static struct i2c_driver eeprom_driver = {
71 .driver = { 71 .driver = {
72 .name = "eeprom", 72 .name = "eeprom",
73 }, 73 },
74 .id = I2C_DRIVERID_EEPROM,
75 .attach_adapter = eeprom_attach_adapter, 74 .attach_adapter = eeprom_attach_adapter,
76 .detach_client = eeprom_detach_client, 75 .detach_client = eeprom_detach_client,
77}; 76};
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index b3b830ccf209..e5b31329b56e 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -67,7 +67,6 @@ static struct i2c_driver pcf8574_driver = {
67 .driver = { 67 .driver = {
68 .name = "pcf8574", 68 .name = "pcf8574",
69 }, 69 },
70 .id = I2C_DRIVERID_PCF8574,
71 .attach_adapter = pcf8574_attach_adapter, 70 .attach_adapter = pcf8574_attach_adapter,
72 .detach_client = pcf8574_detach_client, 71 .detach_client = pcf8574_detach_client,
73}; 72};
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 865f4409c06b..66c7c3bb9429 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -92,7 +92,6 @@ static struct i2c_driver pcf8591_driver = {
92 .driver = { 92 .driver = {
93 .name = "pcf8591", 93 .name = "pcf8591",
94 }, 94 },
95 .id = I2C_DRIVERID_PCF8591,
96 .attach_adapter = pcf8591_attach_adapter, 95 .attach_adapter = pcf8591_attach_adapter,
97 .detach_client = pcf8591_detach_client, 96 .detach_client = pcf8591_detach_client,
98}; 97};
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 78cd33861766..7b5220ca7d7f 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -285,4 +285,13 @@ config INTEL_MENLOW
285 285
286 If unsure, say N. 286 If unsure, say N.
287 287
288config ENCLOSURE_SERVICES
289 tristate "Enclosure Services"
290 default n
291 help
292 Provides support for intelligent enclosures (bays which
293 contain storage devices). You also need either a host
294 driver (SCSI/ATA) which supports enclosures
295 or a SCSI enclosure device (SES) to use these services.
296
288endif # MISC_DEVICES 297endif # MISC_DEVICES
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 1f41654aae4d..7f13549cc87e 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -20,3 +20,4 @@ obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
20obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o 20obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o
21obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o 21obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o
22obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o 22obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
23obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
new file mode 100644
index 000000000000..6fcb0e96adf4
--- /dev/null
+++ b/drivers/misc/enclosure.c
@@ -0,0 +1,484 @@
1/*
2 * Enclosure Services
3 *
4 * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
5 *
6**-----------------------------------------------------------------------------
7**
8** This program is free software; you can redistribute it and/or
9** modify it under the terms of the GNU General Public License
10** version 2 as published by the Free Software Foundation.
11**
12** This program is distributed in the hope that it will be useful,
13** but WITHOUT ANY WARRANTY; without even the implied warranty of
14** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15** GNU General Public License for more details.
16**
17** You should have received a copy of the GNU General Public License
18** along with this program; if not, write to the Free Software
19** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20**
21**-----------------------------------------------------------------------------
22*/
23#include <linux/device.h>
24#include <linux/enclosure.h>
25#include <linux/err.h>
26#include <linux/list.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/mutex.h>
30
31static LIST_HEAD(container_list);
32static DEFINE_MUTEX(container_list_lock);
33static struct class enclosure_class;
34static struct class enclosure_component_class;
35
36/**
37 * enclosure_find - find an enclosure given a device
38 * @dev: the device to find for
39 *
40 * Looks through the list of registered enclosures to see
41 * if it can find a match for a device. Returns NULL if no
42 * enclosure is found. Obtains a reference to the enclosure class
43 * device which must be released with class_device_put().
44 */
45struct enclosure_device *enclosure_find(struct device *dev)
46{
47 struct enclosure_device *edev = NULL;
48
49 mutex_lock(&container_list_lock);
50 list_for_each_entry(edev, &container_list, node) {
51 if (edev->cdev.dev == dev) {
52 class_device_get(&edev->cdev);
53 mutex_unlock(&container_list_lock);
54 return edev;
55 }
56 }
57 mutex_unlock(&container_list_lock);
58
59 return NULL;
60}
61EXPORT_SYMBOL_GPL(enclosure_find);
62
63/**
64 * enclosure_for_each_device - calls a function for each enclosure
65 * @fn: the function to call
66 * @data: the data to pass to each call
67 *
68 * Loops over all the enclosures calling the function.
69 *
70 * Note, this function uses a mutex which will be held across calls to
71 * @fn, so it must have non atomic context, and @fn may (although it
72 * should not) sleep or otherwise cause the mutex to be held for
73 * indefinite periods
74 */
75int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
76 void *data)
77{
78 int error = 0;
79 struct enclosure_device *edev;
80
81 mutex_lock(&container_list_lock);
82 list_for_each_entry(edev, &container_list, node) {
83 error = fn(edev, data);
84 if (error)
85 break;
86 }
87 mutex_unlock(&container_list_lock);
88
89 return error;
90}
91EXPORT_SYMBOL_GPL(enclosure_for_each_device);
92
93/**
94 * enclosure_register - register device as an enclosure
95 *
96 * @dev: device containing the enclosure
97 * @components: number of components in the enclosure
98 *
99 * This sets up the device for being an enclosure. Note that @dev does
100 * not have to be a dedicated enclosure device. It may be some other type
101 * of device that additionally responds to enclosure services
102 */
103struct enclosure_device *
104enclosure_register(struct device *dev, const char *name, int components,
105 struct enclosure_component_callbacks *cb)
106{
107 struct enclosure_device *edev =
108 kzalloc(sizeof(struct enclosure_device) +
109 sizeof(struct enclosure_component)*components,
110 GFP_KERNEL);
111 int err, i;
112
113 BUG_ON(!cb);
114
115 if (!edev)
116 return ERR_PTR(-ENOMEM);
117
118 edev->components = components;
119
120 edev->cdev.class = &enclosure_class;
121 edev->cdev.dev = get_device(dev);
122 edev->cb = cb;
123 snprintf(edev->cdev.class_id, BUS_ID_SIZE, "%s", name);
124 err = class_device_register(&edev->cdev);
125 if (err)
126 goto err;
127
128 for (i = 0; i < components; i++)
129 edev->component[i].number = -1;
130
131 mutex_lock(&container_list_lock);
132 list_add_tail(&edev->node, &container_list);
133 mutex_unlock(&container_list_lock);
134
135 return edev;
136
137 err:
138 put_device(edev->cdev.dev);
139 kfree(edev);
140 return ERR_PTR(err);
141}
142EXPORT_SYMBOL_GPL(enclosure_register);
143
144static struct enclosure_component_callbacks enclosure_null_callbacks;
145
146/**
147 * enclosure_unregister - remove an enclosure
148 *
149 * @edev: the registered enclosure to remove;
150 */
151void enclosure_unregister(struct enclosure_device *edev)
152{
153 int i;
154
155 mutex_lock(&container_list_lock);
156 list_del(&edev->node);
157 mutex_unlock(&container_list_lock);
158
159 for (i = 0; i < edev->components; i++)
160 if (edev->component[i].number != -1)
161 class_device_unregister(&edev->component[i].cdev);
162
163 /* prevent any callbacks into service user */
164 edev->cb = &enclosure_null_callbacks;
165 class_device_unregister(&edev->cdev);
166}
167EXPORT_SYMBOL_GPL(enclosure_unregister);
168
169static void enclosure_release(struct class_device *cdev)
170{
171 struct enclosure_device *edev = to_enclosure_device(cdev);
172
173 put_device(cdev->dev);
174 kfree(edev);
175}
176
177static void enclosure_component_release(struct class_device *cdev)
178{
179 if (cdev->dev)
180 put_device(cdev->dev);
181 class_device_put(cdev->parent);
182}
183
184/**
185 * enclosure_component_register - add a particular component to an enclosure
186 * @edev: the enclosure to add the component
187 * @num: the device number
188 * @type: the type of component being added
189 * @name: an optional name to appear in sysfs (leave NULL if none)
190 *
191 * Registers the component. The name is optional for enclosures that
192 * give their components a unique name. If not, leave the field NULL
193 * and a name will be assigned.
194 *
195 * Returns a pointer to the enclosure component or an error.
196 */
197struct enclosure_component *
198enclosure_component_register(struct enclosure_device *edev,
199 unsigned int number,
200 enum enclosure_component_type type,
201 const char *name)
202{
203 struct enclosure_component *ecomp;
204 struct class_device *cdev;
205 int err;
206
207 if (number >= edev->components)
208 return ERR_PTR(-EINVAL);
209
210 ecomp = &edev->component[number];
211
212 if (ecomp->number != -1)
213 return ERR_PTR(-EINVAL);
214
215 ecomp->type = type;
216 ecomp->number = number;
217 cdev = &ecomp->cdev;
218 cdev->parent = class_device_get(&edev->cdev);
219 cdev->class = &enclosure_component_class;
220 if (name)
221 snprintf(cdev->class_id, BUS_ID_SIZE, "%s", name);
222 else
223 snprintf(cdev->class_id, BUS_ID_SIZE, "%u", number);
224
225 err = class_device_register(cdev);
226 if (err)
227 ERR_PTR(err);
228
229 return ecomp;
230}
231EXPORT_SYMBOL_GPL(enclosure_component_register);
232
233/**
234 * enclosure_add_device - add a device as being part of an enclosure
235 * @edev: the enclosure device being added to.
236 * @num: the number of the component
237 * @dev: the device being added
238 *
239 * Declares a real device to reside in slot (or identifier) @num of an
240 * enclosure. This will cause the relevant sysfs links to appear.
241 * This function may also be used to change a device associated with
242 * an enclosure without having to call enclosure_remove_device() in
243 * between.
244 *
245 * Returns zero on success or an error.
246 */
247int enclosure_add_device(struct enclosure_device *edev, int component,
248 struct device *dev)
249{
250 struct class_device *cdev;
251
252 if (!edev || component >= edev->components)
253 return -EINVAL;
254
255 cdev = &edev->component[component].cdev;
256
257 class_device_del(cdev);
258 if (cdev->dev)
259 put_device(cdev->dev);
260 cdev->dev = get_device(dev);
261 return class_device_add(cdev);
262}
263EXPORT_SYMBOL_GPL(enclosure_add_device);
264
265/**
266 * enclosure_remove_device - remove a device from an enclosure
267 * @edev: the enclosure device
268 * @num: the number of the component to remove
269 *
270 * Returns zero on success or an error.
271 *
272 */
273int enclosure_remove_device(struct enclosure_device *edev, int component)
274{
275 struct class_device *cdev;
276
277 if (!edev || component >= edev->components)
278 return -EINVAL;
279
280 cdev = &edev->component[component].cdev;
281
282 class_device_del(cdev);
283 if (cdev->dev)
284 put_device(cdev->dev);
285 cdev->dev = NULL;
286 return class_device_add(cdev);
287}
288EXPORT_SYMBOL_GPL(enclosure_remove_device);
289
290/*
291 * sysfs pieces below
292 */
293
294static ssize_t enclosure_show_components(struct class_device *cdev, char *buf)
295{
296 struct enclosure_device *edev = to_enclosure_device(cdev);
297
298 return snprintf(buf, 40, "%d\n", edev->components);
299}
300
301static struct class_device_attribute enclosure_attrs[] = {
302 __ATTR(components, S_IRUGO, enclosure_show_components, NULL),
303 __ATTR_NULL
304};
305
306static struct class enclosure_class = {
307 .name = "enclosure",
308 .owner = THIS_MODULE,
309 .release = enclosure_release,
310 .class_dev_attrs = enclosure_attrs,
311};
312
313static const char *const enclosure_status [] = {
314 [ENCLOSURE_STATUS_UNSUPPORTED] = "unsupported",
315 [ENCLOSURE_STATUS_OK] = "OK",
316 [ENCLOSURE_STATUS_CRITICAL] = "critical",
317 [ENCLOSURE_STATUS_NON_CRITICAL] = "non-critical",
318 [ENCLOSURE_STATUS_UNRECOVERABLE] = "unrecoverable",
319 [ENCLOSURE_STATUS_NOT_INSTALLED] = "not installed",
320 [ENCLOSURE_STATUS_UNKNOWN] = "unknown",
321 [ENCLOSURE_STATUS_UNAVAILABLE] = "unavailable",
322};
323
324static const char *const enclosure_type [] = {
325 [ENCLOSURE_COMPONENT_DEVICE] = "device",
326 [ENCLOSURE_COMPONENT_ARRAY_DEVICE] = "array device",
327};
328
329static ssize_t get_component_fault(struct class_device *cdev, char *buf)
330{
331 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
332 struct enclosure_component *ecomp = to_enclosure_component(cdev);
333
334 if (edev->cb->get_fault)
335 edev->cb->get_fault(edev, ecomp);
336 return snprintf(buf, 40, "%d\n", ecomp->fault);
337}
338
339static ssize_t set_component_fault(struct class_device *cdev, const char *buf,
340 size_t count)
341{
342 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
343 struct enclosure_component *ecomp = to_enclosure_component(cdev);
344 int val = simple_strtoul(buf, NULL, 0);
345
346 if (edev->cb->set_fault)
347 edev->cb->set_fault(edev, ecomp, val);
348 return count;
349}
350
351static ssize_t get_component_status(struct class_device *cdev, char *buf)
352{
353 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
354 struct enclosure_component *ecomp = to_enclosure_component(cdev);
355
356 if (edev->cb->get_status)
357 edev->cb->get_status(edev, ecomp);
358 return snprintf(buf, 40, "%s\n", enclosure_status[ecomp->status]);
359}
360
361static ssize_t set_component_status(struct class_device *cdev, const char *buf,
362 size_t count)
363{
364 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
365 struct enclosure_component *ecomp = to_enclosure_component(cdev);
366 int i;
367
368 for (i = 0; enclosure_status[i]; i++) {
369 if (strncmp(buf, enclosure_status[i],
370 strlen(enclosure_status[i])) == 0 &&
371 (buf[strlen(enclosure_status[i])] == '\n' ||
372 buf[strlen(enclosure_status[i])] == '\0'))
373 break;
374 }
375
376 if (enclosure_status[i] && edev->cb->set_status) {
377 edev->cb->set_status(edev, ecomp, i);
378 return count;
379 } else
380 return -EINVAL;
381}
382
383static ssize_t get_component_active(struct class_device *cdev, char *buf)
384{
385 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
386 struct enclosure_component *ecomp = to_enclosure_component(cdev);
387
388 if (edev->cb->get_active)
389 edev->cb->get_active(edev, ecomp);
390 return snprintf(buf, 40, "%d\n", ecomp->active);
391}
392
393static ssize_t set_component_active(struct class_device *cdev, const char *buf,
394 size_t count)
395{
396 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
397 struct enclosure_component *ecomp = to_enclosure_component(cdev);
398 int val = simple_strtoul(buf, NULL, 0);
399
400 if (edev->cb->set_active)
401 edev->cb->set_active(edev, ecomp, val);
402 return count;
403}
404
405static ssize_t get_component_locate(struct class_device *cdev, char *buf)
406{
407 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
408 struct enclosure_component *ecomp = to_enclosure_component(cdev);
409
410 if (edev->cb->get_locate)
411 edev->cb->get_locate(edev, ecomp);
412 return snprintf(buf, 40, "%d\n", ecomp->locate);
413}
414
415static ssize_t set_component_locate(struct class_device *cdev, const char *buf,
416 size_t count)
417{
418 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
419 struct enclosure_component *ecomp = to_enclosure_component(cdev);
420 int val = simple_strtoul(buf, NULL, 0);
421
422 if (edev->cb->set_locate)
423 edev->cb->set_locate(edev, ecomp, val);
424 return count;
425}
426
427static ssize_t get_component_type(struct class_device *cdev, char *buf)
428{
429 struct enclosure_component *ecomp = to_enclosure_component(cdev);
430
431 return snprintf(buf, 40, "%s\n", enclosure_type[ecomp->type]);
432}
433
434
435static struct class_device_attribute enclosure_component_attrs[] = {
436 __ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault,
437 set_component_fault),
438 __ATTR(status, S_IRUGO | S_IWUSR, get_component_status,
439 set_component_status),
440 __ATTR(active, S_IRUGO | S_IWUSR, get_component_active,
441 set_component_active),
442 __ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate,
443 set_component_locate),
444 __ATTR(type, S_IRUGO, get_component_type, NULL),
445 __ATTR_NULL
446};
447
448static struct class enclosure_component_class = {
449 .name = "enclosure_component",
450 .owner = THIS_MODULE,
451 .class_dev_attrs = enclosure_component_attrs,
452 .release = enclosure_component_release,
453};
454
455static int __init enclosure_init(void)
456{
457 int err;
458
459 err = class_register(&enclosure_class);
460 if (err)
461 return err;
462 err = class_register(&enclosure_component_class);
463 if (err)
464 goto err_out;
465
466 return 0;
467 err_out:
468 class_unregister(&enclosure_class);
469
470 return err;
471}
472
473static void __exit enclosure_exit(void)
474{
475 class_unregister(&enclosure_component_class);
476 class_unregister(&enclosure_class);
477}
478
479module_init(enclosure_init);
480module_exit(enclosure_exit);
481
482MODULE_AUTHOR("James Bottomley");
483MODULE_DESCRIPTION("Enclosure Services");
484MODULE_LICENSE("GPL v2");
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 14fc7f39e83e..a5f0aaaf0dd4 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -179,7 +179,15 @@ config CHR_DEV_SCH
179 say M here and read <file:Documentation/kbuild/modules.txt> and 179 say M here and read <file:Documentation/kbuild/modules.txt> and
180 <file:Documentation/scsi/scsi.txt>. The module will be called ch.o. 180 <file:Documentation/scsi/scsi.txt>. The module will be called ch.o.
181 If unsure, say N. 181 If unsure, say N.
182 182
183config SCSI_ENCLOSURE
184 tristate "SCSI Enclosure Support"
185 depends on SCSI && ENCLOSURE_SERVICES
186 help
187 Enclosures are devices sitting on or in SCSI backplanes that
188 manage devices. If you have a disk cage, the chances are that
189 it has an enclosure device. Selecting this option will just allow
190 certain enclosure conditions to be reported and is not required.
183 191
184comment "Some SCSI devices (e.g. CD jukebox) support multiple LUNs" 192comment "Some SCSI devices (e.g. CD jukebox) support multiple LUNs"
185 depends on SCSI 193 depends on SCSI
@@ -350,17 +358,6 @@ config SGIWD93_SCSI
350 If you have a Western Digital WD93 SCSI controller on 358 If you have a Western Digital WD93 SCSI controller on
351 an SGI MIPS system, say Y. Otherwise, say N. 359 an SGI MIPS system, say Y. Otherwise, say N.
352 360
353config SCSI_DECNCR
354 tristate "DEC NCR53C94 Scsi Driver"
355 depends on MACH_DECSTATION && SCSI && TC
356 help
357 Say Y here to support the NCR53C94 SCSI controller chips on IOASIC
358 based TURBOchannel DECstations and TURBOchannel PMAZ-A cards.
359
360config SCSI_DECSII
361 tristate "DEC SII Scsi Driver"
362 depends on MACH_DECSTATION && SCSI && 32BIT
363
364config BLK_DEV_3W_XXXX_RAID 361config BLK_DEV_3W_XXXX_RAID
365 tristate "3ware 5/6/7/8xxx ATA-RAID support" 362 tristate "3ware 5/6/7/8xxx ATA-RAID support"
366 depends on PCI && SCSI 363 depends on PCI && SCSI
@@ -1263,17 +1260,6 @@ config SCSI_NCR53C8XX_NO_DISCONNECT
1263 not allow targets to disconnect is not reasonable if there is more 1260 not allow targets to disconnect is not reasonable if there is more
1264 than 1 device on a SCSI bus. The normal answer therefore is N. 1261 than 1 device on a SCSI bus. The normal answer therefore is N.
1265 1262
1266config SCSI_MCA_53C9X
1267 tristate "NCR MCA 53C9x SCSI support"
1268 depends on MCA_LEGACY && SCSI && BROKEN_ON_SMP
1269 help
1270 Some MicroChannel machines, notably the NCR 35xx line, use a SCSI
1271 controller based on the NCR 53C94. This driver will allow use of
1272 the controller on the 3550, and very possibly others.
1273
1274 To compile this driver as a module, choose M here: the
1275 module will be called mca_53c9x.
1276
1277config SCSI_PAS16 1263config SCSI_PAS16
1278 tristate "PAS16 SCSI support" 1264 tristate "PAS16 SCSI support"
1279 depends on ISA && SCSI 1265 depends on ISA && SCSI
@@ -1600,45 +1586,6 @@ config GVP11_SCSI
1600 To compile this driver as a module, choose M here: the 1586 To compile this driver as a module, choose M here: the
1601 module will be called gvp11. 1587 module will be called gvp11.
1602 1588
1603config CYBERSTORM_SCSI
1604 tristate "CyberStorm SCSI support"
1605 depends on ZORRO && SCSI
1606 help
1607 If you have an Amiga with an original (MkI) Phase5 Cyberstorm
1608 accelerator board and the optional Cyberstorm SCSI controller,
1609 answer Y. Otherwise, say N.
1610
1611config CYBERSTORMII_SCSI
1612 tristate "CyberStorm Mk II SCSI support"
1613 depends on ZORRO && SCSI
1614 help
1615 If you have an Amiga with a Phase5 Cyberstorm MkII accelerator board
1616 and the optional Cyberstorm SCSI controller, say Y. Otherwise,
1617 answer N.
1618
1619config BLZ2060_SCSI
1620 tristate "Blizzard 2060 SCSI support"
1621 depends on ZORRO && SCSI
1622 help
1623 If you have an Amiga with a Phase5 Blizzard 2060 accelerator board
1624 and want to use the onboard SCSI controller, say Y. Otherwise,
1625 answer N.
1626
1627config BLZ1230_SCSI
1628 tristate "Blizzard 1230IV/1260 SCSI support"
1629 depends on ZORRO && SCSI
1630 help
1631 If you have an Amiga 1200 with a Phase5 Blizzard 1230IV or Blizzard
1632 1260 accelerator, and the optional SCSI module, say Y. Otherwise,
1633 say N.
1634
1635config FASTLANE_SCSI
1636 tristate "Fastlane SCSI support"
1637 depends on ZORRO && SCSI
1638 help
1639 If you have the Phase5 Fastlane Z3 SCSI controller, or plan to use
1640 one in the near future, say Y to this question. Otherwise, say N.
1641
1642config SCSI_A4000T 1589config SCSI_A4000T
1643 tristate "A4000T NCR53c710 SCSI support (EXPERIMENTAL)" 1590 tristate "A4000T NCR53c710 SCSI support (EXPERIMENTAL)"
1644 depends on AMIGA && SCSI && EXPERIMENTAL 1591 depends on AMIGA && SCSI && EXPERIMENTAL
@@ -1666,15 +1613,6 @@ config SCSI_ZORRO7XX
1666 accelerator card for the Amiga 1200, 1613 accelerator card for the Amiga 1200,
1667 - the SCSI controller on the GVP Turbo 040/060 accelerator. 1614 - the SCSI controller on the GVP Turbo 040/060 accelerator.
1668 1615
1669config OKTAGON_SCSI
1670 tristate "BSC Oktagon SCSI support (EXPERIMENTAL)"
1671 depends on ZORRO && SCSI && EXPERIMENTAL
1672 help
1673 If you have the BSC Oktagon SCSI disk controller for the Amiga, say
1674 Y to this question. If you're in doubt about whether you have one,
1675 see the picture at
1676 <http://amiga.resource.cx/exp/search.pl?product=oktagon>.
1677
1678config ATARI_SCSI 1616config ATARI_SCSI
1679 tristate "Atari native SCSI support" 1617 tristate "Atari native SCSI support"
1680 depends on ATARI && SCSI 1618 depends on ATARI && SCSI
@@ -1727,18 +1665,6 @@ config MAC_SCSI
1727 SCSI-HOWTO, available from 1665 SCSI-HOWTO, available from
1728 <http://www.tldp.org/docs.html#howto>. 1666 <http://www.tldp.org/docs.html#howto>.
1729 1667
1730config SCSI_MAC_ESP
1731 tristate "Macintosh NCR53c9[46] SCSI"
1732 depends on MAC && SCSI
1733 help
1734 This is the NCR 53c9x SCSI controller found on most of the 68040
1735 based Macintoshes. If you have one of these say Y and read the
1736 SCSI-HOWTO, available from
1737 <http://www.tldp.org/docs.html#howto>.
1738
1739 To compile this driver as a module, choose M here: the
1740 module will be called mac_esp.
1741
1742config MVME147_SCSI 1668config MVME147_SCSI
1743 bool "WD33C93 SCSI driver for MVME147" 1669 bool "WD33C93 SCSI driver for MVME147"
1744 depends on MVME147 && SCSI=y 1670 depends on MVME147 && SCSI=y
@@ -1779,6 +1705,7 @@ config SUN3_SCSI
1779config SUN3X_ESP 1705config SUN3X_ESP
1780 bool "Sun3x ESP SCSI" 1706 bool "Sun3x ESP SCSI"
1781 depends on SUN3X && SCSI=y 1707 depends on SUN3X && SCSI=y
1708 select SCSI_SPI_ATTRS
1782 help 1709 help
1783 The ESP was an on-board SCSI controller used on Sun 3/80 1710 The ESP was an on-board SCSI controller used on Sun 3/80
1784 machines. Say Y here to compile in support for it. 1711 machines. Say Y here to compile in support for it.
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 93e1428d03fc..925c26b4fff9 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -44,15 +44,8 @@ obj-$(CONFIG_A2091_SCSI) += a2091.o wd33c93.o
44obj-$(CONFIG_GVP11_SCSI) += gvp11.o wd33c93.o 44obj-$(CONFIG_GVP11_SCSI) += gvp11.o wd33c93.o
45obj-$(CONFIG_MVME147_SCSI) += mvme147.o wd33c93.o 45obj-$(CONFIG_MVME147_SCSI) += mvme147.o wd33c93.o
46obj-$(CONFIG_SGIWD93_SCSI) += sgiwd93.o wd33c93.o 46obj-$(CONFIG_SGIWD93_SCSI) += sgiwd93.o wd33c93.o
47obj-$(CONFIG_CYBERSTORM_SCSI) += NCR53C9x.o cyberstorm.o
48obj-$(CONFIG_CYBERSTORMII_SCSI) += NCR53C9x.o cyberstormII.o
49obj-$(CONFIG_BLZ2060_SCSI) += NCR53C9x.o blz2060.o
50obj-$(CONFIG_BLZ1230_SCSI) += NCR53C9x.o blz1230.o
51obj-$(CONFIG_FASTLANE_SCSI) += NCR53C9x.o fastlane.o
52obj-$(CONFIG_OKTAGON_SCSI) += NCR53C9x.o oktagon_esp_mod.o
53obj-$(CONFIG_ATARI_SCSI) += atari_scsi.o 47obj-$(CONFIG_ATARI_SCSI) += atari_scsi.o
54obj-$(CONFIG_MAC_SCSI) += mac_scsi.o 48obj-$(CONFIG_MAC_SCSI) += mac_scsi.o
55obj-$(CONFIG_SCSI_MAC_ESP) += mac_esp.o NCR53C9x.o
56obj-$(CONFIG_SUN3_SCSI) += sun3_scsi.o sun3_scsi_vme.o 49obj-$(CONFIG_SUN3_SCSI) += sun3_scsi.o sun3_scsi_vme.o
57obj-$(CONFIG_MVME16x_SCSI) += 53c700.o mvme16x_scsi.o 50obj-$(CONFIG_MVME16x_SCSI) += 53c700.o mvme16x_scsi.o
58obj-$(CONFIG_BVME6000_SCSI) += 53c700.o bvme6000_scsi.o 51obj-$(CONFIG_BVME6000_SCSI) += 53c700.o bvme6000_scsi.o
@@ -95,7 +88,6 @@ obj-$(CONFIG_SCSI_SYM53C8XX_2) += sym53c8xx_2/
95obj-$(CONFIG_SCSI_ZALON) += zalon7xx.o 88obj-$(CONFIG_SCSI_ZALON) += zalon7xx.o
96obj-$(CONFIG_SCSI_EATA_PIO) += eata_pio.o 89obj-$(CONFIG_SCSI_EATA_PIO) += eata_pio.o
97obj-$(CONFIG_SCSI_7000FASST) += wd7000.o 90obj-$(CONFIG_SCSI_7000FASST) += wd7000.o
98obj-$(CONFIG_SCSI_MCA_53C9X) += NCR53C9x.o mca_53c9x.o
99obj-$(CONFIG_SCSI_IBMMCA) += ibmmca.o 91obj-$(CONFIG_SCSI_IBMMCA) += ibmmca.o
100obj-$(CONFIG_SCSI_EATA) += eata.o 92obj-$(CONFIG_SCSI_EATA) += eata.o
101obj-$(CONFIG_SCSI_DC395x) += dc395x.o 93obj-$(CONFIG_SCSI_DC395x) += dc395x.o
@@ -112,13 +104,12 @@ obj-$(CONFIG_SCSI_QLOGICPTI) += qlogicpti.o
112obj-$(CONFIG_BLK_DEV_IDESCSI) += ide-scsi.o 104obj-$(CONFIG_BLK_DEV_IDESCSI) += ide-scsi.o
113obj-$(CONFIG_SCSI_MESH) += mesh.o 105obj-$(CONFIG_SCSI_MESH) += mesh.o
114obj-$(CONFIG_SCSI_MAC53C94) += mac53c94.o 106obj-$(CONFIG_SCSI_MAC53C94) += mac53c94.o
115obj-$(CONFIG_SCSI_DECNCR) += NCR53C9x.o dec_esp.o
116obj-$(CONFIG_BLK_DEV_3W_XXXX_RAID) += 3w-xxxx.o 107obj-$(CONFIG_BLK_DEV_3W_XXXX_RAID) += 3w-xxxx.o
117obj-$(CONFIG_SCSI_3W_9XXX) += 3w-9xxx.o 108obj-$(CONFIG_SCSI_3W_9XXX) += 3w-9xxx.o
118obj-$(CONFIG_SCSI_PPA) += ppa.o 109obj-$(CONFIG_SCSI_PPA) += ppa.o
119obj-$(CONFIG_SCSI_IMM) += imm.o 110obj-$(CONFIG_SCSI_IMM) += imm.o
120obj-$(CONFIG_JAZZ_ESP) += esp_scsi.o jazz_esp.o 111obj-$(CONFIG_JAZZ_ESP) += esp_scsi.o jazz_esp.o
121obj-$(CONFIG_SUN3X_ESP) += NCR53C9x.o sun3x_esp.o 112obj-$(CONFIG_SUN3X_ESP) += esp_scsi.o sun3x_esp.o
122obj-$(CONFIG_SCSI_LASI700) += 53c700.o lasi700.o 113obj-$(CONFIG_SCSI_LASI700) += 53c700.o lasi700.o
123obj-$(CONFIG_SCSI_SNI_53C710) += 53c700.o sni_53c710.o 114obj-$(CONFIG_SCSI_SNI_53C710) += 53c700.o sni_53c710.o
124obj-$(CONFIG_SCSI_NSP32) += nsp32.o 115obj-$(CONFIG_SCSI_NSP32) += nsp32.o
@@ -138,6 +129,7 @@ obj-$(CONFIG_BLK_DEV_SD) += sd_mod.o
138obj-$(CONFIG_BLK_DEV_SR) += sr_mod.o 129obj-$(CONFIG_BLK_DEV_SR) += sr_mod.o
139obj-$(CONFIG_CHR_DEV_SG) += sg.o 130obj-$(CONFIG_CHR_DEV_SG) += sg.o
140obj-$(CONFIG_CHR_DEV_SCH) += ch.o 131obj-$(CONFIG_CHR_DEV_SCH) += ch.o
132obj-$(CONFIG_SCSI_ENCLOSURE) += ses.o
141 133
142# This goes last, so that "real" scsi devices probe earlier 134# This goes last, so that "real" scsi devices probe earlier
143obj-$(CONFIG_SCSI_DEBUG) += scsi_debug.o 135obj-$(CONFIG_SCSI_DEBUG) += scsi_debug.o
diff --git a/drivers/scsi/NCR53C9x.c b/drivers/scsi/NCR53C9x.c
deleted file mode 100644
index 5b0efc903918..000000000000
--- a/drivers/scsi/NCR53C9x.c
+++ /dev/null
@@ -1,3654 +0,0 @@
1/* NCR53C9x.c: Generic SCSI driver code for NCR53C9x chips.
2 *
3 * Originally esp.c : EnhancedScsiProcessor Sun SCSI driver code.
4 *
5 * Copyright (C) 1995, 1998 David S. Miller (davem@caip.rutgers.edu)
6 *
7 * Most DMA dependencies put in driver specific files by
8 * Jesper Skov (jskov@cygnus.co.uk)
9 *
10 * Set up to use esp_read/esp_write (preprocessor macros in NCR53c9x.h) by
11 * Tymm Twillman (tymm@coe.missouri.edu)
12 */
13
14/* TODO:
15 *
16 * 1) Maybe disable parity checking in config register one for SCSI1
17 * targets. (Gilmore says parity error on the SBus can lock up
18 * old sun4c's)
19 * 2) Add support for DMA2 pipelining.
20 * 3) Add tagged queueing.
21 * 4) Maybe change use of "esp" to something more "NCR"'ish.
22 */
23
24#include <linux/module.h>
25
26#include <linux/kernel.h>
27#include <linux/delay.h>
28#include <linux/types.h>
29#include <linux/string.h>
30#include <linux/slab.h>
31#include <linux/blkdev.h>
32#include <linux/interrupt.h>
33#include <linux/proc_fs.h>
34#include <linux/stat.h>
35#include <linux/init.h>
36
37#include "scsi.h"
38#include <scsi/scsi_host.h>
39#include "NCR53C9x.h"
40
41#include <asm/system.h>
42#include <asm/ptrace.h>
43#include <asm/pgtable.h>
44#include <asm/io.h>
45#include <asm/irq.h>
46
47/* Command phase enumeration. */
48enum {
49 not_issued = 0x00, /* Still in the issue_SC queue. */
50
51 /* Various forms of selecting a target. */
52#define in_slct_mask 0x10
53 in_slct_norm = 0x10, /* ESP is arbitrating, normal selection */
54 in_slct_stop = 0x11, /* ESP will select, then stop with IRQ */
55 in_slct_msg = 0x12, /* select, then send a message */
56 in_slct_tag = 0x13, /* select and send tagged queue msg */
57 in_slct_sneg = 0x14, /* select and acquire sync capabilities */
58
59 /* Any post selection activity. */
60#define in_phases_mask 0x20
61 in_datain = 0x20, /* Data is transferring from the bus */
62 in_dataout = 0x21, /* Data is transferring to the bus */
63 in_data_done = 0x22, /* Last DMA data operation done (maybe) */
64 in_msgin = 0x23, /* Eating message from target */
65 in_msgincont = 0x24, /* Eating more msg bytes from target */
66 in_msgindone = 0x25, /* Decide what to do with what we got */
67 in_msgout = 0x26, /* Sending message to target */
68 in_msgoutdone = 0x27, /* Done sending msg out */
69 in_cmdbegin = 0x28, /* Sending cmd after abnormal selection */
70 in_cmdend = 0x29, /* Done sending slow cmd */
71 in_status = 0x2a, /* Was in status phase, finishing cmd */
72 in_freeing = 0x2b, /* freeing the bus for cmd cmplt or disc */
73 in_the_dark = 0x2c, /* Don't know what bus phase we are in */
74
75 /* Special states, ie. not normal bus transitions... */
76#define in_spec_mask 0x80
77 in_abortone = 0x80, /* Aborting one command currently */
78 in_abortall = 0x81, /* Blowing away all commands we have */
79 in_resetdev = 0x82, /* SCSI target reset in progress */
80 in_resetbus = 0x83, /* SCSI bus reset in progress */
81 in_tgterror = 0x84, /* Target did something stupid */
82};
83
84enum {
85 /* Zero has special meaning, see skipahead[12]. */
86/*0*/ do_never,
87
88/*1*/ do_phase_determine,
89/*2*/ do_reset_bus,
90/*3*/ do_reset_complete,
91/*4*/ do_work_bus,
92/*5*/ do_intr_end
93};
94
95/* The master ring of all esp hosts we are managing in this driver. */
96static struct NCR_ESP *espchain;
97int nesps = 0, esps_in_use = 0, esps_running = 0;
98EXPORT_SYMBOL(nesps);
99EXPORT_SYMBOL(esps_running);
100
101irqreturn_t esp_intr(int irq, void *dev_id);
102
103/* Debugging routines */
104static struct esp_cmdstrings {
105 unchar cmdchar;
106 char *text;
107} esp_cmd_strings[] = {
108 /* Miscellaneous */
109 { ESP_CMD_NULL, "ESP_NOP", },
110 { ESP_CMD_FLUSH, "FIFO_FLUSH", },
111 { ESP_CMD_RC, "RSTESP", },
112 { ESP_CMD_RS, "RSTSCSI", },
113 /* Disconnected State Group */
114 { ESP_CMD_RSEL, "RESLCTSEQ", },
115 { ESP_CMD_SEL, "SLCTNATN", },
116 { ESP_CMD_SELA, "SLCTATN", },
117 { ESP_CMD_SELAS, "SLCTATNSTOP", },
118 { ESP_CMD_ESEL, "ENSLCTRESEL", },
119 { ESP_CMD_DSEL, "DISSELRESEL", },
120 { ESP_CMD_SA3, "SLCTATN3", },
121 { ESP_CMD_RSEL3, "RESLCTSEQ", },
122 /* Target State Group */
123 { ESP_CMD_SMSG, "SNDMSG", },
124 { ESP_CMD_SSTAT, "SNDSTATUS", },
125 { ESP_CMD_SDATA, "SNDDATA", },
126 { ESP_CMD_DSEQ, "DISCSEQ", },
127 { ESP_CMD_TSEQ, "TERMSEQ", },
128 { ESP_CMD_TCCSEQ, "TRGTCMDCOMPSEQ", },
129 { ESP_CMD_DCNCT, "DISC", },
130 { ESP_CMD_RMSG, "RCVMSG", },
131 { ESP_CMD_RCMD, "RCVCMD", },
132 { ESP_CMD_RDATA, "RCVDATA", },
133 { ESP_CMD_RCSEQ, "RCVCMDSEQ", },
134 /* Initiator State Group */
135 { ESP_CMD_TI, "TRANSINFO", },
136 { ESP_CMD_ICCSEQ, "INICMDSEQCOMP", },
137 { ESP_CMD_MOK, "MSGACCEPTED", },
138 { ESP_CMD_TPAD, "TPAD", },
139 { ESP_CMD_SATN, "SATN", },
140 { ESP_CMD_RATN, "RATN", },
141};
142#define NUM_ESP_COMMANDS ((sizeof(esp_cmd_strings)) / (sizeof(struct esp_cmdstrings)))
143
144/* Print textual representation of an ESP command */
145static inline void esp_print_cmd(unchar espcmd)
146{
147 unchar dma_bit = espcmd & ESP_CMD_DMA;
148 int i;
149
150 espcmd &= ~dma_bit;
151 for(i=0; i<NUM_ESP_COMMANDS; i++)
152 if(esp_cmd_strings[i].cmdchar == espcmd)
153 break;
154 if(i==NUM_ESP_COMMANDS)
155 printk("ESP_Unknown");
156 else
157 printk("%s%s", esp_cmd_strings[i].text,
158 ((dma_bit) ? "+DMA" : ""));
159}
160
161/* Print the status register's value */
162static inline void esp_print_statreg(unchar statreg)
163{
164 unchar phase;
165
166 printk("STATUS<");
167 phase = statreg & ESP_STAT_PMASK;
168 printk("%s,", (phase == ESP_DOP ? "DATA-OUT" :
169 (phase == ESP_DIP ? "DATA-IN" :
170 (phase == ESP_CMDP ? "COMMAND" :
171 (phase == ESP_STATP ? "STATUS" :
172 (phase == ESP_MOP ? "MSG-OUT" :
173 (phase == ESP_MIP ? "MSG_IN" :
174 "unknown")))))));
175 if(statreg & ESP_STAT_TDONE)
176 printk("TRANS_DONE,");
177 if(statreg & ESP_STAT_TCNT)
178 printk("TCOUNT_ZERO,");
179 if(statreg & ESP_STAT_PERR)
180 printk("P_ERROR,");
181 if(statreg & ESP_STAT_SPAM)
182 printk("SPAM,");
183 if(statreg & ESP_STAT_INTR)
184 printk("IRQ,");
185 printk(">");
186}
187
188/* Print the interrupt register's value */
189static inline void esp_print_ireg(unchar intreg)
190{
191 printk("INTREG< ");
192 if(intreg & ESP_INTR_S)
193 printk("SLCT_NATN ");
194 if(intreg & ESP_INTR_SATN)
195 printk("SLCT_ATN ");
196 if(intreg & ESP_INTR_RSEL)
197 printk("RSLCT ");
198 if(intreg & ESP_INTR_FDONE)
199 printk("FDONE ");
200 if(intreg & ESP_INTR_BSERV)
201 printk("BSERV ");
202 if(intreg & ESP_INTR_DC)
203 printk("DISCNCT ");
204 if(intreg & ESP_INTR_IC)
205 printk("ILL_CMD ");
206 if(intreg & ESP_INTR_SR)
207 printk("SCSI_BUS_RESET ");
208 printk(">");
209}
210
211/* Print the sequence step registers contents */
212static inline void esp_print_seqreg(unchar stepreg)
213{
214 stepreg &= ESP_STEP_VBITS;
215 printk("STEP<%s>",
216 (stepreg == ESP_STEP_ASEL ? "SLCT_ARB_CMPLT" :
217 (stepreg == ESP_STEP_SID ? "1BYTE_MSG_SENT" :
218 (stepreg == ESP_STEP_NCMD ? "NOT_IN_CMD_PHASE" :
219 (stepreg == ESP_STEP_PPC ? "CMD_BYTES_LOST" :
220 (stepreg == ESP_STEP_FINI4 ? "CMD_SENT_OK" :
221 "UNKNOWN"))))));
222}
223
224static char *phase_string(int phase)
225{
226 switch(phase) {
227 case not_issued:
228 return "UNISSUED";
229 case in_slct_norm:
230 return "SLCTNORM";
231 case in_slct_stop:
232 return "SLCTSTOP";
233 case in_slct_msg:
234 return "SLCTMSG";
235 case in_slct_tag:
236 return "SLCTTAG";
237 case in_slct_sneg:
238 return "SLCTSNEG";
239 case in_datain:
240 return "DATAIN";
241 case in_dataout:
242 return "DATAOUT";
243 case in_data_done:
244 return "DATADONE";
245 case in_msgin:
246 return "MSGIN";
247 case in_msgincont:
248 return "MSGINCONT";
249 case in_msgindone:
250 return "MSGINDONE";
251 case in_msgout:
252 return "MSGOUT";
253 case in_msgoutdone:
254 return "MSGOUTDONE";
255 case in_cmdbegin:
256 return "CMDBEGIN";
257 case in_cmdend:
258 return "CMDEND";
259 case in_status:
260 return "STATUS";
261 case in_freeing:
262 return "FREEING";
263 case in_the_dark:
264 return "CLUELESS";
265 case in_abortone:
266 return "ABORTONE";
267 case in_abortall:
268 return "ABORTALL";
269 case in_resetdev:
270 return "RESETDEV";
271 case in_resetbus:
272 return "RESETBUS";
273 case in_tgterror:
274 return "TGTERROR";
275 default:
276 return "UNKNOWN";
277 };
278}
279
280#ifdef DEBUG_STATE_MACHINE
281static inline void esp_advance_phase(Scsi_Cmnd *s, int newphase)
282{
283 ESPLOG(("<%s>", phase_string(newphase)));
284 s->SCp.sent_command = s->SCp.phase;
285 s->SCp.phase = newphase;
286}
287#else
288#define esp_advance_phase(__s, __newphase) \
289 (__s)->SCp.sent_command = (__s)->SCp.phase; \
290 (__s)->SCp.phase = (__newphase);
291#endif
292
293#ifdef DEBUG_ESP_CMDS
294static inline void esp_cmd(struct NCR_ESP *esp, struct ESP_regs *eregs,
295 unchar cmd)
296{
297 esp->espcmdlog[esp->espcmdent] = cmd;
298 esp->espcmdent = (esp->espcmdent + 1) & 31;
299 esp_write(eregs->esp_cmnd, cmd);
300}
301#else
302#define esp_cmd(__esp, __eregs, __cmd) esp_write((__eregs)->esp_cmnd, (__cmd))
303#endif
304
305/* How we use the various Linux SCSI data structures for operation.
306 *
307 * struct scsi_cmnd:
308 *
309 * We keep track of the syncronous capabilities of a target
310 * in the device member, using sync_min_period and
311 * sync_max_offset. These are the values we directly write
312 * into the ESP registers while running a command. If offset
313 * is zero the ESP will use asynchronous transfers.
314 * If the borken flag is set we assume we shouldn't even bother
315 * trying to negotiate for synchronous transfer as this target
316 * is really stupid. If we notice the target is dropping the
317 * bus, and we have been allowing it to disconnect, we clear
318 * the disconnect flag.
319 */
320
321/* Manipulation of the ESP command queues. Thanks to the aha152x driver
322 * and its author, Juergen E. Fischer, for the methods used here.
323 * Note that these are per-ESP queues, not global queues like
324 * the aha152x driver uses.
325 */
326static inline void append_SC(Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
327{
328 Scsi_Cmnd *end;
329
330 new_SC->host_scribble = (unsigned char *) NULL;
331 if(!*SC)
332 *SC = new_SC;
333 else {
334 for(end=*SC;end->host_scribble;end=(Scsi_Cmnd *)end->host_scribble)
335 ;
336 end->host_scribble = (unsigned char *) new_SC;
337 }
338}
339
340static inline void prepend_SC(Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
341{
342 new_SC->host_scribble = (unsigned char *) *SC;
343 *SC = new_SC;
344}
345
346static inline Scsi_Cmnd *remove_first_SC(Scsi_Cmnd **SC)
347{
348 Scsi_Cmnd *ptr;
349
350 ptr = *SC;
351 if(ptr)
352 *SC = (Scsi_Cmnd *) (*SC)->host_scribble;
353 return ptr;
354}
355
356static inline Scsi_Cmnd *remove_SC(Scsi_Cmnd **SC, int target, int lun)
357{
358 Scsi_Cmnd *ptr, *prev;
359
360 for(ptr = *SC, prev = NULL;
361 ptr && ((ptr->device->id != target) || (ptr->device->lun != lun));
362 prev = ptr, ptr = (Scsi_Cmnd *) ptr->host_scribble)
363 ;
364 if(ptr) {
365 if(prev)
366 prev->host_scribble=ptr->host_scribble;
367 else
368 *SC=(Scsi_Cmnd *)ptr->host_scribble;
369 }
370 return ptr;
371}
372
373/* Resetting various pieces of the ESP scsi driver chipset */
374
375/* Reset the ESP chip, _not_ the SCSI bus. */
376static void esp_reset_esp(struct NCR_ESP *esp, struct ESP_regs *eregs)
377{
378 int family_code, version, i;
379 volatile int trash;
380
381 /* Now reset the ESP chip */
382 esp_cmd(esp, eregs, ESP_CMD_RC);
383 esp_cmd(esp, eregs, ESP_CMD_NULL | ESP_CMD_DMA);
384 if(esp->erev == fast)
385 esp_write(eregs->esp_cfg2, ESP_CONFIG2_FENAB);
386 esp_cmd(esp, eregs, ESP_CMD_NULL | ESP_CMD_DMA);
387
388 /* This is the only point at which it is reliable to read
389 * the ID-code for a fast ESP chip variant.
390 */
391 esp->max_period = ((35 * esp->ccycle) / 1000);
392 if(esp->erev == fast) {
393 char *erev2string[] = {
394 "Emulex FAS236",
395 "Emulex FPESP100A",
396 "fast",
397 "QLogic FAS366",
398 "Emulex FAS216",
399 "Symbios Logic 53CF9x-2",
400 "unknown!"
401 };
402
403 version = esp_read(eregs->esp_uid);
404 family_code = (version & 0xf8) >> 3;
405 if(family_code == 0x02) {
406 if ((version & 7) == 2)
407 esp->erev = fas216;
408 else
409 esp->erev = fas236;
410 } else if(family_code == 0x0a)
411 esp->erev = fas366; /* Version is usually '5'. */
412 else if(family_code == 0x00) {
413 if ((version & 7) == 2)
414 esp->erev = fas100a; /* NCR53C9X */
415 else
416 esp->erev = espunknown;
417 } else if(family_code == 0x14) {
418 if ((version & 7) == 2)
419 esp->erev = fsc;
420 else
421 esp->erev = espunknown;
422 } else if(family_code == 0x00) {
423 if ((version & 7) == 2)
424 esp->erev = fas100a; /* NCR53C9X */
425 else
426 esp->erev = espunknown;
427 } else
428 esp->erev = espunknown;
429 ESPLOG(("esp%d: FAST chip is %s (family=%d, version=%d)\n",
430 esp->esp_id, erev2string[esp->erev - fas236],
431 family_code, (version & 7)));
432
433 esp->min_period = ((4 * esp->ccycle) / 1000);
434 } else {
435 esp->min_period = ((5 * esp->ccycle) / 1000);
436 }
437
438 /* Reload the configuration registers */
439 esp_write(eregs->esp_cfact, esp->cfact);
440 esp->prev_stp = 0;
441 esp_write(eregs->esp_stp, 0);
442 esp->prev_soff = 0;
443 esp_write(eregs->esp_soff, 0);
444 esp_write(eregs->esp_timeo, esp->neg_defp);
445 esp->max_period = (esp->max_period + 3)>>2;
446 esp->min_period = (esp->min_period + 3)>>2;
447
448 esp_write(eregs->esp_cfg1, esp->config1);
449 switch(esp->erev) {
450 case esp100:
451 /* nothing to do */
452 break;
453 case esp100a:
454 esp_write(eregs->esp_cfg2, esp->config2);
455 break;
456 case esp236:
457 /* Slow 236 */
458 esp_write(eregs->esp_cfg2, esp->config2);
459 esp->prev_cfg3 = esp->config3[0];
460 esp_write(eregs->esp_cfg3, esp->prev_cfg3);
461 break;
462 case fas366:
463 panic("esp: FAS366 support not present, please notify "
464 "jongk@cs.utwente.nl");
465 break;
466 case fas216:
467 case fas236:
468 case fsc:
469 /* Fast ESP variants */
470 esp_write(eregs->esp_cfg2, esp->config2);
471 for(i=0; i<8; i++)
472 esp->config3[i] |= ESP_CONFIG3_FCLK;
473 esp->prev_cfg3 = esp->config3[0];
474 esp_write(eregs->esp_cfg3, esp->prev_cfg3);
475 if(esp->diff)
476 esp->radelay = 0;
477 else
478 esp->radelay = 16;
479 /* Different timeout constant for these chips */
480 esp->neg_defp =
481 FSC_NEG_DEFP(esp->cfreq,
482 (esp->cfact == ESP_CCF_F0 ?
483 ESP_CCF_F7 + 1 : esp->cfact));
484 esp_write(eregs->esp_timeo, esp->neg_defp);
485 /* Enable Active Negotiation if possible */
486 if((esp->erev == fsc) && !esp->diff)
487 esp_write(eregs->esp_cfg4, ESP_CONFIG4_EAN);
488 break;
489 case fas100a:
490 /* Fast 100a */
491 esp_write(eregs->esp_cfg2, esp->config2);
492 for(i=0; i<8; i++)
493 esp->config3[i] |= ESP_CONFIG3_FCLOCK;
494 esp->prev_cfg3 = esp->config3[0];
495 esp_write(eregs->esp_cfg3, esp->prev_cfg3);
496 esp->radelay = 32;
497 break;
498 default:
499 panic("esp: what could it be... I wonder...");
500 break;
501 };
502
503 /* Eat any bitrot in the chip */
504 trash = esp_read(eregs->esp_intrpt);
505 udelay(100);
506}
507
508/* This places the ESP into a known state at boot time. */
509void esp_bootup_reset(struct NCR_ESP *esp, struct ESP_regs *eregs)
510{
511 volatile unchar trash;
512
513 /* Reset the DMA */
514 if(esp->dma_reset)
515 esp->dma_reset(esp);
516
517 /* Reset the ESP */
518 esp_reset_esp(esp, eregs);
519
520 /* Reset the SCSI bus, but tell ESP not to generate an irq */
521 esp_write(eregs->esp_cfg1, (esp_read(eregs->esp_cfg1) | ESP_CONFIG1_SRRDISAB));
522 esp_cmd(esp, eregs, ESP_CMD_RS);
523 udelay(400);
524 esp_write(eregs->esp_cfg1, esp->config1);
525
526 /* Eat any bitrot in the chip and we are done... */
527 trash = esp_read(eregs->esp_intrpt);
528}
529EXPORT_SYMBOL(esp_bootup_reset);
530
531/* Allocate structure and insert basic data such as SCSI chip frequency
532 * data and a pointer to the device
533 */
534struct NCR_ESP* esp_allocate(struct scsi_host_template *tpnt, void *esp_dev,
535 int hotplug)
536{
537 struct NCR_ESP *esp, *elink;
538 struct Scsi_Host *esp_host;
539
540 if (hotplug)
541 esp_host = scsi_host_alloc(tpnt, sizeof(struct NCR_ESP));
542 else
543 esp_host = scsi_register(tpnt, sizeof(struct NCR_ESP));
544 if(!esp_host)
545 panic("Cannot register ESP SCSI host");
546 esp = (struct NCR_ESP *) esp_host->hostdata;
547 if(!esp)
548 panic("No esp in hostdata");
549 esp->ehost = esp_host;
550 esp->edev = esp_dev;
551 esp->esp_id = nesps++;
552
553 /* Set bitshift value (only used on Amiga with multiple ESPs) */
554 esp->shift = 2;
555
556 /* Put into the chain of esp chips detected */
557 if(espchain) {
558 elink = espchain;
559 while(elink->next) elink = elink->next;
560 elink->next = esp;
561 } else {
562 espchain = esp;
563 }
564 esp->next = NULL;
565
566 return esp;
567}
568
569void esp_deallocate(struct NCR_ESP *esp)
570{
571 struct NCR_ESP *elink;
572
573 if(espchain == esp) {
574 espchain = NULL;
575 } else {
576 for(elink = espchain; elink && (elink->next != esp); elink = elink->next);
577 if(elink)
578 elink->next = esp->next;
579 }
580 nesps--;
581}
582
583/* Complete initialization of ESP structure and device
584 * Caller must have initialized appropriate parts of the ESP structure
585 * between the call to esp_allocate and this function.
586 */
587void esp_initialize(struct NCR_ESP *esp)
588{
589 struct ESP_regs *eregs = esp->eregs;
590 unsigned int fmhz;
591 unchar ccf;
592 int i;
593
594 /* Check out the clock properties of the chip. */
595
596 /* This is getting messy but it has to be done
597 * correctly or else you get weird behavior all
598 * over the place. We are trying to basically
599 * figure out three pieces of information.
600 *
601 * a) Clock Conversion Factor
602 *
603 * This is a representation of the input
604 * crystal clock frequency going into the
605 * ESP on this machine. Any operation whose
606 * timing is longer than 400ns depends on this
607 * value being correct. For example, you'll
608 * get blips for arbitration/selection during
609 * high load or with multiple targets if this
610 * is not set correctly.
611 *
612 * b) Selection Time-Out
613 *
614 * The ESP isn't very bright and will arbitrate
615 * for the bus and try to select a target
616 * forever if you let it. This value tells
617 * the ESP when it has taken too long to
618 * negotiate and that it should interrupt
619 * the CPU so we can see what happened.
620 * The value is computed as follows (from
621 * NCR/Symbios chip docs).
622 *
623 * (Time Out Period) * (Input Clock)
624 * STO = ----------------------------------
625 * (8192) * (Clock Conversion Factor)
626 *
627 * You usually want the time out period to be
628 * around 250ms, I think we'll set it a little
629 * bit higher to account for fully loaded SCSI
630 * bus's and slow devices that don't respond so
631 * quickly to selection attempts. (yeah, I know
632 * this is out of spec. but there is a lot of
633 * buggy pieces of firmware out there so bite me)
634 *
635 * c) Imperical constants for synchronous offset
636 * and transfer period register values
637 *
638 * This entails the smallest and largest sync
639 * period we could ever handle on this ESP.
640 */
641
642 fmhz = esp->cfreq;
643
644 if(fmhz <= (5000000))
645 ccf = 0;
646 else
647 ccf = (((5000000 - 1) + (fmhz))/(5000000));
648 if(!ccf || ccf > 8) {
649 /* If we can't find anything reasonable,
650 * just assume 20MHZ. This is the clock
651 * frequency of the older sun4c's where I've
652 * been unable to find the clock-frequency
653 * PROM property. All other machines provide
654 * useful values it seems.
655 */
656 ccf = ESP_CCF_F4;
657 fmhz = (20000000);
658 }
659 if(ccf==(ESP_CCF_F7+1))
660 esp->cfact = ESP_CCF_F0;
661 else if(ccf == ESP_CCF_NEVER)
662 esp->cfact = ESP_CCF_F2;
663 else
664 esp->cfact = ccf;
665 esp->cfreq = fmhz;
666 esp->ccycle = ESP_MHZ_TO_CYCLE(fmhz);
667 esp->ctick = ESP_TICK(ccf, esp->ccycle);
668 esp->neg_defp = ESP_NEG_DEFP(fmhz, ccf);
669 esp->sync_defp = SYNC_DEFP_SLOW;
670
671 printk("SCSI ID %d Clk %dMHz CCF=%d TOut %d ",
672 esp->scsi_id, (esp->cfreq / 1000000),
673 ccf, (int) esp->neg_defp);
674
675 /* Fill in ehost data */
676 esp->ehost->base = (unsigned long)eregs;
677 esp->ehost->this_id = esp->scsi_id;
678 esp->ehost->irq = esp->irq;
679
680 /* SCSI id mask */
681 esp->scsi_id_mask = (1 << esp->scsi_id);
682
683 /* Probe the revision of this esp */
684 esp->config1 = (ESP_CONFIG1_PENABLE | (esp->scsi_id & 7));
685 esp->config2 = (ESP_CONFIG2_SCSI2ENAB | ESP_CONFIG2_REGPARITY);
686 esp_write(eregs->esp_cfg2, esp->config2);
687 if((esp_read(eregs->esp_cfg2) & ~(ESP_CONFIG2_MAGIC)) !=
688 (ESP_CONFIG2_SCSI2ENAB | ESP_CONFIG2_REGPARITY)) {
689 printk("NCR53C90(esp100)\n");
690 esp->erev = esp100;
691 } else {
692 esp->config2 = 0;
693 esp_write(eregs->esp_cfg2, 0);
694 esp_write(eregs->esp_cfg3, 5);
695 if(esp_read(eregs->esp_cfg3) != 5) {
696 printk("NCR53C90A(esp100a)\n");
697 esp->erev = esp100a;
698 } else {
699 int target;
700
701 for(target=0; target<8; target++)
702 esp->config3[target] = 0;
703 esp->prev_cfg3 = 0;
704 esp_write(eregs->esp_cfg3, 0);
705 if(ccf > ESP_CCF_F5) {
706 printk("NCR53C9XF(espfast)\n");
707 esp->erev = fast;
708 esp->sync_defp = SYNC_DEFP_FAST;
709 } else {
710 printk("NCR53C9x(esp236)\n");
711 esp->erev = esp236;
712 }
713 }
714 }
715
716 /* Initialize the command queues */
717 esp->current_SC = NULL;
718 esp->disconnected_SC = NULL;
719 esp->issue_SC = NULL;
720
721 /* Clear the state machines. */
722 esp->targets_present = 0;
723 esp->resetting_bus = 0;
724 esp->snip = 0;
725
726 init_waitqueue_head(&esp->reset_queue);
727
728 esp->fas_premature_intr_workaround = 0;
729 for(i = 0; i < 32; i++)
730 esp->espcmdlog[i] = 0;
731 esp->espcmdent = 0;
732 for(i = 0; i < 16; i++) {
733 esp->cur_msgout[i] = 0;
734 esp->cur_msgin[i] = 0;
735 }
736 esp->prevmsgout = esp->prevmsgin = 0;
737 esp->msgout_len = esp->msgin_len = 0;
738
739 /* Clear the one behind caches to hold unmatchable values. */
740 esp->prev_soff = esp->prev_stp = esp->prev_cfg3 = 0xff;
741
742 /* Reset the thing before we try anything... */
743 esp_bootup_reset(esp, eregs);
744
745 esps_in_use++;
746}
747
748/* The info function will return whatever useful
749 * information the developer sees fit. If not provided, then
750 * the name field will be used instead.
751 */
752const char *esp_info(struct Scsi_Host *host)
753{
754 struct NCR_ESP *esp;
755
756 esp = (struct NCR_ESP *) host->hostdata;
757 switch(esp->erev) {
758 case esp100:
759 return "ESP100 (NCR53C90)";
760 case esp100a:
761 return "ESP100A (NCR53C90A)";
762 case esp236:
763 return "ESP236 (NCR53C9x)";
764 case fas216:
765 return "Emulex FAS216";
766 case fas236:
767 return "Emulex FAS236";
768 case fas366:
769 return "QLogic FAS366";
770 case fas100a:
771 return "FPESP100A";
772 case fsc:
773 return "Symbios Logic 53CF9x-2";
774 default:
775 panic("Bogon ESP revision");
776 };
777}
778EXPORT_SYMBOL(esp_info);
779
780/* From Wolfgang Stanglmeier's NCR scsi driver. */
781struct info_str
782{
783 char *buffer;
784 int length;
785 int offset;
786 int pos;
787};
788
789static void copy_mem_info(struct info_str *info, char *data, int len)
790{
791 if (info->pos + len > info->length)
792 len = info->length - info->pos;
793
794 if (info->pos + len < info->offset) {
795 info->pos += len;
796 return;
797 }
798 if (info->pos < info->offset) {
799 data += (info->offset - info->pos);
800 len -= (info->offset - info->pos);
801 }
802
803 if (len > 0) {
804 memcpy(info->buffer + info->pos, data, len);
805 info->pos += len;
806 }
807}
808
809static int copy_info(struct info_str *info, char *fmt, ...)
810{
811 va_list args;
812 char buf[81];
813 int len;
814
815 va_start(args, fmt);
816 len = vsprintf(buf, fmt, args);
817 va_end(args);
818
819 copy_mem_info(info, buf, len);
820 return len;
821}
822
823static int esp_host_info(struct NCR_ESP *esp, char *ptr, off_t offset, int len)
824{
825 struct scsi_device *sdev;
826 struct info_str info;
827 int i;
828
829 info.buffer = ptr;
830 info.length = len;
831 info.offset = offset;
832 info.pos = 0;
833
834 copy_info(&info, "ESP Host Adapter:\n");
835 copy_info(&info, "\tESP Model\t\t");
836 switch(esp->erev) {
837 case esp100:
838 copy_info(&info, "ESP100 (NCR53C90)\n");
839 break;
840 case esp100a:
841 copy_info(&info, "ESP100A (NCR53C90A)\n");
842 break;
843 case esp236:
844 copy_info(&info, "ESP236 (NCR53C9x)\n");
845 break;
846 case fas216:
847 copy_info(&info, "Emulex FAS216\n");
848 break;
849 case fas236:
850 copy_info(&info, "Emulex FAS236\n");
851 break;
852 case fas100a:
853 copy_info(&info, "FPESP100A\n");
854 break;
855 case fast:
856 copy_info(&info, "Generic FAST\n");
857 break;
858 case fas366:
859 copy_info(&info, "QLogic FAS366\n");
860 break;
861 case fsc:
862 copy_info(&info, "Symbios Logic 53C9x-2\n");
863 break;
864 case espunknown:
865 default:
866 copy_info(&info, "Unknown!\n");
867 break;
868 };
869 copy_info(&info, "\tLive Targets\t\t[ ");
870 for(i = 0; i < 15; i++) {
871 if(esp->targets_present & (1 << i))
872 copy_info(&info, "%d ", i);
873 }
874 copy_info(&info, "]\n\n");
875
876 /* Now describe the state of each existing target. */
877 copy_info(&info, "Target #\tconfig3\t\tSync Capabilities\tDisconnect\n");
878
879 shost_for_each_device(sdev, esp->ehost) {
880 struct esp_device *esp_dev = sdev->hostdata;
881 uint id = sdev->id;
882
883 if (!(esp->targets_present & (1 << id)))
884 continue;
885
886 copy_info(&info, "%d\t\t", id);
887 copy_info(&info, "%08lx\t", esp->config3[id]);
888 copy_info(&info, "[%02lx,%02lx]\t\t\t",
889 esp_dev->sync_max_offset,
890 esp_dev->sync_min_period);
891 copy_info(&info, "%s\n", esp_dev->disconnect ? "yes" : "no");
892 }
893
894 return info.pos > info.offset? info.pos - info.offset : 0;
895}
896
897/* ESP proc filesystem code. */
898int esp_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t offset, int length,
899 int inout)
900{
901 struct NCR_ESP *esp = (struct NCR_ESP *)shost->hostdata;
902
903 if(inout)
904 return -EINVAL; /* not yet */
905 if(start)
906 *start = buffer;
907 return esp_host_info(esp, buffer, offset, length);
908}
909EXPORT_SYMBOL(esp_proc_info);
910
911static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
912{
913 if(sp->use_sg == 0) {
914 sp->SCp.this_residual = sp->request_bufflen;
915 sp->SCp.buffer = (struct scatterlist *) sp->request_buffer;
916 sp->SCp.buffers_residual = 0;
917 if (esp->dma_mmu_get_scsi_one)
918 esp->dma_mmu_get_scsi_one(esp, sp);
919 else
920 sp->SCp.ptr =
921 (char *) virt_to_phys(sp->request_buffer);
922 } else {
923 sp->SCp.buffer = (struct scatterlist *) sp->request_buffer;
924 sp->SCp.buffers_residual = sp->use_sg - 1;
925 sp->SCp.this_residual = sp->SCp.buffer->length;
926 if (esp->dma_mmu_get_scsi_sgl)
927 esp->dma_mmu_get_scsi_sgl(esp, sp);
928 else
929 sp->SCp.ptr =
930 (char *) virt_to_phys(sg_virt(sp->SCp.buffer));
931 }
932}
933
934static void esp_release_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
935{
936 if(sp->use_sg == 0) {
937 if (esp->dma_mmu_release_scsi_one)
938 esp->dma_mmu_release_scsi_one(esp, sp);
939 } else {
940 if (esp->dma_mmu_release_scsi_sgl)
941 esp->dma_mmu_release_scsi_sgl(esp, sp);
942 }
943}
944
945static void esp_restore_pointers(struct NCR_ESP *esp, Scsi_Cmnd *sp)
946{
947 struct esp_pointers *ep = &esp->data_pointers[scmd_id(sp)];
948
949 sp->SCp.ptr = ep->saved_ptr;
950 sp->SCp.buffer = ep->saved_buffer;
951 sp->SCp.this_residual = ep->saved_this_residual;
952 sp->SCp.buffers_residual = ep->saved_buffers_residual;
953}
954
955static void esp_save_pointers(struct NCR_ESP *esp, Scsi_Cmnd *sp)
956{
957 struct esp_pointers *ep = &esp->data_pointers[scmd_id(sp)];
958
959 ep->saved_ptr = sp->SCp.ptr;
960 ep->saved_buffer = sp->SCp.buffer;
961 ep->saved_this_residual = sp->SCp.this_residual;
962 ep->saved_buffers_residual = sp->SCp.buffers_residual;
963}
964
965/* Some rules:
966 *
967 * 1) Never ever panic while something is live on the bus.
968 * If there is to be any chance of syncing the disks this
969 * rule is to be obeyed.
970 *
971 * 2) Any target that causes a foul condition will no longer
972 * have synchronous transfers done to it, no questions
973 * asked.
974 *
975 * 3) Keep register accesses to a minimum. Think about some
976 * day when we have Xbus machines this is running on and
977 * the ESP chip is on the other end of the machine on a
978 * different board from the cpu where this is running.
979 */
980
981/* Fire off a command. We assume the bus is free and that the only
982 * case where we could see an interrupt is where we have disconnected
983 * commands active and they are trying to reselect us.
984 */
985static inline void esp_check_cmd(struct NCR_ESP *esp, Scsi_Cmnd *sp)
986{
987 switch(sp->cmd_len) {
988 case 6:
989 case 10:
990 case 12:
991 esp->esp_slowcmd = 0;
992 break;
993
994 default:
995 esp->esp_slowcmd = 1;
996 esp->esp_scmdleft = sp->cmd_len;
997 esp->esp_scmdp = &sp->cmnd[0];
998 break;
999 };
1000}
1001
1002static inline void build_sync_nego_msg(struct NCR_ESP *esp, int period, int offset)
1003{
1004 esp->cur_msgout[0] = EXTENDED_MESSAGE;
1005 esp->cur_msgout[1] = 3;
1006 esp->cur_msgout[2] = EXTENDED_SDTR;
1007 esp->cur_msgout[3] = period;
1008 esp->cur_msgout[4] = offset;
1009 esp->msgout_len = 5;
1010}
1011
1012static void esp_exec_cmd(struct NCR_ESP *esp)
1013{
1014 struct ESP_regs *eregs = esp->eregs;
1015 struct esp_device *esp_dev;
1016 Scsi_Cmnd *SCptr;
1017 struct scsi_device *SDptr;
1018 volatile unchar *cmdp = esp->esp_command;
1019 unsigned char the_esp_command;
1020 int lun, target;
1021 int i;
1022
1023 /* Hold off if we have disconnected commands and
1024 * an IRQ is showing...
1025 */
1026 if(esp->disconnected_SC && esp->dma_irq_p(esp))
1027 return;
1028
1029 /* Grab first member of the issue queue. */
1030 SCptr = esp->current_SC = remove_first_SC(&esp->issue_SC);
1031
1032 /* Safe to panic here because current_SC is null. */
1033 if(!SCptr)
1034 panic("esp: esp_exec_cmd and issue queue is NULL");
1035
1036 SDptr = SCptr->device;
1037 esp_dev = SDptr->hostdata;
1038 lun = SCptr->device->lun;
1039 target = SCptr->device->id;
1040
1041 esp->snip = 0;
1042 esp->msgout_len = 0;
1043
1044 /* Send it out whole, or piece by piece? The ESP
1045 * only knows how to automatically send out 6, 10,
1046 * and 12 byte commands. I used to think that the
1047 * Linux SCSI code would never throw anything other
1048 * than that to us, but then again there is the
1049 * SCSI generic driver which can send us anything.
1050 */
1051 esp_check_cmd(esp, SCptr);
1052
1053 /* If arbitration/selection is successful, the ESP will leave
1054 * ATN asserted, causing the target to go into message out
1055 * phase. The ESP will feed the target the identify and then
1056 * the target can only legally go to one of command,
1057 * datain/out, status, or message in phase, or stay in message
1058 * out phase (should we be trying to send a sync negotiation
1059 * message after the identify). It is not allowed to drop
1060 * BSY, but some buggy targets do and we check for this
1061 * condition in the selection complete code. Most of the time
1062 * we'll make the command bytes available to the ESP and it
1063 * will not interrupt us until it finishes command phase, we
1064 * cannot do this for command sizes the ESP does not
1065 * understand and in this case we'll get interrupted right
1066 * when the target goes into command phase.
1067 *
1068 * It is absolutely _illegal_ in the presence of SCSI-2 devices
1069 * to use the ESP select w/o ATN command. When SCSI-2 devices are
1070 * present on the bus we _must_ always go straight to message out
1071 * phase with an identify message for the target. Being that
1072 * selection attempts in SCSI-1 w/o ATN was an option, doing SCSI-2
1073 * selections should not confuse SCSI-1 we hope.
1074 */
1075
1076 if(esp_dev->sync) {
1077 /* this targets sync is known */
1078#ifdef CONFIG_SCSI_MAC_ESP
1079do_sync_known:
1080#endif
1081 if(esp_dev->disconnect)
1082 *cmdp++ = IDENTIFY(1, lun);
1083 else
1084 *cmdp++ = IDENTIFY(0, lun);
1085
1086 if(esp->esp_slowcmd) {
1087 the_esp_command = (ESP_CMD_SELAS | ESP_CMD_DMA);
1088 esp_advance_phase(SCptr, in_slct_stop);
1089 } else {
1090 the_esp_command = (ESP_CMD_SELA | ESP_CMD_DMA);
1091 esp_advance_phase(SCptr, in_slct_norm);
1092 }
1093 } else if(!(esp->targets_present & (1<<target)) || !(esp_dev->disconnect)) {
1094 /* After the bootup SCSI code sends both the
1095 * TEST_UNIT_READY and INQUIRY commands we want
1096 * to at least attempt allowing the device to
1097 * disconnect.
1098 */
1099 ESPMISC(("esp: Selecting device for first time. target=%d "
1100 "lun=%d\n", target, SCptr->device->lun));
1101 if(!SDptr->borken && !esp_dev->disconnect)
1102 esp_dev->disconnect = 1;
1103
1104 *cmdp++ = IDENTIFY(0, lun);
1105 esp->prevmsgout = NOP;
1106 esp_advance_phase(SCptr, in_slct_norm);
1107 the_esp_command = (ESP_CMD_SELA | ESP_CMD_DMA);
1108
1109 /* Take no chances... */
1110 esp_dev->sync_max_offset = 0;
1111 esp_dev->sync_min_period = 0;
1112 } else {
1113 int toshiba_cdrom_hwbug_wkaround = 0;
1114
1115#ifdef CONFIG_SCSI_MAC_ESP
1116 /* Never allow synchronous transfers (disconnect OK) on
1117 * Macintosh. Well, maybe later when we figured out how to
1118 * do DMA on the machines that support it ...
1119 */
1120 esp_dev->disconnect = 1;
1121 esp_dev->sync_max_offset = 0;
1122 esp_dev->sync_min_period = 0;
1123 esp_dev->sync = 1;
1124 esp->snip = 0;
1125 goto do_sync_known;
1126#endif
1127 /* We've talked to this guy before,
1128 * but never negotiated. Let's try
1129 * sync negotiation.
1130 */
1131 if(!SDptr->borken) {
1132 if((SDptr->type == TYPE_ROM) &&
1133 (!strncmp(SDptr->vendor, "TOSHIBA", 7))) {
1134 /* Nice try sucker... */
1135 ESPMISC(("esp%d: Disabling sync for buggy "
1136 "Toshiba CDROM.\n", esp->esp_id));
1137 toshiba_cdrom_hwbug_wkaround = 1;
1138 build_sync_nego_msg(esp, 0, 0);
1139 } else {
1140 build_sync_nego_msg(esp, esp->sync_defp, 15);
1141 }
1142 } else {
1143 build_sync_nego_msg(esp, 0, 0);
1144 }
1145 esp_dev->sync = 1;
1146 esp->snip = 1;
1147
1148 /* A fix for broken SCSI1 targets, when they disconnect
1149 * they lock up the bus and confuse ESP. So disallow
1150 * disconnects for SCSI1 targets for now until we
1151 * find a better fix.
1152 *
1153 * Addendum: This is funny, I figured out what was going
1154 * on. The blotzed SCSI1 target would disconnect,
1155 * one of the other SCSI2 targets or both would be
1156 * disconnected as well. The SCSI1 target would
1157 * stay disconnected long enough that we start
1158 * up a command on one of the SCSI2 targets. As
1159 * the ESP is arbitrating for the bus the SCSI1
1160 * target begins to arbitrate as well to reselect
1161 * the ESP. The SCSI1 target refuses to drop it's
1162 * ID bit on the data bus even though the ESP is
1163 * at ID 7 and is the obvious winner for any
1164 * arbitration. The ESP is a poor sport and refuses
1165 * to lose arbitration, it will continue indefinitely
1166 * trying to arbitrate for the bus and can only be
1167 * stopped via a chip reset or SCSI bus reset.
1168 * Therefore _no_ disconnects for SCSI1 targets
1169 * thank you very much. ;-)
1170 */
1171 if(((SDptr->scsi_level < 3) && (SDptr->type != TYPE_TAPE)) ||
1172 toshiba_cdrom_hwbug_wkaround || SDptr->borken) {
1173 ESPMISC((KERN_INFO "esp%d: Disabling DISCONNECT for target %d "
1174 "lun %d\n", esp->esp_id, SCptr->device->id, SCptr->device->lun));
1175 esp_dev->disconnect = 0;
1176 *cmdp++ = IDENTIFY(0, lun);
1177 } else {
1178 *cmdp++ = IDENTIFY(1, lun);
1179 }
1180
1181 /* ESP fifo is only so big...
1182 * Make this look like a slow command.
1183 */
1184 esp->esp_slowcmd = 1;
1185 esp->esp_scmdleft = SCptr->cmd_len;
1186 esp->esp_scmdp = &SCptr->cmnd[0];
1187
1188 the_esp_command = (ESP_CMD_SELAS | ESP_CMD_DMA);
1189 esp_advance_phase(SCptr, in_slct_msg);
1190 }
1191
1192 if(!esp->esp_slowcmd)
1193 for(i = 0; i < SCptr->cmd_len; i++)
1194 *cmdp++ = SCptr->cmnd[i];
1195
1196 esp_write(eregs->esp_busid, (target & 7));
1197 if (esp->prev_soff != esp_dev->sync_max_offset ||
1198 esp->prev_stp != esp_dev->sync_min_period ||
1199 (esp->erev > esp100a &&
1200 esp->prev_cfg3 != esp->config3[target])) {
1201 esp->prev_soff = esp_dev->sync_max_offset;
1202 esp_write(eregs->esp_soff, esp->prev_soff);
1203 esp->prev_stp = esp_dev->sync_min_period;
1204 esp_write(eregs->esp_stp, esp->prev_stp);
1205 if(esp->erev > esp100a) {
1206 esp->prev_cfg3 = esp->config3[target];
1207 esp_write(eregs->esp_cfg3, esp->prev_cfg3);
1208 }
1209 }
1210 i = (cmdp - esp->esp_command);
1211
1212 /* Set up the DMA and ESP counters */
1213 if(esp->do_pio_cmds){
1214 int j = 0;
1215
1216 /*
1217 * XXX MSch:
1218 *
1219 * It seems this is required, at least to clean up
1220 * after failed commands when using PIO mode ...
1221 */
1222 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
1223
1224 for(;j<i;j++)
1225 esp_write(eregs->esp_fdata, esp->esp_command[j]);
1226 the_esp_command &= ~ESP_CMD_DMA;
1227
1228 /* Tell ESP to "go". */
1229 esp_cmd(esp, eregs, the_esp_command);
1230 } else {
1231 /* Set up the ESP counters */
1232 esp_write(eregs->esp_tclow, i);
1233 esp_write(eregs->esp_tcmed, 0);
1234 esp->dma_init_write(esp, esp->esp_command_dvma, i);
1235
1236 /* Tell ESP to "go". */
1237 esp_cmd(esp, eregs, the_esp_command);
1238 }
1239}
1240
1241/* Queue a SCSI command delivered from the mid-level Linux SCSI code. */
1242int esp_queue(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
1243{
1244 struct NCR_ESP *esp;
1245
1246 /* Set up func ptr and initial driver cmd-phase. */
1247 SCpnt->scsi_done = done;
1248 SCpnt->SCp.phase = not_issued;
1249
1250 esp = (struct NCR_ESP *) SCpnt->device->host->hostdata;
1251
1252 if(esp->dma_led_on)
1253 esp->dma_led_on(esp);
1254
1255 /* We use the scratch area. */
1256 ESPQUEUE(("esp_queue: target=%d lun=%d ", SCpnt->device->id, SCpnt->lun));
1257 ESPDISC(("N<%02x,%02x>", SCpnt->device->id, SCpnt->lun));
1258
1259 esp_get_dmabufs(esp, SCpnt);
1260 esp_save_pointers(esp, SCpnt); /* FIXME for tag queueing */
1261
1262 SCpnt->SCp.Status = CHECK_CONDITION;
1263 SCpnt->SCp.Message = 0xff;
1264 SCpnt->SCp.sent_command = 0;
1265
1266 /* Place into our queue. */
1267 if(SCpnt->cmnd[0] == REQUEST_SENSE) {
1268 ESPQUEUE(("RQSENSE\n"));
1269 prepend_SC(&esp->issue_SC, SCpnt);
1270 } else {
1271 ESPQUEUE(("\n"));
1272 append_SC(&esp->issue_SC, SCpnt);
1273 }
1274
1275 /* Run it now if we can. */
1276 if(!esp->current_SC && !esp->resetting_bus)
1277 esp_exec_cmd(esp);
1278
1279 return 0;
1280}
1281
1282/* Dump driver state. */
1283static void esp_dump_cmd(Scsi_Cmnd *SCptr)
1284{
1285 ESPLOG(("[tgt<%02x> lun<%02x> "
1286 "pphase<%s> cphase<%s>]",
1287 SCptr->device->id, SCptr->device->lun,
1288 phase_string(SCptr->SCp.sent_command),
1289 phase_string(SCptr->SCp.phase)));
1290}
1291
1292static void esp_dump_state(struct NCR_ESP *esp,
1293 struct ESP_regs *eregs)
1294{
1295 Scsi_Cmnd *SCptr = esp->current_SC;
1296#ifdef DEBUG_ESP_CMDS
1297 int i;
1298#endif
1299
1300 ESPLOG(("esp%d: dumping state\n", esp->esp_id));
1301
1302 /* Print DMA status */
1303 esp->dma_dump_state(esp);
1304
1305 ESPLOG(("esp%d: SW [sreg<%02x> sstep<%02x> ireg<%02x>]\n",
1306 esp->esp_id, esp->sreg, esp->seqreg, esp->ireg));
1307 ESPLOG(("esp%d: HW reread [sreg<%02x> sstep<%02x> ireg<%02x>]\n",
1308 esp->esp_id, esp_read(eregs->esp_status), esp_read(eregs->esp_sstep),
1309 esp_read(eregs->esp_intrpt)));
1310#ifdef DEBUG_ESP_CMDS
1311 printk("esp%d: last ESP cmds [", esp->esp_id);
1312 i = (esp->espcmdent - 1) & 31;
1313 printk("<");
1314 esp_print_cmd(esp->espcmdlog[i]);
1315 printk(">");
1316 i = (i - 1) & 31;
1317 printk("<");
1318 esp_print_cmd(esp->espcmdlog[i]);
1319 printk(">");
1320 i = (i - 1) & 31;
1321 printk("<");
1322 esp_print_cmd(esp->espcmdlog[i]);
1323 printk(">");
1324 i = (i - 1) & 31;
1325 printk("<");
1326 esp_print_cmd(esp->espcmdlog[i]);
1327 printk(">");
1328 printk("]\n");
1329#endif /* (DEBUG_ESP_CMDS) */
1330
1331 if(SCptr) {
1332 ESPLOG(("esp%d: current command ", esp->esp_id));
1333 esp_dump_cmd(SCptr);
1334 }
1335 ESPLOG(("\n"));
1336 SCptr = esp->disconnected_SC;
1337 ESPLOG(("esp%d: disconnected ", esp->esp_id));
1338 while(SCptr) {
1339 esp_dump_cmd(SCptr);
1340 SCptr = (Scsi_Cmnd *) SCptr->host_scribble;
1341 }
1342 ESPLOG(("\n"));
1343}
1344
1345/* Abort a command. The host_lock is acquired by caller. */
1346int esp_abort(Scsi_Cmnd *SCptr)
1347{
1348 struct NCR_ESP *esp = (struct NCR_ESP *) SCptr->device->host->hostdata;
1349 struct ESP_regs *eregs = esp->eregs;
1350 int don;
1351
1352 ESPLOG(("esp%d: Aborting command\n", esp->esp_id));
1353 esp_dump_state(esp, eregs);
1354
1355 /* Wheee, if this is the current command on the bus, the
1356 * best we can do is assert ATN and wait for msgout phase.
1357 * This should even fix a hung SCSI bus when we lose state
1358 * in the driver and timeout because the eventual phase change
1359 * will cause the ESP to (eventually) give an interrupt.
1360 */
1361 if(esp->current_SC == SCptr) {
1362 esp->cur_msgout[0] = ABORT;
1363 esp->msgout_len = 1;
1364 esp->msgout_ctr = 0;
1365 esp_cmd(esp, eregs, ESP_CMD_SATN);
1366 return SUCCESS;
1367 }
1368
1369 /* If it is still in the issue queue then we can safely
1370 * call the completion routine and report abort success.
1371 */
1372 don = esp->dma_ports_p(esp);
1373 if(don) {
1374 esp->dma_ints_off(esp);
1375 synchronize_irq(esp->irq);
1376 }
1377 if(esp->issue_SC) {
1378 Scsi_Cmnd **prev, *this;
1379 for(prev = (&esp->issue_SC), this = esp->issue_SC;
1380 this;
1381 prev = (Scsi_Cmnd **) &(this->host_scribble),
1382 this = (Scsi_Cmnd *) this->host_scribble) {
1383 if(this == SCptr) {
1384 *prev = (Scsi_Cmnd *) this->host_scribble;
1385 this->host_scribble = NULL;
1386 esp_release_dmabufs(esp, this);
1387 this->result = DID_ABORT << 16;
1388 this->scsi_done(this);
1389 if(don)
1390 esp->dma_ints_on(esp);
1391 return SUCCESS;
1392 }
1393 }
1394 }
1395
1396 /* Yuck, the command to abort is disconnected, it is not
1397 * worth trying to abort it now if something else is live
1398 * on the bus at this time. So, we let the SCSI code wait
1399 * a little bit and try again later.
1400 */
1401 if(esp->current_SC) {
1402 if(don)
1403 esp->dma_ints_on(esp);
1404 return FAILED;
1405 }
1406
1407 /* It's disconnected, we have to reconnect to re-establish
1408 * the nexus and tell the device to abort. However, we really
1409 * cannot 'reconnect' per se. Don't try to be fancy, just
1410 * indicate failure, which causes our caller to reset the whole
1411 * bus.
1412 */
1413
1414 if(don)
1415 esp->dma_ints_on(esp);
1416 return FAILED;
1417}
1418
1419/* We've sent ESP_CMD_RS to the ESP, the interrupt had just
1420 * arrived indicating the end of the SCSI bus reset. Our job
1421 * is to clean out the command queues and begin re-execution
1422 * of SCSI commands once more.
1423 */
1424static int esp_finish_reset(struct NCR_ESP *esp,
1425 struct ESP_regs *eregs)
1426{
1427 Scsi_Cmnd *sp = esp->current_SC;
1428
1429 /* Clean up currently executing command, if any. */
1430 if (sp != NULL) {
1431 esp_release_dmabufs(esp, sp);
1432 sp->result = (DID_RESET << 16);
1433 sp->scsi_done(sp);
1434 esp->current_SC = NULL;
1435 }
1436
1437 /* Clean up disconnected queue, they have been invalidated
1438 * by the bus reset.
1439 */
1440 if (esp->disconnected_SC) {
1441 while((sp = remove_first_SC(&esp->disconnected_SC)) != NULL) {
1442 esp_release_dmabufs(esp, sp);
1443 sp->result = (DID_RESET << 16);
1444 sp->scsi_done(sp);
1445 }
1446 }
1447
1448 /* SCSI bus reset is complete. */
1449 esp->resetting_bus = 0;
1450 wake_up(&esp->reset_queue);
1451
1452 /* Ok, now it is safe to get commands going once more. */
1453 if(esp->issue_SC)
1454 esp_exec_cmd(esp);
1455
1456 return do_intr_end;
1457}
1458
1459static int esp_do_resetbus(struct NCR_ESP *esp,
1460 struct ESP_regs *eregs)
1461{
1462 ESPLOG(("esp%d: Resetting scsi bus\n", esp->esp_id));
1463 esp->resetting_bus = 1;
1464 esp_cmd(esp, eregs, ESP_CMD_RS);
1465
1466 return do_intr_end;
1467}
1468
1469/* Reset ESP chip, reset hanging bus, then kill active and
1470 * disconnected commands for targets without soft reset.
1471 *
1472 * The host_lock is acquired by caller.
1473 */
1474int esp_reset(Scsi_Cmnd *SCptr)
1475{
1476 struct NCR_ESP *esp = (struct NCR_ESP *) SCptr->device->host->hostdata;
1477
1478 spin_lock_irq(esp->ehost->host_lock);
1479 (void) esp_do_resetbus(esp, esp->eregs);
1480 spin_unlock_irq(esp->ehost->host_lock);
1481
1482 wait_event(esp->reset_queue, (esp->resetting_bus == 0));
1483
1484 return SUCCESS;
1485}
1486
1487/* Internal ESP done function. */
1488static void esp_done(struct NCR_ESP *esp, int error)
1489{
1490 Scsi_Cmnd *done_SC;
1491
1492 if(esp->current_SC) {
1493 done_SC = esp->current_SC;
1494 esp->current_SC = NULL;
1495 esp_release_dmabufs(esp, done_SC);
1496 done_SC->result = error;
1497 done_SC->scsi_done(done_SC);
1498
1499 /* Bus is free, issue any commands in the queue. */
1500 if(esp->issue_SC && !esp->current_SC)
1501 esp_exec_cmd(esp);
1502 } else {
1503 /* Panic is safe as current_SC is null so we may still
1504 * be able to accept more commands to sync disk buffers.
1505 */
1506 ESPLOG(("panicing\n"));
1507 panic("esp: done() called with NULL esp->current_SC");
1508 }
1509}
1510
1511/* Wheee, ESP interrupt engine. */
1512
1513/* Forward declarations. */
1514static int esp_do_phase_determine(struct NCR_ESP *esp,
1515 struct ESP_regs *eregs);
1516static int esp_do_data_finale(struct NCR_ESP *esp, struct ESP_regs *eregs);
1517static int esp_select_complete(struct NCR_ESP *esp, struct ESP_regs *eregs);
1518static int esp_do_status(struct NCR_ESP *esp, struct ESP_regs *eregs);
1519static int esp_do_msgin(struct NCR_ESP *esp, struct ESP_regs *eregs);
1520static int esp_do_msgindone(struct NCR_ESP *esp, struct ESP_regs *eregs);
1521static int esp_do_msgout(struct NCR_ESP *esp, struct ESP_regs *eregs);
1522static int esp_do_cmdbegin(struct NCR_ESP *esp, struct ESP_regs *eregs);
1523
1524#define sreg_datainp(__sreg) (((__sreg) & ESP_STAT_PMASK) == ESP_DIP)
1525#define sreg_dataoutp(__sreg) (((__sreg) & ESP_STAT_PMASK) == ESP_DOP)
1526
1527/* We try to avoid some interrupts by jumping ahead and see if the ESP
1528 * has gotten far enough yet. Hence the following.
1529 */
1530static inline int skipahead1(struct NCR_ESP *esp, struct ESP_regs *eregs,
1531 Scsi_Cmnd *scp, int prev_phase, int new_phase)
1532{
1533 if(scp->SCp.sent_command != prev_phase)
1534 return 0;
1535
1536 if(esp->dma_irq_p(esp)) {
1537 /* Yes, we are able to save an interrupt. */
1538 esp->sreg = (esp_read(eregs->esp_status) & ~(ESP_STAT_INTR));
1539 esp->ireg = esp_read(eregs->esp_intrpt);
1540 if(!(esp->ireg & ESP_INTR_SR))
1541 return 0;
1542 else
1543 return do_reset_complete;
1544 }
1545 /* Ho hum, target is taking forever... */
1546 scp->SCp.sent_command = new_phase; /* so we don't recurse... */
1547 return do_intr_end;
1548}
1549
1550static inline int skipahead2(struct NCR_ESP *esp,
1551 struct ESP_regs *eregs,
1552 Scsi_Cmnd *scp, int prev_phase1, int prev_phase2,
1553 int new_phase)
1554{
1555 if(scp->SCp.sent_command != prev_phase1 &&
1556 scp->SCp.sent_command != prev_phase2)
1557 return 0;
1558 if(esp->dma_irq_p(esp)) {
1559 /* Yes, we are able to save an interrupt. */
1560 esp->sreg = (esp_read(eregs->esp_status) & ~(ESP_STAT_INTR));
1561 esp->ireg = esp_read(eregs->esp_intrpt);
1562 if(!(esp->ireg & ESP_INTR_SR))
1563 return 0;
1564 else
1565 return do_reset_complete;
1566 }
1567 /* Ho hum, target is taking forever... */
1568 scp->SCp.sent_command = new_phase; /* so we don't recurse... */
1569 return do_intr_end;
1570}
1571
1572/* Misc. esp helper macros. */
1573#define esp_setcount(__eregs, __cnt) \
1574 esp_write((__eregs)->esp_tclow, ((__cnt) & 0xff)); \
1575 esp_write((__eregs)->esp_tcmed, (((__cnt) >> 8) & 0xff))
1576
1577#define esp_getcount(__eregs) \
1578 ((esp_read((__eregs)->esp_tclow)&0xff) | \
1579 ((esp_read((__eregs)->esp_tcmed)&0xff) << 8))
1580
1581#define fcount(__esp, __eregs) \
1582 (esp_read((__eregs)->esp_fflags) & ESP_FF_FBYTES)
1583
1584#define fnzero(__esp, __eregs) \
1585 (esp_read((__eregs)->esp_fflags) & ESP_FF_ONOTZERO)
1586
1587/* XXX speculative nops unnecessary when continuing amidst a data phase
1588 * XXX even on esp100!!! another case of flooding the bus with I/O reg
1589 * XXX writes...
1590 */
1591#define esp_maybe_nop(__esp, __eregs) \
1592 if((__esp)->erev == esp100) \
1593 esp_cmd((__esp), (__eregs), ESP_CMD_NULL)
1594
1595#define sreg_to_dataphase(__sreg) \
1596 ((((__sreg) & ESP_STAT_PMASK) == ESP_DOP) ? in_dataout : in_datain)
1597
1598/* The ESP100 when in synchronous data phase, can mistake a long final
1599 * REQ pulse from the target as an extra byte, it places whatever is on
1600 * the data lines into the fifo. For now, we will assume when this
1601 * happens that the target is a bit quirky and we don't want to
1602 * be talking synchronously to it anyways. Regardless, we need to
1603 * tell the ESP to eat the extraneous byte so that we can proceed
1604 * to the next phase.
1605 */
1606static inline int esp100_sync_hwbug(struct NCR_ESP *esp, struct ESP_regs *eregs,
1607 Scsi_Cmnd *sp, int fifocnt)
1608{
1609 /* Do not touch this piece of code. */
1610 if((!(esp->erev == esp100)) ||
1611 (!(sreg_datainp((esp->sreg = esp_read(eregs->esp_status))) && !fifocnt) &&
1612 !(sreg_dataoutp(esp->sreg) && !fnzero(esp, eregs)))) {
1613 if(sp->SCp.phase == in_dataout)
1614 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
1615 return 0;
1616 } else {
1617 /* Async mode for this guy. */
1618 build_sync_nego_msg(esp, 0, 0);
1619
1620 /* Ack the bogus byte, but set ATN first. */
1621 esp_cmd(esp, eregs, ESP_CMD_SATN);
1622 esp_cmd(esp, eregs, ESP_CMD_MOK);
1623 return 1;
1624 }
1625}
1626
1627/* This closes the window during a selection with a reselect pending, because
1628 * we use DMA for the selection process the FIFO should hold the correct
1629 * contents if we get reselected during this process. So we just need to
1630 * ack the possible illegal cmd interrupt pending on the esp100.
1631 */
1632static inline int esp100_reconnect_hwbug(struct NCR_ESP *esp,
1633 struct ESP_regs *eregs)
1634{
1635 volatile unchar junk;
1636
1637 if(esp->erev != esp100)
1638 return 0;
1639 junk = esp_read(eregs->esp_intrpt);
1640
1641 if(junk & ESP_INTR_SR)
1642 return 1;
1643 return 0;
1644}
1645
1646/* This verifies the BUSID bits during a reselection so that we know which
1647 * target is talking to us.
1648 */
1649static inline int reconnect_target(struct NCR_ESP *esp, struct ESP_regs *eregs)
1650{
1651 int it, me = esp->scsi_id_mask, targ = 0;
1652
1653 if(2 != fcount(esp, eregs))
1654 return -1;
1655 it = esp_read(eregs->esp_fdata);
1656 if(!(it & me))
1657 return -1;
1658 it &= ~me;
1659 if(it & (it - 1))
1660 return -1;
1661 while(!(it & 1))
1662 targ++, it >>= 1;
1663 return targ;
1664}
1665
1666/* This verifies the identify from the target so that we know which lun is
1667 * being reconnected.
1668 */
1669static inline int reconnect_lun(struct NCR_ESP *esp, struct ESP_regs *eregs)
1670{
1671 int lun;
1672
1673 if((esp->sreg & ESP_STAT_PMASK) != ESP_MIP)
1674 return -1;
1675 lun = esp_read(eregs->esp_fdata);
1676
1677 /* Yes, you read this correctly. We report lun of zero
1678 * if we see parity error. ESP reports parity error for
1679 * the lun byte, and this is the only way to hope to recover
1680 * because the target is connected.
1681 */
1682 if(esp->sreg & ESP_STAT_PERR)
1683 return 0;
1684
1685 /* Check for illegal bits being set in the lun. */
1686 if((lun & 0x40) || !(lun & 0x80))
1687 return -1;
1688
1689 return lun & 7;
1690}
1691
1692/* This puts the driver in a state where it can revitalize a command that
1693 * is being continued due to reselection.
1694 */
1695static inline void esp_connect(struct NCR_ESP *esp, struct ESP_regs *eregs,
1696 Scsi_Cmnd *sp)
1697{
1698 struct scsi_device *dp = sp->device;
1699 struct esp_device *esp_dev = dp->hostdata;
1700
1701 if(esp->prev_soff != esp_dev->sync_max_offset ||
1702 esp->prev_stp != esp_dev->sync_min_period ||
1703 (esp->erev > esp100a &&
1704 esp->prev_cfg3 != esp->config3[scmd_id(sp)])) {
1705 esp->prev_soff = esp_dev->sync_max_offset;
1706 esp_write(eregs->esp_soff, esp->prev_soff);
1707 esp->prev_stp = esp_dev->sync_min_period;
1708 esp_write(eregs->esp_stp, esp->prev_stp);
1709 if(esp->erev > esp100a) {
1710 esp->prev_cfg3 = esp->config3[scmd_id(sp)];
1711 esp_write(eregs->esp_cfg3, esp->prev_cfg3);
1712 }
1713 }
1714 esp->current_SC = sp;
1715}
1716
1717/* This will place the current working command back into the issue queue
1718 * if we are to receive a reselection amidst a selection attempt.
1719 */
1720static inline void esp_reconnect(struct NCR_ESP *esp, Scsi_Cmnd *sp)
1721{
1722 if(!esp->disconnected_SC)
1723 ESPLOG(("esp%d: Weird, being reselected but disconnected "
1724 "command queue is empty.\n", esp->esp_id));
1725 esp->snip = 0;
1726 esp->current_SC = NULL;
1727 sp->SCp.phase = not_issued;
1728 append_SC(&esp->issue_SC, sp);
1729}
1730
1731/* Begin message in phase. */
1732static int esp_do_msgin(struct NCR_ESP *esp, struct ESP_regs *eregs)
1733{
1734 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
1735 esp_maybe_nop(esp, eregs);
1736 esp_cmd(esp, eregs, ESP_CMD_TI);
1737 esp->msgin_len = 1;
1738 esp->msgin_ctr = 0;
1739 esp_advance_phase(esp->current_SC, in_msgindone);
1740 return do_work_bus;
1741}
1742
1743static inline void advance_sg(struct NCR_ESP *esp, Scsi_Cmnd *sp)
1744{
1745 ++sp->SCp.buffer;
1746 --sp->SCp.buffers_residual;
1747 sp->SCp.this_residual = sp->SCp.buffer->length;
1748 if (esp->dma_advance_sg)
1749 esp->dma_advance_sg (sp);
1750 else
1751 sp->SCp.ptr = (char *) virt_to_phys(sg_virt(sp->SCp.buffer));
1752
1753}
1754
1755/* Please note that the way I've coded these routines is that I _always_
1756 * check for a disconnect during any and all information transfer
1757 * phases. The SCSI standard states that the target _can_ cause a BUS
1758 * FREE condition by dropping all MSG/CD/IO/BSY signals. Also note
1759 * that during information transfer phases the target controls every
1760 * change in phase, the only thing the initiator can do is "ask" for
1761 * a message out phase by driving ATN true. The target can, and sometimes
1762 * will, completely ignore this request so we cannot assume anything when
1763 * we try to force a message out phase to abort/reset a target. Most of
1764 * the time the target will eventually be nice and go to message out, so
1765 * we may have to hold on to our state about what we want to tell the target
1766 * for some period of time.
1767 */
1768
1769/* I think I have things working here correctly. Even partial transfers
1770 * within a buffer or sub-buffer should not upset us at all no matter
1771 * how bad the target and/or ESP fucks things up.
1772 */
1773static int esp_do_data(struct NCR_ESP *esp, struct ESP_regs *eregs)
1774{
1775 Scsi_Cmnd *SCptr = esp->current_SC;
1776 int thisphase, hmuch;
1777
1778 ESPDATA(("esp_do_data: "));
1779 esp_maybe_nop(esp, eregs);
1780 thisphase = sreg_to_dataphase(esp->sreg);
1781 esp_advance_phase(SCptr, thisphase);
1782 ESPDATA(("newphase<%s> ", (thisphase == in_datain) ? "DATAIN" : "DATAOUT"));
1783 hmuch = esp->dma_can_transfer(esp, SCptr);
1784
1785 /*
1786 * XXX MSch: cater for PIO transfer here; PIO used if hmuch == 0
1787 */
1788 if (hmuch) { /* DMA */
1789 /*
1790 * DMA
1791 */
1792 ESPDATA(("hmuch<%d> ", hmuch));
1793 esp->current_transfer_size = hmuch;
1794 esp_setcount(eregs, (esp->fas_premature_intr_workaround ?
1795 (hmuch + 0x40) : hmuch));
1796 esp->dma_setup(esp, (__u32)((unsigned long)SCptr->SCp.ptr),
1797 hmuch, (thisphase == in_datain));
1798 ESPDATA(("DMA|TI --> do_intr_end\n"));
1799 esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);
1800 return do_intr_end;
1801 /*
1802 * end DMA
1803 */
1804 } else {
1805 /*
1806 * PIO
1807 */
1808 int oldphase, i = 0; /* or where we left off last time ?? esp->current_data ?? */
1809 int fifocnt = 0;
1810 unsigned char *p = phys_to_virt((unsigned long)SCptr->SCp.ptr);
1811
1812 oldphase = esp_read(eregs->esp_status) & ESP_STAT_PMASK;
1813
1814 /*
1815 * polled transfer; ugly, can we make this happen in a DRQ
1816 * interrupt handler ??
1817 * requires keeping track of state information in host or
1818 * command struct!
1819 * Problem: I've never seen a DRQ happen on Mac, not even
1820 * with ESP_CMD_DMA ...
1821 */
1822
1823 /* figure out how much needs to be transferred */
1824 hmuch = SCptr->SCp.this_residual;
1825 ESPDATA(("hmuch<%d> pio ", hmuch));
1826 esp->current_transfer_size = hmuch;
1827
1828 /* tell the ESP ... */
1829 esp_setcount(eregs, hmuch);
1830
1831 /* loop */
1832 while (hmuch) {
1833 int j, fifo_stuck = 0, newphase;
1834 unsigned long timeout;
1835#if 0
1836 unsigned long flags;
1837#endif
1838#if 0
1839 if ( i % 10 )
1840 ESPDATA(("\r"));
1841 else
1842 ESPDATA(( /*"\n"*/ "\r"));
1843#endif
1844#if 0
1845 local_irq_save(flags);
1846#endif
1847 if(thisphase == in_datain) {
1848 /* 'go' ... */
1849 esp_cmd(esp, eregs, ESP_CMD_TI);
1850
1851 /* wait for data */
1852 timeout = 1000000;
1853 while (!((esp->sreg=esp_read(eregs->esp_status)) & ESP_STAT_INTR) && --timeout)
1854 udelay(2);
1855 if (timeout == 0)
1856 printk("DRQ datain timeout! \n");
1857
1858 newphase = esp->sreg & ESP_STAT_PMASK;
1859
1860 /* see how much we got ... */
1861 fifocnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);
1862
1863 if (!fifocnt)
1864 fifo_stuck++;
1865 else
1866 fifo_stuck = 0;
1867
1868 ESPDATA(("\rgot %d st %x ph %x", fifocnt, esp->sreg, newphase));
1869
1870 /* read fifo */
1871 for(j=0;j<fifocnt;j++)
1872 p[i++] = esp_read(eregs->esp_fdata);
1873
1874 ESPDATA(("(%d) ", i));
1875
1876 /* how many to go ?? */
1877 hmuch -= fifocnt;
1878
1879 /* break if status phase !! */
1880 if(newphase == ESP_STATP) {
1881 /* clear int. */
1882 esp->ireg = esp_read(eregs->esp_intrpt);
1883 break;
1884 }
1885 } else {
1886#define MAX_FIFO 8
1887 /* how much will fit ? */
1888 int this_count = MAX_FIFO - fifocnt;
1889 if (this_count > hmuch)
1890 this_count = hmuch;
1891
1892 /* fill fifo */
1893 for(j=0;j<this_count;j++)
1894 esp_write(eregs->esp_fdata, p[i++]);
1895
1896 /* how many left if this goes out ?? */
1897 hmuch -= this_count;
1898
1899 /* 'go' ... */
1900 esp_cmd(esp, eregs, ESP_CMD_TI);
1901
1902 /* wait for 'got it' */
1903 timeout = 1000000;
1904 while (!((esp->sreg=esp_read(eregs->esp_status)) & ESP_STAT_INTR) && --timeout)
1905 udelay(2);
1906 if (timeout == 0)
1907 printk("DRQ dataout timeout! \n");
1908
1909 newphase = esp->sreg & ESP_STAT_PMASK;
1910
1911 /* need to check how much was sent ?? */
1912 fifocnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);
1913
1914 ESPDATA(("\rsent %d st %x ph %x", this_count - fifocnt, esp->sreg, newphase));
1915
1916 ESPDATA(("(%d) ", i));
1917
1918 /* break if status phase !! */
1919 if(newphase == ESP_STATP) {
1920 /* clear int. */
1921 esp->ireg = esp_read(eregs->esp_intrpt);
1922 break;
1923 }
1924
1925 }
1926
1927 /* clear int. */
1928 esp->ireg = esp_read(eregs->esp_intrpt);
1929
1930 ESPDATA(("ir %x ... ", esp->ireg));
1931
1932 if (hmuch == 0)
1933 ESPDATA(("done! \n"));
1934
1935#if 0
1936 local_irq_restore(flags);
1937#endif
1938
1939 /* check new bus phase */
1940 if (newphase != oldphase && i < esp->current_transfer_size) {
1941 /* something happened; disconnect ?? */
1942 ESPDATA(("phase change, dropped out with %d done ... ", i));
1943 break;
1944 }
1945
1946 /* check int. status */
1947 if (esp->ireg & ESP_INTR_DC) {
1948 /* disconnect */
1949 ESPDATA(("disconnect; %d transferred ... ", i));
1950 break;
1951 } else if (esp->ireg & ESP_INTR_FDONE) {
1952 /* function done */
1953 ESPDATA(("function done; %d transferred ... ", i));
1954 break;
1955 }
1956
1957 /* XXX fixme: bail out on stall */
1958 if (fifo_stuck > 10) {
1959 /* we're stuck */
1960 ESPDATA(("fifo stall; %d transferred ... ", i));
1961 break;
1962 }
1963 }
1964
1965 ESPDATA(("\n"));
1966 /* check successful completion ?? */
1967
1968 if (thisphase == in_dataout)
1969 hmuch += fifocnt; /* stuck?? adjust data pointer ...*/
1970
1971 /* tell do_data_finale how much was transferred */
1972 esp->current_transfer_size -= hmuch;
1973
1974 /* still not completely sure on this one ... */
1975 return /*do_intr_end*/ do_work_bus /*do_phase_determine*/ ;
1976
1977 /*
1978 * end PIO
1979 */
1980 }
1981 return do_intr_end;
1982}
1983
1984/* See how successful the data transfer was. */
1985static int esp_do_data_finale(struct NCR_ESP *esp,
1986 struct ESP_regs *eregs)
1987{
1988 Scsi_Cmnd *SCptr = esp->current_SC;
1989 struct esp_device *esp_dev = SCptr->device->hostdata;
1990 int bogus_data = 0, bytes_sent = 0, fifocnt, ecount = 0;
1991
1992 if(esp->dma_led_off)
1993 esp->dma_led_off(esp);
1994
1995 ESPDATA(("esp_do_data_finale: "));
1996
1997 if(SCptr->SCp.phase == in_datain) {
1998 if(esp->sreg & ESP_STAT_PERR) {
1999 /* Yuck, parity error. The ESP asserts ATN
2000 * so that we can go to message out phase
2001 * immediately and inform the target that
2002 * something bad happened.
2003 */
2004 ESPLOG(("esp%d: data bad parity detected.\n",
2005 esp->esp_id));
2006 esp->cur_msgout[0] = INITIATOR_ERROR;
2007 esp->msgout_len = 1;
2008 }
2009 if(esp->dma_drain)
2010 esp->dma_drain(esp);
2011 }
2012 if(esp->dma_invalidate)
2013 esp->dma_invalidate(esp);
2014
2015 /* This could happen for the above parity error case. */
2016 if(!(esp->ireg == ESP_INTR_BSERV)) {
2017 /* Please go to msgout phase, please please please... */
2018 ESPLOG(("esp%d: !BSERV after data, probably to msgout\n",
2019 esp->esp_id));
2020 return esp_do_phase_determine(esp, eregs);
2021 }
2022
2023 /* Check for partial transfers and other horrible events. */
2024 fifocnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);
2025 ecount = esp_getcount(eregs);
2026 if(esp->fas_premature_intr_workaround)
2027 ecount -= 0x40;
2028 bytes_sent = esp->current_transfer_size;
2029
2030 ESPDATA(("trans_sz=%d, ", bytes_sent));
2031 if(!(esp->sreg & ESP_STAT_TCNT))
2032 bytes_sent -= ecount;
2033 if(SCptr->SCp.phase == in_dataout)
2034 bytes_sent -= fifocnt;
2035
2036 ESPDATA(("bytes_sent=%d (ecount=%d, fifocnt=%d), ", bytes_sent,
2037 ecount, fifocnt));
2038
2039 /* If we were in synchronous mode, check for peculiarities. */
2040 if(esp_dev->sync_max_offset)
2041 bogus_data = esp100_sync_hwbug(esp, eregs, SCptr, fifocnt);
2042 else
2043 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
2044
2045 /* Until we are sure of what has happened, we are certainly
2046 * in the dark.
2047 */
2048 esp_advance_phase(SCptr, in_the_dark);
2049
2050 /* Check for premature interrupt condition. Can happen on FAS2x6
2051 * chips. QLogic recommends a workaround by overprogramming the
2052 * transfer counters, but this makes doing scatter-gather impossible.
2053 * Until there is a way to disable scatter-gather for a single target,
2054 * and not only for the entire host adapter as it is now, the workaround
2055 * is way to expensive performance wise.
2056 * Instead, it turns out that when this happens the target has disconnected
2057 * already but it doesn't show in the interrupt register. Compensate for
2058 * that here to try and avoid a SCSI bus reset.
2059 */
2060 if(!esp->fas_premature_intr_workaround && (fifocnt == 1) &&
2061 sreg_dataoutp(esp->sreg)) {
2062 ESPLOG(("esp%d: Premature interrupt, enabling workaround\n",
2063 esp->esp_id));
2064#if 0
2065 /* Disable scatter-gather operations, they are not possible
2066 * when using this workaround.
2067 */
2068 esp->ehost->sg_tablesize = 0;
2069 esp->ehost->use_clustering = ENABLE_CLUSTERING;
2070 esp->fas_premature_intr_workaround = 1;
2071 bytes_sent = 0;
2072 if(SCptr->use_sg) {
2073 ESPLOG(("esp%d: Aborting scatter-gather operation\n",
2074 esp->esp_id));
2075 esp->cur_msgout[0] = ABORT;
2076 esp->msgout_len = 1;
2077 esp->msgout_ctr = 0;
2078 esp_cmd(esp, eregs, ESP_CMD_SATN);
2079 esp_setcount(eregs, 0xffff);
2080 esp_cmd(esp, eregs, ESP_CMD_NULL);
2081 esp_cmd(esp, eregs, ESP_CMD_TPAD | ESP_CMD_DMA);
2082 return do_intr_end;
2083 }
2084#else
2085 /* Just set the disconnected bit. That's what appears to
2086 * happen anyway. The state machine will pick it up when
2087 * we return.
2088 */
2089 esp->ireg |= ESP_INTR_DC;
2090#endif
2091 }
2092
2093 if(bytes_sent < 0) {
2094 /* I've seen this happen due to lost state in this
2095 * driver. No idea why it happened, but allowing
2096 * this value to be negative caused things to
2097 * lock up. This allows greater chance of recovery.
2098 * In fact every time I've seen this, it has been
2099 * a driver bug without question.
2100 */
2101 ESPLOG(("esp%d: yieee, bytes_sent < 0!\n", esp->esp_id));
2102 ESPLOG(("esp%d: csz=%d fifocount=%d ecount=%d\n",
2103 esp->esp_id,
2104 esp->current_transfer_size, fifocnt, ecount));
2105 ESPLOG(("esp%d: use_sg=%d ptr=%p this_residual=%d\n",
2106 esp->esp_id,
2107 SCptr->use_sg, SCptr->SCp.ptr, SCptr->SCp.this_residual));
2108 ESPLOG(("esp%d: Forcing async for target %d\n", esp->esp_id,
2109 SCptr->device->id));
2110 SCptr->device->borken = 1;
2111 esp_dev->sync = 0;
2112 bytes_sent = 0;
2113 }
2114
2115 /* Update the state of our transfer. */
2116 SCptr->SCp.ptr += bytes_sent;
2117 SCptr->SCp.this_residual -= bytes_sent;
2118 if(SCptr->SCp.this_residual < 0) {
2119 /* shit */
2120 ESPLOG(("esp%d: Data transfer overrun.\n", esp->esp_id));
2121 SCptr->SCp.this_residual = 0;
2122 }
2123
2124 /* Maybe continue. */
2125 if(!bogus_data) {
2126 ESPDATA(("!bogus_data, "));
2127 /* NO MATTER WHAT, we advance the scatterlist,
2128 * if the target should decide to disconnect
2129 * in between scatter chunks (which is common)
2130 * we could die horribly! I used to have the sg
2131 * advance occur only if we are going back into
2132 * (or are staying in) a data phase, you can
2133 * imagine the hell I went through trying to
2134 * figure this out.
2135 */
2136 if(!SCptr->SCp.this_residual && SCptr->SCp.buffers_residual)
2137 advance_sg(esp, SCptr);
2138#ifdef DEBUG_ESP_DATA
2139 if(sreg_datainp(esp->sreg) || sreg_dataoutp(esp->sreg)) {
2140 ESPDATA(("to more data\n"));
2141 } else {
2142 ESPDATA(("to new phase\n"));
2143 }
2144#endif
2145 return esp_do_phase_determine(esp, eregs);
2146 }
2147 /* Bogus data, just wait for next interrupt. */
2148 ESPLOG(("esp%d: bogus_data during end of data phase\n",
2149 esp->esp_id));
2150 return do_intr_end;
2151}
2152
2153/* We received a non-good status return at the end of
2154 * running a SCSI command. This is used to decide if
2155 * we should clear our synchronous transfer state for
2156 * such a device when that happens.
2157 *
2158 * The idea is that when spinning up a disk or rewinding
2159 * a tape, we don't want to go into a loop re-negotiating
2160 * synchronous capabilities over and over.
2161 */
2162static int esp_should_clear_sync(Scsi_Cmnd *sp)
2163{
2164 unchar cmd = sp->cmnd[0];
2165
2166 /* These cases are for spinning up a disk and
2167 * waiting for that spinup to complete.
2168 */
2169 if(cmd == START_STOP)
2170 return 0;
2171
2172 if(cmd == TEST_UNIT_READY)
2173 return 0;
2174
2175 /* One more special case for SCSI tape drives,
2176 * this is what is used to probe the device for
2177 * completion of a rewind or tape load operation.
2178 */
2179 if(sp->device->type == TYPE_TAPE && cmd == MODE_SENSE)
2180 return 0;
2181
2182 return 1;
2183}
2184
2185/* Either a command is completing or a target is dropping off the bus
2186 * to continue the command in the background so we can do other work.
2187 */
2188static int esp_do_freebus(struct NCR_ESP *esp, struct ESP_regs *eregs)
2189{
2190 Scsi_Cmnd *SCptr = esp->current_SC;
2191 int rval;
2192
2193 rval = skipahead2(esp, eregs, SCptr, in_status, in_msgindone, in_freeing);
2194 if(rval)
2195 return rval;
2196
2197 if(esp->ireg != ESP_INTR_DC) {
2198 ESPLOG(("esp%d: Target will not disconnect\n", esp->esp_id));
2199 return do_reset_bus; /* target will not drop BSY... */
2200 }
2201 esp->msgout_len = 0;
2202 esp->prevmsgout = NOP;
2203 if(esp->prevmsgin == COMMAND_COMPLETE) {
2204 struct esp_device *esp_dev = SCptr->device->hostdata;
2205 /* Normal end of nexus. */
2206 if(esp->disconnected_SC)
2207 esp_cmd(esp, eregs, ESP_CMD_ESEL);
2208
2209 if(SCptr->SCp.Status != GOOD &&
2210 SCptr->SCp.Status != CONDITION_GOOD &&
2211 ((1<<scmd_id(SCptr)) & esp->targets_present) &&
2212 esp_dev->sync && esp_dev->sync_max_offset) {
2213 /* SCSI standard says that the synchronous capabilities
2214 * should be renegotiated at this point. Most likely
2215 * we are about to request sense from this target
2216 * in which case we want to avoid using sync
2217 * transfers until we are sure of the current target
2218 * state.
2219 */
2220 ESPMISC(("esp: Status <%d> for target %d lun %d\n",
2221 SCptr->SCp.Status, SCptr->device->id, SCptr->device->lun));
2222
2223 /* But don't do this when spinning up a disk at
2224 * boot time while we poll for completion as it
2225 * fills up the console with messages. Also, tapes
2226 * can report not ready many times right after
2227 * loading up a tape.
2228 */
2229 if(esp_should_clear_sync(SCptr) != 0)
2230 esp_dev->sync = 0;
2231 }
2232 ESPDISC(("F<%02x,%02x>", SCptr->device->id, SCptr->device->lun));
2233 esp_done(esp, ((SCptr->SCp.Status & 0xff) |
2234 ((SCptr->SCp.Message & 0xff)<<8) |
2235 (DID_OK << 16)));
2236 } else if(esp->prevmsgin == DISCONNECT) {
2237 /* Normal disconnect. */
2238 esp_cmd(esp, eregs, ESP_CMD_ESEL);
2239 ESPDISC(("D<%02x,%02x>", SCptr->device->id, SCptr->device->lun));
2240 append_SC(&esp->disconnected_SC, SCptr);
2241 esp->current_SC = NULL;
2242 if(esp->issue_SC)
2243 esp_exec_cmd(esp);
2244 } else {
2245 /* Driver bug, we do not expect a disconnect here
2246 * and should not have advanced the state engine
2247 * to in_freeing.
2248 */
2249 ESPLOG(("esp%d: last msg not disc and not cmd cmplt.\n",
2250 esp->esp_id));
2251 return do_reset_bus;
2252 }
2253 return do_intr_end;
2254}
2255
2256/* When a reselect occurs, and we cannot find the command to
2257 * reconnect to in our queues, we do this.
2258 */
2259static int esp_bad_reconnect(struct NCR_ESP *esp)
2260{
2261 Scsi_Cmnd *sp;
2262
2263 ESPLOG(("esp%d: Eieeee, reconnecting unknown command!\n",
2264 esp->esp_id));
2265 ESPLOG(("QUEUE DUMP\n"));
2266 sp = esp->issue_SC;
2267 ESPLOG(("esp%d: issue_SC[", esp->esp_id));
2268 while(sp) {
2269 ESPLOG(("<%02x,%02x>", sp->device->id, sp->device->lun));
2270 sp = (Scsi_Cmnd *) sp->host_scribble;
2271 }
2272 ESPLOG(("]\n"));
2273 sp = esp->current_SC;
2274 ESPLOG(("esp%d: current_SC[", esp->esp_id));
2275 while(sp) {
2276 ESPLOG(("<%02x,%02x>", sp->device->id, sp->device->lun));
2277 sp = (Scsi_Cmnd *) sp->host_scribble;
2278 }
2279 ESPLOG(("]\n"));
2280 sp = esp->disconnected_SC;
2281 ESPLOG(("esp%d: disconnected_SC[", esp->esp_id));
2282 while(sp) {
2283 ESPLOG(("<%02x,%02x>", sp->device->id, sp->device->lun));
2284 sp = (Scsi_Cmnd *) sp->host_scribble;
2285 }
2286 ESPLOG(("]\n"));
2287 return do_reset_bus;
2288}
2289
2290/* Do the needy when a target tries to reconnect to us. */
2291static int esp_do_reconnect(struct NCR_ESP *esp,
2292 struct ESP_regs *eregs)
2293{
2294 int lun, target;
2295 Scsi_Cmnd *SCptr;
2296
2297 /* Check for all bogus conditions first. */
2298 target = reconnect_target(esp, eregs);
2299 if(target < 0) {
2300 ESPDISC(("bad bus bits\n"));
2301 return do_reset_bus;
2302 }
2303 lun = reconnect_lun(esp, eregs);
2304 if(lun < 0) {
2305 ESPDISC(("target=%2x, bad identify msg\n", target));
2306 return do_reset_bus;
2307 }
2308
2309 /* Things look ok... */
2310 ESPDISC(("R<%02x,%02x>", target, lun));
2311
2312 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
2313 if(esp100_reconnect_hwbug(esp, eregs))
2314 return do_reset_bus;
2315 esp_cmd(esp, eregs, ESP_CMD_NULL);
2316
2317 SCptr = remove_SC(&esp->disconnected_SC, (unchar) target, (unchar) lun);
2318 if(!SCptr)
2319 return esp_bad_reconnect(esp);
2320
2321 esp_connect(esp, eregs, SCptr);
2322 esp_cmd(esp, eregs, ESP_CMD_MOK);
2323
2324 /* Reconnect implies a restore pointers operation. */
2325 esp_restore_pointers(esp, SCptr);
2326
2327 esp->snip = 0;
2328 esp_advance_phase(SCptr, in_the_dark);
2329 return do_intr_end;
2330}
2331
2332/* End of NEXUS (hopefully), pick up status + message byte then leave if
2333 * all goes well.
2334 */
2335static int esp_do_status(struct NCR_ESP *esp, struct ESP_regs *eregs)
2336{
2337 Scsi_Cmnd *SCptr = esp->current_SC;
2338 int intr, rval;
2339
2340 rval = skipahead1(esp, eregs, SCptr, in_the_dark, in_status);
2341 if(rval)
2342 return rval;
2343
2344 intr = esp->ireg;
2345 ESPSTAT(("esp_do_status: "));
2346 if(intr != ESP_INTR_DC) {
2347 int message_out = 0; /* for parity problems */
2348
2349 /* Ack the message. */
2350 ESPSTAT(("ack msg, "));
2351 esp_cmd(esp, eregs, ESP_CMD_MOK);
2352
2353 if(esp->dma_poll)
2354 esp->dma_poll(esp, (unsigned char *) esp->esp_command);
2355
2356 ESPSTAT(("got something, "));
2357 /* ESP chimes in with one of
2358 *
2359 * 1) function done interrupt:
2360 * both status and message in bytes
2361 * are available
2362 *
2363 * 2) bus service interrupt:
2364 * only status byte was acquired
2365 *
2366 * 3) Anything else:
2367 * can't happen, but we test for it
2368 * anyways
2369 *
2370 * ALSO: If bad parity was detected on either
2371 * the status _or_ the message byte then
2372 * the ESP has asserted ATN on the bus
2373 * and we must therefore wait for the
2374 * next phase change.
2375 */
2376 if(intr & ESP_INTR_FDONE) {
2377 /* We got it all, hallejulia. */
2378 ESPSTAT(("got both, "));
2379 SCptr->SCp.Status = esp->esp_command[0];
2380 SCptr->SCp.Message = esp->esp_command[1];
2381 esp->prevmsgin = SCptr->SCp.Message;
2382 esp->cur_msgin[0] = SCptr->SCp.Message;
2383 if(esp->sreg & ESP_STAT_PERR) {
2384 /* There was bad parity for the
2385 * message byte, the status byte
2386 * was ok.
2387 */
2388 message_out = MSG_PARITY_ERROR;
2389 }
2390 } else if(intr == ESP_INTR_BSERV) {
2391 /* Only got status byte. */
2392 ESPLOG(("esp%d: got status only, ", esp->esp_id));
2393 if(!(esp->sreg & ESP_STAT_PERR)) {
2394 SCptr->SCp.Status = esp->esp_command[0];
2395 SCptr->SCp.Message = 0xff;
2396 } else {
2397 /* The status byte had bad parity.
2398 * we leave the scsi_pointer Status
2399 * field alone as we set it to a default
2400 * of CHECK_CONDITION in esp_queue.
2401 */
2402 message_out = INITIATOR_ERROR;
2403 }
2404 } else {
2405 /* This shouldn't happen ever. */
2406 ESPSTAT(("got bolixed\n"));
2407 esp_advance_phase(SCptr, in_the_dark);
2408 return esp_do_phase_determine(esp, eregs);
2409 }
2410
2411 if(!message_out) {
2412 ESPSTAT(("status=%2x msg=%2x, ", SCptr->SCp.Status,
2413 SCptr->SCp.Message));
2414 if(SCptr->SCp.Message == COMMAND_COMPLETE) {
2415 ESPSTAT(("and was COMMAND_COMPLETE\n"));
2416 esp_advance_phase(SCptr, in_freeing);
2417 return esp_do_freebus(esp, eregs);
2418 } else {
2419 ESPLOG(("esp%d: and _not_ COMMAND_COMPLETE\n",
2420 esp->esp_id));
2421 esp->msgin_len = esp->msgin_ctr = 1;
2422 esp_advance_phase(SCptr, in_msgindone);
2423 return esp_do_msgindone(esp, eregs);
2424 }
2425 } else {
2426 /* With luck we'll be able to let the target
2427 * know that bad parity happened, it will know
2428 * which byte caused the problems and send it
2429 * again. For the case where the status byte
2430 * receives bad parity, I do not believe most
2431 * targets recover very well. We'll see.
2432 */
2433 ESPLOG(("esp%d: bad parity somewhere mout=%2x\n",
2434 esp->esp_id, message_out));
2435 esp->cur_msgout[0] = message_out;
2436 esp->msgout_len = esp->msgout_ctr = 1;
2437 esp_advance_phase(SCptr, in_the_dark);
2438 return esp_do_phase_determine(esp, eregs);
2439 }
2440 } else {
2441 /* If we disconnect now, all hell breaks loose. */
2442 ESPLOG(("esp%d: whoops, disconnect\n", esp->esp_id));
2443 esp_advance_phase(SCptr, in_the_dark);
2444 return esp_do_phase_determine(esp, eregs);
2445 }
2446}
2447
2448static int esp_enter_status(struct NCR_ESP *esp,
2449 struct ESP_regs *eregs)
2450{
2451 unchar thecmd = ESP_CMD_ICCSEQ;
2452
2453 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
2454
2455 if(esp->do_pio_cmds) {
2456 esp_advance_phase(esp->current_SC, in_status);
2457 esp_cmd(esp, eregs, thecmd);
2458 while(!(esp_read(esp->eregs->esp_status) & ESP_STAT_INTR));
2459 esp->esp_command[0] = esp_read(eregs->esp_fdata);
2460 while(!(esp_read(esp->eregs->esp_status) & ESP_STAT_INTR));
2461 esp->esp_command[1] = esp_read(eregs->esp_fdata);
2462 } else {
2463 esp->esp_command[0] = esp->esp_command[1] = 0xff;
2464 esp_write(eregs->esp_tclow, 2);
2465 esp_write(eregs->esp_tcmed, 0);
2466 esp->dma_init_read(esp, esp->esp_command_dvma, 2);
2467 thecmd |= ESP_CMD_DMA;
2468 esp_cmd(esp, eregs, thecmd);
2469 esp_advance_phase(esp->current_SC, in_status);
2470 }
2471
2472 return esp_do_status(esp, eregs);
2473}
2474
2475static int esp_disconnect_amidst_phases(struct NCR_ESP *esp,
2476 struct ESP_regs *eregs)
2477{
2478 Scsi_Cmnd *sp = esp->current_SC;
2479 struct esp_device *esp_dev = sp->device->hostdata;
2480
2481 /* This means real problems if we see this
2482 * here. Unless we were actually trying
2483 * to force the device to abort/reset.
2484 */
2485 ESPLOG(("esp%d: Disconnect amidst phases, ", esp->esp_id));
2486 ESPLOG(("pphase<%s> cphase<%s>, ",
2487 phase_string(sp->SCp.phase),
2488 phase_string(sp->SCp.sent_command)));
2489
2490 if(esp->disconnected_SC)
2491 esp_cmd(esp, eregs, ESP_CMD_ESEL);
2492
2493 switch(esp->cur_msgout[0]) {
2494 default:
2495 /* We didn't expect this to happen at all. */
2496 ESPLOG(("device is bolixed\n"));
2497 esp_advance_phase(sp, in_tgterror);
2498 esp_done(esp, (DID_ERROR << 16));
2499 break;
2500
2501 case BUS_DEVICE_RESET:
2502 ESPLOG(("device reset successful\n"));
2503 esp_dev->sync_max_offset = 0;
2504 esp_dev->sync_min_period = 0;
2505 esp_dev->sync = 0;
2506 esp_advance_phase(sp, in_resetdev);
2507 esp_done(esp, (DID_RESET << 16));
2508 break;
2509
2510 case ABORT:
2511 ESPLOG(("device abort successful\n"));
2512 esp_advance_phase(sp, in_abortone);
2513 esp_done(esp, (DID_ABORT << 16));
2514 break;
2515
2516 };
2517 return do_intr_end;
2518}
2519
2520static int esp_enter_msgout(struct NCR_ESP *esp,
2521 struct ESP_regs *eregs)
2522{
2523 esp_advance_phase(esp->current_SC, in_msgout);
2524 return esp_do_msgout(esp, eregs);
2525}
2526
2527static int esp_enter_msgin(struct NCR_ESP *esp,
2528 struct ESP_regs *eregs)
2529{
2530 esp_advance_phase(esp->current_SC, in_msgin);
2531 return esp_do_msgin(esp, eregs);
2532}
2533
2534static int esp_enter_cmd(struct NCR_ESP *esp,
2535 struct ESP_regs *eregs)
2536{
2537 esp_advance_phase(esp->current_SC, in_cmdbegin);
2538 return esp_do_cmdbegin(esp, eregs);
2539}
2540
2541static int esp_enter_badphase(struct NCR_ESP *esp,
2542 struct ESP_regs *eregs)
2543{
2544 ESPLOG(("esp%d: Bizarre bus phase %2x.\n", esp->esp_id,
2545 esp->sreg & ESP_STAT_PMASK));
2546 return do_reset_bus;
2547}
2548
2549typedef int (*espfunc_t)(struct NCR_ESP *,
2550 struct ESP_regs *);
2551
2552static espfunc_t phase_vector[] = {
2553 esp_do_data, /* ESP_DOP */
2554 esp_do_data, /* ESP_DIP */
2555 esp_enter_cmd, /* ESP_CMDP */
2556 esp_enter_status, /* ESP_STATP */
2557 esp_enter_badphase, /* ESP_STAT_PMSG */
2558 esp_enter_badphase, /* ESP_STAT_PMSG | ESP_STAT_PIO */
2559 esp_enter_msgout, /* ESP_MOP */
2560 esp_enter_msgin, /* ESP_MIP */
2561};
2562
2563/* The target has control of the bus and we have to see where it has
2564 * taken us.
2565 */
2566static int esp_do_phase_determine(struct NCR_ESP *esp,
2567 struct ESP_regs *eregs)
2568{
2569 if ((esp->ireg & ESP_INTR_DC) != 0)
2570 return esp_disconnect_amidst_phases(esp, eregs);
2571 return phase_vector[esp->sreg & ESP_STAT_PMASK](esp, eregs);
2572}
2573
2574/* First interrupt after exec'ing a cmd comes here. */
2575static int esp_select_complete(struct NCR_ESP *esp, struct ESP_regs *eregs)
2576{
2577 Scsi_Cmnd *SCptr = esp->current_SC;
2578 struct esp_device *esp_dev = SCptr->device->hostdata;
2579 int cmd_bytes_sent, fcnt;
2580
2581 fcnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);
2582 cmd_bytes_sent = esp->dma_bytes_sent(esp, fcnt);
2583 if(esp->dma_invalidate)
2584 esp->dma_invalidate(esp);
2585
2586 /* Let's check to see if a reselect happened
2587 * while we we're trying to select. This must
2588 * be checked first.
2589 */
2590 if(esp->ireg == (ESP_INTR_RSEL | ESP_INTR_FDONE)) {
2591 esp_reconnect(esp, SCptr);
2592 return esp_do_reconnect(esp, eregs);
2593 }
2594
2595 /* Looks like things worked, we should see a bus service &
2596 * a function complete interrupt at this point. Note we
2597 * are doing a direct comparison because we don't want to
2598 * be fooled into thinking selection was successful if
2599 * ESP_INTR_DC is set, see below.
2600 */
2601 if(esp->ireg == (ESP_INTR_FDONE | ESP_INTR_BSERV)) {
2602 /* target speaks... */
2603 esp->targets_present |= (1<<scmd_id(SCptr));
2604
2605 /* What if the target ignores the sdtr? */
2606 if(esp->snip)
2607 esp_dev->sync = 1;
2608
2609 /* See how far, if at all, we got in getting
2610 * the information out to the target.
2611 */
2612 switch(esp->seqreg) {
2613 default:
2614
2615 case ESP_STEP_ASEL:
2616 /* Arbitration won, target selected, but
2617 * we are in some phase which is not command
2618 * phase nor is it message out phase.
2619 *
2620 * XXX We've confused the target, obviously.
2621 * XXX So clear it's state, but we also end
2622 * XXX up clearing everyone elses. That isn't
2623 * XXX so nice. I'd like to just reset this
2624 * XXX target, but if I cannot even get it's
2625 * XXX attention and finish selection to talk
2626 * XXX to it, there is not much more I can do.
2627 * XXX If we have a loaded bus we're going to
2628 * XXX spend the next second or so renegotiating
2629 * XXX for synchronous transfers.
2630 */
2631 ESPLOG(("esp%d: STEP_ASEL for tgt %d\n",
2632 esp->esp_id, SCptr->device->id));
2633
2634 case ESP_STEP_SID:
2635 /* Arbitration won, target selected, went
2636 * to message out phase, sent one message
2637 * byte, then we stopped. ATN is asserted
2638 * on the SCSI bus and the target is still
2639 * there hanging on. This is a legal
2640 * sequence step if we gave the ESP a select
2641 * and stop command.
2642 *
2643 * XXX See above, I could set the borken flag
2644 * XXX in the device struct and retry the
2645 * XXX command. But would that help for
2646 * XXX tagged capable targets?
2647 */
2648
2649 case ESP_STEP_NCMD:
2650 /* Arbitration won, target selected, maybe
2651 * sent the one message byte in message out
2652 * phase, but we did not go to command phase
2653 * in the end. Actually, we could have sent
2654 * only some of the message bytes if we tried
2655 * to send out the entire identify and tag
2656 * message using ESP_CMD_SA3.
2657 */
2658 cmd_bytes_sent = 0;
2659 break;
2660
2661 case ESP_STEP_PPC:
2662 /* No, not the powerPC pinhead. Arbitration
2663 * won, all message bytes sent if we went to
2664 * message out phase, went to command phase
2665 * but only part of the command was sent.
2666 *
2667 * XXX I've seen this, but usually in conjunction
2668 * XXX with a gross error which appears to have
2669 * XXX occurred between the time I told the
2670 * XXX ESP to arbitrate and when I got the
2671 * XXX interrupt. Could I have misloaded the
2672 * XXX command bytes into the fifo? Actually,
2673 * XXX I most likely missed a phase, and therefore
2674 * XXX went into never never land and didn't even
2675 * XXX know it. That was the old driver though.
2676 * XXX What is even more peculiar is that the ESP
2677 * XXX showed the proper function complete and
2678 * XXX bus service bits in the interrupt register.
2679 */
2680
2681 case ESP_STEP_FINI4:
2682 case ESP_STEP_FINI5:
2683 case ESP_STEP_FINI6:
2684 case ESP_STEP_FINI7:
2685 /* Account for the identify message */
2686 if(SCptr->SCp.phase == in_slct_norm)
2687 cmd_bytes_sent -= 1;
2688 };
2689 esp_cmd(esp, eregs, ESP_CMD_NULL);
2690
2691 /* Be careful, we could really get fucked during synchronous
2692 * data transfers if we try to flush the fifo now.
2693 */
2694 if(!fcnt && /* Fifo is empty and... */
2695 /* either we are not doing synchronous transfers or... */
2696 (!esp_dev->sync_max_offset ||
2697 /* We are not going into data in phase. */
2698 ((esp->sreg & ESP_STAT_PMASK) != ESP_DIP)))
2699 esp_cmd(esp, eregs, ESP_CMD_FLUSH); /* flush is safe */
2700
2701 /* See how far we got if this is not a slow command. */
2702 if(!esp->esp_slowcmd) {
2703 if(cmd_bytes_sent < 0)
2704 cmd_bytes_sent = 0;
2705 if(cmd_bytes_sent != SCptr->cmd_len) {
2706 /* Crapola, mark it as a slowcmd
2707 * so that we have some chance of
2708 * keeping the command alive with
2709 * good luck.
2710 *
2711 * XXX Actually, if we didn't send it all
2712 * XXX this means either we didn't set things
2713 * XXX up properly (driver bug) or the target
2714 * XXX or the ESP detected parity on one of
2715 * XXX the command bytes. This makes much
2716 * XXX more sense, and therefore this code
2717 * XXX should be changed to send out a
2718 * XXX parity error message or if the status
2719 * XXX register shows no parity error then
2720 * XXX just expect the target to bring the
2721 * XXX bus into message in phase so that it
2722 * XXX can send us the parity error message.
2723 * XXX SCSI sucks...
2724 */
2725 esp->esp_slowcmd = 1;
2726 esp->esp_scmdp = &(SCptr->cmnd[cmd_bytes_sent]);
2727 esp->esp_scmdleft = (SCptr->cmd_len - cmd_bytes_sent);
2728 }
2729 }
2730
2731 /* Now figure out where we went. */
2732 esp_advance_phase(SCptr, in_the_dark);
2733 return esp_do_phase_determine(esp, eregs);
2734 }
2735
2736 /* Did the target even make it? */
2737 if(esp->ireg == ESP_INTR_DC) {
2738 /* wheee... nobody there or they didn't like
2739 * what we told it to do, clean up.
2740 */
2741
2742 /* If anyone is off the bus, but working on
2743 * a command in the background for us, tell
2744 * the ESP to listen for them.
2745 */
2746 if(esp->disconnected_SC)
2747 esp_cmd(esp, eregs, ESP_CMD_ESEL);
2748
2749 if(((1<<SCptr->device->id) & esp->targets_present) &&
2750 esp->seqreg && esp->cur_msgout[0] == EXTENDED_MESSAGE &&
2751 (SCptr->SCp.phase == in_slct_msg ||
2752 SCptr->SCp.phase == in_slct_stop)) {
2753 /* shit */
2754 esp->snip = 0;
2755 ESPLOG(("esp%d: Failed synchronous negotiation for target %d "
2756 "lun %d\n", esp->esp_id, SCptr->device->id, SCptr->device->lun));
2757 esp_dev->sync_max_offset = 0;
2758 esp_dev->sync_min_period = 0;
2759 esp_dev->sync = 1; /* so we don't negotiate again */
2760
2761 /* Run the command again, this time though we
2762 * won't try to negotiate for synchronous transfers.
2763 *
2764 * XXX I'd like to do something like send an
2765 * XXX INITIATOR_ERROR or ABORT message to the
2766 * XXX target to tell it, "Sorry I confused you,
2767 * XXX please come back and I will be nicer next
2768 * XXX time". But that requires having the target
2769 * XXX on the bus, and it has dropped BSY on us.
2770 */
2771 esp->current_SC = NULL;
2772 esp_advance_phase(SCptr, not_issued);
2773 prepend_SC(&esp->issue_SC, SCptr);
2774 esp_exec_cmd(esp);
2775 return do_intr_end;
2776 }
2777
2778 /* Ok, this is normal, this is what we see during boot
2779 * or whenever when we are scanning the bus for targets.
2780 * But first make sure that is really what is happening.
2781 */
2782 if(((1<<SCptr->device->id) & esp->targets_present)) {
2783 ESPLOG(("esp%d: Warning, live target %d not responding to "
2784 "selection.\n", esp->esp_id, SCptr->device->id));
2785
2786 /* This _CAN_ happen. The SCSI standard states that
2787 * the target is to _not_ respond to selection if
2788 * _it_ detects bad parity on the bus for any reason.
2789 * Therefore, we assume that if we've talked successfully
2790 * to this target before, bad parity is the problem.
2791 */
2792 esp_done(esp, (DID_PARITY << 16));
2793 } else {
2794 /* Else, there really isn't anyone there. */
2795 ESPMISC(("esp: selection failure, maybe nobody there?\n"));
2796 ESPMISC(("esp: target %d lun %d\n",
2797 SCptr->device->id, SCptr->device->lun));
2798 esp_done(esp, (DID_BAD_TARGET << 16));
2799 }
2800 return do_intr_end;
2801 }
2802
2803
2804 ESPLOG(("esp%d: Selection failure.\n", esp->esp_id));
2805 printk("esp%d: Currently -- ", esp->esp_id);
2806 esp_print_ireg(esp->ireg);
2807 printk(" ");
2808 esp_print_statreg(esp->sreg);
2809 printk(" ");
2810 esp_print_seqreg(esp->seqreg);
2811 printk("\n");
2812 printk("esp%d: New -- ", esp->esp_id);
2813 esp->sreg = esp_read(eregs->esp_status);
2814 esp->seqreg = esp_read(eregs->esp_sstep);
2815 esp->ireg = esp_read(eregs->esp_intrpt);
2816 esp_print_ireg(esp->ireg);
2817 printk(" ");
2818 esp_print_statreg(esp->sreg);
2819 printk(" ");
2820 esp_print_seqreg(esp->seqreg);
2821 printk("\n");
2822 ESPLOG(("esp%d: resetting bus\n", esp->esp_id));
2823 return do_reset_bus; /* ugh... */
2824}
2825
2826/* Continue reading bytes for msgin phase. */
2827static int esp_do_msgincont(struct NCR_ESP *esp, struct ESP_regs *eregs)
2828{
2829 if(esp->ireg & ESP_INTR_BSERV) {
2830 /* in the right phase too? */
2831 if((esp->sreg & ESP_STAT_PMASK) == ESP_MIP) {
2832 /* phew... */
2833 esp_cmd(esp, eregs, ESP_CMD_TI);
2834 esp_advance_phase(esp->current_SC, in_msgindone);
2835 return do_intr_end;
2836 }
2837
2838 /* We changed phase but ESP shows bus service,
2839 * in this case it is most likely that we, the
2840 * hacker who has been up for 20hrs straight
2841 * staring at the screen, drowned in coffee
2842 * smelling like retched cigarette ashes
2843 * have miscoded something..... so, try to
2844 * recover as best we can.
2845 */
2846 ESPLOG(("esp%d: message in mis-carriage.\n", esp->esp_id));
2847 }
2848 esp_advance_phase(esp->current_SC, in_the_dark);
2849 return do_phase_determine;
2850}
2851
2852static int check_singlebyte_msg(struct NCR_ESP *esp,
2853 struct ESP_regs *eregs)
2854{
2855 esp->prevmsgin = esp->cur_msgin[0];
2856 if(esp->cur_msgin[0] & 0x80) {
2857 /* wheee... */
2858 ESPLOG(("esp%d: target sends identify amidst phases\n",
2859 esp->esp_id));
2860 esp_advance_phase(esp->current_SC, in_the_dark);
2861 return 0;
2862 } else if(((esp->cur_msgin[0] & 0xf0) == 0x20) ||
2863 (esp->cur_msgin[0] == EXTENDED_MESSAGE)) {
2864 esp->msgin_len = 2;
2865 esp_advance_phase(esp->current_SC, in_msgincont);
2866 return 0;
2867 }
2868 esp_advance_phase(esp->current_SC, in_the_dark);
2869 switch(esp->cur_msgin[0]) {
2870 default:
2871 /* We don't want to hear about it. */
2872 ESPLOG(("esp%d: msg %02x which we don't know about\n", esp->esp_id,
2873 esp->cur_msgin[0]));
2874 return MESSAGE_REJECT;
2875
2876 case NOP:
2877 ESPLOG(("esp%d: target %d sends a nop\n", esp->esp_id,
2878 esp->current_SC->device->id));
2879 return 0;
2880
2881 case RESTORE_POINTERS:
2882 /* In this case we might also have to backup the
2883 * "slow command" pointer. It is rare to get such
2884 * a save/restore pointer sequence so early in the
2885 * bus transition sequences, but cover it.
2886 */
2887 if(esp->esp_slowcmd) {
2888 esp->esp_scmdleft = esp->current_SC->cmd_len;
2889 esp->esp_scmdp = &esp->current_SC->cmnd[0];
2890 }
2891 esp_restore_pointers(esp, esp->current_SC);
2892 return 0;
2893
2894 case SAVE_POINTERS:
2895 esp_save_pointers(esp, esp->current_SC);
2896 return 0;
2897
2898 case COMMAND_COMPLETE:
2899 case DISCONNECT:
2900 /* Freeing the bus, let it go. */
2901 esp->current_SC->SCp.phase = in_freeing;
2902 return 0;
2903
2904 case MESSAGE_REJECT:
2905 ESPMISC(("msg reject, "));
2906 if(esp->prevmsgout == EXTENDED_MESSAGE) {
2907 struct esp_device *esp_dev = esp->current_SC->device->hostdata;
2908
2909 /* Doesn't look like this target can
2910 * do synchronous or WIDE transfers.
2911 */
2912 ESPSDTR(("got reject, was trying nego, clearing sync/WIDE\n"));
2913 esp_dev->sync = 1;
2914 esp_dev->wide = 1;
2915 esp_dev->sync_min_period = 0;
2916 esp_dev->sync_max_offset = 0;
2917 return 0;
2918 } else {
2919 ESPMISC(("not sync nego, sending ABORT\n"));
2920 return ABORT;
2921 }
2922 };
2923}
2924
2925/* Target negotiates for synchronous transfers before we do, this
2926 * is legal although very strange. What is even funnier is that
2927 * the SCSI2 standard specifically recommends against targets doing
2928 * this because so many initiators cannot cope with this occurring.
2929 */
2930static int target_with_ants_in_pants(struct NCR_ESP *esp,
2931 Scsi_Cmnd *SCptr,
2932 struct esp_device *esp_dev)
2933{
2934 if(esp_dev->sync || SCptr->device->borken) {
2935 /* sorry, no can do */
2936 ESPSDTR(("forcing to async, "));
2937 build_sync_nego_msg(esp, 0, 0);
2938 esp_dev->sync = 1;
2939 esp->snip = 1;
2940 ESPLOG(("esp%d: hoping for msgout\n", esp->esp_id));
2941 esp_advance_phase(SCptr, in_the_dark);
2942 return EXTENDED_MESSAGE;
2943 }
2944
2945 /* Ok, we'll check them out... */
2946 return 0;
2947}
2948
2949static void sync_report(struct NCR_ESP *esp)
2950{
2951 int msg3, msg4;
2952 char *type;
2953
2954 msg3 = esp->cur_msgin[3];
2955 msg4 = esp->cur_msgin[4];
2956 if(msg4) {
2957 int hz = 1000000000 / (msg3 * 4);
2958 int integer = hz / 1000000;
2959 int fraction = (hz - (integer * 1000000)) / 10000;
2960 if((msg3 * 4) < 200) {
2961 type = "FAST";
2962 } else {
2963 type = "synchronous";
2964 }
2965
2966 /* Do not transform this back into one big printk
2967 * again, it triggers a bug in our sparc64-gcc272
2968 * sibling call optimization. -DaveM
2969 */
2970 ESPLOG((KERN_INFO "esp%d: target %d ",
2971 esp->esp_id, esp->current_SC->device->id));
2972 ESPLOG(("[period %dns offset %d %d.%02dMHz ",
2973 (int) msg3 * 4, (int) msg4,
2974 integer, fraction));
2975 ESPLOG(("%s SCSI%s]\n", type,
2976 (((msg3 * 4) < 200) ? "-II" : "")));
2977 } else {
2978 ESPLOG((KERN_INFO "esp%d: target %d asynchronous\n",
2979 esp->esp_id, esp->current_SC->device->id));
2980 }
2981}
2982
2983static int check_multibyte_msg(struct NCR_ESP *esp,
2984 struct ESP_regs *eregs)
2985{
2986 Scsi_Cmnd *SCptr = esp->current_SC;
2987 struct esp_device *esp_dev = SCptr->device->hostdata;
2988 unchar regval = 0;
2989 int message_out = 0;
2990
2991 ESPSDTR(("chk multibyte msg: "));
2992 if(esp->cur_msgin[2] == EXTENDED_SDTR) {
2993 int period = esp->cur_msgin[3];
2994 int offset = esp->cur_msgin[4];
2995
2996 ESPSDTR(("is sync nego response, "));
2997 if(!esp->snip) {
2998 int rval;
2999
3000 /* Target negotiates first! */
3001 ESPSDTR(("target jumps the gun, "));
3002 message_out = EXTENDED_MESSAGE; /* we must respond */
3003 rval = target_with_ants_in_pants(esp, SCptr, esp_dev);
3004 if(rval)
3005 return rval;
3006 }
3007
3008 ESPSDTR(("examining sdtr, "));
3009
3010 /* Offset cannot be larger than ESP fifo size. */
3011 if(offset > 15) {
3012 ESPSDTR(("offset too big %2x, ", offset));
3013 offset = 15;
3014 ESPSDTR(("sending back new offset\n"));
3015 build_sync_nego_msg(esp, period, offset);
3016 return EXTENDED_MESSAGE;
3017 }
3018
3019 if(offset && period > esp->max_period) {
3020 /* Yeee, async for this slow device. */
3021 ESPSDTR(("period too long %2x, ", period));
3022 build_sync_nego_msg(esp, 0, 0);
3023 ESPSDTR(("hoping for msgout\n"));
3024 esp_advance_phase(esp->current_SC, in_the_dark);
3025 return EXTENDED_MESSAGE;
3026 } else if (offset && period < esp->min_period) {
3027 ESPSDTR(("period too short %2x, ", period));
3028 period = esp->min_period;
3029 if(esp->erev > esp236)
3030 regval = 4;
3031 else
3032 regval = 5;
3033 } else if(offset) {
3034 int tmp;
3035
3036 ESPSDTR(("period is ok, "));
3037 tmp = esp->ccycle / 1000;
3038 regval = (((period << 2) + tmp - 1) / tmp);
3039 if(regval && (esp->erev > esp236)) {
3040 if(period >= 50)
3041 regval--;
3042 }
3043 }
3044
3045 if(offset) {
3046 unchar bit;
3047
3048 esp_dev->sync_min_period = (regval & 0x1f);
3049 esp_dev->sync_max_offset = (offset | esp->radelay);
3050 if(esp->erev > esp236) {
3051 if(esp->erev == fas100a)
3052 bit = ESP_CONFIG3_FAST;
3053 else
3054 bit = ESP_CONFIG3_FSCSI;
3055 if(period < 50)
3056 esp->config3[SCptr->device->id] |= bit;
3057 else
3058 esp->config3[SCptr->device->id] &= ~bit;
3059 esp->prev_cfg3 = esp->config3[SCptr->device->id];
3060 esp_write(eregs->esp_cfg3, esp->prev_cfg3);
3061 }
3062 esp->prev_soff = esp_dev->sync_min_period;
3063 esp_write(eregs->esp_soff, esp->prev_soff);
3064 esp->prev_stp = esp_dev->sync_max_offset;
3065 esp_write(eregs->esp_stp, esp->prev_stp);
3066
3067 ESPSDTR(("soff=%2x stp=%2x cfg3=%2x\n",
3068 esp_dev->sync_max_offset,
3069 esp_dev->sync_min_period,
3070 esp->config3[scmd_id(SCptr)]));
3071
3072 esp->snip = 0;
3073 } else if(esp_dev->sync_max_offset) {
3074 unchar bit;
3075
3076 /* back to async mode */
3077 ESPSDTR(("unaccaptable sync nego, forcing async\n"));
3078 esp_dev->sync_max_offset = 0;
3079 esp_dev->sync_min_period = 0;
3080 esp->prev_soff = 0;
3081 esp_write(eregs->esp_soff, 0);
3082 esp->prev_stp = 0;
3083 esp_write(eregs->esp_stp, 0);
3084 if(esp->erev > esp236) {
3085 if(esp->erev == fas100a)
3086 bit = ESP_CONFIG3_FAST;
3087 else
3088 bit = ESP_CONFIG3_FSCSI;
3089 esp->config3[SCptr->device->id] &= ~bit;
3090 esp->prev_cfg3 = esp->config3[SCptr->device->id];
3091 esp_write(eregs->esp_cfg3, esp->prev_cfg3);
3092 }
3093 }
3094
3095 sync_report(esp);
3096
3097 ESPSDTR(("chk multibyte msg: sync is known, "));
3098 esp_dev->sync = 1;
3099
3100 if(message_out) {
3101 ESPLOG(("esp%d: sending sdtr back, hoping for msgout\n",
3102 esp->esp_id));
3103 build_sync_nego_msg(esp, period, offset);
3104 esp_advance_phase(SCptr, in_the_dark);
3105 return EXTENDED_MESSAGE;
3106 }
3107
3108 ESPSDTR(("returning zero\n"));
3109 esp_advance_phase(SCptr, in_the_dark); /* ...or else! */
3110 return 0;
3111 } else if(esp->cur_msgin[2] == EXTENDED_WDTR) {
3112 ESPLOG(("esp%d: AIEEE wide msg received\n", esp->esp_id));
3113 message_out = MESSAGE_REJECT;
3114 } else if(esp->cur_msgin[2] == EXTENDED_MODIFY_DATA_POINTER) {
3115 ESPLOG(("esp%d: rejecting modify data ptr msg\n", esp->esp_id));
3116 message_out = MESSAGE_REJECT;
3117 }
3118 esp_advance_phase(SCptr, in_the_dark);
3119 return message_out;
3120}
3121
3122static int esp_do_msgindone(struct NCR_ESP *esp, struct ESP_regs *eregs)
3123{
3124 Scsi_Cmnd *SCptr = esp->current_SC;
3125 int message_out = 0, it = 0, rval;
3126
3127 rval = skipahead1(esp, eregs, SCptr, in_msgin, in_msgindone);
3128 if(rval)
3129 return rval;
3130 if(SCptr->SCp.sent_command != in_status) {
3131 if(!(esp->ireg & ESP_INTR_DC)) {
3132 if(esp->msgin_len && (esp->sreg & ESP_STAT_PERR)) {
3133 message_out = MSG_PARITY_ERROR;
3134 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
3135 } else if((it = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES))!=1) {
3136 /* We certainly dropped the ball somewhere. */
3137 message_out = INITIATOR_ERROR;
3138 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
3139 } else if(!esp->msgin_len) {
3140 it = esp_read(eregs->esp_fdata);
3141 esp_advance_phase(SCptr, in_msgincont);
3142 } else {
3143 /* it is ok and we want it */
3144 it = esp->cur_msgin[esp->msgin_ctr] =
3145 esp_read(eregs->esp_fdata);
3146 esp->msgin_ctr++;
3147 }
3148 } else {
3149 esp_advance_phase(SCptr, in_the_dark);
3150 return do_work_bus;
3151 }
3152 } else {
3153 it = esp->cur_msgin[0];
3154 }
3155 if(!message_out && esp->msgin_len) {
3156 if(esp->msgin_ctr < esp->msgin_len) {
3157 esp_advance_phase(SCptr, in_msgincont);
3158 } else if(esp->msgin_len == 1) {
3159 message_out = check_singlebyte_msg(esp, eregs);
3160 } else if(esp->msgin_len == 2) {
3161 if(esp->cur_msgin[0] == EXTENDED_MESSAGE) {
3162 if((it+2) >= 15) {
3163 message_out = MESSAGE_REJECT;
3164 } else {
3165 esp->msgin_len = (it + 2);
3166 esp_advance_phase(SCptr, in_msgincont);
3167 }
3168 } else {
3169 message_out = MESSAGE_REJECT; /* foo on you */
3170 }
3171 } else {
3172 message_out = check_multibyte_msg(esp, eregs);
3173 }
3174 }
3175 if(message_out < 0) {
3176 return -message_out;
3177 } else if(message_out) {
3178 if(((message_out != 1) &&
3179 ((message_out < 0x20) || (message_out & 0x80))))
3180 esp->msgout_len = 1;
3181 esp->cur_msgout[0] = message_out;
3182 esp_cmd(esp, eregs, ESP_CMD_SATN);
3183 esp_advance_phase(SCptr, in_the_dark);
3184 esp->msgin_len = 0;
3185 }
3186 esp->sreg = esp_read(eregs->esp_status);
3187 esp->sreg &= ~(ESP_STAT_INTR);
3188 if((esp->sreg & (ESP_STAT_PMSG|ESP_STAT_PCD)) == (ESP_STAT_PMSG|ESP_STAT_PCD))
3189 esp_cmd(esp, eregs, ESP_CMD_MOK);
3190 if((SCptr->SCp.sent_command == in_msgindone) &&
3191 (SCptr->SCp.phase == in_freeing))
3192 return esp_do_freebus(esp, eregs);
3193 return do_intr_end;
3194}
3195
3196static int esp_do_cmdbegin(struct NCR_ESP *esp, struct ESP_regs *eregs)
3197{
3198 unsigned char tmp;
3199 Scsi_Cmnd *SCptr = esp->current_SC;
3200
3201 esp_advance_phase(SCptr, in_cmdend);
3202 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
3203 tmp = *esp->esp_scmdp++;
3204 esp->esp_scmdleft--;
3205 esp_write(eregs->esp_fdata, tmp);
3206 esp_cmd(esp, eregs, ESP_CMD_TI);
3207 return do_intr_end;
3208}
3209
3210static int esp_do_cmddone(struct NCR_ESP *esp, struct ESP_regs *eregs)
3211{
3212 esp_cmd(esp, eregs, ESP_CMD_NULL);
3213 if(esp->ireg & ESP_INTR_BSERV) {
3214 esp_advance_phase(esp->current_SC, in_the_dark);
3215 return esp_do_phase_determine(esp, eregs);
3216 }
3217 ESPLOG(("esp%d: in do_cmddone() but didn't get BSERV interrupt.\n",
3218 esp->esp_id));
3219 return do_reset_bus;
3220}
3221
3222static int esp_do_msgout(struct NCR_ESP *esp, struct ESP_regs *eregs)
3223{
3224 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
3225 switch(esp->msgout_len) {
3226 case 1:
3227 esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
3228 esp_cmd(esp, eregs, ESP_CMD_TI);
3229 break;
3230
3231 case 2:
3232 if(esp->do_pio_cmds){
3233 esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
3234 esp_write(eregs->esp_fdata, esp->cur_msgout[1]);
3235 esp_cmd(esp, eregs, ESP_CMD_TI);
3236 } else {
3237 esp->esp_command[0] = esp->cur_msgout[0];
3238 esp->esp_command[1] = esp->cur_msgout[1];
3239 esp->dma_setup(esp, esp->esp_command_dvma, 2, 0);
3240 esp_setcount(eregs, 2);
3241 esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);
3242 }
3243 break;
3244
3245 case 4:
3246 esp->snip = 1;
3247 if(esp->do_pio_cmds){
3248 esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
3249 esp_write(eregs->esp_fdata, esp->cur_msgout[1]);
3250 esp_write(eregs->esp_fdata, esp->cur_msgout[2]);
3251 esp_write(eregs->esp_fdata, esp->cur_msgout[3]);
3252 esp_cmd(esp, eregs, ESP_CMD_TI);
3253 } else {
3254 esp->esp_command[0] = esp->cur_msgout[0];
3255 esp->esp_command[1] = esp->cur_msgout[1];
3256 esp->esp_command[2] = esp->cur_msgout[2];
3257 esp->esp_command[3] = esp->cur_msgout[3];
3258 esp->dma_setup(esp, esp->esp_command_dvma, 4, 0);
3259 esp_setcount(eregs, 4);
3260 esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);
3261 }
3262 break;
3263
3264 case 5:
3265 esp->snip = 1;
3266 if(esp->do_pio_cmds){
3267 esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
3268 esp_write(eregs->esp_fdata, esp->cur_msgout[1]);
3269 esp_write(eregs->esp_fdata, esp->cur_msgout[2]);
3270 esp_write(eregs->esp_fdata, esp->cur_msgout[3]);
3271 esp_write(eregs->esp_fdata, esp->cur_msgout[4]);
3272 esp_cmd(esp, eregs, ESP_CMD_TI);
3273 } else {
3274 esp->esp_command[0] = esp->cur_msgout[0];
3275 esp->esp_command[1] = esp->cur_msgout[1];
3276 esp->esp_command[2] = esp->cur_msgout[2];
3277 esp->esp_command[3] = esp->cur_msgout[3];
3278 esp->esp_command[4] = esp->cur_msgout[4];
3279 esp->dma_setup(esp, esp->esp_command_dvma, 5, 0);
3280 esp_setcount(eregs, 5);
3281 esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);
3282 }
3283 break;
3284
3285 default:
3286 /* whoops */
3287 ESPMISC(("bogus msgout sending NOP\n"));
3288 esp->cur_msgout[0] = NOP;
3289 esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
3290 esp->msgout_len = 1;
3291 esp_cmd(esp, eregs, ESP_CMD_TI);
3292 break;
3293 }
3294 esp_advance_phase(esp->current_SC, in_msgoutdone);
3295 return do_intr_end;
3296}
3297
3298static int esp_do_msgoutdone(struct NCR_ESP *esp,
3299 struct ESP_regs *eregs)
3300{
3301 if((esp->msgout_len > 1) && esp->dma_barrier)
3302 esp->dma_barrier(esp);
3303
3304 if(!(esp->ireg & ESP_INTR_DC)) {
3305 esp_cmd(esp, eregs, ESP_CMD_NULL);
3306 switch(esp->sreg & ESP_STAT_PMASK) {
3307 case ESP_MOP:
3308 /* whoops, parity error */
3309 ESPLOG(("esp%d: still in msgout, parity error assumed\n",
3310 esp->esp_id));
3311 if(esp->msgout_len > 1)
3312 esp_cmd(esp, eregs, ESP_CMD_SATN);
3313 esp_advance_phase(esp->current_SC, in_msgout);
3314 return do_work_bus;
3315
3316 case ESP_DIP:
3317 break;
3318
3319 default:
3320 if(!fcount(esp, eregs) &&
3321 !(((struct esp_device *)esp->current_SC->device->hostdata)->sync_max_offset))
3322 esp_cmd(esp, eregs, ESP_CMD_FLUSH);
3323 break;
3324
3325 };
3326 }
3327
3328 /* If we sent out a synchronous negotiation message, update
3329 * our state.
3330 */
3331 if(esp->cur_msgout[2] == EXTENDED_MESSAGE &&
3332 esp->cur_msgout[4] == EXTENDED_SDTR) {
3333 esp->snip = 1; /* anal retentiveness... */
3334 }
3335
3336 esp->prevmsgout = esp->cur_msgout[0];
3337 esp->msgout_len = 0;
3338 esp_advance_phase(esp->current_SC, in_the_dark);
3339 return esp_do_phase_determine(esp, eregs);
3340}
3341
3342static int esp_bus_unexpected(struct NCR_ESP *esp, struct ESP_regs *eregs)
3343{
3344 ESPLOG(("esp%d: command in weird state %2x\n",
3345 esp->esp_id, esp->current_SC->SCp.phase));
3346 return do_reset_bus;
3347}
3348
3349static espfunc_t bus_vector[] = {
3350 esp_do_data_finale,
3351 esp_do_data_finale,
3352 esp_bus_unexpected,
3353 esp_do_msgin,
3354 esp_do_msgincont,
3355 esp_do_msgindone,
3356 esp_do_msgout,
3357 esp_do_msgoutdone,
3358 esp_do_cmdbegin,
3359 esp_do_cmddone,
3360 esp_do_status,
3361 esp_do_freebus,
3362 esp_do_phase_determine,
3363 esp_bus_unexpected,
3364 esp_bus_unexpected,
3365 esp_bus_unexpected,
3366};
3367
3368/* This is the second tier in our dual-level SCSI state machine. */
3369static int esp_work_bus(struct NCR_ESP *esp, struct ESP_regs *eregs)
3370{
3371 Scsi_Cmnd *SCptr = esp->current_SC;
3372 unsigned int phase;
3373
3374 ESPBUS(("esp_work_bus: "));
3375 if(!SCptr) {
3376 ESPBUS(("reconnect\n"));
3377 return esp_do_reconnect(esp, eregs);
3378 }
3379 phase = SCptr->SCp.phase;
3380 if ((phase & 0xf0) == in_phases_mask)
3381 return bus_vector[(phase & 0x0f)](esp, eregs);
3382 else if((phase & 0xf0) == in_slct_mask)
3383 return esp_select_complete(esp, eregs);
3384 else
3385 return esp_bus_unexpected(esp, eregs);
3386}
3387
3388static espfunc_t isvc_vector[] = {
3389 NULL,
3390 esp_do_phase_determine,
3391 esp_do_resetbus,
3392 esp_finish_reset,
3393 esp_work_bus
3394};
3395
3396/* Main interrupt handler for an esp adapter. */
3397void esp_handle(struct NCR_ESP *esp)
3398{
3399 struct ESP_regs *eregs;
3400 Scsi_Cmnd *SCptr;
3401 int what_next = do_intr_end;
3402 eregs = esp->eregs;
3403 SCptr = esp->current_SC;
3404
3405 if(esp->dma_irq_entry)
3406 esp->dma_irq_entry(esp);
3407
3408 /* Check for errors. */
3409 esp->sreg = esp_read(eregs->esp_status);
3410 esp->sreg &= (~ESP_STAT_INTR);
3411 esp->seqreg = (esp_read(eregs->esp_sstep) & ESP_STEP_VBITS);
3412 esp->ireg = esp_read(eregs->esp_intrpt); /* Unlatch intr and stat regs */
3413 ESPIRQ(("handle_irq: [sreg<%02x> sstep<%02x> ireg<%02x>]\n",
3414 esp->sreg, esp->seqreg, esp->ireg));
3415 if(esp->sreg & (ESP_STAT_SPAM)) {
3416 /* Gross error, could be due to one of:
3417 *
3418 * - top of fifo overwritten, could be because
3419 * we tried to do a synchronous transfer with
3420 * an offset greater than ESP fifo size
3421 *
3422 * - top of command register overwritten
3423 *
3424 * - DMA setup to go in one direction, SCSI
3425 * bus points in the other, whoops
3426 *
3427 * - weird phase change during asynchronous
3428 * data phase while we are initiator
3429 */
3430 ESPLOG(("esp%d: Gross error sreg=%2x\n", esp->esp_id, esp->sreg));
3431
3432 /* If a command is live on the bus we cannot safely
3433 * reset the bus, so we'll just let the pieces fall
3434 * where they may. Here we are hoping that the
3435 * target will be able to cleanly go away soon
3436 * so we can safely reset things.
3437 */
3438 if(!SCptr) {
3439 ESPLOG(("esp%d: No current cmd during gross error, "
3440 "resetting bus\n", esp->esp_id));
3441 what_next = do_reset_bus;
3442 goto state_machine;
3443 }
3444 }
3445
3446 /* No current cmd is only valid at this point when there are
3447 * commands off the bus or we are trying a reset.
3448 */
3449 if(!SCptr && !esp->disconnected_SC && !(esp->ireg & ESP_INTR_SR)) {
3450 /* Panic is safe, since current_SC is null. */
3451 ESPLOG(("esp%d: no command in esp_handle()\n", esp->esp_id));
3452 panic("esp_handle: current_SC == penguin within interrupt!");
3453 }
3454
3455 if(esp->ireg & (ESP_INTR_IC)) {
3456 /* Illegal command fed to ESP. Outside of obvious
3457 * software bugs that could cause this, there is
3458 * a condition with ESP100 where we can confuse the
3459 * ESP into an erroneous illegal command interrupt
3460 * because it does not scrape the FIFO properly
3461 * for reselection. See esp100_reconnect_hwbug()
3462 * to see how we try very hard to avoid this.
3463 */
3464 ESPLOG(("esp%d: invalid command\n", esp->esp_id));
3465
3466 esp_dump_state(esp, eregs);
3467
3468 if(SCptr) {
3469 /* Devices with very buggy firmware can drop BSY
3470 * during a scatter list interrupt when using sync
3471 * mode transfers. We continue the transfer as
3472 * expected, the target drops the bus, the ESP
3473 * gets confused, and we get a illegal command
3474 * interrupt because the bus is in the disconnected
3475 * state now and ESP_CMD_TI is only allowed when
3476 * a nexus is alive on the bus.
3477 */
3478 ESPLOG(("esp%d: Forcing async and disabling disconnect for "
3479 "target %d\n", esp->esp_id, SCptr->device->id));
3480 SCptr->device->borken = 1; /* foo on you */
3481 }
3482
3483 what_next = do_reset_bus;
3484 } else if(!(esp->ireg & ~(ESP_INTR_FDONE | ESP_INTR_BSERV | ESP_INTR_DC))) {
3485 int phase;
3486
3487 if(SCptr) {
3488 phase = SCptr->SCp.phase;
3489 if(phase & in_phases_mask) {
3490 what_next = esp_work_bus(esp, eregs);
3491 } else if(phase & in_slct_mask) {
3492 what_next = esp_select_complete(esp, eregs);
3493 } else {
3494 ESPLOG(("esp%d: interrupt for no good reason...\n",
3495 esp->esp_id));
3496 what_next = do_intr_end;
3497 }
3498 } else {
3499 ESPLOG(("esp%d: BSERV or FDONE or DC while SCptr==NULL\n",
3500 esp->esp_id));
3501 what_next = do_reset_bus;
3502 }
3503 } else if(esp->ireg & ESP_INTR_SR) {
3504 ESPLOG(("esp%d: SCSI bus reset interrupt\n", esp->esp_id));
3505 what_next = do_reset_complete;
3506 } else if(esp->ireg & (ESP_INTR_S | ESP_INTR_SATN)) {
3507 ESPLOG(("esp%d: AIEEE we have been selected by another initiator!\n",
3508 esp->esp_id));
3509 what_next = do_reset_bus;
3510 } else if(esp->ireg & ESP_INTR_RSEL) {
3511 if(!SCptr) {
3512 /* This is ok. */
3513 what_next = esp_do_reconnect(esp, eregs);
3514 } else if(SCptr->SCp.phase & in_slct_mask) {
3515 /* Only selection code knows how to clean
3516 * up properly.
3517 */
3518 ESPDISC(("Reselected during selection attempt\n"));
3519 what_next = esp_select_complete(esp, eregs);
3520 } else {
3521 ESPLOG(("esp%d: Reselected while bus is busy\n",
3522 esp->esp_id));
3523 what_next = do_reset_bus;
3524 }
3525 }
3526
3527 /* This is tier-one in our dual level SCSI state machine. */
3528state_machine:
3529 while(what_next != do_intr_end) {
3530 if (what_next >= do_phase_determine &&
3531 what_next < do_intr_end)
3532 what_next = isvc_vector[what_next](esp, eregs);
3533 else {
3534 /* state is completely lost ;-( */
3535 ESPLOG(("esp%d: interrupt engine loses state, resetting bus\n",
3536 esp->esp_id));
3537 what_next = do_reset_bus;
3538 }
3539 }
3540 if(esp->dma_irq_exit)
3541 esp->dma_irq_exit(esp);
3542}
3543EXPORT_SYMBOL(esp_handle);
3544
3545#ifndef CONFIG_SMP
3546irqreturn_t esp_intr(int irq, void *dev_id)
3547{
3548 struct NCR_ESP *esp;
3549 unsigned long flags;
3550 int again;
3551 struct Scsi_Host *dev = dev_id;
3552
3553 /* Handle all ESP interrupts showing at this IRQ level. */
3554 spin_lock_irqsave(dev->host_lock, flags);
3555repeat:
3556 again = 0;
3557 for_each_esp(esp) {
3558#ifndef __mips__
3559 if(((esp)->irq & 0xff) == irq) {
3560#endif
3561 if(esp->dma_irq_p(esp)) {
3562 again = 1;
3563
3564 esp->dma_ints_off(esp);
3565
3566 ESPIRQ(("I%d(", esp->esp_id));
3567 esp_handle(esp);
3568 ESPIRQ((")"));
3569
3570 esp->dma_ints_on(esp);
3571 }
3572#ifndef __mips__
3573 }
3574#endif
3575 }
3576 if(again)
3577 goto repeat;
3578 spin_unlock_irqrestore(dev->host_lock, flags);
3579 return IRQ_HANDLED;
3580}
3581#else
3582/* For SMP we only service one ESP on the list list at our IRQ level! */
3583irqreturn_t esp_intr(int irq, void *dev_id)
3584{
3585 struct NCR_ESP *esp;
3586 unsigned long flags;
3587 struct Scsi_Host *dev = dev_id;
3588
3589 /* Handle all ESP interrupts showing at this IRQ level. */
3590 spin_lock_irqsave(dev->host_lock, flags);
3591 for_each_esp(esp) {
3592 if(((esp)->irq & 0xf) == irq) {
3593 if(esp->dma_irq_p(esp)) {
3594 esp->dma_ints_off(esp);
3595
3596 ESPIRQ(("I[%d:%d](",
3597 smp_processor_id(), esp->esp_id));
3598 esp_handle(esp);
3599 ESPIRQ((")"));
3600
3601 esp->dma_ints_on(esp);
3602 goto out;
3603 }
3604 }
3605 }
3606out:
3607 spin_unlock_irqrestore(dev->host_lock, flags);
3608 return IRQ_HANDLED;
3609}
3610#endif
3611
3612int esp_slave_alloc(struct scsi_device *SDptr)
3613{
3614 struct esp_device *esp_dev =
3615 kzalloc(sizeof(struct esp_device), GFP_ATOMIC);
3616
3617 if (!esp_dev)
3618 return -ENOMEM;
3619 SDptr->hostdata = esp_dev;
3620 return 0;
3621}
3622
3623void esp_slave_destroy(struct scsi_device *SDptr)
3624{
3625 struct NCR_ESP *esp = (struct NCR_ESP *) SDptr->host->hostdata;
3626
3627 esp->targets_present &= ~(1 << sdev_id(SDptr));
3628 kfree(SDptr->hostdata);
3629 SDptr->hostdata = NULL;
3630}
3631
3632#ifdef MODULE
3633int init_module(void) { return 0; }
3634void cleanup_module(void) {}
3635void esp_release(void)
3636{
3637 esps_in_use--;
3638 esps_running = esps_in_use;
3639}
3640EXPORT_SYMBOL(esp_release);
3641#endif
3642
3643EXPORT_SYMBOL(esp_abort);
3644EXPORT_SYMBOL(esp_allocate);
3645EXPORT_SYMBOL(esp_deallocate);
3646EXPORT_SYMBOL(esp_initialize);
3647EXPORT_SYMBOL(esp_intr);
3648EXPORT_SYMBOL(esp_queue);
3649EXPORT_SYMBOL(esp_reset);
3650EXPORT_SYMBOL(esp_slave_alloc);
3651EXPORT_SYMBOL(esp_slave_destroy);
3652EXPORT_SYMBOL(esps_in_use);
3653
3654MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/NCR53C9x.h b/drivers/scsi/NCR53C9x.h
deleted file mode 100644
index 00a0ba040dba..000000000000
--- a/drivers/scsi/NCR53C9x.h
+++ /dev/null
@@ -1,668 +0,0 @@
1/* NCR53C9x.c: Defines and structures for the NCR53C9x generic driver.
2 *
3 * Originally esp.h: Defines and structures for the Sparc ESP
4 * (Enhanced SCSI Processor) driver under Linux.
5 *
6 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7 *
8 * Generalization by Jesper Skov (jskov@cygnus.co.uk)
9 *
10 * More generalization (for i386 stuff) by Tymm Twillman (tymm@computer.org)
11 */
12
13#ifndef NCR53C9X_H
14#define NCR53C9X_H
15
16#include <linux/interrupt.h>
17
18/* djweis for mac driver */
19#if defined(CONFIG_MAC)
20#define PAD_SIZE 15
21#else
22#define PAD_SIZE 3
23#endif
24
25/* Handle multiple hostadapters on Amiga
26 * generally PAD_SIZE = 3
27 * but there is one exception: Oktagon (PAD_SIZE = 1) */
28#if defined(CONFIG_OKTAGON_SCSI) || defined(CONFIG_OKTAGON_SCSI_MODULE)
29#undef PAD_SIZE
30#if defined(CONFIG_BLZ1230_SCSI) || defined(CONFIG_BLZ1230_SCSI_MODULE) || \
31 defined(CONFIG_BLZ2060_SCSI) || defined(CONFIG_BLZ2060_SCSI_MODULE) || \
32 defined(CONFIG_CYBERSTORM_SCSI) || defined(CONFIG_CYBERSTORM_SCSI_MODULE) || \
33 defined(CONFIG_CYBERSTORMII_SCSI) || defined(CONFIG_CYBERSTORMII_SCSI_MODULE) || \
34 defined(CONFIG_FASTLANE_SCSI) || defined(CONFIG_FASTLANE_SCSI_MODULE)
35#define MULTIPLE_PAD_SIZES
36#else
37#define PAD_SIZE 1
38#endif
39#endif
40
41/* Macros for debugging messages */
42
43#define DEBUG_ESP
44/* #define DEBUG_ESP_DATA */
45/* #define DEBUG_ESP_QUEUE */
46/* #define DEBUG_ESP_DISCONNECT */
47/* #define DEBUG_ESP_STATUS */
48/* #define DEBUG_ESP_PHASES */
49/* #define DEBUG_ESP_WORKBUS */
50/* #define DEBUG_STATE_MACHINE */
51/* #define DEBUG_ESP_CMDS */
52/* #define DEBUG_ESP_IRQS */
53/* #define DEBUG_SDTR */
54/* #define DEBUG_ESP_SG */
55
56/* Use the following to sprinkle debugging messages in a way which
57 * suits you if combinations of the above become too verbose when
58 * trying to track down a specific problem.
59 */
60/* #define DEBUG_ESP_MISC */
61
62#if defined(DEBUG_ESP)
63#define ESPLOG(foo) printk foo
64#else
65#define ESPLOG(foo)
66#endif /* (DEBUG_ESP) */
67
68#if defined(DEBUG_ESP_DATA)
69#define ESPDATA(foo) printk foo
70#else
71#define ESPDATA(foo)
72#endif
73
74#if defined(DEBUG_ESP_QUEUE)
75#define ESPQUEUE(foo) printk foo
76#else
77#define ESPQUEUE(foo)
78#endif
79
80#if defined(DEBUG_ESP_DISCONNECT)
81#define ESPDISC(foo) printk foo
82#else
83#define ESPDISC(foo)
84#endif
85
86#if defined(DEBUG_ESP_STATUS)
87#define ESPSTAT(foo) printk foo
88#else
89#define ESPSTAT(foo)
90#endif
91
92#if defined(DEBUG_ESP_PHASES)
93#define ESPPHASE(foo) printk foo
94#else
95#define ESPPHASE(foo)
96#endif
97
98#if defined(DEBUG_ESP_WORKBUS)
99#define ESPBUS(foo) printk foo
100#else
101#define ESPBUS(foo)
102#endif
103
104#if defined(DEBUG_ESP_IRQS)
105#define ESPIRQ(foo) printk foo
106#else
107#define ESPIRQ(foo)
108#endif
109
110#if defined(DEBUG_SDTR)
111#define ESPSDTR(foo) printk foo
112#else
113#define ESPSDTR(foo)
114#endif
115
116#if defined(DEBUG_ESP_MISC)
117#define ESPMISC(foo) printk foo
118#else
119#define ESPMISC(foo)
120#endif
121
122/*
123 * padding for register structure
124 */
125#ifdef CONFIG_JAZZ_ESP
126#define EREGS_PAD(n)
127#else
128#ifndef MULTIPLE_PAD_SIZES
129#define EREGS_PAD(n) unchar n[PAD_SIZE];
130#endif
131#endif
132
133/* The ESP SCSI controllers have their register sets in three
134 * "classes":
135 *
136 * 1) Registers which are both read and write.
137 * 2) Registers which are read only.
138 * 3) Registers which are write only.
139 *
140 * Yet, they all live within the same IO space.
141 */
142
143#if !defined(__i386__) && !defined(__x86_64__)
144
145#ifndef MULTIPLE_PAD_SIZES
146
147#ifdef CONFIG_CPU_HAS_WB
148#include <asm/wbflush.h>
149#define esp_write(__reg, __val) do{(__reg) = (__val); wbflush();} while(0)
150#else
151#define esp_write(__reg, __val) ((__reg) = (__val))
152#endif
153#define esp_read(__reg) (__reg)
154
155struct ESP_regs {
156 /* Access Description Offset */
157 volatile unchar esp_tclow; /* rw Low bits of the transfer count 0x00 */
158 EREGS_PAD(tlpad1);
159 volatile unchar esp_tcmed; /* rw Mid bits of the transfer count 0x04 */
160 EREGS_PAD(fdpad);
161 volatile unchar esp_fdata; /* rw FIFO data bits 0x08 */
162 EREGS_PAD(cbpad);
163 volatile unchar esp_cmnd; /* rw SCSI command bits 0x0c */
164 EREGS_PAD(stpad);
165 volatile unchar esp_status; /* ro ESP status register 0x10 */
166#define esp_busid esp_status /* wo Bus ID for select/reselect 0x10 */
167 EREGS_PAD(irqpd);
168 volatile unchar esp_intrpt; /* ro Kind of interrupt 0x14 */
169#define esp_timeo esp_intrpt /* wo Timeout value for select/resel 0x14 */
170 EREGS_PAD(sspad);
171 volatile unchar esp_sstep; /* ro Sequence step register 0x18 */
172#define esp_stp esp_sstep /* wo Transfer period per sync 0x18 */
173 EREGS_PAD(ffpad);
174 volatile unchar esp_fflags; /* ro Bits of current FIFO info 0x1c */
175#define esp_soff esp_fflags /* wo Sync offset 0x1c */
176 EREGS_PAD(cf1pd);
177 volatile unchar esp_cfg1; /* rw First configuration register 0x20 */
178 EREGS_PAD(cfpad);
179 volatile unchar esp_cfact; /* wo Clock conversion factor 0x24 */
180 EREGS_PAD(ctpad);
181 volatile unchar esp_ctest; /* wo Chip test register 0x28 */
182 EREGS_PAD(cf2pd);
183 volatile unchar esp_cfg2; /* rw Second configuration register 0x2c */
184 EREGS_PAD(cf3pd);
185
186 /* The following is only found on the 53C9X series SCSI chips */
187 volatile unchar esp_cfg3; /* rw Third configuration register 0x30 */
188 EREGS_PAD(cf4pd);
189 volatile unchar esp_cfg4; /* rw Fourth configuration register 0x34 */
190 EREGS_PAD(thpd);
191 /* The following is found on all chips except the NCR53C90 (ESP100) */
192 volatile unchar esp_tchi; /* rw High bits of transfer count 0x38 */
193#define esp_uid esp_tchi /* ro Unique ID code 0x38 */
194 EREGS_PAD(fgpad);
195 volatile unchar esp_fgrnd; /* rw Data base for fifo 0x3c */
196};
197
198#else /* MULTIPLE_PAD_SIZES */
199
200#define esp_write(__reg, __val) (*(__reg) = (__val))
201#define esp_read(__reg) (*(__reg))
202
203struct ESP_regs {
204 unsigned char io_addr[64]; /* dummy */
205 /* Access Description Offset */
206#define esp_tclow io_addr /* rw Low bits of the transfer count 0x00 */
207#define esp_tcmed io_addr + (1<<(esp->shift)) /* rw Mid bits of the transfer count 0x04 */
208#define esp_fdata io_addr + (2<<(esp->shift)) /* rw FIFO data bits 0x08 */
209#define esp_cmnd io_addr + (3<<(esp->shift)) /* rw SCSI command bits 0x0c */
210#define esp_status io_addr + (4<<(esp->shift)) /* ro ESP status register 0x10 */
211#define esp_busid esp_status /* wo Bus ID for select/reselect 0x10 */
212#define esp_intrpt io_addr + (5<<(esp->shift)) /* ro Kind of interrupt 0x14 */
213#define esp_timeo esp_intrpt /* wo Timeout value for select/resel 0x14 */
214#define esp_sstep io_addr + (6<<(esp->shift)) /* ro Sequence step register 0x18 */
215#define esp_stp esp_sstep /* wo Transfer period per sync 0x18 */
216#define esp_fflags io_addr + (7<<(esp->shift)) /* ro Bits of current FIFO info 0x1c */
217#define esp_soff esp_fflags /* wo Sync offset 0x1c */
218#define esp_cfg1 io_addr + (8<<(esp->shift)) /* rw First configuration register 0x20 */
219#define esp_cfact io_addr + (9<<(esp->shift)) /* wo Clock conversion factor 0x24 */
220#define esp_ctest io_addr + (10<<(esp->shift)) /* wo Chip test register 0x28 */
221#define esp_cfg2 io_addr + (11<<(esp->shift)) /* rw Second configuration register 0x2c */
222
223 /* The following is only found on the 53C9X series SCSI chips */
224#define esp_cfg3 io_addr + (12<<(esp->shift)) /* rw Third configuration register 0x30 */
225#define esp_cfg4 io_addr + (13<<(esp->shift)) /* rw Fourth configuration register 0x34 */
226
227 /* The following is found on all chips except the NCR53C90 (ESP100) */
228#define esp_tchi io_addr + (14<<(esp->shift)) /* rw High bits of transfer count 0x38 */
229#define esp_uid esp_tchi /* ro Unique ID code 0x38 */
230#define esp_fgrnd io_addr + (15<<(esp->shift)) /* rw Data base for fifo 0x3c */
231};
232
233#endif
234
235#else /* !defined(__i386__) && !defined(__x86_64__) */
236
237#define esp_write(__reg, __val) outb((__val), (__reg))
238#define esp_read(__reg) inb((__reg))
239
240struct ESP_regs {
241 unsigned int io_addr;
242 /* Access Description Offset */
243#define esp_tclow io_addr /* rw Low bits of the transfer count 0x00 */
244#define esp_tcmed io_addr + 1 /* rw Mid bits of the transfer count 0x04 */
245#define esp_fdata io_addr + 2 /* rw FIFO data bits 0x08 */
246#define esp_cmnd io_addr + 3 /* rw SCSI command bits 0x0c */
247#define esp_status io_addr + 4 /* ro ESP status register 0x10 */
248#define esp_busid esp_status /* wo Bus ID for select/reselect 0x10 */
249#define esp_intrpt io_addr + 5 /* ro Kind of interrupt 0x14 */
250#define esp_timeo esp_intrpt /* wo Timeout value for select/resel 0x14 */
251#define esp_sstep io_addr + 6 /* ro Sequence step register 0x18 */
252#define esp_stp esp_sstep /* wo Transfer period per sync 0x18 */
253#define esp_fflags io_addr + 7 /* ro Bits of current FIFO info 0x1c */
254#define esp_soff esp_fflags /* wo Sync offset 0x1c */
255#define esp_cfg1 io_addr + 8 /* rw First configuration register 0x20 */
256#define esp_cfact io_addr + 9 /* wo Clock conversion factor 0x24 */
257#define esp_ctest io_addr + 10 /* wo Chip test register 0x28 */
258#define esp_cfg2 io_addr + 11 /* rw Second configuration register 0x2c */
259
260 /* The following is only found on the 53C9X series SCSI chips */
261#define esp_cfg3 io_addr + 12 /* rw Third configuration register 0x30 */
262#define esp_cfg4 io_addr + 13 /* rw Fourth configuration register 0x34 */
263
264 /* The following is found on all chips except the NCR53C90 (ESP100) */
265#define esp_tchi io_addr + 14 /* rw High bits of transfer count 0x38 */
266#define esp_uid esp_tchi /* ro Unique ID code 0x38 */
267#define esp_fgrnd io_addr + 15 /* rw Data base for fifo 0x3c */
268};
269
270#endif /* !defined(__i386__) && !defined(__x86_64__) */
271
272/* Various revisions of the ESP board. */
273enum esp_rev {
274 esp100 = 0x00, /* NCR53C90 - very broken */
275 esp100a = 0x01, /* NCR53C90A */
276 esp236 = 0x02,
277 fas236 = 0x03,
278 fas100a = 0x04,
279 fast = 0x05,
280 fas366 = 0x06,
281 fas216 = 0x07,
282 fsc = 0x08, /* SYM53C94-2 */
283 espunknown = 0x09
284};
285
286/* We allocate one of these for each scsi device and attach it to
287 * SDptr->hostdata for use in the driver
288 */
289struct esp_device {
290 unsigned char sync_min_period;
291 unsigned char sync_max_offset;
292 unsigned sync:1;
293 unsigned wide:1;
294 unsigned disconnect:1;
295};
296
297/* We get one of these for each ESP probed. */
298struct NCR_ESP {
299 struct NCR_ESP *next; /* Next ESP on probed or NULL */
300 struct ESP_regs *eregs; /* All esp registers */
301 int dma; /* Who I do transfers with. */
302 void *dregs; /* And his registers. */
303 struct Scsi_Host *ehost; /* Backpointer to SCSI Host */
304
305 void *edev; /* Pointer to controller base/SBus */
306 int esp_id; /* Unique per-ESP ID number */
307
308 /* ESP Configuration Registers */
309 unsigned char config1; /* Copy of the 1st config register */
310 unsigned char config2; /* Copy of the 2nd config register */
311 unsigned char config3[16]; /* Copy of the 3rd config register */
312
313 /* The current command we are sending to the ESP chip. This esp_command
314 * ptr needs to be mapped in DVMA area so we can send commands and read
315 * from the ESP fifo without burning precious CPU cycles. Programmed I/O
316 * sucks when we have the DVMA to do it for us. The ESP is stupid and will
317 * only send out 6, 10, and 12 byte SCSI commands, others we need to send
318 * one byte at a time. esp_slowcmd being set says that we are doing one
319 * of the command types ESP doesn't understand, esp_scmdp keeps track of
320 * which byte we are sending, esp_scmdleft says how many bytes to go.
321 */
322 volatile unchar *esp_command; /* Location of command (CPU view) */
323 __u32 esp_command_dvma; /* Location of command (DVMA view) */
324 unsigned char esp_clen; /* Length of this command */
325 unsigned char esp_slowcmd;
326 unsigned char *esp_scmdp;
327 unsigned char esp_scmdleft;
328
329 /* The following are used to determine the cause of an IRQ. Upon every
330 * IRQ entry we synchronize these with the hardware registers.
331 */
332 unchar ireg; /* Copy of ESP interrupt register */
333 unchar sreg; /* Same for ESP status register */
334 unchar seqreg; /* The ESP sequence register */
335
336 /* The following is set when a premature interrupt condition is detected
337 * in some FAS revisions.
338 */
339 unchar fas_premature_intr_workaround;
340
341 /* To save register writes to the ESP, which can be expensive, we
342 * keep track of the previous value that various registers had for
343 * the last target we connected to. If they are the same for the
344 * current target, we skip the register writes as they are not needed.
345 */
346 unchar prev_soff, prev_stp, prev_cfg3;
347
348 /* For each target we keep track of save/restore data
349 * pointer information. This needs to be updated majorly
350 * when we add support for tagged queueing. -DaveM
351 */
352 struct esp_pointers {
353 char *saved_ptr;
354 struct scatterlist *saved_buffer;
355 int saved_this_residual;
356 int saved_buffers_residual;
357 } data_pointers[16] /*XXX [MAX_TAGS_PER_TARGET]*/;
358
359 /* Clock periods, frequencies, synchronization, etc. */
360 unsigned int cfreq; /* Clock frequency in HZ */
361 unsigned int cfact; /* Clock conversion factor */
362 unsigned int ccycle; /* One ESP clock cycle */
363 unsigned int ctick; /* One ESP clock time */
364 unsigned int radelay; /* FAST chip req/ack delay */
365 unsigned int neg_defp; /* Default negotiation period */
366 unsigned int sync_defp; /* Default sync transfer period */
367 unsigned int max_period; /* longest our period can be */
368 unsigned int min_period; /* shortest period we can withstand */
369 /* For slow to medium speed input clock rates we shoot for 5mb/s,
370 * but for high input clock rates we try to do 10mb/s although I
371 * don't think a transfer can even run that fast with an ESP even
372 * with DMA2 scatter gather pipelining.
373 */
374#define SYNC_DEFP_SLOW 0x32 /* 5mb/s */
375#define SYNC_DEFP_FAST 0x19 /* 10mb/s */
376
377 unsigned int snip; /* Sync. negotiation in progress */
378 unsigned int wnip; /* WIDE negotiation in progress */
379 unsigned int targets_present; /* targets spoken to before */
380
381 int current_transfer_size; /* Set at beginning of data dma */
382
383 unchar espcmdlog[32]; /* Log of current esp cmds sent. */
384 unchar espcmdent; /* Current entry in esp cmd log. */
385
386 /* Misc. info about this ESP */
387 enum esp_rev erev; /* ESP revision */
388 int irq; /* IRQ for this ESP */
389 int scsi_id; /* Who am I as initiator? */
390 int scsi_id_mask; /* Bitmask of 'me'. */
391 int diff; /* Differential SCSI bus? */
392 int slot; /* Slot the adapter occupies */
393
394 /* Our command queues, only one cmd lives in the current_SC queue. */
395 Scsi_Cmnd *issue_SC; /* Commands to be issued */
396 Scsi_Cmnd *current_SC; /* Who is currently working the bus */
397 Scsi_Cmnd *disconnected_SC; /* Commands disconnected from the bus */
398
399 /* Message goo */
400 unchar cur_msgout[16];
401 unchar cur_msgin[16];
402 unchar prevmsgout, prevmsgin;
403 unchar msgout_len, msgin_len;
404 unchar msgout_ctr, msgin_ctr;
405
406 /* States that we cannot keep in the per cmd structure because they
407 * cannot be assosciated with any specific command.
408 */
409 unchar resetting_bus;
410 wait_queue_head_t reset_queue;
411
412 unchar do_pio_cmds; /* Do command transfer with pio */
413
414 /* How much bits do we have to shift the registers */
415 unsigned char shift;
416
417 /* Functions handling DMA
418 */
419 /* Required functions */
420 int (*dma_bytes_sent)(struct NCR_ESP *, int);
421 int (*dma_can_transfer)(struct NCR_ESP *, Scsi_Cmnd *);
422 void (*dma_dump_state)(struct NCR_ESP *);
423 void (*dma_init_read)(struct NCR_ESP *, __u32, int);
424 void (*dma_init_write)(struct NCR_ESP *, __u32, int);
425 void (*dma_ints_off)(struct NCR_ESP *);
426 void (*dma_ints_on)(struct NCR_ESP *);
427 int (*dma_irq_p)(struct NCR_ESP *);
428 int (*dma_ports_p)(struct NCR_ESP *);
429 void (*dma_setup)(struct NCR_ESP *, __u32, int, int);
430
431 /* Optional functions (i.e. may be initialized to 0) */
432 void (*dma_barrier)(struct NCR_ESP *);
433 void (*dma_drain)(struct NCR_ESP *);
434 void (*dma_invalidate)(struct NCR_ESP *);
435 void (*dma_irq_entry)(struct NCR_ESP *);
436 void (*dma_irq_exit)(struct NCR_ESP *);
437 void (*dma_led_off)(struct NCR_ESP *);
438 void (*dma_led_on)(struct NCR_ESP *);
439 void (*dma_poll)(struct NCR_ESP *, unsigned char *);
440 void (*dma_reset)(struct NCR_ESP *);
441
442 /* Optional virtual DMA functions */
443 void (*dma_mmu_get_scsi_one)(struct NCR_ESP *, Scsi_Cmnd *);
444 void (*dma_mmu_get_scsi_sgl)(struct NCR_ESP *, Scsi_Cmnd *);
445 void (*dma_mmu_release_scsi_one)(struct NCR_ESP *, Scsi_Cmnd *);
446 void (*dma_mmu_release_scsi_sgl)(struct NCR_ESP *, Scsi_Cmnd *);
447 void (*dma_advance_sg)(Scsi_Cmnd *);
448};
449
450/* Bitfield meanings for the above registers. */
451
452/* ESP config reg 1, read-write, found on all ESP chips */
453#define ESP_CONFIG1_ID 0x07 /* My BUS ID bits */
454#define ESP_CONFIG1_CHTEST 0x08 /* Enable ESP chip tests */
455#define ESP_CONFIG1_PENABLE 0x10 /* Enable parity checks */
456#define ESP_CONFIG1_PARTEST 0x20 /* Parity test mode enabled? */
457#define ESP_CONFIG1_SRRDISAB 0x40 /* Disable SCSI reset reports */
458#define ESP_CONFIG1_SLCABLE 0x80 /* Enable slow cable mode */
459
460/* ESP config reg 2, read-write, found only on esp100a+esp200+esp236+fsc chips */
461#define ESP_CONFIG2_DMAPARITY 0x01 /* enable DMA Parity (200,236,fsc) */
462#define ESP_CONFIG2_REGPARITY 0x02 /* enable reg Parity (200,236,fsc) */
463#define ESP_CONFIG2_BADPARITY 0x04 /* Bad parity target abort */
464#define ESP_CONFIG2_SCSI2ENAB 0x08 /* Enable SCSI-2 features (tmode only) */
465#define ESP_CONFIG2_HI 0x10 /* High Impedance DREQ ??? */
466#define ESP_CONFIG2_HMEFENAB 0x10 /* HME features enable */
467#define ESP_CONFIG2_BCM 0x20 /* Enable byte-ctrl (236,fsc) */
468#define ESP_CONFIG2_FENAB 0x40 /* Enable features (fas100,esp216,fsc) */
469#define ESP_CONFIG2_SPL 0x40 /* Enable status-phase latch (esp236) */
470#define ESP_CONFIG2_RFB 0x80 /* Reserve FIFO byte (fsc) */
471#define ESP_CONFIG2_MAGIC 0xe0 /* Invalid bits... */
472
473/* ESP config register 3 read-write, found only esp236+fas236+fas100a+fsc chips */
474#define ESP_CONFIG3_FCLOCK 0x01 /* FAST SCSI clock rate (esp100a/fas366) */
475#define ESP_CONFIG3_TEM 0x01 /* Enable thresh-8 mode (esp/fas236/fsc) */
476#define ESP_CONFIG3_FAST 0x02 /* Enable FAST SCSI (esp100a) */
477#define ESP_CONFIG3_ADMA 0x02 /* Enable alternate-dma (esp/fas236/fsc) */
478#define ESP_CONFIG3_TENB 0x04 /* group2 SCSI2 support (esp100a) */
479#define ESP_CONFIG3_SRB 0x04 /* Save residual byte (esp/fas236/fsc) */
480#define ESP_CONFIG3_TMS 0x08 /* Three-byte msg's ok (esp100a) */
481#define ESP_CONFIG3_FCLK 0x08 /* Fast SCSI clock rate (esp/fas236/fsc) */
482#define ESP_CONFIG3_IDMSG 0x10 /* ID message checking (esp100a) */
483#define ESP_CONFIG3_FSCSI 0x10 /* Enable FAST SCSI (esp/fas236/fsc) */
484#define ESP_CONFIG3_GTM 0x20 /* group2 SCSI2 support (esp/fas236/fsc) */
485#define ESP_CONFIG3_TBMS 0x40 /* Three-byte msg's ok (esp/fas236/fsc) */
486#define ESP_CONFIG3_IMS 0x80 /* ID msg chk'ng (esp/fas236/fsc) */
487
488/* ESP config register 4 read-write, found only on fsc chips */
489#define ESP_CONFIG4_BBTE 0x01 /* Back-to-Back transfer enable */
490#define ESP_CONFIG4_TEST 0x02 /* Transfer counter test mode */
491#define ESP_CONFIG4_EAN 0x04 /* Enable Active Negotiation */
492
493/* ESP command register read-write */
494/* Group 1 commands: These may be sent at any point in time to the ESP
495 * chip. None of them can generate interrupts 'cept
496 * the "SCSI bus reset" command if you have not disabled
497 * SCSI reset interrupts in the config1 ESP register.
498 */
499#define ESP_CMD_NULL 0x00 /* Null command, ie. a nop */
500#define ESP_CMD_FLUSH 0x01 /* FIFO Flush */
501#define ESP_CMD_RC 0x02 /* Chip reset */
502#define ESP_CMD_RS 0x03 /* SCSI bus reset */
503
504/* Group 2 commands: ESP must be an initiator and connected to a target
505 * for these commands to work.
506 */
507#define ESP_CMD_TI 0x10 /* Transfer Information */
508#define ESP_CMD_ICCSEQ 0x11 /* Initiator cmd complete sequence */
509#define ESP_CMD_MOK 0x12 /* Message okie-dokie */
510#define ESP_CMD_TPAD 0x18 /* Transfer Pad */
511#define ESP_CMD_SATN 0x1a /* Set ATN */
512#define ESP_CMD_RATN 0x1b /* De-assert ATN */
513
514/* Group 3 commands: ESP must be in the MSGOUT or MSGIN state and be connected
515 * to a target as the initiator for these commands to work.
516 */
517#define ESP_CMD_SMSG 0x20 /* Send message */
518#define ESP_CMD_SSTAT 0x21 /* Send status */
519#define ESP_CMD_SDATA 0x22 /* Send data */
520#define ESP_CMD_DSEQ 0x23 /* Discontinue Sequence */
521#define ESP_CMD_TSEQ 0x24 /* Terminate Sequence */
522#define ESP_CMD_TCCSEQ 0x25 /* Target cmd cmplt sequence */
523#define ESP_CMD_DCNCT 0x27 /* Disconnect */
524#define ESP_CMD_RMSG 0x28 /* Receive Message */
525#define ESP_CMD_RCMD 0x29 /* Receive Command */
526#define ESP_CMD_RDATA 0x2a /* Receive Data */
527#define ESP_CMD_RCSEQ 0x2b /* Receive cmd sequence */
528
529/* Group 4 commands: The ESP must be in the disconnected state and must
530 * not be connected to any targets as initiator for
531 * these commands to work.
532 */
533#define ESP_CMD_RSEL 0x40 /* Reselect */
534#define ESP_CMD_SEL 0x41 /* Select w/o ATN */
535#define ESP_CMD_SELA 0x42 /* Select w/ATN */
536#define ESP_CMD_SELAS 0x43 /* Select w/ATN & STOP */
537#define ESP_CMD_ESEL 0x44 /* Enable selection */
538#define ESP_CMD_DSEL 0x45 /* Disable selections */
539#define ESP_CMD_SA3 0x46 /* Select w/ATN3 */
540#define ESP_CMD_RSEL3 0x47 /* Reselect3 */
541
542/* This bit enables the ESP's DMA */
543#define ESP_CMD_DMA 0x80 /* Do DMA? */
544
545/* ESP status register read-only */
546#define ESP_STAT_PIO 0x01 /* IO phase bit */
547#define ESP_STAT_PCD 0x02 /* CD phase bit */
548#define ESP_STAT_PMSG 0x04 /* MSG phase bit */
549#define ESP_STAT_PMASK 0x07 /* Mask of phase bits */
550#define ESP_STAT_TDONE 0x08 /* Transfer Completed */
551#define ESP_STAT_TCNT 0x10 /* Transfer Counter Is Zero */
552#define ESP_STAT_PERR 0x20 /* Parity error */
553#define ESP_STAT_SPAM 0x40 /* Real bad error */
554/* This indicates the 'interrupt pending' condition, it is a reserved
555 * bit on old revs of the ESP (ESP100, ESP100A, FAS100A).
556 */
557#define ESP_STAT_INTR 0x80 /* Interrupt */
558
559/* The status register can be masked with ESP_STAT_PMASK and compared
560 * with the following values to determine the current phase the ESP
561 * (at least thinks it) is in. For our purposes we also add our own
562 * software 'done' bit for our phase management engine.
563 */
564#define ESP_DOP (0) /* Data Out */
565#define ESP_DIP (ESP_STAT_PIO) /* Data In */
566#define ESP_CMDP (ESP_STAT_PCD) /* Command */
567#define ESP_STATP (ESP_STAT_PCD|ESP_STAT_PIO) /* Status */
568#define ESP_MOP (ESP_STAT_PMSG|ESP_STAT_PCD) /* Message Out */
569#define ESP_MIP (ESP_STAT_PMSG|ESP_STAT_PCD|ESP_STAT_PIO) /* Message In */
570
571/* ESP interrupt register read-only */
572#define ESP_INTR_S 0x01 /* Select w/o ATN */
573#define ESP_INTR_SATN 0x02 /* Select w/ATN */
574#define ESP_INTR_RSEL 0x04 /* Reselected */
575#define ESP_INTR_FDONE 0x08 /* Function done */
576#define ESP_INTR_BSERV 0x10 /* Bus service */
577#define ESP_INTR_DC 0x20 /* Disconnect */
578#define ESP_INTR_IC 0x40 /* Illegal command given */
579#define ESP_INTR_SR 0x80 /* SCSI bus reset detected */
580
581/* Interrupt status macros */
582#define ESP_SRESET_IRQ(esp) ((esp)->intreg & (ESP_INTR_SR))
583#define ESP_ILLCMD_IRQ(esp) ((esp)->intreg & (ESP_INTR_IC))
584#define ESP_SELECT_WITH_ATN_IRQ(esp) ((esp)->intreg & (ESP_INTR_SATN))
585#define ESP_SELECT_WITHOUT_ATN_IRQ(esp) ((esp)->intreg & (ESP_INTR_S))
586#define ESP_SELECTION_IRQ(esp) ((ESP_SELECT_WITH_ATN_IRQ(esp)) || \
587 (ESP_SELECT_WITHOUT_ATN_IRQ(esp)))
588#define ESP_RESELECTION_IRQ(esp) ((esp)->intreg & (ESP_INTR_RSEL))
589
590/* ESP sequence step register read-only */
591#define ESP_STEP_VBITS 0x07 /* Valid bits */
592#define ESP_STEP_ASEL 0x00 /* Selection&Arbitrate cmplt */
593#define ESP_STEP_SID 0x01 /* One msg byte sent */
594#define ESP_STEP_NCMD 0x02 /* Was not in command phase */
595#define ESP_STEP_PPC 0x03 /* Early phase chg caused cmnd
596 * bytes to be lost
597 */
598#define ESP_STEP_FINI4 0x04 /* Command was sent ok */
599
600/* Ho hum, some ESP's set the step register to this as well... */
601#define ESP_STEP_FINI5 0x05
602#define ESP_STEP_FINI6 0x06
603#define ESP_STEP_FINI7 0x07
604#define ESP_STEP_SOM 0x08 /* Synchronous Offset Max */
605
606/* ESP chip-test register read-write */
607#define ESP_TEST_TARG 0x01 /* Target test mode */
608#define ESP_TEST_INI 0x02 /* Initiator test mode */
609#define ESP_TEST_TS 0x04 /* Tristate test mode */
610
611/* ESP unique ID register read-only, found on fas236+fas100a+fsc only */
612#define ESP_UID_F100A 0x00 /* FAS100A */
613#define ESP_UID_F236 0x02 /* FAS236 */
614#define ESP_UID_FSC 0xa2 /* NCR53CF9x-2 */
615#define ESP_UID_REV 0x07 /* ESP revision */
616#define ESP_UID_FAM 0xf8 /* ESP family */
617
618/* ESP fifo flags register read-only */
619/* Note that the following implies a 16 byte FIFO on the ESP. */
620#define ESP_FF_FBYTES 0x1f /* Num bytes in FIFO */
621#define ESP_FF_ONOTZERO 0x20 /* offset ctr not zero (esp100,fsc) */
622#define ESP_FF_SSTEP 0xe0 /* Sequence step */
623
624/* ESP clock conversion factor register write-only */
625#define ESP_CCF_F0 0x00 /* 35.01MHz - 40MHz */
626#define ESP_CCF_NEVER 0x01 /* Set it to this and die */
627#define ESP_CCF_F2 0x02 /* 10MHz */
628#define ESP_CCF_F3 0x03 /* 10.01MHz - 15MHz */
629#define ESP_CCF_F4 0x04 /* 15.01MHz - 20MHz */
630#define ESP_CCF_F5 0x05 /* 20.01MHz - 25MHz */
631#define ESP_CCF_F6 0x06 /* 25.01MHz - 30MHz */
632#define ESP_CCF_F7 0x07 /* 30.01MHz - 35MHz */
633
634#define ESP_BUS_TIMEOUT 275 /* In milli-seconds */
635#define ESP_TIMEO_CONST 8192
636#define FSC_TIMEO_CONST 7668
637#define ESP_NEG_DEFP(mhz, cfact) \
638 ((ESP_BUS_TIMEOUT * ((mhz) / 1000)) / (8192 * (cfact)))
639#define FSC_NEG_DEFP(mhz, cfact) \
640 ((ESP_BUS_TIMEOUT * ((mhz) / 1000)) / (7668 * (cfact)))
641#define ESP_MHZ_TO_CYCLE(mhertz) ((1000000000) / ((mhertz) / 1000))
642#define ESP_TICK(ccf, cycle) ((7682 * (ccf) * (cycle) / 1000))
643
644
645/* UGLY, UGLY, UGLY! */
646extern int nesps, esps_in_use, esps_running;
647
648/* For our interrupt engine. */
649#define for_each_esp(esp) \
650 for((esp) = espchain; (esp); (esp) = (esp)->next)
651
652
653/* External functions */
654extern void esp_bootup_reset(struct NCR_ESP *esp, struct ESP_regs *eregs);
655extern struct NCR_ESP *esp_allocate(struct scsi_host_template *, void *, int);
656extern void esp_deallocate(struct NCR_ESP *);
657extern void esp_release(void);
658extern void esp_initialize(struct NCR_ESP *);
659extern irqreturn_t esp_intr(int, void *);
660extern const char *esp_info(struct Scsi_Host *);
661extern int esp_queue(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
662extern int esp_abort(Scsi_Cmnd *);
663extern int esp_reset(Scsi_Cmnd *);
664extern int esp_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t offset, int length,
665 int inout);
666extern int esp_slave_alloc(struct scsi_device *);
667extern void esp_slave_destroy(struct scsi_device *);
668#endif /* !(NCR53C9X_H) */
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index d7235f42cf5f..bfd0e64964ac 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -859,44 +859,31 @@ static int setinqserial(struct aac_dev *dev, void *data, int cid)
859 le32_to_cpu(dev->adapter_info.serial[0]), cid); 859 le32_to_cpu(dev->adapter_info.serial[0]), cid);
860} 860}
861 861
862static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code, 862static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
863 u8 a_sense_code, u8 incorrect_length, 863 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
864 u8 bit_pointer, u16 field_pointer,
865 u32 residue)
866{ 864{
867 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */ 865 u8 *sense_buf = (u8 *)sense_data;
866 /* Sense data valid, err code 70h */
867 sense_buf[0] = 0x70; /* No info field */
868 sense_buf[1] = 0; /* Segment number, always zero */ 868 sense_buf[1] = 0; /* Segment number, always zero */
869 869
870 if (incorrect_length) { 870 sense_buf[2] = sense_key; /* Sense key */
871 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
872 sense_buf[3] = BYTE3(residue);
873 sense_buf[4] = BYTE2(residue);
874 sense_buf[5] = BYTE1(residue);
875 sense_buf[6] = BYTE0(residue);
876 } else
877 sense_buf[2] = sense_key; /* Sense key */
878
879 if (sense_key == ILLEGAL_REQUEST)
880 sense_buf[7] = 10; /* Additional sense length */
881 else
882 sense_buf[7] = 6; /* Additional sense length */
883 871
884 sense_buf[12] = sense_code; /* Additional sense code */ 872 sense_buf[12] = sense_code; /* Additional sense code */
885 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */ 873 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
874
886 if (sense_key == ILLEGAL_REQUEST) { 875 if (sense_key == ILLEGAL_REQUEST) {
887 sense_buf[15] = 0; 876 sense_buf[7] = 10; /* Additional sense length */
888 877
889 if (sense_code == SENCODE_INVALID_PARAM_FIELD) 878 sense_buf[15] = bit_pointer;
890 sense_buf[15] = 0x80;/* Std sense key specific field */
891 /* Illegal parameter is in the parameter block */ 879 /* Illegal parameter is in the parameter block */
892
893 if (sense_code == SENCODE_INVALID_CDB_FIELD) 880 if (sense_code == SENCODE_INVALID_CDB_FIELD)
894 sense_buf[15] = 0xc0;/* Std sense key specific field */ 881 sense_buf[15] |= 0xc0;/* Std sense key specific field */
895 /* Illegal parameter is in the CDB block */ 882 /* Illegal parameter is in the CDB block */
896 sense_buf[15] |= bit_pointer;
897 sense_buf[16] = field_pointer >> 8; /* MSB */ 883 sense_buf[16] = field_pointer >> 8; /* MSB */
898 sense_buf[17] = field_pointer; /* LSB */ 884 sense_buf[17] = field_pointer; /* LSB */
899 } 885 } else
886 sense_buf[7] = 6; /* Additional sense length */
900} 887}
901 888
902static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba) 889static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
@@ -906,11 +893,9 @@ static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
906 dprintk((KERN_DEBUG "aacraid: Illegal lba\n")); 893 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
907 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | 894 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
908 SAM_STAT_CHECK_CONDITION; 895 SAM_STAT_CHECK_CONDITION;
909 set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 896 set_sense(&dev->fsa_dev[cid].sense_data,
910 HARDWARE_ERROR, 897 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
911 SENCODE_INTERNAL_TARGET_FAILURE, 898 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
912 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
913 0, 0);
914 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 899 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
915 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 900 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
916 SCSI_SENSE_BUFFERSIZE)); 901 SCSI_SENSE_BUFFERSIZE));
@@ -1520,11 +1505,9 @@ static void io_callback(void *context, struct fib * fibptr)
1520 le32_to_cpu(readreply->status)); 1505 le32_to_cpu(readreply->status));
1521#endif 1506#endif
1522 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1507 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1523 set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 1508 set_sense(&dev->fsa_dev[cid].sense_data,
1524 HARDWARE_ERROR, 1509 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1525 SENCODE_INTERNAL_TARGET_FAILURE, 1510 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1526 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1527 0, 0);
1528 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1511 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1529 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1512 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1530 SCSI_SENSE_BUFFERSIZE)); 1513 SCSI_SENSE_BUFFERSIZE));
@@ -1733,11 +1716,9 @@ static void synchronize_callback(void *context, struct fib *fibptr)
1733 le32_to_cpu(synchronizereply->status)); 1716 le32_to_cpu(synchronizereply->status));
1734 cmd->result = DID_OK << 16 | 1717 cmd->result = DID_OK << 16 |
1735 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1718 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1736 set_sense((u8 *)&dev->fsa_dev[cid].sense_data, 1719 set_sense(&dev->fsa_dev[cid].sense_data,
1737 HARDWARE_ERROR, 1720 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1738 SENCODE_INTERNAL_TARGET_FAILURE, 1721 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1739 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1740 0, 0);
1741 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1722 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1742 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1723 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1743 SCSI_SENSE_BUFFERSIZE)); 1724 SCSI_SENSE_BUFFERSIZE));
@@ -1945,10 +1926,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1945 { 1926 {
1946 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0])); 1927 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1947 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1928 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1948 set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 1929 set_sense(&dev->fsa_dev[cid].sense_data,
1949 ILLEGAL_REQUEST, 1930 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1950 SENCODE_INVALID_COMMAND, 1931 ASENCODE_INVALID_COMMAND, 0, 0);
1951 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1952 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1932 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1953 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1933 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1954 SCSI_SENSE_BUFFERSIZE)); 1934 SCSI_SENSE_BUFFERSIZE));
@@ -1995,10 +1975,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1995 scsicmd->result = DID_OK << 16 | 1975 scsicmd->result = DID_OK << 16 |
1996 COMMAND_COMPLETE << 8 | 1976 COMMAND_COMPLETE << 8 |
1997 SAM_STAT_CHECK_CONDITION; 1977 SAM_STAT_CHECK_CONDITION;
1998 set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 1978 set_sense(&dev->fsa_dev[cid].sense_data,
1999 ILLEGAL_REQUEST, 1979 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2000 SENCODE_INVALID_CDB_FIELD, 1980 ASENCODE_NO_SENSE, 7, 2);
2001 ASENCODE_NO_SENSE, 0, 7, 2, 0);
2002 memcpy(scsicmd->sense_buffer, 1981 memcpy(scsicmd->sense_buffer,
2003 &dev->fsa_dev[cid].sense_data, 1982 &dev->fsa_dev[cid].sense_data,
2004 min_t(size_t, 1983 min_t(size_t,
@@ -2254,9 +2233,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2254 */ 2233 */
2255 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0])); 2234 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2256 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 2235 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2257 set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 2236 set_sense(&dev->fsa_dev[cid].sense_data,
2258 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND, 2237 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2259 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0); 2238 ASENCODE_INVALID_COMMAND, 0, 0);
2260 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 2239 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2261 min_t(size_t, 2240 min_t(size_t,
2262 sizeof(dev->fsa_dev[cid].sense_data), 2241 sizeof(dev->fsa_dev[cid].sense_data),
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index f8afa358b6b6..abef05146d75 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -243,6 +243,7 @@ static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
243 * Search the list of AdapterFibContext addresses on the adapter 243 * Search the list of AdapterFibContext addresses on the adapter
244 * to be sure this is a valid address 244 * to be sure this is a valid address
245 */ 245 */
246 spin_lock_irqsave(&dev->fib_lock, flags);
246 entry = dev->fib_list.next; 247 entry = dev->fib_list.next;
247 fibctx = NULL; 248 fibctx = NULL;
248 249
@@ -251,24 +252,25 @@ static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
251 /* 252 /*
252 * Extract the AdapterFibContext from the Input parameters. 253 * Extract the AdapterFibContext from the Input parameters.
253 */ 254 */
254 if (fibctx->unique == f.fibctx) { /* We found a winner */ 255 if (fibctx->unique == f.fibctx) { /* We found a winner */
255 break; 256 break;
256 } 257 }
257 entry = entry->next; 258 entry = entry->next;
258 fibctx = NULL; 259 fibctx = NULL;
259 } 260 }
260 if (!fibctx) { 261 if (!fibctx) {
262 spin_unlock_irqrestore(&dev->fib_lock, flags);
261 dprintk ((KERN_INFO "Fib Context not found\n")); 263 dprintk ((KERN_INFO "Fib Context not found\n"));
262 return -EINVAL; 264 return -EINVAL;
263 } 265 }
264 266
265 if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) || 267 if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
266 (fibctx->size != sizeof(struct aac_fib_context))) { 268 (fibctx->size != sizeof(struct aac_fib_context))) {
269 spin_unlock_irqrestore(&dev->fib_lock, flags);
267 dprintk ((KERN_INFO "Fib Context corrupt?\n")); 270 dprintk ((KERN_INFO "Fib Context corrupt?\n"));
268 return -EINVAL; 271 return -EINVAL;
269 } 272 }
270 status = 0; 273 status = 0;
271 spin_lock_irqsave(&dev->fib_lock, flags);
272 /* 274 /*
273 * If there are no fibs to send back, then either wait or return 275 * If there are no fibs to send back, then either wait or return
274 * -EAGAIN 276 * -EAGAIN
@@ -414,8 +416,8 @@ static int close_getadapter_fib(struct aac_dev * dev, void __user *arg)
414 * @arg: ioctl arguments 416 * @arg: ioctl arguments
415 * 417 *
416 * This routine returns the driver version. 418 * This routine returns the driver version.
417 * Under Linux, there have been no version incompatibilities, so this is 419 * Under Linux, there have been no version incompatibilities, so this is
418 * simple! 420 * simple!
419 */ 421 */
420 422
421static int check_revision(struct aac_dev *dev, void __user *arg) 423static int check_revision(struct aac_dev *dev, void __user *arg)
@@ -463,7 +465,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
463 u32 data_dir; 465 u32 data_dir;
464 void __user *sg_user[32]; 466 void __user *sg_user[32];
465 void *sg_list[32]; 467 void *sg_list[32];
466 u32 sg_indx = 0; 468 u32 sg_indx = 0;
467 u32 byte_count = 0; 469 u32 byte_count = 0;
468 u32 actual_fibsize64, actual_fibsize = 0; 470 u32 actual_fibsize64, actual_fibsize = 0;
469 int i; 471 int i;
@@ -517,11 +519,11 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
517 // Fix up srb for endian and force some values 519 // Fix up srb for endian and force some values
518 520
519 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); // Force this 521 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); // Force this
520 srbcmd->channel = cpu_to_le32(user_srbcmd->channel); 522 srbcmd->channel = cpu_to_le32(user_srbcmd->channel);
521 srbcmd->id = cpu_to_le32(user_srbcmd->id); 523 srbcmd->id = cpu_to_le32(user_srbcmd->id);
522 srbcmd->lun = cpu_to_le32(user_srbcmd->lun); 524 srbcmd->lun = cpu_to_le32(user_srbcmd->lun);
523 srbcmd->timeout = cpu_to_le32(user_srbcmd->timeout); 525 srbcmd->timeout = cpu_to_le32(user_srbcmd->timeout);
524 srbcmd->flags = cpu_to_le32(flags); 526 srbcmd->flags = cpu_to_le32(flags);
525 srbcmd->retry_limit = 0; // Obsolete parameter 527 srbcmd->retry_limit = 0; // Obsolete parameter
526 srbcmd->cdb_size = cpu_to_le32(user_srbcmd->cdb_size); 528 srbcmd->cdb_size = cpu_to_le32(user_srbcmd->cdb_size);
527 memcpy(srbcmd->cdb, user_srbcmd->cdb, sizeof(srbcmd->cdb)); 529 memcpy(srbcmd->cdb, user_srbcmd->cdb, sizeof(srbcmd->cdb));
@@ -786,9 +788,9 @@ static int aac_get_pci_info(struct aac_dev* dev, void __user *arg)
786 pci_info.bus = dev->pdev->bus->number; 788 pci_info.bus = dev->pdev->bus->number;
787 pci_info.slot = PCI_SLOT(dev->pdev->devfn); 789 pci_info.slot = PCI_SLOT(dev->pdev->devfn);
788 790
789 if (copy_to_user(arg, &pci_info, sizeof(struct aac_pci_info))) { 791 if (copy_to_user(arg, &pci_info, sizeof(struct aac_pci_info))) {
790 dprintk((KERN_DEBUG "aacraid: Could not copy pci info\n")); 792 dprintk((KERN_DEBUG "aacraid: Could not copy pci info\n"));
791 return -EFAULT; 793 return -EFAULT;
792 } 794 }
793 return 0; 795 return 0;
794} 796}
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index fb0886140dd7..e80d2a0c46af 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1130,31 +1130,29 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
1130 if (error < 0) 1130 if (error < 0)
1131 goto out_deinit; 1131 goto out_deinit;
1132 1132
1133 if (!(aac->adapter_info.options & AAC_OPT_NEW_COMM)) {
1134 error = pci_set_dma_max_seg_size(pdev, 65536);
1135 if (error)
1136 goto out_deinit;
1137 }
1138
1139 /* 1133 /*
1140 * Lets override negotiations and drop the maximum SG limit to 34 1134 * Lets override negotiations and drop the maximum SG limit to 34
1141 */ 1135 */
1142 if ((aac_drivers[index].quirks & AAC_QUIRK_34SG) && 1136 if ((aac_drivers[index].quirks & AAC_QUIRK_34SG) &&
1143 (aac->scsi_host_ptr->sg_tablesize > 34)) { 1137 (shost->sg_tablesize > 34)) {
1144 aac->scsi_host_ptr->sg_tablesize = 34; 1138 shost->sg_tablesize = 34;
1145 aac->scsi_host_ptr->max_sectors 1139 shost->max_sectors = (shost->sg_tablesize * 8) + 112;
1146 = (aac->scsi_host_ptr->sg_tablesize * 8) + 112;
1147 } 1140 }
1148 1141
1149 if ((aac_drivers[index].quirks & AAC_QUIRK_17SG) && 1142 if ((aac_drivers[index].quirks & AAC_QUIRK_17SG) &&
1150 (aac->scsi_host_ptr->sg_tablesize > 17)) { 1143 (shost->sg_tablesize > 17)) {
1151 aac->scsi_host_ptr->sg_tablesize = 17; 1144 shost->sg_tablesize = 17;
1152 aac->scsi_host_ptr->max_sectors 1145 shost->max_sectors = (shost->sg_tablesize * 8) + 112;
1153 = (aac->scsi_host_ptr->sg_tablesize * 8) + 112;
1154 } 1146 }
1155 1147
1148 error = pci_set_dma_max_seg_size(pdev,
1149 (aac->adapter_info.options & AAC_OPT_NEW_COMM) ?
1150 (shost->max_sectors << 9) : 65536);
1151 if (error)
1152 goto out_deinit;
1153
1156 /* 1154 /*
1157 * Firware printf works only with older firmware. 1155 * Firmware printf works only with older firmware.
1158 */ 1156 */
1159 if (aac_drivers[index].quirks & AAC_QUIRK_34SG) 1157 if (aac_drivers[index].quirks & AAC_QUIRK_34SG)
1160 aac->printf_enabled = 1; 1158 aac->printf_enabled = 1;
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 374ed025dc5a..ccef891d642f 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -12261,7 +12261,7 @@ static ushort __devinit AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
12261/* 12261/*
12262 * Write the EEPROM from 'cfg_buf'. 12262 * Write the EEPROM from 'cfg_buf'.
12263 */ 12263 */
12264void __devinit 12264static void __devinit
12265AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf) 12265AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
12266{ 12266{
12267 ushort *wbuf; 12267 ushort *wbuf;
@@ -12328,7 +12328,7 @@ AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
12328/* 12328/*
12329 * Write the EEPROM from 'cfg_buf'. 12329 * Write the EEPROM from 'cfg_buf'.
12330 */ 12330 */
12331void __devinit 12331static void __devinit
12332AdvSet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf) 12332AdvSet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
12333{ 12333{
12334 ushort *wbuf; 12334 ushort *wbuf;
@@ -12395,7 +12395,7 @@ AdvSet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
12395/* 12395/*
12396 * Write the EEPROM from 'cfg_buf'. 12396 * Write the EEPROM from 'cfg_buf'.
12397 */ 12397 */
12398void __devinit 12398static void __devinit
12399AdvSet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf) 12399AdvSet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf)
12400{ 12400{
12401 ushort *wbuf; 12401 ushort *wbuf;
diff --git a/drivers/scsi/arcmsr/arcmsr.h b/drivers/scsi/arcmsr/arcmsr.h
index a67e29f83ae5..57786502e3ec 100644
--- a/drivers/scsi/arcmsr/arcmsr.h
+++ b/drivers/scsi/arcmsr/arcmsr.h
@@ -48,7 +48,7 @@ struct class_device_attribute;
48/*The limit of outstanding scsi command that firmware can handle*/ 48/*The limit of outstanding scsi command that firmware can handle*/
49#define ARCMSR_MAX_OUTSTANDING_CMD 256 49#define ARCMSR_MAX_OUTSTANDING_CMD 256
50#define ARCMSR_MAX_FREECCB_NUM 320 50#define ARCMSR_MAX_FREECCB_NUM 320
51#define ARCMSR_DRIVER_VERSION "Driver Version 1.20.00.15 2007/08/30" 51#define ARCMSR_DRIVER_VERSION "Driver Version 1.20.00.15 2007/12/24"
52#define ARCMSR_SCSI_INITIATOR_ID 255 52#define ARCMSR_SCSI_INITIATOR_ID 255
53#define ARCMSR_MAX_XFER_SECTORS 512 53#define ARCMSR_MAX_XFER_SECTORS 512
54#define ARCMSR_MAX_XFER_SECTORS_B 4096 54#define ARCMSR_MAX_XFER_SECTORS_B 4096
@@ -248,6 +248,7 @@ struct FIRMWARE_INFO
248#define ARCMSR_MESSAGE_START_BGRB 0x00060008 248#define ARCMSR_MESSAGE_START_BGRB 0x00060008
249#define ARCMSR_MESSAGE_START_DRIVER_MODE 0x000E0008 249#define ARCMSR_MESSAGE_START_DRIVER_MODE 0x000E0008
250#define ARCMSR_MESSAGE_SET_POST_WINDOW 0x000F0008 250#define ARCMSR_MESSAGE_SET_POST_WINDOW 0x000F0008
251#define ARCMSR_MESSAGE_ACTIVE_EOI_MODE 0x00100008
251/* ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK */ 252/* ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK */
252#define ARCMSR_MESSAGE_FIRMWARE_OK 0x80000000 253#define ARCMSR_MESSAGE_FIRMWARE_OK 0x80000000
253/* ioctl transfer */ 254/* ioctl transfer */
@@ -256,6 +257,7 @@ struct FIRMWARE_INFO
256#define ARCMSR_DRV2IOP_DATA_READ_OK 0x00000002 257#define ARCMSR_DRV2IOP_DATA_READ_OK 0x00000002
257#define ARCMSR_DRV2IOP_CDB_POSTED 0x00000004 258#define ARCMSR_DRV2IOP_CDB_POSTED 0x00000004
258#define ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED 0x00000008 259#define ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED 0x00000008
260#define ARCMSR_DRV2IOP_END_OF_INTERRUPT 0x00000010
259 261
260/* data tunnel buffer between user space program and its firmware */ 262/* data tunnel buffer between user space program and its firmware */
261/* user space data to iop 128bytes */ 263/* user space data to iop 128bytes */
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index f4a202e8df26..4f9ff32cfed0 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -315,9 +315,6 @@ static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb)
315 (0x20 - ((unsigned long)dma_coherent_handle & 0x1F)); 315 (0x20 - ((unsigned long)dma_coherent_handle & 0x1F));
316 } 316 }
317 317
318 reg = (struct MessageUnit_B *)(dma_coherent +
319 ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock));
320
321 dma_addr = dma_coherent_handle; 318 dma_addr = dma_coherent_handle;
322 ccb_tmp = (struct CommandControlBlock *)dma_coherent; 319 ccb_tmp = (struct CommandControlBlock *)dma_coherent;
323 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) { 320 for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) {
@@ -371,8 +368,8 @@ static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb)
371 368
372out: 369out:
373 dma_free_coherent(&acb->pdev->dev, 370 dma_free_coherent(&acb->pdev->dev,
374 ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock) + 0x20, 371 (ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock) + 0x20 +
375 acb->dma_coherent, acb->dma_coherent_handle); 372 sizeof(struct MessageUnit_B)), acb->dma_coherent, acb->dma_coherent_handle);
376 return -ENOMEM; 373 return -ENOMEM;
377} 374}
378 375
@@ -509,6 +506,7 @@ static uint8_t arcmsr_hbb_wait_msgint_ready(struct AdapterControlBlock *acb)
509 & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE) { 506 & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE) {
510 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN 507 writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
511 , reg->iop2drv_doorbell_reg); 508 , reg->iop2drv_doorbell_reg);
509 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg);
512 return 0x00; 510 return 0x00;
513 } 511 }
514 msleep(10); 512 msleep(10);
@@ -748,6 +746,7 @@ static void arcmsr_drain_donequeue(struct AdapterControlBlock *acb, uint32_t fla
748 , ccb->startdone 746 , ccb->startdone
749 , atomic_read(&acb->ccboutstandingcount)); 747 , atomic_read(&acb->ccboutstandingcount));
750 } 748 }
749 else
751 arcmsr_report_ccb_state(acb, ccb, flag_ccb); 750 arcmsr_report_ccb_state(acb, ccb, flag_ccb);
752} 751}
753 752
@@ -886,7 +885,7 @@ static void arcmsr_enable_outbound_ints(struct AdapterControlBlock *acb, \
886 } 885 }
887} 886}
888 887
889static void arcmsr_build_ccb(struct AdapterControlBlock *acb, 888static int arcmsr_build_ccb(struct AdapterControlBlock *acb,
890 struct CommandControlBlock *ccb, struct scsi_cmnd *pcmd) 889 struct CommandControlBlock *ccb, struct scsi_cmnd *pcmd)
891{ 890{
892 struct ARCMSR_CDB *arcmsr_cdb = (struct ARCMSR_CDB *)&ccb->arcmsr_cdb; 891 struct ARCMSR_CDB *arcmsr_cdb = (struct ARCMSR_CDB *)&ccb->arcmsr_cdb;
@@ -906,6 +905,8 @@ static void arcmsr_build_ccb(struct AdapterControlBlock *acb,
906 memcpy(arcmsr_cdb->Cdb, pcmd->cmnd, pcmd->cmd_len); 905 memcpy(arcmsr_cdb->Cdb, pcmd->cmnd, pcmd->cmd_len);
907 906
908 nseg = scsi_dma_map(pcmd); 907 nseg = scsi_dma_map(pcmd);
908 if (nseg > ARCMSR_MAX_SG_ENTRIES)
909 return FAILED;
909 BUG_ON(nseg < 0); 910 BUG_ON(nseg < 0);
910 911
911 if (nseg) { 912 if (nseg) {
@@ -946,6 +947,7 @@ static void arcmsr_build_ccb(struct AdapterControlBlock *acb,
946 arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE; 947 arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE;
947 ccb->ccb_flags |= CCB_FLAG_WRITE; 948 ccb->ccb_flags |= CCB_FLAG_WRITE;
948 } 949 }
950 return SUCCESS;
949} 951}
950 952
951static void arcmsr_post_ccb(struct AdapterControlBlock *acb, struct CommandControlBlock *ccb) 953static void arcmsr_post_ccb(struct AdapterControlBlock *acb, struct CommandControlBlock *ccb)
@@ -1036,18 +1038,22 @@ static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb)
1036 switch (acb->adapter_type) { 1038 switch (acb->adapter_type) {
1037 case ACB_ADAPTER_TYPE_A: { 1039 case ACB_ADAPTER_TYPE_A: {
1038 iounmap(acb->pmuA); 1040 iounmap(acb->pmuA);
1041 dma_free_coherent(&acb->pdev->dev,
1042 ARCMSR_MAX_FREECCB_NUM * sizeof (struct CommandControlBlock) + 0x20,
1043 acb->dma_coherent,
1044 acb->dma_coherent_handle);
1039 break; 1045 break;
1040 } 1046 }
1041 case ACB_ADAPTER_TYPE_B: { 1047 case ACB_ADAPTER_TYPE_B: {
1042 struct MessageUnit_B *reg = acb->pmuB; 1048 struct MessageUnit_B *reg = acb->pmuB;
1043 iounmap(reg->drv2iop_doorbell_reg - ARCMSR_DRV2IOP_DOORBELL); 1049 iounmap(reg->drv2iop_doorbell_reg - ARCMSR_DRV2IOP_DOORBELL);
1044 iounmap(reg->ioctl_wbuffer_reg - ARCMSR_IOCTL_WBUFFER); 1050 iounmap(reg->ioctl_wbuffer_reg - ARCMSR_IOCTL_WBUFFER);
1051 dma_free_coherent(&acb->pdev->dev,
1052 (ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock) + 0x20 +
1053 sizeof(struct MessageUnit_B)), acb->dma_coherent, acb->dma_coherent_handle);
1045 } 1054 }
1046 } 1055 }
1047 dma_free_coherent(&acb->pdev->dev, 1056
1048 ARCMSR_MAX_FREECCB_NUM * sizeof (struct CommandControlBlock) + 0x20,
1049 acb->dma_coherent,
1050 acb->dma_coherent_handle);
1051} 1057}
1052 1058
1053void arcmsr_iop_message_read(struct AdapterControlBlock *acb) 1059void arcmsr_iop_message_read(struct AdapterControlBlock *acb)
@@ -1273,7 +1279,9 @@ static int arcmsr_handle_hbb_isr(struct AdapterControlBlock *acb)
1273 return 1; 1279 return 1;
1274 1280
1275 writel(~outbound_doorbell, reg->iop2drv_doorbell_reg); 1281 writel(~outbound_doorbell, reg->iop2drv_doorbell_reg);
1276 1282 /*in case the last action of doorbell interrupt clearance is cached, this action can push HW to write down the clear bit*/
1283 readl(reg->iop2drv_doorbell_reg);
1284 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg);
1277 if (outbound_doorbell & ARCMSR_IOP2DRV_DATA_WRITE_OK) { 1285 if (outbound_doorbell & ARCMSR_IOP2DRV_DATA_WRITE_OK) {
1278 arcmsr_iop2drv_data_wrote_handle(acb); 1286 arcmsr_iop2drv_data_wrote_handle(acb);
1279 } 1287 }
@@ -1380,12 +1388,13 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, \
1380 1388
1381 case ARCMSR_MESSAGE_READ_RQBUFFER: { 1389 case ARCMSR_MESSAGE_READ_RQBUFFER: {
1382 unsigned long *ver_addr; 1390 unsigned long *ver_addr;
1383 dma_addr_t buf_handle;
1384 uint8_t *pQbuffer, *ptmpQbuffer; 1391 uint8_t *pQbuffer, *ptmpQbuffer;
1385 int32_t allxfer_len = 0; 1392 int32_t allxfer_len = 0;
1393 void *tmp;
1386 1394
1387 ver_addr = pci_alloc_consistent(acb->pdev, 1032, &buf_handle); 1395 tmp = kmalloc(1032, GFP_KERNEL|GFP_DMA);
1388 if (!ver_addr) { 1396 ver_addr = (unsigned long *)tmp;
1397 if (!tmp) {
1389 retvalue = ARCMSR_MESSAGE_FAIL; 1398 retvalue = ARCMSR_MESSAGE_FAIL;
1390 goto message_out; 1399 goto message_out;
1391 } 1400 }
@@ -1421,18 +1430,19 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, \
1421 memcpy(pcmdmessagefld->messagedatabuffer, (uint8_t *)ver_addr, allxfer_len); 1430 memcpy(pcmdmessagefld->messagedatabuffer, (uint8_t *)ver_addr, allxfer_len);
1422 pcmdmessagefld->cmdmessage.Length = allxfer_len; 1431 pcmdmessagefld->cmdmessage.Length = allxfer_len;
1423 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK; 1432 pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK;
1424 pci_free_consistent(acb->pdev, 1032, ver_addr, buf_handle); 1433 kfree(tmp);
1425 } 1434 }
1426 break; 1435 break;
1427 1436
1428 case ARCMSR_MESSAGE_WRITE_WQBUFFER: { 1437 case ARCMSR_MESSAGE_WRITE_WQBUFFER: {
1429 unsigned long *ver_addr; 1438 unsigned long *ver_addr;
1430 dma_addr_t buf_handle;
1431 int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; 1439 int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex;
1432 uint8_t *pQbuffer, *ptmpuserbuffer; 1440 uint8_t *pQbuffer, *ptmpuserbuffer;
1441 void *tmp;
1433 1442
1434 ver_addr = pci_alloc_consistent(acb->pdev, 1032, &buf_handle); 1443 tmp = kmalloc(1032, GFP_KERNEL|GFP_DMA);
1435 if (!ver_addr) { 1444 ver_addr = (unsigned long *)tmp;
1445 if (!tmp) {
1436 retvalue = ARCMSR_MESSAGE_FAIL; 1446 retvalue = ARCMSR_MESSAGE_FAIL;
1437 goto message_out; 1447 goto message_out;
1438 } 1448 }
@@ -1482,7 +1492,7 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, \
1482 retvalue = ARCMSR_MESSAGE_FAIL; 1492 retvalue = ARCMSR_MESSAGE_FAIL;
1483 } 1493 }
1484 } 1494 }
1485 pci_free_consistent(acb->pdev, 1032, ver_addr, buf_handle); 1495 kfree(tmp);
1486 } 1496 }
1487 break; 1497 break;
1488 1498
@@ -1682,8 +1692,11 @@ static int arcmsr_queue_command(struct scsi_cmnd *cmd,
1682 ccb = arcmsr_get_freeccb(acb); 1692 ccb = arcmsr_get_freeccb(acb);
1683 if (!ccb) 1693 if (!ccb)
1684 return SCSI_MLQUEUE_HOST_BUSY; 1694 return SCSI_MLQUEUE_HOST_BUSY;
1685 1695 if ( arcmsr_build_ccb( acb, ccb, cmd ) == FAILED ) {
1686 arcmsr_build_ccb(acb, ccb, cmd); 1696 cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1);
1697 cmd->scsi_done(cmd);
1698 return 0;
1699 }
1687 arcmsr_post_ccb(acb, ccb); 1700 arcmsr_post_ccb(acb, ccb);
1688 return 0; 1701 return 0;
1689} 1702}
@@ -1844,7 +1857,7 @@ static void arcmsr_polling_hba_ccbdone(struct AdapterControlBlock *acb,
1844 } 1857 }
1845} 1858}
1846 1859
1847static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb, \ 1860static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb,
1848 struct CommandControlBlock *poll_ccb) 1861 struct CommandControlBlock *poll_ccb)
1849{ 1862{
1850 struct MessageUnit_B *reg = acb->pmuB; 1863 struct MessageUnit_B *reg = acb->pmuB;
@@ -1878,7 +1891,7 @@ static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb, \
1878 (acb->vir2phy_offset + (flag_ccb << 5));/*frame must be 32 bytes aligned*/ 1891 (acb->vir2phy_offset + (flag_ccb << 5));/*frame must be 32 bytes aligned*/
1879 poll_ccb_done = (ccb == poll_ccb) ? 1:0; 1892 poll_ccb_done = (ccb == poll_ccb) ? 1:0;
1880 if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) { 1893 if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) {
1881 if (ccb->startdone == ARCMSR_CCB_ABORTED) { 1894 if ((ccb->startdone == ARCMSR_CCB_ABORTED) || (ccb == poll_ccb)) {
1882 printk(KERN_NOTICE "arcmsr%d: \ 1895 printk(KERN_NOTICE "arcmsr%d: \
1883 scsi id = %d lun = %d ccb = '0x%p' poll command abort successfully \n" 1896 scsi id = %d lun = %d ccb = '0x%p' poll command abort successfully \n"
1884 ,acb->host->host_no 1897 ,acb->host->host_no
@@ -1901,7 +1914,7 @@ static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb, \
1901 } /*drain reply FIFO*/ 1914 } /*drain reply FIFO*/
1902} 1915}
1903 1916
1904static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb, \ 1917static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb,
1905 struct CommandControlBlock *poll_ccb) 1918 struct CommandControlBlock *poll_ccb)
1906{ 1919{
1907 switch (acb->adapter_type) { 1920 switch (acb->adapter_type) {
@@ -2026,6 +2039,7 @@ static void arcmsr_wait_firmware_ready(struct AdapterControlBlock *acb)
2026 do { 2039 do {
2027 firmware_state = readl(reg->iop2drv_doorbell_reg); 2040 firmware_state = readl(reg->iop2drv_doorbell_reg);
2028 } while ((firmware_state & ARCMSR_MESSAGE_FIRMWARE_OK) == 0); 2041 } while ((firmware_state & ARCMSR_MESSAGE_FIRMWARE_OK) == 0);
2042 writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg);
2029 } 2043 }
2030 break; 2044 break;
2031 } 2045 }
@@ -2090,19 +2104,39 @@ static void arcmsr_clear_doorbell_queue_buffer(struct AdapterControlBlock *acb)
2090 } 2104 }
2091} 2105}
2092 2106
2107static void arcmsr_enable_eoi_mode(struct AdapterControlBlock *acb)
2108{
2109 switch (acb->adapter_type) {
2110 case ACB_ADAPTER_TYPE_A:
2111 return;
2112 case ACB_ADAPTER_TYPE_B:
2113 {
2114 struct MessageUnit_B *reg = acb->pmuB;
2115 writel(ARCMSR_MESSAGE_ACTIVE_EOI_MODE, reg->drv2iop_doorbell_reg);
2116 if(arcmsr_hbb_wait_msgint_ready(acb)) {
2117 printk(KERN_NOTICE "ARCMSR IOP enables EOI_MODE TIMEOUT");
2118 return;
2119 }
2120 }
2121 break;
2122 }
2123 return;
2124}
2125
2093static void arcmsr_iop_init(struct AdapterControlBlock *acb) 2126static void arcmsr_iop_init(struct AdapterControlBlock *acb)
2094{ 2127{
2095 uint32_t intmask_org; 2128 uint32_t intmask_org;
2096 2129
2097 arcmsr_wait_firmware_ready(acb);
2098 arcmsr_iop_confirm(acb);
2099 /* disable all outbound interrupt */ 2130 /* disable all outbound interrupt */
2100 intmask_org = arcmsr_disable_outbound_ints(acb); 2131 intmask_org = arcmsr_disable_outbound_ints(acb);
2132 arcmsr_wait_firmware_ready(acb);
2133 arcmsr_iop_confirm(acb);
2101 arcmsr_get_firmware_spec(acb); 2134 arcmsr_get_firmware_spec(acb);
2102 /*start background rebuild*/ 2135 /*start background rebuild*/
2103 arcmsr_start_adapter_bgrb(acb); 2136 arcmsr_start_adapter_bgrb(acb);
2104 /* empty doorbell Qbuffer if door bell ringed */ 2137 /* empty doorbell Qbuffer if door bell ringed */
2105 arcmsr_clear_doorbell_queue_buffer(acb); 2138 arcmsr_clear_doorbell_queue_buffer(acb);
2139 arcmsr_enable_eoi_mode(acb);
2106 /* enable outbound Post Queue,outbound doorbell Interrupt */ 2140 /* enable outbound Post Queue,outbound doorbell Interrupt */
2107 arcmsr_enable_outbound_ints(acb, intmask_org); 2141 arcmsr_enable_outbound_ints(acb, intmask_org);
2108 acb->acb_flags |= ACB_F_IOP_INITED; 2142 acb->acb_flags |= ACB_F_IOP_INITED;
@@ -2275,6 +2309,7 @@ static pci_ers_result_t arcmsr_pci_slot_reset(struct pci_dev *pdev)
2275 arcmsr_start_adapter_bgrb(acb); 2309 arcmsr_start_adapter_bgrb(acb);
2276 /* empty doorbell Qbuffer if door bell ringed */ 2310 /* empty doorbell Qbuffer if door bell ringed */
2277 arcmsr_clear_doorbell_queue_buffer(acb); 2311 arcmsr_clear_doorbell_queue_buffer(acb);
2312 arcmsr_enable_eoi_mode(acb);
2278 /* enable outbound Post Queue,outbound doorbell Interrupt */ 2313 /* enable outbound Post Queue,outbound doorbell Interrupt */
2279 arcmsr_enable_outbound_ints(acb, intmask_org); 2314 arcmsr_enable_outbound_ints(acb, intmask_org);
2280 acb->acb_flags |= ACB_F_IOP_INITED; 2315 acb->acb_flags |= ACB_F_IOP_INITED;
diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index eceacf6d49ea..3bedf2466bd1 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -1790,7 +1790,7 @@ int acornscsi_starttransfer(AS_Host *host)
1790 return 0; 1790 return 0;
1791 } 1791 }
1792 1792
1793 residual = host->SCpnt->request_bufflen - host->scsi.SCp.scsi_xferred; 1793 residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred;
1794 1794
1795 sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer); 1795 sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
1796 sbic_arm_writenext(host->scsi.io_port, residual >> 16); 1796 sbic_arm_writenext(host->scsi.io_port, residual >> 16);
@@ -2270,7 +2270,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
2270 case 0x4b: /* -> PHASE_STATUSIN */ 2270 case 0x4b: /* -> PHASE_STATUSIN */
2271 case 0x8b: /* -> PHASE_STATUSIN */ 2271 case 0x8b: /* -> PHASE_STATUSIN */
2272 /* DATA IN -> STATUS */ 2272 /* DATA IN -> STATUS */
2273 host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2273 host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
2274 acornscsi_sbic_xfcount(host); 2274 acornscsi_sbic_xfcount(host);
2275 acornscsi_dma_stop(host); 2275 acornscsi_dma_stop(host);
2276 acornscsi_readstatusbyte(host); 2276 acornscsi_readstatusbyte(host);
@@ -2281,7 +2281,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
2281 case 0x4e: /* -> PHASE_MSGOUT */ 2281 case 0x4e: /* -> PHASE_MSGOUT */
2282 case 0x8e: /* -> PHASE_MSGOUT */ 2282 case 0x8e: /* -> PHASE_MSGOUT */
2283 /* DATA IN -> MESSAGE OUT */ 2283 /* DATA IN -> MESSAGE OUT */
2284 host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2284 host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
2285 acornscsi_sbic_xfcount(host); 2285 acornscsi_sbic_xfcount(host);
2286 acornscsi_dma_stop(host); 2286 acornscsi_dma_stop(host);
2287 acornscsi_sendmessage(host); 2287 acornscsi_sendmessage(host);
@@ -2291,7 +2291,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
2291 case 0x4f: /* message in */ 2291 case 0x4f: /* message in */
2292 case 0x8f: /* message in */ 2292 case 0x8f: /* message in */
2293 /* DATA IN -> MESSAGE IN */ 2293 /* DATA IN -> MESSAGE IN */
2294 host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2294 host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
2295 acornscsi_sbic_xfcount(host); 2295 acornscsi_sbic_xfcount(host);
2296 acornscsi_dma_stop(host); 2296 acornscsi_dma_stop(host);
2297 acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */ 2297 acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
@@ -2319,7 +2319,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
2319 case 0x4b: /* -> PHASE_STATUSIN */ 2319 case 0x4b: /* -> PHASE_STATUSIN */
2320 case 0x8b: /* -> PHASE_STATUSIN */ 2320 case 0x8b: /* -> PHASE_STATUSIN */
2321 /* DATA OUT -> STATUS */ 2321 /* DATA OUT -> STATUS */
2322 host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2322 host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
2323 acornscsi_sbic_xfcount(host); 2323 acornscsi_sbic_xfcount(host);
2324 acornscsi_dma_stop(host); 2324 acornscsi_dma_stop(host);
2325 acornscsi_dma_adjust(host); 2325 acornscsi_dma_adjust(host);
@@ -2331,7 +2331,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
2331 case 0x4e: /* -> PHASE_MSGOUT */ 2331 case 0x4e: /* -> PHASE_MSGOUT */
2332 case 0x8e: /* -> PHASE_MSGOUT */ 2332 case 0x8e: /* -> PHASE_MSGOUT */
2333 /* DATA OUT -> MESSAGE OUT */ 2333 /* DATA OUT -> MESSAGE OUT */
2334 host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2334 host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
2335 acornscsi_sbic_xfcount(host); 2335 acornscsi_sbic_xfcount(host);
2336 acornscsi_dma_stop(host); 2336 acornscsi_dma_stop(host);
2337 acornscsi_dma_adjust(host); 2337 acornscsi_dma_adjust(host);
@@ -2342,7 +2342,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
2342 case 0x4f: /* message in */ 2342 case 0x4f: /* message in */
2343 case 0x8f: /* message in */ 2343 case 0x8f: /* message in */
2344 /* DATA OUT -> MESSAGE IN */ 2344 /* DATA OUT -> MESSAGE IN */
2345 host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen - 2345 host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
2346 acornscsi_sbic_xfcount(host); 2346 acornscsi_sbic_xfcount(host);
2347 acornscsi_dma_stop(host); 2347 acornscsi_dma_stop(host);
2348 acornscsi_dma_adjust(host); 2348 acornscsi_dma_adjust(host);
diff --git a/drivers/scsi/arm/scsi.h b/drivers/scsi/arm/scsi.h
index bb6550e31926..138a521ba1a8 100644
--- a/drivers/scsi/arm/scsi.h
+++ b/drivers/scsi/arm/scsi.h
@@ -18,17 +18,32 @@
18 * The scatter-gather list handling. This contains all 18 * The scatter-gather list handling. This contains all
19 * the yucky stuff that needs to be fixed properly. 19 * the yucky stuff that needs to be fixed properly.
20 */ 20 */
21
22/*
23 * copy_SCp_to_sg() Assumes contiguous allocation at @sg of at-most @max
24 * entries of uninitialized memory. SCp is from scsi-ml and has a valid
25 * (possibly chained) sg-list
26 */
21static inline int copy_SCp_to_sg(struct scatterlist *sg, struct scsi_pointer *SCp, int max) 27static inline int copy_SCp_to_sg(struct scatterlist *sg, struct scsi_pointer *SCp, int max)
22{ 28{
23 int bufs = SCp->buffers_residual; 29 int bufs = SCp->buffers_residual;
24 30
31 /* FIXME: It should be easy for drivers to loop on copy_SCp_to_sg().
32 * and to remove this BUG_ON. Use min() in-its-place
33 */
25 BUG_ON(bufs + 1 > max); 34 BUG_ON(bufs + 1 > max);
26 35
27 sg_set_buf(sg, SCp->ptr, SCp->this_residual); 36 sg_set_buf(sg, SCp->ptr, SCp->this_residual);
28 37
29 if (bufs) 38 if (bufs) {
30 memcpy(sg + 1, SCp->buffer + 1, 39 struct scatterlist *src_sg;
31 sizeof(struct scatterlist) * bufs); 40 unsigned i;
41
42 for_each_sg(sg_next(SCp->buffer), src_sg, bufs, i)
43 *(++sg) = *src_sg;
44 sg_mark_end(sg);
45 }
46
32 return bufs + 1; 47 return bufs + 1;
33} 48}
34 49
@@ -36,7 +51,7 @@ static inline int next_SCp(struct scsi_pointer *SCp)
36{ 51{
37 int ret = SCp->buffers_residual; 52 int ret = SCp->buffers_residual;
38 if (ret) { 53 if (ret) {
39 SCp->buffer++; 54 SCp->buffer = sg_next(SCp->buffer);
40 SCp->buffers_residual--; 55 SCp->buffers_residual--;
41 SCp->ptr = sg_virt(SCp->buffer); 56 SCp->ptr = sg_virt(SCp->buffer);
42 SCp->this_residual = SCp->buffer->length; 57 SCp->this_residual = SCp->buffer->length;
@@ -68,46 +83,46 @@ static inline void init_SCp(struct scsi_cmnd *SCpnt)
68{ 83{
69 memset(&SCpnt->SCp, 0, sizeof(struct scsi_pointer)); 84 memset(&SCpnt->SCp, 0, sizeof(struct scsi_pointer));
70 85
71 if (SCpnt->use_sg) { 86 if (scsi_bufflen(SCpnt)) {
72 unsigned long len = 0; 87 unsigned long len = 0;
73 int buf;
74 88
75 SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer; 89 SCpnt->SCp.buffer = scsi_sglist(SCpnt);
76 SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1; 90 SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
77 SCpnt->SCp.ptr = sg_virt(SCpnt->SCp.buffer); 91 SCpnt->SCp.ptr = sg_virt(SCpnt->SCp.buffer);
78 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; 92 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
79 SCpnt->SCp.phase = SCpnt->request_bufflen; 93 SCpnt->SCp.phase = scsi_bufflen(SCpnt);
80 94
81#ifdef BELT_AND_BRACES 95#ifdef BELT_AND_BRACES
82 /* 96 { /*
83 * Calculate correct buffer length. Some commands 97 * Calculate correct buffer length. Some commands
84 * come in with the wrong request_bufflen. 98 * come in with the wrong scsi_bufflen.
85 */ 99 */
86 for (buf = 0; buf <= SCpnt->SCp.buffers_residual; buf++) 100 struct scatterlist *sg;
87 len += SCpnt->SCp.buffer[buf].length; 101 unsigned i, sg_count = scsi_sg_count(SCpnt);
88 102
89 if (SCpnt->request_bufflen != len) 103 scsi_for_each_sg(SCpnt, sg, sg_count, i)
90 printk(KERN_WARNING "scsi%d.%c: bad request buffer " 104 len += sg->length;
91 "length %d, should be %ld\n", SCpnt->device->host->host_no, 105
92 '0' + SCpnt->device->id, SCpnt->request_bufflen, len); 106 if (scsi_bufflen(SCpnt) != len) {
93 SCpnt->request_bufflen = len; 107 printk(KERN_WARNING
108 "scsi%d.%c: bad request buffer "
109 "length %d, should be %ld\n",
110 SCpnt->device->host->host_no,
111 '0' + SCpnt->device->id,
112 scsi_bufflen(SCpnt), len);
113 /*
114 * FIXME: Totaly naive fixup. We should abort
115 * with error
116 */
117 SCpnt->SCp.phase =
118 min_t(unsigned long, len,
119 scsi_bufflen(SCpnt));
120 }
121 }
94#endif 122#endif
95 } else { 123 } else {
96 SCpnt->SCp.ptr = (unsigned char *)SCpnt->request_buffer;
97 SCpnt->SCp.this_residual = SCpnt->request_bufflen;
98 SCpnt->SCp.phase = SCpnt->request_bufflen;
99 }
100
101 /*
102 * If the upper SCSI layers pass a buffer, but zero length,
103 * we aren't interested in the buffer pointer.
104 */
105 if (SCpnt->SCp.this_residual == 0 && SCpnt->SCp.ptr) {
106#if 0 //def BELT_AND_BRACES
107 printk(KERN_WARNING "scsi%d.%c: zero length buffer passed for "
108 "command ", SCpnt->host->host_no, '0' + SCpnt->target);
109 __scsi_print_command(SCpnt->cmnd);
110#endif
111 SCpnt->SCp.ptr = NULL; 124 SCpnt->SCp.ptr = NULL;
125 SCpnt->SCp.this_residual = 0;
126 SCpnt->SCp.phase = 0;
112 } 127 }
113} 128}
diff --git a/drivers/scsi/blz1230.c b/drivers/scsi/blz1230.c
deleted file mode 100644
index 23f7c24ab809..000000000000
--- a/drivers/scsi/blz1230.c
+++ /dev/null
@@ -1,353 +0,0 @@
1/* blz1230.c: Driver for Blizzard 1230 SCSI IV Controller.
2 *
3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
4 *
5 * This driver is based on the CyberStorm driver, hence the occasional
6 * reference to CyberStorm.
7 */
8
9/* TODO:
10 *
11 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
12 * to the caches and the Sparc MMU mapping.
13 * 2) Make as few routines required outside the generic driver. A lot of the
14 * routines in this file used to be inline!
15 */
16
17#include <linux/module.h>
18
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/delay.h>
22#include <linux/types.h>
23#include <linux/string.h>
24#include <linux/slab.h>
25#include <linux/blkdev.h>
26#include <linux/proc_fs.h>
27#include <linux/stat.h>
28#include <linux/interrupt.h>
29
30#include "scsi.h"
31#include <scsi/scsi_host.h>
32#include "NCR53C9x.h"
33
34#include <linux/zorro.h>
35#include <asm/irq.h>
36#include <asm/amigaints.h>
37#include <asm/amigahw.h>
38
39#include <asm/pgtable.h>
40
41#define MKIV 1
42
43/* The controller registers can be found in the Z2 config area at these
44 * offsets:
45 */
46#define BLZ1230_ESP_ADDR 0x8000
47#define BLZ1230_DMA_ADDR 0x10000
48#define BLZ1230II_ESP_ADDR 0x10000
49#define BLZ1230II_DMA_ADDR 0x10021
50
51
52/* The Blizzard 1230 DMA interface
53 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54 * Only two things can be programmed in the Blizzard DMA:
55 * 1) The data direction is controlled by the status of bit 31 (1 = write)
56 * 2) The source/dest address (word aligned, shifted one right) in bits 30-0
57 *
58 * Program DMA by first latching the highest byte of the address/direction
59 * (i.e. bits 31-24 of the long word constructed as described in steps 1+2
60 * above). Then write each byte of the address/direction (starting with the
61 * top byte, working down) to the DMA address register.
62 *
63 * Figure out interrupt status by reading the ESP status byte.
64 */
65struct blz1230_dma_registers {
66 volatile unsigned char dma_addr; /* DMA address [0x0000] */
67 unsigned char dmapad2[0x7fff];
68 volatile unsigned char dma_latch; /* DMA latch [0x8000] */
69};
70
71struct blz1230II_dma_registers {
72 volatile unsigned char dma_addr; /* DMA address [0x0000] */
73 unsigned char dmapad2[0xf];
74 volatile unsigned char dma_latch; /* DMA latch [0x0010] */
75};
76
77#define BLZ1230_DMA_WRITE 0x80000000
78
79static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
80static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
81static void dma_dump_state(struct NCR_ESP *esp);
82static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
83static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
84static void dma_ints_off(struct NCR_ESP *esp);
85static void dma_ints_on(struct NCR_ESP *esp);
86static int dma_irq_p(struct NCR_ESP *esp);
87static int dma_ports_p(struct NCR_ESP *esp);
88static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
89
90static volatile unsigned char cmd_buffer[16];
91 /* This is where all commands are put
92 * before they are transferred to the ESP chip
93 * via PIO.
94 */
95
96/***************************************************************** Detection */
97int __init blz1230_esp_detect(struct scsi_host_template *tpnt)
98{
99 struct NCR_ESP *esp;
100 struct zorro_dev *z = NULL;
101 unsigned long address;
102 struct ESP_regs *eregs;
103 unsigned long board;
104
105#if MKIV
106#define REAL_BLZ1230_ID ZORRO_PROD_PHASE5_BLIZZARD_1230_IV_1260
107#define REAL_BLZ1230_ESP_ADDR BLZ1230_ESP_ADDR
108#define REAL_BLZ1230_DMA_ADDR BLZ1230_DMA_ADDR
109#else
110#define REAL_BLZ1230_ID ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060
111#define REAL_BLZ1230_ESP_ADDR BLZ1230II_ESP_ADDR
112#define REAL_BLZ1230_DMA_ADDR BLZ1230II_DMA_ADDR
113#endif
114
115 if ((z = zorro_find_device(REAL_BLZ1230_ID, z))) {
116 board = z->resource.start;
117 if (request_mem_region(board+REAL_BLZ1230_ESP_ADDR,
118 sizeof(struct ESP_regs), "NCR53C9x")) {
119 /* Do some magic to figure out if the blizzard is
120 * equipped with a SCSI controller
121 */
122 address = ZTWO_VADDR(board);
123 eregs = (struct ESP_regs *)(address + REAL_BLZ1230_ESP_ADDR);
124 esp = esp_allocate(tpnt, (void *)board + REAL_BLZ1230_ESP_ADDR,
125 0);
126
127 esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
128 udelay(5);
129 if(esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7))
130 goto err_out;
131
132 /* Do command transfer with programmed I/O */
133 esp->do_pio_cmds = 1;
134
135 /* Required functions */
136 esp->dma_bytes_sent = &dma_bytes_sent;
137 esp->dma_can_transfer = &dma_can_transfer;
138 esp->dma_dump_state = &dma_dump_state;
139 esp->dma_init_read = &dma_init_read;
140 esp->dma_init_write = &dma_init_write;
141 esp->dma_ints_off = &dma_ints_off;
142 esp->dma_ints_on = &dma_ints_on;
143 esp->dma_irq_p = &dma_irq_p;
144 esp->dma_ports_p = &dma_ports_p;
145 esp->dma_setup = &dma_setup;
146
147 /* Optional functions */
148 esp->dma_barrier = 0;
149 esp->dma_drain = 0;
150 esp->dma_invalidate = 0;
151 esp->dma_irq_entry = 0;
152 esp->dma_irq_exit = 0;
153 esp->dma_led_on = 0;
154 esp->dma_led_off = 0;
155 esp->dma_poll = 0;
156 esp->dma_reset = 0;
157
158 /* SCSI chip speed */
159 esp->cfreq = 40000000;
160
161 /* The DMA registers on the Blizzard are mapped
162 * relative to the device (i.e. in the same Zorro
163 * I/O block).
164 */
165 esp->dregs = (void *)(address + REAL_BLZ1230_DMA_ADDR);
166
167 /* ESP register base */
168 esp->eregs = eregs;
169
170 /* Set the command buffer */
171 esp->esp_command = cmd_buffer;
172 esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
173
174 esp->irq = IRQ_AMIGA_PORTS;
175 esp->slot = board+REAL_BLZ1230_ESP_ADDR;
176 if (request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
177 "Blizzard 1230 SCSI IV", esp->ehost))
178 goto err_out;
179
180 /* Figure out our scsi ID on the bus */
181 esp->scsi_id = 7;
182
183 /* We don't have a differential SCSI-bus. */
184 esp->diff = 0;
185
186 esp_initialize(esp);
187
188 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
189 esps_running = esps_in_use;
190 return esps_in_use;
191 }
192 }
193 return 0;
194
195 err_out:
196 scsi_unregister(esp->ehost);
197 esp_deallocate(esp);
198 release_mem_region(board+REAL_BLZ1230_ESP_ADDR,
199 sizeof(struct ESP_regs));
200 return 0;
201}
202
203/************************************************************* DMA Functions */
204static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
205{
206 /* Since the Blizzard DMA is fully dedicated to the ESP chip,
207 * the number of bytes sent (to the ESP chip) equals the number
208 * of bytes in the FIFO - there is no buffering in the DMA controller.
209 * XXXX Do I read this right? It is from host to ESP, right?
210 */
211 return fifo_count;
212}
213
214static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
215{
216 /* I don't think there's any limit on the Blizzard DMA. So we use what
217 * the ESP chip can handle (24 bit).
218 */
219 unsigned long sz = sp->SCp.this_residual;
220 if(sz > 0x1000000)
221 sz = 0x1000000;
222 return sz;
223}
224
225static void dma_dump_state(struct NCR_ESP *esp)
226{
227 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
228 amiga_custom.intreqr, amiga_custom.intenar));
229}
230
231void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
232{
233#if MKIV
234 struct blz1230_dma_registers *dregs =
235 (struct blz1230_dma_registers *) (esp->dregs);
236#else
237 struct blz1230II_dma_registers *dregs =
238 (struct blz1230II_dma_registers *) (esp->dregs);
239#endif
240
241 cache_clear(addr, length);
242
243 addr >>= 1;
244 addr &= ~(BLZ1230_DMA_WRITE);
245
246 /* First set latch */
247 dregs->dma_latch = (addr >> 24) & 0xff;
248
249 /* Then pump the address to the DMA address register */
250#if MKIV
251 dregs->dma_addr = (addr >> 24) & 0xff;
252#endif
253 dregs->dma_addr = (addr >> 16) & 0xff;
254 dregs->dma_addr = (addr >> 8) & 0xff;
255 dregs->dma_addr = (addr ) & 0xff;
256}
257
258void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
259{
260#if MKIV
261 struct blz1230_dma_registers *dregs =
262 (struct blz1230_dma_registers *) (esp->dregs);
263#else
264 struct blz1230II_dma_registers *dregs =
265 (struct blz1230II_dma_registers *) (esp->dregs);
266#endif
267
268 cache_push(addr, length);
269
270 addr >>= 1;
271 addr |= BLZ1230_DMA_WRITE;
272
273 /* First set latch */
274 dregs->dma_latch = (addr >> 24) & 0xff;
275
276 /* Then pump the address to the DMA address register */
277#if MKIV
278 dregs->dma_addr = (addr >> 24) & 0xff;
279#endif
280 dregs->dma_addr = (addr >> 16) & 0xff;
281 dregs->dma_addr = (addr >> 8) & 0xff;
282 dregs->dma_addr = (addr ) & 0xff;
283}
284
285static void dma_ints_off(struct NCR_ESP *esp)
286{
287 disable_irq(esp->irq);
288}
289
290static void dma_ints_on(struct NCR_ESP *esp)
291{
292 enable_irq(esp->irq);
293}
294
295static int dma_irq_p(struct NCR_ESP *esp)
296{
297 return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
298}
299
300static int dma_ports_p(struct NCR_ESP *esp)
301{
302 return ((amiga_custom.intenar) & IF_PORTS);
303}
304
305static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
306{
307 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
308 * so when (write) is true, it actually means READ!
309 */
310 if(write){
311 dma_init_read(esp, addr, count);
312 } else {
313 dma_init_write(esp, addr, count);
314 }
315}
316
317#define HOSTS_C
318
319int blz1230_esp_release(struct Scsi_Host *instance)
320{
321#ifdef MODULE
322 unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
323 esp_deallocate((struct NCR_ESP *)instance->hostdata);
324 esp_release();
325 release_mem_region(address, sizeof(struct ESP_regs));
326 free_irq(IRQ_AMIGA_PORTS, esp_intr);
327#endif
328 return 1;
329}
330
331
332static struct scsi_host_template driver_template = {
333 .proc_name = "esp-blz1230",
334 .proc_info = esp_proc_info,
335 .name = "Blizzard1230 SCSI IV",
336 .detect = blz1230_esp_detect,
337 .slave_alloc = esp_slave_alloc,
338 .slave_destroy = esp_slave_destroy,
339 .release = blz1230_esp_release,
340 .queuecommand = esp_queue,
341 .eh_abort_handler = esp_abort,
342 .eh_bus_reset_handler = esp_reset,
343 .can_queue = 7,
344 .this_id = 7,
345 .sg_tablesize = SG_ALL,
346 .cmd_per_lun = 1,
347 .use_clustering = ENABLE_CLUSTERING
348};
349
350
351#include "scsi_module.c"
352
353MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/blz2060.c b/drivers/scsi/blz2060.c
deleted file mode 100644
index b6203ec00961..000000000000
--- a/drivers/scsi/blz2060.c
+++ /dev/null
@@ -1,306 +0,0 @@
1/* blz2060.c: Driver for Blizzard 2060 SCSI Controller.
2 *
3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
4 *
5 * This driver is based on the CyberStorm driver, hence the occasional
6 * reference to CyberStorm.
7 */
8
9/* TODO:
10 *
11 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
12 * to the caches and the Sparc MMU mapping.
13 * 2) Make as few routines required outside the generic driver. A lot of the
14 * routines in this file used to be inline!
15 */
16
17#include <linux/module.h>
18
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/delay.h>
22#include <linux/types.h>
23#include <linux/string.h>
24#include <linux/slab.h>
25#include <linux/blkdev.h>
26#include <linux/proc_fs.h>
27#include <linux/stat.h>
28#include <linux/interrupt.h>
29
30#include "scsi.h"
31#include <scsi/scsi_host.h>
32#include "NCR53C9x.h"
33
34#include <linux/zorro.h>
35#include <asm/irq.h>
36#include <asm/amigaints.h>
37#include <asm/amigahw.h>
38
39#include <asm/pgtable.h>
40
41/* The controller registers can be found in the Z2 config area at these
42 * offsets:
43 */
44#define BLZ2060_ESP_ADDR 0x1ff00
45#define BLZ2060_DMA_ADDR 0x1ffe0
46
47
48/* The Blizzard 2060 DMA interface
49 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50 * Only two things can be programmed in the Blizzard DMA:
51 * 1) The data direction is controlled by the status of bit 31 (1 = write)
52 * 2) The source/dest address (word aligned, shifted one right) in bits 30-0
53 *
54 * Figure out interrupt status by reading the ESP status byte.
55 */
56struct blz2060_dma_registers {
57 volatile unsigned char dma_led_ctrl; /* DMA led control [0x000] */
58 unsigned char dmapad1[0x0f];
59 volatile unsigned char dma_addr0; /* DMA address (MSB) [0x010] */
60 unsigned char dmapad2[0x03];
61 volatile unsigned char dma_addr1; /* DMA address [0x014] */
62 unsigned char dmapad3[0x03];
63 volatile unsigned char dma_addr2; /* DMA address [0x018] */
64 unsigned char dmapad4[0x03];
65 volatile unsigned char dma_addr3; /* DMA address (LSB) [0x01c] */
66};
67
68#define BLZ2060_DMA_WRITE 0x80000000
69
70/* DMA control bits */
71#define BLZ2060_DMA_LED 0x02 /* HD led control 1 = off */
72
73static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
74static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
75static void dma_dump_state(struct NCR_ESP *esp);
76static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
77static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
78static void dma_ints_off(struct NCR_ESP *esp);
79static void dma_ints_on(struct NCR_ESP *esp);
80static int dma_irq_p(struct NCR_ESP *esp);
81static void dma_led_off(struct NCR_ESP *esp);
82static void dma_led_on(struct NCR_ESP *esp);
83static int dma_ports_p(struct NCR_ESP *esp);
84static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
85
86static volatile unsigned char cmd_buffer[16];
87 /* This is where all commands are put
88 * before they are transferred to the ESP chip
89 * via PIO.
90 */
91
92/***************************************************************** Detection */
93int __init blz2060_esp_detect(struct scsi_host_template *tpnt)
94{
95 struct NCR_ESP *esp;
96 struct zorro_dev *z = NULL;
97 unsigned long address;
98
99 if ((z = zorro_find_device(ZORRO_PROD_PHASE5_BLIZZARD_2060, z))) {
100 unsigned long board = z->resource.start;
101 if (request_mem_region(board+BLZ2060_ESP_ADDR,
102 sizeof(struct ESP_regs), "NCR53C9x")) {
103 esp = esp_allocate(tpnt, (void *)board + BLZ2060_ESP_ADDR, 0);
104
105 /* Do command transfer with programmed I/O */
106 esp->do_pio_cmds = 1;
107
108 /* Required functions */
109 esp->dma_bytes_sent = &dma_bytes_sent;
110 esp->dma_can_transfer = &dma_can_transfer;
111 esp->dma_dump_state = &dma_dump_state;
112 esp->dma_init_read = &dma_init_read;
113 esp->dma_init_write = &dma_init_write;
114 esp->dma_ints_off = &dma_ints_off;
115 esp->dma_ints_on = &dma_ints_on;
116 esp->dma_irq_p = &dma_irq_p;
117 esp->dma_ports_p = &dma_ports_p;
118 esp->dma_setup = &dma_setup;
119
120 /* Optional functions */
121 esp->dma_barrier = 0;
122 esp->dma_drain = 0;
123 esp->dma_invalidate = 0;
124 esp->dma_irq_entry = 0;
125 esp->dma_irq_exit = 0;
126 esp->dma_led_on = &dma_led_on;
127 esp->dma_led_off = &dma_led_off;
128 esp->dma_poll = 0;
129 esp->dma_reset = 0;
130
131 /* SCSI chip speed */
132 esp->cfreq = 40000000;
133
134 /* The DMA registers on the Blizzard are mapped
135 * relative to the device (i.e. in the same Zorro
136 * I/O block).
137 */
138 address = (unsigned long)ZTWO_VADDR(board);
139 esp->dregs = (void *)(address + BLZ2060_DMA_ADDR);
140
141 /* ESP register base */
142 esp->eregs = (struct ESP_regs *)(address + BLZ2060_ESP_ADDR);
143
144 /* Set the command buffer */
145 esp->esp_command = cmd_buffer;
146 esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
147
148 esp->irq = IRQ_AMIGA_PORTS;
149 request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
150 "Blizzard 2060 SCSI", esp->ehost);
151
152 /* Figure out our scsi ID on the bus */
153 esp->scsi_id = 7;
154
155 /* We don't have a differential SCSI-bus. */
156 esp->diff = 0;
157
158 esp_initialize(esp);
159
160 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
161 esps_running = esps_in_use;
162 return esps_in_use;
163 }
164 }
165 return 0;
166}
167
168/************************************************************* DMA Functions */
169static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
170{
171 /* Since the Blizzard DMA is fully dedicated to the ESP chip,
172 * the number of bytes sent (to the ESP chip) equals the number
173 * of bytes in the FIFO - there is no buffering in the DMA controller.
174 * XXXX Do I read this right? It is from host to ESP, right?
175 */
176 return fifo_count;
177}
178
179static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
180{
181 /* I don't think there's any limit on the Blizzard DMA. So we use what
182 * the ESP chip can handle (24 bit).
183 */
184 unsigned long sz = sp->SCp.this_residual;
185 if(sz > 0x1000000)
186 sz = 0x1000000;
187 return sz;
188}
189
190static void dma_dump_state(struct NCR_ESP *esp)
191{
192 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
193 amiga_custom.intreqr, amiga_custom.intenar));
194}
195
196static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
197{
198 struct blz2060_dma_registers *dregs =
199 (struct blz2060_dma_registers *) (esp->dregs);
200
201 cache_clear(addr, length);
202
203 addr >>= 1;
204 addr &= ~(BLZ2060_DMA_WRITE);
205 dregs->dma_addr3 = (addr ) & 0xff;
206 dregs->dma_addr2 = (addr >> 8) & 0xff;
207 dregs->dma_addr1 = (addr >> 16) & 0xff;
208 dregs->dma_addr0 = (addr >> 24) & 0xff;
209}
210
211static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
212{
213 struct blz2060_dma_registers *dregs =
214 (struct blz2060_dma_registers *) (esp->dregs);
215
216 cache_push(addr, length);
217
218 addr >>= 1;
219 addr |= BLZ2060_DMA_WRITE;
220 dregs->dma_addr3 = (addr ) & 0xff;
221 dregs->dma_addr2 = (addr >> 8) & 0xff;
222 dregs->dma_addr1 = (addr >> 16) & 0xff;
223 dregs->dma_addr0 = (addr >> 24) & 0xff;
224}
225
226static void dma_ints_off(struct NCR_ESP *esp)
227{
228 disable_irq(esp->irq);
229}
230
231static void dma_ints_on(struct NCR_ESP *esp)
232{
233 enable_irq(esp->irq);
234}
235
236static int dma_irq_p(struct NCR_ESP *esp)
237{
238 return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
239}
240
241static void dma_led_off(struct NCR_ESP *esp)
242{
243 ((struct blz2060_dma_registers *) (esp->dregs))->dma_led_ctrl =
244 BLZ2060_DMA_LED;
245}
246
247static void dma_led_on(struct NCR_ESP *esp)
248{
249 ((struct blz2060_dma_registers *) (esp->dregs))->dma_led_ctrl = 0;
250}
251
252static int dma_ports_p(struct NCR_ESP *esp)
253{
254 return ((amiga_custom.intenar) & IF_PORTS);
255}
256
257static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
258{
259 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
260 * so when (write) is true, it actually means READ!
261 */
262 if(write){
263 dma_init_read(esp, addr, count);
264 } else {
265 dma_init_write(esp, addr, count);
266 }
267}
268
269#define HOSTS_C
270
271int blz2060_esp_release(struct Scsi_Host *instance)
272{
273#ifdef MODULE
274 unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
275
276 esp_deallocate((struct NCR_ESP *)instance->hostdata);
277 esp_release();
278 release_mem_region(address, sizeof(struct ESP_regs));
279 free_irq(IRQ_AMIGA_PORTS, esp_intr);
280#endif
281 return 1;
282}
283
284
285static struct scsi_host_template driver_template = {
286 .proc_name = "esp-blz2060",
287 .proc_info = esp_proc_info,
288 .name = "Blizzard2060 SCSI",
289 .detect = blz2060_esp_detect,
290 .slave_alloc = esp_slave_alloc,
291 .slave_destroy = esp_slave_destroy,
292 .release = blz2060_esp_release,
293 .queuecommand = esp_queue,
294 .eh_abort_handler = esp_abort,
295 .eh_bus_reset_handler = esp_reset,
296 .can_queue = 7,
297 .this_id = 7,
298 .sg_tablesize = SG_ALL,
299 .cmd_per_lun = 1,
300 .use_clustering = ENABLE_CLUSTERING
301};
302
303
304#include "scsi_module.c"
305
306MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/cyberstorm.c b/drivers/scsi/cyberstorm.c
deleted file mode 100644
index c6b98a42e89d..000000000000
--- a/drivers/scsi/cyberstorm.c
+++ /dev/null
@@ -1,377 +0,0 @@
1/* cyberstorm.c: Driver for CyberStorm SCSI Controller.
2 *
3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
4 *
5 * The CyberStorm SCSI driver is based on David S. Miller's ESP driver
6 * for the Sparc computers.
7 *
8 * This work was made possible by Phase5 who willingly (and most generously)
9 * supported me with hardware and all the information I needed.
10 */
11
12/* TODO:
13 *
14 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
15 * to the caches and the Sparc MMU mapping.
16 * 2) Make as few routines required outside the generic driver. A lot of the
17 * routines in this file used to be inline!
18 */
19
20#include <linux/module.h>
21
22#include <linux/init.h>
23#include <linux/kernel.h>
24#include <linux/delay.h>
25#include <linux/types.h>
26#include <linux/string.h>
27#include <linux/slab.h>
28#include <linux/blkdev.h>
29#include <linux/proc_fs.h>
30#include <linux/stat.h>
31#include <linux/interrupt.h>
32
33#include "scsi.h"
34#include <scsi/scsi_host.h>
35#include "NCR53C9x.h"
36
37#include <linux/zorro.h>
38#include <asm/irq.h>
39#include <asm/amigaints.h>
40#include <asm/amigahw.h>
41
42#include <asm/pgtable.h>
43
44/* The controller registers can be found in the Z2 config area at these
45 * offsets:
46 */
47#define CYBER_ESP_ADDR 0xf400
48#define CYBER_DMA_ADDR 0xf800
49
50
51/* The CyberStorm DMA interface */
52struct cyber_dma_registers {
53 volatile unsigned char dma_addr0; /* DMA address (MSB) [0x000] */
54 unsigned char dmapad1[1];
55 volatile unsigned char dma_addr1; /* DMA address [0x002] */
56 unsigned char dmapad2[1];
57 volatile unsigned char dma_addr2; /* DMA address [0x004] */
58 unsigned char dmapad3[1];
59 volatile unsigned char dma_addr3; /* DMA address (LSB) [0x006] */
60 unsigned char dmapad4[0x3fb];
61 volatile unsigned char cond_reg; /* DMA cond (ro) [0x402] */
62#define ctrl_reg cond_reg /* DMA control (wo) [0x402] */
63};
64
65/* DMA control bits */
66#define CYBER_DMA_LED 0x80 /* HD led control 1 = on */
67#define CYBER_DMA_WRITE 0x40 /* DMA direction. 1 = write */
68#define CYBER_DMA_Z3 0x20 /* 16 (Z2) or 32 (CHIP/Z3) bit DMA transfer */
69
70/* DMA status bits */
71#define CYBER_DMA_HNDL_INTR 0x80 /* DMA IRQ pending? */
72
73/* The bits below appears to be Phase5 Debug bits only; they were not
74 * described by Phase5 so using them may seem a bit stupid...
75 */
76#define CYBER_HOST_ID 0x02 /* If set, host ID should be 7, otherwise
77 * it should be 6.
78 */
79#define CYBER_SLOW_CABLE 0x08 /* If *not* set, assume SLOW_CABLE */
80
81static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
82static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
83static void dma_dump_state(struct NCR_ESP *esp);
84static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
85static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
86static void dma_ints_off(struct NCR_ESP *esp);
87static void dma_ints_on(struct NCR_ESP *esp);
88static int dma_irq_p(struct NCR_ESP *esp);
89static void dma_led_off(struct NCR_ESP *esp);
90static void dma_led_on(struct NCR_ESP *esp);
91static int dma_ports_p(struct NCR_ESP *esp);
92static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
93
94static unsigned char ctrl_data = 0; /* Keep backup of the stuff written
95 * to ctrl_reg. Always write a copy
96 * to this register when writing to
97 * the hardware register!
98 */
99
100static volatile unsigned char cmd_buffer[16];
101 /* This is where all commands are put
102 * before they are transferred to the ESP chip
103 * via PIO.
104 */
105
106/***************************************************************** Detection */
107int __init cyber_esp_detect(struct scsi_host_template *tpnt)
108{
109 struct NCR_ESP *esp;
110 struct zorro_dev *z = NULL;
111 unsigned long address;
112
113 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
114 unsigned long board = z->resource.start;
115 if ((z->id == ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM ||
116 z->id == ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060) &&
117 request_mem_region(board+CYBER_ESP_ADDR,
118 sizeof(struct ESP_regs), "NCR53C9x")) {
119 /* Figure out if this is a CyberStorm or really a
120 * Fastlane/Blizzard Mk II by looking at the board size.
121 * CyberStorm maps 64kB
122 * (ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM does anyway)
123 */
124 if(z->resource.end-board != 0xffff) {
125 release_mem_region(board+CYBER_ESP_ADDR,
126 sizeof(struct ESP_regs));
127 return 0;
128 }
129 esp = esp_allocate(tpnt, (void *)board + CYBER_ESP_ADDR, 0);
130
131 /* Do command transfer with programmed I/O */
132 esp->do_pio_cmds = 1;
133
134 /* Required functions */
135 esp->dma_bytes_sent = &dma_bytes_sent;
136 esp->dma_can_transfer = &dma_can_transfer;
137 esp->dma_dump_state = &dma_dump_state;
138 esp->dma_init_read = &dma_init_read;
139 esp->dma_init_write = &dma_init_write;
140 esp->dma_ints_off = &dma_ints_off;
141 esp->dma_ints_on = &dma_ints_on;
142 esp->dma_irq_p = &dma_irq_p;
143 esp->dma_ports_p = &dma_ports_p;
144 esp->dma_setup = &dma_setup;
145
146 /* Optional functions */
147 esp->dma_barrier = 0;
148 esp->dma_drain = 0;
149 esp->dma_invalidate = 0;
150 esp->dma_irq_entry = 0;
151 esp->dma_irq_exit = 0;
152 esp->dma_led_on = &dma_led_on;
153 esp->dma_led_off = &dma_led_off;
154 esp->dma_poll = 0;
155 esp->dma_reset = 0;
156
157 /* SCSI chip speed */
158 esp->cfreq = 40000000;
159
160 /* The DMA registers on the CyberStorm are mapped
161 * relative to the device (i.e. in the same Zorro
162 * I/O block).
163 */
164 address = (unsigned long)ZTWO_VADDR(board);
165 esp->dregs = (void *)(address + CYBER_DMA_ADDR);
166
167 /* ESP register base */
168 esp->eregs = (struct ESP_regs *)(address + CYBER_ESP_ADDR);
169
170 /* Set the command buffer */
171 esp->esp_command = cmd_buffer;
172 esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
173
174 esp->irq = IRQ_AMIGA_PORTS;
175 request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
176 "CyberStorm SCSI", esp->ehost);
177 /* Figure out our scsi ID on the bus */
178 /* The DMA cond flag contains a hardcoded jumper bit
179 * which can be used to select host number 6 or 7.
180 * However, even though it may change, we use a hardcoded
181 * value of 7.
182 */
183 esp->scsi_id = 7;
184
185 /* We don't have a differential SCSI-bus. */
186 esp->diff = 0;
187
188 esp_initialize(esp);
189
190 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
191 esps_running = esps_in_use;
192 return esps_in_use;
193 }
194 }
195 return 0;
196}
197
198/************************************************************* DMA Functions */
199static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
200{
201 /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
202 * the number of bytes sent (to the ESP chip) equals the number
203 * of bytes in the FIFO - there is no buffering in the DMA controller.
204 * XXXX Do I read this right? It is from host to ESP, right?
205 */
206 return fifo_count;
207}
208
209static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
210{
211 /* I don't think there's any limit on the CyberDMA. So we use what
212 * the ESP chip can handle (24 bit).
213 */
214 unsigned long sz = sp->SCp.this_residual;
215 if(sz > 0x1000000)
216 sz = 0x1000000;
217 return sz;
218}
219
220static void dma_dump_state(struct NCR_ESP *esp)
221{
222 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
223 esp->esp_id, ((struct cyber_dma_registers *)
224 (esp->dregs))->cond_reg));
225 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
226 amiga_custom.intreqr, amiga_custom.intenar));
227}
228
229static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
230{
231 struct cyber_dma_registers *dregs =
232 (struct cyber_dma_registers *) esp->dregs;
233
234 cache_clear(addr, length);
235
236 addr &= ~(1);
237 dregs->dma_addr0 = (addr >> 24) & 0xff;
238 dregs->dma_addr1 = (addr >> 16) & 0xff;
239 dregs->dma_addr2 = (addr >> 8) & 0xff;
240 dregs->dma_addr3 = (addr ) & 0xff;
241 ctrl_data &= ~(CYBER_DMA_WRITE);
242
243 /* Check if physical address is outside Z2 space and of
244 * block length/block aligned in memory. If this is the
245 * case, enable 32 bit transfer. In all other cases, fall back
246 * to 16 bit transfer.
247 * Obviously 32 bit transfer should be enabled if the DMA address
248 * and length are 32 bit aligned. However, this leads to some
249 * strange behavior. Even 64 bit aligned addr/length fails.
250 * Until I've found a reason for this, 32 bit transfer is only
251 * used for full-block transfers (1kB).
252 * -jskov
253 */
254#if 0
255 if((addr & 0x3fc) || length & 0x3ff || ((addr > 0x200000) &&
256 (addr < 0xff0000)))
257 ctrl_data &= ~(CYBER_DMA_Z3); /* Z2, do 16 bit DMA */
258 else
259 ctrl_data |= CYBER_DMA_Z3; /* CHIP/Z3, do 32 bit DMA */
260#else
261 ctrl_data &= ~(CYBER_DMA_Z3); /* Z2, do 16 bit DMA */
262#endif
263 dregs->ctrl_reg = ctrl_data;
264}
265
266static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
267{
268 struct cyber_dma_registers *dregs =
269 (struct cyber_dma_registers *) esp->dregs;
270
271 cache_push(addr, length);
272
273 addr |= 1;
274 dregs->dma_addr0 = (addr >> 24) & 0xff;
275 dregs->dma_addr1 = (addr >> 16) & 0xff;
276 dregs->dma_addr2 = (addr >> 8) & 0xff;
277 dregs->dma_addr3 = (addr ) & 0xff;
278 ctrl_data |= CYBER_DMA_WRITE;
279
280 /* See comment above */
281#if 0
282 if((addr & 0x3fc) || length & 0x3ff || ((addr > 0x200000) &&
283 (addr < 0xff0000)))
284 ctrl_data &= ~(CYBER_DMA_Z3); /* Z2, do 16 bit DMA */
285 else
286 ctrl_data |= CYBER_DMA_Z3; /* CHIP/Z3, do 32 bit DMA */
287#else
288 ctrl_data &= ~(CYBER_DMA_Z3); /* Z2, do 16 bit DMA */
289#endif
290 dregs->ctrl_reg = ctrl_data;
291}
292
293static void dma_ints_off(struct NCR_ESP *esp)
294{
295 disable_irq(esp->irq);
296}
297
298static void dma_ints_on(struct NCR_ESP *esp)
299{
300 enable_irq(esp->irq);
301}
302
303static int dma_irq_p(struct NCR_ESP *esp)
304{
305 /* It's important to check the DMA IRQ bit in the correct way! */
306 return ((esp_read(esp->eregs->esp_status) & ESP_STAT_INTR) &&
307 ((((struct cyber_dma_registers *)(esp->dregs))->cond_reg) &
308 CYBER_DMA_HNDL_INTR));
309}
310
311static void dma_led_off(struct NCR_ESP *esp)
312{
313 ctrl_data &= ~CYBER_DMA_LED;
314 ((struct cyber_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
315}
316
317static void dma_led_on(struct NCR_ESP *esp)
318{
319 ctrl_data |= CYBER_DMA_LED;
320 ((struct cyber_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
321}
322
323static int dma_ports_p(struct NCR_ESP *esp)
324{
325 return ((amiga_custom.intenar) & IF_PORTS);
326}
327
328static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
329{
330 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
331 * so when (write) is true, it actually means READ!
332 */
333 if(write){
334 dma_init_read(esp, addr, count);
335 } else {
336 dma_init_write(esp, addr, count);
337 }
338}
339
340#define HOSTS_C
341
342int cyber_esp_release(struct Scsi_Host *instance)
343{
344#ifdef MODULE
345 unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
346
347 esp_deallocate((struct NCR_ESP *)instance->hostdata);
348 esp_release();
349 release_mem_region(address, sizeof(struct ESP_regs));
350 free_irq(IRQ_AMIGA_PORTS, esp_intr);
351#endif
352 return 1;
353}
354
355
356static struct scsi_host_template driver_template = {
357 .proc_name = "esp-cyberstorm",
358 .proc_info = esp_proc_info,
359 .name = "CyberStorm SCSI",
360 .detect = cyber_esp_detect,
361 .slave_alloc = esp_slave_alloc,
362 .slave_destroy = esp_slave_destroy,
363 .release = cyber_esp_release,
364 .queuecommand = esp_queue,
365 .eh_abort_handler = esp_abort,
366 .eh_bus_reset_handler = esp_reset,
367 .can_queue = 7,
368 .this_id = 7,
369 .sg_tablesize = SG_ALL,
370 .cmd_per_lun = 1,
371 .use_clustering = ENABLE_CLUSTERING
372};
373
374
375#include "scsi_module.c"
376
377MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/cyberstormII.c b/drivers/scsi/cyberstormII.c
deleted file mode 100644
index e336e853e66f..000000000000
--- a/drivers/scsi/cyberstormII.c
+++ /dev/null
@@ -1,314 +0,0 @@
1/* cyberstormII.c: Driver for CyberStorm SCSI Mk II
2 *
3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
4 *
5 * This driver is based on cyberstorm.c
6 */
7
8/* TODO:
9 *
10 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
11 * to the caches and the Sparc MMU mapping.
12 * 2) Make as few routines required outside the generic driver. A lot of the
13 * routines in this file used to be inline!
14 */
15
16#include <linux/module.h>
17
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/delay.h>
21#include <linux/types.h>
22#include <linux/string.h>
23#include <linux/slab.h>
24#include <linux/blkdev.h>
25#include <linux/proc_fs.h>
26#include <linux/stat.h>
27#include <linux/interrupt.h>
28
29#include "scsi.h"
30#include <scsi/scsi_host.h>
31#include "NCR53C9x.h"
32
33#include <linux/zorro.h>
34#include <asm/irq.h>
35#include <asm/amigaints.h>
36#include <asm/amigahw.h>
37
38#include <asm/pgtable.h>
39
40/* The controller registers can be found in the Z2 config area at these
41 * offsets:
42 */
43#define CYBERII_ESP_ADDR 0x1ff03
44#define CYBERII_DMA_ADDR 0x1ff43
45
46
47/* The CyberStorm II DMA interface */
48struct cyberII_dma_registers {
49 volatile unsigned char cond_reg; /* DMA cond (ro) [0x000] */
50#define ctrl_reg cond_reg /* DMA control (wo) [0x000] */
51 unsigned char dmapad4[0x3f];
52 volatile unsigned char dma_addr0; /* DMA address (MSB) [0x040] */
53 unsigned char dmapad1[3];
54 volatile unsigned char dma_addr1; /* DMA address [0x044] */
55 unsigned char dmapad2[3];
56 volatile unsigned char dma_addr2; /* DMA address [0x048] */
57 unsigned char dmapad3[3];
58 volatile unsigned char dma_addr3; /* DMA address (LSB) [0x04c] */
59};
60
61/* DMA control bits */
62#define CYBERII_DMA_LED 0x02 /* HD led control 1 = on */
63
64static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
65static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
66static void dma_dump_state(struct NCR_ESP *esp);
67static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
68static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
69static void dma_ints_off(struct NCR_ESP *esp);
70static void dma_ints_on(struct NCR_ESP *esp);
71static int dma_irq_p(struct NCR_ESP *esp);
72static void dma_led_off(struct NCR_ESP *esp);
73static void dma_led_on(struct NCR_ESP *esp);
74static int dma_ports_p(struct NCR_ESP *esp);
75static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
76
77static volatile unsigned char cmd_buffer[16];
78 /* This is where all commands are put
79 * before they are transferred to the ESP chip
80 * via PIO.
81 */
82
83/***************************************************************** Detection */
84int __init cyberII_esp_detect(struct scsi_host_template *tpnt)
85{
86 struct NCR_ESP *esp;
87 struct zorro_dev *z = NULL;
88 unsigned long address;
89 struct ESP_regs *eregs;
90
91 if ((z = zorro_find_device(ZORRO_PROD_PHASE5_CYBERSTORM_MK_II, z))) {
92 unsigned long board = z->resource.start;
93 if (request_mem_region(board+CYBERII_ESP_ADDR,
94 sizeof(struct ESP_regs), "NCR53C9x")) {
95 /* Do some magic to figure out if the CyberStorm Mk II
96 * is equipped with a SCSI controller
97 */
98 address = (unsigned long)ZTWO_VADDR(board);
99 eregs = (struct ESP_regs *)(address + CYBERII_ESP_ADDR);
100
101 esp = esp_allocate(tpnt, (void *)board + CYBERII_ESP_ADDR, 0);
102
103 esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
104 udelay(5);
105 if(esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7)) {
106 esp_deallocate(esp);
107 scsi_unregister(esp->ehost);
108 release_mem_region(board+CYBERII_ESP_ADDR,
109 sizeof(struct ESP_regs));
110 return 0; /* Bail out if address did not hold data */
111 }
112
113 /* Do command transfer with programmed I/O */
114 esp->do_pio_cmds = 1;
115
116 /* Required functions */
117 esp->dma_bytes_sent = &dma_bytes_sent;
118 esp->dma_can_transfer = &dma_can_transfer;
119 esp->dma_dump_state = &dma_dump_state;
120 esp->dma_init_read = &dma_init_read;
121 esp->dma_init_write = &dma_init_write;
122 esp->dma_ints_off = &dma_ints_off;
123 esp->dma_ints_on = &dma_ints_on;
124 esp->dma_irq_p = &dma_irq_p;
125 esp->dma_ports_p = &dma_ports_p;
126 esp->dma_setup = &dma_setup;
127
128 /* Optional functions */
129 esp->dma_barrier = 0;
130 esp->dma_drain = 0;
131 esp->dma_invalidate = 0;
132 esp->dma_irq_entry = 0;
133 esp->dma_irq_exit = 0;
134 esp->dma_led_on = &dma_led_on;
135 esp->dma_led_off = &dma_led_off;
136 esp->dma_poll = 0;
137 esp->dma_reset = 0;
138
139 /* SCSI chip speed */
140 esp->cfreq = 40000000;
141
142 /* The DMA registers on the CyberStorm are mapped
143 * relative to the device (i.e. in the same Zorro
144 * I/O block).
145 */
146 esp->dregs = (void *)(address + CYBERII_DMA_ADDR);
147
148 /* ESP register base */
149 esp->eregs = eregs;
150
151 /* Set the command buffer */
152 esp->esp_command = cmd_buffer;
153 esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
154
155 esp->irq = IRQ_AMIGA_PORTS;
156 request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
157 "CyberStorm SCSI Mk II", esp->ehost);
158
159 /* Figure out our scsi ID on the bus */
160 esp->scsi_id = 7;
161
162 /* We don't have a differential SCSI-bus. */
163 esp->diff = 0;
164
165 esp_initialize(esp);
166
167 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
168 esps_running = esps_in_use;
169 return esps_in_use;
170 }
171 }
172 return 0;
173}
174
175/************************************************************* DMA Functions */
176static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
177{
178 /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
179 * the number of bytes sent (to the ESP chip) equals the number
180 * of bytes in the FIFO - there is no buffering in the DMA controller.
181 * XXXX Do I read this right? It is from host to ESP, right?
182 */
183 return fifo_count;
184}
185
186static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
187{
188 /* I don't think there's any limit on the CyberDMA. So we use what
189 * the ESP chip can handle (24 bit).
190 */
191 unsigned long sz = sp->SCp.this_residual;
192 if(sz > 0x1000000)
193 sz = 0x1000000;
194 return sz;
195}
196
197static void dma_dump_state(struct NCR_ESP *esp)
198{
199 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
200 esp->esp_id, ((struct cyberII_dma_registers *)
201 (esp->dregs))->cond_reg));
202 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
203 amiga_custom.intreqr, amiga_custom.intenar));
204}
205
206static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
207{
208 struct cyberII_dma_registers *dregs =
209 (struct cyberII_dma_registers *) esp->dregs;
210
211 cache_clear(addr, length);
212
213 addr &= ~(1);
214 dregs->dma_addr0 = (addr >> 24) & 0xff;
215 dregs->dma_addr1 = (addr >> 16) & 0xff;
216 dregs->dma_addr2 = (addr >> 8) & 0xff;
217 dregs->dma_addr3 = (addr ) & 0xff;
218}
219
220static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
221{
222 struct cyberII_dma_registers *dregs =
223 (struct cyberII_dma_registers *) esp->dregs;
224
225 cache_push(addr, length);
226
227 addr |= 1;
228 dregs->dma_addr0 = (addr >> 24) & 0xff;
229 dregs->dma_addr1 = (addr >> 16) & 0xff;
230 dregs->dma_addr2 = (addr >> 8) & 0xff;
231 dregs->dma_addr3 = (addr ) & 0xff;
232}
233
234static void dma_ints_off(struct NCR_ESP *esp)
235{
236 disable_irq(esp->irq);
237}
238
239static void dma_ints_on(struct NCR_ESP *esp)
240{
241 enable_irq(esp->irq);
242}
243
244static int dma_irq_p(struct NCR_ESP *esp)
245{
246 /* It's important to check the DMA IRQ bit in the correct way! */
247 return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
248}
249
250static void dma_led_off(struct NCR_ESP *esp)
251{
252 ((struct cyberII_dma_registers *)(esp->dregs))->ctrl_reg &= ~CYBERII_DMA_LED;
253}
254
255static void dma_led_on(struct NCR_ESP *esp)
256{
257 ((struct cyberII_dma_registers *)(esp->dregs))->ctrl_reg |= CYBERII_DMA_LED;
258}
259
260static int dma_ports_p(struct NCR_ESP *esp)
261{
262 return ((amiga_custom.intenar) & IF_PORTS);
263}
264
265static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
266{
267 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
268 * so when (write) is true, it actually means READ!
269 */
270 if(write){
271 dma_init_read(esp, addr, count);
272 } else {
273 dma_init_write(esp, addr, count);
274 }
275}
276
277#define HOSTS_C
278
279int cyberII_esp_release(struct Scsi_Host *instance)
280{
281#ifdef MODULE
282 unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
283
284 esp_deallocate((struct NCR_ESP *)instance->hostdata);
285 esp_release();
286 release_mem_region(address, sizeof(struct ESP_regs));
287 free_irq(IRQ_AMIGA_PORTS, esp_intr);
288#endif
289 return 1;
290}
291
292
293static struct scsi_host_template driver_template = {
294 .proc_name = "esp-cyberstormII",
295 .proc_info = esp_proc_info,
296 .name = "CyberStorm Mk II SCSI",
297 .detect = cyberII_esp_detect,
298 .slave_alloc = esp_slave_alloc,
299 .slave_destroy = esp_slave_destroy,
300 .release = cyberII_esp_release,
301 .queuecommand = esp_queue,
302 .eh_abort_handler = esp_abort,
303 .eh_bus_reset_handler = esp_reset,
304 .can_queue = 7,
305 .this_id = 7,
306 .sg_tablesize = SG_ALL,
307 .cmd_per_lun = 1,
308 .use_clustering = ENABLE_CLUSTERING
309};
310
311
312#include "scsi_module.c"
313
314MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index 22ef3716e786..e351db6c0077 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -4267,7 +4267,7 @@ static int __devinit adapter_sg_tables_alloc(struct AdapterCtlBlk *acb)
4267 const unsigned srbs_per_page = PAGE_SIZE/SEGMENTX_LEN; 4267 const unsigned srbs_per_page = PAGE_SIZE/SEGMENTX_LEN;
4268 int srb_idx = 0; 4268 int srb_idx = 0;
4269 unsigned i = 0; 4269 unsigned i = 0;
4270 struct SGentry *ptr; 4270 struct SGentry *uninitialized_var(ptr);
4271 4271
4272 for (i = 0; i < DC395x_MAX_SRB_CNT; i++) 4272 for (i = 0; i < DC395x_MAX_SRB_CNT; i++)
4273 acb->srb_array[i].segment_x = NULL; 4273 acb->srb_array[i].segment_x = NULL;
diff --git a/drivers/scsi/dec_esp.c b/drivers/scsi/dec_esp.c
deleted file mode 100644
index d42ad663ffee..000000000000
--- a/drivers/scsi/dec_esp.c
+++ /dev/null
@@ -1,687 +0,0 @@
1/*
2 * dec_esp.c: Driver for SCSI chips on IOASIC based TURBOchannel DECstations
3 * and TURBOchannel PMAZ-A cards
4 *
5 * TURBOchannel changes by Harald Koerfgen
6 * PMAZ-A support by David Airlie
7 *
8 * based on jazz_esp.c:
9 * Copyright (C) 1997 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
10 *
11 * jazz_esp is based on David S. Miller's ESP driver and cyber_esp
12 *
13 * 20000819 - Small PMAZ-AA fixes by Florian Lohoff <flo@rfc822.org>
14 * Be warned the PMAZ-AA works currently as a single card.
15 * Dont try to put multiple cards in one machine - They are
16 * both detected but it may crash under high load garbling your
17 * data.
18 * 20001005 - Initialization fixes for 2.4.0-test9
19 * Florian Lohoff <flo@rfc822.org>
20 *
21 * Copyright (C) 2002, 2003, 2005, 2006 Maciej W. Rozycki
22 */
23
24#include <linux/kernel.h>
25#include <linux/delay.h>
26#include <linux/types.h>
27#include <linux/string.h>
28#include <linux/slab.h>
29#include <linux/blkdev.h>
30#include <linux/proc_fs.h>
31#include <linux/spinlock.h>
32#include <linux/stat.h>
33#include <linux/tc.h>
34
35#include <asm/dma.h>
36#include <asm/irq.h>
37#include <asm/pgtable.h>
38#include <asm/system.h>
39
40#include <asm/dec/interrupts.h>
41#include <asm/dec/ioasic.h>
42#include <asm/dec/ioasic_addrs.h>
43#include <asm/dec/ioasic_ints.h>
44#include <asm/dec/machtype.h>
45#include <asm/dec/system.h>
46
47#define DEC_SCSI_SREG 0
48#define DEC_SCSI_DMAREG 0x40000
49#define DEC_SCSI_SRAM 0x80000
50#define DEC_SCSI_DIAG 0xC0000
51
52#include "scsi.h"
53#include <scsi/scsi_host.h>
54#include "NCR53C9x.h"
55
56static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
57static void dma_drain(struct NCR_ESP *esp);
58static int dma_can_transfer(struct NCR_ESP *esp, struct scsi_cmnd *sp);
59static void dma_dump_state(struct NCR_ESP *esp);
60static void dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length);
61static void dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length);
62static void dma_ints_off(struct NCR_ESP *esp);
63static void dma_ints_on(struct NCR_ESP *esp);
64static int dma_irq_p(struct NCR_ESP *esp);
65static int dma_ports_p(struct NCR_ESP *esp);
66static void dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write);
67static void dma_mmu_get_scsi_one(struct NCR_ESP *esp, struct scsi_cmnd * sp);
68static void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, struct scsi_cmnd * sp);
69static void dma_advance_sg(struct scsi_cmnd * sp);
70
71static void pmaz_dma_drain(struct NCR_ESP *esp);
72static void pmaz_dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length);
73static void pmaz_dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length);
74static void pmaz_dma_ints_off(struct NCR_ESP *esp);
75static void pmaz_dma_ints_on(struct NCR_ESP *esp);
76static void pmaz_dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write);
77static void pmaz_dma_mmu_get_scsi_one(struct NCR_ESP *esp, struct scsi_cmnd * sp);
78
79#define TC_ESP_RAM_SIZE 0x20000
80#define ESP_TGT_DMA_SIZE ((TC_ESP_RAM_SIZE/7) & ~(sizeof(int)-1))
81#define ESP_NCMD 7
82
83#define TC_ESP_DMAR_MASK 0x1ffff
84#define TC_ESP_DMAR_WRITE 0x80000000
85#define TC_ESP_DMA_ADDR(x) ((unsigned)(x) & TC_ESP_DMAR_MASK)
86
87u32 esp_virt_buffer;
88int scsi_current_length;
89
90volatile unsigned char cmd_buffer[16];
91volatile unsigned char pmaz_cmd_buffer[16];
92 /* This is where all commands are put
93 * before they are trasfered to the ESP chip
94 * via PIO.
95 */
96
97static irqreturn_t scsi_dma_merr_int(int, void *);
98static irqreturn_t scsi_dma_err_int(int, void *);
99static irqreturn_t scsi_dma_int(int, void *);
100
101static struct scsi_host_template dec_esp_template = {
102 .module = THIS_MODULE,
103 .name = "NCR53C94",
104 .info = esp_info,
105 .queuecommand = esp_queue,
106 .eh_abort_handler = esp_abort,
107 .eh_bus_reset_handler = esp_reset,
108 .slave_alloc = esp_slave_alloc,
109 .slave_destroy = esp_slave_destroy,
110 .proc_info = esp_proc_info,
111 .proc_name = "dec_esp",
112 .can_queue = 7,
113 .sg_tablesize = SG_ALL,
114 .cmd_per_lun = 1,
115 .use_clustering = DISABLE_CLUSTERING,
116};
117
118static struct NCR_ESP *dec_esp_platform;
119
120/***************************************************************** Detection */
121static int dec_esp_platform_probe(void)
122{
123 struct NCR_ESP *esp;
124 int err = 0;
125
126 if (IOASIC) {
127 esp = esp_allocate(&dec_esp_template, NULL, 1);
128
129 /* Do command transfer with programmed I/O */
130 esp->do_pio_cmds = 1;
131
132 /* Required functions */
133 esp->dma_bytes_sent = &dma_bytes_sent;
134 esp->dma_can_transfer = &dma_can_transfer;
135 esp->dma_dump_state = &dma_dump_state;
136 esp->dma_init_read = &dma_init_read;
137 esp->dma_init_write = &dma_init_write;
138 esp->dma_ints_off = &dma_ints_off;
139 esp->dma_ints_on = &dma_ints_on;
140 esp->dma_irq_p = &dma_irq_p;
141 esp->dma_ports_p = &dma_ports_p;
142 esp->dma_setup = &dma_setup;
143
144 /* Optional functions */
145 esp->dma_barrier = 0;
146 esp->dma_drain = &dma_drain;
147 esp->dma_invalidate = 0;
148 esp->dma_irq_entry = 0;
149 esp->dma_irq_exit = 0;
150 esp->dma_poll = 0;
151 esp->dma_reset = 0;
152 esp->dma_led_off = 0;
153 esp->dma_led_on = 0;
154
155 /* virtual DMA functions */
156 esp->dma_mmu_get_scsi_one = &dma_mmu_get_scsi_one;
157 esp->dma_mmu_get_scsi_sgl = &dma_mmu_get_scsi_sgl;
158 esp->dma_mmu_release_scsi_one = 0;
159 esp->dma_mmu_release_scsi_sgl = 0;
160 esp->dma_advance_sg = &dma_advance_sg;
161
162
163 /* SCSI chip speed */
164 esp->cfreq = 25000000;
165
166 esp->dregs = 0;
167
168 /* ESP register base */
169 esp->eregs = (void *)CKSEG1ADDR(dec_kn_slot_base +
170 IOASIC_SCSI);
171
172 /* Set the command buffer */
173 esp->esp_command = (volatile unsigned char *) cmd_buffer;
174
175 /* get virtual dma address for command buffer */
176 esp->esp_command_dvma = virt_to_phys(cmd_buffer);
177
178 esp->irq = dec_interrupt[DEC_IRQ_ASC];
179
180 esp->scsi_id = 7;
181
182 /* Check for differential SCSI-bus */
183 esp->diff = 0;
184
185 err = request_irq(esp->irq, esp_intr, IRQF_DISABLED,
186 "ncr53c94", esp->ehost);
187 if (err)
188 goto err_alloc;
189 err = request_irq(dec_interrupt[DEC_IRQ_ASC_MERR],
190 scsi_dma_merr_int, IRQF_DISABLED,
191 "ncr53c94 error", esp->ehost);
192 if (err)
193 goto err_irq;
194 err = request_irq(dec_interrupt[DEC_IRQ_ASC_ERR],
195 scsi_dma_err_int, IRQF_DISABLED,
196 "ncr53c94 overrun", esp->ehost);
197 if (err)
198 goto err_irq_merr;
199 err = request_irq(dec_interrupt[DEC_IRQ_ASC_DMA], scsi_dma_int,
200 IRQF_DISABLED, "ncr53c94 dma", esp->ehost);
201 if (err)
202 goto err_irq_err;
203
204 esp_initialize(esp);
205
206 err = scsi_add_host(esp->ehost, NULL);
207 if (err) {
208 printk(KERN_ERR "ESP: Unable to register adapter\n");
209 goto err_irq_dma;
210 }
211
212 scsi_scan_host(esp->ehost);
213
214 dec_esp_platform = esp;
215 }
216
217 return 0;
218
219err_irq_dma:
220 free_irq(dec_interrupt[DEC_IRQ_ASC_DMA], esp->ehost);
221err_irq_err:
222 free_irq(dec_interrupt[DEC_IRQ_ASC_ERR], esp->ehost);
223err_irq_merr:
224 free_irq(dec_interrupt[DEC_IRQ_ASC_MERR], esp->ehost);
225err_irq:
226 free_irq(esp->irq, esp->ehost);
227err_alloc:
228 esp_deallocate(esp);
229 scsi_host_put(esp->ehost);
230 return err;
231}
232
233static int __init dec_esp_probe(struct device *dev)
234{
235 struct NCR_ESP *esp;
236 resource_size_t start, len;
237 int err;
238
239 esp = esp_allocate(&dec_esp_template, NULL, 1);
240
241 dev_set_drvdata(dev, esp);
242
243 start = to_tc_dev(dev)->resource.start;
244 len = to_tc_dev(dev)->resource.end - start + 1;
245
246 if (!request_mem_region(start, len, dev->bus_id)) {
247 printk(KERN_ERR "%s: Unable to reserve MMIO resource\n",
248 dev->bus_id);
249 err = -EBUSY;
250 goto err_alloc;
251 }
252
253 /* Store base addr into esp struct. */
254 esp->slot = start;
255
256 esp->dregs = 0;
257 esp->eregs = (void *)CKSEG1ADDR(start + DEC_SCSI_SREG);
258 esp->do_pio_cmds = 1;
259
260 /* Set the command buffer. */
261 esp->esp_command = (volatile unsigned char *)pmaz_cmd_buffer;
262
263 /* Get virtual dma address for command buffer. */
264 esp->esp_command_dvma = virt_to_phys(pmaz_cmd_buffer);
265
266 esp->cfreq = tc_get_speed(to_tc_dev(dev)->bus);
267
268 esp->irq = to_tc_dev(dev)->interrupt;
269
270 /* Required functions. */
271 esp->dma_bytes_sent = &dma_bytes_sent;
272 esp->dma_can_transfer = &dma_can_transfer;
273 esp->dma_dump_state = &dma_dump_state;
274 esp->dma_init_read = &pmaz_dma_init_read;
275 esp->dma_init_write = &pmaz_dma_init_write;
276 esp->dma_ints_off = &pmaz_dma_ints_off;
277 esp->dma_ints_on = &pmaz_dma_ints_on;
278 esp->dma_irq_p = &dma_irq_p;
279 esp->dma_ports_p = &dma_ports_p;
280 esp->dma_setup = &pmaz_dma_setup;
281
282 /* Optional functions. */
283 esp->dma_barrier = 0;
284 esp->dma_drain = &pmaz_dma_drain;
285 esp->dma_invalidate = 0;
286 esp->dma_irq_entry = 0;
287 esp->dma_irq_exit = 0;
288 esp->dma_poll = 0;
289 esp->dma_reset = 0;
290 esp->dma_led_off = 0;
291 esp->dma_led_on = 0;
292
293 esp->dma_mmu_get_scsi_one = pmaz_dma_mmu_get_scsi_one;
294 esp->dma_mmu_get_scsi_sgl = 0;
295 esp->dma_mmu_release_scsi_one = 0;
296 esp->dma_mmu_release_scsi_sgl = 0;
297 esp->dma_advance_sg = 0;
298
299 err = request_irq(esp->irq, esp_intr, IRQF_DISABLED, "PMAZ_AA",
300 esp->ehost);
301 if (err) {
302 printk(KERN_ERR "%s: Unable to get IRQ %d\n",
303 dev->bus_id, esp->irq);
304 goto err_resource;
305 }
306
307 esp->scsi_id = 7;
308 esp->diff = 0;
309 esp_initialize(esp);
310
311 err = scsi_add_host(esp->ehost, dev);
312 if (err) {
313 printk(KERN_ERR "%s: Unable to register adapter\n",
314 dev->bus_id);
315 goto err_irq;
316 }
317
318 scsi_scan_host(esp->ehost);
319
320 return 0;
321
322err_irq:
323 free_irq(esp->irq, esp->ehost);
324
325err_resource:
326 release_mem_region(start, len);
327
328err_alloc:
329 esp_deallocate(esp);
330 scsi_host_put(esp->ehost);
331 return err;
332}
333
334static void __exit dec_esp_platform_remove(void)
335{
336 struct NCR_ESP *esp = dec_esp_platform;
337
338 free_irq(esp->irq, esp->ehost);
339 esp_deallocate(esp);
340 scsi_host_put(esp->ehost);
341 dec_esp_platform = NULL;
342}
343
344static void __exit dec_esp_remove(struct device *dev)
345{
346 struct NCR_ESP *esp = dev_get_drvdata(dev);
347
348 free_irq(esp->irq, esp->ehost);
349 esp_deallocate(esp);
350 scsi_host_put(esp->ehost);
351}
352
353
354/************************************************************* DMA Functions */
355static irqreturn_t scsi_dma_merr_int(int irq, void *dev_id)
356{
357 printk("Got unexpected SCSI DMA Interrupt! < ");
358 printk("SCSI_DMA_MEMRDERR ");
359 printk(">\n");
360
361 return IRQ_HANDLED;
362}
363
364static irqreturn_t scsi_dma_err_int(int irq, void *dev_id)
365{
366 /* empty */
367
368 return IRQ_HANDLED;
369}
370
371static irqreturn_t scsi_dma_int(int irq, void *dev_id)
372{
373 u32 scsi_next_ptr;
374
375 scsi_next_ptr = ioasic_read(IO_REG_SCSI_DMA_P);
376
377 /* next page */
378 scsi_next_ptr = (((scsi_next_ptr >> 3) + PAGE_SIZE) & PAGE_MASK) << 3;
379 ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
380 fast_iob();
381
382 return IRQ_HANDLED;
383}
384
385static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
386{
387 return fifo_count;
388}
389
390static void dma_drain(struct NCR_ESP *esp)
391{
392 u32 nw, data0, data1, scsi_data_ptr;
393 u16 *p;
394
395 nw = ioasic_read(IO_REG_SCSI_SCR);
396
397 /*
398 * Is there something in the dma buffers left?
399 */
400 if (nw) {
401 scsi_data_ptr = ioasic_read(IO_REG_SCSI_DMA_P) >> 3;
402 p = phys_to_virt(scsi_data_ptr);
403 switch (nw) {
404 case 1:
405 data0 = ioasic_read(IO_REG_SCSI_SDR0);
406 p[0] = data0 & 0xffff;
407 break;
408 case 2:
409 data0 = ioasic_read(IO_REG_SCSI_SDR0);
410 p[0] = data0 & 0xffff;
411 p[1] = (data0 >> 16) & 0xffff;
412 break;
413 case 3:
414 data0 = ioasic_read(IO_REG_SCSI_SDR0);
415 data1 = ioasic_read(IO_REG_SCSI_SDR1);
416 p[0] = data0 & 0xffff;
417 p[1] = (data0 >> 16) & 0xffff;
418 p[2] = data1 & 0xffff;
419 break;
420 default:
421 printk("Strange: %d words in dma buffer left\n", nw);
422 break;
423 }
424 }
425}
426
427static int dma_can_transfer(struct NCR_ESP *esp, struct scsi_cmnd * sp)
428{
429 return sp->SCp.this_residual;
430}
431
432static void dma_dump_state(struct NCR_ESP *esp)
433{
434}
435
436static void dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length)
437{
438 u32 scsi_next_ptr, ioasic_ssr;
439 unsigned long flags;
440
441 if (vaddress & 3)
442 panic("dec_esp.c: unable to handle partial word transfers, yet...");
443
444 dma_cache_wback_inv((unsigned long) phys_to_virt(vaddress), length);
445
446 spin_lock_irqsave(&ioasic_ssr_lock, flags);
447
448 fast_mb();
449 ioasic_ssr = ioasic_read(IO_REG_SSR);
450
451 ioasic_ssr &= ~IO_SSR_SCSI_DMA_EN;
452 ioasic_write(IO_REG_SSR, ioasic_ssr);
453
454 fast_wmb();
455 ioasic_write(IO_REG_SCSI_SCR, 0);
456 ioasic_write(IO_REG_SCSI_DMA_P, vaddress << 3);
457
458 /* prepare for next page */
459 scsi_next_ptr = ((vaddress + PAGE_SIZE) & PAGE_MASK) << 3;
460 ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
461
462 ioasic_ssr |= (IO_SSR_SCSI_DMA_DIR | IO_SSR_SCSI_DMA_EN);
463 fast_wmb();
464 ioasic_write(IO_REG_SSR, ioasic_ssr);
465
466 fast_iob();
467 spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
468}
469
470static void dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length)
471{
472 u32 scsi_next_ptr, ioasic_ssr;
473 unsigned long flags;
474
475 if (vaddress & 3)
476 panic("dec_esp.c: unable to handle partial word transfers, yet...");
477
478 dma_cache_wback_inv((unsigned long) phys_to_virt(vaddress), length);
479
480 spin_lock_irqsave(&ioasic_ssr_lock, flags);
481
482 fast_mb();
483 ioasic_ssr = ioasic_read(IO_REG_SSR);
484
485 ioasic_ssr &= ~(IO_SSR_SCSI_DMA_DIR | IO_SSR_SCSI_DMA_EN);
486 ioasic_write(IO_REG_SSR, ioasic_ssr);
487
488 fast_wmb();
489 ioasic_write(IO_REG_SCSI_SCR, 0);
490 ioasic_write(IO_REG_SCSI_DMA_P, vaddress << 3);
491
492 /* prepare for next page */
493 scsi_next_ptr = ((vaddress + PAGE_SIZE) & PAGE_MASK) << 3;
494 ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
495
496 ioasic_ssr |= IO_SSR_SCSI_DMA_EN;
497 fast_wmb();
498 ioasic_write(IO_REG_SSR, ioasic_ssr);
499
500 fast_iob();
501 spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
502}
503
504static void dma_ints_off(struct NCR_ESP *esp)
505{
506 disable_irq(dec_interrupt[DEC_IRQ_ASC_DMA]);
507}
508
509static void dma_ints_on(struct NCR_ESP *esp)
510{
511 enable_irq(dec_interrupt[DEC_IRQ_ASC_DMA]);
512}
513
514static int dma_irq_p(struct NCR_ESP *esp)
515{
516 return (esp->eregs->esp_status & ESP_STAT_INTR);
517}
518
519static int dma_ports_p(struct NCR_ESP *esp)
520{
521 /*
522 * FIXME: what's this good for?
523 */
524 return 1;
525}
526
527static void dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write)
528{
529 /*
530 * DMA_ST_WRITE means "move data from device to memory"
531 * so when (write) is true, it actually means READ!
532 */
533 if (write)
534 dma_init_read(esp, addr, count);
535 else
536 dma_init_write(esp, addr, count);
537}
538
539static void dma_mmu_get_scsi_one(struct NCR_ESP *esp, struct scsi_cmnd * sp)
540{
541 sp->SCp.ptr = (char *)virt_to_phys(sp->request_buffer);
542}
543
544static void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, struct scsi_cmnd * sp)
545{
546 int sz = sp->SCp.buffers_residual;
547 struct scatterlist *sg = sp->SCp.buffer;
548
549 while (sz >= 0) {
550 sg[sz].dma_address = page_to_phys(sg[sz].page) + sg[sz].offset;
551 sz--;
552 }
553 sp->SCp.ptr = (char *)(sp->SCp.buffer->dma_address);
554}
555
556static void dma_advance_sg(struct scsi_cmnd * sp)
557{
558 sp->SCp.ptr = (char *)(sp->SCp.buffer->dma_address);
559}
560
561static void pmaz_dma_drain(struct NCR_ESP *esp)
562{
563 memcpy(phys_to_virt(esp_virt_buffer),
564 (void *)CKSEG1ADDR(esp->slot + DEC_SCSI_SRAM +
565 ESP_TGT_DMA_SIZE),
566 scsi_current_length);
567}
568
569static void pmaz_dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length)
570{
571 volatile u32 *dmareg =
572 (volatile u32 *)CKSEG1ADDR(esp->slot + DEC_SCSI_DMAREG);
573
574 if (length > ESP_TGT_DMA_SIZE)
575 length = ESP_TGT_DMA_SIZE;
576
577 *dmareg = TC_ESP_DMA_ADDR(ESP_TGT_DMA_SIZE);
578
579 iob();
580
581 esp_virt_buffer = vaddress;
582 scsi_current_length = length;
583}
584
585static void pmaz_dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length)
586{
587 volatile u32 *dmareg =
588 (volatile u32 *)CKSEG1ADDR(esp->slot + DEC_SCSI_DMAREG);
589
590 memcpy((void *)CKSEG1ADDR(esp->slot + DEC_SCSI_SRAM +
591 ESP_TGT_DMA_SIZE),
592 phys_to_virt(vaddress), length);
593
594 wmb();
595 *dmareg = TC_ESP_DMAR_WRITE | TC_ESP_DMA_ADDR(ESP_TGT_DMA_SIZE);
596
597 iob();
598}
599
600static void pmaz_dma_ints_off(struct NCR_ESP *esp)
601{
602}
603
604static void pmaz_dma_ints_on(struct NCR_ESP *esp)
605{
606}
607
608static void pmaz_dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write)
609{
610 /*
611 * DMA_ST_WRITE means "move data from device to memory"
612 * so when (write) is true, it actually means READ!
613 */
614 if (write)
615 pmaz_dma_init_read(esp, addr, count);
616 else
617 pmaz_dma_init_write(esp, addr, count);
618}
619
620static void pmaz_dma_mmu_get_scsi_one(struct NCR_ESP *esp, struct scsi_cmnd * sp)
621{
622 sp->SCp.ptr = (char *)virt_to_phys(sp->request_buffer);
623}
624
625
626#ifdef CONFIG_TC
627static int __init dec_esp_tc_probe(struct device *dev);
628static int __exit dec_esp_tc_remove(struct device *dev);
629
630static const struct tc_device_id dec_esp_tc_table[] = {
631 { "DEC ", "PMAZ-AA " },
632 { }
633};
634MODULE_DEVICE_TABLE(tc, dec_esp_tc_table);
635
636static struct tc_driver dec_esp_tc_driver = {
637 .id_table = dec_esp_tc_table,
638 .driver = {
639 .name = "dec_esp",
640 .bus = &tc_bus_type,
641 .probe = dec_esp_tc_probe,
642 .remove = __exit_p(dec_esp_tc_remove),
643 },
644};
645
646static int __init dec_esp_tc_probe(struct device *dev)
647{
648 int status = dec_esp_probe(dev);
649 if (!status)
650 get_device(dev);
651 return status;
652}
653
654static int __exit dec_esp_tc_remove(struct device *dev)
655{
656 put_device(dev);
657 dec_esp_remove(dev);
658 return 0;
659}
660#endif
661
662static int __init dec_esp_init(void)
663{
664 int status;
665
666 status = tc_register_driver(&dec_esp_tc_driver);
667 if (!status)
668 dec_esp_platform_probe();
669
670 if (nesps) {
671 pr_info("ESP: Total of %d ESP hosts found, "
672 "%d actually in use.\n", nesps, esps_in_use);
673 esps_running = esps_in_use;
674 }
675
676 return status;
677}
678
679static void __exit dec_esp_exit(void)
680{
681 dec_esp_platform_remove();
682 tc_unregister_driver(&dec_esp_tc_driver);
683}
684
685
686module_init(dec_esp_init);
687module_exit(dec_esp_exit);
diff --git a/drivers/scsi/fastlane.c b/drivers/scsi/fastlane.c
deleted file mode 100644
index 4266a2139b5f..000000000000
--- a/drivers/scsi/fastlane.c
+++ /dev/null
@@ -1,421 +0,0 @@
1/* fastlane.c: Driver for Phase5's Fastlane SCSI Controller.
2 *
3 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
4 *
5 * This driver is based on the CyberStorm driver, hence the occasional
6 * reference to CyberStorm.
7 *
8 * Betatesting & crucial adjustments by
9 * Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
10 *
11 */
12
13/* TODO:
14 *
15 * o According to the doc from laire, it is required to reset the DMA when
16 * the transfer is done. ATM we reset DMA just before every new
17 * dma_init_(read|write).
18 *
19 * 1) Figure out how to make a cleaner merge with the sparc driver with regard
20 * to the caches and the Sparc MMU mapping.
21 * 2) Make as few routines required outside the generic driver. A lot of the
22 * routines in this file used to be inline!
23 */
24
25#include <linux/module.h>
26
27#include <linux/init.h>
28#include <linux/kernel.h>
29#include <linux/delay.h>
30#include <linux/types.h>
31#include <linux/string.h>
32#include <linux/slab.h>
33#include <linux/blkdev.h>
34#include <linux/proc_fs.h>
35#include <linux/stat.h>
36#include <linux/interrupt.h>
37
38#include "scsi.h"
39#include <scsi/scsi_host.h>
40#include "NCR53C9x.h"
41
42#include <linux/zorro.h>
43#include <asm/irq.h>
44
45#include <asm/amigaints.h>
46#include <asm/amigahw.h>
47
48#include <asm/pgtable.h>
49
50/* Such day has just come... */
51#if 0
52/* Let this defined unless you really need to enable DMA IRQ one day */
53#define NODMAIRQ
54#endif
55
56/* The controller registers can be found in the Z2 config area at these
57 * offsets:
58 */
59#define FASTLANE_ESP_ADDR 0x1000001
60#define FASTLANE_DMA_ADDR 0x1000041
61
62
63/* The Fastlane DMA interface */
64struct fastlane_dma_registers {
65 volatile unsigned char cond_reg; /* DMA status (ro) [0x0000] */
66#define ctrl_reg cond_reg /* DMA control (wo) [0x0000] */
67 unsigned char dmapad1[0x3f];
68 volatile unsigned char clear_strobe; /* DMA clear (wo) [0x0040] */
69};
70
71
72/* DMA status bits */
73#define FASTLANE_DMA_MINT 0x80
74#define FASTLANE_DMA_IACT 0x40
75#define FASTLANE_DMA_CREQ 0x20
76
77/* DMA control bits */
78#define FASTLANE_DMA_FCODE 0xa0
79#define FASTLANE_DMA_MASK 0xf3
80#define FASTLANE_DMA_LED 0x10 /* HD led control 1 = on */
81#define FASTLANE_DMA_WRITE 0x08 /* 1 = write */
82#define FASTLANE_DMA_ENABLE 0x04 /* Enable DMA */
83#define FASTLANE_DMA_EDI 0x02 /* Enable DMA IRQ ? */
84#define FASTLANE_DMA_ESI 0x01 /* Enable SCSI IRQ */
85
86static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
87static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
88static void dma_dump_state(struct NCR_ESP *esp);
89static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
90static void dma_init_write(struct NCR_ESP *esp, __u32 vaddr, int length);
91static void dma_ints_off(struct NCR_ESP *esp);
92static void dma_ints_on(struct NCR_ESP *esp);
93static int dma_irq_p(struct NCR_ESP *esp);
94static void dma_irq_exit(struct NCR_ESP *esp);
95static void dma_led_off(struct NCR_ESP *esp);
96static void dma_led_on(struct NCR_ESP *esp);
97static int dma_ports_p(struct NCR_ESP *esp);
98static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
99
100static unsigned char ctrl_data = 0; /* Keep backup of the stuff written
101 * to ctrl_reg. Always write a copy
102 * to this register when writing to
103 * the hardware register!
104 */
105
106static volatile unsigned char cmd_buffer[16];
107 /* This is where all commands are put
108 * before they are transferred to the ESP chip
109 * via PIO.
110 */
111
112static inline void dma_clear(struct NCR_ESP *esp)
113{
114 struct fastlane_dma_registers *dregs =
115 (struct fastlane_dma_registers *) (esp->dregs);
116 unsigned long *t;
117
118 ctrl_data = (ctrl_data & FASTLANE_DMA_MASK);
119 dregs->ctrl_reg = ctrl_data;
120
121 t = (unsigned long *)(esp->edev);
122
123 dregs->clear_strobe = 0;
124 *t = 0 ;
125}
126
127/***************************************************************** Detection */
128int __init fastlane_esp_detect(struct scsi_host_template *tpnt)
129{
130 struct NCR_ESP *esp;
131 struct zorro_dev *z = NULL;
132 unsigned long address;
133
134 if ((z = zorro_find_device(ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060, z))) {
135 unsigned long board = z->resource.start;
136 if (request_mem_region(board+FASTLANE_ESP_ADDR,
137 sizeof(struct ESP_regs), "NCR53C9x")) {
138 /* Check if this is really a fastlane controller. The problem
139 * is that also the cyberstorm and blizzard controllers use
140 * this ID value. Fortunately only Fastlane maps in Z3 space
141 */
142 if (board < 0x1000000) {
143 goto err_release;
144 }
145 esp = esp_allocate(tpnt, (void *)board + FASTLANE_ESP_ADDR, 0);
146
147 /* Do command transfer with programmed I/O */
148 esp->do_pio_cmds = 1;
149
150 /* Required functions */
151 esp->dma_bytes_sent = &dma_bytes_sent;
152 esp->dma_can_transfer = &dma_can_transfer;
153 esp->dma_dump_state = &dma_dump_state;
154 esp->dma_init_read = &dma_init_read;
155 esp->dma_init_write = &dma_init_write;
156 esp->dma_ints_off = &dma_ints_off;
157 esp->dma_ints_on = &dma_ints_on;
158 esp->dma_irq_p = &dma_irq_p;
159 esp->dma_ports_p = &dma_ports_p;
160 esp->dma_setup = &dma_setup;
161
162 /* Optional functions */
163 esp->dma_barrier = 0;
164 esp->dma_drain = 0;
165 esp->dma_invalidate = 0;
166 esp->dma_irq_entry = 0;
167 esp->dma_irq_exit = &dma_irq_exit;
168 esp->dma_led_on = &dma_led_on;
169 esp->dma_led_off = &dma_led_off;
170 esp->dma_poll = 0;
171 esp->dma_reset = 0;
172
173 /* Initialize the portBits (enable IRQs) */
174 ctrl_data = (FASTLANE_DMA_FCODE |
175#ifndef NODMAIRQ
176 FASTLANE_DMA_EDI |
177#endif
178 FASTLANE_DMA_ESI);
179
180
181 /* SCSI chip clock */
182 esp->cfreq = 40000000;
183
184
185 /* Map the physical address space into virtual kernel space */
186 address = (unsigned long)
187 z_ioremap(board, z->resource.end-board+1);
188
189 if(!address){
190 printk("Could not remap Fastlane controller memory!");
191 goto err_unregister;
192 }
193
194
195 /* The DMA registers on the Fastlane are mapped
196 * relative to the device (i.e. in the same Zorro
197 * I/O block).
198 */
199 esp->dregs = (void *)(address + FASTLANE_DMA_ADDR);
200
201 /* ESP register base */
202 esp->eregs = (struct ESP_regs *)(address + FASTLANE_ESP_ADDR);
203
204 /* Board base */
205 esp->edev = (void *) address;
206
207 /* Set the command buffer */
208 esp->esp_command = cmd_buffer;
209 esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
210
211 esp->irq = IRQ_AMIGA_PORTS;
212 esp->slot = board+FASTLANE_ESP_ADDR;
213 if (request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
214 "Fastlane SCSI", esp->ehost)) {
215 printk(KERN_WARNING "Fastlane: Could not get IRQ%d, aborting.\n", IRQ_AMIGA_PORTS);
216 goto err_unmap;
217 }
218
219 /* Controller ID */
220 esp->scsi_id = 7;
221
222 /* We don't have a differential SCSI-bus. */
223 esp->diff = 0;
224
225 dma_clear(esp);
226 esp_initialize(esp);
227
228 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
229 esps_running = esps_in_use;
230 return esps_in_use;
231 }
232 }
233 return 0;
234
235 err_unmap:
236 z_iounmap((void *)address);
237 err_unregister:
238 scsi_unregister (esp->ehost);
239 err_release:
240 release_mem_region(z->resource.start+FASTLANE_ESP_ADDR,
241 sizeof(struct ESP_regs));
242 return 0;
243}
244
245
246/************************************************************* DMA Functions */
247static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
248{
249 /* Since the Fastlane DMA is fully dedicated to the ESP chip,
250 * the number of bytes sent (to the ESP chip) equals the number
251 * of bytes in the FIFO - there is no buffering in the DMA controller.
252 * XXXX Do I read this right? It is from host to ESP, right?
253 */
254 return fifo_count;
255}
256
257static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
258{
259 unsigned long sz = sp->SCp.this_residual;
260 if(sz > 0xfffc)
261 sz = 0xfffc;
262 return sz;
263}
264
265static void dma_dump_state(struct NCR_ESP *esp)
266{
267 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
268 esp->esp_id, ((struct fastlane_dma_registers *)
269 (esp->dregs))->cond_reg));
270 ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
271 amiga_custom.intreqr, amiga_custom.intenar));
272}
273
274static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
275{
276 struct fastlane_dma_registers *dregs =
277 (struct fastlane_dma_registers *) (esp->dregs);
278 unsigned long *t;
279
280 cache_clear(addr, length);
281
282 dma_clear(esp);
283
284 t = (unsigned long *)((addr & 0x00ffffff) + esp->edev);
285
286 dregs->clear_strobe = 0;
287 *t = addr;
288
289 ctrl_data = (ctrl_data & FASTLANE_DMA_MASK) | FASTLANE_DMA_ENABLE;
290 dregs->ctrl_reg = ctrl_data;
291}
292
293static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
294{
295 struct fastlane_dma_registers *dregs =
296 (struct fastlane_dma_registers *) (esp->dregs);
297 unsigned long *t;
298
299 cache_push(addr, length);
300
301 dma_clear(esp);
302
303 t = (unsigned long *)((addr & 0x00ffffff) + (esp->edev));
304
305 dregs->clear_strobe = 0;
306 *t = addr;
307
308 ctrl_data = ((ctrl_data & FASTLANE_DMA_MASK) |
309 FASTLANE_DMA_ENABLE |
310 FASTLANE_DMA_WRITE);
311 dregs->ctrl_reg = ctrl_data;
312}
313
314
315static void dma_ints_off(struct NCR_ESP *esp)
316{
317 disable_irq(esp->irq);
318}
319
320static void dma_ints_on(struct NCR_ESP *esp)
321{
322 enable_irq(esp->irq);
323}
324
325static void dma_irq_exit(struct NCR_ESP *esp)
326{
327 struct fastlane_dma_registers *dregs =
328 (struct fastlane_dma_registers *) (esp->dregs);
329
330 dregs->ctrl_reg = ctrl_data & ~(FASTLANE_DMA_EDI|FASTLANE_DMA_ESI);
331#ifdef __mc68000__
332 nop();
333#endif
334 dregs->ctrl_reg = ctrl_data;
335}
336
337static int dma_irq_p(struct NCR_ESP *esp)
338{
339 struct fastlane_dma_registers *dregs =
340 (struct fastlane_dma_registers *) (esp->dregs);
341 unsigned char dma_status;
342
343 dma_status = dregs->cond_reg;
344
345 if(dma_status & FASTLANE_DMA_IACT)
346 return 0; /* not our IRQ */
347
348 /* Return non-zero if ESP requested IRQ */
349 return (
350#ifndef NODMAIRQ
351 (dma_status & FASTLANE_DMA_CREQ) &&
352#endif
353 (!(dma_status & FASTLANE_DMA_MINT)) &&
354 (esp_read(((struct ESP_regs *) (esp->eregs))->esp_status) & ESP_STAT_INTR));
355}
356
357static void dma_led_off(struct NCR_ESP *esp)
358{
359 ctrl_data &= ~FASTLANE_DMA_LED;
360 ((struct fastlane_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
361}
362
363static void dma_led_on(struct NCR_ESP *esp)
364{
365 ctrl_data |= FASTLANE_DMA_LED;
366 ((struct fastlane_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
367}
368
369static int dma_ports_p(struct NCR_ESP *esp)
370{
371 return ((amiga_custom.intenar) & IF_PORTS);
372}
373
374static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
375{
376 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
377 * so when (write) is true, it actually means READ!
378 */
379 if(write){
380 dma_init_read(esp, addr, count);
381 } else {
382 dma_init_write(esp, addr, count);
383 }
384}
385
386#define HOSTS_C
387
388int fastlane_esp_release(struct Scsi_Host *instance)
389{
390#ifdef MODULE
391 unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
392 esp_deallocate((struct NCR_ESP *)instance->hostdata);
393 esp_release();
394 release_mem_region(address, sizeof(struct ESP_regs));
395 free_irq(IRQ_AMIGA_PORTS, esp_intr);
396#endif
397 return 1;
398}
399
400
401static struct scsi_host_template driver_template = {
402 .proc_name = "esp-fastlane",
403 .proc_info = esp_proc_info,
404 .name = "Fastlane SCSI",
405 .detect = fastlane_esp_detect,
406 .slave_alloc = esp_slave_alloc,
407 .slave_destroy = esp_slave_destroy,
408 .release = fastlane_esp_release,
409 .queuecommand = esp_queue,
410 .eh_abort_handler = esp_abort,
411 .eh_bus_reset_handler = esp_reset,
412 .can_queue = 7,
413 .this_id = 7,
414 .sg_tablesize = SG_ALL,
415 .cmd_per_lun = 1,
416 .use_clustering = ENABLE_CLUSTERING
417};
418
419#include "scsi_module.c"
420
421MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index b6f99dfbb038..8a178674cb18 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -629,8 +629,9 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
629 int rc; 629 int rc;
630 630
631 if (tcp_conn->in.datalen) { 631 if (tcp_conn->in.datalen) {
632 printk(KERN_ERR "iscsi_tcp: invalid R2t with datalen %d\n", 632 iscsi_conn_printk(KERN_ERR, conn,
633 tcp_conn->in.datalen); 633 "invalid R2t with datalen %d\n",
634 tcp_conn->in.datalen);
634 return ISCSI_ERR_DATALEN; 635 return ISCSI_ERR_DATALEN;
635 } 636 }
636 637
@@ -644,8 +645,9 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
644 iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr); 645 iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr);
645 646
646 if (!ctask->sc || session->state != ISCSI_STATE_LOGGED_IN) { 647 if (!ctask->sc || session->state != ISCSI_STATE_LOGGED_IN) {
647 printk(KERN_INFO "iscsi_tcp: dropping R2T itt %d in " 648 iscsi_conn_printk(KERN_INFO, conn,
648 "recovery...\n", ctask->itt); 649 "dropping R2T itt %d in recovery.\n",
650 ctask->itt);
649 return 0; 651 return 0;
650 } 652 }
651 653
@@ -655,7 +657,8 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
655 r2t->exp_statsn = rhdr->statsn; 657 r2t->exp_statsn = rhdr->statsn;
656 r2t->data_length = be32_to_cpu(rhdr->data_length); 658 r2t->data_length = be32_to_cpu(rhdr->data_length);
657 if (r2t->data_length == 0) { 659 if (r2t->data_length == 0) {
658 printk(KERN_ERR "iscsi_tcp: invalid R2T with zero data len\n"); 660 iscsi_conn_printk(KERN_ERR, conn,
661 "invalid R2T with zero data len\n");
659 __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t, 662 __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t,
660 sizeof(void*)); 663 sizeof(void*));
661 return ISCSI_ERR_DATALEN; 664 return ISCSI_ERR_DATALEN;
@@ -668,9 +671,10 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
668 671
669 r2t->data_offset = be32_to_cpu(rhdr->data_offset); 672 r2t->data_offset = be32_to_cpu(rhdr->data_offset);
670 if (r2t->data_offset + r2t->data_length > scsi_bufflen(ctask->sc)) { 673 if (r2t->data_offset + r2t->data_length > scsi_bufflen(ctask->sc)) {
671 printk(KERN_ERR "iscsi_tcp: invalid R2T with data len %u at " 674 iscsi_conn_printk(KERN_ERR, conn,
672 "offset %u and total length %d\n", r2t->data_length, 675 "invalid R2T with data len %u at offset %u "
673 r2t->data_offset, scsi_bufflen(ctask->sc)); 676 "and total length %d\n", r2t->data_length,
677 r2t->data_offset, scsi_bufflen(ctask->sc));
674 __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t, 678 __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t,
675 sizeof(void*)); 679 sizeof(void*));
676 return ISCSI_ERR_DATALEN; 680 return ISCSI_ERR_DATALEN;
@@ -736,8 +740,9 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
736 /* verify PDU length */ 740 /* verify PDU length */
737 tcp_conn->in.datalen = ntoh24(hdr->dlength); 741 tcp_conn->in.datalen = ntoh24(hdr->dlength);
738 if (tcp_conn->in.datalen > conn->max_recv_dlength) { 742 if (tcp_conn->in.datalen > conn->max_recv_dlength) {
739 printk(KERN_ERR "iscsi_tcp: datalen %d > %d\n", 743 iscsi_conn_printk(KERN_ERR, conn,
740 tcp_conn->in.datalen, conn->max_recv_dlength); 744 "iscsi_tcp: datalen %d > %d\n",
745 tcp_conn->in.datalen, conn->max_recv_dlength);
741 return ISCSI_ERR_DATALEN; 746 return ISCSI_ERR_DATALEN;
742 } 747 }
743 748
@@ -819,10 +824,12 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
819 * For now we fail until we find a vendor that needs it 824 * For now we fail until we find a vendor that needs it
820 */ 825 */
821 if (ISCSI_DEF_MAX_RECV_SEG_LEN < tcp_conn->in.datalen) { 826 if (ISCSI_DEF_MAX_RECV_SEG_LEN < tcp_conn->in.datalen) {
822 printk(KERN_ERR "iscsi_tcp: received buffer of len %u " 827 iscsi_conn_printk(KERN_ERR, conn,
823 "but conn buffer is only %u (opcode %0x)\n", 828 "iscsi_tcp: received buffer of "
824 tcp_conn->in.datalen, 829 "len %u but conn buffer is only %u "
825 ISCSI_DEF_MAX_RECV_SEG_LEN, opcode); 830 "(opcode %0x)\n",
831 tcp_conn->in.datalen,
832 ISCSI_DEF_MAX_RECV_SEG_LEN, opcode);
826 rc = ISCSI_ERR_PROTO; 833 rc = ISCSI_ERR_PROTO;
827 break; 834 break;
828 } 835 }
@@ -1496,30 +1503,25 @@ iscsi_tcp_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1496 tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0, 1503 tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0,
1497 CRYPTO_ALG_ASYNC); 1504 CRYPTO_ALG_ASYNC);
1498 tcp_conn->tx_hash.flags = 0; 1505 tcp_conn->tx_hash.flags = 0;
1499 if (IS_ERR(tcp_conn->tx_hash.tfm)) { 1506 if (IS_ERR(tcp_conn->tx_hash.tfm))
1500 printk(KERN_ERR "Could not create connection due to crc32c "
1501 "loading error %ld. Make sure the crc32c module is "
1502 "built as a module or into the kernel\n",
1503 PTR_ERR(tcp_conn->tx_hash.tfm));
1504 goto free_tcp_conn; 1507 goto free_tcp_conn;
1505 }
1506 1508
1507 tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0, 1509 tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0,
1508 CRYPTO_ALG_ASYNC); 1510 CRYPTO_ALG_ASYNC);
1509 tcp_conn->rx_hash.flags = 0; 1511 tcp_conn->rx_hash.flags = 0;
1510 if (IS_ERR(tcp_conn->rx_hash.tfm)) { 1512 if (IS_ERR(tcp_conn->rx_hash.tfm))
1511 printk(KERN_ERR "Could not create connection due to crc32c "
1512 "loading error %ld. Make sure the crc32c module is "
1513 "built as a module or into the kernel\n",
1514 PTR_ERR(tcp_conn->rx_hash.tfm));
1515 goto free_tx_tfm; 1513 goto free_tx_tfm;
1516 }
1517 1514
1518 return cls_conn; 1515 return cls_conn;
1519 1516
1520free_tx_tfm: 1517free_tx_tfm:
1521 crypto_free_hash(tcp_conn->tx_hash.tfm); 1518 crypto_free_hash(tcp_conn->tx_hash.tfm);
1522free_tcp_conn: 1519free_tcp_conn:
1520 iscsi_conn_printk(KERN_ERR, conn,
1521 "Could not create connection due to crc32c "
1522 "loading error. Make sure the crc32c "
1523 "module is built as a module or into the "
1524 "kernel\n");
1523 kfree(tcp_conn); 1525 kfree(tcp_conn);
1524tcp_conn_alloc_fail: 1526tcp_conn_alloc_fail:
1525 iscsi_conn_teardown(cls_conn); 1527 iscsi_conn_teardown(cls_conn);
@@ -1627,7 +1629,8 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
1627 /* lookup for existing socket */ 1629 /* lookup for existing socket */
1628 sock = sockfd_lookup((int)transport_eph, &err); 1630 sock = sockfd_lookup((int)transport_eph, &err);
1629 if (!sock) { 1631 if (!sock) {
1630 printk(KERN_ERR "iscsi_tcp: sockfd_lookup failed %d\n", err); 1632 iscsi_conn_printk(KERN_ERR, conn,
1633 "sockfd_lookup failed %d\n", err);
1631 return -EEXIST; 1634 return -EEXIST;
1632 } 1635 }
1633 /* 1636 /*
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 553168ae44f1..59f8445eab0d 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -160,7 +160,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
160 hdr->opcode = ISCSI_OP_SCSI_CMD; 160 hdr->opcode = ISCSI_OP_SCSI_CMD;
161 hdr->flags = ISCSI_ATTR_SIMPLE; 161 hdr->flags = ISCSI_ATTR_SIMPLE;
162 int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun); 162 int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
163 hdr->itt = build_itt(ctask->itt, conn->id, session->age); 163 hdr->itt = build_itt(ctask->itt, session->age);
164 hdr->data_length = cpu_to_be32(scsi_bufflen(sc)); 164 hdr->data_length = cpu_to_be32(scsi_bufflen(sc));
165 hdr->cmdsn = cpu_to_be32(session->cmdsn); 165 hdr->cmdsn = cpu_to_be32(session->cmdsn);
166 session->cmdsn++; 166 session->cmdsn++;
@@ -416,8 +416,9 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
416 416
417 if (datalen < 2) { 417 if (datalen < 2) {
418invalid_datalen: 418invalid_datalen:
419 printk(KERN_ERR "iscsi: Got CHECK_CONDITION but " 419 iscsi_conn_printk(KERN_ERR, conn,
420 "invalid data buffer size of %d\n", datalen); 420 "Got CHECK_CONDITION but invalid data "
421 "buffer size of %d\n", datalen);
421 sc->result = DID_BAD_TARGET << 16; 422 sc->result = DID_BAD_TARGET << 16;
422 goto out; 423 goto out;
423 } 424 }
@@ -494,7 +495,7 @@ static void iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
494 495
495 mtask = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0); 496 mtask = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0);
496 if (!mtask) { 497 if (!mtask) {
497 printk(KERN_ERR "Could not send nopout\n"); 498 iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n");
498 return; 499 return;
499 } 500 }
500 501
@@ -522,9 +523,10 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
522 if (ntoh24(reject->dlength) >= sizeof(struct iscsi_hdr)) { 523 if (ntoh24(reject->dlength) >= sizeof(struct iscsi_hdr)) {
523 memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr)); 524 memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr));
524 itt = get_itt(rejected_pdu.itt); 525 itt = get_itt(rejected_pdu.itt);
525 printk(KERN_ERR "itt 0x%x had pdu (op 0x%x) rejected " 526 iscsi_conn_printk(KERN_ERR, conn,
526 "due to DataDigest error.\n", itt, 527 "itt 0x%x had pdu (op 0x%x) rejected "
527 rejected_pdu.opcode); 528 "due to DataDigest error.\n", itt,
529 rejected_pdu.opcode);
528 } 530 }
529 } 531 }
530 return 0; 532 return 0;
@@ -541,8 +543,8 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
541 * queuecommand or send generic. session lock must be held and verify 543 * queuecommand or send generic. session lock must be held and verify
542 * itt must have been called. 544 * itt must have been called.
543 */ 545 */
544int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, 546static int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
545 char *data, int datalen) 547 char *data, int datalen)
546{ 548{
547 struct iscsi_session *session = conn->session; 549 struct iscsi_session *session = conn->session;
548 int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0; 550 int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0;
@@ -672,7 +674,6 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
672 674
673 return rc; 675 return rc;
674} 676}
675EXPORT_SYMBOL_GPL(__iscsi_complete_pdu);
676 677
677int iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, 678int iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
678 char *data, int datalen) 679 char *data, int datalen)
@@ -697,18 +698,13 @@ int iscsi_verify_itt(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
697 if (hdr->itt != RESERVED_ITT) { 698 if (hdr->itt != RESERVED_ITT) {
698 if (((__force u32)hdr->itt & ISCSI_AGE_MASK) != 699 if (((__force u32)hdr->itt & ISCSI_AGE_MASK) !=
699 (session->age << ISCSI_AGE_SHIFT)) { 700 (session->age << ISCSI_AGE_SHIFT)) {
700 printk(KERN_ERR "iscsi: received itt %x expected " 701 iscsi_conn_printk(KERN_ERR, conn,
701 "session age (%x)\n", (__force u32)hdr->itt, 702 "received itt %x expected session "
702 session->age & ISCSI_AGE_MASK); 703 "age (%x)\n", (__force u32)hdr->itt,
704 session->age & ISCSI_AGE_MASK);
703 return ISCSI_ERR_BAD_ITT; 705 return ISCSI_ERR_BAD_ITT;
704 } 706 }
705 707
706 if (((__force u32)hdr->itt & ISCSI_CID_MASK) !=
707 (conn->id << ISCSI_CID_SHIFT)) {
708 printk(KERN_ERR "iscsi: received itt %x, expected "
709 "CID (%x)\n", (__force u32)hdr->itt, conn->id);
710 return ISCSI_ERR_BAD_ITT;
711 }
712 itt = get_itt(hdr->itt); 708 itt = get_itt(hdr->itt);
713 } else 709 } else
714 itt = ~0U; 710 itt = ~0U;
@@ -717,16 +713,17 @@ int iscsi_verify_itt(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
717 ctask = session->cmds[itt]; 713 ctask = session->cmds[itt];
718 714
719 if (!ctask->sc) { 715 if (!ctask->sc) {
720 printk(KERN_INFO "iscsi: dropping ctask with " 716 iscsi_conn_printk(KERN_INFO, conn, "dropping ctask "
721 "itt 0x%x\n", ctask->itt); 717 "with itt 0x%x\n", ctask->itt);
722 /* force drop */ 718 /* force drop */
723 return ISCSI_ERR_NO_SCSI_CMD; 719 return ISCSI_ERR_NO_SCSI_CMD;
724 } 720 }
725 721
726 if (ctask->sc->SCp.phase != session->age) { 722 if (ctask->sc->SCp.phase != session->age) {
727 printk(KERN_ERR "iscsi: ctask's session age %d, " 723 iscsi_conn_printk(KERN_ERR, conn,
728 "expected %d\n", ctask->sc->SCp.phase, 724 "iscsi: ctask's session age %d, "
729 session->age); 725 "expected %d\n", ctask->sc->SCp.phase,
726 session->age);
730 return ISCSI_ERR_SESSION_FAILED; 727 return ISCSI_ERR_SESSION_FAILED;
731 } 728 }
732 } 729 }
@@ -771,7 +768,7 @@ static void iscsi_prep_mtask(struct iscsi_conn *conn,
771 */ 768 */
772 nop->cmdsn = cpu_to_be32(session->cmdsn); 769 nop->cmdsn = cpu_to_be32(session->cmdsn);
773 if (hdr->itt != RESERVED_ITT) { 770 if (hdr->itt != RESERVED_ITT) {
774 hdr->itt = build_itt(mtask->itt, conn->id, session->age); 771 hdr->itt = build_itt(mtask->itt, session->age);
775 /* 772 /*
776 * TODO: We always use immediate, so we never hit this. 773 * TODO: We always use immediate, so we never hit this.
777 * If we start to send tmfs or nops as non-immediate then 774 * If we start to send tmfs or nops as non-immediate then
@@ -997,6 +994,7 @@ enum {
997 FAILURE_SESSION_IN_RECOVERY, 994 FAILURE_SESSION_IN_RECOVERY,
998 FAILURE_SESSION_RECOVERY_TIMEOUT, 995 FAILURE_SESSION_RECOVERY_TIMEOUT,
999 FAILURE_SESSION_LOGGING_OUT, 996 FAILURE_SESSION_LOGGING_OUT,
997 FAILURE_SESSION_NOT_READY,
1000}; 998};
1001 999
1002int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) 1000int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
@@ -1017,6 +1015,12 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1017 session = iscsi_hostdata(host->hostdata); 1015 session = iscsi_hostdata(host->hostdata);
1018 spin_lock(&session->lock); 1016 spin_lock(&session->lock);
1019 1017
1018 reason = iscsi_session_chkready(session_to_cls(session));
1019 if (reason) {
1020 sc->result = reason;
1021 goto fault;
1022 }
1023
1020 /* 1024 /*
1021 * ISCSI_STATE_FAILED is a temp. state. The recovery 1025 * ISCSI_STATE_FAILED is a temp. state. The recovery
1022 * code will decide what is best to do with command queued 1026 * code will decide what is best to do with command queued
@@ -1033,18 +1037,23 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1033 switch (session->state) { 1037 switch (session->state) {
1034 case ISCSI_STATE_IN_RECOVERY: 1038 case ISCSI_STATE_IN_RECOVERY:
1035 reason = FAILURE_SESSION_IN_RECOVERY; 1039 reason = FAILURE_SESSION_IN_RECOVERY;
1036 goto reject; 1040 sc->result = DID_IMM_RETRY << 16;
1041 break;
1037 case ISCSI_STATE_LOGGING_OUT: 1042 case ISCSI_STATE_LOGGING_OUT:
1038 reason = FAILURE_SESSION_LOGGING_OUT; 1043 reason = FAILURE_SESSION_LOGGING_OUT;
1039 goto reject; 1044 sc->result = DID_IMM_RETRY << 16;
1045 break;
1040 case ISCSI_STATE_RECOVERY_FAILED: 1046 case ISCSI_STATE_RECOVERY_FAILED:
1041 reason = FAILURE_SESSION_RECOVERY_TIMEOUT; 1047 reason = FAILURE_SESSION_RECOVERY_TIMEOUT;
1048 sc->result = DID_NO_CONNECT << 16;
1042 break; 1049 break;
1043 case ISCSI_STATE_TERMINATE: 1050 case ISCSI_STATE_TERMINATE:
1044 reason = FAILURE_SESSION_TERMINATE; 1051 reason = FAILURE_SESSION_TERMINATE;
1052 sc->result = DID_NO_CONNECT << 16;
1045 break; 1053 break;
1046 default: 1054 default:
1047 reason = FAILURE_SESSION_FREED; 1055 reason = FAILURE_SESSION_FREED;
1056 sc->result = DID_NO_CONNECT << 16;
1048 } 1057 }
1049 goto fault; 1058 goto fault;
1050 } 1059 }
@@ -1052,6 +1061,7 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1052 conn = session->leadconn; 1061 conn = session->leadconn;
1053 if (!conn) { 1062 if (!conn) {
1054 reason = FAILURE_SESSION_FREED; 1063 reason = FAILURE_SESSION_FREED;
1064 sc->result = DID_NO_CONNECT << 16;
1055 goto fault; 1065 goto fault;
1056 } 1066 }
1057 1067
@@ -1091,9 +1101,7 @@ reject:
1091 1101
1092fault: 1102fault:
1093 spin_unlock(&session->lock); 1103 spin_unlock(&session->lock);
1094 printk(KERN_ERR "iscsi: cmd 0x%x is not queued (%d)\n", 1104 debug_scsi("iscsi: cmd 0x%x is not queued (%d)\n", sc->cmnd[0], reason);
1095 sc->cmnd[0], reason);
1096 sc->result = (DID_NO_CONNECT << 16);
1097 scsi_set_resid(sc, scsi_bufflen(sc)); 1105 scsi_set_resid(sc, scsi_bufflen(sc));
1098 sc->scsi_done(sc); 1106 sc->scsi_done(sc);
1099 spin_lock(host->host_lock); 1107 spin_lock(host->host_lock);
@@ -1160,7 +1168,8 @@ failed:
1160 mutex_lock(&session->eh_mutex); 1168 mutex_lock(&session->eh_mutex);
1161 spin_lock_bh(&session->lock); 1169 spin_lock_bh(&session->lock);
1162 if (session->state == ISCSI_STATE_LOGGED_IN) 1170 if (session->state == ISCSI_STATE_LOGGED_IN)
1163 printk(KERN_INFO "iscsi: host reset succeeded\n"); 1171 iscsi_session_printk(KERN_INFO, session,
1172 "host reset succeeded\n");
1164 else 1173 else
1165 goto failed; 1174 goto failed;
1166 spin_unlock_bh(&session->lock); 1175 spin_unlock_bh(&session->lock);
@@ -1239,7 +1248,8 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
1239 * Fail commands. session lock held and recv side suspended and xmit 1248 * Fail commands. session lock held and recv side suspended and xmit
1240 * thread flushed 1249 * thread flushed
1241 */ 1250 */
1242static void fail_all_commands(struct iscsi_conn *conn, unsigned lun) 1251static void fail_all_commands(struct iscsi_conn *conn, unsigned lun,
1252 int error)
1243{ 1253{
1244 struct iscsi_cmd_task *ctask, *tmp; 1254 struct iscsi_cmd_task *ctask, *tmp;
1245 1255
@@ -1251,7 +1261,7 @@ static void fail_all_commands(struct iscsi_conn *conn, unsigned lun)
1251 if (lun == ctask->sc->device->lun || lun == -1) { 1261 if (lun == ctask->sc->device->lun || lun == -1) {
1252 debug_scsi("failing pending sc %p itt 0x%x\n", 1262 debug_scsi("failing pending sc %p itt 0x%x\n",
1253 ctask->sc, ctask->itt); 1263 ctask->sc, ctask->itt);
1254 fail_command(conn, ctask, DID_BUS_BUSY << 16); 1264 fail_command(conn, ctask, error << 16);
1255 } 1265 }
1256 } 1266 }
1257 1267
@@ -1259,7 +1269,7 @@ static void fail_all_commands(struct iscsi_conn *conn, unsigned lun)
1259 if (lun == ctask->sc->device->lun || lun == -1) { 1269 if (lun == ctask->sc->device->lun || lun == -1) {
1260 debug_scsi("failing requeued sc %p itt 0x%x\n", 1270 debug_scsi("failing requeued sc %p itt 0x%x\n",
1261 ctask->sc, ctask->itt); 1271 ctask->sc, ctask->itt);
1262 fail_command(conn, ctask, DID_BUS_BUSY << 16); 1272 fail_command(conn, ctask, error << 16);
1263 } 1273 }
1264 } 1274 }
1265 1275
@@ -1357,10 +1367,10 @@ static void iscsi_check_transport_timeouts(unsigned long data)
1357 last_recv = conn->last_recv; 1367 last_recv = conn->last_recv;
1358 if (time_before_eq(last_recv + timeout + (conn->ping_timeout * HZ), 1368 if (time_before_eq(last_recv + timeout + (conn->ping_timeout * HZ),
1359 jiffies)) { 1369 jiffies)) {
1360 printk(KERN_ERR "ping timeout of %d secs expired, " 1370 iscsi_conn_printk(KERN_ERR, conn, "ping timeout of %d secs "
1361 "last rx %lu, last ping %lu, now %lu\n", 1371 "expired, last rx %lu, last ping %lu, "
1362 conn->ping_timeout, last_recv, 1372 "now %lu\n", conn->ping_timeout, last_recv,
1363 conn->last_ping, jiffies); 1373 conn->last_ping, jiffies);
1364 spin_unlock(&session->lock); 1374 spin_unlock(&session->lock);
1365 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 1375 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1366 return; 1376 return;
@@ -1373,14 +1383,11 @@ static void iscsi_check_transport_timeouts(unsigned long data)
1373 iscsi_send_nopout(conn, NULL); 1383 iscsi_send_nopout(conn, NULL);
1374 } 1384 }
1375 next_timeout = last_recv + timeout + (conn->ping_timeout * HZ); 1385 next_timeout = last_recv + timeout + (conn->ping_timeout * HZ);
1376 } else { 1386 } else
1377 next_timeout = last_recv + timeout; 1387 next_timeout = last_recv + timeout;
1378 }
1379 1388
1380 if (next_timeout) { 1389 debug_scsi("Setting next tmo %lu\n", next_timeout);
1381 debug_scsi("Setting next tmo %lu\n", next_timeout); 1390 mod_timer(&conn->transport_timer, next_timeout);
1382 mod_timer(&conn->transport_timer, next_timeout);
1383 }
1384done: 1391done:
1385 spin_unlock(&session->lock); 1392 spin_unlock(&session->lock);
1386} 1393}
@@ -1573,7 +1580,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
1573 /* need to grab the recv lock then session lock */ 1580 /* need to grab the recv lock then session lock */
1574 write_lock_bh(conn->recv_lock); 1581 write_lock_bh(conn->recv_lock);
1575 spin_lock(&session->lock); 1582 spin_lock(&session->lock);
1576 fail_all_commands(conn, sc->device->lun); 1583 fail_all_commands(conn, sc->device->lun, DID_ERROR);
1577 conn->tmf_state = TMF_INITIAL; 1584 conn->tmf_state = TMF_INITIAL;
1578 spin_unlock(&session->lock); 1585 spin_unlock(&session->lock);
1579 write_unlock_bh(conn->recv_lock); 1586 write_unlock_bh(conn->recv_lock);
@@ -1944,9 +1951,10 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
1944 } 1951 }
1945 spin_unlock_irqrestore(session->host->host_lock, flags); 1952 spin_unlock_irqrestore(session->host->host_lock, flags);
1946 msleep_interruptible(500); 1953 msleep_interruptible(500);
1947 printk(KERN_INFO "iscsi: scsi conn_destroy(): host_busy %d " 1954 iscsi_conn_printk(KERN_INFO, conn, "iscsi conn_destroy(): "
1948 "host_failed %d\n", session->host->host_busy, 1955 "host_busy %d host_failed %d\n",
1949 session->host->host_failed); 1956 session->host->host_busy,
1957 session->host->host_failed);
1950 /* 1958 /*
1951 * force eh_abort() to unblock 1959 * force eh_abort() to unblock
1952 */ 1960 */
@@ -1975,27 +1983,28 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
1975 struct iscsi_session *session = conn->session; 1983 struct iscsi_session *session = conn->session;
1976 1984
1977 if (!session) { 1985 if (!session) {
1978 printk(KERN_ERR "iscsi: can't start unbound connection\n"); 1986 iscsi_conn_printk(KERN_ERR, conn,
1987 "can't start unbound connection\n");
1979 return -EPERM; 1988 return -EPERM;
1980 } 1989 }
1981 1990
1982 if ((session->imm_data_en || !session->initial_r2t_en) && 1991 if ((session->imm_data_en || !session->initial_r2t_en) &&
1983 session->first_burst > session->max_burst) { 1992 session->first_burst > session->max_burst) {
1984 printk("iscsi: invalid burst lengths: " 1993 iscsi_conn_printk(KERN_INFO, conn, "invalid burst lengths: "
1985 "first_burst %d max_burst %d\n", 1994 "first_burst %d max_burst %d\n",
1986 session->first_burst, session->max_burst); 1995 session->first_burst, session->max_burst);
1987 return -EINVAL; 1996 return -EINVAL;
1988 } 1997 }
1989 1998
1990 if (conn->ping_timeout && !conn->recv_timeout) { 1999 if (conn->ping_timeout && !conn->recv_timeout) {
1991 printk(KERN_ERR "iscsi: invalid recv timeout of zero " 2000 iscsi_conn_printk(KERN_ERR, conn, "invalid recv timeout of "
1992 "Using 5 seconds\n."); 2001 "zero. Using 5 seconds\n.");
1993 conn->recv_timeout = 5; 2002 conn->recv_timeout = 5;
1994 } 2003 }
1995 2004
1996 if (conn->recv_timeout && !conn->ping_timeout) { 2005 if (conn->recv_timeout && !conn->ping_timeout) {
1997 printk(KERN_ERR "iscsi: invalid ping timeout of zero " 2006 iscsi_conn_printk(KERN_ERR, conn, "invalid ping timeout of "
1998 "Using 5 seconds.\n"); 2007 "zero. Using 5 seconds.\n");
1999 conn->ping_timeout = 5; 2008 conn->ping_timeout = 5;
2000 } 2009 }
2001 2010
@@ -2019,11 +2028,9 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
2019 conn->stop_stage = 0; 2028 conn->stop_stage = 0;
2020 conn->tmf_state = TMF_INITIAL; 2029 conn->tmf_state = TMF_INITIAL;
2021 session->age++; 2030 session->age++;
2022 spin_unlock_bh(&session->lock); 2031 if (session->age == 16)
2023 2032 session->age = 0;
2024 iscsi_unblock_session(session_to_cls(session)); 2033 break;
2025 wake_up(&conn->ehwait);
2026 return 0;
2027 case STOP_CONN_TERM: 2034 case STOP_CONN_TERM:
2028 conn->stop_stage = 0; 2035 conn->stop_stage = 0;
2029 break; 2036 break;
@@ -2032,6 +2039,8 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
2032 } 2039 }
2033 spin_unlock_bh(&session->lock); 2040 spin_unlock_bh(&session->lock);
2034 2041
2042 iscsi_unblock_session(session_to_cls(session));
2043 wake_up(&conn->ehwait);
2035 return 0; 2044 return 0;
2036} 2045}
2037EXPORT_SYMBOL_GPL(iscsi_conn_start); 2046EXPORT_SYMBOL_GPL(iscsi_conn_start);
@@ -2123,7 +2132,8 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
2123 * flush queues. 2132 * flush queues.
2124 */ 2133 */
2125 spin_lock_bh(&session->lock); 2134 spin_lock_bh(&session->lock);
2126 fail_all_commands(conn, -1); 2135 fail_all_commands(conn, -1,
2136 STOP_CONN_RECOVER ? DID_BUS_BUSY : DID_ERROR);
2127 flush_control_queues(session, conn); 2137 flush_control_queues(session, conn);
2128 spin_unlock_bh(&session->lock); 2138 spin_unlock_bh(&session->lock);
2129 mutex_unlock(&session->eh_mutex); 2139 mutex_unlock(&session->eh_mutex);
@@ -2140,7 +2150,8 @@ void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
2140 iscsi_start_session_recovery(session, conn, flag); 2150 iscsi_start_session_recovery(session, conn, flag);
2141 break; 2151 break;
2142 default: 2152 default:
2143 printk(KERN_ERR "iscsi: invalid stop flag %d\n", flag); 2153 iscsi_conn_printk(KERN_ERR, conn,
2154 "invalid stop flag %d\n", flag);
2144 } 2155 }
2145} 2156}
2146EXPORT_SYMBOL_GPL(iscsi_conn_stop); 2157EXPORT_SYMBOL_GPL(iscsi_conn_stop);
diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c
deleted file mode 100644
index bcb49021b7e2..000000000000
--- a/drivers/scsi/mac_esp.c
+++ /dev/null
@@ -1,751 +0,0 @@
1/*
2 * 68k mac 53c9[46] scsi driver
3 *
4 * copyright (c) 1998, David Weis weisd3458@uni.edu
5 *
6 * debugging on Quadra 800 and 660AV Michael Schmitz, Dave Kilzer 7/98
7 *
8 * based loosely on cyber_esp.c
9 */
10
11/* these are unused for now */
12#define myreadl(addr) (*(volatile unsigned int *) (addr))
13#define mywritel(b, addr) ((*(volatile unsigned int *) (addr)) = (b))
14
15
16#include <linux/kernel.h>
17#include <linux/delay.h>
18#include <linux/types.h>
19#include <linux/ctype.h>
20#include <linux/string.h>
21#include <linux/slab.h>
22#include <linux/blkdev.h>
23#include <linux/proc_fs.h>
24#include <linux/stat.h>
25#include <linux/init.h>
26#include <linux/interrupt.h>
27
28#include "scsi.h"
29#include <scsi/scsi_host.h>
30#include "NCR53C9x.h"
31
32#include <asm/io.h>
33
34#include <asm/setup.h>
35#include <asm/irq.h>
36#include <asm/macints.h>
37#include <asm/machw.h>
38#include <asm/mac_via.h>
39
40#include <asm/pgtable.h>
41
42#include <asm/macintosh.h>
43
44/* #define DEBUG_MAC_ESP */
45
46extern void esp_handle(struct NCR_ESP *esp);
47extern void mac_esp_intr(int irq, void *dev_id);
48
49static int dma_bytes_sent(struct NCR_ESP * esp, int fifo_count);
50static int dma_can_transfer(struct NCR_ESP * esp, Scsi_Cmnd *sp);
51static void dma_dump_state(struct NCR_ESP * esp);
52static void dma_init_read(struct NCR_ESP * esp, char * vaddress, int length);
53static void dma_init_write(struct NCR_ESP * esp, char * vaddress, int length);
54static void dma_ints_off(struct NCR_ESP * esp);
55static void dma_ints_on(struct NCR_ESP * esp);
56static int dma_irq_p(struct NCR_ESP * esp);
57static int dma_irq_p_quick(struct NCR_ESP * esp);
58static void dma_led_off(struct NCR_ESP * esp);
59static void dma_led_on(struct NCR_ESP *esp);
60static int dma_ports_p(struct NCR_ESP *esp);
61static void dma_setup(struct NCR_ESP * esp, __u32 addr, int count, int write);
62static void dma_setup_quick(struct NCR_ESP * esp, __u32 addr, int count, int write);
63
64static int esp_dafb_dma_irq_p(struct NCR_ESP * espdev);
65static int esp_iosb_dma_irq_p(struct NCR_ESP * espdev);
66
67static volatile unsigned char cmd_buffer[16];
68 /* This is where all commands are put
69 * before they are transferred to the ESP chip
70 * via PIO.
71 */
72
73static int esp_initialized = 0;
74
75static int setup_num_esps = -1;
76static int setup_disconnect = -1;
77static int setup_nosync = -1;
78static int setup_can_queue = -1;
79static int setup_cmd_per_lun = -1;
80static int setup_sg_tablesize = -1;
81#ifdef SUPPORT_TAGS
82static int setup_use_tagged_queuing = -1;
83#endif
84static int setup_hostid = -1;
85
86/*
87 * Experimental ESP inthandler; check macints.c to make sure dev_id is
88 * set up properly!
89 */
90
91void mac_esp_intr(int irq, void *dev_id)
92{
93 struct NCR_ESP *esp = (struct NCR_ESP *) dev_id;
94 int irq_p = 0;
95
96 /* Handle the one ESP interrupt showing at this IRQ level. */
97 if(((esp)->irq & 0xff) == irq) {
98 /*
99 * Debug ..
100 */
101 irq_p = esp->dma_irq_p(esp);
102 printk("mac_esp: irq_p %x current %p disconnected %p\n",
103 irq_p, esp->current_SC, esp->disconnected_SC);
104
105 /*
106 * Mac: if we're here, it's an ESP interrupt for sure!
107 */
108 if((esp->current_SC || esp->disconnected_SC)) {
109 esp->dma_ints_off(esp);
110
111 ESPIRQ(("I%d(", esp->esp_id));
112 esp_handle(esp);
113 ESPIRQ((")"));
114
115 esp->dma_ints_on(esp);
116 }
117 }
118}
119
120/*
121 * Debug hooks; use for playing with the interrupt flag testing and interrupt
122 * acknowledge on the various machines
123 */
124
125void scsi_esp_polled(int irq, void *dev_id)
126{
127 if (esp_initialized == 0)
128 return;
129
130 mac_esp_intr(irq, dev_id);
131}
132
133void fake_intr(int irq, void *dev_id)
134{
135#ifdef DEBUG_MAC_ESP
136 printk("mac_esp: got irq\n");
137#endif
138
139 mac_esp_intr(irq, dev_id);
140}
141
142irqreturn_t fake_drq(int irq, void *dev_id)
143{
144 printk("mac_esp: got drq\n");
145 return IRQ_HANDLED;
146}
147
148#define DRIVER_SETUP
149
150/*
151 * Function : mac_esp_setup(char *str)
152 *
153 * Purpose : booter command line initialization of the overrides array,
154 *
155 * Inputs : str - parameters, separated by commas.
156 *
157 * Currently unused in the new driver; need to add settable parameters to the
158 * detect function.
159 *
160 */
161
162static int __init mac_esp_setup(char *str) {
163#ifdef DRIVER_SETUP
164 /* Format of mac53c9x parameter is:
165 * mac53c9x=<num_esps>,<disconnect>,<nosync>,<can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>
166 * Negative values mean don't change.
167 */
168
169 char *this_opt;
170 long opt;
171
172 this_opt = strsep (&str, ",");
173 if(this_opt) {
174 opt = simple_strtol( this_opt, NULL, 0 );
175
176 if (opt >= 0 && opt <= 2)
177 setup_num_esps = opt;
178 else if (opt > 2)
179 printk( "mac_esp_setup: invalid number of hosts %ld !\n", opt );
180
181 this_opt = strsep (&str, ",");
182 }
183 if(this_opt) {
184 opt = simple_strtol( this_opt, NULL, 0 );
185
186 if (opt > 0)
187 setup_disconnect = opt;
188
189 this_opt = strsep (&str, ",");
190 }
191 if(this_opt) {
192 opt = simple_strtol( this_opt, NULL, 0 );
193
194 if (opt >= 0)
195 setup_nosync = opt;
196
197 this_opt = strsep (&str, ",");
198 }
199 if(this_opt) {
200 opt = simple_strtol( this_opt, NULL, 0 );
201
202 if (opt > 0)
203 setup_can_queue = opt;
204
205 this_opt = strsep (&str, ",");
206 }
207 if(this_opt) {
208 opt = simple_strtol( this_opt, NULL, 0 );
209
210 if (opt > 0)
211 setup_cmd_per_lun = opt;
212
213 this_opt = strsep (&str, ",");
214 }
215 if(this_opt) {
216 opt = simple_strtol( this_opt, NULL, 0 );
217
218 if (opt >= 0) {
219 setup_sg_tablesize = opt;
220 /* Must be <= SG_ALL (255) */
221 if (setup_sg_tablesize > SG_ALL)
222 setup_sg_tablesize = SG_ALL;
223 }
224
225 this_opt = strsep (&str, ",");
226 }
227 if(this_opt) {
228 opt = simple_strtol( this_opt, NULL, 0 );
229
230 /* Must be between 0 and 7 */
231 if (opt >= 0 && opt <= 7)
232 setup_hostid = opt;
233 else if (opt > 7)
234 printk( "mac_esp_setup: invalid host ID %ld !\n", opt);
235
236 this_opt = strsep (&str, ",");
237 }
238#ifdef SUPPORT_TAGS
239 if(this_opt) {
240 opt = simple_strtol( this_opt, NULL, 0 );
241 if (opt >= 0)
242 setup_use_tagged_queuing = !!opt;
243 }
244#endif
245#endif
246 return 1;
247}
248
249__setup("mac53c9x=", mac_esp_setup);
250
251
252/*
253 * ESP address 'detection'
254 */
255
256unsigned long get_base(int chip_num)
257{
258 /*
259 * using the chip_num and mac model, figure out where the
260 * chips are mapped
261 */
262
263 unsigned long io_base = 0x50f00000;
264 unsigned int second_offset = 0x402;
265 unsigned long scsi_loc = 0;
266
267 switch (macintosh_config->scsi_type) {
268
269 /* 950, 900, 700 */
270 case MAC_SCSI_QUADRA2:
271 scsi_loc = io_base + 0xf000 + ((chip_num == 0) ? 0 : second_offset);
272 break;
273
274 /* av's */
275 case MAC_SCSI_QUADRA3:
276 scsi_loc = io_base + 0x18000 + ((chip_num == 0) ? 0 : second_offset);
277 break;
278
279 /* most quadra/centris models are like this */
280 case MAC_SCSI_QUADRA:
281 scsi_loc = io_base + 0x10000;
282 break;
283
284 default:
285 printk("mac_esp: get_base: hit default!\n");
286 scsi_loc = io_base + 0x10000;
287 break;
288
289 } /* switch */
290
291 printk("mac_esp: io base at 0x%lx\n", scsi_loc);
292
293 return scsi_loc;
294}
295
296/*
297 * Model dependent ESP setup
298 */
299
300int mac_esp_detect(struct scsi_host_template * tpnt)
301{
302 int quick = 0;
303 int chipnum, chipspresent = 0;
304#if 0
305 unsigned long timeout;
306#endif
307
308 if (esp_initialized > 0)
309 return -ENODEV;
310
311 /* what do we have in this machine... */
312 if (MACHW_PRESENT(MAC_SCSI_96)) {
313 chipspresent ++;
314 }
315
316 if (MACHW_PRESENT(MAC_SCSI_96_2)) {
317 chipspresent ++;
318 }
319
320 /* number of ESPs present ? */
321 if (setup_num_esps >= 0) {
322 if (chipspresent >= setup_num_esps)
323 chipspresent = setup_num_esps;
324 else
325 printk("mac_esp_detect: num_hosts detected %d setup %d \n",
326 chipspresent, setup_num_esps);
327 }
328
329 /* TODO: add disconnect / nosync flags */
330
331 /* setup variables */
332 tpnt->can_queue =
333 (setup_can_queue > 0) ? setup_can_queue : 7;
334 tpnt->cmd_per_lun =
335 (setup_cmd_per_lun > 0) ? setup_cmd_per_lun : 1;
336 tpnt->sg_tablesize =
337 (setup_sg_tablesize >= 0) ? setup_sg_tablesize : SG_ALL;
338
339 if (setup_hostid >= 0)
340 tpnt->this_id = setup_hostid;
341 else {
342 /* use 7 as default */
343 tpnt->this_id = 7;
344 }
345
346#ifdef SUPPORT_TAGS
347 if (setup_use_tagged_queuing < 0)
348 setup_use_tagged_queuing = DEFAULT_USE_TAGGED_QUEUING;
349#endif
350
351 for (chipnum = 0; chipnum < chipspresent; chipnum ++) {
352 struct NCR_ESP * esp;
353
354 esp = esp_allocate(tpnt, NULL, 0);
355 esp->eregs = (struct ESP_regs *) get_base(chipnum);
356
357 esp->dma_irq_p = &esp_dafb_dma_irq_p;
358 if (chipnum == 0) {
359
360 if (macintosh_config->scsi_type == MAC_SCSI_QUADRA) {
361 /* most machines except those below :-) */
362 quick = 1;
363 esp->dma_irq_p = &esp_iosb_dma_irq_p;
364 } else if (macintosh_config->scsi_type == MAC_SCSI_QUADRA3) {
365 /* mostly av's */
366 quick = 0;
367 } else {
368 /* q950, 900, 700 */
369 quick = 1;
370 out_be32(0xf9800024, 0x1d1);
371 esp->dregs = (void *) 0xf9800024;
372 }
373
374 } else { /* chipnum */
375
376 quick = 1;
377 out_be32(0xf9800028, 0x1d1);
378 esp->dregs = (void *) 0xf9800028;
379
380 } /* chipnum == 0 */
381
382 /* use pio for command bytes; pio for message/data: TBI */
383 esp->do_pio_cmds = 1;
384
385 /* Set the command buffer */
386 esp->esp_command = (volatile unsigned char*) cmd_buffer;
387 esp->esp_command_dvma = (__u32) cmd_buffer;
388
389 /* various functions */
390 esp->dma_bytes_sent = &dma_bytes_sent;
391 esp->dma_can_transfer = &dma_can_transfer;
392 esp->dma_dump_state = &dma_dump_state;
393 esp->dma_init_read = NULL;
394 esp->dma_init_write = NULL;
395 esp->dma_ints_off = &dma_ints_off;
396 esp->dma_ints_on = &dma_ints_on;
397
398 esp->dma_ports_p = &dma_ports_p;
399
400
401 /* Optional functions */
402 esp->dma_barrier = NULL;
403 esp->dma_drain = NULL;
404 esp->dma_invalidate = NULL;
405 esp->dma_irq_entry = NULL;
406 esp->dma_irq_exit = NULL;
407 esp->dma_led_on = NULL;
408 esp->dma_led_off = NULL;
409 esp->dma_poll = NULL;
410 esp->dma_reset = NULL;
411
412 /* SCSI chip speed */
413 /* below esp->cfreq = 40000000; */
414
415
416 if (quick) {
417 /* 'quick' means there's handshake glue logic like in the 5380 case */
418 esp->dma_setup = &dma_setup_quick;
419 } else {
420 esp->dma_setup = &dma_setup;
421 }
422
423 if (chipnum == 0) {
424
425 esp->irq = IRQ_MAC_SCSI;
426
427 request_irq(IRQ_MAC_SCSI, esp_intr, 0, "Mac ESP SCSI", esp->ehost);
428#if 0 /* conflicts with IOP ADB */
429 request_irq(IRQ_MAC_SCSIDRQ, fake_drq, 0, "Mac ESP DRQ", esp->ehost);
430#endif
431
432 if (macintosh_config->scsi_type == MAC_SCSI_QUADRA) {
433 esp->cfreq = 16500000;
434 } else {
435 esp->cfreq = 25000000;
436 }
437
438
439 } else { /* chipnum == 1 */
440
441 esp->irq = IRQ_MAC_SCSIDRQ;
442#if 0 /* conflicts with IOP ADB */
443 request_irq(IRQ_MAC_SCSIDRQ, esp_intr, 0, "Mac ESP SCSI 2", esp->ehost);
444#endif
445
446 esp->cfreq = 25000000;
447
448 }
449
450 if (quick) {
451 printk("esp: using quick version\n");
452 }
453
454 printk("esp: addr at 0x%p\n", esp->eregs);
455
456 esp->scsi_id = 7;
457 esp->diff = 0;
458
459 esp_initialize(esp);
460
461 } /* for chipnum */
462
463 if (chipspresent)
464 printk("\nmac_esp: %d esp controllers found\n", chipspresent);
465
466 esp_initialized = chipspresent;
467
468 return chipspresent;
469}
470
471static int mac_esp_release(struct Scsi_Host *shost)
472{
473 if (shost->irq)
474 free_irq(shost->irq, NULL);
475 if (shost->io_port && shost->n_io_port)
476 release_region(shost->io_port, shost->n_io_port);
477 scsi_unregister(shost);
478 return 0;
479}
480
481/*
482 * I've been wondering what this is supposed to do, for some time. Talking
483 * to Allen Briggs: These machines have an extra register someplace where the
484 * DRQ pin of the ESP can be monitored. That isn't useful for determining
485 * anything else (such as reselect interrupt or other magic) though.
486 * Maybe make the semantics should be changed like
487 * if (esp->current_SC)
488 * ... check DRQ flag ...
489 * else
490 * ... disconnected, check pending VIA interrupt ...
491 *
492 * There's a problem with using the dabf flag or mac_irq_pending() here: both
493 * seem to return 1 even though no interrupt is currently pending, resulting
494 * in esp_exec_cmd() holding off the next command, and possibly infinite loops
495 * in esp_intr().
496 * Short term fix: just use esp_status & ESP_STAT_INTR here, as long as we
497 * use simple PIO. The DRQ status will be important when implementing pseudo
498 * DMA mode (set up ESP transfer count, return, do a batch of bytes in PIO or
499 * 'hardware handshake' mode upon DRQ).
500 * If you plan on changing this (i.e. to save the esp_status register access in
501 * favor of a VIA register access or a shadow register for the IFR), make sure
502 * to try a debug version of this first to monitor what registers would be a good
503 * indicator of the ESP interrupt.
504 */
505
506static int esp_dafb_dma_irq_p(struct NCR_ESP * esp)
507{
508 unsigned int ret;
509 int sreg = esp_read(esp->eregs->esp_status);
510
511#ifdef DEBUG_MAC_ESP
512 printk("mac_esp: esp_dafb_dma_irq_p dafb %d irq %d\n",
513 readl(esp->dregs), mac_irq_pending(IRQ_MAC_SCSI));
514#endif
515
516 sreg &= ESP_STAT_INTR;
517
518 /*
519 * maybe working; this is essentially what's used for iosb_dma_irq_p
520 */
521 if (sreg)
522 return 1;
523 else
524 return 0;
525
526 /*
527 * didn't work ...
528 */
529#if 0
530 if (esp->current_SC)
531 ret = readl(esp->dregs) & 0x200;
532 else if (esp->disconnected_SC)
533 ret = 1; /* sreg ?? */
534 else
535 ret = mac_irq_pending(IRQ_MAC_SCSI);
536
537 return(ret);
538#endif
539
540}
541
542/*
543 * See above: testing mac_irq_pending always returned 8 (SCSI IRQ) regardless
544 * of the actual ESP status.
545 */
546
547static int esp_iosb_dma_irq_p(struct NCR_ESP * esp)
548{
549 int ret = mac_irq_pending(IRQ_MAC_SCSI) || mac_irq_pending(IRQ_MAC_SCSIDRQ);
550 int sreg = esp_read(esp->eregs->esp_status);
551
552#ifdef DEBUG_MAC_ESP
553 printk("mac_esp: dma_irq_p drq %d irq %d sreg %x curr %p disc %p\n",
554 mac_irq_pending(IRQ_MAC_SCSIDRQ), mac_irq_pending(IRQ_MAC_SCSI),
555 sreg, esp->current_SC, esp->disconnected_SC);
556#endif
557
558 sreg &= ESP_STAT_INTR;
559
560 if (sreg)
561 return (sreg);
562 else
563 return 0;
564}
565
566/*
567 * This seems to be OK for PIO at least ... usually 0 after PIO.
568 */
569
570static int dma_bytes_sent(struct NCR_ESP * esp, int fifo_count)
571{
572
573#ifdef DEBUG_MAC_ESP
574 printk("mac_esp: dma bytes sent = %x\n", fifo_count);
575#endif
576
577 return fifo_count;
578}
579
580/*
581 * dma_can_transfer is used to switch between DMA and PIO, if DMA (pseudo)
582 * is ever implemented. Returning 0 here will use PIO.
583 */
584
585static int dma_can_transfer(struct NCR_ESP * esp, Scsi_Cmnd * sp)
586{
587 unsigned long sz = sp->SCp.this_residual;
588#if 0 /* no DMA yet; make conditional */
589 if (sz > 0x10000000) {
590 sz = 0x10000000;
591 }
592 printk("mac_esp: dma can transfer = 0lx%x\n", sz);
593#else
594
595#ifdef DEBUG_MAC_ESP
596 printk("mac_esp: pio to transfer = %ld\n", sz);
597#endif
598
599 sz = 0;
600#endif
601 return sz;
602}
603
604/*
605 * Not yet ...
606 */
607
608static void dma_dump_state(struct NCR_ESP * esp)
609{
610#ifdef DEBUG_MAC_ESP
611 printk("mac_esp: dma_dump_state: called\n");
612#endif
613#if 0
614 ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
615 esp->esp_id, ((struct mac_dma_registers *)
616 (esp->dregs))->cond_reg));
617#endif
618}
619
620/*
621 * DMA setup: should be used to set up the ESP transfer count for pseudo
622 * DMA transfers; need a DRQ transfer function to do the actual transfer
623 */
624
625static void dma_init_read(struct NCR_ESP * esp, char * vaddress, int length)
626{
627 printk("mac_esp: dma_init_read\n");
628}
629
630
631static void dma_init_write(struct NCR_ESP * esp, char * vaddress, int length)
632{
633 printk("mac_esp: dma_init_write\n");
634}
635
636
637static void dma_ints_off(struct NCR_ESP * esp)
638{
639 disable_irq(esp->irq);
640}
641
642
643static void dma_ints_on(struct NCR_ESP * esp)
644{
645 enable_irq(esp->irq);
646}
647
648/*
649 * generic dma_irq_p(), unused
650 */
651
652static int dma_irq_p(struct NCR_ESP * esp)
653{
654 int i = esp_read(esp->eregs->esp_status);
655
656#ifdef DEBUG_MAC_ESP
657 printk("mac_esp: dma_irq_p status %d\n", i);
658#endif
659
660 return (i & ESP_STAT_INTR);
661}
662
663static int dma_irq_p_quick(struct NCR_ESP * esp)
664{
665 /*
666 * Copied from iosb_dma_irq_p()
667 */
668 int ret = mac_irq_pending(IRQ_MAC_SCSI) || mac_irq_pending(IRQ_MAC_SCSIDRQ);
669 int sreg = esp_read(esp->eregs->esp_status);
670
671#ifdef DEBUG_MAC_ESP
672 printk("mac_esp: dma_irq_p drq %d irq %d sreg %x curr %p disc %p\n",
673 mac_irq_pending(IRQ_MAC_SCSIDRQ), mac_irq_pending(IRQ_MAC_SCSI),
674 sreg, esp->current_SC, esp->disconnected_SC);
675#endif
676
677 sreg &= ESP_STAT_INTR;
678
679 if (sreg)
680 return (sreg);
681 else
682 return 0;
683
684}
685
686static void dma_led_off(struct NCR_ESP * esp)
687{
688#ifdef DEBUG_MAC_ESP
689 printk("mac_esp: dma_led_off: called\n");
690#endif
691}
692
693
694static void dma_led_on(struct NCR_ESP * esp)
695{
696#ifdef DEBUG_MAC_ESP
697 printk("mac_esp: dma_led_on: called\n");
698#endif
699}
700
701
702static int dma_ports_p(struct NCR_ESP * esp)
703{
704 return 0;
705}
706
707
708static void dma_setup(struct NCR_ESP * esp, __u32 addr, int count, int write)
709{
710
711#ifdef DEBUG_MAC_ESP
712 printk("mac_esp: dma_setup\n");
713#endif
714
715 if (write) {
716 dma_init_read(esp, (char *) addr, count);
717 } else {
718 dma_init_write(esp, (char *) addr, count);
719 }
720}
721
722
723static void dma_setup_quick(struct NCR_ESP * esp, __u32 addr, int count, int write)
724{
725#ifdef DEBUG_MAC_ESP
726 printk("mac_esp: dma_setup_quick\n");
727#endif
728}
729
730static struct scsi_host_template driver_template = {
731 .proc_name = "mac_esp",
732 .name = "Mac 53C9x SCSI",
733 .detect = mac_esp_detect,
734 .slave_alloc = esp_slave_alloc,
735 .slave_destroy = esp_slave_destroy,
736 .release = mac_esp_release,
737 .info = esp_info,
738 .queuecommand = esp_queue,
739 .eh_abort_handler = esp_abort,
740 .eh_bus_reset_handler = esp_reset,
741 .can_queue = 7,
742 .this_id = 7,
743 .sg_tablesize = SG_ALL,
744 .cmd_per_lun = 1,
745 .use_clustering = DISABLE_CLUSTERING
746};
747
748
749#include "scsi_module.c"
750
751MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/mca_53c9x.c b/drivers/scsi/mca_53c9x.c
deleted file mode 100644
index d693d0f21395..000000000000
--- a/drivers/scsi/mca_53c9x.c
+++ /dev/null
@@ -1,520 +0,0 @@
1/* mca_53c9x.c: Driver for the SCSI adapter found on NCR 35xx
2 * (and maybe some other) Microchannel machines
3 *
4 * Code taken mostly from Cyberstorm SCSI drivers
5 * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
6 *
7 * Hacked to work with the NCR MCA stuff by Tymm Twillman (tymm@computer.org)
8 *
9 * The CyberStorm SCSI driver (and this driver) is based on David S. Miller's
10 * ESP driver * for the Sparc computers.
11 *
12 * Special thanks to Ken Stewart at Symbios (LSI) for helping with info on
13 * the 86C01. I was on the brink of going ga-ga...
14 *
15 * Also thanks to Jesper Skov for helping me with info on how the Amiga
16 * does things...
17 */
18
19/*
20 * This is currently only set up to use one 53c9x card at a time; it could be
21 * changed fairly easily to detect/use more than one, but I'm not too sure how
22 * many cards that use the 53c9x on MCA systems there are (if, in fact, there
23 * are cards that use them, other than the one built into some NCR systems)...
24 * If anyone requests this, I'll throw it in, otherwise it's not worth the
25 * effort.
26 */
27
28/*
29 * Info on the 86C01 MCA interface chip at the bottom, if you care enough to
30 * look.
31 */
32
33#include <linux/delay.h>
34#include <linux/interrupt.h>
35#include <linux/kernel.h>
36#include <linux/mca.h>
37#include <linux/types.h>
38#include <linux/string.h>
39#include <linux/slab.h>
40#include <linux/blkdev.h>
41#include <linux/proc_fs.h>
42#include <linux/stat.h>
43#include <linux/mca-legacy.h>
44
45#include "scsi.h"
46#include <scsi/scsi_host.h>
47#include "NCR53C9x.h"
48
49#include <asm/dma.h>
50#include <asm/irq.h>
51#include <asm/mca_dma.h>
52#include <asm/pgtable.h>
53
54/*
55 * From ibmmca.c (IBM scsi controller card driver) -- used for turning PS2 disk
56 * activity LED on and off
57 */
58
59#define PS2_SYS_CTR 0x92
60
61/* Ports the ncr's 53c94 can be put at; indexed by pos register value */
62
63#define MCA_53C9X_IO_PORTS { \
64 0x0000, 0x0240, 0x0340, 0x0400, \
65 0x0420, 0x3240, 0x8240, 0xA240, \
66 }
67
68/*
69 * Supposedly there were some cards put together with the 'c9x and 86c01. If
70 * they have different ID's from the ones on the 3500 series machines,
71 * you can add them here and hopefully things will work out.
72 */
73
74#define MCA_53C9X_IDS { \
75 0x7F4C, \
76 0x0000, \
77 }
78
79static int dma_bytes_sent(struct NCR_ESP *, int);
80static int dma_can_transfer(struct NCR_ESP *, Scsi_Cmnd *);
81static void dma_dump_state(struct NCR_ESP *);
82static void dma_init_read(struct NCR_ESP *, __u32, int);
83static void dma_init_write(struct NCR_ESP *, __u32, int);
84static void dma_ints_off(struct NCR_ESP *);
85static void dma_ints_on(struct NCR_ESP *);
86static int dma_irq_p(struct NCR_ESP *);
87static int dma_ports_p(struct NCR_ESP *);
88static void dma_setup(struct NCR_ESP *, __u32, int, int);
89static void dma_led_on(struct NCR_ESP *);
90static void dma_led_off(struct NCR_ESP *);
91
92/* This is where all commands are put before they are trasfered to the
93 * 53c9x via PIO.
94 */
95
96static volatile unsigned char cmd_buffer[16];
97
98/*
99 * We keep the structure that is used to access the registers on the 53c9x
100 * here.
101 */
102
103static struct ESP_regs eregs;
104
105/***************************************************************** Detection */
106static int mca_esp_detect(struct scsi_host_template *tpnt)
107{
108 struct NCR_ESP *esp;
109 static int io_port_by_pos[] = MCA_53C9X_IO_PORTS;
110 int mca_53c9x_ids[] = MCA_53C9X_IDS;
111 int *id_to_check = mca_53c9x_ids;
112 int slot;
113 int pos[3];
114 unsigned int tmp_io_addr;
115 unsigned char tmp_byte;
116
117
118 if (!MCA_bus)
119 return 0;
120
121 while (*id_to_check) {
122 if ((slot = mca_find_adapter(*id_to_check, 0)) !=
123 MCA_NOTFOUND)
124 {
125 esp = esp_allocate(tpnt, NULL, 0);
126
127 pos[0] = mca_read_stored_pos(slot, 2);
128 pos[1] = mca_read_stored_pos(slot, 3);
129 pos[2] = mca_read_stored_pos(slot, 4);
130
131 esp->eregs = &eregs;
132
133 /*
134 * IO port base is given in the first (non-ID) pos
135 * register, like so:
136 *
137 * Bits 3 2 1 IO base
138 * ----------------------------
139 * 0 0 0 <disabled>
140 * 0 0 1 0x0240
141 * 0 1 0 0x0340
142 * 0 1 1 0x0400
143 * 1 0 0 0x0420
144 * 1 0 1 0x3240
145 * 1 1 0 0x8240
146 * 1 1 1 0xA240
147 */
148
149 tmp_io_addr =
150 io_port_by_pos[(pos[0] & 0x0E) >> 1];
151
152 esp->eregs->io_addr = tmp_io_addr + 0x10;
153
154 if (esp->eregs->io_addr == 0x0000) {
155 printk("Adapter is disabled.\n");
156 break;
157 }
158
159 /*
160 * IRQ is specified in bits 4 and 5:
161 *
162 * Bits 4 5 IRQ
163 * -----------------------
164 * 0 0 3
165 * 0 1 5
166 * 1 0 7
167 * 1 1 9
168 */
169
170 esp->irq = ((pos[0] & 0x30) >> 3) + 3;
171
172 /*
173 * DMA channel is in the low 3 bits of the second
174 * POS register
175 */
176
177 esp->dma = pos[1] & 7;
178 esp->slot = slot;
179
180 if (request_irq(esp->irq, esp_intr, 0,
181 "NCR 53c9x SCSI", esp->ehost))
182 {
183 printk("Unable to request IRQ %d.\n", esp->irq);
184 esp_deallocate(esp);
185 scsi_unregister(esp->ehost);
186 return 0;
187 }
188
189 if (request_dma(esp->dma, "NCR 53c9x SCSI")) {
190 printk("Unable to request DMA channel %d.\n",
191 esp->dma);
192 free_irq(esp->irq, esp_intr);
193 esp_deallocate(esp);
194 scsi_unregister(esp->ehost);
195 return 0;
196 }
197
198 request_region(tmp_io_addr, 32, "NCR 53c9x SCSI");
199
200 /*
201 * 86C01 handles DMA, IO mode, from address
202 * (base + 0x0a)
203 */
204
205 mca_disable_dma(esp->dma);
206 mca_set_dma_io(esp->dma, tmp_io_addr + 0x0a);
207 mca_enable_dma(esp->dma);
208
209 /* Tell the 86C01 to give us interrupts */
210
211 tmp_byte = inb(tmp_io_addr + 0x02) | 0x40;
212 outb(tmp_byte, tmp_io_addr + 0x02);
213
214 /*
215 * Scsi ID -- general purpose register, hi
216 * 2 bits; add 4 to this number to get the
217 * ID
218 */
219
220 esp->scsi_id = ((pos[2] & 0xC0) >> 6) + 4;
221
222 /* Do command transfer with programmed I/O */
223
224 esp->do_pio_cmds = 1;
225
226 /* Required functions */
227
228 esp->dma_bytes_sent = &dma_bytes_sent;
229 esp->dma_can_transfer = &dma_can_transfer;
230 esp->dma_dump_state = &dma_dump_state;
231 esp->dma_init_read = &dma_init_read;
232 esp->dma_init_write = &dma_init_write;
233 esp->dma_ints_off = &dma_ints_off;
234 esp->dma_ints_on = &dma_ints_on;
235 esp->dma_irq_p = &dma_irq_p;
236 esp->dma_ports_p = &dma_ports_p;
237 esp->dma_setup = &dma_setup;
238
239 /* Optional functions */
240
241 esp->dma_barrier = NULL;
242 esp->dma_drain = NULL;
243 esp->dma_invalidate = NULL;
244 esp->dma_irq_entry = NULL;
245 esp->dma_irq_exit = NULL;
246 esp->dma_led_on = dma_led_on;
247 esp->dma_led_off = dma_led_off;
248 esp->dma_poll = NULL;
249 esp->dma_reset = NULL;
250
251 /* Set the command buffer */
252
253 esp->esp_command = (volatile unsigned char*)
254 cmd_buffer;
255 esp->esp_command_dvma = isa_virt_to_bus(cmd_buffer);
256
257 /* SCSI chip speed */
258
259 esp->cfreq = 25000000;
260
261 /* Differential SCSI? I think not. */
262
263 esp->diff = 0;
264
265 esp_initialize(esp);
266
267 printk(" Adapter found in slot %2d: io port 0x%x "
268 "irq %d dma channel %d\n", slot + 1, tmp_io_addr,
269 esp->irq, esp->dma);
270
271 mca_set_adapter_name(slot, "NCR 53C9X SCSI Adapter");
272 mca_mark_as_used(slot);
273
274 break;
275 }
276
277 id_to_check++;
278 }
279
280 return esps_in_use;
281}
282
283
284/******************************************************************* Release */
285
286static int mca_esp_release(struct Scsi_Host *host)
287{
288 struct NCR_ESP *esp = (struct NCR_ESP *)host->hostdata;
289 unsigned char tmp_byte;
290
291 esp_deallocate(esp);
292 /*
293 * Tell the 86C01 to stop sending interrupts
294 */
295
296 tmp_byte = inb(esp->eregs->io_addr - 0x0E);
297 tmp_byte &= ~0x40;
298 outb(tmp_byte, esp->eregs->io_addr - 0x0E);
299
300 free_irq(esp->irq, esp_intr);
301 free_dma(esp->dma);
302
303 mca_mark_as_unused(esp->slot);
304
305 return 0;
306}
307
308/************************************************************* DMA Functions */
309static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
310{
311 /* Ask the 53c9x. It knows. */
312
313 return fifo_count;
314}
315
316static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
317{
318 /*
319 * The MCA dma channels can only do up to 128K bytes at a time.
320 * (16 bit mode)
321 */
322
323 unsigned long sz = sp->SCp.this_residual;
324 if(sz > 0x20000)
325 sz = 0x20000;
326 return sz;
327}
328
329static void dma_dump_state(struct NCR_ESP *esp)
330{
331 /*
332 * Doesn't quite match up to the other drivers, but we do what we
333 * can.
334 */
335
336 ESPLOG(("esp%d: dma channel <%d>\n", esp->esp_id, esp->dma));
337 ESPLOG(("bytes left to dma: %d\n", mca_get_dma_residue(esp->dma)));
338}
339
340static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
341{
342 unsigned long flags;
343
344
345 save_flags(flags);
346 cli();
347
348 mca_disable_dma(esp->dma);
349 mca_set_dma_mode(esp->dma, MCA_DMA_MODE_XFER | MCA_DMA_MODE_16 |
350 MCA_DMA_MODE_IO);
351 mca_set_dma_addr(esp->dma, addr);
352 mca_set_dma_count(esp->dma, length / 2); /* !!! */
353 mca_enable_dma(esp->dma);
354
355 restore_flags(flags);
356}
357
358static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
359{
360 unsigned long flags;
361
362
363 save_flags(flags);
364 cli();
365
366 mca_disable_dma(esp->dma);
367 mca_set_dma_mode(esp->dma, MCA_DMA_MODE_XFER | MCA_DMA_MODE_WRITE |
368 MCA_DMA_MODE_16 | MCA_DMA_MODE_IO);
369 mca_set_dma_addr(esp->dma, addr);
370 mca_set_dma_count(esp->dma, length / 2); /* !!! */
371 mca_enable_dma(esp->dma);
372
373 restore_flags(flags);
374}
375
376static void dma_ints_off(struct NCR_ESP *esp)
377{
378 /*
379 * Tell the 'C01 to shut up. All interrupts are routed through it.
380 */
381
382 outb(inb(esp->eregs->io_addr - 0x0E) & ~0x40,
383 esp->eregs->io_addr - 0x0E);
384}
385
386static void dma_ints_on(struct NCR_ESP *esp)
387{
388 /*
389 * Ok. You can speak again.
390 */
391
392 outb(inb(esp->eregs->io_addr - 0x0E) | 0x40,
393 esp->eregs->io_addr - 0x0E);
394}
395
396static int dma_irq_p(struct NCR_ESP *esp)
397{
398 /*
399 * DaveM says that this should return a "yes" if there is an interrupt
400 * or a DMA error occurred. I copied the Amiga driver's semantics,
401 * though, because it seems to work and we can't really tell if
402 * a DMA error happened. This gives the "yes" if the scsi chip
403 * is sending an interrupt and no DMA activity is taking place
404 */
405
406 return (!(inb(esp->eregs->io_addr - 0x04) & 1) &&
407 !(inb(esp->eregs->io_addr - 0x04) & 2) );
408}
409
410static int dma_ports_p(struct NCR_ESP *esp)
411{
412 /*
413 * Check to see if interrupts are enabled on the 'C01 (in case abort
414 * is entered multiple times, so we only do the abort once)
415 */
416
417 return (inb(esp->eregs->io_addr - 0x0E) & 0x40) ? 1:0;
418}
419
420static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
421{
422 if(write){
423 dma_init_write(esp, addr, count);
424 } else {
425 dma_init_read(esp, addr, count);
426 }
427}
428
429/*
430 * These will not play nicely with other disk controllers that try to use the
431 * disk active LED... but what can you do? Don't answer that.
432 *
433 * Stolen shamelessly from ibmmca.c -- IBM Microchannel SCSI adapter driver
434 *
435 */
436
437static void dma_led_on(struct NCR_ESP *esp)
438{
439 outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR);
440}
441
442static void dma_led_off(struct NCR_ESP *esp)
443{
444 outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR);
445}
446
447static struct scsi_host_template driver_template = {
448 .proc_name = "mca_53c9x",
449 .name = "NCR 53c9x SCSI",
450 .detect = mca_esp_detect,
451 .slave_alloc = esp_slave_alloc,
452 .slave_destroy = esp_slave_destroy,
453 .release = mca_esp_release,
454 .queuecommand = esp_queue,
455 .eh_abort_handler = esp_abort,
456 .eh_bus_reset_handler = esp_reset,
457 .can_queue = 7,
458 .sg_tablesize = SG_ALL,
459 .cmd_per_lun = 1,
460 .unchecked_isa_dma = 1,
461 .use_clustering = DISABLE_CLUSTERING
462};
463
464
465#include "scsi_module.c"
466
467/*
468 * OK, here's the goods I promised. The NCR 86C01 is an MCA interface chip
469 * that handles enabling/diabling IRQ, dma interfacing, IO port selection
470 * and other fun stuff. It takes up 16 addresses, and the chip it is
471 * connnected to gets the following 16. Registers are as follows:
472 *
473 * Offsets 0-1 : Card ID
474 *
475 * Offset 2 : Mode enable register --
476 * Bit 7 : Data Word width (1 = 16, 0 = 8)
477 * Bit 6 : IRQ enable (1 = enabled)
478 * Bits 5,4 : IRQ select
479 * 0 0 : IRQ 3
480 * 0 1 : IRQ 5
481 * 1 0 : IRQ 7
482 * 1 1 : IRQ 9
483 * Bits 3-1 : Base Address
484 * 0 0 0 : <disabled>
485 * 0 0 1 : 0x0240
486 * 0 1 0 : 0x0340
487 * 0 1 1 : 0x0400
488 * 1 0 0 : 0x0420
489 * 1 0 1 : 0x3240
490 * 1 1 0 : 0x8240
491 * 1 1 1 : 0xA240
492 * Bit 0 : Card enable (1 = enabled)
493 *
494 * Offset 3 : DMA control register --
495 * Bit 7 : DMA enable (1 = enabled)
496 * Bits 6,5 : Preemt Count Select (transfers to complete after
497 * 'C01 has been preempted on MCA bus)
498 * 0 0 : 0
499 * 0 1 : 1
500 * 1 0 : 3
501 * 1 1 : 7
502 * (all these wacky numbers; I'm sure there's a reason somewhere)
503 * Bit 4 : Fairness enable (1 = fair bus priority)
504 * Bits 3-0 : Arbitration level (0-15 consecutive)
505 *
506 * Offset 4 : General purpose register
507 * Bits 7-3 : User definable (here, 7,6 are SCSI ID)
508 * Bits 2-0 : reserved
509 *
510 * Offset 10 : DMA decode register (used for IO based DMA; also can do
511 * PIO through this port)
512 *
513 * Offset 12 : Status
514 * Bits 7-2 : reserved
515 * Bit 1 : DMA pending (1 = pending)
516 * Bit 0 : IRQ pending (0 = pending)
517 *
518 * Exciting, huh?
519 *
520 */
diff --git a/drivers/scsi/oktagon_esp.c b/drivers/scsi/oktagon_esp.c
deleted file mode 100644
index 8e5eadbd5c51..000000000000
--- a/drivers/scsi/oktagon_esp.c
+++ /dev/null
@@ -1,606 +0,0 @@
1/*
2 * Oktagon_esp.c -- Driver for bsc Oktagon
3 *
4 * Written by Carsten Pluntke 1998
5 *
6 * Based on cyber_esp.c
7 */
8
9
10#if defined(CONFIG_AMIGA) || defined(CONFIG_APUS)
11#define USE_BOTTOM_HALF
12#endif
13
14#include <linux/module.h>
15
16#include <linux/kernel.h>
17#include <linux/delay.h>
18#include <linux/types.h>
19#include <linux/string.h>
20#include <linux/slab.h>
21#include <linux/blkdev.h>
22#include <linux/proc_fs.h>
23#include <linux/stat.h>
24#include <linux/reboot.h>
25#include <asm/system.h>
26#include <asm/ptrace.h>
27#include <asm/pgtable.h>
28
29
30#include "scsi.h"
31#include <scsi/scsi_host.h>
32#include "NCR53C9x.h"
33
34#include <linux/zorro.h>
35#include <asm/irq.h>
36#include <asm/amigaints.h>
37#include <asm/amigahw.h>
38
39#ifdef USE_BOTTOM_HALF
40#include <linux/workqueue.h>
41#include <linux/interrupt.h>
42#endif
43
44/* The controller registers can be found in the Z2 config area at these
45 * offsets:
46 */
47#define OKTAGON_ESP_ADDR 0x03000
48#define OKTAGON_DMA_ADDR 0x01000
49
50
51static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
52static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
53static void dma_dump_state(struct NCR_ESP *esp);
54static void dma_init_read(struct NCR_ESP *esp, __u32 vaddress, int length);
55static void dma_init_write(struct NCR_ESP *esp, __u32 vaddress, int length);
56static void dma_ints_off(struct NCR_ESP *esp);
57static void dma_ints_on(struct NCR_ESP *esp);
58static int dma_irq_p(struct NCR_ESP *esp);
59static void dma_led_off(struct NCR_ESP *esp);
60static void dma_led_on(struct NCR_ESP *esp);
61static int dma_ports_p(struct NCR_ESP *esp);
62static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
63
64static void dma_irq_exit(struct NCR_ESP *esp);
65static void dma_invalidate(struct NCR_ESP *esp);
66
67static void dma_mmu_get_scsi_one(struct NCR_ESP *,Scsi_Cmnd *);
68static void dma_mmu_get_scsi_sgl(struct NCR_ESP *,Scsi_Cmnd *);
69static void dma_mmu_release_scsi_one(struct NCR_ESP *,Scsi_Cmnd *);
70static void dma_mmu_release_scsi_sgl(struct NCR_ESP *,Scsi_Cmnd *);
71static void dma_advance_sg(Scsi_Cmnd *);
72static int oktagon_notify_reboot(struct notifier_block *this, unsigned long code, void *x);
73
74#ifdef USE_BOTTOM_HALF
75static void dma_commit(struct work_struct *unused);
76
77long oktag_to_io(long *paddr, long *addr, long len);
78long oktag_from_io(long *addr, long *paddr, long len);
79
80static DECLARE_WORK(tq_fake_dma, dma_commit);
81
82#define DMA_MAXTRANSFER 0x8000
83
84#else
85
86/*
87 * No bottom half. Use transfer directly from IRQ. Find a narrow path
88 * between too much IRQ overhead and clogging the IRQ for too long.
89 */
90
91#define DMA_MAXTRANSFER 0x1000
92
93#endif
94
95static struct notifier_block oktagon_notifier = {
96 oktagon_notify_reboot,
97 NULL,
98 0
99};
100
101static long *paddress;
102static long *address;
103static long len;
104static long dma_on;
105static int direction;
106static struct NCR_ESP *current_esp;
107
108
109static volatile unsigned char cmd_buffer[16];
110 /* This is where all commands are put
111 * before they are trasfered to the ESP chip
112 * via PIO.
113 */
114
115/***************************************************************** Detection */
116int oktagon_esp_detect(struct scsi_host_template *tpnt)
117{
118 struct NCR_ESP *esp;
119 struct zorro_dev *z = NULL;
120 unsigned long address;
121 struct ESP_regs *eregs;
122
123 while ((z = zorro_find_device(ZORRO_PROD_BSC_OKTAGON_2008, z))) {
124 unsigned long board = z->resource.start;
125 if (request_mem_region(board+OKTAGON_ESP_ADDR,
126 sizeof(struct ESP_regs), "NCR53C9x")) {
127 /*
128 * It is a SCSI controller.
129 * Hardwire Host adapter to SCSI ID 7
130 */
131
132 address = (unsigned long)ZTWO_VADDR(board);
133 eregs = (struct ESP_regs *)(address + OKTAGON_ESP_ADDR);
134
135 /* This line was 5 lines lower */
136 esp = esp_allocate(tpnt, (void *)board + OKTAGON_ESP_ADDR, 0);
137
138 /* we have to shift the registers only one bit for oktagon */
139 esp->shift = 1;
140
141 esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
142 udelay(5);
143 if (esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7))
144 return 0; /* Bail out if address did not hold data */
145
146 /* Do command transfer with programmed I/O */
147 esp->do_pio_cmds = 1;
148
149 /* Required functions */
150 esp->dma_bytes_sent = &dma_bytes_sent;
151 esp->dma_can_transfer = &dma_can_transfer;
152 esp->dma_dump_state = &dma_dump_state;
153 esp->dma_init_read = &dma_init_read;
154 esp->dma_init_write = &dma_init_write;
155 esp->dma_ints_off = &dma_ints_off;
156 esp->dma_ints_on = &dma_ints_on;
157 esp->dma_irq_p = &dma_irq_p;
158 esp->dma_ports_p = &dma_ports_p;
159 esp->dma_setup = &dma_setup;
160
161 /* Optional functions */
162 esp->dma_barrier = 0;
163 esp->dma_drain = 0;
164 esp->dma_invalidate = &dma_invalidate;
165 esp->dma_irq_entry = 0;
166 esp->dma_irq_exit = &dma_irq_exit;
167 esp->dma_led_on = &dma_led_on;
168 esp->dma_led_off = &dma_led_off;
169 esp->dma_poll = 0;
170 esp->dma_reset = 0;
171
172 esp->dma_mmu_get_scsi_one = &dma_mmu_get_scsi_one;
173 esp->dma_mmu_get_scsi_sgl = &dma_mmu_get_scsi_sgl;
174 esp->dma_mmu_release_scsi_one = &dma_mmu_release_scsi_one;
175 esp->dma_mmu_release_scsi_sgl = &dma_mmu_release_scsi_sgl;
176 esp->dma_advance_sg = &dma_advance_sg;
177
178 /* SCSI chip speed */
179 /* Looking at the quartz of the SCSI board... */
180 esp->cfreq = 25000000;
181
182 /* The DMA registers on the CyberStorm are mapped
183 * relative to the device (i.e. in the same Zorro
184 * I/O block).
185 */
186 esp->dregs = (void *)(address + OKTAGON_DMA_ADDR);
187
188 paddress = (long *) esp->dregs;
189
190 /* ESP register base */
191 esp->eregs = eregs;
192
193 /* Set the command buffer */
194 esp->esp_command = (volatile unsigned char*) cmd_buffer;
195
196 /* Yes, the virtual address. See below. */
197 esp->esp_command_dvma = (__u32) cmd_buffer;
198
199 esp->irq = IRQ_AMIGA_PORTS;
200 request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
201 "BSC Oktagon SCSI", esp->ehost);
202
203 /* Figure out our scsi ID on the bus */
204 esp->scsi_id = 7;
205
206 /* We don't have a differential SCSI-bus. */
207 esp->diff = 0;
208
209 esp_initialize(esp);
210
211 printk("ESP_Oktagon Driver 1.1"
212#ifdef USE_BOTTOM_HALF
213 " [BOTTOM_HALF]"
214#else
215 " [IRQ]"
216#endif
217 " registered.\n");
218 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps,esps_in_use);
219 esps_running = esps_in_use;
220 current_esp = esp;
221 register_reboot_notifier(&oktagon_notifier);
222 return esps_in_use;
223 }
224 }
225 return 0;
226}
227
228
229/*
230 * On certain configurations the SCSI equipment gets confused on reboot,
231 * so we have to reset it then.
232 */
233
234static int
235oktagon_notify_reboot(struct notifier_block *this, unsigned long code, void *x)
236{
237 struct NCR_ESP *esp;
238
239 if((code == SYS_DOWN || code == SYS_HALT) && (esp = current_esp))
240 {
241 esp_bootup_reset(esp,esp->eregs);
242 udelay(500); /* Settle time. Maybe unnecessary. */
243 }
244 return NOTIFY_DONE;
245}
246
247
248
249#ifdef USE_BOTTOM_HALF
250
251
252/*
253 * The bsc Oktagon controller has no real DMA, so we have to do the 'DMA
254 * transfer' in the interrupt (Yikes!) or use a bottom half to not to clutter
255 * IRQ's for longer-than-good.
256 *
257 * FIXME
258 * BIG PROBLEM: 'len' is usually the buffer length, not the expected length
259 * of the data. So DMA may finish prematurely, further reads lead to
260 * 'machine check' on APUS systems (don't know about m68k systems, AmigaOS
261 * deliberately ignores the bus faults) and a normal copy-loop can't
262 * be exited prematurely just at the right moment by the dma_invalidate IRQ.
263 * So do it the hard way, write an own copier in assembler and
264 * catch the exception.
265 * -- Carsten
266 */
267
268
269static void dma_commit(struct work_struct *unused)
270{
271 long wait,len2,pos;
272 struct NCR_ESP *esp;
273
274 ESPDATA(("Transfer: %ld bytes, Address 0x%08lX, Direction: %d\n",
275 len,(long) address,direction));
276 dma_ints_off(current_esp);
277
278 pos = 0;
279 wait = 1;
280 if(direction) /* write? (memory to device) */
281 {
282 while(len > 0)
283 {
284 len2 = oktag_to_io(paddress, address+pos, len);
285 if(!len2)
286 {
287 if(wait > 1000)
288 {
289 printk("Expedited DMA exit (writing) %ld\n",len);
290 break;
291 }
292 mdelay(wait);
293 wait *= 2;
294 }
295 pos += len2;
296 len -= len2*sizeof(long);
297 }
298 } else {
299 while(len > 0)
300 {
301 len2 = oktag_from_io(address+pos, paddress, len);
302 if(!len2)
303 {
304 if(wait > 1000)
305 {
306 printk("Expedited DMA exit (reading) %ld\n",len);
307 break;
308 }
309 mdelay(wait);
310 wait *= 2;
311 }
312 pos += len2;
313 len -= len2*sizeof(long);
314 }
315 }
316
317 /* to make esp->shift work */
318 esp=current_esp;
319
320#if 0
321 len2 = (esp_read(current_esp->eregs->esp_tclow) & 0xff) |
322 ((esp_read(current_esp->eregs->esp_tcmed) & 0xff) << 8);
323
324 /*
325 * Uh uh. If you see this, len and transfer count registers were out of
326 * sync. That means really serious trouble.
327 */
328
329 if(len2)
330 printk("Eeeek!! Transfer count still %ld!\n",len2);
331#endif
332
333 /*
334 * Normally we just need to exit and wait for the interrupt to come.
335 * But at least one device (my Microtek ScanMaker 630) regularly mis-
336 * calculates the bytes it should send which is really ugly because
337 * it locks up the SCSI bus if not accounted for.
338 */
339
340 if(!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR))
341 {
342 long len = 100;
343 long trash[10];
344
345 /*
346 * Interrupt bit was not set. Either the device is just plain lazy
347 * so we give it a 10 ms chance or...
348 */
349 while(len-- && (!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR)))
350 udelay(100);
351
352
353 if(!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR))
354 {
355 /*
356 * So we think that the transfer count is out of sync. Since we
357 * have all we want we are happy and can ditch the trash.
358 */
359
360 len = DMA_MAXTRANSFER;
361
362 while(len-- && (!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR)))
363 oktag_from_io(trash,paddress,2);
364
365 if(!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR))
366 {
367 /*
368 * Things really have gone wrong. If we leave the system in that
369 * state, the SCSI bus is locked forever. I hope that this will
370 * turn the system in a more or less running state.
371 */
372 printk("Device is bolixed, trying bus reset...\n");
373 esp_bootup_reset(current_esp,current_esp->eregs);
374 }
375 }
376 }
377
378 ESPDATA(("Transfer_finale: do_data_finale should come\n"));
379
380 len = 0;
381 dma_on = 0;
382 dma_ints_on(current_esp);
383}
384
385#endif
386
387/************************************************************* DMA Functions */
388static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
389{
390 /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
391 * the number of bytes sent (to the ESP chip) equals the number
392 * of bytes in the FIFO - there is no buffering in the DMA controller.
393 * XXXX Do I read this right? It is from host to ESP, right?
394 */
395 return fifo_count;
396}
397
398static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
399{
400 unsigned long sz = sp->SCp.this_residual;
401 if(sz > DMA_MAXTRANSFER)
402 sz = DMA_MAXTRANSFER;
403 return sz;
404}
405
406static void dma_dump_state(struct NCR_ESP *esp)
407{
408}
409
410/*
411 * What the f$@& is this?
412 *
413 * Some SCSI devices (like my Microtek ScanMaker 630 scanner) want to transfer
414 * more data than requested. How much? Dunno. So ditch the bogus data into
415 * the sink, hoping the device will advance to the next phase sooner or later.
416 *
417 * -- Carsten
418 */
419
420static long oktag_eva_buffer[16]; /* The data sink */
421
422static void oktag_check_dma(void)
423{
424 struct NCR_ESP *esp;
425
426 esp=current_esp;
427 if(!len)
428 {
429 address = oktag_eva_buffer;
430 len = 2;
431 /* esp_do_data sets them to zero like len */
432 esp_write(current_esp->eregs->esp_tclow,2);
433 esp_write(current_esp->eregs->esp_tcmed,0);
434 }
435}
436
437static void dma_init_read(struct NCR_ESP *esp, __u32 vaddress, int length)
438{
439 /* Zorro is noncached, everything else done using processor. */
440 /* cache_clear(addr, length); */
441
442 if(dma_on)
443 panic("dma_init_read while dma process is initialized/running!\n");
444 direction = 0;
445 address = (long *) vaddress;
446 current_esp = esp;
447 len = length;
448 oktag_check_dma();
449 dma_on = 1;
450}
451
452static void dma_init_write(struct NCR_ESP *esp, __u32 vaddress, int length)
453{
454 /* cache_push(addr, length); */
455
456 if(dma_on)
457 panic("dma_init_write while dma process is initialized/running!\n");
458 direction = 1;
459 address = (long *) vaddress;
460 current_esp = esp;
461 len = length;
462 oktag_check_dma();
463 dma_on = 1;
464}
465
466static void dma_ints_off(struct NCR_ESP *esp)
467{
468 disable_irq(esp->irq);
469}
470
471static void dma_ints_on(struct NCR_ESP *esp)
472{
473 enable_irq(esp->irq);
474}
475
476static int dma_irq_p(struct NCR_ESP *esp)
477{
478 /* It's important to check the DMA IRQ bit in the correct way! */
479 return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
480}
481
482static void dma_led_off(struct NCR_ESP *esp)
483{
484}
485
486static void dma_led_on(struct NCR_ESP *esp)
487{
488}
489
490static int dma_ports_p(struct NCR_ESP *esp)
491{
492 return ((amiga_custom.intenar) & IF_PORTS);
493}
494
495static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
496{
497 /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
498 * so when (write) is true, it actually means READ!
499 */
500 if(write){
501 dma_init_read(esp, addr, count);
502 } else {
503 dma_init_write(esp, addr, count);
504 }
505}
506
507/*
508 * IRQ entry when DMA transfer is ready to be started
509 */
510
511static void dma_irq_exit(struct NCR_ESP *esp)
512{
513#ifdef USE_BOTTOM_HALF
514 if(dma_on)
515 {
516 schedule_work(&tq_fake_dma);
517 }
518#else
519 while(len && !dma_irq_p(esp))
520 {
521 if(direction)
522 *paddress = *address++;
523 else
524 *address++ = *paddress;
525 len -= (sizeof(long));
526 }
527 len = 0;
528 dma_on = 0;
529#endif
530}
531
532/*
533 * IRQ entry when DMA has just finished
534 */
535
536static void dma_invalidate(struct NCR_ESP *esp)
537{
538}
539
540/*
541 * Since the processor does the data transfer we have to use the custom
542 * mmu interface to pass the virtual address, not the physical.
543 */
544
545void dma_mmu_get_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd *sp)
546{
547 sp->SCp.ptr =
548 sp->request_buffer;
549}
550
551void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd *sp)
552{
553 sp->SCp.ptr = sg_virt(sp->SCp.buffer);
554}
555
556void dma_mmu_release_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd *sp)
557{
558}
559
560void dma_mmu_release_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd *sp)
561{
562}
563
564void dma_advance_sg(Scsi_Cmnd *sp)
565{
566 sp->SCp.ptr = sg_virt(sp->SCp.buffer);
567}
568
569
570#define HOSTS_C
571
572int oktagon_esp_release(struct Scsi_Host *instance)
573{
574#ifdef MODULE
575 unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
576 esp_release();
577 release_mem_region(address, sizeof(struct ESP_regs));
578 free_irq(IRQ_AMIGA_PORTS, esp_intr);
579 unregister_reboot_notifier(&oktagon_notifier);
580#endif
581 return 1;
582}
583
584
585static struct scsi_host_template driver_template = {
586 .proc_name = "esp-oktagon",
587 .proc_info = &esp_proc_info,
588 .name = "BSC Oktagon SCSI",
589 .detect = oktagon_esp_detect,
590 .slave_alloc = esp_slave_alloc,
591 .slave_destroy = esp_slave_destroy,
592 .release = oktagon_esp_release,
593 .queuecommand = esp_queue,
594 .eh_abort_handler = esp_abort,
595 .eh_bus_reset_handler = esp_reset,
596 .can_queue = 7,
597 .this_id = 7,
598 .sg_tablesize = SG_ALL,
599 .cmd_per_lun = 1,
600 .use_clustering = ENABLE_CLUSTERING
601};
602
603
604#include "scsi_module.c"
605
606MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/oktagon_io.S b/drivers/scsi/oktagon_io.S
deleted file mode 100644
index 8a7340b02707..000000000000
--- a/drivers/scsi/oktagon_io.S
+++ /dev/null
@@ -1,194 +0,0 @@
1/* -*- mode: asm -*-
2 * Due to problems while transferring data I've put these routines as assembly
3 * code.
4 * Since I'm no PPC assembler guru, the code is just the assembler version of
5
6int oktag_to_io(long *paddr,long *addr,long len)
7{
8 long *addr2 = addr;
9 for(len=(len+sizeof(long)-1)/sizeof(long);len--;)
10 *paddr = *addr2++;
11 return addr2 - addr;
12}
13
14int oktag_from_io(long *addr,long *paddr,long len)
15{
16 long *addr2 = addr;
17 for(len=(len+sizeof(long)-1)/sizeof(long);len--;)
18 *addr2++ = *paddr;
19 return addr2 - addr;
20}
21
22 * assembled using gcc -O2 -S, with two exception catch points where data
23 * is moved to/from the IO register.
24 */
25
26
27#ifdef CONFIG_APUS
28
29 .file "oktagon_io.c"
30
31gcc2_compiled.:
32/*
33 .section ".text"
34*/
35 .align 2
36 .globl oktag_to_io
37 .type oktag_to_io,@function
38oktag_to_io:
39 addi 5,5,3
40 srwi 5,5,2
41 cmpwi 1,5,0
42 mr 9,3
43 mr 3,4
44 addi 5,5,-1
45 bc 12,6,.L3
46.L5:
47 cmpwi 1,5,0
48 lwz 0,0(3)
49 addi 3,3,4
50 addi 5,5,-1
51exp1: stw 0,0(9)
52 bc 4,6,.L5
53.L3:
54ret1: subf 3,4,3
55 srawi 3,3,2
56 blr
57.Lfe1:
58 .size oktag_to_io,.Lfe1-oktag_to_io
59 .align 2
60 .globl oktag_from_io
61 .type oktag_from_io,@function
62oktag_from_io:
63 addi 5,5,3
64 srwi 5,5,2
65 cmpwi 1,5,0
66 mr 9,3
67 addi 5,5,-1
68 bc 12,6,.L9
69.L11:
70 cmpwi 1,5,0
71exp2: lwz 0,0(4)
72 addi 5,5,-1
73 stw 0,0(3)
74 addi 3,3,4
75 bc 4,6,.L11
76.L9:
77ret2: subf 3,9,3
78 srawi 3,3,2
79 blr
80.Lfe2:
81 .size oktag_from_io,.Lfe2-oktag_from_io
82 .ident "GCC: (GNU) egcs-2.90.29 980515 (egcs-1.0.3 release)"
83
84/*
85 * Exception table.
86 * Second longword shows where to jump when an exception at the addr the first
87 * longword is pointing to is caught.
88 */
89
90.section __ex_table,"a"
91 .align 2
92oktagon_except:
93 .long exp1,ret1
94 .long exp2,ret2
95
96#else
97
98/*
99The code which follows is for 680x0 based assembler and is meant for
100Linux/m68k. It was created by cross compiling the code using the
101instructions given above. I then added the four labels used in the
102exception handler table at the bottom of this file.
103- Kevin <kcozens@interlog.com>
104*/
105
106#ifdef CONFIG_AMIGA
107
108 .file "oktagon_io.c"
109 .version "01.01"
110gcc2_compiled.:
111.text
112 .align 2
113.globl oktag_to_io
114 .type oktag_to_io,@function
115oktag_to_io:
116 link.w %a6,#0
117 move.l %d2,-(%sp)
118 move.l 8(%a6),%a1
119 move.l 12(%a6),%d1
120 move.l %d1,%a0
121 move.l 16(%a6),%d0
122 addq.l #3,%d0
123 lsr.l #2,%d0
124 subq.l #1,%d0
125 moveq.l #-1,%d2
126 cmp.l %d0,%d2
127 jbeq .L3
128.L5:
129exp1:
130 move.l (%a0)+,(%a1)
131 dbra %d0,.L5
132 clr.w %d0
133 subq.l #1,%d0
134 jbcc .L5
135.L3:
136ret1:
137 move.l %a0,%d0
138 sub.l %d1,%d0
139 asr.l #2,%d0
140 move.l -4(%a6),%d2
141 unlk %a6
142 rts
143
144.Lfe1:
145 .size oktag_to_io,.Lfe1-oktag_to_io
146 .align 2
147.globl oktag_from_io
148 .type oktag_from_io,@function
149oktag_from_io:
150 link.w %a6,#0
151 move.l %d2,-(%sp)
152 move.l 8(%a6),%d1
153 move.l 12(%a6),%a1
154 move.l %d1,%a0
155 move.l 16(%a6),%d0
156 addq.l #3,%d0
157 lsr.l #2,%d0
158 subq.l #1,%d0
159 moveq.l #-1,%d2
160 cmp.l %d0,%d2
161 jbeq .L9
162.L11:
163exp2:
164 move.l (%a1),(%a0)+
165 dbra %d0,.L11
166 clr.w %d0
167 subq.l #1,%d0
168 jbcc .L11
169.L9:
170ret2:
171 move.l %a0,%d0
172 sub.l %d1,%d0
173 asr.l #2,%d0
174 move.l -4(%a6),%d2
175 unlk %a6
176 rts
177.Lfe2:
178 .size oktag_from_io,.Lfe2-oktag_from_io
179 .ident "GCC: (GNU) 2.7.2.1"
180
181/*
182 * Exception table.
183 * Second longword shows where to jump when an exception at the addr the first
184 * longword is pointing to is caught.
185 */
186
187.section __ex_table,"a"
188 .align 2
189oktagon_except:
190 .long exp1,ret1
191 .long exp2,ret2
192
193#endif
194#endif
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index 17b4a7c4618c..0cd614a0fa73 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -35,7 +35,7 @@
35 35
36#define BOUNCE_SIZE (64*1024) 36#define BOUNCE_SIZE (64*1024)
37 37
38#define PS3ROM_MAX_SECTORS (BOUNCE_SIZE / CD_FRAMESIZE) 38#define PS3ROM_MAX_SECTORS (BOUNCE_SIZE >> 9)
39 39
40 40
41struct ps3rom_private { 41struct ps3rom_private {
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index adf97320574b..4894dc886b62 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -428,6 +428,19 @@ qla2x00_sysfs_read_sfp(struct kobject *kobj,
428 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2) 428 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
429 return 0; 429 return 0;
430 430
431 if (ha->sfp_data)
432 goto do_read;
433
434 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
435 &ha->sfp_data_dma);
436 if (!ha->sfp_data) {
437 qla_printk(KERN_WARNING, ha,
438 "Unable to allocate memory for SFP read-data.\n");
439 return 0;
440 }
441
442do_read:
443 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
431 addr = 0xa0; 444 addr = 0xa0;
432 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE; 445 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
433 iter++, offset += SFP_BLOCK_SIZE) { 446 iter++, offset += SFP_BLOCK_SIZE) {
@@ -835,7 +848,7 @@ qla2x00_get_host_port_id(struct Scsi_Host *shost)
835static void 848static void
836qla2x00_get_host_speed(struct Scsi_Host *shost) 849qla2x00_get_host_speed(struct Scsi_Host *shost)
837{ 850{
838 scsi_qla_host_t *ha = shost_priv(shost); 851 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
839 uint32_t speed = 0; 852 uint32_t speed = 0;
840 853
841 switch (ha->link_data_rate) { 854 switch (ha->link_data_rate) {
@@ -848,6 +861,9 @@ qla2x00_get_host_speed(struct Scsi_Host *shost)
848 case PORT_SPEED_4GB: 861 case PORT_SPEED_4GB:
849 speed = 4; 862 speed = 4;
850 break; 863 break;
864 case PORT_SPEED_8GB:
865 speed = 8;
866 break;
851 } 867 }
852 fc_host_speed(shost) = speed; 868 fc_host_speed(shost) = speed;
853} 869}
@@ -855,7 +871,7 @@ qla2x00_get_host_speed(struct Scsi_Host *shost)
855static void 871static void
856qla2x00_get_host_port_type(struct Scsi_Host *shost) 872qla2x00_get_host_port_type(struct Scsi_Host *shost)
857{ 873{
858 scsi_qla_host_t *ha = shost_priv(shost); 874 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
859 uint32_t port_type = FC_PORTTYPE_UNKNOWN; 875 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
860 876
861 switch (ha->current_topology) { 877 switch (ha->current_topology) {
@@ -965,7 +981,7 @@ qla2x00_issue_lip(struct Scsi_Host *shost)
965static struct fc_host_statistics * 981static struct fc_host_statistics *
966qla2x00_get_fc_host_stats(struct Scsi_Host *shost) 982qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
967{ 983{
968 scsi_qla_host_t *ha = shost_priv(shost); 984 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
969 int rval; 985 int rval;
970 struct link_statistics *stats; 986 struct link_statistics *stats;
971 dma_addr_t stats_dma; 987 dma_addr_t stats_dma;
@@ -1049,7 +1065,7 @@ qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1049static void 1065static void
1050qla2x00_get_host_port_state(struct Scsi_Host *shost) 1066qla2x00_get_host_port_state(struct Scsi_Host *shost)
1051{ 1067{
1052 scsi_qla_host_t *ha = shost_priv(shost); 1068 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
1053 1069
1054 if (!ha->flags.online) 1070 if (!ha->flags.online)
1055 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 1071 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index b72c7f170854..3750319f4968 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2041,8 +2041,6 @@ typedef struct vport_params {
2041#define VP_RET_CODE_NO_MEM 5 2041#define VP_RET_CODE_NO_MEM 5
2042#define VP_RET_CODE_NOT_FOUND 6 2042#define VP_RET_CODE_NOT_FOUND 6
2043 2043
2044#define to_qla_parent(x) (((x)->parent) ? (x)->parent : (x))
2045
2046/* 2044/*
2047 * ISP operations 2045 * ISP operations
2048 */ 2046 */
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index ba35fc26ce6b..193f688ec3d7 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -66,6 +66,7 @@ extern int ql2xqfullrampup;
66extern int num_hosts; 66extern int num_hosts;
67 67
68extern int qla2x00_loop_reset(scsi_qla_host_t *); 68extern int qla2x00_loop_reset(scsi_qla_host_t *);
69extern void qla2x00_abort_all_cmds(scsi_qla_host_t *, int);
69 70
70/* 71/*
71 * Global Functions in qla_mid.c source file. 72 * Global Functions in qla_mid.c source file.
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index d0633ca894be..d5c7853e7eba 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -925,6 +925,16 @@ qla2x00_setup_chip(scsi_qla_host_t *ha)
925{ 925{
926 int rval; 926 int rval;
927 uint32_t srisc_address = 0; 927 uint32_t srisc_address = 0;
928 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
929 unsigned long flags;
930
931 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
932 /* Disable SRAM, Instruction RAM and GP RAM parity. */
933 spin_lock_irqsave(&ha->hardware_lock, flags);
934 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
935 RD_REG_WORD(&reg->hccr);
936 spin_unlock_irqrestore(&ha->hardware_lock, flags);
937 }
928 938
929 /* Load firmware sequences */ 939 /* Load firmware sequences */
930 rval = ha->isp_ops->load_risc(ha, &srisc_address); 940 rval = ha->isp_ops->load_risc(ha, &srisc_address);
@@ -968,6 +978,19 @@ qla2x00_setup_chip(scsi_qla_host_t *ha)
968 } 978 }
969 } 979 }
970 980
981 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
982 /* Enable proper parity. */
983 spin_lock_irqsave(&ha->hardware_lock, flags);
984 if (IS_QLA2300(ha))
985 /* SRAM parity */
986 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
987 else
988 /* SRAM, Instruction RAM and GP RAM parity */
989 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
990 RD_REG_WORD(&reg->hccr);
991 spin_unlock_irqrestore(&ha->hardware_lock, flags);
992 }
993
971 if (rval) { 994 if (rval) {
972 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n", 995 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
973 ha->host_no)); 996 ha->host_no));
@@ -3213,9 +3236,6 @@ int
3213qla2x00_abort_isp(scsi_qla_host_t *ha) 3236qla2x00_abort_isp(scsi_qla_host_t *ha)
3214{ 3237{
3215 int rval; 3238 int rval;
3216 unsigned long flags = 0;
3217 uint16_t cnt;
3218 srb_t *sp;
3219 uint8_t status = 0; 3239 uint8_t status = 0;
3220 3240
3221 if (ha->flags.online) { 3241 if (ha->flags.online) {
@@ -3236,19 +3256,8 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
3236 LOOP_DOWN_TIME); 3256 LOOP_DOWN_TIME);
3237 } 3257 }
3238 3258
3239 spin_lock_irqsave(&ha->hardware_lock, flags);
3240 /* Requeue all commands in outstanding command list. */ 3259 /* Requeue all commands in outstanding command list. */
3241 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { 3260 qla2x00_abort_all_cmds(ha, DID_RESET << 16);
3242 sp = ha->outstanding_cmds[cnt];
3243 if (sp) {
3244 ha->outstanding_cmds[cnt] = NULL;
3245 sp->flags = 0;
3246 sp->cmd->result = DID_RESET << 16;
3247 sp->cmd->host_scribble = (unsigned char *)NULL;
3248 qla2x00_sp_compl(ha, sp);
3249 }
3250 }
3251 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3252 3261
3253 ha->isp_ops->get_flash_version(ha, ha->request_ring); 3262 ha->isp_ops->get_flash_version(ha, ha->request_ring);
3254 3263
@@ -3273,6 +3282,7 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
3273 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags); 3282 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3274 3283
3275 if (ha->eft) { 3284 if (ha->eft) {
3285 memset(ha->eft, 0, EFT_SIZE);
3276 rval = qla2x00_enable_eft_trace(ha, 3286 rval = qla2x00_enable_eft_trace(ha,
3277 ha->eft_dma, EFT_NUM_BUFFERS); 3287 ha->eft_dma, EFT_NUM_BUFFERS);
3278 if (rval) { 3288 if (rval) {
@@ -3357,60 +3367,15 @@ static int
3357qla2x00_restart_isp(scsi_qla_host_t *ha) 3367qla2x00_restart_isp(scsi_qla_host_t *ha)
3358{ 3368{
3359 uint8_t status = 0; 3369 uint8_t status = 0;
3360 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3361 unsigned long flags = 0;
3362 uint32_t wait_time; 3370 uint32_t wait_time;
3363 3371
3364 /* If firmware needs to be loaded */ 3372 /* If firmware needs to be loaded */
3365 if (qla2x00_isp_firmware(ha)) { 3373 if (qla2x00_isp_firmware(ha)) {
3366 ha->flags.online = 0; 3374 ha->flags.online = 0;
3367 if (!(status = ha->isp_ops->chip_diag(ha))) { 3375 if (!(status = ha->isp_ops->chip_diag(ha)))
3368 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3369 status = qla2x00_setup_chip(ha);
3370 goto done;
3371 }
3372
3373 spin_lock_irqsave(&ha->hardware_lock, flags);
3374
3375 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
3376 !IS_QLA25XX(ha)) {
3377 /*
3378 * Disable SRAM, Instruction RAM and GP RAM
3379 * parity.
3380 */
3381 WRT_REG_WORD(&reg->hccr,
3382 (HCCR_ENABLE_PARITY + 0x0));
3383 RD_REG_WORD(&reg->hccr);
3384 }
3385
3386 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3387
3388 status = qla2x00_setup_chip(ha); 3376 status = qla2x00_setup_chip(ha);
3389
3390 spin_lock_irqsave(&ha->hardware_lock, flags);
3391
3392 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
3393 !IS_QLA25XX(ha)) {
3394 /* Enable proper parity */
3395 if (IS_QLA2300(ha))
3396 /* SRAM parity */
3397 WRT_REG_WORD(&reg->hccr,
3398 (HCCR_ENABLE_PARITY + 0x1));
3399 else
3400 /*
3401 * SRAM, Instruction RAM and GP RAM
3402 * parity.
3403 */
3404 WRT_REG_WORD(&reg->hccr,
3405 (HCCR_ENABLE_PARITY + 0x7));
3406 RD_REG_WORD(&reg->hccr);
3407 }
3408
3409 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3410 }
3411 } 3377 }
3412 3378
3413 done:
3414 if (!status && !(status = qla2x00_init_rings(ha))) { 3379 if (!status && !(status = qla2x00_init_rings(ha))) {
3415 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); 3380 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3416 if (!(status = qla2x00_fw_ready(ha))) { 3381 if (!(status = qla2x00_fw_ready(ha))) {
diff --git a/drivers/scsi/qla2xxx/qla_inline.h b/drivers/scsi/qla2xxx/qla_inline.h
index 8e3b04464cff..5d1a3f7c408f 100644
--- a/drivers/scsi/qla2xxx/qla_inline.h
+++ b/drivers/scsi/qla2xxx/qla_inline.h
@@ -119,6 +119,13 @@ static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *ha)
119 qla2x00_get_firmware_state(ha, &fw_state); 119 qla2x00_get_firmware_state(ha, &fw_state);
120} 120}
121 121
122static __inline__ scsi_qla_host_t * to_qla_parent(scsi_qla_host_t *);
123static __inline__ scsi_qla_host_t *
124to_qla_parent(scsi_qla_host_t *ha)
125{
126 return ha->parent ? ha->parent : ha;
127}
128
122/** 129/**
123 * qla2x00_issue_marker() - Issue a Marker IOCB if necessary. 130 * qla2x00_issue_marker() - Issue a Marker IOCB if necessary.
124 * @ha: HA context 131 * @ha: HA context
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 642a0c3f09c6..14e6f22944b7 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1815,6 +1815,8 @@ int
1815qla2x00_request_irqs(scsi_qla_host_t *ha) 1815qla2x00_request_irqs(scsi_qla_host_t *ha)
1816{ 1816{
1817 int ret; 1817 int ret;
1818 device_reg_t __iomem *reg = ha->iobase;
1819 unsigned long flags;
1818 1820
1819 /* If possible, enable MSI-X. */ 1821 /* If possible, enable MSI-X. */
1820 if (!IS_QLA2432(ha) && !IS_QLA2532(ha)) 1822 if (!IS_QLA2432(ha) && !IS_QLA2532(ha))
@@ -1846,7 +1848,7 @@ qla2x00_request_irqs(scsi_qla_host_t *ha)
1846 DEBUG2(qla_printk(KERN_INFO, ha, 1848 DEBUG2(qla_printk(KERN_INFO, ha,
1847 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision, 1849 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1848 ha->fw_attributes)); 1850 ha->fw_attributes));
1849 return ret; 1851 goto clear_risc_ints;
1850 } 1852 }
1851 qla_printk(KERN_WARNING, ha, 1853 qla_printk(KERN_WARNING, ha,
1852 "MSI-X: Falling back-to INTa mode -- %d.\n", ret); 1854 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
@@ -1864,15 +1866,30 @@ skip_msi:
1864 1866
1865 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler, 1867 ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1866 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha); 1868 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
1867 if (!ret) { 1869 if (ret) {
1868 ha->flags.inta_enabled = 1;
1869 ha->host->irq = ha->pdev->irq;
1870 } else {
1871 qla_printk(KERN_WARNING, ha, 1870 qla_printk(KERN_WARNING, ha,
1872 "Failed to reserve interrupt %d already in use.\n", 1871 "Failed to reserve interrupt %d already in use.\n",
1873 ha->pdev->irq); 1872 ha->pdev->irq);
1873 goto fail;
1874 }
1875 ha->flags.inta_enabled = 1;
1876 ha->host->irq = ha->pdev->irq;
1877clear_risc_ints:
1878
1879 ha->isp_ops->disable_intrs(ha);
1880 spin_lock_irqsave(&ha->hardware_lock, flags);
1881 if (IS_FWI2_CAPABLE(ha)) {
1882 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1883 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1884 } else {
1885 WRT_REG_WORD(&reg->isp.semaphore, 0);
1886 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1887 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
1874 } 1888 }
1889 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1890 ha->isp_ops->enable_intrs(ha);
1875 1891
1892fail:
1876 return ret; 1893 return ret;
1877} 1894}
1878 1895
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 0c10c0b0fb73..99d29fff836d 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -980,7 +980,7 @@ qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
980 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n", 980 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
981 ha->host_no)); 981 ha->host_no));
982 982
983 if (ha->fw_attributes & BIT_2) 983 if (ha->flags.npiv_supported)
984 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE; 984 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
985 else 985 else
986 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE; 986 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 8f69caf83272..3c1b43356adb 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -204,10 +204,8 @@ static int qla2x00_do_dpc(void *data);
204 204
205static void qla2x00_rst_aen(scsi_qla_host_t *); 205static void qla2x00_rst_aen(scsi_qla_host_t *);
206 206
207static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *); 207static int qla2x00_mem_alloc(scsi_qla_host_t *);
208static void qla2x00_mem_free(scsi_qla_host_t *ha); 208static void qla2x00_mem_free(scsi_qla_host_t *ha);
209static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
210static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
211static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *); 209static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
212 210
213/* -------------------------------------------------------------------------- */ 211/* -------------------------------------------------------------------------- */
@@ -1117,6 +1115,27 @@ qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1117 return ha->isp_ops->abort_target(reset_fcport); 1115 return ha->isp_ops->abort_target(reset_fcport);
1118} 1116}
1119 1117
1118void
1119qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res)
1120{
1121 int cnt;
1122 unsigned long flags;
1123 srb_t *sp;
1124
1125 spin_lock_irqsave(&ha->hardware_lock, flags);
1126 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1127 sp = ha->outstanding_cmds[cnt];
1128 if (sp) {
1129 ha->outstanding_cmds[cnt] = NULL;
1130 sp->flags = 0;
1131 sp->cmd->result = res;
1132 sp->cmd->host_scribble = (unsigned char *)NULL;
1133 qla2x00_sp_compl(ha, sp);
1134 }
1135 }
1136 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1137}
1138
1120static int 1139static int
1121qla2xxx_slave_alloc(struct scsi_device *sdev) 1140qla2xxx_slave_alloc(struct scsi_device *sdev)
1122{ 1141{
@@ -1557,10 +1576,8 @@ static int __devinit
1557qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) 1576qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1558{ 1577{
1559 int ret = -ENODEV; 1578 int ret = -ENODEV;
1560 device_reg_t __iomem *reg;
1561 struct Scsi_Host *host; 1579 struct Scsi_Host *host;
1562 scsi_qla_host_t *ha; 1580 scsi_qla_host_t *ha;
1563 unsigned long flags = 0;
1564 char pci_info[30]; 1581 char pci_info[30];
1565 char fw_str[30]; 1582 char fw_str[30];
1566 struct scsi_host_template *sht; 1583 struct scsi_host_template *sht;
@@ -1608,6 +1625,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1608 ha->parent = NULL; 1625 ha->parent = NULL;
1609 ha->bars = bars; 1626 ha->bars = bars;
1610 ha->mem_only = mem_only; 1627 ha->mem_only = mem_only;
1628 spin_lock_init(&ha->hardware_lock);
1611 1629
1612 /* Set ISP-type information. */ 1630 /* Set ISP-type information. */
1613 qla2x00_set_isp_flags(ha); 1631 qla2x00_set_isp_flags(ha);
@@ -1621,8 +1639,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1621 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq, 1639 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1622 ha->iobase); 1640 ha->iobase);
1623 1641
1624 spin_lock_init(&ha->hardware_lock);
1625
1626 ha->prev_topology = 0; 1642 ha->prev_topology = 0;
1627 ha->init_cb_size = sizeof(init_cb_t); 1643 ha->init_cb_size = sizeof(init_cb_t);
1628 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx; 1644 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
@@ -1751,34 +1767,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1751 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n", 1767 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1752 ha->host_no, ha)); 1768 ha->host_no, ha));
1753 1769
1754 ha->isp_ops->disable_intrs(ha);
1755
1756 spin_lock_irqsave(&ha->hardware_lock, flags);
1757 reg = ha->iobase;
1758 if (IS_FWI2_CAPABLE(ha)) {
1759 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
1760 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
1761 } else {
1762 WRT_REG_WORD(&reg->isp.semaphore, 0);
1763 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
1764 WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
1765
1766 /* Enable proper parity */
1767 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1768 if (IS_QLA2300(ha))
1769 /* SRAM parity */
1770 WRT_REG_WORD(&reg->isp.hccr,
1771 (HCCR_ENABLE_PARITY + 0x1));
1772 else
1773 /* SRAM, Instruction RAM and GP RAM parity */
1774 WRT_REG_WORD(&reg->isp.hccr,
1775 (HCCR_ENABLE_PARITY + 0x7));
1776 }
1777 }
1778 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1779
1780 ha->isp_ops->enable_intrs(ha);
1781
1782 pci_set_drvdata(pdev, ha); 1770 pci_set_drvdata(pdev, ha);
1783 1771
1784 ha->flags.init_done = 1; 1772 ha->flags.init_done = 1;
@@ -1848,10 +1836,14 @@ qla2x00_remove_one(struct pci_dev *pdev)
1848static void 1836static void
1849qla2x00_free_device(scsi_qla_host_t *ha) 1837qla2x00_free_device(scsi_qla_host_t *ha)
1850{ 1838{
1839 qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16);
1840
1851 /* Disable timer */ 1841 /* Disable timer */
1852 if (ha->timer_active) 1842 if (ha->timer_active)
1853 qla2x00_stop_timer(ha); 1843 qla2x00_stop_timer(ha);
1854 1844
1845 ha->flags.online = 0;
1846
1855 /* Kill the kernel thread for this host */ 1847 /* Kill the kernel thread for this host */
1856 if (ha->dpc_thread) { 1848 if (ha->dpc_thread) {
1857 struct task_struct *t = ha->dpc_thread; 1849 struct task_struct *t = ha->dpc_thread;
@@ -1870,8 +1862,6 @@ qla2x00_free_device(scsi_qla_host_t *ha)
1870 if (ha->eft) 1862 if (ha->eft)
1871 qla2x00_disable_eft_trace(ha); 1863 qla2x00_disable_eft_trace(ha);
1872 1864
1873 ha->flags.online = 0;
1874
1875 /* Stop currently executing firmware. */ 1865 /* Stop currently executing firmware. */
1876 qla2x00_try_to_stop_firmware(ha); 1866 qla2x00_try_to_stop_firmware(ha);
1877 1867
@@ -2010,196 +2000,109 @@ qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
2010* 2000*
2011* Returns: 2001* Returns:
2012* 0 = success. 2002* 0 = success.
2013* 1 = failure. 2003* !0 = failure.
2014*/ 2004*/
2015static uint8_t 2005static int
2016qla2x00_mem_alloc(scsi_qla_host_t *ha) 2006qla2x00_mem_alloc(scsi_qla_host_t *ha)
2017{ 2007{
2018 char name[16]; 2008 char name[16];
2019 uint8_t status = 1;
2020 int retry= 10;
2021
2022 do {
2023 /*
2024 * This will loop only once if everything goes well, else some
2025 * number of retries will be performed to get around a kernel
2026 * bug where available mem is not allocated until after a
2027 * little delay and a retry.
2028 */
2029 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
2030 (ha->request_q_length + 1) * sizeof(request_t),
2031 &ha->request_dma, GFP_KERNEL);
2032 if (ha->request_ring == NULL) {
2033 qla_printk(KERN_WARNING, ha,
2034 "Memory Allocation failed - request_ring\n");
2035
2036 qla2x00_mem_free(ha);
2037 msleep(100);
2038
2039 continue;
2040 }
2041
2042 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
2043 (ha->response_q_length + 1) * sizeof(response_t),
2044 &ha->response_dma, GFP_KERNEL);
2045 if (ha->response_ring == NULL) {
2046 qla_printk(KERN_WARNING, ha,
2047 "Memory Allocation failed - response_ring\n");
2048
2049 qla2x00_mem_free(ha);
2050 msleep(100);
2051
2052 continue;
2053 }
2054
2055 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2056 &ha->gid_list_dma, GFP_KERNEL);
2057 if (ha->gid_list == NULL) {
2058 qla_printk(KERN_WARNING, ha,
2059 "Memory Allocation failed - gid_list\n");
2060
2061 qla2x00_mem_free(ha);
2062 msleep(100);
2063
2064 continue;
2065 }
2066
2067 /* get consistent memory allocated for init control block */
2068 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev,
2069 ha->init_cb_size, &ha->init_cb_dma, GFP_KERNEL);
2070 if (ha->init_cb == NULL) {
2071 qla_printk(KERN_WARNING, ha,
2072 "Memory Allocation failed - init_cb\n");
2073
2074 qla2x00_mem_free(ha);
2075 msleep(100);
2076
2077 continue;
2078 }
2079 memset(ha->init_cb, 0, ha->init_cb_size);
2080
2081 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
2082 ha->host_no);
2083 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2084 DMA_POOL_SIZE, 8, 0);
2085 if (ha->s_dma_pool == NULL) {
2086 qla_printk(KERN_WARNING, ha,
2087 "Memory Allocation failed - s_dma_pool\n");
2088
2089 qla2x00_mem_free(ha);
2090 msleep(100);
2091
2092 continue;
2093 }
2094
2095 if (qla2x00_allocate_sp_pool(ha)) {
2096 qla_printk(KERN_WARNING, ha,
2097 "Memory Allocation failed - "
2098 "qla2x00_allocate_sp_pool()\n");
2099
2100 qla2x00_mem_free(ha);
2101 msleep(100);
2102
2103 continue;
2104 }
2105
2106 /* Allocate memory for SNS commands */
2107 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2108 /* Get consistent memory allocated for SNS commands */
2109 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2110 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
2111 GFP_KERNEL);
2112 if (ha->sns_cmd == NULL) {
2113 /* error */
2114 qla_printk(KERN_WARNING, ha,
2115 "Memory Allocation failed - sns_cmd\n");
2116
2117 qla2x00_mem_free(ha);
2118 msleep(100);
2119
2120 continue;
2121 }
2122 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2123 } else {
2124 /* Get consistent memory allocated for MS IOCB */
2125 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2126 &ha->ms_iocb_dma);
2127 if (ha->ms_iocb == NULL) {
2128 /* error */
2129 qla_printk(KERN_WARNING, ha,
2130 "Memory Allocation failed - ms_iocb\n");
2131
2132 qla2x00_mem_free(ha);
2133 msleep(100);
2134
2135 continue;
2136 }
2137 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2138
2139 /*
2140 * Get consistent memory allocated for CT SNS
2141 * commands
2142 */
2143 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2144 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
2145 GFP_KERNEL);
2146 if (ha->ct_sns == NULL) {
2147 /* error */
2148 qla_printk(KERN_WARNING, ha,
2149 "Memory Allocation failed - ct_sns\n");
2150 2009
2151 qla2x00_mem_free(ha); 2010 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
2152 msleep(100); 2011 (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma,
2012 GFP_KERNEL);
2013 if (!ha->request_ring)
2014 goto fail;
2015
2016 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
2017 (ha->response_q_length + 1) * sizeof(response_t),
2018 &ha->response_dma, GFP_KERNEL);
2019 if (!ha->response_ring)
2020 goto fail_free_request_ring;
2021
2022 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2023 &ha->gid_list_dma, GFP_KERNEL);
2024 if (!ha->gid_list)
2025 goto fail_free_response_ring;
2026
2027 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2028 &ha->init_cb_dma, GFP_KERNEL);
2029 if (!ha->init_cb)
2030 goto fail_free_gid_list;
2031
2032 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
2033 ha->host_no);
2034 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2035 DMA_POOL_SIZE, 8, 0);
2036 if (!ha->s_dma_pool)
2037 goto fail_free_init_cb;
2153 2038
2154 continue; 2039 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2155 } 2040 if (!ha->srb_mempool)
2156 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt)); 2041 goto fail_free_s_dma_pool;
2157 2042
2158 if (IS_FWI2_CAPABLE(ha)) { 2043 /* Get memory for cached NVRAM */
2159 /* 2044 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2160 * Get consistent memory allocated for SFP 2045 if (!ha->nvram)
2161 * block. 2046 goto fail_free_srb_mempool;
2162 */ 2047
2163 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, 2048 /* Allocate memory for SNS commands */
2164 GFP_KERNEL, &ha->sfp_data_dma); 2049 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2165 if (ha->sfp_data == NULL) { 2050 /* Get consistent memory allocated for SNS commands */
2166 qla_printk(KERN_WARNING, ha, 2051 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2167 "Memory Allocation failed - " 2052 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2168 "sfp_data\n"); 2053 if (!ha->sns_cmd)
2169 2054 goto fail_free_nvram;
2170 qla2x00_mem_free(ha); 2055 } else {
2171 msleep(100); 2056 /* Get consistent memory allocated for MS IOCB */
2172 2057 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2173 continue; 2058 &ha->ms_iocb_dma);
2174 } 2059 if (!ha->ms_iocb)
2175 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE); 2060 goto fail_free_nvram;
2176 }
2177 }
2178
2179 /* Get memory for cached NVRAM */
2180 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2181 if (ha->nvram == NULL) {
2182 /* error */
2183 qla_printk(KERN_WARNING, ha,
2184 "Memory Allocation failed - nvram cache\n");
2185
2186 qla2x00_mem_free(ha);
2187 msleep(100);
2188
2189 continue;
2190 }
2191
2192 /* Done all allocations without any error. */
2193 status = 0;
2194
2195 } while (retry-- && status != 0);
2196 2061
2197 if (status) { 2062 /* Get consistent memory allocated for CT SNS commands */
2198 printk(KERN_WARNING 2063 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2199 "%s(): **** FAILED ****\n", __func__); 2064 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2065 if (!ha->ct_sns)
2066 goto fail_free_ms_iocb;
2200 } 2067 }
2201 2068
2202 return(status); 2069 return 0;
2070
2071fail_free_ms_iocb:
2072 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2073 ha->ms_iocb = NULL;
2074 ha->ms_iocb_dma = 0;
2075fail_free_nvram:
2076 kfree(ha->nvram);
2077 ha->nvram = NULL;
2078fail_free_srb_mempool:
2079 mempool_destroy(ha->srb_mempool);
2080 ha->srb_mempool = NULL;
2081fail_free_s_dma_pool:
2082 dma_pool_destroy(ha->s_dma_pool);
2083 ha->s_dma_pool = NULL;
2084fail_free_init_cb:
2085 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2086 ha->init_cb_dma);
2087 ha->init_cb = NULL;
2088 ha->init_cb_dma = 0;
2089fail_free_gid_list:
2090 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2091 ha->gid_list_dma);
2092 ha->gid_list = NULL;
2093 ha->gid_list_dma = 0;
2094fail_free_response_ring:
2095 dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) *
2096 sizeof(response_t), ha->response_ring, ha->response_dma);
2097 ha->response_ring = NULL;
2098 ha->response_dma = 0;
2099fail_free_request_ring:
2100 dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
2101 sizeof(request_t), ha->request_ring, ha->request_dma);
2102 ha->request_ring = NULL;
2103 ha->request_dma = 0;
2104fail:
2105 return -ENOMEM;
2203} 2106}
2204 2107
2205/* 2108/*
@@ -2215,14 +2118,8 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2215 struct list_head *fcpl, *fcptemp; 2118 struct list_head *fcpl, *fcptemp;
2216 fc_port_t *fcport; 2119 fc_port_t *fcport;
2217 2120
2218 if (ha == NULL) { 2121 if (ha->srb_mempool)
2219 /* error */ 2122 mempool_destroy(ha->srb_mempool);
2220 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
2221 return;
2222 }
2223
2224 /* free sp pool */
2225 qla2x00_free_sp_pool(ha);
2226 2123
2227 if (ha->fce) 2124 if (ha->fce)
2228 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, 2125 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
@@ -2270,6 +2167,7 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2270 (ha->request_q_length + 1) * sizeof(request_t), 2167 (ha->request_q_length + 1) * sizeof(request_t),
2271 ha->request_ring, ha->request_dma); 2168 ha->request_ring, ha->request_dma);
2272 2169
2170 ha->srb_mempool = NULL;
2273 ha->eft = NULL; 2171 ha->eft = NULL;
2274 ha->eft_dma = 0; 2172 ha->eft_dma = 0;
2275 ha->sns_cmd = NULL; 2173 ha->sns_cmd = NULL;
@@ -2308,44 +2206,6 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2308 kfree(ha->nvram); 2206 kfree(ha->nvram);
2309} 2207}
2310 2208
2311/*
2312 * qla2x00_allocate_sp_pool
2313 * This routine is called during initialization to allocate
2314 * memory for local srb_t.
2315 *
2316 * Input:
2317 * ha = adapter block pointer.
2318 *
2319 * Context:
2320 * Kernel context.
2321 */
2322static int
2323qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
2324{
2325 int rval;
2326
2327 rval = QLA_SUCCESS;
2328 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2329 if (ha->srb_mempool == NULL) {
2330 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2331 rval = QLA_FUNCTION_FAILED;
2332 }
2333 return (rval);
2334}
2335
2336/*
2337 * This routine frees all adapter allocated memory.
2338 *
2339 */
2340static void
2341qla2x00_free_sp_pool( scsi_qla_host_t *ha)
2342{
2343 if (ha->srb_mempool) {
2344 mempool_destroy(ha->srb_mempool);
2345 ha->srb_mempool = NULL;
2346 }
2347}
2348
2349/************************************************************************** 2209/**************************************************************************
2350* qla2x00_do_dpc 2210* qla2x00_do_dpc
2351* This kernel thread is a task that is schedule by the interrupt handler 2211* This kernel thread is a task that is schedule by the interrupt handler
@@ -2367,6 +2227,9 @@ qla2x00_do_dpc(void *data)
2367 fc_port_t *fcport; 2227 fc_port_t *fcport;
2368 uint8_t status; 2228 uint8_t status;
2369 uint16_t next_loopid; 2229 uint16_t next_loopid;
2230 struct scsi_qla_host *vha;
2231 int i;
2232
2370 2233
2371 ha = (scsi_qla_host_t *)data; 2234 ha = (scsi_qla_host_t *)data;
2372 2235
@@ -2409,6 +2272,18 @@ qla2x00_do_dpc(void *data)
2409 } 2272 }
2410 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); 2273 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2411 } 2274 }
2275
2276 for_each_mapped_vp_idx(ha, i) {
2277 list_for_each_entry(vha, &ha->vp_list,
2278 vp_list) {
2279 if (i == vha->vp_idx) {
2280 set_bit(ISP_ABORT_NEEDED,
2281 &vha->dpc_flags);
2282 break;
2283 }
2284 }
2285 }
2286
2412 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n", 2287 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2413 ha->host_no)); 2288 ha->host_no));
2414 } 2289 }
@@ -3029,3 +2904,4 @@ MODULE_FIRMWARE(FW_FILE_ISP22XX);
3029MODULE_FIRMWARE(FW_FILE_ISP2300); 2904MODULE_FIRMWARE(FW_FILE_ISP2300);
3030MODULE_FIRMWARE(FW_FILE_ISP2322); 2905MODULE_FIRMWARE(FW_FILE_ISP2322);
3031MODULE_FIRMWARE(FW_FILE_ISP24XX); 2906MODULE_FIRMWARE(FW_FILE_ISP24XX);
2907MODULE_FIRMWARE(FW_FILE_ISP25XX);
diff --git a/drivers/scsi/qla2xxx/qla_sup.c b/drivers/scsi/qla2xxx/qla_sup.c
index b68fb73613ed..26822c8807ee 100644
--- a/drivers/scsi/qla2xxx/qla_sup.c
+++ b/drivers/scsi/qla2xxx/qla_sup.c
@@ -893,6 +893,8 @@ qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
893 } 893 }
894} 894}
895 895
896#define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
897
896void 898void
897qla2x00_beacon_blink(struct scsi_qla_host *ha) 899qla2x00_beacon_blink(struct scsi_qla_host *ha)
898{ 900{
@@ -902,15 +904,12 @@ qla2x00_beacon_blink(struct scsi_qla_host *ha)
902 unsigned long flags; 904 unsigned long flags;
903 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 905 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
904 906
905 if (ha->pio_address)
906 reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
907
908 spin_lock_irqsave(&ha->hardware_lock, flags); 907 spin_lock_irqsave(&ha->hardware_lock, flags);
909 908
910 /* Save the Original GPIOE. */ 909 /* Save the Original GPIOE. */
911 if (ha->pio_address) { 910 if (ha->pio_address) {
912 gpio_enable = RD_REG_WORD_PIO(&reg->gpioe); 911 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
913 gpio_data = RD_REG_WORD_PIO(&reg->gpiod); 912 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
914 } else { 913 } else {
915 gpio_enable = RD_REG_WORD(&reg->gpioe); 914 gpio_enable = RD_REG_WORD(&reg->gpioe);
916 gpio_data = RD_REG_WORD(&reg->gpiod); 915 gpio_data = RD_REG_WORD(&reg->gpiod);
@@ -920,7 +919,7 @@ qla2x00_beacon_blink(struct scsi_qla_host *ha)
920 gpio_enable |= GPIO_LED_MASK; 919 gpio_enable |= GPIO_LED_MASK;
921 920
922 if (ha->pio_address) { 921 if (ha->pio_address) {
923 WRT_REG_WORD_PIO(&reg->gpioe, gpio_enable); 922 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
924 } else { 923 } else {
925 WRT_REG_WORD(&reg->gpioe, gpio_enable); 924 WRT_REG_WORD(&reg->gpioe, gpio_enable);
926 RD_REG_WORD(&reg->gpioe); 925 RD_REG_WORD(&reg->gpioe);
@@ -936,7 +935,7 @@ qla2x00_beacon_blink(struct scsi_qla_host *ha)
936 935
937 /* Set the modified gpio_data values */ 936 /* Set the modified gpio_data values */
938 if (ha->pio_address) { 937 if (ha->pio_address) {
939 WRT_REG_WORD_PIO(&reg->gpiod, gpio_data); 938 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
940 } else { 939 } else {
941 WRT_REG_WORD(&reg->gpiod, gpio_data); 940 WRT_REG_WORD(&reg->gpiod, gpio_data);
942 RD_REG_WORD(&reg->gpiod); 941 RD_REG_WORD(&reg->gpiod);
@@ -962,14 +961,11 @@ qla2x00_beacon_on(struct scsi_qla_host *ha)
962 return QLA_FUNCTION_FAILED; 961 return QLA_FUNCTION_FAILED;
963 } 962 }
964 963
965 if (ha->pio_address)
966 reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
967
968 /* Turn off LEDs. */ 964 /* Turn off LEDs. */
969 spin_lock_irqsave(&ha->hardware_lock, flags); 965 spin_lock_irqsave(&ha->hardware_lock, flags);
970 if (ha->pio_address) { 966 if (ha->pio_address) {
971 gpio_enable = RD_REG_WORD_PIO(&reg->gpioe); 967 gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
972 gpio_data = RD_REG_WORD_PIO(&reg->gpiod); 968 gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
973 } else { 969 } else {
974 gpio_enable = RD_REG_WORD(&reg->gpioe); 970 gpio_enable = RD_REG_WORD(&reg->gpioe);
975 gpio_data = RD_REG_WORD(&reg->gpiod); 971 gpio_data = RD_REG_WORD(&reg->gpiod);
@@ -978,7 +974,7 @@ qla2x00_beacon_on(struct scsi_qla_host *ha)
978 974
979 /* Set the modified gpio_enable values. */ 975 /* Set the modified gpio_enable values. */
980 if (ha->pio_address) { 976 if (ha->pio_address) {
981 WRT_REG_WORD_PIO(&reg->gpioe, gpio_enable); 977 WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
982 } else { 978 } else {
983 WRT_REG_WORD(&reg->gpioe, gpio_enable); 979 WRT_REG_WORD(&reg->gpioe, gpio_enable);
984 RD_REG_WORD(&reg->gpioe); 980 RD_REG_WORD(&reg->gpioe);
@@ -987,7 +983,7 @@ qla2x00_beacon_on(struct scsi_qla_host *ha)
987 /* Clear out previously set LED colour. */ 983 /* Clear out previously set LED colour. */
988 gpio_data &= ~GPIO_LED_MASK; 984 gpio_data &= ~GPIO_LED_MASK;
989 if (ha->pio_address) { 985 if (ha->pio_address) {
990 WRT_REG_WORD_PIO(&reg->gpiod, gpio_data); 986 WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
991 } else { 987 } else {
992 WRT_REG_WORD(&reg->gpiod, gpio_data); 988 WRT_REG_WORD(&reg->gpiod, gpio_data);
993 RD_REG_WORD(&reg->gpiod); 989 RD_REG_WORD(&reg->gpiod);
@@ -1244,13 +1240,12 @@ qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
1244 if (ha->pio_address) { 1240 if (ha->pio_address) {
1245 uint16_t data2; 1241 uint16_t data2;
1246 1242
1247 reg = (struct device_reg_2xxx __iomem *)ha->pio_address; 1243 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
1248 WRT_REG_WORD_PIO(&reg->flash_address, (uint16_t)addr);
1249 do { 1244 do {
1250 data = RD_REG_WORD_PIO(&reg->flash_data); 1245 data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
1251 barrier(); 1246 barrier();
1252 cpu_relax(); 1247 cpu_relax();
1253 data2 = RD_REG_WORD_PIO(&reg->flash_data); 1248 data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
1254 } while (data != data2); 1249 } while (data != data2);
1255 } else { 1250 } else {
1256 WRT_REG_WORD(&reg->flash_address, (uint16_t)addr); 1251 WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
@@ -1304,9 +1299,8 @@ qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
1304 1299
1305 /* Always perform IO mapped accesses to the FLASH registers. */ 1300 /* Always perform IO mapped accesses to the FLASH registers. */
1306 if (ha->pio_address) { 1301 if (ha->pio_address) {
1307 reg = (struct device_reg_2xxx __iomem *)ha->pio_address; 1302 WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
1308 WRT_REG_WORD_PIO(&reg->flash_address, (uint16_t)addr); 1303 WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
1309 WRT_REG_WORD_PIO(&reg->flash_data, (uint16_t)data);
1310 } else { 1304 } else {
1311 WRT_REG_WORD(&reg->flash_address, (uint16_t)addr); 1305 WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
1312 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */ 1306 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index 2c2f6b4697c7..c5742cc15abb 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,7 +7,7 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.02.00-k7" 10#define QLA2XXX_VERSION "8.02.00-k8"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 2 13#define QLA_DRIVER_MINOR_VER 2
diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
index 49925f92555e..10b3b9a620f3 100644
--- a/drivers/scsi/qla4xxx/ql4_init.c
+++ b/drivers/scsi/qla4xxx/ql4_init.c
@@ -1306,6 +1306,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
1306 atomic_set(&ddb_entry->relogin_timer, 0); 1306 atomic_set(&ddb_entry->relogin_timer, 0);
1307 clear_bit(DF_RELOGIN, &ddb_entry->flags); 1307 clear_bit(DF_RELOGIN, &ddb_entry->flags);
1308 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags); 1308 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
1309 iscsi_unblock_session(ddb_entry->sess);
1309 iscsi_session_event(ddb_entry->sess, 1310 iscsi_session_event(ddb_entry->sess,
1310 ISCSI_KEVENT_CREATE_SESSION); 1311 ISCSI_KEVENT_CREATE_SESSION);
1311 /* 1312 /*
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 2e2b9fedffcc..c3c59d763037 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -63,8 +63,6 @@ static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
63 enum iscsi_param param, char *buf); 63 enum iscsi_param param, char *buf);
64static int qla4xxx_host_get_param(struct Scsi_Host *shost, 64static int qla4xxx_host_get_param(struct Scsi_Host *shost,
65 enum iscsi_host_param param, char *buf); 65 enum iscsi_host_param param, char *buf);
66static void qla4xxx_conn_stop(struct iscsi_cls_conn *conn, int flag);
67static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
68static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session); 66static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
69 67
70/* 68/*
@@ -91,6 +89,8 @@ static struct scsi_host_template qla4xxx_driver_template = {
91 .slave_alloc = qla4xxx_slave_alloc, 89 .slave_alloc = qla4xxx_slave_alloc,
92 .slave_destroy = qla4xxx_slave_destroy, 90 .slave_destroy = qla4xxx_slave_destroy,
93 91
92 .scan_finished = iscsi_scan_finished,
93
94 .this_id = -1, 94 .this_id = -1,
95 .cmd_per_lun = 3, 95 .cmd_per_lun = 3,
96 .use_clustering = ENABLE_CLUSTERING, 96 .use_clustering = ENABLE_CLUSTERING,
@@ -116,8 +116,6 @@ static struct iscsi_transport qla4xxx_iscsi_transport = {
116 .get_conn_param = qla4xxx_conn_get_param, 116 .get_conn_param = qla4xxx_conn_get_param,
117 .get_session_param = qla4xxx_sess_get_param, 117 .get_session_param = qla4xxx_sess_get_param,
118 .get_host_param = qla4xxx_host_get_param, 118 .get_host_param = qla4xxx_host_get_param,
119 .start_conn = qla4xxx_conn_start,
120 .stop_conn = qla4xxx_conn_stop,
121 .session_recovery_timedout = qla4xxx_recovery_timedout, 119 .session_recovery_timedout = qla4xxx_recovery_timedout,
122}; 120};
123 121
@@ -128,48 +126,19 @@ static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
128 struct ddb_entry *ddb_entry = session->dd_data; 126 struct ddb_entry *ddb_entry = session->dd_data;
129 struct scsi_qla_host *ha = ddb_entry->ha; 127 struct scsi_qla_host *ha = ddb_entry->ha;
130 128
131 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count of (%d) " 129 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
132 "secs exhausted, marking device DEAD.\n", ha->host_no, 130 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
133 __func__, ddb_entry->fw_ddb_index,
134 ha->port_down_retry_count));
135
136 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
137
138 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc flags = "
139 "0x%lx\n", ha->host_no, __func__, ha->dpc_flags));
140 queue_work(ha->dpc_thread, &ha->dpc_work);
141}
142
143static int qla4xxx_conn_start(struct iscsi_cls_conn *conn)
144{
145 struct iscsi_cls_session *session;
146 struct ddb_entry *ddb_entry;
147
148 session = iscsi_dev_to_session(conn->dev.parent);
149 ddb_entry = session->dd_data;
150
151 DEBUG2(printk("scsi%ld: %s: index [%d] starting conn\n",
152 ddb_entry->ha->host_no, __func__,
153 ddb_entry->fw_ddb_index));
154 iscsi_unblock_session(session);
155 return 0;
156}
157
158static void qla4xxx_conn_stop(struct iscsi_cls_conn *conn, int flag)
159{
160 struct iscsi_cls_session *session;
161 struct ddb_entry *ddb_entry;
162 131
163 session = iscsi_dev_to_session(conn->dev.parent); 132 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count "
164 ddb_entry = session->dd_data; 133 "of (%d) secs exhausted, marking device DEAD.\n",
134 ha->host_no, __func__, ddb_entry->fw_ddb_index,
135 ha->port_down_retry_count));
165 136
166 DEBUG2(printk("scsi%ld: %s: index [%d] stopping conn\n", 137 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc "
167 ddb_entry->ha->host_no, __func__, 138 "flags = 0x%lx\n",
168 ddb_entry->fw_ddb_index)); 139 ha->host_no, __func__, ha->dpc_flags));
169 if (flag == STOP_CONN_RECOVER) 140 queue_work(ha->dpc_thread, &ha->dpc_work);
170 iscsi_block_session(session); 141 }
171 else
172 printk(KERN_ERR "iscsi: invalid stop flag %d\n", flag);
173} 142}
174 143
175static int qla4xxx_host_get_param(struct Scsi_Host *shost, 144static int qla4xxx_host_get_param(struct Scsi_Host *shost,
@@ -308,6 +277,9 @@ int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
308 DEBUG2(printk(KERN_ERR "Could not add connection.\n")); 277 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
309 return -ENOMEM; 278 return -ENOMEM;
310 } 279 }
280
281 /* finally ready to go */
282 iscsi_unblock_session(ddb_entry->sess);
311 return 0; 283 return 0;
312} 284}
313 285
@@ -364,6 +336,7 @@ void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
364 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n", 336 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
365 ha->host_no, ddb_entry->bus, ddb_entry->target, 337 ha->host_no, ddb_entry->bus, ddb_entry->target,
366 ddb_entry->fw_ddb_index)); 338 ddb_entry->fw_ddb_index));
339 iscsi_block_session(ddb_entry->sess);
367 iscsi_conn_error(ddb_entry->conn, ISCSI_ERR_CONN_FAILED); 340 iscsi_conn_error(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
368} 341}
369 342
@@ -430,9 +403,21 @@ static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
430{ 403{
431 struct scsi_qla_host *ha = to_qla_host(cmd->device->host); 404 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
432 struct ddb_entry *ddb_entry = cmd->device->hostdata; 405 struct ddb_entry *ddb_entry = cmd->device->hostdata;
406 struct iscsi_cls_session *sess = ddb_entry->sess;
433 struct srb *srb; 407 struct srb *srb;
434 int rval; 408 int rval;
435 409
410 if (!sess) {
411 cmd->result = DID_IMM_RETRY << 16;
412 goto qc_fail_command;
413 }
414
415 rval = iscsi_session_chkready(sess);
416 if (rval) {
417 cmd->result = rval;
418 goto qc_fail_command;
419 }
420
436 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) { 421 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
437 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) { 422 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
438 cmd->result = DID_NO_CONNECT << 16; 423 cmd->result = DID_NO_CONNECT << 16;
@@ -1323,7 +1308,7 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1323 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), 1308 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
1324 ha->host_no, ha->firmware_version[0], ha->firmware_version[1], 1309 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
1325 ha->patch_number, ha->build_number); 1310 ha->patch_number, ha->build_number);
1326 1311 scsi_scan_host(host);
1327 return 0; 1312 return 0;
1328 1313
1329remove_host: 1314remove_host:
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index b35d19472caa..fecba05b4e77 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -969,9 +969,10 @@ void starget_for_each_device(struct scsi_target *starget, void *data,
969EXPORT_SYMBOL(starget_for_each_device); 969EXPORT_SYMBOL(starget_for_each_device);
970 970
971/** 971/**
972 * __starget_for_each_device - helper to walk all devices of a target 972 * __starget_for_each_device - helper to walk all devices of a target (UNLOCKED)
973 * (UNLOCKED)
974 * @starget: target whose devices we want to iterate over. 973 * @starget: target whose devices we want to iterate over.
974 * @data: parameter for callback @fn()
975 * @fn: callback function that is invoked for each device
975 * 976 *
976 * This traverses over each device of @starget. It does _not_ 977 * This traverses over each device of @starget. It does _not_
977 * take a reference on the scsi_device, so the whole loop must be 978 * take a reference on the scsi_device, so the whole loop must be
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f243fc30c908..135c1d054701 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -301,7 +301,6 @@ static int scsi_req_map_sg(struct request *rq, struct scatterlist *sgl,
301 page = sg_page(sg); 301 page = sg_page(sg);
302 off = sg->offset; 302 off = sg->offset;
303 len = sg->length; 303 len = sg->length;
304 data_len += len;
305 304
306 while (len > 0 && data_len > 0) { 305 while (len > 0 && data_len > 0) {
307 /* 306 /*
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 0d7b4e79415c..fac7534f3ec4 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -30,10 +30,10 @@
30#include <scsi/scsi_transport_iscsi.h> 30#include <scsi/scsi_transport_iscsi.h>
31#include <scsi/iscsi_if.h> 31#include <scsi/iscsi_if.h>
32 32
33#define ISCSI_SESSION_ATTRS 18 33#define ISCSI_SESSION_ATTRS 19
34#define ISCSI_CONN_ATTRS 11 34#define ISCSI_CONN_ATTRS 13
35#define ISCSI_HOST_ATTRS 4 35#define ISCSI_HOST_ATTRS 4
36#define ISCSI_TRANSPORT_VERSION "2.0-867" 36#define ISCSI_TRANSPORT_VERSION "2.0-868"
37 37
38struct iscsi_internal { 38struct iscsi_internal {
39 int daemon_pid; 39 int daemon_pid;
@@ -127,12 +127,13 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
127 memset(ihost, 0, sizeof(*ihost)); 127 memset(ihost, 0, sizeof(*ihost));
128 INIT_LIST_HEAD(&ihost->sessions); 128 INIT_LIST_HEAD(&ihost->sessions);
129 mutex_init(&ihost->mutex); 129 mutex_init(&ihost->mutex);
130 atomic_set(&ihost->nr_scans, 0);
130 131
131 snprintf(ihost->unbind_workq_name, KOBJ_NAME_LEN, "iscsi_unbind_%d", 132 snprintf(ihost->scan_workq_name, KOBJ_NAME_LEN, "iscsi_scan_%d",
132 shost->host_no); 133 shost->host_no);
133 ihost->unbind_workq = create_singlethread_workqueue( 134 ihost->scan_workq = create_singlethread_workqueue(
134 ihost->unbind_workq_name); 135 ihost->scan_workq_name);
135 if (!ihost->unbind_workq) 136 if (!ihost->scan_workq)
136 return -ENOMEM; 137 return -ENOMEM;
137 return 0; 138 return 0;
138} 139}
@@ -143,7 +144,7 @@ static int iscsi_remove_host(struct transport_container *tc, struct device *dev,
143 struct Scsi_Host *shost = dev_to_shost(dev); 144 struct Scsi_Host *shost = dev_to_shost(dev);
144 struct iscsi_host *ihost = shost->shost_data; 145 struct iscsi_host *ihost = shost->shost_data;
145 146
146 destroy_workqueue(ihost->unbind_workq); 147 destroy_workqueue(ihost->scan_workq);
147 return 0; 148 return 0;
148} 149}
149 150
@@ -221,6 +222,54 @@ static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
221 * The following functions can be used by LLDs that allocate 222 * The following functions can be used by LLDs that allocate
222 * their own scsi_hosts or by software iscsi LLDs 223 * their own scsi_hosts or by software iscsi LLDs
223 */ 224 */
225static struct {
226 int value;
227 char *name;
228} iscsi_session_state_names[] = {
229 { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" },
230 { ISCSI_SESSION_FAILED, "FAILED" },
231 { ISCSI_SESSION_FREE, "FREE" },
232};
233
234const char *iscsi_session_state_name(int state)
235{
236 int i;
237 char *name = NULL;
238
239 for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
240 if (iscsi_session_state_names[i].value == state) {
241 name = iscsi_session_state_names[i].name;
242 break;
243 }
244 }
245 return name;
246}
247
248int iscsi_session_chkready(struct iscsi_cls_session *session)
249{
250 unsigned long flags;
251 int err;
252
253 spin_lock_irqsave(&session->lock, flags);
254 switch (session->state) {
255 case ISCSI_SESSION_LOGGED_IN:
256 err = 0;
257 break;
258 case ISCSI_SESSION_FAILED:
259 err = DID_IMM_RETRY << 16;
260 break;
261 case ISCSI_SESSION_FREE:
262 err = DID_NO_CONNECT << 16;
263 break;
264 default:
265 err = DID_NO_CONNECT << 16;
266 break;
267 }
268 spin_unlock_irqrestore(&session->lock, flags);
269 return err;
270}
271EXPORT_SYMBOL_GPL(iscsi_session_chkready);
272
224static void iscsi_session_release(struct device *dev) 273static void iscsi_session_release(struct device *dev)
225{ 274{
226 struct iscsi_cls_session *session = iscsi_dev_to_session(dev); 275 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
@@ -236,6 +285,25 @@ static int iscsi_is_session_dev(const struct device *dev)
236 return dev->release == iscsi_session_release; 285 return dev->release == iscsi_session_release;
237} 286}
238 287
288/**
289 * iscsi_scan_finished - helper to report when running scans are done
290 * @shost: scsi host
291 * @time: scan run time
292 *
293 * This function can be used by drives like qla4xxx to report to the scsi
294 * layer when the scans it kicked off at module load time are done.
295 */
296int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
297{
298 struct iscsi_host *ihost = shost->shost_data;
299 /*
300 * qla4xxx will have kicked off some session unblocks before calling
301 * scsi_scan_host, so just wait for them to complete.
302 */
303 return !atomic_read(&ihost->nr_scans);
304}
305EXPORT_SYMBOL_GPL(iscsi_scan_finished);
306
239static int iscsi_user_scan(struct Scsi_Host *shost, uint channel, 307static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
240 uint id, uint lun) 308 uint id, uint lun)
241{ 309{
@@ -254,14 +322,50 @@ static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
254 return 0; 322 return 0;
255} 323}
256 324
325static void iscsi_scan_session(struct work_struct *work)
326{
327 struct iscsi_cls_session *session =
328 container_of(work, struct iscsi_cls_session, scan_work);
329 struct Scsi_Host *shost = iscsi_session_to_shost(session);
330 struct iscsi_host *ihost = shost->shost_data;
331 unsigned long flags;
332
333 spin_lock_irqsave(&session->lock, flags);
334 if (session->state != ISCSI_SESSION_LOGGED_IN) {
335 spin_unlock_irqrestore(&session->lock, flags);
336 goto done;
337 }
338 spin_unlock_irqrestore(&session->lock, flags);
339
340 scsi_scan_target(&session->dev, 0, session->target_id,
341 SCAN_WILD_CARD, 1);
342done:
343 atomic_dec(&ihost->nr_scans);
344}
345
257static void session_recovery_timedout(struct work_struct *work) 346static void session_recovery_timedout(struct work_struct *work)
258{ 347{
259 struct iscsi_cls_session *session = 348 struct iscsi_cls_session *session =
260 container_of(work, struct iscsi_cls_session, 349 container_of(work, struct iscsi_cls_session,
261 recovery_work.work); 350 recovery_work.work);
351 unsigned long flags;
352
353 iscsi_cls_session_printk(KERN_INFO, session,
354 "session recovery timed out after %d secs\n",
355 session->recovery_tmo);
262 356
263 dev_printk(KERN_INFO, &session->dev, "iscsi: session recovery timed " 357 spin_lock_irqsave(&session->lock, flags);
264 "out after %d secs\n", session->recovery_tmo); 358 switch (session->state) {
359 case ISCSI_SESSION_FAILED:
360 session->state = ISCSI_SESSION_FREE;
361 break;
362 case ISCSI_SESSION_LOGGED_IN:
363 case ISCSI_SESSION_FREE:
364 /* we raced with the unblock's flush */
365 spin_unlock_irqrestore(&session->lock, flags);
366 return;
367 }
368 spin_unlock_irqrestore(&session->lock, flags);
265 369
266 if (session->transport->session_recovery_timedout) 370 if (session->transport->session_recovery_timedout)
267 session->transport->session_recovery_timedout(session); 371 session->transport->session_recovery_timedout(session);
@@ -269,16 +373,44 @@ static void session_recovery_timedout(struct work_struct *work)
269 scsi_target_unblock(&session->dev); 373 scsi_target_unblock(&session->dev);
270} 374}
271 375
272void iscsi_unblock_session(struct iscsi_cls_session *session) 376void __iscsi_unblock_session(struct iscsi_cls_session *session)
273{ 377{
274 if (!cancel_delayed_work(&session->recovery_work)) 378 if (!cancel_delayed_work(&session->recovery_work))
275 flush_workqueue(iscsi_eh_timer_workq); 379 flush_workqueue(iscsi_eh_timer_workq);
276 scsi_target_unblock(&session->dev); 380 scsi_target_unblock(&session->dev);
277} 381}
382
383void iscsi_unblock_session(struct iscsi_cls_session *session)
384{
385 struct Scsi_Host *shost = iscsi_session_to_shost(session);
386 struct iscsi_host *ihost = shost->shost_data;
387 unsigned long flags;
388
389 spin_lock_irqsave(&session->lock, flags);
390 session->state = ISCSI_SESSION_LOGGED_IN;
391 spin_unlock_irqrestore(&session->lock, flags);
392
393 __iscsi_unblock_session(session);
394 /*
395 * Only do kernel scanning if the driver is properly hooked into
396 * the async scanning code (drivers like iscsi_tcp do login and
397 * scanning from userspace).
398 */
399 if (shost->hostt->scan_finished) {
400 if (queue_work(ihost->scan_workq, &session->scan_work))
401 atomic_inc(&ihost->nr_scans);
402 }
403}
278EXPORT_SYMBOL_GPL(iscsi_unblock_session); 404EXPORT_SYMBOL_GPL(iscsi_unblock_session);
279 405
280void iscsi_block_session(struct iscsi_cls_session *session) 406void iscsi_block_session(struct iscsi_cls_session *session)
281{ 407{
408 unsigned long flags;
409
410 spin_lock_irqsave(&session->lock, flags);
411 session->state = ISCSI_SESSION_FAILED;
412 spin_unlock_irqrestore(&session->lock, flags);
413
282 scsi_target_block(&session->dev); 414 scsi_target_block(&session->dev);
283 queue_delayed_work(iscsi_eh_timer_workq, &session->recovery_work, 415 queue_delayed_work(iscsi_eh_timer_workq, &session->recovery_work,
284 session->recovery_tmo * HZ); 416 session->recovery_tmo * HZ);
@@ -311,7 +443,7 @@ static int iscsi_unbind_session(struct iscsi_cls_session *session)
311 struct Scsi_Host *shost = iscsi_session_to_shost(session); 443 struct Scsi_Host *shost = iscsi_session_to_shost(session);
312 struct iscsi_host *ihost = shost->shost_data; 444 struct iscsi_host *ihost = shost->shost_data;
313 445
314 return queue_work(ihost->unbind_workq, &session->unbind_work); 446 return queue_work(ihost->scan_workq, &session->unbind_work);
315} 447}
316 448
317struct iscsi_cls_session * 449struct iscsi_cls_session *
@@ -327,10 +459,13 @@ iscsi_alloc_session(struct Scsi_Host *shost,
327 459
328 session->transport = transport; 460 session->transport = transport;
329 session->recovery_tmo = 120; 461 session->recovery_tmo = 120;
462 session->state = ISCSI_SESSION_FREE;
330 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout); 463 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
331 INIT_LIST_HEAD(&session->host_list); 464 INIT_LIST_HEAD(&session->host_list);
332 INIT_LIST_HEAD(&session->sess_list); 465 INIT_LIST_HEAD(&session->sess_list);
333 INIT_WORK(&session->unbind_work, __iscsi_unbind_session); 466 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
467 INIT_WORK(&session->scan_work, iscsi_scan_session);
468 spin_lock_init(&session->lock);
334 469
335 /* this is released in the dev's release function */ 470 /* this is released in the dev's release function */
336 scsi_host_get(shost); 471 scsi_host_get(shost);
@@ -358,8 +493,8 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
358 session->sid); 493 session->sid);
359 err = device_add(&session->dev); 494 err = device_add(&session->dev);
360 if (err) { 495 if (err) {
361 dev_printk(KERN_ERR, &session->dev, "iscsi: could not " 496 iscsi_cls_session_printk(KERN_ERR, session,
362 "register session's dev\n"); 497 "could not register session's dev\n");
363 goto release_host; 498 goto release_host;
364 } 499 }
365 transport_register_device(&session->dev); 500 transport_register_device(&session->dev);
@@ -444,22 +579,28 @@ void iscsi_remove_session(struct iscsi_cls_session *session)
444 * If we are blocked let commands flow again. The lld or iscsi 579 * If we are blocked let commands flow again. The lld or iscsi
445 * layer should set up the queuecommand to fail commands. 580 * layer should set up the queuecommand to fail commands.
446 */ 581 */
447 iscsi_unblock_session(session); 582 spin_lock_irqsave(&session->lock, flags);
448 iscsi_unbind_session(session); 583 session->state = ISCSI_SESSION_FREE;
584 spin_unlock_irqrestore(&session->lock, flags);
585 __iscsi_unblock_session(session);
586 __iscsi_unbind_session(&session->unbind_work);
587
588 /* flush running scans */
589 flush_workqueue(ihost->scan_workq);
449 /* 590 /*
450 * If the session dropped while removing devices then we need to make 591 * If the session dropped while removing devices then we need to make
451 * sure it is not blocked 592 * sure it is not blocked
452 */ 593 */
453 if (!cancel_delayed_work(&session->recovery_work)) 594 if (!cancel_delayed_work(&session->recovery_work))
454 flush_workqueue(iscsi_eh_timer_workq); 595 flush_workqueue(iscsi_eh_timer_workq);
455 flush_workqueue(ihost->unbind_workq);
456 596
457 /* hw iscsi may not have removed all connections from session */ 597 /* hw iscsi may not have removed all connections from session */
458 err = device_for_each_child(&session->dev, NULL, 598 err = device_for_each_child(&session->dev, NULL,
459 iscsi_iter_destroy_conn_fn); 599 iscsi_iter_destroy_conn_fn);
460 if (err) 600 if (err)
461 dev_printk(KERN_ERR, &session->dev, "iscsi: Could not delete " 601 iscsi_cls_session_printk(KERN_ERR, session,
462 "all connections for session. Error %d.\n", err); 602 "Could not delete all connections "
603 "for session. Error %d.\n", err);
463 604
464 transport_unregister_device(&session->dev); 605 transport_unregister_device(&session->dev);
465 device_del(&session->dev); 606 device_del(&session->dev);
@@ -531,8 +672,8 @@ iscsi_create_conn(struct iscsi_cls_session *session, uint32_t cid)
531 conn->dev.release = iscsi_conn_release; 672 conn->dev.release = iscsi_conn_release;
532 err = device_register(&conn->dev); 673 err = device_register(&conn->dev);
533 if (err) { 674 if (err) {
534 dev_printk(KERN_ERR, &conn->dev, "iscsi: could not register " 675 iscsi_cls_session_printk(KERN_ERR, session, "could not "
535 "connection's dev\n"); 676 "register connection's dev\n");
536 goto release_parent_ref; 677 goto release_parent_ref;
537 } 678 }
538 transport_register_device(&conn->dev); 679 transport_register_device(&conn->dev);
@@ -639,8 +780,8 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
639 skb = alloc_skb(len, GFP_ATOMIC); 780 skb = alloc_skb(len, GFP_ATOMIC);
640 if (!skb) { 781 if (!skb) {
641 iscsi_conn_error(conn, ISCSI_ERR_CONN_FAILED); 782 iscsi_conn_error(conn, ISCSI_ERR_CONN_FAILED);
642 dev_printk(KERN_ERR, &conn->dev, "iscsi: can not deliver " 783 iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
643 "control PDU: OOM\n"); 784 "control PDU: OOM\n");
644 return -ENOMEM; 785 return -ENOMEM;
645 } 786 }
646 787
@@ -661,20 +802,27 @@ EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
661 802
662void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error) 803void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
663{ 804{
805 struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
664 struct nlmsghdr *nlh; 806 struct nlmsghdr *nlh;
665 struct sk_buff *skb; 807 struct sk_buff *skb;
666 struct iscsi_uevent *ev; 808 struct iscsi_uevent *ev;
667 struct iscsi_internal *priv; 809 struct iscsi_internal *priv;
668 int len = NLMSG_SPACE(sizeof(*ev)); 810 int len = NLMSG_SPACE(sizeof(*ev));
811 unsigned long flags;
669 812
670 priv = iscsi_if_transport_lookup(conn->transport); 813 priv = iscsi_if_transport_lookup(conn->transport);
671 if (!priv) 814 if (!priv)
672 return; 815 return;
673 816
817 spin_lock_irqsave(&session->lock, flags);
818 if (session->state == ISCSI_SESSION_LOGGED_IN)
819 session->state = ISCSI_SESSION_FAILED;
820 spin_unlock_irqrestore(&session->lock, flags);
821
674 skb = alloc_skb(len, GFP_ATOMIC); 822 skb = alloc_skb(len, GFP_ATOMIC);
675 if (!skb) { 823 if (!skb) {
676 dev_printk(KERN_ERR, &conn->dev, "iscsi: gracefully ignored " 824 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
677 "conn error (%d)\n", error); 825 "conn error (%d)\n", error);
678 return; 826 return;
679 } 827 }
680 828
@@ -688,8 +836,8 @@ void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
688 836
689 iscsi_broadcast_skb(skb, GFP_ATOMIC); 837 iscsi_broadcast_skb(skb, GFP_ATOMIC);
690 838
691 dev_printk(KERN_INFO, &conn->dev, "iscsi: detected conn error (%d)\n", 839 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
692 error); 840 error);
693} 841}
694EXPORT_SYMBOL_GPL(iscsi_conn_error); 842EXPORT_SYMBOL_GPL(iscsi_conn_error);
695 843
@@ -744,8 +892,8 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
744 892
745 skbstat = alloc_skb(len, GFP_ATOMIC); 893 skbstat = alloc_skb(len, GFP_ATOMIC);
746 if (!skbstat) { 894 if (!skbstat) {
747 dev_printk(KERN_ERR, &conn->dev, "iscsi: can not " 895 iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
748 "deliver stats: OOM\n"); 896 "deliver stats: OOM\n");
749 return -ENOMEM; 897 return -ENOMEM;
750 } 898 }
751 899
@@ -801,8 +949,9 @@ int iscsi_session_event(struct iscsi_cls_session *session,
801 949
802 skb = alloc_skb(len, GFP_KERNEL); 950 skb = alloc_skb(len, GFP_KERNEL);
803 if (!skb) { 951 if (!skb) {
804 dev_printk(KERN_ERR, &session->dev, "Cannot notify userspace " 952 iscsi_cls_session_printk(KERN_ERR, session,
805 "of session event %u\n", event); 953 "Cannot notify userspace of session "
954 "event %u\n", event);
806 return -ENOMEM; 955 return -ENOMEM;
807 } 956 }
808 957
@@ -825,8 +974,8 @@ int iscsi_session_event(struct iscsi_cls_session *session,
825 ev->r.unbind_session.sid = session->sid; 974 ev->r.unbind_session.sid = session->sid;
826 break; 975 break;
827 default: 976 default:
828 dev_printk(KERN_ERR, &session->dev, "Invalid event %u.\n", 977 iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
829 event); 978 "%u.\n", event);
830 kfree_skb(skb); 979 kfree_skb(skb);
831 return -EINVAL; 980 return -EINVAL;
832 } 981 }
@@ -837,8 +986,10 @@ int iscsi_session_event(struct iscsi_cls_session *session,
837 */ 986 */
838 rc = iscsi_broadcast_skb(skb, GFP_KERNEL); 987 rc = iscsi_broadcast_skb(skb, GFP_KERNEL);
839 if (rc < 0) 988 if (rc < 0)
840 dev_printk(KERN_ERR, &session->dev, "Cannot notify userspace " 989 iscsi_cls_session_printk(KERN_ERR, session,
841 "of session event %u. Check iscsi daemon\n", event); 990 "Cannot notify userspace of session "
991 "event %u. Check iscsi daemon\n",
992 event);
842 return rc; 993 return rc;
843} 994}
844EXPORT_SYMBOL_GPL(iscsi_session_event); 995EXPORT_SYMBOL_GPL(iscsi_session_event);
@@ -871,16 +1022,15 @@ iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
871 1022
872 session = iscsi_session_lookup(ev->u.c_conn.sid); 1023 session = iscsi_session_lookup(ev->u.c_conn.sid);
873 if (!session) { 1024 if (!session) {
874 printk(KERN_ERR "iscsi: invalid session %d\n", 1025 printk(KERN_ERR "iscsi: invalid session %d.\n",
875 ev->u.c_conn.sid); 1026 ev->u.c_conn.sid);
876 return -EINVAL; 1027 return -EINVAL;
877 } 1028 }
878 1029
879 conn = transport->create_conn(session, ev->u.c_conn.cid); 1030 conn = transport->create_conn(session, ev->u.c_conn.cid);
880 if (!conn) { 1031 if (!conn) {
881 printk(KERN_ERR "iscsi: couldn't create a new " 1032 iscsi_cls_session_printk(KERN_ERR, session,
882 "connection for session %d\n", 1033 "couldn't create a new connection.");
883 session->sid);
884 return -ENOMEM; 1034 return -ENOMEM;
885 } 1035 }
886 1036
@@ -1246,6 +1396,15 @@ iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
1246iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0); 1396iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
1247iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0); 1397iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
1248 1398
1399static ssize_t
1400show_priv_session_state(struct class_device *cdev, char *buf)
1401{
1402 struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev);
1403 return sprintf(buf, "%s\n", iscsi_session_state_name(session->state));
1404}
1405static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
1406 NULL);
1407
1249#define iscsi_priv_session_attr_show(field, format) \ 1408#define iscsi_priv_session_attr_show(field, format) \
1250static ssize_t \ 1409static ssize_t \
1251show_priv_session_##field(struct class_device *cdev, char *buf) \ 1410show_priv_session_##field(struct class_device *cdev, char *buf) \
@@ -1472,6 +1631,7 @@ iscsi_register_transport(struct iscsi_transport *tt)
1472 SETUP_SESSION_RD_ATTR(abort_tmo, ISCSI_ABORT_TMO); 1631 SETUP_SESSION_RD_ATTR(abort_tmo, ISCSI_ABORT_TMO);
1473 SETUP_SESSION_RD_ATTR(lu_reset_tmo,ISCSI_LU_RESET_TMO); 1632 SETUP_SESSION_RD_ATTR(lu_reset_tmo,ISCSI_LU_RESET_TMO);
1474 SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo); 1633 SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo);
1634 SETUP_PRIV_SESSION_RD_ATTR(state);
1475 1635
1476 BUG_ON(count > ISCSI_SESSION_ATTRS); 1636 BUG_ON(count > ISCSI_SESSION_ATTRS);
1477 priv->session_attrs[count] = NULL; 1637 priv->session_attrs[count] = NULL;
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 51a5557f42dd..37df8bbe7f46 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -929,6 +929,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
929 unsigned int xfer_size = scsi_bufflen(SCpnt); 929 unsigned int xfer_size = scsi_bufflen(SCpnt);
930 unsigned int good_bytes = result ? 0 : xfer_size; 930 unsigned int good_bytes = result ? 0 : xfer_size;
931 u64 start_lba = SCpnt->request->sector; 931 u64 start_lba = SCpnt->request->sector;
932 u64 end_lba = SCpnt->request->sector + (xfer_size / 512);
932 u64 bad_lba; 933 u64 bad_lba;
933 struct scsi_sense_hdr sshdr; 934 struct scsi_sense_hdr sshdr;
934 int sense_valid = 0; 935 int sense_valid = 0;
@@ -967,26 +968,23 @@ static int sd_done(struct scsi_cmnd *SCpnt)
967 goto out; 968 goto out;
968 if (xfer_size <= SCpnt->device->sector_size) 969 if (xfer_size <= SCpnt->device->sector_size)
969 goto out; 970 goto out;
970 switch (SCpnt->device->sector_size) { 971 if (SCpnt->device->sector_size < 512) {
971 case 256: 972 /* only legitimate sector_size here is 256 */
972 start_lba <<= 1; 973 start_lba <<= 1;
973 break; 974 end_lba <<= 1;
974 case 512: 975 } else {
975 break; 976 /* be careful ... don't want any overflows */
976 case 1024: 977 u64 factor = SCpnt->device->sector_size / 512;
977 start_lba >>= 1; 978 do_div(start_lba, factor);
978 break; 979 do_div(end_lba, factor);
979 case 2048:
980 start_lba >>= 2;
981 break;
982 case 4096:
983 start_lba >>= 3;
984 break;
985 default:
986 /* Print something here with limiting frequency. */
987 goto out;
988 break;
989 } 980 }
981
982 if (bad_lba < start_lba || bad_lba >= end_lba)
983 /* the bad lba was reported incorrectly, we have
984 * no idea where the error is
985 */
986 goto out;
987
990 /* This computation should always be done in terms of 988 /* This computation should always be done in terms of
991 * the resolution of the device's medium. 989 * the resolution of the device's medium.
992 */ 990 */
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
new file mode 100644
index 000000000000..2a6e4f472eaa
--- /dev/null
+++ b/drivers/scsi/ses.c
@@ -0,0 +1,689 @@
1/*
2 * SCSI Enclosure Services
3 *
4 * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
5 *
6**-----------------------------------------------------------------------------
7**
8** This program is free software; you can redistribute it and/or
9** modify it under the terms of the GNU General Public License
10** version 2 as published by the Free Software Foundation.
11**
12** This program is distributed in the hope that it will be useful,
13** but WITHOUT ANY WARRANTY; without even the implied warranty of
14** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15** GNU General Public License for more details.
16**
17** You should have received a copy of the GNU General Public License
18** along with this program; if not, write to the Free Software
19** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20**
21**-----------------------------------------------------------------------------
22*/
23
24#include <linux/module.h>
25#include <linux/kernel.h>
26#include <linux/enclosure.h>
27
28#include <scsi/scsi.h>
29#include <scsi/scsi_cmnd.h>
30#include <scsi/scsi_dbg.h>
31#include <scsi/scsi_device.h>
32#include <scsi/scsi_driver.h>
33#include <scsi/scsi_host.h>
34
35struct ses_device {
36 char *page1;
37 char *page2;
38 char *page10;
39 short page1_len;
40 short page2_len;
41 short page10_len;
42};
43
44struct ses_component {
45 u64 addr;
46 unsigned char *desc;
47};
48
49static int ses_probe(struct device *dev)
50{
51 struct scsi_device *sdev = to_scsi_device(dev);
52 int err = -ENODEV;
53
54 if (sdev->type != TYPE_ENCLOSURE)
55 goto out;
56
57 err = 0;
58 sdev_printk(KERN_NOTICE, sdev, "Attached Enclosure device\n");
59
60 out:
61 return err;
62}
63
64#define SES_TIMEOUT 30
65#define SES_RETRIES 3
66
67static int ses_recv_diag(struct scsi_device *sdev, int page_code,
68 void *buf, int bufflen)
69{
70 char cmd[] = {
71 RECEIVE_DIAGNOSTIC,
72 1, /* Set PCV bit */
73 page_code,
74 bufflen >> 8,
75 bufflen & 0xff,
76 0
77 };
78
79 return scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, bufflen,
80 NULL, SES_TIMEOUT, SES_RETRIES);
81}
82
83static int ses_send_diag(struct scsi_device *sdev, int page_code,
84 void *buf, int bufflen)
85{
86 u32 result;
87
88 char cmd[] = {
89 SEND_DIAGNOSTIC,
90 0x10, /* Set PF bit */
91 0,
92 bufflen >> 8,
93 bufflen & 0xff,
94 0
95 };
96
97 result = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, buf, bufflen,
98 NULL, SES_TIMEOUT, SES_RETRIES);
99 if (result)
100 sdev_printk(KERN_ERR, sdev, "SEND DIAGNOSTIC result: %8x\n",
101 result);
102 return result;
103}
104
105static int ses_set_page2_descriptor(struct enclosure_device *edev,
106 struct enclosure_component *ecomp,
107 char *desc)
108{
109 int i, j, count = 0, descriptor = ecomp->number;
110 struct scsi_device *sdev = to_scsi_device(edev->cdev.dev);
111 struct ses_device *ses_dev = edev->scratch;
112 char *type_ptr = ses_dev->page1 + 12 + ses_dev->page1[11];
113 char *desc_ptr = ses_dev->page2 + 8;
114
115 /* Clear everything */
116 memset(desc_ptr, 0, ses_dev->page2_len - 8);
117 for (i = 0; i < ses_dev->page1[10]; i++, type_ptr += 4) {
118 for (j = 0; j < type_ptr[1]; j++) {
119 desc_ptr += 4;
120 if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE &&
121 type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE)
122 continue;
123 if (count++ == descriptor) {
124 memcpy(desc_ptr, desc, 4);
125 /* set select */
126 desc_ptr[0] |= 0x80;
127 /* clear reserved, just in case */
128 desc_ptr[0] &= 0xf0;
129 }
130 }
131 }
132
133 return ses_send_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len);
134}
135
136static char *ses_get_page2_descriptor(struct enclosure_device *edev,
137 struct enclosure_component *ecomp)
138{
139 int i, j, count = 0, descriptor = ecomp->number;
140 struct scsi_device *sdev = to_scsi_device(edev->cdev.dev);
141 struct ses_device *ses_dev = edev->scratch;
142 char *type_ptr = ses_dev->page1 + 12 + ses_dev->page1[11];
143 char *desc_ptr = ses_dev->page2 + 8;
144
145 ses_recv_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len);
146
147 for (i = 0; i < ses_dev->page1[10]; i++, type_ptr += 4) {
148 for (j = 0; j < type_ptr[1]; j++) {
149 desc_ptr += 4;
150 if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE &&
151 type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE)
152 continue;
153 if (count++ == descriptor)
154 return desc_ptr;
155 }
156 }
157 return NULL;
158}
159
160static void ses_get_fault(struct enclosure_device *edev,
161 struct enclosure_component *ecomp)
162{
163 char *desc;
164
165 desc = ses_get_page2_descriptor(edev, ecomp);
166 ecomp->fault = (desc[3] & 0x60) >> 4;
167}
168
169static int ses_set_fault(struct enclosure_device *edev,
170 struct enclosure_component *ecomp,
171 enum enclosure_component_setting val)
172{
173 char desc[4] = {0 };
174
175 switch (val) {
176 case ENCLOSURE_SETTING_DISABLED:
177 /* zero is disabled */
178 break;
179 case ENCLOSURE_SETTING_ENABLED:
180 desc[2] = 0x02;
181 break;
182 default:
183 /* SES doesn't do the SGPIO blink settings */
184 return -EINVAL;
185 }
186
187 return ses_set_page2_descriptor(edev, ecomp, desc);
188}
189
190static void ses_get_status(struct enclosure_device *edev,
191 struct enclosure_component *ecomp)
192{
193 char *desc;
194
195 desc = ses_get_page2_descriptor(edev, ecomp);
196 ecomp->status = (desc[0] & 0x0f);
197}
198
199static void ses_get_locate(struct enclosure_device *edev,
200 struct enclosure_component *ecomp)
201{
202 char *desc;
203
204 desc = ses_get_page2_descriptor(edev, ecomp);
205 ecomp->locate = (desc[2] & 0x02) ? 1 : 0;
206}
207
208static int ses_set_locate(struct enclosure_device *edev,
209 struct enclosure_component *ecomp,
210 enum enclosure_component_setting val)
211{
212 char desc[4] = {0 };
213
214 switch (val) {
215 case ENCLOSURE_SETTING_DISABLED:
216 /* zero is disabled */
217 break;
218 case ENCLOSURE_SETTING_ENABLED:
219 desc[2] = 0x02;
220 break;
221 default:
222 /* SES doesn't do the SGPIO blink settings */
223 return -EINVAL;
224 }
225 return ses_set_page2_descriptor(edev, ecomp, desc);
226}
227
228static int ses_set_active(struct enclosure_device *edev,
229 struct enclosure_component *ecomp,
230 enum enclosure_component_setting val)
231{
232 char desc[4] = {0 };
233
234 switch (val) {
235 case ENCLOSURE_SETTING_DISABLED:
236 /* zero is disabled */
237 ecomp->active = 0;
238 break;
239 case ENCLOSURE_SETTING_ENABLED:
240 desc[2] = 0x80;
241 ecomp->active = 1;
242 break;
243 default:
244 /* SES doesn't do the SGPIO blink settings */
245 return -EINVAL;
246 }
247 return ses_set_page2_descriptor(edev, ecomp, desc);
248}
249
250static struct enclosure_component_callbacks ses_enclosure_callbacks = {
251 .get_fault = ses_get_fault,
252 .set_fault = ses_set_fault,
253 .get_status = ses_get_status,
254 .get_locate = ses_get_locate,
255 .set_locate = ses_set_locate,
256 .set_active = ses_set_active,
257};
258
259struct ses_host_edev {
260 struct Scsi_Host *shost;
261 struct enclosure_device *edev;
262};
263
264int ses_match_host(struct enclosure_device *edev, void *data)
265{
266 struct ses_host_edev *sed = data;
267 struct scsi_device *sdev;
268
269 if (!scsi_is_sdev_device(edev->cdev.dev))
270 return 0;
271
272 sdev = to_scsi_device(edev->cdev.dev);
273
274 if (sdev->host != sed->shost)
275 return 0;
276
277 sed->edev = edev;
278 return 1;
279}
280
281static void ses_process_descriptor(struct enclosure_component *ecomp,
282 unsigned char *desc)
283{
284 int eip = desc[0] & 0x10;
285 int invalid = desc[0] & 0x80;
286 enum scsi_protocol proto = desc[0] & 0x0f;
287 u64 addr = 0;
288 struct ses_component *scomp = ecomp->scratch;
289 unsigned char *d;
290
291 scomp->desc = desc;
292
293 if (invalid)
294 return;
295
296 switch (proto) {
297 case SCSI_PROTOCOL_SAS:
298 if (eip)
299 d = desc + 8;
300 else
301 d = desc + 4;
302 /* only take the phy0 addr */
303 addr = (u64)d[12] << 56 |
304 (u64)d[13] << 48 |
305 (u64)d[14] << 40 |
306 (u64)d[15] << 32 |
307 (u64)d[16] << 24 |
308 (u64)d[17] << 16 |
309 (u64)d[18] << 8 |
310 (u64)d[19];
311 break;
312 default:
313 /* FIXME: Need to add more protocols than just SAS */
314 break;
315 }
316 scomp->addr = addr;
317}
318
319struct efd {
320 u64 addr;
321 struct device *dev;
322};
323
324static int ses_enclosure_find_by_addr(struct enclosure_device *edev,
325 void *data)
326{
327 struct efd *efd = data;
328 int i;
329 struct ses_component *scomp;
330
331 if (!edev->component[0].scratch)
332 return 0;
333
334 for (i = 0; i < edev->components; i++) {
335 scomp = edev->component[i].scratch;
336 if (scomp->addr != efd->addr)
337 continue;
338
339 enclosure_add_device(edev, i, efd->dev);
340 return 1;
341 }
342 return 0;
343}
344
345#define VPD_INQUIRY_SIZE 512
346
347static void ses_match_to_enclosure(struct enclosure_device *edev,
348 struct scsi_device *sdev)
349{
350 unsigned char *buf = kmalloc(VPD_INQUIRY_SIZE, GFP_KERNEL);
351 unsigned char *desc;
352 int len;
353 struct efd efd = {
354 .addr = 0,
355 };
356 unsigned char cmd[] = {
357 INQUIRY,
358 1,
359 0x83,
360 VPD_INQUIRY_SIZE >> 8,
361 VPD_INQUIRY_SIZE & 0xff,
362 0
363 };
364
365 if (!buf)
366 return;
367
368 if (scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf,
369 VPD_INQUIRY_SIZE, NULL, SES_TIMEOUT, SES_RETRIES))
370 goto free;
371
372 len = (buf[2] << 8) + buf[3];
373 desc = buf + 4;
374 while (desc < buf + len) {
375 enum scsi_protocol proto = desc[0] >> 4;
376 u8 code_set = desc[0] & 0x0f;
377 u8 piv = desc[1] & 0x80;
378 u8 assoc = (desc[1] & 0x30) >> 4;
379 u8 type = desc[1] & 0x0f;
380 u8 len = desc[3];
381
382 if (piv && code_set == 1 && assoc == 1 && code_set == 1
383 && proto == SCSI_PROTOCOL_SAS && type == 3 && len == 8)
384 efd.addr = (u64)desc[4] << 56 |
385 (u64)desc[5] << 48 |
386 (u64)desc[6] << 40 |
387 (u64)desc[7] << 32 |
388 (u64)desc[8] << 24 |
389 (u64)desc[9] << 16 |
390 (u64)desc[10] << 8 |
391 (u64)desc[11];
392
393 desc += len + 4;
394 }
395 if (!efd.addr)
396 goto free;
397
398 efd.dev = &sdev->sdev_gendev;
399
400 enclosure_for_each_device(ses_enclosure_find_by_addr, &efd);
401 free:
402 kfree(buf);
403}
404
405#define INIT_ALLOC_SIZE 32
406
407static int ses_intf_add(struct class_device *cdev,
408 struct class_interface *intf)
409{
410 struct scsi_device *sdev = to_scsi_device(cdev->dev);
411 struct scsi_device *tmp_sdev;
412 unsigned char *buf = NULL, *hdr_buf, *type_ptr, *desc_ptr,
413 *addl_desc_ptr;
414 struct ses_device *ses_dev;
415 u32 result;
416 int i, j, types, len, components = 0;
417 int err = -ENOMEM;
418 struct enclosure_device *edev;
419 struct ses_component *scomp;
420
421 if (!scsi_device_enclosure(sdev)) {
422 /* not an enclosure, but might be in one */
423 edev = enclosure_find(&sdev->host->shost_gendev);
424 if (edev) {
425 ses_match_to_enclosure(edev, sdev);
426 class_device_put(&edev->cdev);
427 }
428 return -ENODEV;
429 }
430
431 /* TYPE_ENCLOSURE prints a message in probe */
432 if (sdev->type != TYPE_ENCLOSURE)
433 sdev_printk(KERN_NOTICE, sdev, "Embedded Enclosure Device\n");
434
435 ses_dev = kzalloc(sizeof(*ses_dev), GFP_KERNEL);
436 hdr_buf = kzalloc(INIT_ALLOC_SIZE, GFP_KERNEL);
437 if (!hdr_buf || !ses_dev)
438 goto err_init_free;
439
440 result = ses_recv_diag(sdev, 1, hdr_buf, INIT_ALLOC_SIZE);
441 if (result)
442 goto recv_failed;
443
444 if (hdr_buf[1] != 0) {
445 /* FIXME: need subenclosure support; I've just never
446 * seen a device with subenclosures and it makes the
447 * traversal routines more complex */
448 sdev_printk(KERN_ERR, sdev,
449 "FIXME driver has no support for subenclosures (%d)\n",
450 buf[1]);
451 goto err_free;
452 }
453
454 len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
455 buf = kzalloc(len, GFP_KERNEL);
456 if (!buf)
457 goto err_free;
458
459 ses_dev->page1 = buf;
460 ses_dev->page1_len = len;
461
462 result = ses_recv_diag(sdev, 1, buf, len);
463 if (result)
464 goto recv_failed;
465
466 types = buf[10];
467 len = buf[11];
468
469 type_ptr = buf + 12 + len;
470
471 for (i = 0; i < types; i++, type_ptr += 4) {
472 if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE ||
473 type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE)
474 components += type_ptr[1];
475 }
476
477 result = ses_recv_diag(sdev, 2, hdr_buf, INIT_ALLOC_SIZE);
478 if (result)
479 goto recv_failed;
480
481 len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
482 buf = kzalloc(len, GFP_KERNEL);
483 if (!buf)
484 goto err_free;
485
486 /* make sure getting page 2 actually works */
487 result = ses_recv_diag(sdev, 2, buf, len);
488 if (result)
489 goto recv_failed;
490 ses_dev->page2 = buf;
491 ses_dev->page2_len = len;
492
493 /* The additional information page --- allows us
494 * to match up the devices */
495 result = ses_recv_diag(sdev, 10, hdr_buf, INIT_ALLOC_SIZE);
496 if (result)
497 goto no_page10;
498
499 len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
500 buf = kzalloc(len, GFP_KERNEL);
501 if (!buf)
502 goto err_free;
503
504 result = ses_recv_diag(sdev, 10, buf, len);
505 if (result)
506 goto recv_failed;
507 ses_dev->page10 = buf;
508 ses_dev->page10_len = len;
509
510 no_page10:
511 scomp = kmalloc(sizeof(struct ses_component) * components, GFP_KERNEL);
512 if (!scomp)
513 goto err_free;
514
515 edev = enclosure_register(cdev->dev, sdev->sdev_gendev.bus_id,
516 components, &ses_enclosure_callbacks);
517 if (IS_ERR(edev)) {
518 err = PTR_ERR(edev);
519 goto err_free;
520 }
521
522 edev->scratch = ses_dev;
523 for (i = 0; i < components; i++)
524 edev->component[i].scratch = scomp++;
525
526 /* Page 7 for the descriptors is optional */
527 buf = NULL;
528 result = ses_recv_diag(sdev, 7, hdr_buf, INIT_ALLOC_SIZE);
529 if (result)
530 goto simple_populate;
531
532 len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
533 /* add 1 for trailing '\0' we'll use */
534 buf = kzalloc(len + 1, GFP_KERNEL);
535 result = ses_recv_diag(sdev, 7, buf, len);
536 if (result) {
537 simple_populate:
538 kfree(buf);
539 buf = NULL;
540 desc_ptr = NULL;
541 addl_desc_ptr = NULL;
542 } else {
543 desc_ptr = buf + 8;
544 len = (desc_ptr[2] << 8) + desc_ptr[3];
545 /* skip past overall descriptor */
546 desc_ptr += len + 4;
547 addl_desc_ptr = ses_dev->page10 + 8;
548 }
549 type_ptr = ses_dev->page1 + 12 + ses_dev->page1[11];
550 components = 0;
551 for (i = 0; i < types; i++, type_ptr += 4) {
552 for (j = 0; j < type_ptr[1]; j++) {
553 char *name = NULL;
554 struct enclosure_component *ecomp;
555
556 if (desc_ptr) {
557 len = (desc_ptr[2] << 8) + desc_ptr[3];
558 desc_ptr += 4;
559 /* Add trailing zero - pushes into
560 * reserved space */
561 desc_ptr[len] = '\0';
562 name = desc_ptr;
563 }
564 if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE &&
565 type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE)
566 continue;
567 ecomp = enclosure_component_register(edev,
568 components++,
569 type_ptr[0],
570 name);
571 if (desc_ptr) {
572 desc_ptr += len;
573 if (!IS_ERR(ecomp))
574 ses_process_descriptor(ecomp,
575 addl_desc_ptr);
576
577 if (addl_desc_ptr)
578 addl_desc_ptr += addl_desc_ptr[1] + 2;
579 }
580 }
581 }
582 kfree(buf);
583 kfree(hdr_buf);
584
585 /* see if there are any devices matching before
586 * we found the enclosure */
587 shost_for_each_device(tmp_sdev, sdev->host) {
588 if (tmp_sdev->lun != 0 || scsi_device_enclosure(tmp_sdev))
589 continue;
590 ses_match_to_enclosure(edev, tmp_sdev);
591 }
592
593 return 0;
594
595 recv_failed:
596 sdev_printk(KERN_ERR, sdev, "Failed to get diagnostic page 0x%x\n",
597 result);
598 err = -ENODEV;
599 err_free:
600 kfree(buf);
601 kfree(ses_dev->page10);
602 kfree(ses_dev->page2);
603 kfree(ses_dev->page1);
604 err_init_free:
605 kfree(ses_dev);
606 kfree(hdr_buf);
607 sdev_printk(KERN_ERR, sdev, "Failed to bind enclosure %d\n", err);
608 return err;
609}
610
611static int ses_remove(struct device *dev)
612{
613 return 0;
614}
615
616static void ses_intf_remove(struct class_device *cdev,
617 struct class_interface *intf)
618{
619 struct scsi_device *sdev = to_scsi_device(cdev->dev);
620 struct enclosure_device *edev;
621 struct ses_device *ses_dev;
622
623 if (!scsi_device_enclosure(sdev))
624 return;
625
626 edev = enclosure_find(cdev->dev);
627 if (!edev)
628 return;
629
630 ses_dev = edev->scratch;
631 edev->scratch = NULL;
632
633 kfree(ses_dev->page1);
634 kfree(ses_dev->page2);
635 kfree(ses_dev);
636
637 kfree(edev->component[0].scratch);
638
639 class_device_put(&edev->cdev);
640 enclosure_unregister(edev);
641}
642
643static struct class_interface ses_interface = {
644 .add = ses_intf_add,
645 .remove = ses_intf_remove,
646};
647
648static struct scsi_driver ses_template = {
649 .owner = THIS_MODULE,
650 .gendrv = {
651 .name = "ses",
652 .probe = ses_probe,
653 .remove = ses_remove,
654 },
655};
656
657static int __init ses_init(void)
658{
659 int err;
660
661 err = scsi_register_interface(&ses_interface);
662 if (err)
663 return err;
664
665 err = scsi_register_driver(&ses_template.gendrv);
666 if (err)
667 goto out_unreg;
668
669 return 0;
670
671 out_unreg:
672 scsi_unregister_interface(&ses_interface);
673 return err;
674}
675
676static void __exit ses_exit(void)
677{
678 scsi_unregister_driver(&ses_template.gendrv);
679 scsi_unregister_interface(&ses_interface);
680}
681
682module_init(ses_init);
683module_exit(ses_exit);
684
685MODULE_ALIAS_SCSI_DEVICE(TYPE_ENCLOSURE);
686
687MODULE_AUTHOR("James Bottomley");
688MODULE_DESCRIPTION("SCSI Enclosure Services (ses) driver");
689MODULE_LICENSE("GPL v2");
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index aba28f335b88..e5156aa6dd20 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1160,23 +1160,22 @@ sg_fasync(int fd, struct file *filp, int mode)
1160 return (retval < 0) ? retval : 0; 1160 return (retval < 0) ? retval : 0;
1161} 1161}
1162 1162
1163static struct page * 1163static int
1164sg_vma_nopage(struct vm_area_struct *vma, unsigned long addr, int *type) 1164sg_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1165{ 1165{
1166 Sg_fd *sfp; 1166 Sg_fd *sfp;
1167 struct page *page = NOPAGE_SIGBUS;
1168 unsigned long offset, len, sa; 1167 unsigned long offset, len, sa;
1169 Sg_scatter_hold *rsv_schp; 1168 Sg_scatter_hold *rsv_schp;
1170 struct scatterlist *sg; 1169 struct scatterlist *sg;
1171 int k; 1170 int k;
1172 1171
1173 if ((NULL == vma) || (!(sfp = (Sg_fd *) vma->vm_private_data))) 1172 if ((NULL == vma) || (!(sfp = (Sg_fd *) vma->vm_private_data)))
1174 return page; 1173 return VM_FAULT_SIGBUS;
1175 rsv_schp = &sfp->reserve; 1174 rsv_schp = &sfp->reserve;
1176 offset = addr - vma->vm_start; 1175 offset = vmf->pgoff << PAGE_SHIFT;
1177 if (offset >= rsv_schp->bufflen) 1176 if (offset >= rsv_schp->bufflen)
1178 return page; 1177 return VM_FAULT_SIGBUS;
1179 SCSI_LOG_TIMEOUT(3, printk("sg_vma_nopage: offset=%lu, scatg=%d\n", 1178 SCSI_LOG_TIMEOUT(3, printk("sg_vma_fault: offset=%lu, scatg=%d\n",
1180 offset, rsv_schp->k_use_sg)); 1179 offset, rsv_schp->k_use_sg));
1181 sg = rsv_schp->buffer; 1180 sg = rsv_schp->buffer;
1182 sa = vma->vm_start; 1181 sa = vma->vm_start;
@@ -1185,21 +1184,21 @@ sg_vma_nopage(struct vm_area_struct *vma, unsigned long addr, int *type)
1185 len = vma->vm_end - sa; 1184 len = vma->vm_end - sa;
1186 len = (len < sg->length) ? len : sg->length; 1185 len = (len < sg->length) ? len : sg->length;
1187 if (offset < len) { 1186 if (offset < len) {
1187 struct page *page;
1188 page = virt_to_page(page_address(sg_page(sg)) + offset); 1188 page = virt_to_page(page_address(sg_page(sg)) + offset);
1189 get_page(page); /* increment page count */ 1189 get_page(page); /* increment page count */
1190 break; 1190 vmf->page = page;
1191 return 0; /* success */
1191 } 1192 }
1192 sa += len; 1193 sa += len;
1193 offset -= len; 1194 offset -= len;
1194 } 1195 }
1195 1196
1196 if (type) 1197 return VM_FAULT_SIGBUS;
1197 *type = VM_FAULT_MINOR;
1198 return page;
1199} 1198}
1200 1199
1201static struct vm_operations_struct sg_mmap_vm_ops = { 1200static struct vm_operations_struct sg_mmap_vm_ops = {
1202 .nopage = sg_vma_nopage, 1201 .fault = sg_vma_fault,
1203}; 1202};
1204 1203
1205static int 1204static int
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 50ba49250203..208565bdbe8e 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -163,6 +163,29 @@ static void scsi_cd_put(struct scsi_cd *cd)
163 mutex_unlock(&sr_ref_mutex); 163 mutex_unlock(&sr_ref_mutex);
164} 164}
165 165
166/* identical to scsi_test_unit_ready except that it doesn't
167 * eat the NOT_READY returns for removable media */
168int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr)
169{
170 int retries = MAX_RETRIES;
171 int the_result;
172 u8 cmd[] = {TEST_UNIT_READY, 0, 0, 0, 0, 0 };
173
174 /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION
175 * conditions are gone, or a timeout happens
176 */
177 do {
178 the_result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL,
179 0, sshdr, SR_TIMEOUT,
180 retries--);
181
182 } while (retries > 0 &&
183 (!scsi_status_is_good(the_result) ||
184 (scsi_sense_valid(sshdr) &&
185 sshdr->sense_key == UNIT_ATTENTION)));
186 return the_result;
187}
188
166/* 189/*
167 * This function checks to see if the media has been changed in the 190 * This function checks to see if the media has been changed in the
168 * CDROM drive. It is possible that we have already sensed a change, 191 * CDROM drive. It is possible that we have already sensed a change,
@@ -185,8 +208,7 @@ static int sr_media_change(struct cdrom_device_info *cdi, int slot)
185 } 208 }
186 209
187 sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL); 210 sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL);
188 retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, 211 retval = sr_test_unit_ready(cd->device, sshdr);
189 sshdr);
190 if (retval || (scsi_sense_valid(sshdr) && 212 if (retval || (scsi_sense_valid(sshdr) &&
191 /* 0x3a is medium not present */ 213 /* 0x3a is medium not present */
192 sshdr->asc == 0x3a)) { 214 sshdr->asc == 0x3a)) {
@@ -733,10 +755,8 @@ static void get_capabilities(struct scsi_cd *cd)
733{ 755{
734 unsigned char *buffer; 756 unsigned char *buffer;
735 struct scsi_mode_data data; 757 struct scsi_mode_data data;
736 unsigned char cmd[MAX_COMMAND_SIZE];
737 struct scsi_sense_hdr sshdr; 758 struct scsi_sense_hdr sshdr;
738 unsigned int the_result; 759 int rc, n;
739 int retries, rc, n;
740 760
741 static const char *loadmech[] = 761 static const char *loadmech[] =
742 { 762 {
@@ -758,23 +778,8 @@ static void get_capabilities(struct scsi_cd *cd)
758 return; 778 return;
759 } 779 }
760 780
761 /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION 781 /* eat unit attentions */
762 * conditions are gone, or a timeout happens 782 sr_test_unit_ready(cd->device, &sshdr);
763 */
764 retries = 0;
765 do {
766 memset((void *)cmd, 0, MAX_COMMAND_SIZE);
767 cmd[0] = TEST_UNIT_READY;
768
769 the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL,
770 0, &sshdr, SR_TIMEOUT,
771 MAX_RETRIES);
772
773 retries++;
774 } while (retries < 5 &&
775 (!scsi_status_is_good(the_result) ||
776 (scsi_sense_valid(&sshdr) &&
777 sshdr.sense_key == UNIT_ATTENTION)));
778 783
779 /* ask for mode page 0x2a */ 784 /* ask for mode page 0x2a */
780 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128, 785 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
diff --git a/drivers/scsi/sr.h b/drivers/scsi/sr.h
index 81fbc0b78a52..1e144dfdbd4b 100644
--- a/drivers/scsi/sr.h
+++ b/drivers/scsi/sr.h
@@ -61,6 +61,7 @@ int sr_select_speed(struct cdrom_device_info *cdi, int speed);
61int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *); 61int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *);
62 62
63int sr_is_xa(Scsi_CD *); 63int sr_is_xa(Scsi_CD *);
64int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr);
64 65
65/* sr_vendor.c */ 66/* sr_vendor.c */
66void sr_vendor_init(Scsi_CD *); 67void sr_vendor_init(Scsi_CD *);
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index d5cebff1d646..ae87d08df588 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -306,8 +306,7 @@ int sr_drive_status(struct cdrom_device_info *cdi, int slot)
306 /* we have no changer support */ 306 /* we have no changer support */
307 return -EINVAL; 307 return -EINVAL;
308 } 308 }
309 if (0 == scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, 309 if (0 == sr_test_unit_ready(cd->device, &sshdr))
310 &sshdr))
311 return CDS_DISC_OK; 310 return CDS_DISC_OK;
312 311
313 if (!cdrom_get_media_event(cdi, &med)) { 312 if (!cdrom_get_media_event(cdi, &med)) {
diff --git a/drivers/scsi/sun3x_esp.c b/drivers/scsi/sun3x_esp.c
index 1bc41907a038..06152c7fa689 100644
--- a/drivers/scsi/sun3x_esp.c
+++ b/drivers/scsi/sun3x_esp.c
@@ -1,392 +1,316 @@
1/* sun3x_esp.c: EnhancedScsiProcessor Sun3x SCSI driver code. 1/* sun3x_esp.c: ESP front-end for Sun3x systems.
2 * 2 *
3 * (C) 1999 Thomas Bogendoerfer (tsbogend@alpha.franken.de) 3 * Copyright (C) 2007,2008 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
4 *
5 * Based on David S. Miller's esp driver
6 */ 4 */
7 5
8#include <linux/kernel.h> 6#include <linux/kernel.h>
9#include <linux/types.h> 7#include <linux/types.h>
10#include <linux/string.h>
11#include <linux/slab.h>
12#include <linux/blkdev.h>
13#include <linux/proc_fs.h>
14#include <linux/stat.h>
15#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h>
16#include <linux/interrupt.h> 13#include <linux/interrupt.h>
17 14
18#include "scsi.h"
19#include <scsi/scsi_host.h>
20#include "NCR53C9x.h"
21
22#include <asm/sun3x.h> 15#include <asm/sun3x.h>
16#include <asm/io.h>
17#include <asm/dma.h>
23#include <asm/dvma.h> 18#include <asm/dvma.h>
24#include <asm/irq.h>
25
26static void dma_barrier(struct NCR_ESP *esp);
27static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
28static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
29static void dma_drain(struct NCR_ESP *esp);
30static void dma_invalidate(struct NCR_ESP *esp);
31static void dma_dump_state(struct NCR_ESP *esp);
32static void dma_init_read(struct NCR_ESP *esp, __u32 vaddress, int length);
33static void dma_init_write(struct NCR_ESP *esp, __u32 vaddress, int length);
34static void dma_ints_off(struct NCR_ESP *esp);
35static void dma_ints_on(struct NCR_ESP *esp);
36static int dma_irq_p(struct NCR_ESP *esp);
37static void dma_poll(struct NCR_ESP *esp, unsigned char *vaddr);
38static int dma_ports_p(struct NCR_ESP *esp);
39static void dma_reset(struct NCR_ESP *esp);
40static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
41static void dma_mmu_get_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp);
42static void dma_mmu_get_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp);
43static void dma_mmu_release_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp);
44static void dma_mmu_release_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp);
45static void dma_advance_sg (Scsi_Cmnd *sp);
46
47/* Detecting ESP chips on the machine. This is the simple and easy
48 * version.
49 */
50int sun3x_esp_detect(struct scsi_host_template *tpnt)
51{
52 struct NCR_ESP *esp;
53 struct ConfigDev *esp_dev;
54
55 esp_dev = 0;
56 esp = esp_allocate(tpnt, esp_dev, 0);
57
58 /* Do command transfer with DMA */
59 esp->do_pio_cmds = 0;
60
61 /* Required functions */
62 esp->dma_bytes_sent = &dma_bytes_sent;
63 esp->dma_can_transfer = &dma_can_transfer;
64 esp->dma_dump_state = &dma_dump_state;
65 esp->dma_init_read = &dma_init_read;
66 esp->dma_init_write = &dma_init_write;
67 esp->dma_ints_off = &dma_ints_off;
68 esp->dma_ints_on = &dma_ints_on;
69 esp->dma_irq_p = &dma_irq_p;
70 esp->dma_ports_p = &dma_ports_p;
71 esp->dma_setup = &dma_setup;
72
73 /* Optional functions */
74 esp->dma_barrier = &dma_barrier;
75 esp->dma_invalidate = &dma_invalidate;
76 esp->dma_drain = &dma_drain;
77 esp->dma_irq_entry = 0;
78 esp->dma_irq_exit = 0;
79 esp->dma_led_on = 0;
80 esp->dma_led_off = 0;
81 esp->dma_poll = &dma_poll;
82 esp->dma_reset = &dma_reset;
83
84 /* virtual DMA functions */
85 esp->dma_mmu_get_scsi_one = &dma_mmu_get_scsi_one;
86 esp->dma_mmu_get_scsi_sgl = &dma_mmu_get_scsi_sgl;
87 esp->dma_mmu_release_scsi_one = &dma_mmu_release_scsi_one;
88 esp->dma_mmu_release_scsi_sgl = &dma_mmu_release_scsi_sgl;
89 esp->dma_advance_sg = &dma_advance_sg;
90
91 /* SCSI chip speed */
92 esp->cfreq = 20000000;
93 esp->eregs = (struct ESP_regs *)(SUN3X_ESP_BASE);
94 esp->dregs = (void *)SUN3X_ESP_DMA;
95 19
96 esp->esp_command = (volatile unsigned char *)dvma_malloc(DVMA_PAGE_SIZE); 20/* DMA controller reg offsets */
97 esp->esp_command_dvma = dvma_vtob((unsigned long)esp->esp_command); 21#define DMA_CSR 0x00UL /* rw DMA control/status register 0x00 */
98 22#define DMA_ADDR 0x04UL /* rw DMA transfer address register 0x04 */
99 esp->irq = 2; 23#define DMA_COUNT 0x08UL /* rw DMA transfer count register 0x08 */
100 if (request_irq(esp->irq, esp_intr, IRQF_DISABLED, 24#define DMA_TEST 0x0cUL /* rw DMA test/debug register 0x0c */
101 "SUN3X SCSI", esp->ehost)) {
102 esp_deallocate(esp);
103 return 0;
104 }
105 25
106 esp->scsi_id = 7; 26#include <scsi/scsi_host.h>
107 esp->diff = 0;
108 27
109 esp_initialize(esp); 28#include "esp_scsi.h"
110 29
111 /* for reasons beyond my knowledge (and which should likely be fixed) 30#define DRV_MODULE_NAME "sun3x_esp"
112 sync mode doesn't work on a 3/80 at 5mhz. but it does at 4. */ 31#define PFX DRV_MODULE_NAME ": "
113 esp->sync_defp = 0x3f; 32#define DRV_VERSION "1.000"
33#define DRV_MODULE_RELDATE "Nov 1, 2007"
114 34
115 printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, 35/*
116 esps_in_use); 36 * m68k always assumes readl/writel operate on little endian
117 esps_running = esps_in_use; 37 * mmio space; this is wrong at least for Sun3x, so we
118 return esps_in_use; 38 * need to workaround this until a proper way is found
39 */
40#if 0
41#define dma_read32(REG) \
42 readl(esp->dma_regs + (REG))
43#define dma_write32(VAL, REG) \
44 writel((VAL), esp->dma_regs + (REG))
45#else
46#define dma_read32(REG) \
47 *(volatile u32 *)(esp->dma_regs + (REG))
48#define dma_write32(VAL, REG) \
49 do { *(volatile u32 *)(esp->dma_regs + (REG)) = (VAL); } while (0)
50#endif
51
52static void sun3x_esp_write8(struct esp *esp, u8 val, unsigned long reg)
53{
54 writeb(val, esp->regs + (reg * 4UL));
119} 55}
120 56
121static void dma_do_drain(struct NCR_ESP *esp) 57static u8 sun3x_esp_read8(struct esp *esp, unsigned long reg)
122{ 58{
123 struct sparc_dma_registers *dregs = 59 return readb(esp->regs + (reg * 4UL));
124 (struct sparc_dma_registers *) esp->dregs;
125
126 int count = 500000;
127
128 while((dregs->cond_reg & DMA_PEND_READ) && (--count > 0))
129 udelay(1);
130
131 if(!count) {
132 printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
133 }
134
135 dregs->cond_reg |= DMA_FIFO_STDRAIN;
136
137 count = 500000;
138
139 while((dregs->cond_reg & DMA_FIFO_ISDRAIN) && (--count > 0))
140 udelay(1);
141
142 if(!count) {
143 printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
144 }
145
146} 60}
147 61
148static void dma_barrier(struct NCR_ESP *esp) 62static dma_addr_t sun3x_esp_map_single(struct esp *esp, void *buf,
63 size_t sz, int dir)
149{ 64{
150 struct sparc_dma_registers *dregs = 65 return dma_map_single(esp->dev, buf, sz, dir);
151 (struct sparc_dma_registers *) esp->dregs;
152 int count = 500000;
153
154 while((dregs->cond_reg & DMA_PEND_READ) && (--count > 0))
155 udelay(1);
156
157 if(!count) {
158 printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
159 }
160
161 dregs->cond_reg &= ~(DMA_ENABLE);
162} 66}
163 67
164/* This uses various DMA csr fields and the fifo flags count value to 68static int sun3x_esp_map_sg(struct esp *esp, struct scatterlist *sg,
165 * determine how many bytes were successfully sent/received by the ESP. 69 int num_sg, int dir)
166 */
167static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
168{ 70{
169 struct sparc_dma_registers *dregs = 71 return dma_map_sg(esp->dev, sg, num_sg, dir);
170 (struct sparc_dma_registers *) esp->dregs;
171
172 int rval = dregs->st_addr - esp->esp_command_dvma;
173
174 return rval - fifo_count;
175} 72}
176 73
177static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp) 74static void sun3x_esp_unmap_single(struct esp *esp, dma_addr_t addr,
75 size_t sz, int dir)
178{ 76{
179 return sp->SCp.this_residual; 77 dma_unmap_single(esp->dev, addr, sz, dir);
180} 78}
181 79
182static void dma_drain(struct NCR_ESP *esp) 80static void sun3x_esp_unmap_sg(struct esp *esp, struct scatterlist *sg,
81 int num_sg, int dir)
183{ 82{
184 struct sparc_dma_registers *dregs = 83 dma_unmap_sg(esp->dev, sg, num_sg, dir);
185 (struct sparc_dma_registers *) esp->dregs;
186 int count = 500000;
187
188 if(dregs->cond_reg & DMA_FIFO_ISDRAIN) {
189 dregs->cond_reg |= DMA_FIFO_STDRAIN;
190 while((dregs->cond_reg & DMA_FIFO_ISDRAIN) && (--count > 0))
191 udelay(1);
192 if(!count) {
193 printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
194 }
195
196 }
197} 84}
198 85
199static void dma_invalidate(struct NCR_ESP *esp) 86static int sun3x_esp_irq_pending(struct esp *esp)
200{ 87{
201 struct sparc_dma_registers *dregs = 88 if (dma_read32(DMA_CSR) & (DMA_HNDL_INTR | DMA_HNDL_ERROR))
202 (struct sparc_dma_registers *) esp->dregs; 89 return 1;
203 90 return 0;
204 __u32 tmp; 91}
205 int count = 500000;
206
207 while(((tmp = dregs->cond_reg) & DMA_PEND_READ) && (--count > 0))
208 udelay(1);
209 92
210 if(!count) { 93static void sun3x_esp_reset_dma(struct esp *esp)
211 printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg); 94{
212 } 95 u32 val;
213 96
214 dregs->cond_reg = tmp | DMA_FIFO_INV; 97 val = dma_read32(DMA_CSR);
215 dregs->cond_reg &= ~DMA_FIFO_INV; 98 dma_write32(val | DMA_RST_SCSI, DMA_CSR);
99 dma_write32(val & ~DMA_RST_SCSI, DMA_CSR);
216 100
101 /* Enable interrupts. */
102 val = dma_read32(DMA_CSR);
103 dma_write32(val | DMA_INT_ENAB, DMA_CSR);
217} 104}
218 105
219static void dma_dump_state(struct NCR_ESP *esp) 106static void sun3x_esp_dma_drain(struct esp *esp)
220{ 107{
221 struct sparc_dma_registers *dregs = 108 u32 csr;
222 (struct sparc_dma_registers *) esp->dregs; 109 int lim;
223 110
224 ESPLOG(("esp%d: dma -- cond_reg<%08lx> addr<%08lx>\n", 111 csr = dma_read32(DMA_CSR);
225 esp->esp_id, dregs->cond_reg, dregs->st_addr)); 112 if (!(csr & DMA_FIFO_ISDRAIN))
226} 113 return;
227 114
228static void dma_init_read(struct NCR_ESP *esp, __u32 vaddress, int length) 115 dma_write32(csr | DMA_FIFO_STDRAIN, DMA_CSR);
229{
230 struct sparc_dma_registers *dregs =
231 (struct sparc_dma_registers *) esp->dregs;
232 116
233 dregs->st_addr = vaddress; 117 lim = 1000;
234 dregs->cond_reg |= (DMA_ST_WRITE | DMA_ENABLE); 118 while (dma_read32(DMA_CSR) & DMA_FIFO_ISDRAIN) {
119 if (--lim == 0) {
120 printk(KERN_ALERT PFX "esp%d: DMA will not drain!\n",
121 esp->host->unique_id);
122 break;
123 }
124 udelay(1);
125 }
235} 126}
236 127
237static void dma_init_write(struct NCR_ESP *esp, __u32 vaddress, int length) 128static void sun3x_esp_dma_invalidate(struct esp *esp)
238{ 129{
239 struct sparc_dma_registers *dregs = 130 u32 val;
240 (struct sparc_dma_registers *) esp->dregs; 131 int lim;
241 132
242 /* Set up the DMA counters */ 133 lim = 1000;
134 while ((val = dma_read32(DMA_CSR)) & DMA_PEND_READ) {
135 if (--lim == 0) {
136 printk(KERN_ALERT PFX "esp%d: DMA will not "
137 "invalidate!\n", esp->host->unique_id);
138 break;
139 }
140 udelay(1);
141 }
243 142
244 dregs->st_addr = vaddress; 143 val &= ~(DMA_ENABLE | DMA_ST_WRITE | DMA_BCNT_ENAB);
245 dregs->cond_reg = ((dregs->cond_reg & ~(DMA_ST_WRITE)) | DMA_ENABLE); 144 val |= DMA_FIFO_INV;
145 dma_write32(val, DMA_CSR);
146 val &= ~DMA_FIFO_INV;
147 dma_write32(val, DMA_CSR);
246} 148}
247 149
248static void dma_ints_off(struct NCR_ESP *esp) 150static void sun3x_esp_send_dma_cmd(struct esp *esp, u32 addr, u32 esp_count,
151 u32 dma_count, int write, u8 cmd)
249{ 152{
250 DMA_INTSOFF((struct sparc_dma_registers *) esp->dregs); 153 u32 csr;
154
155 BUG_ON(!(cmd & ESP_CMD_DMA));
156
157 sun3x_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
158 sun3x_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
159 csr = dma_read32(DMA_CSR);
160 csr |= DMA_ENABLE;
161 if (write)
162 csr |= DMA_ST_WRITE;
163 else
164 csr &= ~DMA_ST_WRITE;
165 dma_write32(csr, DMA_CSR);
166 dma_write32(addr, DMA_ADDR);
167
168 scsi_esp_cmd(esp, cmd);
251} 169}
252 170
253static void dma_ints_on(struct NCR_ESP *esp) 171static int sun3x_esp_dma_error(struct esp *esp)
254{ 172{
255 DMA_INTSON((struct sparc_dma_registers *) esp->dregs); 173 u32 csr = dma_read32(DMA_CSR);
256}
257 174
258static int dma_irq_p(struct NCR_ESP *esp) 175 if (csr & DMA_HNDL_ERROR)
259{ 176 return 1;
260 return DMA_IRQ_P((struct sparc_dma_registers *) esp->dregs); 177
178 return 0;
261} 179}
262 180
263static void dma_poll(struct NCR_ESP *esp, unsigned char *vaddr) 181static const struct esp_driver_ops sun3x_esp_ops = {
182 .esp_write8 = sun3x_esp_write8,
183 .esp_read8 = sun3x_esp_read8,
184 .map_single = sun3x_esp_map_single,
185 .map_sg = sun3x_esp_map_sg,
186 .unmap_single = sun3x_esp_unmap_single,
187 .unmap_sg = sun3x_esp_unmap_sg,
188 .irq_pending = sun3x_esp_irq_pending,
189 .reset_dma = sun3x_esp_reset_dma,
190 .dma_drain = sun3x_esp_dma_drain,
191 .dma_invalidate = sun3x_esp_dma_invalidate,
192 .send_dma_cmd = sun3x_esp_send_dma_cmd,
193 .dma_error = sun3x_esp_dma_error,
194};
195
196static int __devinit esp_sun3x_probe(struct platform_device *dev)
264{ 197{
265 int count = 50; 198 struct scsi_host_template *tpnt = &scsi_esp_template;
266 dma_do_drain(esp); 199 struct Scsi_Host *host;
200 struct esp *esp;
201 struct resource *res;
202 int err = -ENOMEM;
267 203
268 /* Wait till the first bits settle. */ 204 host = scsi_host_alloc(tpnt, sizeof(struct esp));
269 while((*(volatile unsigned char *)vaddr == 0xff) && (--count > 0)) 205 if (!host)
270 udelay(1); 206 goto fail;
271 207
272 if(!count) { 208 host->max_id = 8;
273// printk("%s:%d timeout expire (data %02x)\n", __FILE__, __LINE__, 209 esp = shost_priv(host);
274// esp_read(esp->eregs->esp_fdata));
275 //mach_halt();
276 vaddr[0] = esp_read(esp->eregs->esp_fdata);
277 vaddr[1] = esp_read(esp->eregs->esp_fdata);
278 }
279 210
280} 211 esp->host = host;
212 esp->dev = dev;
213 esp->ops = &sun3x_esp_ops;
281 214
282static int dma_ports_p(struct NCR_ESP *esp) 215 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
283{ 216 if (!res && !res->start)
284 return (((struct sparc_dma_registers *) esp->dregs)->cond_reg 217 goto fail_unlink;
285 & DMA_INT_ENAB);
286}
287 218
288/* Resetting various pieces of the ESP scsi driver chipset/buses. */ 219 esp->regs = ioremap_nocache(res->start, 0x20);
289static void dma_reset(struct NCR_ESP *esp) 220 if (!esp->regs)
290{ 221 goto fail_unmap_regs;
291 struct sparc_dma_registers *dregs =
292 (struct sparc_dma_registers *)esp->dregs;
293 222
294 /* Punt the DVMA into a known state. */ 223 res = platform_get_resource(dev, IORESOURCE_MEM, 1);
295 dregs->cond_reg |= DMA_RST_SCSI; 224 if (!res && !res->start)
296 dregs->cond_reg &= ~(DMA_RST_SCSI); 225 goto fail_unmap_regs;
297 DMA_INTSON(dregs);
298}
299 226
300static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write) 227 esp->dma_regs = ioremap_nocache(res->start, 0x10);
301{
302 struct sparc_dma_registers *dregs =
303 (struct sparc_dma_registers *) esp->dregs;
304 unsigned long nreg = dregs->cond_reg;
305 228
306// printk("dma_setup %c addr %08x cnt %08x\n", 229 esp->command_block = dma_alloc_coherent(esp->dev, 16,
307// write ? 'W' : 'R', addr, count); 230 &esp->command_block_dma,
231 GFP_KERNEL);
232 if (!esp->command_block)
233 goto fail_unmap_regs_dma;
308 234
309 dma_do_drain(esp); 235 host->irq = platform_get_irq(dev, 0);
236 err = request_irq(host->irq, scsi_esp_intr, IRQF_SHARED,
237 "SUN3X ESP", esp);
238 if (err < 0)
239 goto fail_unmap_command_block;
310 240
311 if(write) 241 esp->scsi_id = 7;
312 nreg |= DMA_ST_WRITE; 242 esp->host->this_id = esp->scsi_id;
313 else { 243 esp->scsi_id_mask = (1 << esp->scsi_id);
314 nreg &= ~(DMA_ST_WRITE); 244 esp->cfreq = 20000000;
315 }
316
317 nreg |= DMA_ENABLE;
318 dregs->cond_reg = nreg;
319 dregs->st_addr = addr;
320}
321 245
322static void dma_mmu_get_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp) 246 dev_set_drvdata(&dev->dev, esp);
323{ 247
324 sp->SCp.have_data_in = dvma_map((unsigned long)sp->SCp.buffer, 248 err = scsi_esp_register(esp, &dev->dev);
325 sp->SCp.this_residual); 249 if (err)
326 sp->SCp.ptr = (char *)((unsigned long)sp->SCp.have_data_in); 250 goto fail_free_irq;
251
252 return 0;
253
254fail_free_irq:
255 free_irq(host->irq, esp);
256fail_unmap_command_block:
257 dma_free_coherent(esp->dev, 16,
258 esp->command_block,
259 esp->command_block_dma);
260fail_unmap_regs_dma:
261 iounmap(esp->dma_regs);
262fail_unmap_regs:
263 iounmap(esp->regs);
264fail_unlink:
265 scsi_host_put(host);
266fail:
267 return err;
327} 268}
328 269
329static void dma_mmu_get_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp) 270static int __devexit esp_sun3x_remove(struct platform_device *dev)
330{ 271{
331 int sz = sp->SCp.buffers_residual; 272 struct esp *esp = dev_get_drvdata(&dev->dev);
332 struct scatterlist *sg = sp->SCp.buffer; 273 unsigned int irq = esp->host->irq;
333 274 u32 val;
334 while (sz >= 0) {
335 sg[sz].dma_address = dvma_map((unsigned long)sg_virt(&sg[sz]),
336 sg[sz].length);
337 sz--;
338 }
339 sp->SCp.ptr=(char *)((unsigned long)sp->SCp.buffer->dma_address);
340}
341 275
342static void dma_mmu_release_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp) 276 scsi_esp_unregister(esp);
343{
344 dvma_unmap((char *)sp->SCp.have_data_in);
345}
346 277
347static void dma_mmu_release_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp) 278 /* Disable interrupts. */
348{ 279 val = dma_read32(DMA_CSR);
349 int sz = sp->use_sg - 1; 280 dma_write32(val & ~DMA_INT_ENAB, DMA_CSR);
350 struct scatterlist *sg = (struct scatterlist *)sp->request_buffer;
351
352 while(sz >= 0) {
353 dvma_unmap((char *)sg[sz].dma_address);
354 sz--;
355 }
356}
357 281
358static void dma_advance_sg (Scsi_Cmnd *sp) 282 free_irq(irq, esp);
359{ 283 dma_free_coherent(esp->dev, 16,
360 sp->SCp.ptr = (char *)((unsigned long)sp->SCp.buffer->dma_address); 284 esp->command_block,
361} 285 esp->command_block_dma);
362 286
363static int sun3x_esp_release(struct Scsi_Host *instance) 287 scsi_host_put(esp->host);
364{
365 /* this code does not support being compiled as a module */
366 return 1;
367 288
289 return 0;
368} 290}
369 291
370static struct scsi_host_template driver_template = { 292static struct platform_driver esp_sun3x_driver = {
371 .proc_name = "sun3x_esp", 293 .probe = esp_sun3x_probe,
372 .proc_info = &esp_proc_info, 294 .remove = __devexit_p(esp_sun3x_remove),
373 .name = "Sun ESP 100/100a/200", 295 .driver = {
374 .detect = sun3x_esp_detect, 296 .name = "sun3x_esp",
375 .release = sun3x_esp_release, 297 },
376 .slave_alloc = esp_slave_alloc,
377 .slave_destroy = esp_slave_destroy,
378 .info = esp_info,
379 .queuecommand = esp_queue,
380 .eh_abort_handler = esp_abort,
381 .eh_bus_reset_handler = esp_reset,
382 .can_queue = 7,
383 .this_id = 7,
384 .sg_tablesize = SG_ALL,
385 .cmd_per_lun = 1,
386 .use_clustering = DISABLE_CLUSTERING,
387}; 298};
388 299
300static int __init sun3x_esp_init(void)
301{
302 return platform_driver_register(&esp_sun3x_driver);
303}
389 304
390#include "scsi_module.c" 305static void __exit sun3x_esp_exit(void)
306{
307 platform_driver_unregister(&esp_sun3x_driver);
308}
391 309
310MODULE_DESCRIPTION("Sun3x ESP SCSI driver");
311MODULE_AUTHOR("Thomas Bogendoerfer (tsbogend@alpha.franken.de)");
392MODULE_LICENSE("GPL"); 312MODULE_LICENSE("GPL");
313MODULE_VERSION(DRV_VERSION);
314
315module_init(sun3x_esp_init);
316module_exit(sun3x_esp_exit);
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.c b/drivers/scsi/sym53c8xx_2/sym_hipd.c
index 254bdaeb35ff..35142b5341b5 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.c
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.c
@@ -3842,7 +3842,7 @@ int sym_compute_residual(struct sym_hcb *np, struct sym_ccb *cp)
3842 if (cp->startp == cp->phys.head.lastp || 3842 if (cp->startp == cp->phys.head.lastp ||
3843 sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp), 3843 sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp),
3844 &dp_ofs) < 0) { 3844 &dp_ofs) < 0) {
3845 return cp->data_len; 3845 return cp->data_len - cp->odd_byte_adjustment;
3846 } 3846 }
3847 3847
3848 /* 3848 /*
diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index 662c00451be4..58d7eee4fe81 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -1216,7 +1216,7 @@ static void scsi_to_dev_dir(unsigned int i, unsigned int j) {
1216 cpp->xdir = DTD_IN; 1216 cpp->xdir = DTD_IN;
1217 return; 1217 return;
1218 } 1218 }
1219 else if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) { 1219 else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
1220 cpp->xdir = DTD_OUT; 1220 cpp->xdir = DTD_OUT;
1221 return; 1221 return;
1222 } 1222 }