aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/Kconfig20
-rw-r--r--drivers/block/Makefile2
-rw-r--r--drivers/block/acsi_slm.c1032
-rw-r--r--drivers/block/cciss.c2
-rw-r--r--drivers/block/cciss_scsi.c75
-rw-r--r--drivers/block/nbd.c22
-rw-r--r--drivers/block/pktcdvd.c6
-rw-r--r--drivers/block/sunvdc.c972
-rw-r--r--drivers/block/ub.c14
-rw-r--r--drivers/block/umem.c58
-rw-r--r--drivers/block/z2ram.c3
11 files changed, 1021 insertions, 1185 deletions
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 6e23af1ecbdb..c5a61571a076 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -59,17 +59,6 @@ config AMIGA_Z2RAM
59 To compile this driver as a module, choose M here: the 59 To compile this driver as a module, choose M here: the
60 module will be called z2ram. 60 module will be called z2ram.
61 61
62config ATARI_SLM
63 tristate "Atari SLM laser printer support"
64 depends on ATARI
65 help
66 If you have an Atari SLM laser printer, say Y to include support for
67 it in the kernel. Otherwise, say N. This driver is also available as
68 a module ( = code which can be inserted in and removed from the
69 running kernel whenever you want). The module will be called
70 acsi_slm. Be warned: the driver needs much ST-RAM and can cause
71 problems due to that fact!
72
73config BLK_DEV_XD 62config BLK_DEV_XD
74 tristate "XT hard disk support" 63 tristate "XT hard disk support"
75 depends on ISA && ISA_DMA_API 64 depends on ISA && ISA_DMA_API
@@ -113,7 +102,7 @@ source "drivers/block/paride/Kconfig"
113 102
114config BLK_CPQ_DA 103config BLK_CPQ_DA
115 tristate "Compaq SMART2 support" 104 tristate "Compaq SMART2 support"
116 depends on PCI 105 depends on PCI && VIRT_TO_BUS
117 help 106 help
118 This is the driver for Compaq Smart Array controllers. Everyone 107 This is the driver for Compaq Smart Array controllers. Everyone
119 using these boards should say Y here. See the file 108 using these boards should say Y here. See the file
@@ -423,6 +412,13 @@ config ATA_OVER_ETH
423 This driver provides Support for ATA over Ethernet block 412 This driver provides Support for ATA over Ethernet block
424 devices like the Coraid EtherDrive (R) Storage Blade. 413 devices like the Coraid EtherDrive (R) Storage Blade.
425 414
415config SUNVDC
416 tristate "Sun Virtual Disk Client support"
417 depends on SUN_LDOMS
418 help
419 Support for virtual disk devices as a client under Sun
420 Logical Domains.
421
426source "drivers/s390/block/Kconfig" 422source "drivers/s390/block/Kconfig"
427 423
428endif # BLK_DEV 424endif # BLK_DEV
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index e5f98acc5d52..7926be8c9fb7 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -9,7 +9,6 @@ obj-$(CONFIG_MAC_FLOPPY) += swim3.o
9obj-$(CONFIG_BLK_DEV_FD) += floppy.o 9obj-$(CONFIG_BLK_DEV_FD) += floppy.o
10obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o 10obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o
11obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o 11obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o
12obj-$(CONFIG_ATARI_SLM) += acsi_slm.o
13obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o 12obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o
14obj-$(CONFIG_BLK_DEV_RAM) += rd.o 13obj-$(CONFIG_BLK_DEV_RAM) += rd.o
15obj-$(CONFIG_BLK_DEV_LOOP) += loop.o 14obj-$(CONFIG_BLK_DEV_LOOP) += loop.o
@@ -19,6 +18,7 @@ obj-$(CONFIG_BLK_CPQ_DA) += cpqarray.o
19obj-$(CONFIG_BLK_CPQ_CISS_DA) += cciss.o 18obj-$(CONFIG_BLK_CPQ_CISS_DA) += cciss.o
20obj-$(CONFIG_BLK_DEV_DAC960) += DAC960.o 19obj-$(CONFIG_BLK_DEV_DAC960) += DAC960.o
21obj-$(CONFIG_CDROM_PKTCDVD) += pktcdvd.o 20obj-$(CONFIG_CDROM_PKTCDVD) += pktcdvd.o
21obj-$(CONFIG_SUNVDC) += sunvdc.o
22 22
23obj-$(CONFIG_BLK_DEV_UMEM) += umem.o 23obj-$(CONFIG_BLK_DEV_UMEM) += umem.o
24obj-$(CONFIG_BLK_DEV_NBD) += nbd.o 24obj-$(CONFIG_BLK_DEV_NBD) += nbd.o
diff --git a/drivers/block/acsi_slm.c b/drivers/block/acsi_slm.c
deleted file mode 100644
index 1d9d9b4f48cc..000000000000
--- a/drivers/block/acsi_slm.c
+++ /dev/null
@@ -1,1032 +0,0 @@
1/*
2 * acsi_slm.c -- Device driver for the Atari SLM laser printer
3 *
4 * Copyright 1995 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
8 * more details.
9 *
10 */
11
12/*
13
14Notes:
15
16The major number for SLM printers is 28 (like ACSI), but as a character
17device, not block device. The minor number is the number of the printer (if
18you have more than one SLM; currently max. 2 (#define-constant) SLMs are
19supported). The device can be opened for reading and writing. If reading it,
20you get some status infos (MODE SENSE data). Writing mode is used for the data
21to be printed. Some ioctls allow to get the printer status and to tune printer
22modes and some internal variables.
23
24A special problem of the SLM driver is the timing and thus the buffering of
25the print data. The problem is that all the data for one page must be present
26in memory when printing starts, else --when swapping occurs-- the timing could
27not be guaranteed. There are several ways to assure this:
28
29 1) Reserve a buffer of 1196k (maximum page size) statically by
30 atari_stram_alloc(). The data are collected there until they're complete,
31 and then printing starts. Since the buffer is reserved, no further
32 considerations about memory and swapping are needed. So this is the
33 simplest method, but it needs a lot of memory for just the SLM.
34
35 An striking advantage of this method is (supposed the SLM_CONT_CNT_REPROG
36 method works, see there), that there are no timing problems with the DMA
37 anymore.
38
39 2) The other method would be to reserve the buffer dynamically each time
40 printing is required. I could think of looking at mem_map where the
41 largest unallocted ST-RAM area is, taking the area, and then extending it
42 by swapping out the neighbored pages, until the needed size is reached.
43 This requires some mm hacking, but seems possible. The only obstacle could
44 be pages that cannot be swapped out (reserved pages)...
45
46 3) Another possibility would be to leave the real data in user space and to
47 work with two dribble buffers of about 32k in the driver: While the one
48 buffer is DMAed to the SLM, the other can be filled with new data. But
49 to keep the timing, that requires that the user data remain in memory and
50 are not swapped out. Requires mm hacking, too, but maybe not so bad as
51 method 2).
52
53*/
54
55#include <linux/module.h>
56
57#include <linux/errno.h>
58#include <linux/sched.h>
59#include <linux/timer.h>
60#include <linux/fs.h>
61#include <linux/major.h>
62#include <linux/kernel.h>
63#include <linux/delay.h>
64#include <linux/interrupt.h>
65#include <linux/time.h>
66#include <linux/mm.h>
67#include <linux/slab.h>
68
69#include <asm/pgtable.h>
70#include <asm/system.h>
71#include <asm/uaccess.h>
72#include <asm/atarihw.h>
73#include <asm/atariints.h>
74#include <asm/atari_acsi.h>
75#include <asm/atari_stdma.h>
76#include <asm/atari_stram.h>
77#include <asm/atari_SLM.h>
78
79
80#undef DEBUG
81
82/* Define this if the page data are continuous in physical memory. That
83 * requires less reprogramming of the ST-DMA */
84#define SLM_CONTINUOUS_DMA
85
86/* Use continuous reprogramming of the ST-DMA counter register. This is
87 * --strictly speaking-- not allowed, Atari recommends not to look at the
88 * counter register while a DMA is going on. But I don't know if that applies
89 * only for reading the register, or also writing to it. Writing only works
90 * fine for me... The advantage is that the timing becomes absolutely
91 * uncritical: Just update each, say 200ms, the counter reg to its maximum,
92 * and the DMA will work until the status byte interrupt occurs.
93 */
94#define SLM_CONT_CNT_REPROG
95
96#define CMDSET_TARG_LUN(cmd,targ,lun) \
97 do { \
98 cmd[0] = (cmd[0] & ~0xe0) | (targ)<<5; \
99 cmd[1] = (cmd[1] & ~0xe0) | (lun)<<5; \
100 } while(0)
101
102#define START_TIMER(to) mod_timer(&slm_timer, jiffies + (to))
103#define STOP_TIMER() del_timer(&slm_timer)
104
105
106static char slmreqsense_cmd[6] = { 0x03, 0, 0, 0, 0, 0 };
107static char slmprint_cmd[6] = { 0x0a, 0, 0, 0, 0, 0 };
108static char slminquiry_cmd[6] = { 0x12, 0, 0, 0, 0, 0x80 };
109static char slmmsense_cmd[6] = { 0x1a, 0, 0, 0, 255, 0 };
110#if 0
111static char slmmselect_cmd[6] = { 0x15, 0, 0, 0, 0, 0 };
112#endif
113
114
115#define MAX_SLM 2
116
117static struct slm {
118 unsigned target; /* target number */
119 unsigned lun; /* LUN in target controller */
120 atomic_t wr_ok; /* set to 0 if output part busy */
121 atomic_t rd_ok; /* set to 0 if status part busy */
122} slm_info[MAX_SLM];
123
124int N_SLM_Printers = 0;
125
126/* printer buffer */
127static unsigned char *SLMBuffer; /* start of buffer */
128static unsigned char *BufferP; /* current position in buffer */
129static int BufferSize; /* length of buffer for page size */
130
131typedef enum { IDLE, FILLING, PRINTING } SLMSTATE;
132static SLMSTATE SLMState;
133static int SLMBufOwner; /* SLM# currently using the buffer */
134
135/* DMA variables */
136#ifndef SLM_CONT_CNT_REPROG
137static unsigned long SLMCurAddr; /* current base addr of DMA chunk */
138static unsigned long SLMEndAddr; /* expected end addr */
139static unsigned long SLMSliceSize; /* size of one DMA chunk */
140#endif
141static int SLMError;
142
143/* wait queues */
144static DECLARE_WAIT_QUEUE_HEAD(slm_wait); /* waiting for buffer */
145static DECLARE_WAIT_QUEUE_HEAD(print_wait); /* waiting for printing finished */
146
147/* status codes */
148#define SLMSTAT_OK 0x00
149#define SLMSTAT_ORNERY 0x02
150#define SLMSTAT_TONER 0x03
151#define SLMSTAT_WARMUP 0x04
152#define SLMSTAT_PAPER 0x05
153#define SLMSTAT_DRUM 0x06
154#define SLMSTAT_INJAM 0x07
155#define SLMSTAT_THRJAM 0x08
156#define SLMSTAT_OUTJAM 0x09
157#define SLMSTAT_COVER 0x0a
158#define SLMSTAT_FUSER 0x0b
159#define SLMSTAT_IMAGER 0x0c
160#define SLMSTAT_MOTOR 0x0d
161#define SLMSTAT_VIDEO 0x0e
162#define SLMSTAT_SYSTO 0x10
163#define SLMSTAT_OPCODE 0x12
164#define SLMSTAT_DEVNUM 0x15
165#define SLMSTAT_PARAM 0x1a
166#define SLMSTAT_ACSITO 0x1b /* driver defined */
167#define SLMSTAT_NOTALL 0x1c /* driver defined */
168
169static char *SLMErrors[] = {
170 /* 0x00 */ "OK and ready",
171 /* 0x01 */ NULL,
172 /* 0x02 */ "ornery printer",
173 /* 0x03 */ "toner empty",
174 /* 0x04 */ "warming up",
175 /* 0x05 */ "paper empty",
176 /* 0x06 */ "drum empty",
177 /* 0x07 */ "input jam",
178 /* 0x08 */ "through jam",
179 /* 0x09 */ "output jam",
180 /* 0x0a */ "cover open",
181 /* 0x0b */ "fuser malfunction",
182 /* 0x0c */ "imager malfunction",
183 /* 0x0d */ "motor malfunction",
184 /* 0x0e */ "video malfunction",
185 /* 0x0f */ NULL,
186 /* 0x10 */ "printer system timeout",
187 /* 0x11 */ NULL,
188 /* 0x12 */ "invalid operation code",
189 /* 0x13 */ NULL,
190 /* 0x14 */ NULL,
191 /* 0x15 */ "invalid device number",
192 /* 0x16 */ NULL,
193 /* 0x17 */ NULL,
194 /* 0x18 */ NULL,
195 /* 0x19 */ NULL,
196 /* 0x1a */ "invalid parameter list",
197 /* 0x1b */ "ACSI timeout",
198 /* 0x1c */ "not all printed"
199};
200
201#define N_ERRORS (sizeof(SLMErrors)/sizeof(*SLMErrors))
202
203/* real (driver caused) error? */
204#define IS_REAL_ERROR(x) (x > 0x10)
205
206
207static struct {
208 char *name;
209 int w, h;
210} StdPageSize[] = {
211 { "Letter", 2400, 3180 },
212 { "Legal", 2400, 4080 },
213 { "A4", 2336, 3386 },
214 { "B5", 2016, 2914 }
215};
216
217#define N_STD_SIZES (sizeof(StdPageSize)/sizeof(*StdPageSize))
218
219#define SLM_BUFFER_SIZE (2336*3386/8) /* A4 for now */
220#define SLM_DMA_AMOUNT 255 /* #sectors to program the DMA for */
221
222#ifdef SLM_CONTINUOUS_DMA
223# define SLM_DMA_INT_OFFSET 0 /* DMA goes until seccnt 0, no offs */
224# define SLM_DMA_END_OFFSET 32 /* 32 Byte ST-DMA FIFO */
225# define SLM_SLICE_SIZE(w) (255*512)
226#else
227# define SLM_DMA_INT_OFFSET 32 /* 32 Byte ST-DMA FIFO */
228# define SLM_DMA_END_OFFSET 32 /* 32 Byte ST-DMA FIFO */
229# define SLM_SLICE_SIZE(w) ((254*512)/(w/8)*(w/8))
230#endif
231
232/* calculate the number of jiffies to wait for 'n' bytes */
233#ifdef SLM_CONT_CNT_REPROG
234#define DMA_TIME_FOR(n) 50
235#define DMA_STARTUP_TIME 0
236#else
237#define DMA_TIME_FOR(n) (n/1400-1)
238#define DMA_STARTUP_TIME 650
239#endif
240
241/***************************** Prototypes *****************************/
242
243static char *slm_errstr( int stat );
244static int slm_getstats( char *buffer, int device );
245static ssize_t slm_read( struct file* file, char *buf, size_t count, loff_t
246 *ppos );
247static void start_print( int device );
248static irqreturn_t slm_interrupt(int irc, void *data);
249static void slm_test_ready( unsigned long dummy );
250static void set_dma_addr( unsigned long paddr );
251static unsigned long get_dma_addr( void );
252static ssize_t slm_write( struct file *file, const char *buf, size_t count,
253 loff_t *ppos );
254static int slm_ioctl( struct inode *inode, struct file *file, unsigned int
255 cmd, unsigned long arg );
256static int slm_open( struct inode *inode, struct file *file );
257static int slm_release( struct inode *inode, struct file *file );
258static int slm_req_sense( int device );
259static int slm_mode_sense( int device, char *buffer, int abs_flag );
260#if 0
261static int slm_mode_select( int device, char *buffer, int len, int
262 default_flag );
263#endif
264static int slm_get_pagesize( int device, int *w, int *h );
265
266/************************* End of Prototypes **************************/
267
268
269static DEFINE_TIMER(slm_timer, slm_test_ready, 0, 0);
270
271static const struct file_operations slm_fops = {
272 .owner = THIS_MODULE,
273 .read = slm_read,
274 .write = slm_write,
275 .ioctl = slm_ioctl,
276 .open = slm_open,
277 .release = slm_release,
278};
279
280
281/* ---------------------------------------------------------------------- */
282/* Status Functions */
283
284
285static char *slm_errstr( int stat )
286
287{ char *p;
288 static char str[22];
289
290 stat &= 0x1f;
291 if (stat >= 0 && stat < N_ERRORS && (p = SLMErrors[stat]))
292 return( p );
293 sprintf( str, "unknown status 0x%02x", stat );
294 return( str );
295}
296
297
298static int slm_getstats( char *buffer, int device )
299
300{ int len = 0, stat, i, w, h;
301 unsigned char buf[256];
302
303 stat = slm_mode_sense( device, buf, 0 );
304 if (IS_REAL_ERROR(stat))
305 return( -EIO );
306
307#define SHORTDATA(i) ((buf[i] << 8) | buf[i+1])
308#define BOOLDATA(i,mask) ((buf[i] & mask) ? "on" : "off")
309
310 w = SHORTDATA( 3 );
311 h = SHORTDATA( 1 );
312
313 len += sprintf( buffer+len, "Status\t\t%s\n",
314 slm_errstr( stat ) );
315 len += sprintf( buffer+len, "Page Size\t%dx%d",
316 w, h );
317
318 for( i = 0; i < N_STD_SIZES; ++i ) {
319 if (w == StdPageSize[i].w && h == StdPageSize[i].h)
320 break;
321 }
322 if (i < N_STD_SIZES)
323 len += sprintf( buffer+len, " (%s)", StdPageSize[i].name );
324 buffer[len++] = '\n';
325
326 len += sprintf( buffer+len, "Top/Left Margin\t%d/%d\n",
327 SHORTDATA( 5 ), SHORTDATA( 7 ) );
328 len += sprintf( buffer+len, "Manual Feed\t%s\n",
329 BOOLDATA( 9, 0x01 ) );
330 len += sprintf( buffer+len, "Input Select\t%d\n",
331 (buf[9] >> 1) & 7 );
332 len += sprintf( buffer+len, "Auto Select\t%s\n",
333 BOOLDATA( 9, 0x10 ) );
334 len += sprintf( buffer+len, "Prefeed Paper\t%s\n",
335 BOOLDATA( 9, 0x20 ) );
336 len += sprintf( buffer+len, "Thick Pixels\t%s\n",
337 BOOLDATA( 9, 0x40 ) );
338 len += sprintf( buffer+len, "H/V Resol.\t%d/%d dpi\n",
339 SHORTDATA( 12 ), SHORTDATA( 10 ) );
340 len += sprintf( buffer+len, "System Timeout\t%d\n",
341 buf[14] );
342 len += sprintf( buffer+len, "Scan Time\t%d\n",
343 SHORTDATA( 15 ) );
344 len += sprintf( buffer+len, "Page Count\t%d\n",
345 SHORTDATA( 17 ) );
346 len += sprintf( buffer+len, "In/Out Cap.\t%d/%d\n",
347 SHORTDATA( 19 ), SHORTDATA( 21 ) );
348 len += sprintf( buffer+len, "Stagger Output\t%s\n",
349 BOOLDATA( 23, 0x01 ) );
350 len += sprintf( buffer+len, "Output Select\t%d\n",
351 (buf[23] >> 1) & 7 );
352 len += sprintf( buffer+len, "Duplex Print\t%s\n",
353 BOOLDATA( 23, 0x10 ) );
354 len += sprintf( buffer+len, "Color Sep.\t%s\n",
355 BOOLDATA( 23, 0x20 ) );
356
357 return( len );
358}
359
360
361static ssize_t slm_read( struct file *file, char *buf, size_t count,
362 loff_t *ppos )
363
364{
365 struct inode *node = file->f_path.dentry->d_inode;
366 unsigned long page;
367 int length;
368 int end;
369
370 if (!(page = __get_free_page( GFP_KERNEL )))
371 return( -ENOMEM );
372
373 length = slm_getstats( (char *)page, iminor(node) );
374 if (length < 0) {
375 count = length;
376 goto out;
377 }
378 if (file->f_pos >= length) {
379 count = 0;
380 goto out;
381 }
382 if (count + file->f_pos > length)
383 count = length - file->f_pos;
384 end = count + file->f_pos;
385 if (copy_to_user(buf, (char *)page + file->f_pos, count)) {
386 count = -EFAULT;
387 goto out;
388 }
389 file->f_pos = end;
390out: free_page( page );
391 return( count );
392}
393
394
395/* ---------------------------------------------------------------------- */
396/* Printing */
397
398
399static void start_print( int device )
400
401{ struct slm *sip = &slm_info[device];
402 unsigned char *cmd;
403 unsigned long paddr;
404 int i;
405
406 stdma_lock( slm_interrupt, NULL );
407
408 CMDSET_TARG_LUN( slmprint_cmd, sip->target, sip->lun );
409 cmd = slmprint_cmd;
410 paddr = virt_to_phys( SLMBuffer );
411 dma_cache_maintenance( paddr, virt_to_phys(BufferP)-paddr, 1 );
412 DISABLE_IRQ();
413
414 /* Low on A1 */
415 dma_wd.dma_mode_status = 0x88;
416 MFPDELAY();
417
418 /* send the command bytes except the last */
419 for( i = 0; i < 5; ++i ) {
420 DMA_LONG_WRITE( *cmd++, 0x8a );
421 udelay(20);
422 if (!acsi_wait_for_IRQ( HZ/2 )) {
423 SLMError = 1;
424 return; /* timeout */
425 }
426 }
427 /* last command byte */
428 DMA_LONG_WRITE( *cmd++, 0x82 );
429 MFPDELAY();
430 /* set DMA address */
431 set_dma_addr( paddr );
432 /* program DMA for write and select sector counter reg */
433 dma_wd.dma_mode_status = 0x192;
434 MFPDELAY();
435 /* program for 255*512 bytes and start DMA */
436 DMA_LONG_WRITE( SLM_DMA_AMOUNT, 0x112 );
437
438#ifndef SLM_CONT_CNT_REPROG
439 SLMCurAddr = paddr;
440 SLMEndAddr = paddr + SLMSliceSize + SLM_DMA_INT_OFFSET;
441#endif
442 START_TIMER( DMA_STARTUP_TIME + DMA_TIME_FOR( SLMSliceSize ));
443#if !defined(SLM_CONT_CNT_REPROG) && defined(DEBUG)
444 printk( "SLM: CurAddr=%#lx EndAddr=%#lx timer=%ld\n",
445 SLMCurAddr, SLMEndAddr, DMA_TIME_FOR( SLMSliceSize ) );
446#endif
447
448 ENABLE_IRQ();
449}
450
451
452/* Only called when an error happened or at the end of a page */
453
454static irqreturn_t slm_interrupt(int irc, void *data)
455
456{ unsigned long addr;
457 int stat;
458
459 STOP_TIMER();
460 addr = get_dma_addr();
461 stat = acsi_getstatus();
462 SLMError = (stat < 0) ? SLMSTAT_ACSITO :
463 (addr < virt_to_phys(BufferP)) ? SLMSTAT_NOTALL :
464 stat;
465
466 dma_wd.dma_mode_status = 0x80;
467 MFPDELAY();
468#ifdef DEBUG
469 printk( "SLM: interrupt, addr=%#lx, error=%d\n", addr, SLMError );
470#endif
471
472 wake_up( &print_wait );
473 stdma_release();
474 ENABLE_IRQ();
475 return IRQ_HANDLED;
476}
477
478
479static void slm_test_ready( unsigned long dummy )
480
481{
482#ifdef SLM_CONT_CNT_REPROG
483 /* program for 255*512 bytes again */
484 dma_wd.fdc_acces_seccount = SLM_DMA_AMOUNT;
485 START_TIMER( DMA_TIME_FOR(0) );
486#ifdef DEBUG
487 printk( "SLM: reprogramming timer for %d jiffies, addr=%#lx\n",
488 DMA_TIME_FOR(0), get_dma_addr() );
489#endif
490
491#else /* !SLM_CONT_CNT_REPROG */
492
493 unsigned long flags, addr;
494 int d, ti;
495#ifdef DEBUG
496 struct timeval start_tm, end_tm;
497 int did_wait = 0;
498#endif
499
500 local_irq_save(flags);
501
502 addr = get_dma_addr();
503 if ((d = SLMEndAddr - addr) > 0) {
504 local_irq_restore(flags);
505
506 /* slice not yet finished, decide whether to start another timer or to
507 * busy-wait */
508 ti = DMA_TIME_FOR( d );
509 if (ti > 0) {
510#ifdef DEBUG
511 printk( "SLM: reprogramming timer for %d jiffies, rest %d bytes\n",
512 ti, d );
513#endif
514 START_TIMER( ti );
515 return;
516 }
517 /* wait for desired end address to be reached */
518#ifdef DEBUG
519 do_gettimeofday( &start_tm );
520 did_wait = 1;
521#endif
522 local_irq_disable();
523 while( get_dma_addr() < SLMEndAddr )
524 barrier();
525 }
526
527 /* slice finished, start next one */
528 SLMCurAddr += SLMSliceSize;
529
530#ifdef SLM_CONTINUOUS_DMA
531 /* program for 255*512 bytes again */
532 dma_wd.fdc_acces_seccount = SLM_DMA_AMOUNT;
533#else
534 /* set DMA address;
535 * add 2 bytes for the ones in the SLM controller FIFO! */
536 set_dma_addr( SLMCurAddr + 2 );
537 /* toggle DMA to write and select sector counter reg */
538 dma_wd.dma_mode_status = 0x92;
539 MFPDELAY();
540 dma_wd.dma_mode_status = 0x192;
541 MFPDELAY();
542 /* program for 255*512 bytes and start DMA */
543 DMA_LONG_WRITE( SLM_DMA_AMOUNT, 0x112 );
544#endif
545
546 local_irq_restore(flags);
547
548#ifdef DEBUG
549 if (did_wait) {
550 int ms;
551 do_gettimeofday( &end_tm );
552 ms = (end_tm.tv_sec*1000000+end_tm.tv_usec) -
553 (start_tm.tv_sec*1000000+start_tm.tv_usec);
554 printk( "SLM: did %ld.%ld ms busy waiting for %d bytes\n",
555 ms/1000, ms%1000, d );
556 }
557 else
558 printk( "SLM: didn't wait (!)\n" );
559#endif
560
561 if ((unsigned char *)PTOV( SLMCurAddr + SLMSliceSize ) >= BufferP) {
562 /* will be last slice, no timer necessary */
563#ifdef DEBUG
564 printk( "SLM: CurAddr=%#lx EndAddr=%#lx last slice -> no timer\n",
565 SLMCurAddr, SLMEndAddr );
566#endif
567 }
568 else {
569 /* not last slice */
570 SLMEndAddr = SLMCurAddr + SLMSliceSize + SLM_DMA_INT_OFFSET;
571 START_TIMER( DMA_TIME_FOR( SLMSliceSize ));
572#ifdef DEBUG
573 printk( "SLM: CurAddr=%#lx EndAddr=%#lx timer=%ld\n",
574 SLMCurAddr, SLMEndAddr, DMA_TIME_FOR( SLMSliceSize ) );
575#endif
576 }
577#endif /* SLM_CONT_CNT_REPROG */
578}
579
580
581static void set_dma_addr( unsigned long paddr )
582
583{ unsigned long flags;
584
585 local_irq_save(flags);
586 dma_wd.dma_lo = (unsigned char)paddr;
587 paddr >>= 8;
588 MFPDELAY();
589 dma_wd.dma_md = (unsigned char)paddr;
590 paddr >>= 8;
591 MFPDELAY();
592 if (ATARIHW_PRESENT( EXTD_DMA ))
593 st_dma_ext_dmahi = (unsigned short)paddr;
594 else
595 dma_wd.dma_hi = (unsigned char)paddr;
596 MFPDELAY();
597 local_irq_restore(flags);
598}
599
600
601static unsigned long get_dma_addr( void )
602
603{ unsigned long addr;
604
605 addr = dma_wd.dma_lo & 0xff;
606 MFPDELAY();
607 addr |= (dma_wd.dma_md & 0xff) << 8;
608 MFPDELAY();
609 addr |= (dma_wd.dma_hi & 0xff) << 16;
610 MFPDELAY();
611
612 return( addr );
613}
614
615
616static ssize_t slm_write( struct file *file, const char *buf, size_t count,
617 loff_t *ppos )
618
619{
620 struct inode *node = file->f_path.dentry->d_inode;
621 int device = iminor(node);
622 int n, filled, w, h;
623
624 while( SLMState == PRINTING ||
625 (SLMState == FILLING && SLMBufOwner != device) ) {
626 interruptible_sleep_on( &slm_wait );
627 if (signal_pending(current))
628 return( -ERESTARTSYS );
629 }
630 if (SLMState == IDLE) {
631 /* first data of page: get current page size */
632 if (slm_get_pagesize( device, &w, &h ))
633 return( -EIO );
634 BufferSize = w*h/8;
635 if (BufferSize > SLM_BUFFER_SIZE)
636 return( -ENOMEM );
637
638 SLMState = FILLING;
639 SLMBufOwner = device;
640 }
641
642 n = count;
643 filled = BufferP - SLMBuffer;
644 if (filled + n > BufferSize)
645 n = BufferSize - filled;
646
647 if (copy_from_user(BufferP, buf, n))
648 return -EFAULT;
649 BufferP += n;
650 filled += n;
651
652 if (filled == BufferSize) {
653 /* Check the paper size again! The user may have switched it in the
654 * time between starting the data and finishing them. Would end up in
655 * a trashy page... */
656 if (slm_get_pagesize( device, &w, &h ))
657 return( -EIO );
658 if (BufferSize != w*h/8) {
659 printk( KERN_NOTICE "slm%d: page size changed while printing\n",
660 device );
661 return( -EAGAIN );
662 }
663
664 SLMState = PRINTING;
665 /* choose a slice size that is a multiple of the line size */
666#ifndef SLM_CONT_CNT_REPROG
667 SLMSliceSize = SLM_SLICE_SIZE(w);
668#endif
669
670 start_print( device );
671 sleep_on( &print_wait );
672 if (SLMError && IS_REAL_ERROR(SLMError)) {
673 printk( KERN_ERR "slm%d: %s\n", device, slm_errstr(SLMError) );
674 n = -EIO;
675 }
676
677 SLMState = IDLE;
678 BufferP = SLMBuffer;
679 wake_up_interruptible( &slm_wait );
680 }
681
682 return( n );
683}
684
685
686/* ---------------------------------------------------------------------- */
687/* ioctl Functions */
688
689
690static int slm_ioctl( struct inode *inode, struct file *file,
691 unsigned int cmd, unsigned long arg )
692
693{ int device = iminor(inode), err;
694
695 /* I can think of setting:
696 * - manual feed
697 * - paper format
698 * - copy count
699 * - ...
700 * but haven't implemented that yet :-)
701 * BTW, has anybody better docs about the MODE SENSE/MODE SELECT data?
702 */
703 switch( cmd ) {
704
705 case SLMIORESET: /* reset buffer, i.e. empty the buffer */
706 if (!(file->f_mode & 2))
707 return( -EINVAL );
708 if (SLMState == PRINTING)
709 return( -EBUSY );
710 SLMState = IDLE;
711 BufferP = SLMBuffer;
712 wake_up_interruptible( &slm_wait );
713 return( 0 );
714
715 case SLMIOGSTAT: { /* get status */
716 int stat;
717 char *str;
718
719 stat = slm_req_sense( device );
720 if (arg) {
721 str = slm_errstr( stat );
722 if (put_user(stat,
723 (long *)&((struct SLM_status *)arg)->stat))
724 return -EFAULT;
725 if (copy_to_user( ((struct SLM_status *)arg)->str, str,
726 strlen(str) + 1))
727 return -EFAULT;
728 }
729 return( stat );
730 }
731
732 case SLMIOGPSIZE: { /* get paper size */
733 int w, h;
734
735 if ((err = slm_get_pagesize( device, &w, &h ))) return( err );
736
737 if (put_user(w, (long *)&((struct SLM_paper_size *)arg)->width))
738 return -EFAULT;
739 if (put_user(h, (long *)&((struct SLM_paper_size *)arg)->height))
740 return -EFAULT;
741 return( 0 );
742 }
743
744 case SLMIOGMFEED: /* get manual feed */
745 return( -EINVAL );
746
747 case SLMIOSPSIZE: /* set paper size */
748 return( -EINVAL );
749
750 case SLMIOSMFEED: /* set manual feed */
751 return( -EINVAL );
752
753 }
754 return( -EINVAL );
755}
756
757
758/* ---------------------------------------------------------------------- */
759/* Opening and Closing */
760
761
762static int slm_open( struct inode *inode, struct file *file )
763
764{ int device;
765 struct slm *sip;
766
767 device = iminor(inode);
768 if (device >= N_SLM_Printers)
769 return( -ENXIO );
770 sip = &slm_info[device];
771
772 if (file->f_mode & 2) {
773 /* open for writing is exclusive */
774 if ( !atomic_dec_and_test(&sip->wr_ok) ) {
775 atomic_inc(&sip->wr_ok);
776 return( -EBUSY );
777 }
778 }
779 if (file->f_mode & 1) {
780 /* open for reading is exclusive */
781 if ( !atomic_dec_and_test(&sip->rd_ok) ) {
782 atomic_inc(&sip->rd_ok);
783 return( -EBUSY );
784 }
785 }
786
787 return( 0 );
788}
789
790
791static int slm_release( struct inode *inode, struct file *file )
792
793{ int device;
794 struct slm *sip;
795
796 device = iminor(inode);
797 sip = &slm_info[device];
798
799 if (file->f_mode & 2)
800 atomic_inc( &sip->wr_ok );
801 if (file->f_mode & 1)
802 atomic_inc( &sip->rd_ok );
803
804 return( 0 );
805}
806
807
808/* ---------------------------------------------------------------------- */
809/* ACSI Primitives for the SLM */
810
811
812static int slm_req_sense( int device )
813
814{ int stat, rv;
815 struct slm *sip = &slm_info[device];
816
817 stdma_lock( NULL, NULL );
818
819 CMDSET_TARG_LUN( slmreqsense_cmd, sip->target, sip->lun );
820 if (!acsicmd_nodma( slmreqsense_cmd, 0 ) ||
821 (stat = acsi_getstatus()) < 0)
822 rv = SLMSTAT_ACSITO;
823 else
824 rv = stat & 0x1f;
825
826 ENABLE_IRQ();
827 stdma_release();
828 return( rv );
829}
830
831
832static int slm_mode_sense( int device, char *buffer, int abs_flag )
833
834{ unsigned char stat, len;
835 int rv = 0;
836 struct slm *sip = &slm_info[device];
837
838 stdma_lock( NULL, NULL );
839
840 CMDSET_TARG_LUN( slmmsense_cmd, sip->target, sip->lun );
841 slmmsense_cmd[5] = abs_flag ? 0x80 : 0;
842 if (!acsicmd_nodma( slmmsense_cmd, 0 )) {
843 rv = SLMSTAT_ACSITO;
844 goto the_end;
845 }
846
847 if (!acsi_extstatus( &stat, 1 )) {
848 acsi_end_extstatus();
849 rv = SLMSTAT_ACSITO;
850 goto the_end;
851 }
852
853 if (!acsi_extstatus( &len, 1 )) {
854 acsi_end_extstatus();
855 rv = SLMSTAT_ACSITO;
856 goto the_end;
857 }
858 buffer[0] = len;
859 if (!acsi_extstatus( buffer+1, len )) {
860 acsi_end_extstatus();
861 rv = SLMSTAT_ACSITO;
862 goto the_end;
863 }
864
865 acsi_end_extstatus();
866 rv = stat & 0x1f;
867
868 the_end:
869 ENABLE_IRQ();
870 stdma_release();
871 return( rv );
872}
873
874
875#if 0
876/* currently unused */
877static int slm_mode_select( int device, char *buffer, int len,
878 int default_flag )
879
880{ int stat, rv;
881 struct slm *sip = &slm_info[device];
882
883 stdma_lock( NULL, NULL );
884
885 CMDSET_TARG_LUN( slmmselect_cmd, sip->target, sip->lun );
886 slmmselect_cmd[5] = default_flag ? 0x80 : 0;
887 if (!acsicmd_nodma( slmmselect_cmd, 0 )) {
888 rv = SLMSTAT_ACSITO;
889 goto the_end;
890 }
891
892 if (!default_flag) {
893 unsigned char c = len;
894 if (!acsi_extcmd( &c, 1 )) {
895 rv = SLMSTAT_ACSITO;
896 goto the_end;
897 }
898 if (!acsi_extcmd( buffer, len )) {
899 rv = SLMSTAT_ACSITO;
900 goto the_end;
901 }
902 }
903
904 stat = acsi_getstatus();
905 rv = (stat < 0 ? SLMSTAT_ACSITO : stat);
906
907 the_end:
908 ENABLE_IRQ();
909 stdma_release();
910 return( rv );
911}
912#endif
913
914
915static int slm_get_pagesize( int device, int *w, int *h )
916
917{ char buf[256];
918 int stat;
919
920 stat = slm_mode_sense( device, buf, 0 );
921 ENABLE_IRQ();
922 stdma_release();
923
924 if (stat != SLMSTAT_OK)
925 return( -EIO );
926
927 *w = (buf[3] << 8) | buf[4];
928 *h = (buf[1] << 8) | buf[2];
929 return( 0 );
930}
931
932
933/* ---------------------------------------------------------------------- */
934/* Initialization */
935
936
937int attach_slm( int target, int lun )
938
939{ static int did_register;
940 int len;
941
942 if (N_SLM_Printers >= MAX_SLM) {
943 printk( KERN_WARNING "Too much SLMs\n" );
944 return( 0 );
945 }
946
947 /* do an INQUIRY */
948 udelay(100);
949 CMDSET_TARG_LUN( slminquiry_cmd, target, lun );
950 if (!acsicmd_nodma( slminquiry_cmd, 0 )) {
951 inq_timeout:
952 printk( KERN_ERR "SLM inquiry command timed out.\n" );
953 inq_fail:
954 acsi_end_extstatus();
955 return( 0 );
956 }
957 /* read status and header of return data */
958 if (!acsi_extstatus( SLMBuffer, 6 ))
959 goto inq_timeout;
960
961 if (SLMBuffer[1] != 2) { /* device type == printer? */
962 printk( KERN_ERR "SLM inquiry returned device type != printer\n" );
963 goto inq_fail;
964 }
965 len = SLMBuffer[5];
966
967 /* read id string */
968 if (!acsi_extstatus( SLMBuffer, len ))
969 goto inq_timeout;
970 acsi_end_extstatus();
971 SLMBuffer[len] = 0;
972
973 if (!did_register) {
974 did_register = 1;
975 }
976
977 slm_info[N_SLM_Printers].target = target;
978 slm_info[N_SLM_Printers].lun = lun;
979 atomic_set(&slm_info[N_SLM_Printers].wr_ok, 1 );
980 atomic_set(&slm_info[N_SLM_Printers].rd_ok, 1 );
981
982 printk( KERN_INFO " Printer: %s\n", SLMBuffer );
983 printk( KERN_INFO "Detected slm%d at id %d lun %d\n",
984 N_SLM_Printers, target, lun );
985 N_SLM_Printers++;
986 return( 1 );
987}
988
989int slm_init( void )
990
991{
992 int i;
993 if (register_chrdev( ACSI_MAJOR, "slm", &slm_fops )) {
994 printk( KERN_ERR "Unable to get major %d for ACSI SLM\n", ACSI_MAJOR );
995 return -EBUSY;
996 }
997
998 if (!(SLMBuffer = atari_stram_alloc( SLM_BUFFER_SIZE, "SLM" ))) {
999 printk( KERN_ERR "Unable to get SLM ST-Ram buffer.\n" );
1000 unregister_chrdev( ACSI_MAJOR, "slm" );
1001 return -ENOMEM;
1002 }
1003 BufferP = SLMBuffer;
1004 SLMState = IDLE;
1005
1006 return 0;
1007}
1008
1009#ifdef MODULE
1010
1011/* from acsi.c */
1012void acsi_attach_SLMs( int (*attach_func)( int, int ) );
1013
1014int init_module(void)
1015{
1016 int err;
1017
1018 if ((err = slm_init()))
1019 return( err );
1020 /* This calls attach_slm() for every target/lun where acsi.c detected a
1021 * printer */
1022 acsi_attach_SLMs( attach_slm );
1023 return( 0 );
1024}
1025
1026void cleanup_module(void)
1027{
1028 if (unregister_chrdev( ACSI_MAJOR, "slm" ) != 0)
1029 printk( KERN_ERR "acsi_slm: cleanup_module failed\n");
1030 atari_stram_free( SLMBuffer );
1031}
1032#endif
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 0fcad430474e..a2d6612b80d2 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1170,7 +1170,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
1170 case SG_EMULATED_HOST: 1170 case SG_EMULATED_HOST:
1171 case SG_IO: 1171 case SG_IO:
1172 case SCSI_IOCTL_SEND_COMMAND: 1172 case SCSI_IOCTL_SEND_COMMAND:
1173 return scsi_cmd_ioctl(filep, disk, cmd, argp); 1173 return scsi_cmd_ioctl(filep, disk->queue, disk, cmd, argp);
1174 1174
1175 /* scsi_cmd_ioctl would normally handle these, below, but */ 1175 /* scsi_cmd_ioctl would normally handle these, below, but */
1176 /* they aren't a good fit for cciss, as CD-ROMs are */ 1176 /* they aren't a good fit for cciss, as CD-ROMs are */
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 90961a8ea895..4aca7ddfdddf 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -555,7 +555,6 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
555{ 555{
556 struct scsi_cmnd *cmd; 556 struct scsi_cmnd *cmd;
557 ctlr_info_t *ctlr; 557 ctlr_info_t *ctlr;
558 u64bit addr64;
559 ErrorInfo_struct *ei; 558 ErrorInfo_struct *ei;
560 559
561 ei = cp->err_info; 560 ei = cp->err_info;
@@ -569,20 +568,7 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
569 cmd = (struct scsi_cmnd *) cp->scsi_cmd; 568 cmd = (struct scsi_cmnd *) cp->scsi_cmd;
570 ctlr = hba[cp->ctlr]; 569 ctlr = hba[cp->ctlr];
571 570
572 /* undo the DMA mappings */ 571 scsi_dma_unmap(cmd);
573
574 if (cmd->use_sg) {
575 pci_unmap_sg(ctlr->pdev,
576 cmd->request_buffer, cmd->use_sg,
577 cmd->sc_data_direction);
578 }
579 else if (cmd->request_bufflen) {
580 addr64.val32.lower = cp->SG[0].Addr.lower;
581 addr64.val32.upper = cp->SG[0].Addr.upper;
582 pci_unmap_single(ctlr->pdev, (dma_addr_t) addr64.val,
583 cmd->request_bufflen,
584 cmd->sc_data_direction);
585 }
586 572
587 cmd->result = (DID_OK << 16); /* host byte */ 573 cmd->result = (DID_OK << 16); /* host byte */
588 cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */ 574 cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */
@@ -597,7 +583,7 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
597 ei->SenseLen > SCSI_SENSE_BUFFERSIZE ? 583 ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
598 SCSI_SENSE_BUFFERSIZE : 584 SCSI_SENSE_BUFFERSIZE :
599 ei->SenseLen); 585 ei->SenseLen);
600 cmd->resid = ei->ResidualCnt; 586 scsi_set_resid(cmd, ei->ResidualCnt);
601 587
602 if(ei->CommandStatus != 0) 588 if(ei->CommandStatus != 0)
603 { /* an error has occurred */ 589 { /* an error has occurred */
@@ -1204,46 +1190,29 @@ cciss_scatter_gather(struct pci_dev *pdev,
1204 CommandList_struct *cp, 1190 CommandList_struct *cp,
1205 struct scsi_cmnd *cmd) 1191 struct scsi_cmnd *cmd)
1206{ 1192{
1207 unsigned int use_sg, nsegs=0, len; 1193 unsigned int len;
1208 struct scatterlist *scatter = (struct scatterlist *) cmd->request_buffer; 1194 struct scatterlist *sg;
1209 __u64 addr64; 1195 __u64 addr64;
1210 1196 int use_sg, i;
1211 /* is it just one virtual address? */ 1197
1212 if (!cmd->use_sg) { 1198 BUG_ON(scsi_sg_count(cmd) > MAXSGENTRIES);
1213 if (cmd->request_bufflen) { /* anything to xfer? */ 1199
1214 1200 use_sg = scsi_dma_map(cmd);
1215 addr64 = (__u64) pci_map_single(pdev, 1201 if (use_sg) { /* not too many addrs? */
1216 cmd->request_buffer, 1202 scsi_for_each_sg(cmd, sg, use_sg, i) {
1217 cmd->request_bufflen, 1203 addr64 = (__u64) sg_dma_address(sg);
1218 cmd->sc_data_direction); 1204 len = sg_dma_len(sg);
1219 1205 cp->SG[i].Addr.lower =
1220 cp->SG[0].Addr.lower = 1206 (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
1221 (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF); 1207 cp->SG[i].Addr.upper =
1222 cp->SG[0].Addr.upper = 1208 (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
1223 (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF); 1209 cp->SG[i].Len = len;
1224 cp->SG[0].Len = cmd->request_bufflen; 1210 cp->SG[i].Ext = 0; // we are not chaining
1225 nsegs=1;
1226 }
1227 } /* else, must be a list of virtual addresses.... */
1228 else if (cmd->use_sg <= MAXSGENTRIES) { /* not too many addrs? */
1229
1230 use_sg = pci_map_sg(pdev, cmd->request_buffer, cmd->use_sg,
1231 cmd->sc_data_direction);
1232
1233 for (nsegs=0; nsegs < use_sg; nsegs++) {
1234 addr64 = (__u64) sg_dma_address(&scatter[nsegs]);
1235 len = sg_dma_len(&scatter[nsegs]);
1236 cp->SG[nsegs].Addr.lower =
1237 (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
1238 cp->SG[nsegs].Addr.upper =
1239 (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
1240 cp->SG[nsegs].Len = len;
1241 cp->SG[nsegs].Ext = 0; // we are not chaining
1242 } 1211 }
1243 } else BUG(); 1212 }
1244 1213
1245 cp->Header.SGList = (__u8) nsegs; /* no. SGs contig in this cmd */ 1214 cp->Header.SGList = (__u8) use_sg; /* no. SGs contig in this cmd */
1246 cp->Header.SGTotal = (__u16) nsegs; /* total sgs in this cmd list */ 1215 cp->Header.SGTotal = (__u16) use_sg; /* total sgs in this cmd list */
1247 return; 1216 return;
1248} 1217}
1249 1218
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index c575fb1d585f..c12951024090 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -122,17 +122,12 @@ static int sock_xmit(struct socket *sock, int send, void *buf, int size,
122 int result; 122 int result;
123 struct msghdr msg; 123 struct msghdr msg;
124 struct kvec iov; 124 struct kvec iov;
125 unsigned long flags; 125 sigset_t blocked, oldset;
126 sigset_t oldset;
127 126
128 /* Allow interception of SIGKILL only 127 /* Allow interception of SIGKILL only
129 * Don't allow other signals to interrupt the transmission */ 128 * Don't allow other signals to interrupt the transmission */
130 spin_lock_irqsave(&current->sighand->siglock, flags); 129 siginitsetinv(&blocked, sigmask(SIGKILL));
131 oldset = current->blocked; 130 sigprocmask(SIG_SETMASK, &blocked, &oldset);
132 sigfillset(&current->blocked);
133 sigdelsetmask(&current->blocked, sigmask(SIGKILL));
134 recalc_sigpending();
135 spin_unlock_irqrestore(&current->sighand->siglock, flags);
136 131
137 do { 132 do {
138 sock->sk->sk_allocation = GFP_NOIO; 133 sock->sk->sk_allocation = GFP_NOIO;
@@ -151,11 +146,9 @@ static int sock_xmit(struct socket *sock, int send, void *buf, int size,
151 146
152 if (signal_pending(current)) { 147 if (signal_pending(current)) {
153 siginfo_t info; 148 siginfo_t info;
154 spin_lock_irqsave(&current->sighand->siglock, flags);
155 printk(KERN_WARNING "nbd (pid %d: %s) got signal %d\n", 149 printk(KERN_WARNING "nbd (pid %d: %s) got signal %d\n",
156 current->pid, current->comm, 150 current->pid, current->comm,
157 dequeue_signal(current, &current->blocked, &info)); 151 dequeue_signal_lock(current, &current->blocked, &info));
158 spin_unlock_irqrestore(&current->sighand->siglock, flags);
159 result = -EINTR; 152 result = -EINTR;
160 break; 153 break;
161 } 154 }
@@ -169,10 +162,7 @@ static int sock_xmit(struct socket *sock, int send, void *buf, int size,
169 buf += result; 162 buf += result;
170 } while (size > 0); 163 } while (size > 0);
171 164
172 spin_lock_irqsave(&current->sighand->siglock, flags); 165 sigprocmask(SIG_SETMASK, &oldset, NULL);
173 current->blocked = oldset;
174 recalc_sigpending();
175 spin_unlock_irqrestore(&current->sighand->siglock, flags);
176 166
177 return result; 167 return result;
178} 168}
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index f1b9dd7d47d6..7c294a40002e 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -146,8 +146,7 @@ static void pkt_kobj_release(struct kobject *kobj)
146 **********************************************************/ 146 **********************************************************/
147 147
148#define DEF_ATTR(_obj,_name,_mode) \ 148#define DEF_ATTR(_obj,_name,_mode) \
149 static struct attribute _obj = { \ 149 static struct attribute _obj = { .name = _name, .mode = _mode }
150 .name = _name, .owner = THIS_MODULE, .mode = _mode }
151 150
152/********************************************************** 151/**********************************************************
153 /sys/class/pktcdvd/pktcdvd[0-7]/ 152 /sys/class/pktcdvd/pktcdvd[0-7]/
@@ -1653,9 +1652,6 @@ static int kcdrwd(void *foobar)
1653 } 1652 }
1654 } 1653 }
1655 1654
1656 if (signal_pending(current)) {
1657 flush_signals(current);
1658 }
1659 if (kthread_should_stop()) 1655 if (kthread_should_stop())
1660 break; 1656 break;
1661 } 1657 }
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
new file mode 100644
index 000000000000..0f5e3caf85d7
--- /dev/null
+++ b/drivers/block/sunvdc.c
@@ -0,0 +1,972 @@
1/* sunvdc.c: Sun LDOM Virtual Disk Client.
2 *
3 * Copyright (C) 2007 David S. Miller <davem@davemloft.net>
4 */
5
6#include <linux/module.h>
7#include <linux/kernel.h>
8#include <linux/types.h>
9#include <linux/blkdev.h>
10#include <linux/hdreg.h>
11#include <linux/genhd.h>
12#include <linux/slab.h>
13#include <linux/spinlock.h>
14#include <linux/completion.h>
15#include <linux/delay.h>
16#include <linux/init.h>
17#include <linux/list.h>
18
19#include <asm/vio.h>
20#include <asm/ldc.h>
21
22#define DRV_MODULE_NAME "sunvdc"
23#define PFX DRV_MODULE_NAME ": "
24#define DRV_MODULE_VERSION "1.0"
25#define DRV_MODULE_RELDATE "June 25, 2007"
26
27static char version[] __devinitdata =
28 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
29MODULE_AUTHOR("David S. Miller (davem@davemloft.net)");
30MODULE_DESCRIPTION("Sun LDOM virtual disk client driver");
31MODULE_LICENSE("GPL");
32MODULE_VERSION(DRV_MODULE_VERSION);
33
34#define VDC_TX_RING_SIZE 256
35
36#define WAITING_FOR_LINK_UP 0x01
37#define WAITING_FOR_TX_SPACE 0x02
38#define WAITING_FOR_GEN_CMD 0x04
39#define WAITING_FOR_ANY -1
40
41struct vdc_req_entry {
42 struct request *req;
43};
44
45struct vdc_port {
46 struct vio_driver_state vio;
47
48 struct vdc *vp;
49
50 struct gendisk *disk;
51
52 struct vdc_completion *cmp;
53
54 u64 req_id;
55 u64 seq;
56 struct vdc_req_entry rq_arr[VDC_TX_RING_SIZE];
57
58 unsigned long ring_cookies;
59
60 u64 max_xfer_size;
61 u32 vdisk_block_size;
62
63 /* The server fills these in for us in the disk attribute
64 * ACK packet.
65 */
66 u64 operations;
67 u32 vdisk_size;
68 u8 vdisk_type;
69 u8 dev_no;
70
71 char disk_name[32];
72
73 struct vio_disk_geom geom;
74 struct vio_disk_vtoc label;
75
76 struct list_head list;
77};
78
79static inline struct vdc_port *to_vdc_port(struct vio_driver_state *vio)
80{
81 return container_of(vio, struct vdc_port, vio);
82}
83
84struct vdc {
85 /* Protects prot_list. */
86 spinlock_t lock;
87
88 struct vio_dev *dev;
89
90 struct list_head port_list;
91};
92
93/* Ordered from largest major to lowest */
94static struct vio_version vdc_versions[] = {
95 { .major = 1, .minor = 0 },
96};
97
98#define VDCBLK_NAME "vdisk"
99static int vdc_major;
100#define PARTITION_SHIFT 3
101
102static inline u32 vdc_tx_dring_avail(struct vio_dring_state *dr)
103{
104 return vio_dring_avail(dr, VDC_TX_RING_SIZE);
105}
106
107static int vdc_getgeo(struct block_device *bdev, struct hd_geometry *geo)
108{
109 struct gendisk *disk = bdev->bd_disk;
110 struct vdc_port *port = disk->private_data;
111
112 geo->heads = (u8) port->geom.num_hd;
113 geo->sectors = (u8) port->geom.num_sec;
114 geo->cylinders = port->geom.num_cyl;
115
116 return 0;
117}
118
119static struct block_device_operations vdc_fops = {
120 .owner = THIS_MODULE,
121 .getgeo = vdc_getgeo,
122};
123
124static void vdc_finish(struct vio_driver_state *vio, int err, int waiting_for)
125{
126 if (vio->cmp &&
127 (waiting_for == -1 ||
128 vio->cmp->waiting_for == waiting_for)) {
129 vio->cmp->err = err;
130 complete(&vio->cmp->com);
131 vio->cmp = NULL;
132 }
133}
134
135static void vdc_handshake_complete(struct vio_driver_state *vio)
136{
137 vdc_finish(vio, 0, WAITING_FOR_LINK_UP);
138}
139
140static int vdc_handle_unknown(struct vdc_port *port, void *arg)
141{
142 struct vio_msg_tag *pkt = arg;
143
144 printk(KERN_ERR PFX "Received unknown msg [%02x:%02x:%04x:%08x]\n",
145 pkt->type, pkt->stype, pkt->stype_env, pkt->sid);
146 printk(KERN_ERR PFX "Resetting connection.\n");
147
148 ldc_disconnect(port->vio.lp);
149
150 return -ECONNRESET;
151}
152
153static int vdc_send_attr(struct vio_driver_state *vio)
154{
155 struct vdc_port *port = to_vdc_port(vio);
156 struct vio_disk_attr_info pkt;
157
158 memset(&pkt, 0, sizeof(pkt));
159
160 pkt.tag.type = VIO_TYPE_CTRL;
161 pkt.tag.stype = VIO_SUBTYPE_INFO;
162 pkt.tag.stype_env = VIO_ATTR_INFO;
163 pkt.tag.sid = vio_send_sid(vio);
164
165 pkt.xfer_mode = VIO_DRING_MODE;
166 pkt.vdisk_block_size = port->vdisk_block_size;
167 pkt.max_xfer_size = port->max_xfer_size;
168
169 viodbg(HS, "SEND ATTR xfer_mode[0x%x] blksz[%u] max_xfer[%lu]\n",
170 pkt.xfer_mode, pkt.vdisk_block_size, pkt.max_xfer_size);
171
172 return vio_ldc_send(&port->vio, &pkt, sizeof(pkt));
173}
174
175static int vdc_handle_attr(struct vio_driver_state *vio, void *arg)
176{
177 struct vdc_port *port = to_vdc_port(vio);
178 struct vio_disk_attr_info *pkt = arg;
179
180 viodbg(HS, "GOT ATTR stype[0x%x] ops[%lx] disk_size[%lu] disk_type[%x] "
181 "xfer_mode[0x%x] blksz[%u] max_xfer[%lu]\n",
182 pkt->tag.stype, pkt->operations,
183 pkt->vdisk_size, pkt->vdisk_type,
184 pkt->xfer_mode, pkt->vdisk_block_size,
185 pkt->max_xfer_size);
186
187 if (pkt->tag.stype == VIO_SUBTYPE_ACK) {
188 switch (pkt->vdisk_type) {
189 case VD_DISK_TYPE_DISK:
190 case VD_DISK_TYPE_SLICE:
191 break;
192
193 default:
194 printk(KERN_ERR PFX "%s: Bogus vdisk_type 0x%x\n",
195 vio->name, pkt->vdisk_type);
196 return -ECONNRESET;
197 }
198
199 if (pkt->vdisk_block_size > port->vdisk_block_size) {
200 printk(KERN_ERR PFX "%s: BLOCK size increased "
201 "%u --> %u\n",
202 vio->name,
203 port->vdisk_block_size, pkt->vdisk_block_size);
204 return -ECONNRESET;
205 }
206
207 port->operations = pkt->operations;
208 port->vdisk_size = pkt->vdisk_size;
209 port->vdisk_type = pkt->vdisk_type;
210 if (pkt->max_xfer_size < port->max_xfer_size)
211 port->max_xfer_size = pkt->max_xfer_size;
212 port->vdisk_block_size = pkt->vdisk_block_size;
213 return 0;
214 } else {
215 printk(KERN_ERR PFX "%s: Attribute NACK\n", vio->name);
216
217 return -ECONNRESET;
218 }
219}
220
221static void vdc_end_special(struct vdc_port *port, struct vio_disk_desc *desc)
222{
223 int err = desc->status;
224
225 vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD);
226}
227
228static void vdc_end_request(struct request *req, int uptodate, int num_sectors)
229{
230 if (end_that_request_first(req, uptodate, num_sectors))
231 return;
232 add_disk_randomness(req->rq_disk);
233 end_that_request_last(req, uptodate);
234}
235
236static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
237 unsigned int index)
238{
239 struct vio_disk_desc *desc = vio_dring_entry(dr, index);
240 struct vdc_req_entry *rqe = &port->rq_arr[index];
241 struct request *req;
242
243 if (unlikely(desc->hdr.state != VIO_DESC_DONE))
244 return;
245
246 ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies);
247 desc->hdr.state = VIO_DESC_FREE;
248 dr->cons = (index + 1) & (VDC_TX_RING_SIZE - 1);
249
250 req = rqe->req;
251 if (req == NULL) {
252 vdc_end_special(port, desc);
253 return;
254 }
255
256 rqe->req = NULL;
257
258 vdc_end_request(req, !desc->status, desc->size >> 9);
259
260 if (blk_queue_stopped(port->disk->queue))
261 blk_start_queue(port->disk->queue);
262}
263
264static int vdc_ack(struct vdc_port *port, void *msgbuf)
265{
266 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
267 struct vio_dring_data *pkt = msgbuf;
268
269 if (unlikely(pkt->dring_ident != dr->ident ||
270 pkt->start_idx != pkt->end_idx ||
271 pkt->start_idx >= VDC_TX_RING_SIZE))
272 return 0;
273
274 vdc_end_one(port, dr, pkt->start_idx);
275
276 return 0;
277}
278
279static int vdc_nack(struct vdc_port *port, void *msgbuf)
280{
281 /* XXX Implement me XXX */
282 return 0;
283}
284
285static void vdc_event(void *arg, int event)
286{
287 struct vdc_port *port = arg;
288 struct vio_driver_state *vio = &port->vio;
289 unsigned long flags;
290 int err;
291
292 spin_lock_irqsave(&vio->lock, flags);
293
294 if (unlikely(event == LDC_EVENT_RESET ||
295 event == LDC_EVENT_UP)) {
296 vio_link_state_change(vio, event);
297 spin_unlock_irqrestore(&vio->lock, flags);
298 return;
299 }
300
301 if (unlikely(event != LDC_EVENT_DATA_READY)) {
302 printk(KERN_WARNING PFX "Unexpected LDC event %d\n", event);
303 spin_unlock_irqrestore(&vio->lock, flags);
304 return;
305 }
306
307 err = 0;
308 while (1) {
309 union {
310 struct vio_msg_tag tag;
311 u64 raw[8];
312 } msgbuf;
313
314 err = ldc_read(vio->lp, &msgbuf, sizeof(msgbuf));
315 if (unlikely(err < 0)) {
316 if (err == -ECONNRESET)
317 vio_conn_reset(vio);
318 break;
319 }
320 if (err == 0)
321 break;
322 viodbg(DATA, "TAG [%02x:%02x:%04x:%08x]\n",
323 msgbuf.tag.type,
324 msgbuf.tag.stype,
325 msgbuf.tag.stype_env,
326 msgbuf.tag.sid);
327 err = vio_validate_sid(vio, &msgbuf.tag);
328 if (err < 0)
329 break;
330
331 if (likely(msgbuf.tag.type == VIO_TYPE_DATA)) {
332 if (msgbuf.tag.stype == VIO_SUBTYPE_ACK)
333 err = vdc_ack(port, &msgbuf);
334 else if (msgbuf.tag.stype == VIO_SUBTYPE_NACK)
335 err = vdc_nack(port, &msgbuf);
336 else
337 err = vdc_handle_unknown(port, &msgbuf);
338 } else if (msgbuf.tag.type == VIO_TYPE_CTRL) {
339 err = vio_control_pkt_engine(vio, &msgbuf);
340 } else {
341 err = vdc_handle_unknown(port, &msgbuf);
342 }
343 if (err < 0)
344 break;
345 }
346 if (err < 0)
347 vdc_finish(&port->vio, err, WAITING_FOR_ANY);
348 spin_unlock_irqrestore(&vio->lock, flags);
349}
350
351static int __vdc_tx_trigger(struct vdc_port *port)
352{
353 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
354 struct vio_dring_data hdr = {
355 .tag = {
356 .type = VIO_TYPE_DATA,
357 .stype = VIO_SUBTYPE_INFO,
358 .stype_env = VIO_DRING_DATA,
359 .sid = vio_send_sid(&port->vio),
360 },
361 .dring_ident = dr->ident,
362 .start_idx = dr->prod,
363 .end_idx = dr->prod,
364 };
365 int err, delay;
366
367 hdr.seq = dr->snd_nxt;
368 delay = 1;
369 do {
370 err = vio_ldc_send(&port->vio, &hdr, sizeof(hdr));
371 if (err > 0) {
372 dr->snd_nxt++;
373 break;
374 }
375 udelay(delay);
376 if ((delay <<= 1) > 128)
377 delay = 128;
378 } while (err == -EAGAIN);
379
380 return err;
381}
382
383static int __send_request(struct request *req)
384{
385 struct vdc_port *port = req->rq_disk->private_data;
386 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
387 struct scatterlist sg[port->ring_cookies];
388 struct vdc_req_entry *rqe;
389 struct vio_disk_desc *desc;
390 unsigned int map_perm;
391 int nsg, err, i;
392 u64 len;
393 u8 op;
394
395 map_perm = LDC_MAP_SHADOW | LDC_MAP_DIRECT | LDC_MAP_IO;
396
397 if (rq_data_dir(req) == READ) {
398 map_perm |= LDC_MAP_W;
399 op = VD_OP_BREAD;
400 } else {
401 map_perm |= LDC_MAP_R;
402 op = VD_OP_BWRITE;
403 }
404
405 nsg = blk_rq_map_sg(req->q, req, sg);
406
407 len = 0;
408 for (i = 0; i < nsg; i++)
409 len += sg[i].length;
410
411 if (unlikely(vdc_tx_dring_avail(dr) < 1)) {
412 blk_stop_queue(port->disk->queue);
413 err = -ENOMEM;
414 goto out;
415 }
416
417 desc = vio_dring_cur(dr);
418
419 err = ldc_map_sg(port->vio.lp, sg, nsg,
420 desc->cookies, port->ring_cookies,
421 map_perm);
422 if (err < 0) {
423 printk(KERN_ERR PFX "ldc_map_sg() failure, err=%d.\n", err);
424 return err;
425 }
426
427 rqe = &port->rq_arr[dr->prod];
428 rqe->req = req;
429
430 desc->hdr.ack = VIO_ACK_ENABLE;
431 desc->req_id = port->req_id;
432 desc->operation = op;
433 if (port->vdisk_type == VD_DISK_TYPE_DISK) {
434 desc->slice = 2;
435 } else {
436 desc->slice = 0;
437 }
438 desc->status = ~0;
439 desc->offset = (req->sector << 9) / port->vdisk_block_size;
440 desc->size = len;
441 desc->ncookies = err;
442
443 /* This has to be a non-SMP write barrier because we are writing
444 * to memory which is shared with the peer LDOM.
445 */
446 wmb();
447 desc->hdr.state = VIO_DESC_READY;
448
449 err = __vdc_tx_trigger(port);
450 if (err < 0) {
451 printk(KERN_ERR PFX "vdc_tx_trigger() failure, err=%d\n", err);
452 } else {
453 port->req_id++;
454 dr->prod = (dr->prod + 1) & (VDC_TX_RING_SIZE - 1);
455 }
456out:
457
458 return err;
459}
460
461static void do_vdc_request(request_queue_t *q)
462{
463 while (1) {
464 struct request *req = elv_next_request(q);
465
466 if (!req)
467 break;
468
469 blkdev_dequeue_request(req);
470 if (__send_request(req) < 0)
471 vdc_end_request(req, 0, req->hard_nr_sectors);
472 }
473}
474
475static int generic_request(struct vdc_port *port, u8 op, void *buf, int len)
476{
477 struct vio_dring_state *dr;
478 struct vio_completion comp;
479 struct vio_disk_desc *desc;
480 unsigned int map_perm;
481 unsigned long flags;
482 int op_len, err;
483 void *req_buf;
484
485 if (!(((u64)1 << ((u64)op - 1)) & port->operations))
486 return -EOPNOTSUPP;
487
488 switch (op) {
489 case VD_OP_BREAD:
490 case VD_OP_BWRITE:
491 default:
492 return -EINVAL;
493
494 case VD_OP_FLUSH:
495 op_len = 0;
496 map_perm = 0;
497 break;
498
499 case VD_OP_GET_WCE:
500 op_len = sizeof(u32);
501 map_perm = LDC_MAP_W;
502 break;
503
504 case VD_OP_SET_WCE:
505 op_len = sizeof(u32);
506 map_perm = LDC_MAP_R;
507 break;
508
509 case VD_OP_GET_VTOC:
510 op_len = sizeof(struct vio_disk_vtoc);
511 map_perm = LDC_MAP_W;
512 break;
513
514 case VD_OP_SET_VTOC:
515 op_len = sizeof(struct vio_disk_vtoc);
516 map_perm = LDC_MAP_R;
517 break;
518
519 case VD_OP_GET_DISKGEOM:
520 op_len = sizeof(struct vio_disk_geom);
521 map_perm = LDC_MAP_W;
522 break;
523
524 case VD_OP_SET_DISKGEOM:
525 op_len = sizeof(struct vio_disk_geom);
526 map_perm = LDC_MAP_R;
527 break;
528
529 case VD_OP_SCSICMD:
530 op_len = 16;
531 map_perm = LDC_MAP_RW;
532 break;
533
534 case VD_OP_GET_DEVID:
535 op_len = sizeof(struct vio_disk_devid);
536 map_perm = LDC_MAP_W;
537 break;
538
539 case VD_OP_GET_EFI:
540 case VD_OP_SET_EFI:
541 return -EOPNOTSUPP;
542 break;
543 };
544
545 map_perm |= LDC_MAP_SHADOW | LDC_MAP_DIRECT | LDC_MAP_IO;
546
547 op_len = (op_len + 7) & ~7;
548 req_buf = kzalloc(op_len, GFP_KERNEL);
549 if (!req_buf)
550 return -ENOMEM;
551
552 if (len > op_len)
553 len = op_len;
554
555 if (map_perm & LDC_MAP_R)
556 memcpy(req_buf, buf, len);
557
558 spin_lock_irqsave(&port->vio.lock, flags);
559
560 dr = &port->vio.drings[VIO_DRIVER_TX_RING];
561
562 /* XXX If we want to use this code generically we have to
563 * XXX handle TX ring exhaustion etc.
564 */
565 desc = vio_dring_cur(dr);
566
567 err = ldc_map_single(port->vio.lp, req_buf, op_len,
568 desc->cookies, port->ring_cookies,
569 map_perm);
570 if (err < 0) {
571 spin_unlock_irqrestore(&port->vio.lock, flags);
572 kfree(req_buf);
573 return err;
574 }
575
576 init_completion(&comp.com);
577 comp.waiting_for = WAITING_FOR_GEN_CMD;
578 port->vio.cmp = &comp;
579
580 desc->hdr.ack = VIO_ACK_ENABLE;
581 desc->req_id = port->req_id;
582 desc->operation = op;
583 desc->slice = 0;
584 desc->status = ~0;
585 desc->offset = 0;
586 desc->size = op_len;
587 desc->ncookies = err;
588
589 /* This has to be a non-SMP write barrier because we are writing
590 * to memory which is shared with the peer LDOM.
591 */
592 wmb();
593 desc->hdr.state = VIO_DESC_READY;
594
595 err = __vdc_tx_trigger(port);
596 if (err >= 0) {
597 port->req_id++;
598 dr->prod = (dr->prod + 1) & (VDC_TX_RING_SIZE - 1);
599 spin_unlock_irqrestore(&port->vio.lock, flags);
600
601 wait_for_completion(&comp.com);
602 err = comp.err;
603 } else {
604 port->vio.cmp = NULL;
605 spin_unlock_irqrestore(&port->vio.lock, flags);
606 }
607
608 if (map_perm & LDC_MAP_W)
609 memcpy(buf, req_buf, len);
610
611 kfree(req_buf);
612
613 return err;
614}
615
616static int __devinit vdc_alloc_tx_ring(struct vdc_port *port)
617{
618 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
619 unsigned long len, entry_size;
620 int ncookies;
621 void *dring;
622
623 entry_size = sizeof(struct vio_disk_desc) +
624 (sizeof(struct ldc_trans_cookie) * port->ring_cookies);
625 len = (VDC_TX_RING_SIZE * entry_size);
626
627 ncookies = VIO_MAX_RING_COOKIES;
628 dring = ldc_alloc_exp_dring(port->vio.lp, len,
629 dr->cookies, &ncookies,
630 (LDC_MAP_SHADOW |
631 LDC_MAP_DIRECT |
632 LDC_MAP_RW));
633 if (IS_ERR(dring))
634 return PTR_ERR(dring);
635
636 dr->base = dring;
637 dr->entry_size = entry_size;
638 dr->num_entries = VDC_TX_RING_SIZE;
639 dr->prod = dr->cons = 0;
640 dr->pending = VDC_TX_RING_SIZE;
641 dr->ncookies = ncookies;
642
643 return 0;
644}
645
646static void vdc_free_tx_ring(struct vdc_port *port)
647{
648 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
649
650 if (dr->base) {
651 ldc_free_exp_dring(port->vio.lp, dr->base,
652 (dr->entry_size * dr->num_entries),
653 dr->cookies, dr->ncookies);
654 dr->base = NULL;
655 dr->entry_size = 0;
656 dr->num_entries = 0;
657 dr->pending = 0;
658 dr->ncookies = 0;
659 }
660}
661
662static int probe_disk(struct vdc_port *port)
663{
664 struct vio_completion comp;
665 struct request_queue *q;
666 struct gendisk *g;
667 int err;
668
669 init_completion(&comp.com);
670 comp.err = 0;
671 comp.waiting_for = WAITING_FOR_LINK_UP;
672 port->vio.cmp = &comp;
673
674 vio_port_up(&port->vio);
675
676 wait_for_completion(&comp.com);
677 if (comp.err)
678 return comp.err;
679
680 err = generic_request(port, VD_OP_GET_VTOC,
681 &port->label, sizeof(port->label));
682 if (err < 0) {
683 printk(KERN_ERR PFX "VD_OP_GET_VTOC returns error %d\n", err);
684 return err;
685 }
686
687 err = generic_request(port, VD_OP_GET_DISKGEOM,
688 &port->geom, sizeof(port->geom));
689 if (err < 0) {
690 printk(KERN_ERR PFX "VD_OP_GET_DISKGEOM returns "
691 "error %d\n", err);
692 return err;
693 }
694
695 port->vdisk_size = ((u64)port->geom.num_cyl *
696 (u64)port->geom.num_hd *
697 (u64)port->geom.num_sec);
698
699 q = blk_init_queue(do_vdc_request, &port->vio.lock);
700 if (!q) {
701 printk(KERN_ERR PFX "%s: Could not allocate queue.\n",
702 port->vio.name);
703 return -ENOMEM;
704 }
705 g = alloc_disk(1 << PARTITION_SHIFT);
706 if (!g) {
707 printk(KERN_ERR PFX "%s: Could not allocate gendisk.\n",
708 port->vio.name);
709 blk_cleanup_queue(q);
710 return -ENOMEM;
711 }
712
713 port->disk = g;
714
715 blk_queue_max_hw_segments(q, port->ring_cookies);
716 blk_queue_max_phys_segments(q, port->ring_cookies);
717 blk_queue_max_sectors(q, port->max_xfer_size);
718 g->major = vdc_major;
719 g->first_minor = port->dev_no << PARTITION_SHIFT;
720 strcpy(g->disk_name, port->disk_name);
721
722 g->fops = &vdc_fops;
723 g->queue = q;
724 g->private_data = port;
725 g->driverfs_dev = &port->vio.vdev->dev;
726
727 set_capacity(g, port->vdisk_size);
728
729 printk(KERN_INFO PFX "%s: %u sectors (%u MB)\n",
730 g->disk_name,
731 port->vdisk_size, (port->vdisk_size >> (20 - 9)));
732
733 add_disk(g);
734
735 return 0;
736}
737
738static struct ldc_channel_config vdc_ldc_cfg = {
739 .event = vdc_event,
740 .mtu = 64,
741 .mode = LDC_MODE_UNRELIABLE,
742};
743
744static struct vio_driver_ops vdc_vio_ops = {
745 .send_attr = vdc_send_attr,
746 .handle_attr = vdc_handle_attr,
747 .handshake_complete = vdc_handshake_complete,
748};
749
750static int __devinit vdc_port_probe(struct vio_dev *vdev,
751 const struct vio_device_id *id)
752{
753 struct mdesc_handle *hp;
754 struct vdc_port *port;
755 unsigned long flags;
756 struct vdc *vp;
757 const u64 *port_id;
758 int err;
759
760 vp = dev_get_drvdata(vdev->dev.parent);
761 if (!vp) {
762 printk(KERN_ERR PFX "Cannot find port parent vdc.\n");
763 return -ENODEV;
764 }
765
766 hp = mdesc_grab();
767
768 port_id = mdesc_get_property(hp, vdev->mp, "id", NULL);
769 err = -ENODEV;
770 if (!port_id) {
771 printk(KERN_ERR PFX "Port lacks id property.\n");
772 goto err_out_release_mdesc;
773 }
774 if ((*port_id << PARTITION_SHIFT) & ~(u64)MINORMASK) {
775 printk(KERN_ERR PFX "Port id [%lu] too large.\n", *port_id);
776 goto err_out_release_mdesc;
777 }
778
779 port = kzalloc(sizeof(*port), GFP_KERNEL);
780 err = -ENOMEM;
781 if (!port) {
782 printk(KERN_ERR PFX "Cannot allocate vdc_port.\n");
783 goto err_out_release_mdesc;
784 }
785
786 port->vp = vp;
787 port->dev_no = *port_id;
788
789 if (port->dev_no >= 26)
790 snprintf(port->disk_name, sizeof(port->disk_name),
791 VDCBLK_NAME "%c%c",
792 'a' + (port->dev_no / 26) - 1,
793 'a' + (port->dev_no % 26));
794 else
795 snprintf(port->disk_name, sizeof(port->disk_name),
796 VDCBLK_NAME "%c", 'a' + (port->dev_no % 26));
797
798 err = vio_driver_init(&port->vio, vdev, VDEV_DISK,
799 vdc_versions, ARRAY_SIZE(vdc_versions),
800 &vdc_vio_ops, port->disk_name);
801 if (err)
802 goto err_out_free_port;
803
804 port->vdisk_block_size = 512;
805 port->max_xfer_size = ((128 * 1024) / port->vdisk_block_size);
806 port->ring_cookies = ((port->max_xfer_size *
807 port->vdisk_block_size) / PAGE_SIZE) + 2;
808
809 err = vio_ldc_alloc(&port->vio, &vdc_ldc_cfg, port);
810 if (err)
811 goto err_out_free_port;
812
813 err = vdc_alloc_tx_ring(port);
814 if (err)
815 goto err_out_free_ldc;
816
817 err = probe_disk(port);
818 if (err)
819 goto err_out_free_tx_ring;
820
821 INIT_LIST_HEAD(&port->list);
822
823 spin_lock_irqsave(&vp->lock, flags);
824 list_add(&port->list, &vp->port_list);
825 spin_unlock_irqrestore(&vp->lock, flags);
826
827 dev_set_drvdata(&vdev->dev, port);
828
829 mdesc_release(hp);
830
831 return 0;
832
833err_out_free_tx_ring:
834 vdc_free_tx_ring(port);
835
836err_out_free_ldc:
837 vio_ldc_free(&port->vio);
838
839err_out_free_port:
840 kfree(port);
841
842err_out_release_mdesc:
843 mdesc_release(hp);
844 return err;
845}
846
847static int vdc_port_remove(struct vio_dev *vdev)
848{
849 struct vdc_port *port = dev_get_drvdata(&vdev->dev);
850
851 if (port) {
852 del_timer_sync(&port->vio.timer);
853
854 vdc_free_tx_ring(port);
855 vio_ldc_free(&port->vio);
856
857 dev_set_drvdata(&vdev->dev, NULL);
858
859 kfree(port);
860 }
861 return 0;
862}
863
864static struct vio_device_id vdc_port_match[] = {
865 {
866 .type = "vdc-port",
867 },
868 {},
869};
870MODULE_DEVICE_TABLE(vio, vdc_match);
871
872static struct vio_driver vdc_port_driver = {
873 .id_table = vdc_port_match,
874 .probe = vdc_port_probe,
875 .remove = vdc_port_remove,
876 .driver = {
877 .name = "vdc_port",
878 .owner = THIS_MODULE,
879 }
880};
881
882static int __devinit vdc_probe(struct vio_dev *vdev,
883 const struct vio_device_id *id)
884{
885 static int vdc_version_printed;
886 struct vdc *vp;
887
888 if (vdc_version_printed++ == 0)
889 printk(KERN_INFO "%s", version);
890
891 vp = kzalloc(sizeof(struct vdc), GFP_KERNEL);
892 if (!vp)
893 return -ENOMEM;
894
895 spin_lock_init(&vp->lock);
896 vp->dev = vdev;
897 INIT_LIST_HEAD(&vp->port_list);
898
899 dev_set_drvdata(&vdev->dev, vp);
900
901 return 0;
902}
903
904static int vdc_remove(struct vio_dev *vdev)
905{
906
907 struct vdc *vp = dev_get_drvdata(&vdev->dev);
908
909 if (vp) {
910 kfree(vp);
911 dev_set_drvdata(&vdev->dev, NULL);
912 }
913 return 0;
914}
915
916static struct vio_device_id vdc_match[] = {
917 {
918 .type = "block",
919 },
920 {},
921};
922MODULE_DEVICE_TABLE(vio, vdc_match);
923
924static struct vio_driver vdc_driver = {
925 .id_table = vdc_match,
926 .probe = vdc_probe,
927 .remove = vdc_remove,
928 .driver = {
929 .name = "vdc",
930 .owner = THIS_MODULE,
931 }
932};
933
934static int __init vdc_init(void)
935{
936 int err;
937
938 err = register_blkdev(0, VDCBLK_NAME);
939 if (err < 0)
940 goto out_err;
941
942 vdc_major = err;
943 err = vio_register_driver(&vdc_driver);
944 if (err)
945 goto out_unregister_blkdev;
946
947 err = vio_register_driver(&vdc_port_driver);
948 if (err)
949 goto out_unregister_vdc;
950
951 return 0;
952
953out_unregister_vdc:
954 vio_unregister_driver(&vdc_driver);
955
956out_unregister_blkdev:
957 unregister_blkdev(vdc_major, VDCBLK_NAME);
958 vdc_major = 0;
959
960out_err:
961 return err;
962}
963
964static void __exit vdc_exit(void)
965{
966 vio_unregister_driver(&vdc_port_driver);
967 vio_unregister_driver(&vdc_driver);
968 unregister_blkdev(vdc_major, VDCBLK_NAME);
969}
970
971module_init(vdc_init);
972module_exit(vdc_exit);
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index 746a118a9b52..8b13d7d2cb63 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -1547,10 +1547,8 @@ static void ub_reset_enter(struct ub_dev *sc, int try)
1547#endif 1547#endif
1548 1548
1549#if 0 /* We let them stop themselves. */ 1549#if 0 /* We let them stop themselves. */
1550 struct list_head *p;
1551 struct ub_lun *lun; 1550 struct ub_lun *lun;
1552 list_for_each(p, &sc->luns) { 1551 list_for_each_entry(lun, &sc->luns, link) {
1553 lun = list_entry(p, struct ub_lun, link);
1554 blk_stop_queue(lun->disk->queue); 1552 blk_stop_queue(lun->disk->queue);
1555 } 1553 }
1556#endif 1554#endif
@@ -1562,7 +1560,6 @@ static void ub_reset_task(struct work_struct *work)
1562{ 1560{
1563 struct ub_dev *sc = container_of(work, struct ub_dev, reset_work); 1561 struct ub_dev *sc = container_of(work, struct ub_dev, reset_work);
1564 unsigned long flags; 1562 unsigned long flags;
1565 struct list_head *p;
1566 struct ub_lun *lun; 1563 struct ub_lun *lun;
1567 int lkr, rc; 1564 int lkr, rc;
1568 1565
@@ -1608,8 +1605,7 @@ static void ub_reset_task(struct work_struct *work)
1608 spin_lock_irqsave(sc->lock, flags); 1605 spin_lock_irqsave(sc->lock, flags);
1609 sc->reset = 0; 1606 sc->reset = 0;
1610 tasklet_schedule(&sc->tasklet); 1607 tasklet_schedule(&sc->tasklet);
1611 list_for_each(p, &sc->luns) { 1608 list_for_each_entry(lun, &sc->luns, link) {
1612 lun = list_entry(p, struct ub_lun, link);
1613 blk_start_queue(lun->disk->queue); 1609 blk_start_queue(lun->disk->queue);
1614 } 1610 }
1615 wake_up(&sc->reset_wait); 1611 wake_up(&sc->reset_wait);
@@ -1713,7 +1709,7 @@ static int ub_bd_ioctl(struct inode *inode, struct file *filp,
1713 struct gendisk *disk = inode->i_bdev->bd_disk; 1709 struct gendisk *disk = inode->i_bdev->bd_disk;
1714 void __user *usermem = (void __user *) arg; 1710 void __user *usermem = (void __user *) arg;
1715 1711
1716 return scsi_cmd_ioctl(filp, disk, cmd, usermem); 1712 return scsi_cmd_ioctl(filp, disk->queue, disk, cmd, usermem);
1717} 1713}
1718 1714
1719/* 1715/*
@@ -2348,7 +2344,6 @@ err_alloc:
2348static void ub_disconnect(struct usb_interface *intf) 2344static void ub_disconnect(struct usb_interface *intf)
2349{ 2345{
2350 struct ub_dev *sc = usb_get_intfdata(intf); 2346 struct ub_dev *sc = usb_get_intfdata(intf);
2351 struct list_head *p;
2352 struct ub_lun *lun; 2347 struct ub_lun *lun;
2353 unsigned long flags; 2348 unsigned long flags;
2354 2349
@@ -2403,8 +2398,7 @@ static void ub_disconnect(struct usb_interface *intf)
2403 /* 2398 /*
2404 * Unregister the upper layer. 2399 * Unregister the upper layer.
2405 */ 2400 */
2406 list_for_each (p, &sc->luns) { 2401 list_for_each_entry(lun, &sc->luns, link) {
2407 lun = list_entry(p, struct ub_lun, link);
2408 del_gendisk(lun->disk); 2402 del_gendisk(lun->disk);
2409 /* 2403 /*
2410 * I wish I could do: 2404 * I wish I could do:
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 6f5d6203d725..dec74bd23496 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -105,12 +105,6 @@ struct cardinfo {
105 unsigned long csr_base; 105 unsigned long csr_base;
106 unsigned char __iomem *csr_remap; 106 unsigned char __iomem *csr_remap;
107 unsigned long csr_len; 107 unsigned long csr_len;
108#ifdef CONFIG_MM_MAP_MEMORY
109 unsigned long mem_base;
110 unsigned char __iomem *mem_remap;
111 unsigned long mem_len;
112#endif
113
114 unsigned int win_size; /* PCI window size */ 108 unsigned int win_size; /* PCI window size */
115 unsigned int mm_size; /* size in kbytes */ 109 unsigned int mm_size; /* size in kbytes */
116 110
@@ -872,10 +866,6 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
872 866
873 card->csr_base = pci_resource_start(dev, 0); 867 card->csr_base = pci_resource_start(dev, 0);
874 card->csr_len = pci_resource_len(dev, 0); 868 card->csr_len = pci_resource_len(dev, 0);
875#ifdef CONFIG_MM_MAP_MEMORY
876 card->mem_base = pci_resource_start(dev, 1);
877 card->mem_len = pci_resource_len(dev, 1);
878#endif
879 869
880 printk(KERN_INFO "Micro Memory(tm) controller #%d found at %02x:%02x (PCI Mem Module (Battery Backup))\n", 870 printk(KERN_INFO "Micro Memory(tm) controller #%d found at %02x:%02x (PCI Mem Module (Battery Backup))\n",
881 card->card_number, dev->bus->number, dev->devfn); 871 card->card_number, dev->bus->number, dev->devfn);
@@ -903,27 +893,6 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
903 printk(KERN_INFO "MM%d: CSR 0x%08lx -> 0x%p (0x%lx)\n", card->card_number, 893 printk(KERN_INFO "MM%d: CSR 0x%08lx -> 0x%p (0x%lx)\n", card->card_number,
904 card->csr_base, card->csr_remap, card->csr_len); 894 card->csr_base, card->csr_remap, card->csr_len);
905 895
906#ifdef CONFIG_MM_MAP_MEMORY
907 if (!request_mem_region(card->mem_base, card->mem_len, "Micro Memory")) {
908 printk(KERN_ERR "MM%d: Unable to request memory region\n", card->card_number);
909 ret = -ENOMEM;
910
911 goto failed_req_mem;
912 }
913
914 if (!(card->mem_remap = ioremap(card->mem_base, cards->mem_len))) {
915 printk(KERN_ERR "MM%d: Unable to remap memory region\n", card->card_number);
916 ret = -ENOMEM;
917
918 goto failed_remap_mem;
919 }
920
921 printk(KERN_INFO "MM%d: MEM 0x%8lx -> 0x%8lx (0x%lx)\n", card->card_number,
922 card->mem_base, card->mem_remap, card->mem_len);
923#else
924 printk(KERN_INFO "MM%d: MEM area not remapped (CONFIG_MM_MAP_MEMORY not set)\n",
925 card->card_number);
926#endif
927 switch(card->dev->device) { 896 switch(card->dev->device) {
928 case 0x5415: 897 case 0x5415:
929 card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG; 898 card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG;
@@ -1091,12 +1060,6 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1091 card->mm_pages[1].desc, 1060 card->mm_pages[1].desc,
1092 card->mm_pages[1].page_dma); 1061 card->mm_pages[1].page_dma);
1093 failed_magic: 1062 failed_magic:
1094#ifdef CONFIG_MM_MAP_MEMORY
1095 iounmap(card->mem_remap);
1096 failed_remap_mem:
1097 release_mem_region(card->mem_base, card->mem_len);
1098 failed_req_mem:
1099#endif
1100 iounmap(card->csr_remap); 1063 iounmap(card->csr_remap);
1101 failed_remap_csr: 1064 failed_remap_csr:
1102 release_mem_region(card->csr_base, card->csr_len); 1065 release_mem_region(card->csr_base, card->csr_len);
@@ -1116,10 +1079,6 @@ static void mm_pci_remove(struct pci_dev *dev)
1116 tasklet_kill(&card->tasklet); 1079 tasklet_kill(&card->tasklet);
1117 iounmap(card->csr_remap); 1080 iounmap(card->csr_remap);
1118 release_mem_region(card->csr_base, card->csr_len); 1081 release_mem_region(card->csr_base, card->csr_len);
1119#ifdef CONFIG_MM_MAP_MEMORY
1120 iounmap(card->mem_remap);
1121 release_mem_region(card->mem_base, card->mem_len);
1122#endif
1123 free_irq(card->irq, card); 1082 free_irq(card->irq, card);
1124 1083
1125 if (card->mm_pages[0].desc) 1084 if (card->mm_pages[0].desc)
@@ -1133,23 +1092,18 @@ static void mm_pci_remove(struct pci_dev *dev)
1133 blk_cleanup_queue(card->queue); 1092 blk_cleanup_queue(card->queue);
1134} 1093}
1135 1094
1136static const struct pci_device_id mm_pci_ids[] = { { 1095static const struct pci_device_id mm_pci_ids[] = {
1137 .vendor = PCI_VENDOR_ID_MICRO_MEMORY, 1096 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_5415CN)},
1138 .device = PCI_DEVICE_ID_MICRO_MEMORY_5415CN, 1097 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_5425CN)},
1139 }, { 1098 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_6155)},
1140 .vendor = PCI_VENDOR_ID_MICRO_MEMORY, 1099 {
1141 .device = PCI_DEVICE_ID_MICRO_MEMORY_5425CN,
1142 }, {
1143 .vendor = PCI_VENDOR_ID_MICRO_MEMORY,
1144 .device = PCI_DEVICE_ID_MICRO_MEMORY_6155,
1145 }, {
1146 .vendor = 0x8086, 1100 .vendor = 0x8086,
1147 .device = 0xB555, 1101 .device = 0xB555,
1148 .subvendor= 0x1332, 1102 .subvendor= 0x1332,
1149 .subdevice= 0x5460, 1103 .subdevice= 0x5460,
1150 .class = 0x050000, 1104 .class = 0x050000,
1151 .class_mask= 0, 1105 .class_mask= 0,
1152 }, { /* end: all zeroes */ } 1106 }, { /* end: all zeroes */ }
1153}; 1107};
1154 1108
1155MODULE_DEVICE_TABLE(pci, mm_pci_ids); 1109MODULE_DEVICE_TABLE(pci, mm_pci_ids);
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index 7cc2685ca84a..2abf94cc3137 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -44,9 +44,6 @@
44extern int m68k_realnum_memory; 44extern int m68k_realnum_memory;
45extern struct mem_info m68k_memory[NUM_MEMINFO]; 45extern struct mem_info m68k_memory[NUM_MEMINFO];
46 46
47#define TRUE (1)
48#define FALSE (0)
49
50#define Z2MINOR_COMBINED (0) 47#define Z2MINOR_COMBINED (0)
51#define Z2MINOR_Z2ONLY (1) 48#define Z2MINOR_Z2ONLY (1)
52#define Z2MINOR_CHIPONLY (2) 49#define Z2MINOR_CHIPONLY (2)