~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/i2o/i2o_config.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * I2O Configuration Interface Driver
  3  *
  4  * (C) Copyright 1999   Red Hat Software
  5  *      
  6  * Written by Alan Cox, Building Number Three Ltd
  7  *
  8  * Modified 04/20/1999 by Deepak Saxena
  9  *   - Added basic ioctl() support
 10  * Modified 06/07/1999 by Deepak Saxena
 11  *   - Added software download ioctl (still testing)
 12  * Modified 09/10/1999 by Auvo Häkkinen
 13  *   - Changes to i2o_cfg_reply(), ioctl_parms()
 14  *   - Added ioct_validate()
 15  * Modified 09/30/1999 by Taneli Vähäkangas
 16  *   - Fixed ioctl_swdl()
 17  * Modified 10/04/1999 by Taneli Vähäkangas
 18  *   - Changed ioctl_swdl(), implemented ioctl_swul() and ioctl_swdel()
 19  * Modified 11/18/199 by Deepak Saxena
 20  *   - Added event managmenet support
 21  *
 22  * This program is free software; you can redistribute it and/or
 23  * modify it under the terms of the GNU General Public License
 24  * as published by the Free Software Foundation; either version
 25  * 2 of the License, or (at your option) any later version.
 26  */
 27 
 28 #include <linux/module.h>
 29 #include <linux/kernel.h>
 30 #include <linux/pci.h>
 31 #include <linux/i2o.h>
 32 #include <linux/errno.h>
 33 #include <linux/init.h>
 34 #include <linux/malloc.h>
 35 #include <linux/miscdevice.h>
 36 #include <linux/mm.h>
 37 #include <linux/spinlock.h>
 38 #include <linux/smp_lock.h>
 39 
 40 #include <asm/uaccess.h>
 41 #include <asm/io.h>
 42 
 43 static int i2o_cfg_context = -1;
 44 static void *page_buf;
 45 static void *i2o_buffer;
 46 static spinlock_t i2o_config_lock = SPIN_LOCK_UNLOCKED;
 47 struct wait_queue *i2o_wait_queue;
 48 
 49 #define MODINC(x,y) (x = x++ % y)
 50 
 51 struct i2o_cfg_info
 52 {
 53         struct file* fp;
 54         struct fasync_struct *fasync;
 55         struct i2o_evt_info event_q[I2O_EVT_Q_LEN];
 56         u16             q_in;           // Queue head index
 57         u16             q_out;          // Queue tail index
 58         u16             q_len;          // Queue length
 59         u16             q_lost;         // Number of lost events
 60         u32             q_id;           // Event queue ID...used as tx_context
 61         struct  i2o_cfg_info *next;
 62 };
 63 static struct i2o_cfg_info *open_files = NULL;
 64 static int i2o_cfg_info_id = 0;
 65 
 66 static int ioctl_getiops(unsigned long);
 67 static int ioctl_gethrt(unsigned long);
 68 static int ioctl_getlct(unsigned long);
 69 static int ioctl_parms(unsigned long, unsigned int);
 70 static int ioctl_html(unsigned long);
 71 static int ioctl_swdl(unsigned long);
 72 static int ioctl_swul(unsigned long);
 73 static int ioctl_swdel(unsigned long);
 74 static int ioctl_validate(unsigned long); 
 75 static int ioctl_evt_reg(unsigned long, struct file *);
 76 static int ioctl_evt_get(unsigned long, struct file *);
 77 static int cfg_fasync(int, struct file*, int);
 78 
 79 /*
 80  *      This is the callback for any message we have posted. The message itself
 81  *      will be returned to the message pool when we return from the IRQ
 82  *
 83  *      This runs in irq context so be short and sweet.
 84  */
 85 static void i2o_cfg_reply(struct i2o_handler *h, struct i2o_controller *c, struct i2o_message *m)
 86 {
 87         u32 *msg = (u32 *)m;
 88 
 89         if (msg[0] & MSG_FAIL) {
 90                 u32 *preserved_msg = (u32*)(c->mem_offset + msg[7]);
 91 
 92                 printk(KERN_ERR "i2o_config: IOP failed to process the msg.\n");
 93 
 94                 /* Release the preserved msg frame by resubmitting it as a NOP */
 95 
 96                 preserved_msg[0] = THREE_WORD_MSG_SIZE | SGL_OFFSET_0;
 97                 preserved_msg[1] = I2O_CMD_UTIL_NOP << 24 | HOST_TID << 12 | 0;
 98                 preserved_msg[2] = 0;
 99                 i2o_post_message(c, msg[7]);
100         }
101 
102         if (msg[4] >> 24)  // ReqStatus != SUCCESS
103                 i2o_report_status(KERN_INFO,"i2o_config", msg);
104 
105         if(m->function == I2O_CMD_UTIL_EVT_REGISTER)
106         {
107                 struct i2o_cfg_info *inf;
108 
109                 for(inf = open_files; inf; inf = inf->next)
110                         if(inf->q_id == msg[3])
111                                 break;
112 
113                 //
114                 // If this is the case, it means that we're getting
115                 // events for a file descriptor that's been close()'d
116                 // w/o the user unregistering for events first.
117                 // The code currently assumes that the user will 
118                 // take care of unregistering for events before closing
119                 // a file.
120                 // 
121                 // TODO: 
122                 // Should we track event registartion and deregister
123                 // for events when a file is close()'d so this doesn't
124                 // happen? That would get rid of the search through
125                 // the linked list since file->private_data could point
126                 // directly to the i2o_config_info data structure...but
127                 // it would mean having all sorts of tables to track
128                 // what each file is registered for...I think the
129                 // current method is simpler. - DS
130                 //                      
131                 if(!inf)
132                         return;
133 
134                 inf->event_q[inf->q_in].id.iop = c->unit;
135                 inf->event_q[inf->q_in].id.tid = m->target_tid;
136                 inf->event_q[inf->q_in].id.evt_mask = msg[4];
137 
138                 //
139                 // Data size = msg size - reply header
140                 //
141                 inf->event_q[inf->q_in].data_size = (m->size - 5) * 4;
142                 if(inf->event_q[inf->q_in].data_size)
143                         memcpy(inf->event_q[inf->q_in].evt_data, 
144                                 (unsigned char *)(msg + 5),
145                                 inf->event_q[inf->q_in].data_size);
146 
147                 spin_lock(&i2o_config_lock);
148                 MODINC(inf->q_in, I2O_EVT_Q_LEN);
149                 if(inf->q_len == I2O_EVT_Q_LEN)
150                 {
151                         MODINC(inf->q_out, I2O_EVT_Q_LEN);
152                         inf->q_lost++;
153                 }
154                 else
155                 {
156                         // Keep I2OEVTGET on another CPU from touching this
157                         inf->q_len++;
158                 }
159                 spin_unlock(&i2o_config_lock);
160                 
161 
162 //              printk(KERN_INFO "File %p w/id %d has %d events\n",
163 //                      inf->fp, inf->q_id, inf->q_len);        
164 
165                 kill_fasync(&inf->fasync, SIGIO, POLL_IN);
166         }
167 
168         return;
169 }
170 
171 /*
172  *      Each of these describes an i2o message handler. They are
173  *      multiplexed by the i2o_core code
174  */
175  
176 struct i2o_handler cfg_handler=
177 {
178         i2o_cfg_reply,
179         NULL,
180         NULL,
181         NULL,
182         "Configuration",
183         0,
184         0xffffffff      // All classes
185 };
186 
187 static long long cfg_llseek(struct file *file, long long offset, int origin)
188 {
189         return -ESPIPE;
190 }
191 
192 
193 static ssize_t cfg_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
194 {
195         printk(KERN_INFO "i2o_config write not yet supported\n");
196 
197         return 0;
198 }
199 
200 
201 static ssize_t cfg_read(struct file *file, char *buf, size_t count, loff_t *ptr)
202 {
203         return 0;
204 }
205 
206 /*
207  * IOCTL Handler
208  */
209 static int cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd,
210         unsigned long arg)
211 {
212         int ret;
213 
214         switch(cmd)
215         {       
216                 case I2OGETIOPS:
217                         ret = ioctl_getiops(arg);
218                         break;
219 
220                 case I2OHRTGET:
221                         ret = ioctl_gethrt(arg);
222                         break;
223 
224                 case I2OLCTGET:
225                         ret = ioctl_getlct(arg);
226                         break;
227 
228                 case I2OPARMSET:
229                         ret = ioctl_parms(arg, I2OPARMSET);
230                         break;
231 
232                 case I2OPARMGET:
233                         ret = ioctl_parms(arg, I2OPARMGET);
234                         break;
235 
236                 case I2OSWDL:
237                         ret = ioctl_swdl(arg);
238                         break;
239 
240                 case I2OSWUL:
241                         ret = ioctl_swul(arg);
242                         break;
243 
244                 case I2OSWDEL:
245                         ret = ioctl_swdel(arg);
246                         break;
247 
248                 case I2OVALIDATE:
249                         ret = ioctl_validate(arg);
250                         break;
251                         
252                 case I2OHTML:
253                         ret = ioctl_html(arg);
254                         break;
255 
256                 case I2OEVTREG:
257                         ret = ioctl_evt_reg(arg, fp);
258                         break;
259 
260                 case I2OEVTGET:
261                         ret = ioctl_evt_get(arg, fp);
262                         break;
263 
264                 default:
265                         ret = -EINVAL;
266         }
267 
268         return ret;
269 }
270 
271 int ioctl_getiops(unsigned long arg)
272 {
273         u8 *user_iop_table = (u8*)arg;
274         struct i2o_controller *c = NULL;
275         int i;
276         u8 foo[MAX_I2O_CONTROLLERS];
277 
278         if(!access_ok(VERIFY_WRITE, user_iop_table,  MAX_I2O_CONTROLLERS))
279                 return -EFAULT;
280 
281         for(i = 0; i < MAX_I2O_CONTROLLERS; i++)
282         {
283                 c = i2o_find_controller(i);
284                 if(c)
285                 {
286                         foo[i] = 1;
287                         i2o_unlock_controller(c);
288                 }
289                 else
290                 {
291                         foo[i] = 0;
292                 }
293         }
294 
295         __copy_to_user(user_iop_table, foo, MAX_I2O_CONTROLLERS);
296         return 0;
297 }
298 
299 int ioctl_gethrt(unsigned long arg)
300 {
301         struct i2o_controller *c;
302         struct i2o_cmd_hrtlct *cmd = (struct i2o_cmd_hrtlct*)arg;
303         struct i2o_cmd_hrtlct kcmd;
304         i2o_hrt *hrt;
305         int len;
306         u32 reslen;
307         int ret = 0;
308 
309         if(copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
310                 return -EFAULT;
311 
312         if(get_user(reslen, kcmd.reslen) < 0)
313                 return -EFAULT;
314 
315         if(kcmd.resbuf == NULL)
316                 return -EFAULT;
317 
318         c = i2o_find_controller(kcmd.iop);
319         if(!c)
320                 return -ENXIO;
321                 
322         hrt = (i2o_hrt *)c->hrt;
323 
324         i2o_unlock_controller(c);
325 
326         len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
327         
328         /* We did a get user...so assuming mem is ok...is this bad? */
329         put_user(len, kcmd.reslen);
330         if(len > reslen)
331                 ret = -ENOBUFS; 
332         if(copy_to_user(kcmd.resbuf, (void*)hrt, len))
333                 ret = -EFAULT;
334 
335         return ret;
336 }
337 
338 int ioctl_getlct(unsigned long arg)
339 {
340         struct i2o_controller *c;
341         struct i2o_cmd_hrtlct *cmd = (struct i2o_cmd_hrtlct*)arg;
342         struct i2o_cmd_hrtlct kcmd;
343         i2o_lct *lct;
344         int len;
345         int ret = 0;
346         u32 reslen;
347 
348         if(copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_hrtlct)))
349                 return -EFAULT;
350 
351         if(get_user(reslen, kcmd.reslen) < 0)
352                 return -EFAULT;
353 
354         if(kcmd.resbuf == NULL)
355                 return -EFAULT;
356 
357         c = i2o_find_controller(kcmd.iop);
358         if(!c)
359                 return -ENXIO;
360 
361         lct = (i2o_lct *)c->lct;
362         i2o_unlock_controller(c);
363 
364         len = (unsigned int)lct->table_size << 2;
365         put_user(len, kcmd.reslen);
366         if(len > reslen)
367                 ret = -ENOBUFS; 
368         else if(copy_to_user(kcmd.resbuf, (void*)lct, len))
369                 ret = -EFAULT;
370 
371         return ret;
372 }
373 
374 static int ioctl_parms(unsigned long arg, unsigned int type)
375 {
376         int ret = 0;
377         struct i2o_controller *c;
378         struct i2o_cmd_psetget *cmd = (struct i2o_cmd_psetget*)arg;
379         struct i2o_cmd_psetget kcmd;
380         u32 reslen;
381         u8 *ops;
382         u8 *res;
383         int len;
384 
385         u32 i2o_cmd = (type == I2OPARMGET ? 
386                                 I2O_CMD_UTIL_PARAMS_GET :
387                                 I2O_CMD_UTIL_PARAMS_SET);
388 
389         if(copy_from_user(&kcmd, cmd, sizeof(struct i2o_cmd_psetget)))
390                 return -EFAULT;
391 
392         if(get_user(reslen, kcmd.reslen))
393                 return -EFAULT;
394 
395         c = i2o_find_controller(kcmd.iop);
396         if(!c)
397                 return -ENXIO;
398 
399         ops = (u8*)kmalloc(kcmd.oplen, GFP_KERNEL);
400         if(!ops)
401         {
402                 i2o_unlock_controller(c);
403                 return -ENOMEM;
404         }
405 
406         if(copy_from_user(ops, kcmd.opbuf, kcmd.oplen))
407         {
408                 i2o_unlock_controller(c);
409                 kfree(ops);
410                 return -EFAULT;
411         }
412 
413         /*
414          * It's possible to have a _very_ large table
415          * and that the user asks for all of it at once...
416          */
417         res = (u8*)kmalloc(65536, GFP_KERNEL);
418         if(!res)
419         {
420                 i2o_unlock_controller(c);
421                 kfree(ops);
422                 return -ENOMEM;
423         }
424 
425         len = i2o_issue_params(i2o_cmd, c, kcmd.tid, 
426                                 ops, kcmd.oplen, res, 65536);
427         i2o_unlock_controller(c);
428         kfree(ops);
429         
430         if (len < 0) {
431                 kfree(res);
432                 return -EAGAIN;
433         }
434 
435         put_user(len, kcmd.reslen);
436         if(len > reslen)
437                 ret = -ENOBUFS;
438         else if(copy_to_user(cmd->resbuf, res, len))
439                 ret = -EFAULT;
440 
441         kfree(res);
442 
443         return ret;
444 }
445 
446 int ioctl_html(unsigned long arg)
447 {
448         struct i2o_html *cmd = (struct i2o_html*)arg;
449         struct i2o_html kcmd;
450         struct i2o_controller *c;
451         u8 *res = NULL;
452         void *query = NULL;
453         int ret = 0;
454         int token;
455         u32 len;
456         u32 reslen;
457         u32 msg[MSG_FRAME_SIZE/4];
458 
459         if(copy_from_user(&kcmd, cmd, sizeof(struct i2o_html)))
460         {
461                 printk(KERN_INFO "i2o_config: can't copy html cmd\n");
462                 return -EFAULT;
463         }
464 
465         if(get_user(reslen, kcmd.reslen) < 0)
466         {
467                 printk(KERN_INFO "i2o_config: can't copy html reslen\n");
468                 return -EFAULT;
469         }
470 
471         if(!kcmd.resbuf)                
472         {
473                 printk(KERN_INFO "i2o_config: NULL html buffer\n");
474                 return -EFAULT;
475         }
476 
477         c = i2o_find_controller(kcmd.iop);
478         if(!c)
479                 return -ENXIO;
480 
481         if(kcmd.qlen) /* Check for post data */
482         {
483                 query = kmalloc(kcmd.qlen, GFP_KERNEL);
484                 if(!query)
485                 {
486                         i2o_unlock_controller(c);
487                         return -ENOMEM;
488                 }
489                 if(copy_from_user(query, kcmd.qbuf, kcmd.qlen))
490                 {
491                         i2o_unlock_controller(c);
492                         printk(KERN_INFO "i2o_config: could not get query\n");
493                         kfree(query);
494                         return -EFAULT;
495                 }
496         }
497 
498         res = kmalloc(65536, GFP_KERNEL);
499         if(!res)
500         {
501                 i2o_unlock_controller(c);
502                 return -ENOMEM;
503         }
504 
505         msg[1] = (I2O_CMD_UTIL_CONFIG_DIALOG << 24)|HOST_TID<<12|kcmd.tid;
506         msg[2] = i2o_cfg_context;
507         msg[3] = 0;
508         msg[4] = kcmd.page;
509         msg[5] = 0xD0000000|65536;
510         msg[6] = virt_to_bus(res);
511         if(!kcmd.qlen) /* Check for post data */
512                 msg[0] = SEVEN_WORD_MSG_SIZE|SGL_OFFSET_5;
513         else
514         {
515                 msg[0] = NINE_WORD_MSG_SIZE|SGL_OFFSET_5;
516                 msg[5] = 0x50000000|65536;
517                 msg[7] = 0xD4000000|(kcmd.qlen);
518                 msg[8] = virt_to_bus(query);
519         }
520 
521         token = i2o_post_wait(c, msg, 9*4, 10);
522         if(token)
523         {
524                 printk(KERN_DEBUG "token = %#10x\n", token);
525                 i2o_unlock_controller(c);
526                 kfree(res);
527                 if(kcmd.qlen) kfree(query);
528 
529                 return -ETIMEDOUT;
530         }
531         i2o_unlock_controller(c);
532 
533         len = strnlen(res, 65536);
534         put_user(len, kcmd.reslen);
535         if(len > reslen)
536                 ret = -ENOMEM;
537         if(copy_to_user(kcmd.resbuf, res, len))
538                 ret = -EFAULT;
539 
540         kfree(res);
541         if(kcmd.qlen) 
542                 kfree(query);
543 
544         return ret;
545 }
546  
547 int ioctl_swdl(unsigned long arg)
548 {
549         struct i2o_sw_xfer kxfer;
550         struct i2o_sw_xfer *pxfer = (struct i2o_sw_xfer *)arg;
551         unsigned char maxfrag = 0, curfrag = 1;
552         unsigned char *buffer;
553         u32 msg[9];
554         unsigned int status = 0, swlen = 0, fragsize = 8192;
555         struct i2o_controller *c;
556 
557         if(copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
558                 return -EFAULT;
559 
560         if(get_user(swlen, kxfer.swlen) < 0)
561                 return -EFAULT;
562 
563         if(get_user(maxfrag, kxfer.maxfrag) < 0)
564                 return -EFAULT;
565 
566         if(get_user(curfrag, kxfer.curfrag) < 0)
567                 return -EFAULT;
568 
569         if(curfrag==maxfrag) fragsize = swlen-(maxfrag-1)*8192;
570 
571         if(!kxfer.buf || !access_ok(VERIFY_READ, kxfer.buf, fragsize))
572                 return -EFAULT;
573         
574         c = i2o_find_controller(kxfer.iop);
575         if(!c)
576                 return -ENXIO;
577 
578         buffer=kmalloc(fragsize, GFP_KERNEL);
579         if (buffer==NULL)
580         {
581                 i2o_unlock_controller(c);
582                 return -ENOMEM;
583         }
584         __copy_from_user(buffer, kxfer.buf, fragsize);
585 
586         msg[0]= NINE_WORD_MSG_SIZE | SGL_OFFSET_7;
587         msg[1]= I2O_CMD_SW_DOWNLOAD<<24 | HOST_TID<<12 | ADAPTER_TID;
588         msg[2]= (u32)cfg_handler.context;
589         msg[3]= 0;
590         msg[4]= (((u32)kxfer.flags)<<24) | (((u32)kxfer.sw_type)<<16) |
591                 (((u32)maxfrag)<<8) | (((u32)curfrag));
592         msg[5]= swlen;
593         msg[6]= kxfer.sw_id;
594         msg[7]= (0xD0000000 | fragsize);
595         msg[8]= virt_to_bus(buffer);
596 
597 //      printk("i2o_config: swdl frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
598         status = i2o_post_wait(c, msg, sizeof(msg), 60);
599 
600         i2o_unlock_controller(c);
601         kfree(buffer);
602         
603         if (status != I2O_POST_WAIT_OK)
604         {
605                 // it fails if you try and send frags out of order
606                 // and for some yet unknown reasons too
607                 printk(KERN_INFO "i2o_config: swdl failed, DetailedStatus = %d\n", status);
608                 return -ETIMEDOUT;
609         }
610 
611         return 0;
612 }
613 
614 int ioctl_swul(unsigned long arg)
615 {
616         struct i2o_sw_xfer kxfer;
617         struct i2o_sw_xfer *pxfer = (struct i2o_sw_xfer *)arg;
618         unsigned char maxfrag = 0, curfrag = 1;
619         unsigned char *buffer;
620         u32 msg[9];
621         unsigned int status = 0, swlen = 0, fragsize = 8192;
622         struct i2o_controller *c;
623         
624         if(copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
625                 return -EFAULT;
626                 
627         if(get_user(swlen, kxfer.swlen) < 0)
628                 return -EFAULT;
629                 
630         if(get_user(maxfrag, kxfer.maxfrag) < 0)
631                 return -EFAULT;
632                 
633         if(get_user(curfrag, kxfer.curfrag) < 0)
634                 return -EFAULT;
635         
636         if(curfrag==maxfrag) fragsize = swlen-(maxfrag-1)*8192;
637         
638         if(!kxfer.buf || !access_ok(VERIFY_WRITE, kxfer.buf, fragsize))
639                 return -EFAULT;
640                 
641         c = i2o_find_controller(kxfer.iop);
642         if(!c)
643                 return -ENXIO;
644                 
645         buffer=kmalloc(fragsize, GFP_KERNEL);
646         if (buffer==NULL)
647         {
648                 i2o_unlock_controller(c);
649                 return -ENOMEM;
650         }
651         
652         msg[0]= NINE_WORD_MSG_SIZE | SGL_OFFSET_7;
653         msg[1]= I2O_CMD_SW_UPLOAD<<24 | HOST_TID<<12 | ADAPTER_TID;
654         msg[2]= (u32)cfg_handler.context;
655         msg[3]= 0;
656         msg[4]= (u32)kxfer.flags<<24|(u32)kxfer.sw_type<<16|(u32)maxfrag<<8|(u32)curfrag;
657         msg[5]= swlen;
658         msg[6]= kxfer.sw_id;
659         msg[7]= (0xD0000000 | fragsize);
660         msg[8]= virt_to_bus(buffer);
661         
662 //      printk("i2o_config: swul frag %d/%d (size %d)\n", curfrag, maxfrag, fragsize);
663         status = i2o_post_wait(c, msg, sizeof(msg), 60);
664         i2o_unlock_controller(c);
665         
666         if (status != I2O_POST_WAIT_OK)
667         {
668                 kfree(buffer);
669                 printk(KERN_INFO "i2o_config: swul failed, DetailedStatus = %d\n", status);
670                 return -ETIMEDOUT;
671         }
672         
673         __copy_to_user(kxfer.buf, buffer, fragsize);
674         kfree(buffer);
675         
676         return 0;
677 }
678 
679 int ioctl_swdel(unsigned long arg)
680 {
681         struct i2o_controller *c;
682         struct i2o_sw_xfer kxfer, *pxfer = (struct i2o_sw_xfer *)arg;
683         u32 msg[7];
684         unsigned int swlen;
685         int token;
686         
687         if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
688                 return -EFAULT;
689                 
690         if (get_user(swlen, kxfer.swlen) < 0)
691                 return -EFAULT;
692                 
693         c = i2o_find_controller(kxfer.iop);
694         if (!c)
695                 return -ENXIO;
696 
697         msg[0] = SEVEN_WORD_MSG_SIZE | SGL_OFFSET_0;
698         msg[1] = I2O_CMD_SW_REMOVE<<24 | HOST_TID<<12 | ADAPTER_TID;
699         msg[2] = (u32)i2o_cfg_context;
700         msg[3] = 0;
701         msg[4] = (u32)kxfer.flags<<24 | (u32)kxfer.sw_type<<16;
702         msg[5] = swlen;
703         msg[6] = kxfer.sw_id;
704 
705         token = i2o_post_wait(c, msg, sizeof(msg), 10);
706         i2o_unlock_controller(c);
707         
708         if (token != I2O_POST_WAIT_OK)
709         {
710                 printk(KERN_INFO "i2o_config: swdel failed, DetailedStatus = %d\n", token);
711                 return -ETIMEDOUT;
712         }
713         
714         return 0;
715 }
716 
717 int ioctl_validate(unsigned long arg)
718 {
719         int token;
720         int iop = (int)arg;
721         u32 msg[4];
722         struct i2o_controller *c;
723 
724         c=i2o_find_controller(iop);
725         if (!c)
726                 return -ENXIO;
727 
728         msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
729         msg[1] = I2O_CMD_CONFIG_VALIDATE<<24 | HOST_TID<<12 | iop;
730         msg[2] = (u32)i2o_cfg_context;
731         msg[3] = 0;
732 
733         token = i2o_post_wait(c, msg, sizeof(msg), 10);
734         i2o_unlock_controller(c);
735 
736         if (token != I2O_POST_WAIT_OK)
737         {
738                 printk(KERN_INFO "Can't validate configuration, ErrorStatus = %d\n",
739                         token);
740                 return -ETIMEDOUT;
741         }
742 
743         return 0;
744 }   
745 
746 static int ioctl_evt_reg(unsigned long arg, struct file *fp)
747 {
748         u32 msg[5];
749         struct i2o_evt_id *pdesc = (struct i2o_evt_id *)arg;
750         struct i2o_evt_id kdesc;
751         struct i2o_controller *iop;
752         struct i2o_device *d;
753 
754         if (copy_from_user(&kdesc, pdesc, sizeof(struct i2o_evt_id)))
755                 return -EFAULT;
756 
757         /* IOP exists? */
758         iop = i2o_find_controller(kdesc.iop);
759         if(!iop)
760                 return -ENXIO;
761         i2o_unlock_controller(iop);
762 
763         /* Device exists? */
764         for(d = iop->devices; d; d = d->next)
765                 if(d->lct_data.tid == kdesc.tid)
766                         break;
767 
768         if(!d)
769                 return -ENODEV;
770 
771         msg[0] = FOUR_WORD_MSG_SIZE|SGL_OFFSET_0;
772         msg[1] = I2O_CMD_UTIL_EVT_REGISTER<<24 | HOST_TID<<12 | kdesc.tid;
773         msg[2] = (u32)i2o_cfg_context;
774         msg[3] = (u32)fp->private_data;
775         msg[4] = kdesc.evt_mask;
776 
777         i2o_post_this(iop, msg, 20);
778 
779         return 0;
780 }       
781 
782 static int ioctl_evt_get(unsigned long arg, struct file *fp)
783 {
784         u32 id = (u32)fp->private_data;
785         struct i2o_cfg_info *p = NULL;
786         struct i2o_evt_get *uget = (struct i2o_evt_get*)arg;
787         struct i2o_evt_get kget;
788         unsigned int flags;
789 
790         // access_ok doesn't check for NULL?!?!
791         if(!arg)
792                 return -EFAULT;
793         
794         if(!access_ok(VERIFY_WRITE, uget,  sizeof(struct i2o_evt_get)))
795                 return -EFAULT;
796 
797         for(p = open_files; p; p = p->next)
798                 if(p->q_id == id)
799                         break;
800 
801         if(!p->q_len)
802         {
803                 return -ENOENT;
804                 return 0;
805         }
806 
807         memcpy(&kget.info, &p->event_q[p->q_out], sizeof(struct i2o_evt_info));
808         MODINC(p->q_out, I2O_EVT_Q_LEN);
809         spin_lock_irqsave(&i2o_config_lock, flags);
810         p->q_len--;
811         kget.pending = p->q_len;
812         kget.lost = p->q_lost;
813         spin_unlock_irqrestore(&i2o_config_lock, flags);
814 
815         __copy_to_user(uget, &kget, sizeof(struct i2o_evt_get));
816 
817         return 0;
818 }
819 
820 static int cfg_open(struct inode *inode, struct file *file)
821 {
822         struct i2o_cfg_info *tmp = 
823                 (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info), GFP_KERNEL);
824         unsigned int flags;
825 
826         if(!tmp)
827                 return -ENOMEM;
828 
829         file->private_data = (void*)(i2o_cfg_info_id++);
830         tmp->fp = file;
831         tmp->fasync = NULL;
832         tmp->q_id = (u32)file->private_data;
833         tmp->q_len = 0;
834         tmp->q_in = 0;
835         tmp->q_out = 0;
836         tmp->q_lost = 0;
837         tmp->next = open_files;
838 
839         spin_lock_irqsave(&i2o_config_lock, flags);
840         open_files = tmp;
841         spin_unlock_irqrestore(&i2o_config_lock, flags);
842         
843         return 0;
844 }
845 
846 static int cfg_release(struct inode *inode, struct file *file)
847 {
848         u32 id = (u32)file->private_data;
849         struct i2o_cfg_info *p1, *p2;
850         unsigned int flags;
851 
852         lock_kernel();
853         p1 = p2 = NULL;
854 
855         spin_lock_irqsave(&i2o_config_lock, flags);
856         for(p1 = open_files; p1; )
857         {
858                 if(p1->q_id == id)
859                 {
860 
861                         if(p1->fasync)
862                                 cfg_fasync(-1, file, 0);
863                         if(p2)
864                                 p2->next = p1->next;
865                         else
866                                 open_files = p1->next;
867 
868                         kfree(p1);
869                         break;
870                 }
871                 p2 = p1;
872                 p1 = p1->next;
873         }
874         spin_unlock_irqrestore(&i2o_config_lock, flags);
875         unlock_kernel();
876 
877         return 0;
878 }
879 
880 static int cfg_fasync(int fd, struct file *fp, int on)
881 {
882         u32 id = (u32)fp->private_data;
883         struct i2o_cfg_info *p;
884 
885         for(p = open_files; p; p = p->next)
886                 if(p->q_id == id)
887                         break;
888 
889         if(!p)
890                 return -EBADF;
891 
892         return fasync_helper(fd, fp, on, &p->fasync);
893 }
894 
895 static struct file_operations config_fops =
896 {
897         owner:          THIS_MODULE,
898         llseek:         cfg_llseek,
899         read:           cfg_read,
900         write:          cfg_write,
901         ioctl:          cfg_ioctl,
902         open:           cfg_open,
903         release:        cfg_release,
904         fasync:         cfg_fasync,
905 };
906 
907 static struct miscdevice i2o_miscdev = {
908         I2O_MINOR,
909         "i2octl",
910         &config_fops
911 };      
912 
913 #ifdef MODULE
914 int init_module(void)
915 #else
916 int __init i2o_config_init(void)
917 #endif
918 {
919         printk(KERN_INFO "I2O configuration manager v 0.04.\n");
920         printk(KERN_INFO "  (C) Copyright 1999 Red Hat Software\n");
921         
922         if((page_buf = kmalloc(4096, GFP_KERNEL))==NULL)
923         {
924                 printk(KERN_ERR "i2o_config: no memory for page buffer.\n");
925                 return -ENOBUFS;
926         }
927         if(misc_register(&i2o_miscdev)==-1)
928         {
929                 printk(KERN_ERR "i2o_config: can't register device.\n");
930                 kfree(page_buf);
931                 return -EBUSY;
932         }
933         /*
934          *      Install our handler
935          */
936         if(i2o_install_handler(&cfg_handler)<0)
937         {
938                 kfree(page_buf);
939                 printk(KERN_ERR "i2o_config: handler register failed.\n");
940                 misc_deregister(&i2o_miscdev);
941                 return -EBUSY;
942         }
943         /*
944          *      The low 16bits of the transaction context must match this
945          *      for everything we post. Otherwise someone else gets our mail
946          */
947         i2o_cfg_context = cfg_handler.context;
948         return 0;
949 }
950 
951 #ifdef MODULE
952 
953 void cleanup_module(void)
954 {
955         misc_deregister(&i2o_miscdev);
956         
957         if(page_buf)
958                 kfree(page_buf);
959         if(i2o_cfg_context != -1)
960                 i2o_remove_handler(&cfg_handler);
961         if(i2o_buffer)
962                 kfree(i2o_buffer);
963 }
964  
965 EXPORT_NO_SYMBOLS;
966 MODULE_AUTHOR("Red Hat Software");
967 MODULE_DESCRIPTION("I2O Configuration");
968 
969 #endif
970 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.