ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / scsi / scsi_transport_spi.c
1 /* 
2  *  Parallel SCSI (SPI) transport specific attributes exported to sysfs.
3  *
4  *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/smp_lock.h>
23 #include <linux/list.h>
24 #include <linux/spinlock.h>
25 #include <linux/mm.h>
26 #include <linux/workqueue.h>
27 #include <asm/scatterlist.h>
28 #include <asm/io.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_request.h>
33 #include <scsi/scsi_transport.h>
34 #include <scsi/scsi_transport_spi.h>
35
36 #define SPI_PRINTK(x, l, f, a...)       printk(l "scsi(%d:%d:%d:%d): " f, (x)->host->host_no, (x)->channel, (x)->id, (x)->lun , ##a)
37
38 static void transport_class_release(struct class_device *class_dev);
39
40 #define SPI_NUM_ATTRS 10        /* increase this if you add attributes */
41 #define SPI_OTHER_ATTRS 1       /* Increase this if you add "always
42                                  * on" attributes */
43
44 #define SPI_MAX_ECHO_BUFFER_SIZE        4096
45
46 /* Private data accessors (keep these out of the header file) */
47 #define spi_dv_pending(x) (((struct spi_transport_attrs *)&(x)->transport_data)->dv_pending)
48 #define spi_dv_sem(x) (((struct spi_transport_attrs *)&(x)->transport_data)->dv_sem)
49
50 struct spi_internal {
51         struct scsi_transport_template t;
52         struct spi_function_template *f;
53         /* The actual attributes */
54         struct class_device_attribute private_attrs[SPI_NUM_ATTRS];
55         /* The array of null terminated pointers to attributes 
56          * needed by scsi_sysfs.c */
57         struct class_device_attribute *attrs[SPI_NUM_ATTRS + SPI_OTHER_ATTRS + 1];
58 };
59
60 #define to_spi_internal(tmpl)   container_of(tmpl, struct spi_internal, t)
61
62 static const char *const ppr_to_ns[] = {
63         /* The PPR values 0-6 are reserved, fill them in when
64          * the committee defines them */
65         NULL,                   /* 0x00 */
66         NULL,                   /* 0x01 */
67         NULL,                   /* 0x02 */
68         NULL,                   /* 0x03 */
69         NULL,                   /* 0x04 */
70         NULL,                   /* 0x05 */
71         NULL,                   /* 0x06 */
72         "3.125",                /* 0x07 */
73         "6.25",                 /* 0x08 */
74         "12.5",                 /* 0x09 */
75         "25",                   /* 0x0a */
76         "30.3",                 /* 0x0b */
77         "50",                   /* 0x0c */
78 };
79 /* The PPR values at which you calculate the period in ns by multiplying
80  * by 4 */
81 #define SPI_STATIC_PPR  0x0c
82
83 struct class spi_transport_class = {
84         .name = "spi_transport",
85         .release = transport_class_release,
86 };
87
88 static __init int spi_transport_init(void)
89 {
90         return class_register(&spi_transport_class);
91 }
92
93 static void __exit spi_transport_exit(void)
94 {
95         class_unregister(&spi_transport_class);
96 }
97
98 static int spi_setup_transport_attrs(struct scsi_device *sdev)
99 {
100         spi_period(sdev) = -1;  /* illegal value */
101         spi_offset(sdev) = 0;   /* async */
102         spi_width(sdev) = 0;    /* narrow */
103         spi_iu(sdev) = 0;       /* no IU */
104         spi_dt(sdev) = 0;       /* ST */
105         spi_qas(sdev) = 0;
106         spi_wr_flow(sdev) = 0;
107         spi_rd_strm(sdev) = 0;
108         spi_rti(sdev) = 0;
109         spi_pcomp_en(sdev) = 0;
110         spi_dv_pending(sdev) = 0;
111         init_MUTEX(&spi_dv_sem(sdev));
112
113         return 0;
114 }
115
116 static void transport_class_release(struct class_device *class_dev)
117 {
118         struct scsi_device *sdev = transport_class_to_sdev(class_dev);
119         put_device(&sdev->sdev_gendev);
120 }
121
122 #define spi_transport_show_function(field, format_string)               \
123                                                                         \
124 static ssize_t                                                          \
125 show_spi_transport_##field(struct class_device *cdev, char *buf)        \
126 {                                                                       \
127         struct scsi_device *sdev = transport_class_to_sdev(cdev);       \
128         struct spi_transport_attrs *tp;                                 \
129         struct spi_internal *i = to_spi_internal(sdev->host->transportt); \
130         tp = (struct spi_transport_attrs *)&sdev->transport_data;       \
131         if (i->f->get_##field)                                          \
132                 i->f->get_##field(sdev);                                \
133         return snprintf(buf, 20, format_string, tp->field);             \
134 }
135
136 #define spi_transport_store_function(field, format_string)              \
137 static ssize_t                                                          \
138 store_spi_transport_##field(struct class_device *cdev, const char *buf, \
139                             size_t count)                               \
140 {                                                                       \
141         int val;                                                        \
142         struct scsi_device *sdev = transport_class_to_sdev(cdev);       \
143         struct spi_internal *i = to_spi_internal(sdev->host->transportt); \
144                                                                         \
145         val = simple_strtoul(buf, NULL, 0);                             \
146         i->f->set_##field(sdev, val);                                   \
147         return count;                                                   \
148 }
149
150 #define spi_transport_rd_attr(field, format_string)                     \
151         spi_transport_show_function(field, format_string)               \
152         spi_transport_store_function(field, format_string)              \
153 static CLASS_DEVICE_ATTR(field, S_IRUGO | S_IWUSR,                      \
154                          show_spi_transport_##field,                    \
155                          store_spi_transport_##field)
156
157 /* The Parallel SCSI Tranport Attributes: */
158 spi_transport_rd_attr(offset, "%d\n");
159 spi_transport_rd_attr(width, "%d\n");
160 spi_transport_rd_attr(iu, "%d\n");
161 spi_transport_rd_attr(dt, "%d\n");
162 spi_transport_rd_attr(qas, "%d\n");
163 spi_transport_rd_attr(wr_flow, "%d\n");
164 spi_transport_rd_attr(rd_strm, "%d\n");
165 spi_transport_rd_attr(rti, "%d\n");
166 spi_transport_rd_attr(pcomp_en, "%d\n");
167
168 static ssize_t
169 store_spi_revalidate(struct class_device *cdev, const char *buf, size_t count)
170 {
171         struct scsi_device *sdev = transport_class_to_sdev(cdev);
172
173         spi_dv_device(sdev);
174         return count;
175 }
176 static CLASS_DEVICE_ATTR(revalidate, S_IWUSR, NULL, store_spi_revalidate)
177
178 /* Translate the period into ns according to the current spec
179  * for SDTR/PPR messages */
180 static ssize_t show_spi_transport_period(struct class_device *cdev, char *buf)
181
182 {
183         struct scsi_device *sdev = transport_class_to_sdev(cdev);
184         struct spi_transport_attrs *tp;
185         const char *str;
186         struct spi_internal *i = to_spi_internal(sdev->host->transportt);
187
188         tp = (struct spi_transport_attrs *)&sdev->transport_data;
189
190         if (i->f->get_period)
191                 i->f->get_period(sdev);
192
193         switch(tp->period) {
194
195         case 0x07 ... SPI_STATIC_PPR:
196                 str = ppr_to_ns[tp->period];
197                 if(!str)
198                         str = "reserved";
199                 break;
200
201
202         case (SPI_STATIC_PPR+1) ... 0xff:
203                 return sprintf(buf, "%d\n", tp->period * 4);
204
205         default:
206                 str = "unknown";
207         }
208         return sprintf(buf, "%s\n", str);
209 }
210
211 static ssize_t
212 store_spi_transport_period(struct class_device *cdev, const char *buf,
213                             size_t count)
214 {
215         struct scsi_device *sdev = transport_class_to_sdev(cdev);
216         struct spi_internal *i = to_spi_internal(sdev->host->transportt);
217         int j, period = -1;
218
219         for (j = 0; j < SPI_STATIC_PPR; j++) {
220                 int len;
221
222                 if(ppr_to_ns[j] == NULL)
223                         continue;
224
225                 len = strlen(ppr_to_ns[j]);
226
227                 if(strncmp(ppr_to_ns[j], buf, len) != 0)
228                         continue;
229
230                 if(buf[len] != '\n')
231                         continue;
232                 
233                 period = j;
234                 break;
235         }
236
237         if (period == -1) {
238                 int val = simple_strtoul(buf, NULL, 0);
239
240
241                 /* Should probably check limits here, but this
242                  * gets reasonably close to OK for most things */
243                 period = val/4;
244         }
245
246         if (period > 0xff)
247                 period = 0xff;
248
249         i->f->set_period(sdev, period);
250
251         return count;
252 }
253         
254 static CLASS_DEVICE_ATTR(period, S_IRUGO | S_IWUSR, 
255                          show_spi_transport_period,
256                          store_spi_transport_period);
257
258 #define DV_SET(x, y)                    \
259         if(i->f->set_##x)               \
260                 i->f->set_##x(sdev, y)
261
262 #define DV_LOOPS        3
263 #define DV_TIMEOUT      (10*HZ)
264 #define DV_RETRIES      3       /* should only need at most 
265                                  * two cc/ua clears */
266
267
268 /* This is for read/write Domain Validation:  If the device supports
269  * an echo buffer, we do read/write tests to it */
270 static int
271 spi_dv_device_echo_buffer(struct scsi_request *sreq, u8 *buffer,
272                           u8 *ptr, const int retries)
273 {
274         struct scsi_device *sdev = sreq->sr_device;
275         int len = ptr - buffer;
276         int j, k, r;
277         unsigned int pattern = 0x0000ffff;
278
279         const char spi_write_buffer[] = {
280                 WRITE_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0
281         };
282         const char spi_read_buffer[] = {
283                 READ_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0
284         };
285
286         /* set up the pattern buffer.  Doesn't matter if we spill
287          * slightly beyond since that's where the read buffer is */
288         for (j = 0; j < len; ) {
289
290                 /* fill the buffer with counting (test a) */
291                 for ( ; j < min(len, 32); j++)
292                         buffer[j] = j;
293                 k = j;
294                 /* fill the buffer with alternating words of 0x0 and
295                  * 0xffff (test b) */
296                 for ( ; j < min(len, k + 32); j += 2) {
297                         u16 *word = (u16 *)&buffer[j];
298                         
299                         *word = (j & 0x02) ? 0x0000 : 0xffff;
300                 }
301                 k = j;
302                 /* fill with crosstalk (alternating 0x5555 0xaaa)
303                  * (test c) */
304                 for ( ; j < min(len, k + 32); j += 2) {
305                         u16 *word = (u16 *)&buffer[j];
306
307                         *word = (j & 0x02) ? 0x5555 : 0xaaaa;
308                 }
309                 k = j;
310                 /* fill with shifting bits (test d) */
311                 for ( ; j < min(len, k + 32); j += 4) {
312                         u32 *word = (unsigned int *)&buffer[j];
313                         u32 roll = (pattern & 0x80000000) ? 1 : 0;
314                         
315                         *word = pattern;
316                         pattern = (pattern << 1) | roll;
317                 }
318                 /* don't bother with random data (test e) */
319         }
320
321         for (r = 0; r < retries; r++) {
322                 sreq->sr_cmd_len = 0;   /* wait_req to fill in */
323                 sreq->sr_data_direction = DMA_TO_DEVICE;
324                 scsi_wait_req(sreq, spi_write_buffer, buffer, len,
325                               DV_TIMEOUT, DV_RETRIES);
326                 if(sreq->sr_result || !scsi_device_online(sdev)) {
327                         scsi_device_set_state(sdev, SDEV_QUIESCE);
328                         SPI_PRINTK(sdev, KERN_ERR, "Write Buffer failure %x\n", sreq->sr_result);
329                         return 0;
330                 }
331
332                 memset(ptr, 0, len);
333                 sreq->sr_cmd_len = 0;   /* wait_req to fill in */
334                 sreq->sr_data_direction = DMA_FROM_DEVICE;
335                 scsi_wait_req(sreq, spi_read_buffer, ptr, len,
336                               DV_TIMEOUT, DV_RETRIES);
337                 scsi_device_set_state(sdev, SDEV_QUIESCE);
338
339                 if (memcmp(buffer, ptr, len) != 0)
340                         return 0;
341         }
342         return 1;
343 }
344
345 /* This is for the simplest form of Domain Validation: a read test
346  * on the inquiry data from the device */
347 static int
348 spi_dv_device_compare_inquiry(struct scsi_request *sreq, u8 *buffer,
349                               u8 *ptr, const int retries)
350 {
351         int r;
352         const int len = sreq->sr_device->inquiry_len;
353         struct scsi_device *sdev = sreq->sr_device;
354         const char spi_inquiry[] = {
355                 INQUIRY, 0, 0, 0, len, 0
356         };
357
358         for (r = 0; r < retries; r++) {
359                 sreq->sr_cmd_len = 0;   /* wait_req to fill in */
360                 sreq->sr_data_direction = DMA_FROM_DEVICE;
361
362                 memset(ptr, 0, len);
363
364                 scsi_wait_req(sreq, spi_inquiry, ptr, len,
365                               DV_TIMEOUT, DV_RETRIES);
366                 
367                 if(sreq->sr_result || !scsi_device_online(sdev)) {
368                         scsi_device_set_state(sdev, SDEV_QUIESCE);
369                         return 0;
370                 }
371
372                 /* If we don't have the inquiry data already, the
373                  * first read gets it */
374                 if (ptr == buffer) {
375                         ptr += len;
376                         --r;
377                         continue;
378                 }
379
380                 if (memcmp(buffer, ptr, len) != 0)
381                         /* failure */
382                         return 0;
383         }
384         return 1;
385 }
386
387 static int
388 spi_dv_retrain(struct scsi_request *sreq, u8 *buffer, u8 *ptr,
389                int (*compare_fn)(struct scsi_request *, u8 *, u8 *, int))
390 {
391         struct spi_internal *i = to_spi_internal(sreq->sr_host->transportt);
392         struct scsi_device *sdev = sreq->sr_device;
393         int period, prevperiod = 0; 
394
395
396         for (;;) {
397                 if (compare_fn(sreq, buffer, ptr, DV_LOOPS))
398                         /* Successful DV */
399                         break;
400
401                 /* OK, retrain, fallback */
402                 if (i->f->get_period)
403                         i->f->get_period(sdev);
404                 period = spi_period(sdev);
405                 if (period < 0x0d)
406                         period++;
407                 else
408                         period += period >> 1;
409
410                 if (unlikely(period > 0xff || period == prevperiod)) {
411                         /* Total failure; set to async and return */
412                         SPI_PRINTK(sdev, KERN_ERR, "Domain Validation Failure, dropping back to Asynchronous\n");
413                         DV_SET(offset, 0);
414                         return 0;
415                 }
416                 SPI_PRINTK(sdev, KERN_ERR, "Domain Validation detected failure, dropping back\n");
417                 DV_SET(period, period);
418                 prevperiod = period;
419         }
420         return 1;
421 }
422
423 static int
424 spi_dv_device_get_echo_buffer(struct scsi_request *sreq, u8 *buffer)
425 {
426         int l;
427
428         /* first off do a test unit ready.  This can error out 
429          * because of reservations or some other reason.  If it
430          * fails, the device won't let us write to the echo buffer
431          * so just return failure */
432         
433         const char spi_test_unit_ready[] = {
434                 TEST_UNIT_READY, 0, 0, 0, 0, 0
435         };
436
437         const char spi_read_buffer_descriptor[] = {
438                 READ_BUFFER, 0x0b, 0, 0, 0, 0, 0, 0, 4, 0
439         };
440
441         
442         sreq->sr_cmd_len = 0;
443         sreq->sr_data_direction = DMA_NONE;
444
445         /* We send a set of three TURs to clear any outstanding 
446          * unit attention conditions if they exist (Otherwise the
447          * buffer tests won't be happy).  If the TUR still fails
448          * (reservation conflict, device not ready, etc) just
449          * skip the write tests */
450         for (l = 0; ; l++) {
451                 scsi_wait_req(sreq, spi_test_unit_ready, NULL, 0,
452                               DV_TIMEOUT, DV_RETRIES);
453
454                 if(sreq->sr_result) {
455                         if(l >= 3)
456                                 return 0;
457                 } else {
458                         /* TUR succeeded */
459                         break;
460                 }
461         }
462
463         sreq->sr_cmd_len = 0;
464         sreq->sr_data_direction = DMA_FROM_DEVICE;
465
466         scsi_wait_req(sreq, spi_read_buffer_descriptor, buffer, 4,
467                       DV_TIMEOUT, DV_RETRIES);
468
469         if (sreq->sr_result)
470                 /* Device has no echo buffer */
471                 return 0;
472
473         return buffer[3] + ((buffer[2] & 0x1f) << 8);
474 }
475
476 static void
477 spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
478 {
479         struct spi_internal *i = to_spi_internal(sreq->sr_host->transportt);
480         struct scsi_device *sdev = sreq->sr_device;
481         int len = sdev->inquiry_len;
482         /* first set us up for narrow async */
483         DV_SET(offset, 0);
484         DV_SET(width, 0);
485         
486         if (!spi_dv_device_compare_inquiry(sreq, buffer, buffer, DV_LOOPS)) {
487                 SPI_PRINTK(sdev, KERN_ERR, "Domain Validation Initial Inquiry Failed\n");
488                 /* FIXME: should probably offline the device here? */
489                 return;
490         }
491
492         /* test width */
493         if (i->f->set_width && sdev->wdtr) {
494                 i->f->set_width(sdev, 1);
495
496                 if (!spi_dv_device_compare_inquiry(sreq, buffer,
497                                                    buffer + len,
498                                                    DV_LOOPS)) {
499                         SPI_PRINTK(sdev, KERN_ERR, "Wide Transfers Fail\n");
500                         i->f->set_width(sdev, 0);
501                 }
502         }
503
504         if (!i->f->set_period)
505                 return;
506
507         /* device can't handle synchronous */
508         if(!sdev->ppr && !sdev->sdtr)
509                 return;
510
511         /* now set up to the maximum */
512         DV_SET(offset, 255);
513         DV_SET(period, 1);
514         if (!spi_dv_retrain(sreq, buffer, buffer + len,
515                             spi_dv_device_compare_inquiry))
516                 return;
517
518         /* OK, now we have our initial speed set by the read only inquiry
519          * test, now try an echo buffer test (if the device allows it) */
520
521         if ((len = spi_dv_device_get_echo_buffer(sreq, buffer)) == 0) {
522                 SPI_PRINTK(sdev, KERN_INFO, "Domain Validation skipping write tests\n");
523                 return;
524         }
525         if (len > SPI_MAX_ECHO_BUFFER_SIZE) {
526                 SPI_PRINTK(sdev, KERN_WARNING, "Echo buffer size %d is too big, trimming to %d\n", len, SPI_MAX_ECHO_BUFFER_SIZE);
527                 len = SPI_MAX_ECHO_BUFFER_SIZE;
528         }
529
530         spi_dv_retrain(sreq, buffer, buffer + len,
531                        spi_dv_device_echo_buffer);
532 }
533
534
535 /**     spi_dv_device - Do Domain Validation on the device
536  *      @sdev:          scsi device to validate
537  *
538  *      Performs the domain validation on the given device in the
539  *      current execution thread.  Since DV operations may sleep,
540  *      the current thread must have user context.  Also no SCSI
541  *      related locks that would deadlock I/O issued by the DV may
542  *      be held.
543  */
544 void
545 spi_dv_device(struct scsi_device *sdev)
546 {
547         struct scsi_request *sreq = scsi_allocate_request(sdev, GFP_KERNEL);
548         u8 *buffer;
549         const int len = SPI_MAX_ECHO_BUFFER_SIZE*2;
550
551         if (unlikely(!sreq))
552                 return;
553
554         if (unlikely(scsi_device_get(sdev)))
555                 goto out_free_req;
556
557         buffer = kmalloc(len, GFP_KERNEL);
558
559         if (unlikely(!buffer))
560                 goto out_put;
561
562         memset(buffer, 0, len);
563
564         if (unlikely(scsi_device_quiesce(sdev)))
565                 goto out_free;
566
567         spi_dv_pending(sdev) = 1;
568         down(&spi_dv_sem(sdev));
569
570         SPI_PRINTK(sdev, KERN_INFO, "Beginning Domain Validation\n");
571
572         spi_dv_device_internal(sreq, buffer);
573
574         SPI_PRINTK(sdev, KERN_INFO, "Ending Domain Validation\n");
575
576         up(&spi_dv_sem(sdev));
577         spi_dv_pending(sdev) = 0;
578
579         scsi_device_resume(sdev);
580
581  out_free:
582         kfree(buffer);
583  out_put:
584         scsi_device_put(sdev);
585  out_free_req:
586         scsi_release_request(sreq);
587 }
588 EXPORT_SYMBOL(spi_dv_device);
589
590 struct work_queue_wrapper {
591         struct work_struct      work;
592         struct scsi_device      *sdev;
593 };
594
595 static void
596 spi_dv_device_work_wrapper(void *data)
597 {
598         struct work_queue_wrapper *wqw = (struct work_queue_wrapper *)data;
599         struct scsi_device *sdev = wqw->sdev;
600
601         kfree(wqw);
602         spi_dv_device(sdev);
603         spi_dv_pending(sdev) = 0;
604         scsi_device_put(sdev);
605 }
606
607
608 /**
609  *      spi_schedule_dv_device - schedule domain validation to occur on the device
610  *      @sdev:  The device to validate
611  *
612  *      Identical to spi_dv_device() above, except that the DV will be
613  *      scheduled to occur in a workqueue later.  All memory allocations
614  *      are atomic, so may be called from any context including those holding
615  *      SCSI locks.
616  */
617 void
618 spi_schedule_dv_device(struct scsi_device *sdev)
619 {
620         struct work_queue_wrapper *wqw =
621                 kmalloc(sizeof(struct work_queue_wrapper), GFP_ATOMIC);
622
623         if (unlikely(!wqw))
624                 return;
625
626         if (unlikely(spi_dv_pending(sdev))) {
627                 kfree(wqw);
628                 return;
629         }
630         /* Set pending early (dv_device doesn't check it, only sets it) */
631         spi_dv_pending(sdev) = 1;
632         if (unlikely(scsi_device_get(sdev))) {
633                 kfree(wqw);
634                 spi_dv_pending(sdev) = 0;
635                 return;
636         }
637
638         INIT_WORK(&wqw->work, spi_dv_device_work_wrapper, wqw);
639         wqw->sdev = sdev;
640
641         schedule_work(&wqw->work);
642 }
643 EXPORT_SYMBOL(spi_schedule_dv_device);
644
645 #define SETUP_ATTRIBUTE(field)                                          \
646         i->private_attrs[count] = class_device_attr_##field;            \
647         if (!i->f->set_##field) {                                       \
648                 i->private_attrs[count].attr.mode = S_IRUGO;            \
649                 i->private_attrs[count].store = NULL;                   \
650         }                                                               \
651         i->attrs[count] = &i->private_attrs[count];                     \
652         if (i->f->show_##field)                                         \
653                 count++
654
655 struct scsi_transport_template *
656 spi_attach_transport(struct spi_function_template *ft)
657 {
658         struct spi_internal *i = kmalloc(sizeof(struct spi_internal),
659                                          GFP_KERNEL);
660         int count = 0;
661         if (unlikely(!i))
662                 return NULL;
663
664         memset(i, 0, sizeof(struct spi_internal));
665
666
667         i->t.attrs = &i->attrs[0];
668         i->t.class = &spi_transport_class;
669         i->t.setup = &spi_setup_transport_attrs;
670         i->t.size = sizeof(struct spi_transport_attrs);
671         i->f = ft;
672
673         SETUP_ATTRIBUTE(period);
674         SETUP_ATTRIBUTE(offset);
675         SETUP_ATTRIBUTE(width);
676         SETUP_ATTRIBUTE(iu);
677         SETUP_ATTRIBUTE(dt);
678         SETUP_ATTRIBUTE(qas);
679         SETUP_ATTRIBUTE(wr_flow);
680         SETUP_ATTRIBUTE(rd_strm);
681         SETUP_ATTRIBUTE(rti);
682         SETUP_ATTRIBUTE(pcomp_en);
683
684         /* if you add an attribute but forget to increase SPI_NUM_ATTRS
685          * this bug will trigger */
686         BUG_ON(count > SPI_NUM_ATTRS);
687
688         i->attrs[count++] = &class_device_attr_revalidate;
689
690         i->attrs[count] = NULL;
691
692         return &i->t;
693 }
694 EXPORT_SYMBOL(spi_attach_transport);
695
696 void spi_release_transport(struct scsi_transport_template *t)
697 {
698         struct spi_internal *i = to_spi_internal(t);
699
700         kfree(i);
701 }
702 EXPORT_SYMBOL(spi_release_transport);
703
704
705 MODULE_AUTHOR("Martin Hicks");
706 MODULE_DESCRIPTION("SPI Transport Attributes");
707 MODULE_LICENSE("GPL");
708
709 module_init(spi_transport_init);
710 module_exit(spi_transport_exit);