chandev.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:88k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  *  drivers/s390/misc/chandev.c
  3.  *
  4.  *    Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  5.  *    Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
  6.  * 
  7.  *  Generic channel device initialisation support. 
  8.  */
  9. #define TRUE 1
  10. #define FALSE 0
  11. #define __KERNEL_SYSCALLS__
  12. #include <linux/module.h>
  13. #include <linux/config.h>
  14. #include <linux/types.h>
  15. #include <linux/ctype.h>
  16. #include <asm/uaccess.h>
  17. #include <linux/slab.h>
  18. #include <asm/irq.h>
  19. #include <linux/init.h>
  20. #include <linux/unistd.h>
  21. #include <asm/chandev.h>
  22. #include <linux/proc_fs.h>
  23. #include <linux/vmalloc.h>
  24. #include <asm/s390dyn.h>
  25. #include <asm/queue.h>
  26. #include <linux/kmod.h>
  27. #ifndef MIN
  28. #define MIN(a,b) ((a<b)?a:b)
  29. #endif
  30. #ifndef MAX
  31. #define MAX(a,b) ((a>b)?a:b)
  32. #endif
  33. typedef struct chandev_model_info chandev_model_info;
  34. struct chandev_model_info
  35. {
  36. struct chandev_model_info *next;
  37. chandev_type chan_type;
  38. s32 cu_type;      /* control unit type  -1 = don't care */
  39. s16 cu_model;     /* control unit model -1 = don't care */
  40. s32 dev_type;     /* device type -1 = don't care */
  41. s16 dev_model;    /* device model -1 = don't care */
  42. u8  max_port_no;
  43. int auto_msck_recovery;
  44. u8  default_checksum_received_ip_pkts;
  45. u8  default_use_hw_stats; /* where available e.g. lcs */
  46. devreg_t drinfo;
  47. };
  48. typedef struct chandev chandev;
  49. struct chandev
  50. {
  51. struct chandev *next;
  52. chandev_model_info *model_info;
  53. chandev_subchannel_info sch;
  54. int owned;
  55. };
  56. typedef struct chandev_noauto_range chandev_noauto_range;
  57. struct chandev_noauto_range
  58. {
  59. struct chandev_noauto_range *next;
  60. u16     lo_devno;
  61. u16     hi_devno;
  62. };
  63. typedef struct chandev_force chandev_force;
  64. struct chandev_force
  65. {
  66. struct chandev_force *next;
  67. chandev_type chan_type;
  68. s32     devif_num; /* -1 don't care, -2 we are forcing a range e.g. tr0 implies 0 */
  69.         u16     read_lo_devno;
  70. u16     write_hi_devno;
  71. u16     data_devno; /* only used by gigabit ethernet */
  72. s32     memory_usage_in_k;
  73.         s16     port_protocol_no; /* where available e.g. lcs,-1 don't care */
  74. u8      checksum_received_ip_pkts;
  75. u8      use_hw_stats; /* where available e.g. lcs */
  76. /* claw specific stuff */
  77. chandev_claw_info  claw;
  78. };
  79. typedef struct chandev_probelist chandev_probelist;
  80. struct chandev_probelist
  81. {
  82. struct chandev_probelist            *next;
  83. chandev_probefunc                   probefunc;
  84. chandev_shutdownfunc                shutdownfunc;
  85. chandev_msck_notification_func      msck_notfunc;
  86. chandev_type                        chan_type;
  87. int                                 devices_found;
  88. };
  89. #define default_msck_bits ((1<<(chandev_status_not_oper-1))|(1<<(chandev_status_no_path-1))|(1<<(chandev_status_revalidate-1))|(1<<(chandev_status_gone-1)))
  90. static char *msck_status_strs[]=
  91. {
  92. "good",
  93. "not_operational",
  94. "no_path",
  95. "revalidate",
  96. "device_gone"
  97. };
  98. typedef struct chandev_msck_range chandev_msck_range;
  99. struct chandev_msck_range
  100. {
  101. struct chandev_msck_range *next;
  102. u16     lo_devno;
  103. u16     hi_devno;
  104. int      auto_msck_recovery;
  105. };
  106. static chandev_msck_range *chandev_msck_range_head=NULL;
  107. typedef struct chandev_irqinfo chandev_irqinfo;
  108. struct chandev_irqinfo
  109. {
  110. chandev_irqinfo         *next;
  111. chandev_subchannel_info sch;
  112. chandev_msck_status     msck_status;
  113. void                    (*handler)(int, void *, struct pt_regs *);
  114. unsigned long           irqflags;
  115. void                    *dev_id;
  116. char                    devname[0];
  117. };
  118. chandev_irqinfo *chandev_irqinfo_head=NULL;
  119. typedef struct chandev_parms chandev_parms;
  120. struct chandev_parms
  121. {
  122. chandev_parms      *next;
  123. chandev_type       chan_type;
  124. u16                lo_devno;
  125. u16                hi_devno;
  126. char               parmstr[0];
  127. };
  128. static chandev_type chandev_persistent=0; 
  129. chandev_parms *chandev_parms_head=NULL;
  130. typedef struct chandev_activelist chandev_activelist;
  131. struct chandev_activelist
  132. {
  133. struct chandev_activelist        *next;
  134. chandev_irqinfo                  *read_irqinfo;
  135. chandev_irqinfo                  *write_irqinfo;
  136. chandev_irqinfo                  *data_irqinfo;
  137. chandev_probefunc                probefunc;
  138. chandev_shutdownfunc             shutdownfunc;
  139. chandev_msck_notification_func   msck_notfunc;
  140. chandev_unregfunc                unreg_dev;
  141. chandev_type                     chan_type;
  142. u8                               port_no;
  143. chandev_category                 category;
  144. s32                              memory_usage_in_k;
  145. void                             *dev_ptr;
  146. char                             devname[0];
  147. };
  148. static chandev_model_info *chandev_models_head=NULL;
  149. /* The only reason chandev_head is a queue is so that net devices */
  150. /* will be by default named in the order of their irqs */
  151. static qheader chandev_head={NULL,NULL};
  152. static chandev_noauto_range *chandev_noauto_head=NULL;
  153. static chandev_force *chandev_force_head=NULL;
  154. static chandev_probelist *chandev_probelist_head=NULL;
  155. static chandev_activelist *chandev_activelist_head=NULL;
  156. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  157. int chandev_use_devno_names=FALSE;
  158. #endif
  159. static int chandev_cautious_auto_detect=TRUE;
  160. static atomic_t chandev_conf_read=ATOMIC_INIT(FALSE);
  161. static atomic_t chandev_initialised=ATOMIC_INIT(FALSE);
  162. static unsigned long chandev_last_machine_check;
  163. static struct tq_struct chandev_msck_task_tq;
  164. static atomic_t chandev_msck_thread_lock;
  165. static atomic_t chandev_new_msck;
  166. static unsigned long chandev_last_startmsck_list_update;
  167. typedef enum
  168. {
  169. chandev_start,
  170. chandev_first_tag=chandev_start,
  171. chandev_msck,
  172. chandev_num_notify_tags
  173. } chandev_userland_notify_tag;
  174. static char *userland_notify_strs[]=
  175. {
  176. "start",
  177. "machine_check"
  178. };
  179. typedef struct chandev_userland_notify_list chandev_userland_notify_list;
  180. struct chandev_userland_notify_list
  181. {
  182. chandev_userland_notify_list    *next;
  183. chandev_userland_notify_tag      tag;
  184. chandev_msck_status              prev_status;
  185. chandev_msck_status              curr_status;
  186. char                      devname[0];
  187. };
  188. static chandev_userland_notify_list *chandev_userland_notify_head=NULL;
  189. static void chandev_read_conf_if_necessary(void);
  190. static void chandev_read_conf(void);
  191. #if LINUX_VERSION_CODE >=KERNEL_VERSION(2,3,0)
  192. typedef struct net_device  net_device;
  193. #else
  194. typedef struct device  net_device;
  195. static inline void init_waitqueue_head(wait_queue_head_t *q)
  196. {
  197. *q=NULL;
  198. }
  199. #endif
  200. #if LINUX_VERSION_CODE<KERNEL_VERSION(2,3,45)
  201. static __inline__ void netif_stop_queue(net_device *dev)
  202. {
  203. dev->tbusy=1;
  204. }
  205. static __inline__ void netif_start_queue(net_device *dev)
  206. {
  207. dev->tbusy=0;
  208. }
  209. #endif
  210. #define CHANDEV_INVALID_LOCK_OWNER            -1
  211. static long                 chandev_lock_owner;
  212. static int                  chandev_lock_cnt; 
  213. static spinlock_t           chandev_spinlock;
  214. #define CHANDEV_LOCK_DEBUG 0
  215. #if CHANDEV_LOCK_DEBUG && !defined(CONFIG_ARCH_S390X)
  216. #define CHANDEV_BACKTRACE_LOOPCNT 10
  217. void                        *chandev_first_lock_addr[CHANDEV_BACKTRACE_LOOPCNT],
  218.                     *chandev_last_lock_addr[CHANDEV_BACKTRACE_LOOPCNT],
  219.                     *chandev_last_unlock_addr[CHANDEV_BACKTRACE_LOOPCNT];
  220. #define CHANDEV_BACKTRACE(variable) 
  221. memset((variable),0,sizeof(void *)*CHANDEV_BACKTRACE_LOOPCNT); 
  222. (variable)[0]=__builtin_return_address(0); 
  223. if(((long)variable[0])&0x80000000)         
  224. {                                          
  225. (variable)[1]=__builtin_return_address(1); 
  226. if(((long)variable[1])&0x80000000)         
  227. {                                          
  228. (variable)[2]=__builtin_return_address(2); 
  229. if(((long)variable[2])&0x80000000)         
  230. {                                          
  231. (variable)[3]=__builtin_return_address(3); 
  232. if(((long)variable[3])&0x80000000)         
  233. {                                          
  234. (variable)[4]=__builtin_return_address(4); 
  235. if(((long)variable[4])&0x80000000)         
  236. {                                          
  237. (variable)[5]=__builtin_return_address(5); 
  238. if(((long)variable[5])&0x80000000)         
  239. {                                          
  240. (variable)[6]=__builtin_return_address(6); 
  241. if(((long)variable[6])&0x80000000)         
  242. {                                          
  243. (variable)[7]=__builtin_return_address(7); 
  244. if(((long)variable[7])&0x80000000)         
  245. {                                          
  246. (variable)[8]=__builtin_return_address(8); 
  247. if(((long)variable[8])&0x80000000)         
  248. {                                          
  249. (variable)[9]=__builtin_return_address(9); 
  250. }
  251. #else
  252. #define CHANDEV_BACKTRACE(variable)
  253. #endif
  254. typedef struct chandev_not_oper_struct chandev_not_oper_struct;
  255. struct  chandev_not_oper_struct
  256. {
  257. chandev_not_oper_struct *next;
  258. int irq;
  259. int status;
  260. };
  261. /* May as well try to keep machine checks in the order they happen so
  262.  * we use qheader for chandev_not_oper_head instead of list.
  263.  */
  264. static qheader chandev_not_oper_head={NULL,NULL};
  265. static spinlock_t           chandev_not_oper_spinlock;
  266. #define chandev_interrupt_check() 
  267. if(in_interrupt())                
  268.      printk(KERN_WARNING __FUNCTION__ " called under interrupt this shouldn't happenn")
  269. #define for_each(variable,head) 
  270. for((variable)=(head);(variable)!=NULL;(variable)=(variable)->next)
  271. #define for_each_allow_delete(variable,nextmember,head) 
  272. for((variable)=(head),(nextmember)=((head) ? (head)->next:NULL); 
  273. (variable)!=NULL; (variable)=(nextmember),(nextmember)=((nextmember) ? (nextmember->next) : NULL))
  274. #define for_each_allow_delete2(variable,nextmember,head) 
  275. for((variable)=(head);(variable)!=NULL;(variable)=(nextmember))
  276. static void chandev_lock(void)
  277. {
  278. eieio();
  279. chandev_interrupt_check();
  280. if(chandev_lock_owner!=(long)current)
  281. {
  282. while(!spin_trylock(&chandev_spinlock))
  283. schedule();
  284. chandev_lock_cnt=1;
  285. chandev_lock_owner=(long)current;
  286. CHANDEV_BACKTRACE(chandev_first_lock_addr)
  287. }
  288. else
  289. {
  290. chandev_lock_cnt++;
  291. CHANDEV_BACKTRACE(chandev_last_lock_addr)
  292. }
  293. if(chandev_lock_cnt<0||chandev_lock_cnt>100)
  294. {
  295. printk("odd lock_cnt %d lcs_chan_lock",chandev_lock_cnt);
  296. chandev_lock_cnt=1;
  297. }
  298. }
  299. static int chandev_full_unlock(void)
  300. {
  301. int ret_lock_cnt=chandev_lock_cnt;
  302. chandev_lock_cnt=0;
  303. chandev_lock_owner=CHANDEV_INVALID_LOCK_OWNER;
  304. spin_unlock(&chandev_spinlock);
  305. return(ret_lock_cnt);
  306. }
  307. static void chandev_unlock(void)
  308. {
  309. if(chandev_lock_owner!=(long)current)
  310. printk("chandev_unlock: current=%lx"
  311.       " chandev_lock_owner=%lx chandev_lock_cnt=%dn",
  312.       (long)current,
  313.       chandev_lock_owner,
  314.       chandev_lock_cnt);
  315. CHANDEV_BACKTRACE(chandev_last_unlock_addr)
  316. if(--chandev_lock_cnt==0)
  317. {
  318. chandev_lock_owner=CHANDEV_INVALID_LOCK_OWNER;
  319. spin_unlock(&chandev_spinlock);
  320. }
  321. if(chandev_lock_cnt<0)
  322. {
  323. printk("odd lock_cnt=%d in chan_unlock",chandev_lock_cnt);
  324. chandev_full_unlock();
  325. }
  326. }
  327. void *chandev_alloc(size_t size)
  328. {
  329. void *mem=kmalloc(size,GFP_ATOMIC);
  330. if(mem)
  331. memset(mem,0,size);
  332. return(mem);
  333. }
  334. static void chandev_add_to_list(list **listhead,void *member)
  335. {
  336. chandev_lock();
  337. add_to_list(listhead,member);
  338. chandev_unlock();
  339. }
  340. static void chandev_queuemember(qheader *qhead,void *member)
  341. {
  342. chandev_lock();
  343. enqueue_tail(qhead,(queue *)member);
  344. chandev_unlock();
  345. }
  346. static int chandev_remove_from_list(list **listhead,list *member)
  347. {
  348. int retval;
  349. chandev_lock();
  350. retval=remove_from_list(listhead,member);
  351. chandev_unlock();
  352. return(retval);
  353. }
  354. static int chandev_remove_from_queue(qheader *qhead,queue *member)
  355. {
  356. int retval;
  357. chandev_lock();
  358. retval=remove_from_queue(qhead,member);
  359. chandev_unlock();
  360. return(retval);
  361. }
  362. void chandev_free_listmember(list **listhead,list *member)
  363. {
  364. chandev_lock();
  365. if(member)
  366. {
  367. if(chandev_remove_from_list(listhead,member))
  368. kfree(member);
  369. else
  370. printk(KERN_CRIT"chandev_free_listmember detected nonexistant"
  371.        "listmember listhead=%p member %pn",listhead,member);
  372. }
  373. chandev_unlock();
  374. }
  375. void chandev_free_queuemember(qheader *qhead,queue *member)
  376. {
  377. chandev_lock();
  378. if(member)
  379. {
  380. if(chandev_remove_from_queue(qhead,member))
  381. kfree(member);
  382. else
  383. printk(KERN_CRIT"chandev_free_queuemember detected nonexistant"
  384.        "queuemember qhead=%p member %pn",qhead,member);
  385. }
  386. chandev_unlock();
  387. }
  388. void chandev_free_all_list(list **listhead)
  389. {
  390. list *head;
  391. chandev_lock();
  392. while((head=remove_listhead(listhead)))
  393. kfree(head);
  394. chandev_unlock();
  395. }
  396. void chandev_free_all_queue(qheader *qhead)
  397. {
  398. chandev_lock();
  399. while(qhead->head)
  400. chandev_free_queuemember(qhead,qhead->head);
  401. chandev_unlock();
  402. }
  403. static void chandev_wait_for_root_fs(void)
  404. {
  405. wait_queue_head_t      wait;
  406. init_waitqueue_head(&wait);
  407. /* We need to wait till there is a root filesystem */
  408. while(init_task.fs->root==NULL)
  409. {
  410. sleep_on_timeout(&wait,HZ);
  411. }
  412. }
  413. /* We are now hotplug compliant i.e. */
  414. /* we typically get called in /sbin/hotplug chandev our parameters */
  415. static int chandev_exec_start_script(void *unused)
  416. {
  417. char **argv,*tempname;
  418. int retval=-ENOMEM;
  419. int argc,loopcnt;
  420. size_t allocsize;
  421. chandev_userland_notify_list *member;
  422. wait_queue_head_t      wait;
  423. int                    have_tag[chandev_num_notify_tags]={FALSE,};
  424. chandev_userland_notify_tag tagidx;
  425. static char * envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
  426. init_waitqueue_head(&wait);
  427. strcpy(current->comm,"chandev_script");
  428. for(loopcnt=0;loopcnt<10&&(jiffies-chandev_last_startmsck_list_update)<HZ;loopcnt++)
  429. {
  430. sleep_on_timeout(&wait,HZ);
  431. }
  432. if(!chandev_userland_notify_head)
  433. return(0);
  434. chandev_lock();
  435. argc=2;
  436. for(tagidx=chandev_first_tag;tagidx<chandev_num_notify_tags;tagidx++)
  437. {
  438. for_each(member,chandev_userland_notify_head)
  439. {
  440. if(member->tag==tagidx)
  441. {
  442. switch(tagidx)
  443. {
  444. case chandev_start:
  445. argc++;
  446. break;
  447. case chandev_msck:
  448. argc+=3;
  449. break;
  450. default:
  451. }
  452. if(have_tag[tagidx]==FALSE)
  453. argc++;
  454. have_tag[tagidx]=TRUE;
  455. }
  456. }
  457. }
  458. allocsize=(argc+1)*sizeof(char *);
  459.         /* Warning possible stack overflow */
  460. /* We can't kmalloc the parameters here as execve will */
  461. /* not return if successful */
  462. argv=alloca(allocsize);
  463. if(argv)
  464. {
  465. memset(argv,0,allocsize);
  466. argv[0]=hotplug_path;
  467. argv[1]="chandev";
  468. argc=2;
  469. for(tagidx=chandev_first_tag;tagidx<chandev_num_notify_tags;tagidx++)
  470. {
  471. if(have_tag[tagidx])
  472. {
  473. argv[argc++]=userland_notify_strs[tagidx];
  474. for_each(member,chandev_userland_notify_head)
  475. {
  476. if(member->tag==tagidx)
  477. {
  478. tempname=alloca(strlen(member->devname)+1);
  479. if(tempname)
  480. {
  481. strcpy(tempname,member->devname);
  482. argv[argc++]=tempname;
  483. }
  484. else
  485. goto Fail;
  486. if(member->tag==chandev_msck)
  487. {
  488. argv[argc++]=msck_status_strs[member->prev_status];
  489. argv[argc++]=msck_status_strs[member->curr_status];
  490. }
  491. }
  492. }
  493. }
  494. }
  495. chandev_free_all_list((list **)&chandev_userland_notify_head);
  496. chandev_unlock();
  497. chandev_wait_for_root_fs();
  498. /* We are basically execve'ing here there normally is no */
  499. /* return */
  500. retval=exec_usermodehelper(hotplug_path, argv, envp);
  501. goto Fail2;
  502. }
  503.  Fail:
  504. chandev_unlock();
  505.  Fail2:
  506. return(retval);
  507. }
  508. void *chandev_allocstr(const char *str,size_t offset)
  509. {
  510. char *member;
  511. if((member=chandev_alloc(offset+strlen(str)+1)))
  512. {
  513. strcpy(&member[offset],str);
  514. }
  515. return((void *)member);
  516. }
  517. static int chandev_add_to_userland_notify_list(chandev_userland_notify_tag tag,
  518. char *devname, chandev_msck_status prev_status,chandev_msck_status curr_status)
  519. {
  520. chandev_userland_notify_list *member,*nextmember;
  521. int pid;
  522. chandev_lock();
  523. /* remove operations still outstanding for this device */
  524. for_each_allow_delete(member,nextmember,chandev_userland_notify_head)
  525. if(strcmp(member->devname,devname)==0)
  526. chandev_free_listmember((list **)&chandev_userland_notify_head,(list *)member);
  527. if((member=chandev_allocstr(devname,offsetof(chandev_userland_notify_list,devname))))
  528. {
  529. member->tag=tag;
  530. member->prev_status=prev_status;
  531. member->curr_status=curr_status;
  532. add_to_list((list **)&chandev_userland_notify_head,(list *)member);
  533. chandev_last_startmsck_list_update=jiffies;
  534. chandev_unlock();
  535. pid = kernel_thread(chandev_exec_start_script,NULL,SIGCHLD);
  536. if(pid<0)
  537. {
  538. printk("error making kernel thread for chandev_exec_start_scriptn");
  539. return(pid);
  540. }
  541. else
  542. return(0);
  543. }
  544. else
  545. {
  546. chandev_unlock();
  547. printk("chandev_add_to_startmscklist memory allocation failed devname=%sn",devname);
  548. return(-ENOMEM);
  549. }
  550. }
  551. int chandev_oper_func(int irq,devreg_t *dreg)
  552. {
  553. chandev_last_machine_check=jiffies;
  554. if(atomic_dec_and_test(&chandev_msck_thread_lock))
  555. {
  556. schedule_task(&chandev_msck_task_tq);
  557. }
  558. atomic_set(&chandev_new_msck,TRUE);
  559. return(0);
  560. }
  561. static void chandev_not_oper_handler(int irq,int status )
  562. {
  563. chandev_not_oper_struct *new_not_oper;
  564. chandev_last_machine_check=jiffies;
  565. if((new_not_oper=kmalloc(sizeof(chandev_not_oper_struct),GFP_ATOMIC)))
  566. {
  567. new_not_oper->irq=irq;
  568. new_not_oper->status=status;
  569. spin_lock(&chandev_not_oper_spinlock);
  570. enqueue_tail(&chandev_not_oper_head,(queue *)new_not_oper);
  571. spin_unlock(&chandev_not_oper_spinlock);
  572. if(atomic_dec_and_test(&chandev_msck_thread_lock))
  573. {
  574. schedule_task(&chandev_msck_task_tq);
  575. }
  576. }
  577. else
  578. printk("chandev_not_oper_handler failed to allocate memory & "
  579.        "lost a not operational interrupt %d %x",
  580.        irq,status);
  581. }
  582. chandev_irqinfo *chandev_get_irqinfo_by_irq(int irq)
  583. {
  584. chandev_irqinfo *curr_irqinfo;
  585. for_each(curr_irqinfo,chandev_irqinfo_head)
  586. if(irq==curr_irqinfo->sch.irq)
  587. return(curr_irqinfo);
  588. return(NULL);
  589. }
  590. chandev *chandev_get_by_irq(int irq)
  591. {
  592. chandev *curr_chandev;
  593. for_each(curr_chandev,(chandev *)chandev_head.head)
  594. if(curr_chandev->sch.irq==irq)
  595. {
  596. return(curr_chandev);
  597. }
  598. return(NULL);
  599. }
  600. chandev_activelist *chandev_get_activelist_by_irq(int irq)
  601. {
  602. chandev_activelist *curr_device;
  603. for_each(curr_device,chandev_activelist_head)
  604. {
  605. if(curr_device->read_irqinfo->sch.irq==irq||
  606.    curr_device->write_irqinfo->sch.irq==irq||
  607.    (curr_device->data_irqinfo&&curr_device->data_irqinfo->sch.irq==irq))
  608. return(curr_device);
  609. }
  610. return(NULL);
  611. }
  612. void chandev_remove_irqinfo_by_irq(unsigned int irq)
  613. {
  614. chandev_irqinfo *remove_irqinfo;
  615. chandev_activelist *curr_device;
  616. chandev_lock();
  617. /* remove any orphan irqinfo left lying around. */
  618.         if((remove_irqinfo=chandev_get_irqinfo_by_irq(irq)))
  619. {
  620. for_each(curr_device,chandev_activelist_head)
  621. {
  622. if(curr_device->read_irqinfo==remove_irqinfo)
  623. {
  624. curr_device->read_irqinfo=NULL;
  625. break;
  626. }
  627. if(curr_device->write_irqinfo==remove_irqinfo)
  628. {
  629. curr_device->write_irqinfo=NULL;
  630. break;
  631. }
  632. if(curr_device->data_irqinfo&&curr_device->data_irqinfo==remove_irqinfo)
  633. {
  634. curr_device->data_irqinfo=NULL;
  635. break;
  636. }
  637. }
  638. chandev_free_listmember((list **)&chandev_irqinfo_head,
  639.  (list *)remove_irqinfo);
  640. }
  641. chandev_unlock();
  642. }
  643. int chandev_add_schib_info(int irq,chandev_subchannel_info *sch)
  644. {
  645. schib_t *new_schib;
  646. if((new_schib=s390_get_schib(irq)))
  647. {
  648. sch->pim=new_schib->pmcw.pim;
  649. memcpy(&sch->chpid,&new_schib->pmcw.chpid,sizeof(sch->chpid));
  650. return(0);
  651. }
  652. return(-ENODEV);
  653. }
  654. int chandev_request_irq(unsigned int   irq,
  655.                       void           (*handler)(int, void *, struct pt_regs *),
  656.                       unsigned long  irqflags,
  657.                       const char    *devname,
  658.                       void          *dev_id)
  659. {
  660. chandev_irqinfo *new_irqinfo;
  661. chandev_activelist *curr_device;
  662. s390_dev_info_t         devinfo;
  663. int          retval;
  664. chandev_lock();
  665. if((curr_device=chandev_get_activelist_by_irq(irq)))
  666. {
  667. printk("chandev_request_irq failed devname=%s irq=%d "
  668.        "it already belongs to %s shutdown this device first.n",
  669.        devname,irq,curr_device->devname);
  670. chandev_unlock();
  671. return(-EPERM);
  672. }
  673. /* remove any orphan irqinfo left lying around. */
  674. chandev_remove_irqinfo_by_irq(irq);
  675. chandev_unlock();
  676. if((new_irqinfo=chandev_allocstr(devname,offsetof(chandev_irqinfo,devname))))
  677. {
  678. if((retval=get_dev_info_by_irq(irq,&devinfo))||
  679.    (retval=s390_request_irq_special(irq,handler,
  680. chandev_not_oper_handler,
  681. irqflags,devname,dev_id)))
  682. kfree(new_irqinfo);
  683. else
  684. {
  685. new_irqinfo->msck_status=chandev_status_good;
  686. new_irqinfo->sch.devno=devinfo.devno;
  687. new_irqinfo->sch.irq=irq;
  688. new_irqinfo->sch.cu_type=devinfo.sid_data.cu_type; /* control unit type */
  689. new_irqinfo->sch.cu_model=devinfo.sid_data.cu_model; /* control unit model */
  690. new_irqinfo->sch.dev_type=devinfo.sid_data.dev_type; /* device type */
  691. new_irqinfo->sch.dev_model=devinfo.sid_data.dev_model; /* device model */
  692. chandev_add_schib_info(irq,&new_irqinfo->sch);
  693. new_irqinfo->handler=handler;
  694. new_irqinfo->dev_id=dev_id;
  695. chandev_add_to_list((list **)&chandev_irqinfo_head,new_irqinfo);
  696. }
  697. }
  698. else
  699. {
  700. printk("chandev_request_irq memory allocation failed devname=%s irq=%dn",devname,irq);
  701. retval=-ENOMEM;
  702. }
  703. return(retval);
  704. }
  705. /* This should be safe to call even multiple times. */
  706. void chandev_free_irq(unsigned int irq, void *dev_id)
  707. {
  708. s390_dev_info_t devinfo;
  709. int err;
  710. /* remove any orphan irqinfo left lying around. */
  711. chandev_remove_irqinfo_by_irq(irq);
  712. if((err=get_dev_info_by_irq(irq,&devinfo)))
  713. {
  714. printk("chandev_free_irq get_dev_info_by_irq reported err=%X on irq %dn"
  715.        "should not happenn",err,irq);
  716. return;
  717.  }
  718. if(devinfo.status&DEVSTAT_DEVICE_OWNED)
  719.    free_irq(irq,dev_id);
  720. }
  721. /* This should be safe even if chandev_free_irq is already called by the device */
  722. void chandev_free_irq_by_irqinfo(chandev_irqinfo *irqinfo)
  723. {
  724. if(irqinfo)
  725. chandev_free_irq(irqinfo->sch.irq,irqinfo->dev_id);
  726. }
  727. void chandev_sprint_type_model(char *buff,s32 type,s16 model)
  728. {
  729. if(type==-1)
  730. strcpy(buff,"    *    ");
  731. else
  732. sprintf(buff," 0x%04x  ",(int)type);
  733. buff+=strlen(buff);
  734. if(model==-1)
  735. strcpy(buff,"    *   ");
  736. else
  737. sprintf(buff," 0x%02x  ",(int)model);
  738. }
  739. void chandev_sprint_devinfo(char *buff,s32 cu_type,s16 cu_model,s32 dev_type,s16 dev_model)
  740. {
  741. chandev_sprint_type_model(buff,cu_type,cu_model);
  742. chandev_sprint_type_model(&buff[strlen(buff)],dev_type,dev_model);
  743. }
  744. void chandev_remove_parms(chandev_type chan_type,int exact_match,int lo_devno)
  745. {
  746. chandev_parms      *curr_parms,*next_parms;
  747. chandev_lock();
  748. for_each_allow_delete(curr_parms,next_parms,chandev_parms_head)
  749. {
  750. if(((chan_type&(curr_parms->chan_type)&&!exact_match)||
  751.    (chan_type==(curr_parms->chan_type)&&exact_match))&&
  752.    (lo_devno==-1||lo_devno==curr_parms->lo_devno))
  753. chandev_free_listmember((list **)&chandev_parms_head,(list *)curr_parms);
  754. }
  755. chandev_unlock();
  756. }
  757. void chandev_add_parms(chandev_type chan_type,u16 lo_devno,u16 hi_devno,char *parmstr)
  758. {
  759. chandev_parms      *parms;
  760. if(lo_devno>hi_devno)
  761. {
  762. printk("chandev_add_parms detected bad device range lo_devno=0x%04x  hi_devno=0x%04xn,",
  763.        (int)lo_devno,(int)hi_devno);
  764. return;
  765. }
  766. chandev_lock();
  767. for_each(parms,chandev_parms_head)
  768. {
  769. if(chan_type&(parms->chan_type))
  770. {
  771. u16 lomax=MAX(parms->lo_devno,lo_devno),
  772. himin=MIN(parms->hi_devno,lo_devno);
  773. if(lomax<=himin)
  774. {
  775. chandev_unlock();
  776. printk("chandev_add_parms detected overlapping "
  777.        "parameter definitions for chan_type=0x%02x"
  778.        " lo_devno=0x%04x  hi_devno=0x%04xn,"
  779.        " do a del_parms.",chan_type,(int)lo_devno,(int)hi_devno);
  780. return;
  781. }
  782. }
  783. }
  784. chandev_unlock();
  785. if((parms=chandev_allocstr(parmstr,offsetof(chandev_parms,parmstr))))
  786. {
  787. parms->chan_type=chan_type;
  788. parms->lo_devno=lo_devno;
  789. parms->hi_devno=hi_devno;
  790. chandev_add_to_list((list **)&chandev_parms_head,(void *)parms);
  791. }
  792. else
  793. printk("chandev_add_parms memory request failedn");
  794. }
  795. void chandev_add_model(chandev_type chan_type,s32 cu_type,s16 cu_model,
  796.        s32 dev_type,s16 dev_model,u8 max_port_no,int auto_msck_recovery,
  797.        u8 default_checksum_received_ip_pkts,u8 default_use_hw_stats)
  798. {
  799. chandev_model_info *newmodel;
  800. int                err;
  801. char buff[40];
  802. if((newmodel=chandev_alloc(sizeof(chandev_model_info))))
  803. {
  804. devreg_t *drinfo=&newmodel->drinfo;
  805. newmodel->chan_type=chan_type;
  806. newmodel->cu_type=cu_type;
  807. newmodel->cu_model=cu_model;
  808. newmodel->dev_type=dev_type;
  809. newmodel->dev_model=dev_model;
  810. newmodel->max_port_no=max_port_no;
  811. newmodel->auto_msck_recovery=auto_msck_recovery;
  812. newmodel->default_checksum_received_ip_pkts=default_checksum_received_ip_pkts;
  813. newmodel->default_use_hw_stats=default_use_hw_stats; /* where available e.g. lcs */
  814. if(cu_type==-1&&dev_type==-1)
  815. {
  816. chandev_sprint_devinfo(buff,newmodel->cu_type,newmodel->cu_model,
  817.        newmodel->dev_type,newmodel->dev_model);
  818. printk(KERN_INFO"can't call s390_device_register for this device chan_type/chan_model/dev_type/dev_model %sn",buff);
  819. kfree(newmodel);
  820. return;
  821. }
  822. drinfo->flag=DEVREG_TYPE_DEVCHARS;
  823. if(cu_type!=-1)
  824. drinfo->flag|=DEVREG_MATCH_CU_TYPE;
  825. if(cu_model!=-1)
  826. drinfo->flag|=DEVREG_MATCH_CU_MODEL;
  827. if(dev_type!=-1)
  828. drinfo->flag|=DEVREG_MATCH_DEV_TYPE;
  829. if(dev_model!=-1)
  830. drinfo->flag|=DEVREG_MATCH_DEV_MODEL;
  831. drinfo->ci.hc.ctype=cu_type;
  832. drinfo->ci.hc.cmode=cu_model;
  833. drinfo->ci.hc.dtype=dev_type;
  834. drinfo->ci.hc.dmode=dev_model;
  835. drinfo->oper_func=chandev_oper_func;
  836. if((err=s390_device_register(&newmodel->drinfo)))
  837. {
  838. chandev_sprint_devinfo(buff,newmodel->cu_type,newmodel->cu_model,
  839.        newmodel->dev_type,newmodel->dev_model);
  840. printk("s390_device_register failed in chandev_add_model"
  841.        " this is nothing to worry about chan_type/chan_model/dev_type/dev_model %sn",buff);
  842. drinfo->oper_func=NULL;
  843. }
  844. chandev_add_to_list((list **)&chandev_models_head,newmodel);
  845. }
  846. }
  847. void chandev_remove(chandev *member)
  848. {
  849. chandev_free_queuemember(&chandev_head,(queue *)member);
  850. }
  851. void chandev_remove_all(void)
  852. {
  853. chandev_free_all_queue(&chandev_head);
  854. }
  855. void chandev_remove_model(chandev_model_info *model)
  856. {
  857. chandev *curr_chandev,*next_chandev;
  858. chandev_lock();
  859. for_each_allow_delete(curr_chandev,next_chandev,(chandev *)chandev_head.head)
  860. if(curr_chandev->model_info==model)
  861. chandev_remove(curr_chandev);
  862. if(model->drinfo.oper_func)
  863. s390_device_unregister(&model->drinfo);
  864. chandev_free_listmember((list **)&chandev_models_head,(list *)model);
  865. chandev_unlock();
  866. }
  867. void chandev_remove_all_models(void)
  868. {
  869. chandev_lock();
  870. while(chandev_models_head)
  871. chandev_remove_model(chandev_models_head);
  872. chandev_unlock();
  873. }
  874. void chandev_del_model(s32 cu_type,s16 cu_model,s32 dev_type,s16 dev_model)
  875. {
  876. chandev_model_info *curr_model,*next_model;
  877. chandev_lock();
  878. for_each_allow_delete(curr_model,next_model,chandev_models_head)
  879. if((curr_model->cu_type==cu_type||cu_type==-1)&&
  880.    (curr_model->cu_model==cu_model||cu_model==-1)&&
  881.    (curr_model->dev_type==dev_type||dev_type==-1)&&
  882.    (curr_model->dev_model==dev_model||dev_model==-1))
  883. chandev_remove_model(curr_model);
  884. chandev_unlock();
  885. }
  886. static void chandev_init_default_models(void)
  887. {
  888. /* Usually P390/Planter 3172 emulation assume maximum 16 to be safe. */
  889. chandev_add_model(chandev_type_lcs,0x3088,0x1,-1,-1,15,default_msck_bits,FALSE,FALSE);
  890. /* 3172/2216 Paralell the 2216 allows 16 ports per card the */
  891. /* the original 3172 only allows 4 we will assume the max of 16 */
  892. chandev_add_model(chandev_type_lcs|chandev_type_ctc,0x3088,0x8,-1,-1,15,default_msck_bits,FALSE,FALSE);
  893. /* 3172/2216 Escon serial the 2216 allows 16 ports per card the */
  894. /* the original 3172 only allows 4 we will assume the max of 16 */
  895. chandev_add_model(chandev_type_lcs|chandev_type_escon,0x3088,0x1F,-1,-1,15,default_msck_bits,FALSE,FALSE);
  896. /* Only 2 ports allowed on OSA2 cards model 0x60 */
  897. chandev_add_model(chandev_type_lcs,0x3088,0x60,-1,-1,1,default_msck_bits,FALSE,FALSE);
  898. /* qeth gigabit ethernet */
  899. chandev_add_model(chandev_type_qeth,0x1731,0x1,0x1732,0x1,0,default_msck_bits,FALSE,FALSE);
  900. chandev_add_model(chandev_type_qeth,0x1731,0x5,0x1732,0x5,0,default_msck_bits,FALSE,FALSE);
  901. /* Osa-D we currently aren't too emotionally involved with this */
  902. chandev_add_model(chandev_type_osad,0x3088,0x62,-1,-1,0,default_msck_bits,FALSE,FALSE);
  903. /* claw */
  904. chandev_add_model(chandev_type_claw,0x3088,0x61,-1,-1,0,default_msck_bits,FALSE,FALSE);
  905. /* ficon attached ctc */
  906. chandev_add_model(chandev_type_escon,0x3088,0x1E,-1,-1,0,default_msck_bits,FALSE,FALSE);
  907. }
  908. void chandev_del_noauto(u16 devno)
  909. {
  910. chandev_noauto_range *curr_noauto,*next_noauto;
  911. chandev_lock();
  912. for_each_allow_delete(curr_noauto,next_noauto,chandev_noauto_head)
  913. if(curr_noauto->lo_devno<=devno&&curr_noauto->hi_devno>=devno)
  914. chandev_free_listmember((list **)&chandev_noauto_head,(list *)curr_noauto); 
  915. chandev_unlock();
  916. }
  917. void chandev_del_msck(u16 devno)
  918. {
  919. chandev_msck_range *curr_msck_range,*next_msck_range;
  920. chandev_lock();
  921. for_each_allow_delete(curr_msck_range,next_msck_range,chandev_msck_range_head)
  922. if(curr_msck_range->lo_devno<=devno&&curr_msck_range->hi_devno>=devno)
  923. chandev_free_listmember((list **)&chandev_msck_range_head,(list *)curr_msck_range); 
  924. chandev_unlock();
  925. }
  926. void chandev_add(s390_dev_info_t  *newdevinfo,chandev_model_info *newmodelinfo)
  927. {
  928. chandev *new_chandev=NULL;
  929. if((new_chandev=chandev_alloc(sizeof(chandev))))
  930. {
  931. new_chandev->model_info=newmodelinfo;
  932. new_chandev->sch.devno=newdevinfo->devno;
  933. new_chandev->sch.irq=newdevinfo->irq;
  934. new_chandev->sch.cu_type=newdevinfo->sid_data.cu_type; /* control unit type */
  935. new_chandev->sch.cu_model=newdevinfo->sid_data.cu_model; /* control unit model */
  936. new_chandev->sch.dev_type=newdevinfo->sid_data.dev_type; /* device type */
  937. new_chandev->sch.dev_model=newdevinfo->sid_data.dev_model; /* device model */
  938. chandev_add_schib_info(newdevinfo->irq,&new_chandev->sch);
  939. new_chandev->owned=(newdevinfo->status&DEVSTAT_DEVICE_OWNED ? TRUE:FALSE);
  940. chandev_queuemember(&chandev_head,new_chandev);
  941. }
  942. }
  943. void chandev_unregister_probe(chandev_probefunc probefunc)
  944. {
  945. chandev_probelist *curr_probe,*next_probe;
  946. chandev_lock();
  947. for_each_allow_delete(curr_probe,next_probe,chandev_probelist_head)
  948. if(curr_probe->probefunc==probefunc)
  949. chandev_free_listmember((list **)&chandev_probelist_head,
  950. (list *)curr_probe);
  951. chandev_unlock();
  952. }
  953. void chandev_unregister_probe_by_chan_type(chandev_type chan_type)
  954. {
  955. chandev_probelist *curr_probe,*next_probe;
  956. chandev_lock();
  957. for_each_allow_delete(curr_probe,next_probe,chandev_probelist_head)
  958. if(curr_probe->chan_type==chan_type)
  959. chandev_free_listmember((list **)&chandev_probelist_head,
  960. (list *)curr_probe);
  961. chandev_unlock();
  962. }
  963. void chandev_reset(void)
  964. {
  965. chandev_lock();
  966. chandev_remove_all_models();
  967. chandev_free_all_list((list **)&chandev_noauto_head);
  968. chandev_free_all_list((list **)&chandev_msck_range_head);
  969. chandev_free_all_list((list **)&chandev_force_head);
  970. chandev_remove_parms(-1,FALSE,-1);
  971. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  972. chandev_use_devno_names=FALSE;
  973. #endif
  974. chandev_persistent=0;
  975. chandev_unlock();
  976. }
  977. int chandev_is_chandev(int irq,s390_dev_info_t *devinfo,chandev_force **forceinfo,chandev_model_info **ret_model)
  978. {
  979. chandev_force *curr_force;
  980. chandev_model_info *curr_model=NULL;
  981. int err;
  982. int retval=FALSE;
  983. if(forceinfo)
  984. *forceinfo=NULL;
  985. if(ret_model)
  986. *ret_model=NULL;
  987. if((err=get_dev_info_by_irq(irq,devinfo)))
  988. {
  989. printk("chandev_is_chandev get_dev_info_by_irq reported err=%X on irq %dn"
  990.        "should not happenn",err,irq);
  991. return FALSE;
  992. }
  993. chandev_lock();
  994. for_each(curr_model,chandev_models_head)
  995. {
  996. if(((curr_model->cu_type==devinfo->sid_data.cu_type)||(curr_model->cu_type==-1))&&
  997.    ((curr_model->cu_model==devinfo->sid_data.cu_model)||(curr_model->cu_model==-1))&&
  998.    ((curr_model->dev_type==devinfo->sid_data.dev_type)||(curr_model->dev_type==-1))&&
  999.    ((curr_model->dev_model==devinfo->sid_data.dev_model)||(curr_model->dev_model==-1)))
  1000. {
  1001. retval=TRUE;
  1002. if(ret_model)
  1003. *ret_model=curr_model;
  1004. break;
  1005. }
  1006. }
  1007. for_each(curr_force,chandev_force_head)
  1008. {
  1009. if(((curr_force->read_lo_devno==devinfo->devno)&&
  1010.    (curr_force->write_hi_devno==devinfo->devno)&&
  1011.     (curr_force->devif_num!=-2))||
  1012.    ((curr_force->read_lo_devno>=devinfo->devno)&&
  1013.     (curr_force->write_hi_devno<=devinfo->devno)&&
  1014.     (curr_force->devif_num==-2)))
  1015. {
  1016. if(forceinfo)
  1017. *forceinfo=curr_force;
  1018. break;
  1019. }
  1020. }
  1021. chandev_unlock();
  1022. return(retval);
  1023. }
  1024. void chandev_collect_devices(void)
  1025. {
  1026. int curr_irq,loopcnt=0;
  1027. s390_dev_info_t   curr_devinfo;
  1028. chandev_model_info *curr_model;
  1029.      
  1030. for(curr_irq=get_irq_first();curr_irq>=0; curr_irq=get_irq_next(curr_irq))
  1031. {
  1032. /* check read chandev
  1033.  * we had to do the cu_model check also because ctc devices
  1034.  * have the same cutype & after asking some people
  1035.  * the model numbers are given out pseudo randomly so
  1036.  * we can't just take a range of them also the dev_type & models are 0
  1037.  */
  1038. loopcnt++;
  1039. if(loopcnt>0x10000)
  1040. {
  1041. printk(KERN_ERR"chandev_collect_devices detected infinite loop bug in get_irq_nextn");
  1042. break;
  1043. }
  1044. chandev_lock();
  1045. if(chandev_is_chandev(curr_irq,&curr_devinfo,NULL,&curr_model))
  1046. chandev_add(&curr_devinfo,curr_model);
  1047. chandev_unlock();
  1048. }
  1049. }
  1050. int chandev_add_force(chandev_type chan_type,s32 devif_num,u16 read_lo_devno,
  1051. u16 write_hi_devno,u16 data_devno,s32 memory_usage_in_k,s16 port_protocol_no,u8 checksum_received_ip_pkts,
  1052. u8 use_hw_stats,char *host_name,char *adapter_name,char *api_type)
  1053. {
  1054. chandev_force *new_chandev_force;
  1055. if(devif_num==-2&&read_lo_devno>write_hi_devno)
  1056. {
  1057. printk("chandev_add_force detected bad device range lo_devno=0x%04x  hi_devno=0x%04xn,",
  1058.        (int)read_lo_devno,(int)write_hi_devno);
  1059. return(-1);
  1060. }
  1061. if(memory_usage_in_k<0)
  1062. {
  1063. printk("chandev_add_force memory_usage_in_k is badn");
  1064. return(-1);
  1065. }
  1066. if(chan_type==chandev_type_claw)
  1067. {
  1068. int host_name_len=strlen(host_name),
  1069. adapter_name_len=strlen(adapter_name),
  1070. api_type_len=strlen(api_type);
  1071. if(host_name_len>=CLAW_NAMELEN||host_name_len==0||
  1072.    adapter_name_len>=CLAW_NAMELEN||adapter_name_len==0||
  1073.    api_type_len>=CLAW_NAMELEN||api_type_len==0)
  1074. return(-1);
  1075. }
  1076. if((new_chandev_force=chandev_alloc(sizeof(chandev_force))))
  1077. {
  1078. new_chandev_force->chan_type=chan_type;
  1079. new_chandev_force->devif_num=devif_num;
  1080. new_chandev_force->read_lo_devno=read_lo_devno;
  1081. new_chandev_force->write_hi_devno=write_hi_devno;
  1082. new_chandev_force->data_devno=data_devno;
  1083. new_chandev_force->memory_usage_in_k=memory_usage_in_k;
  1084. new_chandev_force->port_protocol_no=port_protocol_no;
  1085. new_chandev_force->checksum_received_ip_pkts=checksum_received_ip_pkts;
  1086. new_chandev_force->use_hw_stats=use_hw_stats;
  1087. if(chan_type==chandev_type_claw)
  1088. {
  1089. strcpy(new_chandev_force->claw.host_name,host_name);
  1090. strcpy(new_chandev_force->claw.adapter_name,adapter_name);
  1091. strcpy(new_chandev_force->claw.api_type,api_type);
  1092. }
  1093. chandev_add_to_list((list **)&chandev_force_head,new_chandev_force);
  1094. }
  1095. return(0);
  1096. }
  1097. void chandev_del_force(int read_lo_devno)
  1098. {
  1099. chandev_force *curr_force,*next_force;
  1100. chandev_lock();
  1101. for_each_allow_delete(curr_force,next_force,chandev_force_head)
  1102. {
  1103. if(curr_force->read_lo_devno==read_lo_devno||read_lo_devno==-1)
  1104. chandev_free_listmember((list **)&chandev_force_head,
  1105. (list *)curr_force);
  1106. }
  1107. chandev_unlock();
  1108. }
  1109. void chandev_shutdown(chandev_activelist *curr_device)
  1110. {
  1111. int err=0;
  1112. chandev_lock();
  1113. /* unregister_netdev calls the dev->close so we shouldn't do this */
  1114. /* this otherwise we crash */
  1115. if(curr_device->unreg_dev)
  1116. {
  1117. curr_device->unreg_dev(curr_device->dev_ptr);
  1118. curr_device->unreg_dev=NULL;
  1119. }
  1120. if(curr_device->shutdownfunc)
  1121. {
  1122. err=curr_device->shutdownfunc(curr_device->dev_ptr);
  1123. }
  1124. if(err)
  1125. printk("chandev_shutdown unable to fully shutdown & unload %s err=%dn"
  1126.        "probably some upper layer still requires the device to existn",
  1127.        curr_device->devname,err);
  1128. else
  1129. {
  1130. chandev_free_irq_by_irqinfo(curr_device->read_irqinfo);
  1131. chandev_free_irq_by_irqinfo(curr_device->write_irqinfo);
  1132. if(curr_device->data_irqinfo)
  1133. chandev_free_irq_by_irqinfo(curr_device->data_irqinfo);
  1134. chandev_free_listmember((list **)&chandev_activelist_head,
  1135. (list *)curr_device);
  1136. }
  1137. chandev_unlock();
  1138. }
  1139. void chandev_shutdown_all(void)
  1140. {
  1141. while(chandev_activelist_head)
  1142. chandev_shutdown(chandev_activelist_head);
  1143. }
  1144. void chandev_shutdown_by_name(char *devname)
  1145. {
  1146. chandev_activelist *curr_device;
  1147. chandev_lock();
  1148. for_each(curr_device,chandev_activelist_head)
  1149. if(strcmp(devname,curr_device->devname)==0)
  1150. {
  1151. chandev_shutdown(curr_device);
  1152. break;
  1153. }
  1154. chandev_unlock();
  1155. }
  1156. static chandev_activelist *chandev_active(u16 devno)
  1157. {
  1158. chandev_activelist *curr_device;
  1159. for_each(curr_device,chandev_activelist_head)
  1160. if(curr_device->read_irqinfo->sch.devno==devno||
  1161.    curr_device->write_irqinfo->sch.devno==devno||
  1162.    (curr_device->data_irqinfo&&curr_device->data_irqinfo->sch.devno==devno))
  1163. {
  1164. return(curr_device);
  1165. }
  1166. return(NULL);
  1167. }
  1168. void chandev_shutdown_by_devno(u16 devno)
  1169. {
  1170. chandev_activelist *curr_device;
  1171. chandev_lock();
  1172. curr_device=chandev_active(devno);
  1173. if(curr_device)
  1174. chandev_shutdown(curr_device);
  1175. chandev_unlock();
  1176. }
  1177. int chandev_pack_args(char *str)
  1178. {
  1179. char *newstr=str,*next;
  1180. int strcnt=1;
  1181. while(*str)
  1182. {
  1183. next=str+1;
  1184. /*remove dead spaces */
  1185. if(isspace(*str)&&isspace(*next))
  1186. {
  1187. str++;
  1188. continue;
  1189. }
  1190. if(isspace(*str))
  1191. {
  1192. *str=',';
  1193. goto pack_dn;
  1194. }
  1195. if(((*str)==';')&&(*next))
  1196. {
  1197. strcnt++;
  1198. *str=0;
  1199. }
  1200. pack_dn:
  1201. *newstr++=*str++;
  1202. }
  1203. *newstr=0;
  1204. return(strcnt);
  1205. }
  1206. typedef enum
  1207. isnull=0,
  1208. isstr=1,
  1209. isnum=2,
  1210. iscomma=4,
  1211. } chandev_strval;
  1212. chandev_strval chandev_strcmp(char *teststr,char **str,long *endlong)
  1213. {
  1214. char *cur;
  1215. chandev_strval  retval=isnull;
  1216. int len=strlen(teststr);
  1217. if(strncmp(teststr,*str,len)==0)
  1218. {
  1219. *str+=len;
  1220. retval=isstr;
  1221. cur=*str;
  1222. *endlong=simple_strtol(cur,str,0);
  1223. if(cur!=*str)
  1224. retval|=isnum;
  1225. if(**str==',')
  1226. {
  1227. retval|=iscomma;
  1228. *str+=1;
  1229. }
  1230. else if(**str!=0)
  1231. retval=isnull;
  1232. }
  1233. return(retval);
  1234. }
  1235. int chandev_initdevice(chandev_probeinfo *probeinfo,void *dev_ptr,u8 port_no,char *devname,chandev_category category,chandev_unregfunc unreg_dev)
  1236. {
  1237. chandev_activelist *newdevice,*curr_device;
  1238. chandev_interrupt_check();
  1239. if(probeinfo->newdevice!=NULL)
  1240. {
  1241. printk("probeinfo->newdevice!=NULL in chandev_initdevice for %s",devname);
  1242. return(-EPERM);
  1243. }
  1244. chandev_lock();
  1245. for_each(curr_device,chandev_activelist_head)
  1246. {
  1247. if(strcmp(curr_device->devname,devname)==0)
  1248. {
  1249. printk("chandev_initdevice detected duplicate devicename %sn",devname);
  1250. chandev_unlock();
  1251. return(-EPERM);
  1252. }
  1253. }
  1254. if((newdevice=chandev_allocstr(devname,offsetof(chandev_activelist,devname))))
  1255. {
  1256. newdevice->read_irqinfo=chandev_get_irqinfo_by_irq(probeinfo->read.irq);
  1257. newdevice->write_irqinfo=chandev_get_irqinfo_by_irq(probeinfo->write.irq);
  1258. if(probeinfo->data_exists)
  1259. newdevice->data_irqinfo=chandev_get_irqinfo_by_irq(probeinfo->data.irq);
  1260. chandev_unlock();
  1261. if(newdevice->read_irqinfo==NULL||newdevice->write_irqinfo==NULL||
  1262.    (probeinfo->data_exists&&newdevice->data_irqinfo==NULL))
  1263. {
  1264. printk("chandev_initdevice, it appears that chandev_request_irq was not "
  1265.        "called for devname=%s read_irq=%d write_irq=%d data_irq=%dn",
  1266.        devname,probeinfo->read.irq,probeinfo->write.irq,probeinfo->data.irq);
  1267. kfree(newdevice);
  1268. return(-EPERM);
  1269. }
  1270. newdevice->chan_type=probeinfo->chan_type;
  1271. newdevice->dev_ptr=dev_ptr;
  1272. newdevice->port_no=port_no;
  1273. newdevice->memory_usage_in_k=probeinfo->memory_usage_in_k;
  1274. newdevice->category=category;
  1275. newdevice->unreg_dev=unreg_dev;
  1276. probeinfo->newdevice=newdevice;
  1277. return(0);
  1278. }
  1279. chandev_unlock();
  1280. return(-ENOMEM);
  1281. }
  1282. char *chandev_build_device_name(chandev_probeinfo *probeinfo,char *destnamebuff,char *basename,int buildfullname)
  1283. {
  1284. if (chandev_use_devno_names&&(!probeinfo->device_forced||probeinfo->devif_num==-1)) 
  1285. sprintf(destnamebuff,"%s%04x",basename,(int)probeinfo->read.devno);
  1286. else
  1287. {
  1288. if(probeinfo->devif_num==-1)
  1289. {
  1290. if(buildfullname)
  1291. {
  1292. int idx,len=strlen(basename);
  1293. chandev_activelist *curr_device;
  1294. for(idx=0;idx<0xffff;idx++)
  1295. {
  1296. for_each(curr_device,chandev_activelist_head)
  1297. {
  1298. if(strncmp(curr_device->devname,basename,len)==0)
  1299. {
  1300. char numbuff[10];
  1301. sprintf(numbuff,"%d",idx);
  1302. if(strcmp(&curr_device->devname[len],numbuff)==0)
  1303. goto next_idx;
  1304. }
  1305. }
  1306. sprintf(destnamebuff,"%s%d",basename,idx);
  1307. return(destnamebuff);
  1308. next_idx:
  1309. }
  1310. printk("chandev_build_device_name was usable to build a unique name for %sn",basename);
  1311. return(NULL);
  1312. }
  1313. else
  1314. sprintf(destnamebuff,"%s%%d",basename);
  1315. }
  1316. else
  1317. {
  1318. sprintf(destnamebuff,"%s%d",basename,(int)probeinfo->devif_num);
  1319. }
  1320. }
  1321. return(destnamebuff);
  1322. }
  1323. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1324. struct net_device *chandev_init_netdev(chandev_probeinfo *probeinfo,char *basename,
  1325. struct net_device *dev, int sizeof_priv,
  1326. struct net_device *(*init_netdevfunc)(struct net_device *dev, int sizeof_priv))
  1327. #else
  1328. struct device *chandev_init_netdev(chandev_probeinfo *probeinfo,char *basename,
  1329. struct device *dev, int sizeof_priv,
  1330. struct device *(*init_netdevfunc)(struct device *dev, int sizeof_priv))
  1331. #endif
  1332. {
  1333. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1334. struct net_device *retdevice=NULL;
  1335. int new_device = FALSE;
  1336. #else
  1337. struct device *retdevice=NULL;
  1338. #endif
  1339. chandev_interrupt_check();
  1340. if (!init_netdevfunc) 
  1341. {
  1342. printk("init_netdevfunc=NULL in chandev_init_netdev, it should not be valid.n");
  1343. return NULL;
  1344. }
  1345. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1346. /* Allocate a device if one is not provided. */
  1347.         if (dev == NULL) 
  1348. {
  1349. /* ensure 32-byte alignment of the private area */
  1350. int alloc_size = sizeof (*dev) + sizeof_priv + 31;
  1351. dev = (struct net_device *) kmalloc (alloc_size, GFP_KERNEL);
  1352. if (dev == NULL) 
  1353. {
  1354. printk(KERN_ERR "chandev_initnetdevice: Unable to allocate device memory.n");
  1355. return NULL;
  1356. }
  1357. memset(dev, 0, alloc_size);
  1358. if (sizeof_priv)
  1359. dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);
  1360. new_device=TRUE;
  1361. }
  1362. chandev_build_device_name(probeinfo,dev->name,basename,FALSE);
  1363. #endif
  1364. retdevice=init_netdevfunc(dev,sizeof_priv);
  1365. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1366. /* Register device if necessary */
  1367. /* we need to do this as init_netdev doesn't call register_netdevice */
  1368. /* for already allocated devices */
  1369. if (retdevice && new_device)
  1370. register_netdev(retdevice);
  1371. #endif
  1372. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1373. /* We allocated it, so we should free it on error */
  1374. if (!retdevice && new_device) 
  1375. kfree(dev);
  1376. #endif
  1377. return retdevice;
  1378. }
  1379. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1380. struct net_device *chandev_initnetdevice(chandev_probeinfo *probeinfo,u8 port_no,
  1381. struct net_device *dev, int sizeof_priv, char *basename, 
  1382. struct net_device *(*init_netdevfunc)(struct net_device *dev, int sizeof_priv),
  1383. void (*unreg_netdevfunc)(struct net_device *dev))
  1384. #else
  1385. struct device *chandev_initnetdevice(chandev_probeinfo *probeinfo,u8 port_no,
  1386. struct device *dev, int sizeof_priv, char *basename,
  1387. struct device *(*init_netdevfunc)(struct device *dev, int sizeof_priv),
  1388. void (*unreg_netdevfunc)(struct device *dev))
  1389. #endif
  1390. {
  1391. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1392. struct net_device *retdevice=NULL;
  1393. int new_device=(dev==NULL);
  1394. #else
  1395. struct device *retdevice=NULL;
  1396. #endif
  1397. if (!unreg_netdevfunc) 
  1398. {
  1399. printk("unreg_netdevfunc=NULL in chandev_initnetdevice, it should not be valid.n");
  1400. return NULL;
  1401. }
  1402. chandev_interrupt_check();
  1403. retdevice=chandev_init_netdev(probeinfo,basename,dev,sizeof_priv,init_netdevfunc);
  1404. if (retdevice) 
  1405. {
  1406. if (chandev_initdevice(probeinfo,retdevice,port_no,retdevice->name,
  1407.       chandev_category_network_device,(chandev_unregfunc)unreg_netdevfunc)) 
  1408. {
  1409. unreg_netdevfunc(retdevice);
  1410. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1411. /* We allocated it, so we should free it on error */
  1412. if(new_device)
  1413. kfree(dev);
  1414. #endif
  1415. retdevice = NULL;
  1416. }
  1417. }
  1418. return retdevice;
  1419. }
  1420. int chandev_compare_chpid_info(chandev_subchannel_info *chan1,chandev_subchannel_info *chan2)
  1421. {
  1422. return (chan1->pim!=chan2->pim || *chan1->chpid!=*chan2->chpid);
  1423. }
  1424. int chandev_compare_cu_dev_info(chandev_subchannel_info *chan1,chandev_subchannel_info *chan2)
  1425. {
  1426. return ((chan1->cu_type != chan2->cu_type)||
  1427. (chan1->cu_model != chan2->cu_model)||
  1428. (chan1->dev_type != chan2->dev_type)||
  1429. (chan1->dev_model != chan2->dev_model));
  1430. }
  1431. int chandev_compare_subchannel_info(chandev_subchannel_info *chan1,chandev_subchannel_info *chan2)
  1432. {
  1433. return((chan1->devno == chan2->devno) &&
  1434.        (chan1->cu_type == chan2->cu_type) &&
  1435.        (chan1->cu_model == chan2->cu_model) &&
  1436.        (chan1->dev_type == chan2->dev_type) &&
  1437.        (chan1->dev_model == chan2->dev_model) &&
  1438.        (chan1->pim == chan2->pim) &&
  1439.        (*chan1->chpid == *chan2->chpid));
  1440. }
  1441. int chandev_doprobe(chandev_force *force,chandev *read,
  1442. chandev *write,chandev *data)
  1443. {
  1444. chandev_probelist *probe;
  1445. chandev_model_info *model_info;
  1446. chandev_probeinfo probeinfo;
  1447. int               rc=-1,hint=-1;
  1448. chandev_activelist *newdevice;
  1449. chandev_probefunc  probefunc;
  1450. chandev_parms      *curr_parms;
  1451. chandev_model_info dummy_model_info;
  1452. memset(&probeinfo,0,sizeof(probeinfo));
  1453. memset(&dummy_model_info,0,sizeof(dummy_model_info));
  1454. probeinfo.device_forced=(force!=NULL);
  1455. probeinfo.chpid_info_inconsistent=chandev_compare_chpid_info(&read->sch,&write->sch)||
  1456.  (data&&chandev_compare_chpid_info(&read->sch,&data->sch));
  1457. probeinfo.cu_dev_info_inconsistent=chandev_compare_cu_dev_info(&read->sch,&write->sch)||
  1458.  (data&&chandev_compare_cu_dev_info(&read->sch,&data->sch));
  1459. if(read->model_info)
  1460. model_info=read->model_info;
  1461. else
  1462. {
  1463. dummy_model_info.chan_type=chandev_type_none;
  1464. dummy_model_info.max_port_no=16;
  1465. model_info=&dummy_model_info;
  1466. }
  1467. for_each(probe,chandev_probelist_head)
  1468. {
  1469. if(force)
  1470. probeinfo.chan_type = ( probe->chan_type & force->chan_type );
  1471. else
  1472. {
  1473. if(chandev_cautious_auto_detect)
  1474. probeinfo.chan_type = ( probe->chan_type == model_info->chan_type ? 
  1475.        probe->chan_type : chandev_type_none );
  1476. else
  1477. probeinfo.chan_type = ( probe->chan_type & model_info->chan_type );
  1478. }
  1479. if(probeinfo.chan_type && (force || ( !probeinfo.cu_dev_info_inconsistent &&
  1480.   ((probe->chan_type&(chandev_type_ctc|chandev_type_escon)) ||
  1481.    !probeinfo.chpid_info_inconsistent))))
  1482. {
  1483. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1484. if(chandev_use_devno_names)
  1485. probeinfo.devif_num=read->sch.devno;
  1486. else
  1487. #endif
  1488. probeinfo.devif_num=-1;
  1489. probeinfo.read=read->sch;
  1490. probeinfo.write=write->sch;
  1491. if(data)
  1492. {
  1493. probeinfo.data=data->sch;
  1494. probeinfo.data_exists=TRUE;
  1495. }
  1496. probeinfo.max_port_no=(force&&(force->port_protocol_no!=-1) ? 
  1497.       force->port_protocol_no : model_info->max_port_no);
  1498. for_each(curr_parms,chandev_parms_head)
  1499. {
  1500. if(probe->chan_type==curr_parms->chan_type&&
  1501.    read->sch.devno>=curr_parms->lo_devno&&
  1502. read->sch.devno<=curr_parms->hi_devno)
  1503. {
  1504. probeinfo.parmstr=curr_parms->parmstr;
  1505. break;
  1506. }
  1507. }
  1508. if(force)
  1509. {
  1510. if(force->chan_type==chandev_type_claw)
  1511. memcpy(&probeinfo.claw,&force->claw,sizeof(chandev_claw_info));
  1512. probeinfo.port_protocol_no=force->port_protocol_no;
  1513. if(force->devif_num==-1&&force->devif_num==-2)
  1514. probeinfo.devif_num=-1;
  1515. else
  1516. probeinfo.devif_num=force->devif_num;
  1517. probeinfo.memory_usage_in_k=force->memory_usage_in_k;
  1518. probeinfo.checksum_received_ip_pkts=force->checksum_received_ip_pkts;
  1519. probeinfo.use_hw_stats=force->use_hw_stats;
  1520. }
  1521. else
  1522. {
  1523. probeinfo.port_protocol_no=0;
  1524. probeinfo.checksum_received_ip_pkts=model_info->default_checksum_received_ip_pkts;
  1525. probeinfo.use_hw_stats=model_info->default_use_hw_stats;
  1526. probeinfo.memory_usage_in_k=0;
  1527. if(probe->chan_type&chandev_type_lcs)
  1528. {
  1529. hint=(read->sch.devno&0xFF)>>1;
  1530. if(hint>model_info->max_port_no)
  1531. {
  1532. /* The card is possibly emulated e.g P/390 */
  1533. /* or possibly configured to use a shared */
  1534. /* port configured by osa-sf. */
  1535. hint=0;
  1536. }
  1537. }
  1538. }
  1539. probeinfo.hint_port_no=hint;
  1540. probefunc=probe->probefunc;
  1541. rc=probefunc(&probeinfo);
  1542. if(rc==0)
  1543. {
  1544. newdevice=probeinfo.newdevice;
  1545. if(newdevice)
  1546. {
  1547. newdevice->probefunc=probe->probefunc;
  1548. newdevice->shutdownfunc=probe->shutdownfunc;
  1549. newdevice->msck_notfunc=probe->msck_notfunc;
  1550. probe->devices_found++;
  1551. chandev_add_to_list((list **)&chandev_activelist_head,
  1552.     newdevice);
  1553. chandev_add_to_userland_notify_list(chandev_start,
  1554.       newdevice->devname,chandev_status_good,chandev_status_good);
  1555. }
  1556. else
  1557. {
  1558. printk("chandev_initdevice either failed or wasn't called for device read_irq=0x%04xn",probeinfo.read.irq);
  1559. }
  1560. break;
  1561. }
  1562. }
  1563. }
  1564. chandev_remove(read);
  1565. chandev_remove(write);
  1566. if(data)
  1567. chandev_remove(data);
  1568. return(rc);
  1569. }
  1570. int chandev_request_irq_from_irqinfo(chandev_irqinfo *irqinfo,chandev *this_chandev)
  1571. {
  1572. int retval=s390_request_irq_special(irqinfo->sch.irq,
  1573.    irqinfo->handler,
  1574.    chandev_not_oper_handler,
  1575.    irqinfo->irqflags,
  1576.    irqinfo->devname,
  1577.    irqinfo->dev_id);
  1578. if(retval==0)
  1579. {
  1580. irqinfo->msck_status=chandev_status_good;
  1581. this_chandev->owned=TRUE;
  1582. }
  1583. return(retval);
  1584. }
  1585. void chandev_irqallocerr(chandev_irqinfo *irqinfo,int err)
  1586. {
  1587. printk("chandev_probe failed to realloc irq=%d for %s err=%dn",irqinfo->sch.irq,irqinfo->devname,err);
  1588. }
  1589. void chandev_call_notification_func(chandev_activelist *curr_device,chandev_irqinfo *curr_irqinfo,
  1590. chandev_msck_status prevstatus)
  1591. {
  1592. if(curr_irqinfo->msck_status!=prevstatus)
  1593. {
  1594. chandev_msck_status new_msck_status=curr_irqinfo->msck_status;
  1595. if(curr_irqinfo->msck_status==chandev_status_good)
  1596. {
  1597. if(curr_device->read_irqinfo->msck_status==chandev_status_good&&
  1598.    curr_device->write_irqinfo->msck_status==chandev_status_good)
  1599. {
  1600. if(curr_device->data_irqinfo)
  1601. {
  1602. if(curr_device->data_irqinfo->msck_status==chandev_status_good)
  1603. new_msck_status=chandev_status_all_chans_good;
  1604. }
  1605. else
  1606. new_msck_status=chandev_status_all_chans_good;
  1607. }
  1608. }
  1609. if(curr_device->msck_notfunc)
  1610. {
  1611. curr_device->msck_notfunc(curr_device->dev_ptr,
  1612.       curr_irqinfo->sch.irq,
  1613.       prevstatus,new_msck_status);
  1614. }
  1615. if(new_msck_status!=chandev_status_good)
  1616. {
  1617. /* No point in sending a machine check if only one channel is good */
  1618. chandev_add_to_userland_notify_list(chandev_msck,curr_device->devname,
  1619.       prevstatus,curr_irqinfo->msck_status);
  1620. }
  1621. }
  1622. }
  1623. int chandev_find_eligible_channels(chandev *first_chandev_to_check,
  1624.        chandev **read,chandev **write,chandev **data,chandev **next,
  1625.    chandev_type chan_type)
  1626. {
  1627. chandev *curr_chandev;
  1628. int eligible_found=FALSE,changed;
  1629. *next=first_chandev_to_check->next;
  1630. *read=*write=*data=NULL;
  1631. for_each(curr_chandev,first_chandev_to_check)
  1632. if((curr_chandev->sch.devno&1)==0&&curr_chandev->model_info->chan_type!=chandev_type_claw)
  1633. {
  1634. *read=curr_chandev;
  1635. if(chan_type==chandev_type_none)
  1636. chan_type=(*read)->model_info->chan_type;
  1637. break;
  1638. }
  1639. if(*read)
  1640. {
  1641. for_each(curr_chandev,(chandev *)chandev_head.head)
  1642. if((((*read)->sch.devno|1)==curr_chandev->sch.devno)&&
  1643.    (chandev_compare_cu_dev_info(&(*read)->sch,&curr_chandev->sch)==0)&&
  1644.    ((chan_type&(chandev_type_ctc|chandev_type_escon))||
  1645.     chandev_compare_chpid_info(&(*read)->sch,&curr_chandev->sch)==0))
  1646. {
  1647. *write=curr_chandev;
  1648. break;
  1649. }
  1650. }
  1651. if((chan_type&chandev_type_qeth))
  1652. {
  1653. if(*write)
  1654. {
  1655. for_each(curr_chandev,(chandev *)chandev_head.head)
  1656. if((curr_chandev!=*read&&curr_chandev!=*write)&&
  1657.    (chandev_compare_cu_dev_info(&(*read)->sch,&curr_chandev->sch)==0)&&
  1658.    (chandev_compare_chpid_info(&(*read)->sch,&curr_chandev->sch)==0))
  1659. {
  1660. *data=curr_chandev;
  1661. break;
  1662. }
  1663. if(*data)
  1664. eligible_found=TRUE;
  1665. }
  1666. }
  1667. else
  1668. if(*write)
  1669. eligible_found=TRUE;
  1670. if(eligible_found)
  1671. {
  1672. do
  1673. {
  1674. changed=FALSE;
  1675. if(*next&&
  1676.    ((*read&&(*read==*next))||
  1677.    (*write&&(*write==*next))||
  1678.    (*data&&(*data==*next))))
  1679. {
  1680. *next=(*next)->next;
  1681. changed=TRUE;
  1682. }
  1683. }while(changed==TRUE);
  1684. }
  1685. return(eligible_found);
  1686. }
  1687. chandev *chandev_get_free_chandev_by_devno(int devno)
  1688. {
  1689. chandev *curr_chandev;
  1690. if(devno==-1)
  1691. return(NULL);
  1692. for_each(curr_chandev,(chandev *)chandev_head.head)
  1693. if(curr_chandev->sch.devno==devno)
  1694. {
  1695. if(chandev_active(devno))
  1696. return(NULL);
  1697. else
  1698. return(curr_chandev);
  1699. }
  1700. return(NULL);
  1701. }
  1702. void chandev_probe(void)
  1703. {
  1704. chandev *read_chandev,*write_chandev,*data_chandev,*curr_chandev,*next_chandev;
  1705. chandev_force *curr_force;
  1706. chandev_noauto_range *curr_noauto;
  1707. chandev_activelist *curr_device;
  1708. chandev_irqinfo *curr_irqinfo;
  1709. s390_dev_info_t curr_devinfo;
  1710. int  err;
  1711. int auto_msck_recovery;
  1712. chandev_msck_status prevstatus;
  1713. chandev_msck_range *curr_msck_range;
  1714. chandev_interrupt_check();
  1715. chandev_read_conf_if_necessary();
  1716. chandev_collect_devices();
  1717. chandev_lock();
  1718. for_each(curr_irqinfo,chandev_irqinfo_head)
  1719. {
  1720. if((curr_device=chandev_get_activelist_by_irq(curr_irqinfo->sch.irq)))
  1721. {
  1722. prevstatus=curr_irqinfo->msck_status;
  1723. if(curr_irqinfo->msck_status!=chandev_status_good)
  1724. {
  1725. curr_chandev=chandev_get_by_irq(curr_irqinfo->sch.irq);
  1726. if(curr_chandev)
  1727. {
  1728. auto_msck_recovery=curr_chandev->model_info->
  1729. auto_msck_recovery;
  1730. }
  1731. else
  1732. goto remove;
  1733. for_each(curr_msck_range,chandev_msck_range_head)
  1734. {
  1735. if(curr_msck_range->lo_devno<=
  1736.    curr_irqinfo->sch.devno&&
  1737.    curr_msck_range->hi_devno>=
  1738.    curr_irqinfo->sch.devno)
  1739. {
  1740. auto_msck_recovery=
  1741. curr_msck_range->
  1742. auto_msck_recovery;
  1743. break;
  1744. }
  1745. }
  1746. if((1<<(curr_irqinfo->msck_status-1))&auto_msck_recovery)
  1747. {
  1748. if(curr_irqinfo->msck_status==chandev_status_revalidate)
  1749. {
  1750. if((get_dev_info_by_irq(curr_irqinfo->sch.irq,&curr_devinfo)==0))
  1751. {
  1752. curr_irqinfo->sch.devno=curr_devinfo.devno;
  1753. curr_irqinfo->msck_status=chandev_status_good;
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if(curr_chandev)
  1759. {
  1760. /* Has the device reappeared */
  1761. if(chandev_compare_subchannel_info(
  1762. &curr_chandev->sch,
  1763. &curr_device->read_irqinfo->sch)||
  1764.    chandev_compare_subchannel_info(
  1765. &curr_chandev->sch,
  1766. &curr_device->write_irqinfo->sch)||
  1767.    (curr_device->data_irqinfo&&
  1768.     chandev_compare_subchannel_info(
  1769.     &curr_chandev->sch,
  1770.     &curr_device->data_irqinfo->sch)))
  1771. {
  1772. if((err=chandev_request_irq_from_irqinfo(curr_irqinfo,curr_chandev))==0)
  1773. curr_irqinfo->msck_status=chandev_status_good;
  1774. else
  1775. chandev_irqallocerr(curr_irqinfo,err);
  1776. }
  1777. }
  1778. }
  1779. }
  1780. }
  1781. chandev_call_notification_func(curr_device,curr_irqinfo,prevstatus);
  1782. }
  1783. /* This is required because the device can go & come back */
  1784.                 /* even before we realize it is gone owing to the waits in our kernel threads */
  1785. /* & the device will be marked as not owned but its status will be good */
  1786.                 /* & an attempt to accidently reprobe it may be done. */ 
  1787. remove:
  1788. chandev_remove(chandev_get_by_irq(curr_irqinfo->sch.irq));
  1789. }
  1790. /* extra sanity */
  1791. for_each_allow_delete(curr_chandev,next_chandev,(chandev *)chandev_head.head)
  1792. if(curr_chandev->owned)
  1793. chandev_remove(curr_chandev);
  1794. for_each(curr_force,chandev_force_head)
  1795. {
  1796. if(curr_force->devif_num==-2)
  1797. {
  1798. for_each_allow_delete2(curr_chandev,next_chandev,(chandev *)chandev_head.head)
  1799. {
  1800. if(chandev_find_eligible_channels(curr_chandev,&read_chandev,
  1801.   &write_chandev,&data_chandev,
  1802.   &next_chandev,
  1803.   curr_force->chan_type));
  1804. {
  1805. if((curr_force->read_lo_devno>=read_chandev->sch.devno)&&
  1806.    (curr_force->write_hi_devno<=read_chandev->sch.devno)&&
  1807.    (curr_force->read_lo_devno>=write_chandev->sch.devno)&&
  1808.    (curr_force->write_hi_devno<=write_chandev->sch.devno)&&
  1809.    (!data_chandev||(data_chandev&&
  1810.    (curr_force->read_lo_devno>=data_chandev->sch.devno)&&
  1811.    (curr_force->write_hi_devno<=data_chandev->sch.devno))))
  1812. chandev_doprobe(curr_force,read_chandev,write_chandev,
  1813. data_chandev);
  1814. }
  1815. }
  1816. }
  1817. else
  1818. {
  1819. read_chandev=chandev_get_free_chandev_by_devno(curr_force->read_lo_devno);
  1820. if(read_chandev)
  1821. {
  1822. write_chandev=chandev_get_free_chandev_by_devno(curr_force->write_hi_devno);
  1823. if(write_chandev)
  1824. {
  1825. if(curr_force->chan_type==chandev_type_qeth)
  1826. {
  1827. data_chandev=chandev_get_free_chandev_by_devno(curr_force->data_devno);
  1828. if(data_chandev==NULL)
  1829. printk("chandev_probe unable to force gigabit_ethernet driver invalid device  no 0x%04x givenn",curr_force->data_devno);
  1830. }
  1831. else
  1832. data_chandev=NULL;
  1833. chandev_doprobe(curr_force,read_chandev,write_chandev,
  1834. data_chandev);
  1835. }
  1836. }
  1837. }
  1838. }
  1839. for_each_allow_delete(curr_chandev,next_chandev,(chandev *)chandev_head.head)
  1840. {
  1841. for_each(curr_noauto,chandev_noauto_head)
  1842. {
  1843. if(curr_chandev->sch.devno>=curr_noauto->lo_devno&&
  1844.    curr_chandev->sch.devno<=curr_noauto->hi_devno)
  1845. {
  1846. chandev_remove(curr_chandev);
  1847. break;
  1848. }
  1849. }
  1850. }
  1851. for_each_allow_delete2(curr_chandev,next_chandev,(chandev *)chandev_head.head)
  1852. {
  1853. if(chandev_find_eligible_channels(curr_chandev,&read_chandev,
  1854.   &write_chandev,&data_chandev,
  1855.   &next_chandev,
  1856.   chandev_type_none))
  1857. chandev_doprobe(NULL,read_chandev,write_chandev,
  1858. data_chandev);
  1859. }
  1860. chandev_remove_all();
  1861. chandev_unlock();
  1862. }
  1863. static void chandev_not_oper_func(int irq,int status)
  1864. {
  1865. chandev_irqinfo *curr_irqinfo;
  1866. chandev_activelist *curr_device;
  1867. chandev_lock();
  1868. for_each(curr_irqinfo,chandev_irqinfo_head)
  1869. if(curr_irqinfo->sch.irq==irq)
  1870. {
  1871. chandev_msck_status prevstatus=curr_irqinfo->msck_status;
  1872. switch(status)
  1873. {
  1874. /* Currently defined but not used in kernel */
  1875. /* Despite being in specs */
  1876. case DEVSTAT_NOT_OPER:
  1877. curr_irqinfo->msck_status=chandev_status_not_oper;
  1878. break;
  1879. #ifdef DEVSTAT_NO_PATH
  1880. /* Kernel hasn't this defined currently. */
  1881. /* Despite being in specs */
  1882. case DEVSTAT_NO_PATH:
  1883. curr_irqinfo->msck_status=chandev_status_no_path;
  1884. break;
  1885. #endif
  1886. case DEVSTAT_REVALIDATE:
  1887. curr_irqinfo->msck_status=chandev_status_revalidate;
  1888. break;
  1889. case DEVSTAT_DEVICE_GONE:
  1890. curr_irqinfo->msck_status=chandev_status_gone;
  1891. break;
  1892.                         }
  1893.                         if((curr_device=chandev_get_activelist_by_irq(irq)))
  1894. chandev_call_notification_func(curr_device,curr_irqinfo,prevstatus);
  1895.   else
  1896. printk("chandev_not_oper_func received channel check for unowned irq %d",irq);
  1897. }
  1898. chandev_unlock();
  1899. }
  1900. static int chandev_msck_thread(void *unused)
  1901. {
  1902. int loopcnt,not_oper_probe_required=FALSE;
  1903. wait_queue_head_t    wait;
  1904. chandev_not_oper_struct *new_not_oper;
  1905. /* This loop exists because machine checks tend to come in groups & we have
  1906.            to wait for the other devnos to appear also */
  1907. init_waitqueue_head(&wait);
  1908. for(loopcnt=0;loopcnt<10||(jiffies-chandev_last_machine_check)<HZ;loopcnt++)
  1909. {
  1910. sleep_on_timeout(&wait,HZ);
  1911. }
  1912. atomic_set(&chandev_msck_thread_lock,1);
  1913. while(!atomic_compare_and_swap(TRUE,FALSE,&chandev_new_msck));
  1914. {
  1915. chandev_probe();
  1916. }
  1917. while(TRUE)
  1918. {
  1919. unsigned long        flags; 
  1920. spin_lock_irqsave(&chandev_not_oper_spinlock,flags);
  1921. new_not_oper=(chandev_not_oper_struct *)dequeue_head(&chandev_not_oper_head);
  1922. spin_unlock_irqrestore(&chandev_not_oper_spinlock,flags);
  1923. if(new_not_oper)
  1924. {
  1925. chandev_not_oper_func(new_not_oper->irq,new_not_oper->status);
  1926. not_oper_probe_required=TRUE;
  1927. kfree(new_not_oper);
  1928. }
  1929. else
  1930. break;
  1931. }
  1932. if(not_oper_probe_required)
  1933. chandev_probe();
  1934. return(0);
  1935. }
  1936. static void chandev_msck_task(void *unused)
  1937. {
  1938. if(kernel_thread(chandev_msck_thread,NULL,SIGCHLD)<0)
  1939. {
  1940. atomic_set(&chandev_msck_thread_lock,1);
  1941. printk("error making chandev_msck_thread kernel threadn");
  1942. }
  1943. }
  1944. static char *argstrs[]=
  1945. {
  1946. "noauto",
  1947. "del_noauto",
  1948. "ctc",
  1949. "escon",
  1950. "lcs",
  1951. "osad",
  1952. "qeth",
  1953. "claw",
  1954. "add_parms",
  1955. "del_parms",
  1956. "del_force",
  1957. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1958. "use_devno_names",
  1959. "dont_use_devno_names",
  1960. #endif
  1961. "cautious_auto_detect",
  1962. "non_cautious_auto_detect",
  1963. "add_model",
  1964. "del_model",
  1965. "auto_msck",
  1966. "del_auto_msck",
  1967. "del_all_models",
  1968. "reset_conf_clean",
  1969. "reset_conf",
  1970. "shutdown",
  1971. "reprobe",
  1972. "unregister_probe",
  1973. "unregister_probe_by_chan_type",
  1974. "read_conf",
  1975. "dont_read_conf",
  1976. "persist"
  1977. };
  1978. typedef enum
  1979. {
  1980. stridx_mult=256,
  1981. first_stridx=0,
  1982. noauto_stridx=first_stridx,
  1983. del_noauto_stridx,
  1984. ctc_stridx,
  1985. escon_stridx,
  1986. lcs_stridx,
  1987. osad_stridx,
  1988.         qeth_stridx,
  1989. claw_stridx,
  1990. add_parms_stridx,
  1991. del_parms_stridx,
  1992. del_force_stridx,
  1993. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  1994. use_devno_names_stridx,
  1995. dont_use_devno_names_stridx,
  1996. #endif
  1997. cautious_auto_detect_stridx,
  1998. non_cautious_auto_detect_stridx,
  1999. add_model_stridx,
  2000. del_model_stridx,
  2001. auto_msck_stridx,
  2002. del_auto_msck_stridx,
  2003. del_all_models_stridx,
  2004. reset_conf_clean_stridx,
  2005. reset_conf_stridx,
  2006. shutdown_stridx,
  2007. reprobe_stridx,
  2008. unregister_probe_stridx,
  2009. unregister_probe_by_chan_type_stridx,
  2010. read_conf_stridx,
  2011. dont_read_conf_stridx,
  2012. persist_stridx,
  2013. last_stridx,
  2014. } chandev_str_enum;
  2015. void chandev_add_noauto(u16 lo_devno,u16 hi_devno)
  2016. {
  2017. chandev_noauto_range *new_range;
  2018. if((new_range=chandev_alloc(sizeof(chandev_noauto_range))))
  2019. {
  2020. new_range->lo_devno=lo_devno;
  2021. new_range->hi_devno=hi_devno;
  2022. chandev_add_to_list((list **)&chandev_noauto_head,new_range);
  2023. }
  2024. }
  2025. void chandev_add_msck_range(u16 lo_devno,u16 hi_devno,int auto_msck_recovery)
  2026. {
  2027. chandev_msck_range *new_range;
  2028. if((new_range=chandev_alloc(sizeof(chandev_msck_range))))
  2029. {
  2030. new_range->lo_devno=lo_devno;
  2031. new_range->hi_devno=hi_devno;
  2032. new_range->auto_msck_recovery=auto_msck_recovery;
  2033. chandev_add_to_list((list **)&chandev_msck_range_head,new_range);
  2034. }
  2035. }
  2036. static char chandev_keydescript[]=
  2037. "nchan_type key bitfield ctc=0x1,escon=0x2,lcs=0x4,osad=0x8,qeth=0x10,claw=0x20n";
  2038. #if  CONFIG_ARCH_S390X
  2039. /* We need this as we sometimes use this to evaluate pointers */
  2040. typedef long chandev_int; 
  2041. #else
  2042. typedef int chandev_int;
  2043. #endif
  2044. #if (LINUX_VERSION_CODE<KERNEL_VERSION(2,3,0)) || (CONFIG_ARCH_S390X)
  2045. /*
  2046.  * Read an int from an option string; if available accept a subsequent
  2047.  * comma as well.
  2048.  *
  2049.  * Return values:
  2050.  * 0 : no int in string
  2051.  * 1 : int found, no subsequent comma
  2052.  * 2 : int found including a subsequent comma
  2053.  */
  2054. static chandev_int chandev_get_option(char **str,chandev_int *pint)
  2055. {
  2056.     char *cur = *str;
  2057.     if (!cur || !(*cur)) return 0;
  2058.     *pint = simple_strtol(cur,str,0);
  2059.     if (cur==*str) return 0;
  2060.     if (**str==',') {
  2061.         (*str)++;
  2062.         return 2;
  2063.     }
  2064.     return 1;
  2065. }
  2066. static char *chandev_get_options(char *str, int nints, chandev_int *ints)
  2067. {
  2068. int res,i=1;
  2069. while (i<nints) 
  2070. {
  2071. res = chandev_get_option(&str, ints+i);
  2072. if (res==0) break;
  2073. i++;
  2074. if (res==1) break;
  2075. }
  2076. ints[0] = i-1;
  2077. return(str);
  2078. }
  2079. #else
  2080. #define chandev_get_option get_option
  2081. #define chandev_get_options get_options
  2082. #endif
  2083. /*
  2084.  * Read an string from an option string; if available accept a subsequent
  2085.  * comma as well & set this comma to a null character when returning the string.
  2086.  *
  2087.  * Return values:
  2088.  * 0 : no string found
  2089.  * 1 : string found, no subsequent comma
  2090.  * 2 : string found including a subsequent comma
  2091.  */
  2092. static int chandev_get_string(char **instr,char **outstr)
  2093. {
  2094. char *cur = *instr;
  2095. if (!cur ||*cur==0)
  2096. {
  2097. *outstr=NULL;
  2098. return 0;
  2099. }
  2100. *outstr=*instr;
  2101. for(;;)
  2102. {
  2103. if(*(++cur)==',')
  2104. {
  2105. *cur=0;
  2106. *instr=cur+1;
  2107. return 2;
  2108. }
  2109. else if(*cur==0)
  2110. {
  2111. *instr=cur+1;
  2112. return 1;
  2113. }
  2114. }
  2115. }
  2116. static int chandev_setup(int in_read_conf,char *instr,char *errstr,int lineno)
  2117. {
  2118. chandev_strval   val=isnull;
  2119. chandev_str_enum stridx;
  2120. long             endlong;
  2121. chandev_type     chan_type;
  2122. char             *str,*currstr,*interpretstr=NULL;
  2123. int              cnt,strcnt;
  2124. int              retval=0;
  2125. #define CHANDEV_MAX_EXTRA_INTS 12
  2126. chandev_int ints[CHANDEV_MAX_EXTRA_INTS+1];
  2127. currstr=alloca(strlen(instr)+1);
  2128. strcpy(currstr,instr);
  2129. strcnt=chandev_pack_args(currstr);
  2130. for(cnt=1;cnt<=strcnt;cnt++)
  2131. {
  2132. interpretstr=currstr;
  2133. memset(ints,0,sizeof(ints));
  2134. for(stridx=first_stridx;stridx<last_stridx;stridx++)
  2135. {
  2136. str=currstr;
  2137. if((val=chandev_strcmp(argstrs[stridx],&str,&endlong)))
  2138. break;
  2139. }
  2140. currstr=str;
  2141. if(val)
  2142. {
  2143. val=(((chandev_strval)stridx)*stridx_mult)+(val&~isstr);
  2144. switch(val)
  2145. {
  2146. case (add_parms_stridx*stridx_mult)|iscomma:
  2147. currstr=chandev_get_options(currstr,4,ints);
  2148. if(*currstr&&ints[0]>=1)
  2149. {
  2150. if(ints[0]==1)
  2151. {
  2152. ints[2]=0;
  2153. ints[3]=0xffff;
  2154. }
  2155. else if(ints[0]==2)
  2156. ints[3]=ints[2];
  2157. chandev_add_parms(ints[1],ints[2],ints[3],currstr);
  2158. goto NextOption;
  2159. }
  2160. else
  2161. goto BadArgs;
  2162. break;
  2163. case (claw_stridx*stridx_mult)|isnum|iscomma:
  2164. case (claw_stridx*stridx_mult)|iscomma:
  2165. currstr=chandev_get_options(str,6,ints);
  2166. break;
  2167. default:
  2168. if(val&iscomma)
  2169. currstr=chandev_get_options(str,CHANDEV_MAX_EXTRA_INTS,ints);
  2170. break;
  2171. }
  2172. switch(val)
  2173. {
  2174. case noauto_stridx*stridx_mult:
  2175. case (noauto_stridx*stridx_mult)|iscomma:
  2176. switch(ints[0])
  2177. {
  2178. case 0: 
  2179. chandev_free_all_list((list **)&chandev_noauto_head);
  2180. chandev_add_noauto(0,0xffff);
  2181. break;
  2182. case 1:
  2183. ints[2]=ints[1];
  2184. case 2:
  2185. chandev_add_noauto(ints[1],ints[2]);
  2186. break;
  2187. default:
  2188. goto BadArgs;
  2189. }
  2190. break;
  2191. case (auto_msck_stridx*stridx_mult)|iscomma:
  2192. switch(ints[0])
  2193. {
  2194. case 1:
  2195. chandev_free_all_list((list **)&chandev_msck_range_head);
  2196. chandev_add_msck_range(0,0xffff,ints[1]);
  2197. break;
  2198. case 2:
  2199. chandev_add_msck_range(ints[1],ints[1],ints[2]);
  2200. break;
  2201. case 3:
  2202. chandev_add_msck_range(ints[1],ints[2],ints[3]);
  2203. break;
  2204. default:
  2205. goto BadArgs;
  2206. }
  2207. case del_auto_msck_stridx*stridx_mult:
  2208. case (del_auto_msck_stridx*stridx_mult)|iscomma:
  2209. switch(ints[0])
  2210. {
  2211. case 0:
  2212. chandev_free_all_list((list **)&chandev_msck_range_head);
  2213. break;
  2214. case 1:
  2215. chandev_del_msck(ints[1]);
  2216. default:
  2217. goto BadArgs;
  2218. }
  2219. case del_noauto_stridx*stridx_mult:
  2220. chandev_free_all_list((list **)&chandev_noauto_head);
  2221. break;
  2222. case (del_noauto_stridx*stridx_mult)|iscomma:
  2223. if(ints[0]==1)
  2224. chandev_del_noauto(ints[1]);
  2225. else
  2226. goto BadArgs;
  2227. break;
  2228. case (qeth_stridx*stridx_mult)|isnum|iscomma:
  2229. if(ints[0]<3||ints[0]>7)
  2230. goto BadArgs;
  2231. chandev_add_force(chandev_type_qeth,endlong,ints[1],ints[2],
  2232.   ints[3],ints[4],ints[5],ints[6],ints[7],
  2233.   NULL,NULL,NULL);
  2234. break;
  2235. case (ctc_stridx*stridx_mult)|isnum|iscomma:
  2236. case (escon_stridx*stridx_mult)|isnum|iscomma:
  2237. case (lcs_stridx*stridx_mult)|isnum|iscomma:
  2238. case (osad_stridx*stridx_mult)|isnum|iscomma:
  2239. case (ctc_stridx*stridx_mult)|iscomma:
  2240. case (escon_stridx*stridx_mult)|iscomma:
  2241. case (lcs_stridx*stridx_mult)|iscomma:
  2242. case (osad_stridx*stridx_mult)|iscomma:
  2243. switch(val&~(isnum|iscomma))
  2244. {
  2245. case (ctc_stridx*stridx_mult):
  2246. chan_type=chandev_type_ctc;
  2247. break;
  2248. case (escon_stridx*stridx_mult):
  2249. chan_type=chandev_type_escon;
  2250. break;
  2251. case (lcs_stridx*stridx_mult):
  2252. chan_type=chandev_type_lcs;
  2253. break;
  2254. case (osad_stridx*stridx_mult):
  2255. chan_type=chandev_type_osad;
  2256. break;
  2257. case (qeth_stridx*stridx_mult):
  2258. chan_type=chandev_type_qeth;
  2259. break;
  2260. default:
  2261. goto BadArgs;
  2262. }
  2263. if((val&isnum)==0)
  2264. endlong=-2;
  2265. if(ints[0]<2||ints[0]>6)
  2266. goto BadArgs;
  2267. chandev_add_force(chan_type,endlong,ints[1],ints[2],
  2268.   0,ints[3],ints[4],ints[5],ints[6],
  2269.   NULL,NULL,NULL);
  2270. break;
  2271. case (claw_stridx*stridx_mult)|isnum|iscomma:
  2272. case (claw_stridx*stridx_mult)|iscomma:
  2273. if(ints[0]>=2&&ints[0]<=5)
  2274. {
  2275. char    *host_name,*adapter_name,*api_type;
  2276. char    *clawstr=alloca(strlen(currstr)+1);
  2277. strcpy(clawstr,currstr);
  2278. if(!(chandev_get_string(&clawstr,&host_name)==2&&
  2279.      chandev_get_string(&clawstr,&adapter_name)==2&&
  2280.      chandev_get_string(&clawstr,&api_type)==1&&
  2281.      chandev_add_force(chandev_type_claw,
  2282.        endlong,ints[1],ints[2],0,
  2283.        ints[3],0,ints[4],ints[5],
  2284.        host_name,adapter_name,api_type)==0))
  2285. goto BadArgs;
  2286. }
  2287. else
  2288. goto BadArgs;
  2289. break;
  2290. case (del_parms_stridx*stridx_mult):
  2291. ints[1]=-1;
  2292. case (del_parms_stridx*stridx_mult)|iscomma:
  2293. if(ints[0]==0)
  2294. ints[1]=-1;
  2295. if(ints[0]<=1)
  2296. ints[2]=FALSE;
  2297. if(ints[0]<=2)
  2298. ints[3]=-1;
  2299. if(ints[0]>3)
  2300. goto BadArgs;
  2301. chandev_remove_parms(ints[1],ints[2],ints[3]);
  2302. break;
  2303. case (del_force_stridx*stridx_mult)|iscomma:
  2304. if(ints[0]!=1)
  2305. goto BadArgs;
  2306. chandev_del_force(ints[1]);
  2307. break;
  2308. case (del_force_stridx*stridx_mult):
  2309. chandev_del_force(-1);
  2310. break;
  2311. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  2312. case (use_devno_names_stridx*stridx_mult):
  2313. chandev_use_devno_names=TRUE;
  2314. break;
  2315. case (dont_use_devno_names_stridx*stridx_mult):
  2316. chandev_use_devno_names=FALSE;
  2317. break;
  2318. #endif
  2319. case (cautious_auto_detect_stridx*stridx_mult):
  2320. chandev_cautious_auto_detect=TRUE;
  2321. break;
  2322. case (non_cautious_auto_detect_stridx*stridx_mult):
  2323. chandev_cautious_auto_detect=FALSE;
  2324. break;
  2325. case (add_model_stridx*stridx_mult)|iscomma:
  2326. if(ints[0]<3)
  2327. goto BadArgs;
  2328. if(ints[0]==3)
  2329. ints[4]=-1;
  2330. if(ints[0]<=4)
  2331. ints[5]=-1;
  2332. if(ints[0]<=5)
  2333. ints[6]=-1;
  2334. if(ints[0]<=6)
  2335. ints[7]=default_msck_bits;
  2336. if(ints[0]<=7)
  2337. ints[8]=FALSE;
  2338. if(ints[0]<=8)
  2339. ints[9]=FALSE;
  2340. ints[0]=7;
  2341. chandev_add_model(ints[1],ints[2],ints[3],
  2342.   ints[4],ints[5],ints[6],ints[7],ints[8],ints[9]);
  2343. break;
  2344. case (del_model_stridx*stridx_mult)|iscomma:
  2345. if(ints[0]<2||ints[0]>4)
  2346. goto BadArgs;
  2347. if(ints[0]<3)
  2348. ints[3]=-2;
  2349. if(ints[0]<4)
  2350. ints[4]=-2;
  2351. ints[0]=4;
  2352. chandev_del_model(ints[1],ints[2],ints[3],ints[4]);
  2353. break;
  2354. case del_all_models_stridx*stridx_mult:
  2355. chandev_remove_all_models();
  2356. break;
  2357. case reset_conf_stridx*stridx_mult:
  2358. chandev_reset();
  2359. chandev_init_default_models();
  2360. break;
  2361. case reset_conf_clean_stridx*stridx_mult:
  2362. chandev_reset();
  2363. break;
  2364. case shutdown_stridx*stridx_mult:
  2365. chandev_shutdown_all();
  2366. break;
  2367. case (shutdown_stridx*stridx_mult)|iscomma:
  2368. switch(ints[0])
  2369. {
  2370. case 0:
  2371. if(strlen(str))
  2372. chandev_shutdown_by_name(str);
  2373. else
  2374. goto BadArgs;
  2375. break;
  2376. case 1:
  2377. chandev_shutdown_by_devno(ints[1]);
  2378. break;
  2379. default:
  2380. goto BadArgs;
  2381. }
  2382. break;
  2383. case reprobe_stridx*stridx_mult:
  2384. chandev_probe();
  2385. break;
  2386. case unregister_probe_stridx*stridx_mult:
  2387. chandev_free_all_list((list **)&chandev_probelist_head);
  2388. break;
  2389. case (unregister_probe_stridx*stridx_mult)|iscomma:
  2390. if(ints[0]!=1)
  2391. goto BadArgs;
  2392. chandev_unregister_probe((chandev_probefunc)ints[1]);
  2393. break;
  2394. case (unregister_probe_by_chan_type_stridx*stridx_mult)|iscomma:
  2395. if(ints[0]!=1)
  2396. goto BadArgs;
  2397. chandev_unregister_probe_by_chan_type((chandev_type)ints[1]);
  2398. break;
  2399. case read_conf_stridx*stridx_mult:
  2400. if(in_read_conf)
  2401. {
  2402. printk("attempt to recursively call read_confn");
  2403. goto BadArgs;
  2404. }
  2405. chandev_read_conf();
  2406. break;
  2407. case dont_read_conf_stridx*stridx_mult:
  2408. atomic_set(&chandev_conf_read,TRUE);
  2409. break;
  2410. case (persist_stridx*stridx_mult)|iscomma:
  2411. if(ints[0]==1)
  2412. chandev_persistent=ints[1];
  2413. else
  2414. goto BadArgs;
  2415. break;
  2416. default:
  2417. goto BadArgs;
  2418. }
  2419. }
  2420. else
  2421. goto BadArgs;
  2422. NextOption:
  2423. if(cnt<strcnt)
  2424. {
  2425. /* eat up stuff till next string */
  2426. while(*(currstr++));
  2427. }
  2428. }
  2429. retval=1;
  2430.  BadArgs:
  2431. if(!retval)
  2432. {
  2433. printk("chandev_setup %s %s",(val==0 ? "unknown verb":"bad argument"),instr);
  2434. if(errstr)
  2435. {
  2436. printk("%s %d interpreted as %s",errstr,lineno,interpretstr);
  2437. if(strcnt>1)
  2438. {
  2439. if(cnt==strcnt)
  2440. printk(" after the last semicolonn");
  2441. else
  2442. printk(" before semicolon no %d",cnt);
  2443. }
  2444. }
  2445. printk(".n Type man chandev for more info.nn");
  2446. }
  2447. return(retval);
  2448. }
  2449. #define CHANDEV_KEYWORD "chandev="
  2450. static int chandev_setup_bootargs(char *str,int paramno)
  2451. {
  2452. int len;
  2453. char *copystr;
  2454. for(len=0;str[len]!=0&&!isspace(str[len]);len++);
  2455. copystr=alloca(len+1);
  2456. strncpy(copystr,str,len);
  2457. copystr[len]=0;
  2458. if(chandev_setup(FALSE,copystr,"at "CHANDEV_KEYWORD" bootparam no",paramno)==0)
  2459. return(0);
  2460. return(len);
  2461. }
  2462. /*
  2463.   We can't parse using a __setup function as kmalloc isn't available
  2464.   at this time.
  2465.  */
  2466. static void __init chandev_parse_args(void)
  2467. {
  2468. #define CHANDEV_KEYWORD "chandev="
  2469. extern char saved_command_line[];
  2470. int cnt,len,paramno=1;
  2471. len=strlen(saved_command_line)-sizeof(CHANDEV_KEYWORD);
  2472. for(cnt=0;cnt<len;cnt++)
  2473. {
  2474. if(strncmp(&saved_command_line[cnt],CHANDEV_KEYWORD,
  2475.    sizeof(CHANDEV_KEYWORD)-1)==0)
  2476. {
  2477. cnt+=(sizeof(CHANDEV_KEYWORD)-1);
  2478. cnt+=chandev_setup_bootargs(&saved_command_line[cnt],paramno);
  2479. paramno++;
  2480. }
  2481. }
  2482. }
  2483. int chandev_do_setup(int in_read_conf,char *buff,int size)
  2484. {
  2485. int curr,comment=FALSE,newline=FALSE,oldnewline=TRUE;
  2486. char *startline=NULL,*endbuff=&buff[size];
  2487. int lineno=0;
  2488. *endbuff=0;
  2489. for(;buff<=endbuff;curr++,buff++)
  2490. {
  2491. if(*buff==0xa||*buff==0xc||*buff==0)
  2492. {
  2493. if(*buff==0xa||*buff==0)
  2494. lineno++;
  2495. *buff=0;
  2496. newline=TRUE;
  2497. }
  2498. else
  2499. newline=FALSE;
  2500. if(*buff=='#')
  2501. comment=TRUE;
  2502. }
  2503. if(comment==TRUE)
  2504. *buff=0;
  2505. if(startline==NULL&&isalpha(*buff))
  2506. startline=buff;
  2507. if(startline&&(buff>startline)&&(oldnewline==FALSE)&&(newline==TRUE))
  2508. {
  2509. if((chandev_setup(in_read_conf,startline," on line no",lineno))==0)
  2510. return(-EINVAL);
  2511. startline=NULL;
  2512. }
  2513. if(newline)
  2514. comment=FALSE;
  2515.         oldnewline=newline;
  2516. }
  2517. return(0);
  2518. }
  2519. static void chandev_read_conf(void)
  2520. {
  2521. #define CHANDEV_FILE "/etc/chandev.conf"
  2522. struct stat statbuf;
  2523. char        *buff;
  2524. int         curr,left,len,fd;
  2525. /* if called from chandev_register_and_probe & 
  2526.    the driver is compiled into the kernel the
  2527.    parameters will need to be passed in from
  2528.    the kernel boot parameter line as the root
  2529.    fs is not mounted yet, we can't wait here.
  2530. */
  2531. if(in_interrupt()||current->fs->root==NULL)
  2532. return;
  2533. atomic_set(&chandev_conf_read,TRUE);
  2534. set_fs(KERNEL_DS);
  2535. if(stat(CHANDEV_FILE,&statbuf)==0)
  2536. {
  2537. set_fs(USER_DS);
  2538. buff=vmalloc(statbuf.st_size+1);
  2539. if(buff)
  2540. {
  2541. set_fs(KERNEL_DS);
  2542. if((fd=open(CHANDEV_FILE,O_RDONLY,0))!=-1)
  2543. {
  2544. curr=0;
  2545. left=statbuf.st_size;
  2546. while((len=read(fd,&buff[curr],left))>0)
  2547. {
  2548. curr+=len;
  2549. left-=len;
  2550. }
  2551. close(fd);
  2552. }
  2553. set_fs(USER_DS);
  2554. chandev_do_setup(TRUE,buff,statbuf.st_size);
  2555. vfree(buff);
  2556. }
  2557. }
  2558. set_fs(USER_DS);
  2559. }
  2560. static void chandev_read_conf_if_necessary(void)
  2561. {
  2562. if(in_interrupt()||current->fs->root==NULL)
  2563. return;
  2564. if(!atomic_compare_and_swap(FALSE,TRUE,&chandev_conf_read))
  2565. chandev_read_conf();
  2566. }
  2567. #ifdef CONFIG_PROC_FS
  2568. #define chandev_printf(exitchan,args...)     
  2569. splen=sprintf(spbuff,##args);                
  2570. spoffset+=splen;                             
  2571. if(spoffset>offset) {                        
  2572.        spbuff+=splen;                        
  2573.        currlen+=splen;                       
  2574. }                                            
  2575. if(currlen>=length)                          
  2576.        goto exitchan;
  2577. void sprintf_msck(char *buff,int auto_msck_recovery)
  2578. {
  2579. chandev_msck_status idx;
  2580. int first_time=TRUE;
  2581. buff[0]=0;
  2582. for(idx=chandev_status_first_msck;idx<chandev_status_last_msck;idx++)
  2583. {
  2584. if((1<<(idx-1))&auto_msck_recovery)
  2585. {
  2586. buff+=sprintf(buff,"%s%s",(first_time ? "":","),
  2587.       msck_status_strs[idx]);
  2588. first_time=FALSE;
  2589. }
  2590. }
  2591. }
  2592. static int chandev_read_proc(char *page, char **start, off_t offset,
  2593.   int length, int *eof, void *data)
  2594. {
  2595. char *spbuff=*start=page;
  2596. int    currlen=0,splen=0;
  2597. off_t  spoffset=0;
  2598. chandev_model_info *curr_model;
  2599. chandev_noauto_range *curr_noauto;
  2600. chandev_force *curr_force;
  2601. chandev_activelist *curr_device;
  2602. chandev_probelist  *curr_probe;
  2603. chandev_msck_range *curr_msck_range;
  2604. s390_dev_info_t   curr_devinfo;
  2605. int pass,chandevs_detected,curr_irq,loopcnt;
  2606. chandev_irqinfo *read_irqinfo,*write_irqinfo,*data_irqinfo;
  2607. char buff[3][80];    
  2608. chandev_lock();
  2609. chandev_printf(chan_exit,"n%sn"
  2610.        "*'s for cu/dev type/models indicate don't caresn",chandev_keydescript);
  2611. chandev_printf(chan_exit,"ncautious_auto_detect: %sn",chandev_cautious_auto_detect ? "on":"off");
  2612. chandev_printf(chan_exit,"npersist = 0x%02xn",chandev_persistent);
  2613. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  2614. chandev_printf(chan_exit,"nuse_devno_names: %snn",chandev_use_devno_names ? "on":"off");
  2615. #endif
  2616. if(chandev_models_head)
  2617. {
  2618. chandev_printf(chan_exit,"Channels enabled for detectionn");      
  2619. chandev_printf(chan_exit,"  chan     cu      cu     dev   dev    max     checksum  use hw  auto recoveryn");
  2620. chandev_printf(chan_exit,"  type    type    model  type  model  port_no. received   stats      typen");
  2621. chandev_printf(chan_exit,"==============================================================================n");
  2622. for_each(curr_model,chandev_models_head)
  2623. {
  2624. chandev_sprint_devinfo(buff[0],curr_model->cu_type,
  2625.        curr_model->cu_model,
  2626.        curr_model->dev_type,
  2627.        curr_model->dev_model);
  2628. sprintf_msck(buff[1],curr_model->auto_msck_recovery);
  2629. chandev_printf(chan_exit,"  0x%02x  %s%3d %s     %s     %sn",
  2630.        curr_model->chan_type,buff[0],
  2631.        (int)curr_model->max_port_no,
  2632.        curr_model->default_checksum_received_ip_pkts ? "yes":"no ",
  2633.        curr_model->default_use_hw_stats ? "yes":"no ",
  2634.        buff[1]);         
  2635. }
  2636. }
  2637.         
  2638. if(chandev_noauto_head)
  2639. {
  2640. chandev_printf(chan_exit,"nNo auto devno rangesn");
  2641. chandev_printf(chan_exit,"   From        To   n");
  2642. chandev_printf(chan_exit,"====================n");
  2643. for_each(curr_noauto,chandev_noauto_head)
  2644. {
  2645. chandev_printf(chan_exit,"  0x%04x     0x%04xn",
  2646.        curr_noauto->lo_devno,
  2647.        curr_noauto->hi_devno);
  2648. }
  2649. }
  2650. if(chandev_msck_range_head)
  2651. {
  2652. chandev_printf(chan_exit,"nAutomatic machine check recovery devno rangesn");
  2653. chandev_printf(chan_exit,"   From        To   automatic recovery typen");
  2654. chandev_printf(chan_exit,"===========================================n");
  2655. for_each(curr_msck_range,chandev_msck_range_head)
  2656. {
  2657. sprintf_msck(buff[0],curr_msck_range->auto_msck_recovery);
  2658. chandev_printf(chan_exit,"  0x%04x     0x%04x %sn",
  2659.        curr_msck_range->lo_devno,
  2660.        curr_msck_range->hi_devno,buff[0])
  2661. }
  2662. }
  2663. if(chandev_force_head)
  2664. {
  2665. chandev_printf(chan_exit,"nForced devicesn");
  2666. chandev_printf(chan_exit,"  chan defif read   write  data   memory      port         ip    hw   host       adapter   apin");
  2667. chandev_printf(chan_exit,"  type  num  devno  devno  devno  usage(k) protocol no.  chksum stats name        name     namen");
  2668. chandev_printf(chan_exit,"===============================================================================================n");
  2669. for_each(curr_force,chandev_force_head)
  2670. {
  2671. if(curr_force->memory_usage_in_k==0)
  2672. strcpy(buff[0],"default");
  2673. else
  2674. sprintf(buff[0],"%6d",curr_force->memory_usage_in_k);
  2675. chandev_printf(chan_exit,"  0x%02x  %3d  0x%04x 0x%04x 0x%04x %7s       %3d       %1d    %1d%s",
  2676.        (int)curr_force->chan_type,(int)curr_force->devif_num,
  2677.        (int)curr_force->read_lo_devno,(int)curr_force->write_hi_devno,
  2678.        (int)curr_force->data_devno,buff[0],
  2679.        (int)curr_force->port_protocol_no,(int)curr_force->checksum_received_ip_pkts,
  2680.        (int)curr_force->use_hw_stats,curr_force->chan_type==chandev_type_claw ? "":"n");
  2681. if(curr_force->chan_type==chandev_type_claw)
  2682. {
  2683. chandev_printf(chan_exit," %9s %9s %9sn",
  2684.        curr_force->claw.host_name,
  2685.        curr_force->claw.adapter_name,
  2686.        curr_force->claw.api_type);
  2687. }
  2688. }
  2689. }
  2690. if(chandev_probelist_head)
  2691. {
  2692. #if CONFIG_ARCH_S390X
  2693. chandev_printf(chan_exit,"nRegistered probe functionsn"
  2694.          "probefunc            shutdownfunc        msck_notfunc        chan  devices devicesn"
  2695.                                          "                                                             type   found  activen"
  2696.                  "==================================================================================n");
  2697. #else
  2698. chandev_printf(chan_exit,"nRegistered probe functionsn"
  2699.                  "probefunc   shutdownfunc   msck_notfunc   chan  devices devicesn"
  2700.                                          "                                          type   found  activen"
  2701.                  "===============================================================n");
  2702. #endif
  2703. for_each(curr_probe,chandev_probelist_head)
  2704. {
  2705. int devices_active=0;
  2706. for_each(curr_device,chandev_activelist_head)
  2707. {
  2708. if(curr_device->probefunc==curr_probe->probefunc)
  2709. devices_active++;
  2710. }
  2711. chandev_printf(chan_exit,"0x%p   0x%p   0x%p       0x%02x     %d      %dn",
  2712.        curr_probe->probefunc,
  2713.        curr_probe->shutdownfunc,
  2714.        curr_probe->msck_notfunc,
  2715.        curr_probe->chan_type,
  2716.        curr_probe->devices_found,
  2717.        devices_active);
  2718. }
  2719. }
  2720. if(chandev_activelist_head)
  2721. {
  2722. unsigned long long total_memory_usage_in_k=0;
  2723. chandev_printf(chan_exit,
  2724.        "nInitialised Devicesn"
  2725.        " read   write  data  read   write  data  chan port  dev     dev         memory   read msck    write msck    data msckn"
  2726.        " irq     irq    irq  devno  devno  devno type no.   ptr     name        usage(k)  status       status        statusn"
  2727.        "=====================================================================================================================n");
  2728. /* We print this list backwards for cosmetic reasons */
  2729. for(curr_device=chandev_activelist_head;
  2730.     curr_device->next!=NULL;curr_device=curr_device->next);
  2731. while(curr_device)
  2732. {
  2733. read_irqinfo=curr_device->read_irqinfo;
  2734. write_irqinfo=curr_device->write_irqinfo;
  2735. data_irqinfo=curr_device->data_irqinfo;
  2736. if(data_irqinfo)
  2737. {
  2738. sprintf(buff[0],"0x%04x",data_irqinfo->sch.irq);
  2739. sprintf(buff[1],"0x%04x",(int)data_irqinfo->sch.devno);
  2740. }
  2741. else
  2742. {
  2743. strcpy(buff[0],"  n/a ");
  2744. strcpy(buff[1],"  n/a ");
  2745. }
  2746. if(curr_device->memory_usage_in_k<0)
  2747. {
  2748. sprintf(buff[2],"%d",(int)-curr_device->memory_usage_in_k);
  2749. total_memory_usage_in_k-=curr_device->memory_usage_in_k;
  2750. }
  2751. else
  2752. strcpy(buff[2],"  n/a ");
  2753. chandev_printf(chan_exit,
  2754.        "0x%04x 0x%04x %s 0x%04x 0x%04x %s 0x%02x %2d 0x%p %-10s  %6s   %-12s %-12s %-12sn",
  2755.        read_irqinfo->sch.irq,
  2756.        write_irqinfo->sch.irq,
  2757.        buff[0],
  2758.        (int)read_irqinfo->sch.devno,
  2759.        (int)write_irqinfo->sch.devno,
  2760.        buff[1],
  2761.        curr_device->chan_type,(int)curr_device->port_no,
  2762.        curr_device->dev_ptr,curr_device->devname,
  2763.        buff[2],
  2764.        msck_status_strs[read_irqinfo->msck_status],
  2765.        msck_status_strs[write_irqinfo->msck_status],
  2766.        data_irqinfo ? msck_status_strs[data_irqinfo->msck_status] :
  2767.        "not applicable");
  2768. get_prev((list *)chandev_activelist_head,
  2769.  (list *)curr_device,
  2770.  (list **)&curr_device);
  2771. }
  2772. chandev_printf(chan_exit,"nTotal device memory usage %Luk.n",total_memory_usage_in_k);
  2773. }
  2774. chandevs_detected=FALSE;
  2775. for(pass=FALSE;pass<=TRUE;pass++)
  2776. {
  2777. if(pass&&chandevs_detected)
  2778. {
  2779. chandev_printf(chan_exit,"nchannels detectedn");
  2780. chandev_printf(chan_exit,"              chan    cu    cu   dev    dev                          in chandevn");
  2781. chandev_printf(chan_exit,"  irq  devno  type   type  model type  model pim      chpids         use  reg.n");
  2782. chandev_printf(chan_exit,"===============================================================================n");
  2783. }
  2784. for(curr_irq=get_irq_first(),loopcnt=0;curr_irq>=0; curr_irq=get_irq_next(curr_irq),loopcnt++)
  2785. {
  2786. if(loopcnt>0x10000)
  2787. {
  2788. printk(KERN_ERR"chandev_read_proc detected infinite loop bug in get_irq_nextn");
  2789. goto chan_error;
  2790. }
  2791. if(chandev_is_chandev(curr_irq,&curr_devinfo,&curr_force,&curr_model))
  2792. {
  2793. schib_t *curr_schib;
  2794. curr_schib=s390_get_schib(curr_irq);
  2795. chandevs_detected=TRUE;
  2796. if(pass)
  2797. {
  2798. chandev_printf(chan_exit,"0x%04x 0x%04x 0x%02x  0x%04x 0x%02x  0x%04x 0x%02x 0x%02x 0x%016Lx  %-5s%-5sn",
  2799.        curr_irq,curr_devinfo.devno,
  2800.        ( curr_force ? curr_force->chan_type : 
  2801.        ( curr_model ? curr_model->chan_type : 
  2802.  chandev_type_none )),
  2803.        (int)curr_devinfo.sid_data.cu_type,
  2804.        (int)curr_devinfo.sid_data.cu_model,
  2805.        (int)curr_devinfo.sid_data.dev_type,
  2806.        (int)curr_devinfo.sid_data.dev_model,
  2807.        (int)(curr_schib ? curr_schib->pmcw.pim : 0),
  2808.        *(long long *)(curr_schib ? &curr_schib->pmcw.chpid[0] : 0),
  2809.        (curr_devinfo.status&DEVSTAT_DEVICE_OWNED) ? "yes":"no ",
  2810.        (chandev_get_irqinfo_by_irq(curr_irq) ? "yes":"no "));
  2811.        
  2812.        
  2813. }
  2814. }
  2815. }
  2816. }
  2817. if(chandev_parms_head)
  2818. {
  2819. chandev_parms      *curr_parms;
  2820. chandev_printf(chan_exit,"n driver specific parametersn");
  2821. chandev_printf(chan_exit,"chan    lo    hi      drivern");
  2822. chandev_printf(chan_exit,"type  devno  devno  parametersn");
  2823. chandev_printf(chan_exit,"=============================================================================n");
  2824. for_each(curr_parms,chandev_parms_head)
  2825. {
  2826. chandev_printf(chan_exit,"0x%02x 0x%04x 0x%04x  %sn",
  2827.        curr_parms->chan_type,(int)curr_parms->lo_devno,
  2828.        (int)curr_parms->hi_devno,curr_parms->parmstr);
  2829. }
  2830. }
  2831.  chan_error:
  2832. *eof=TRUE;
  2833.  chan_exit:
  2834. if(currlen>length) {
  2835. /* rewind to previous printf so that we are correctly
  2836.  * aligned if we get called to print another page.
  2837.                  */
  2838. currlen-=splen;
  2839. }
  2840. chandev_unlock();
  2841. return(currlen);
  2842. }
  2843. static int chandev_write_proc(struct file *file, const char *buffer,
  2844.    unsigned long count, void *data)
  2845. {
  2846. int         rc;
  2847. char        *buff;
  2848. buff=vmalloc(count+1);
  2849. if(buff)
  2850. {
  2851. rc = copy_from_user(buff,buffer,count);
  2852. if (rc)
  2853. goto chandev_write_exit;
  2854. chandev_do_setup(FALSE,buff,count);
  2855. rc=count;
  2856. chandev_write_exit:
  2857. vfree(buff);
  2858. return rc;
  2859. }
  2860. else
  2861. return -ENOMEM;
  2862. return(0);
  2863. }
  2864. static void __init chandev_create_proc(void)
  2865. {
  2866. struct proc_dir_entry *dir_entry=
  2867. create_proc_entry("chandev",0644,
  2868.   &proc_root);
  2869. if(dir_entry)
  2870. {
  2871. dir_entry->read_proc=&chandev_read_proc;
  2872. dir_entry->write_proc=&chandev_write_proc;
  2873. }
  2874. }
  2875. #endif
  2876. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  2877. static  
  2878. #endif
  2879. int __init chandev_init(void)
  2880. {
  2881. atomic_set(&chandev_initialised,TRUE);
  2882. chandev_parse_args();
  2883. chandev_init_default_models();
  2884. #if CONFIG_PROC_FS
  2885. chandev_create_proc();
  2886. #endif
  2887. chandev_msck_task_tq.routine=
  2888. chandev_msck_task;
  2889. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  2890. INIT_LIST_HEAD(&chandev_msck_task_tq.list);
  2891. chandev_msck_task_tq.sync=0;
  2892. #endif
  2893. chandev_msck_task_tq.data=NULL;
  2894. chandev_last_startmsck_list_update=chandev_last_machine_check=jiffies-HZ;
  2895. atomic_set(&chandev_msck_thread_lock,1);
  2896. chandev_lock_owner=CHANDEV_INVALID_LOCK_OWNER;
  2897. chandev_lock_cnt=0;
  2898. spin_lock_init(&chandev_spinlock);
  2899. spin_lock_init(&chandev_not_oper_spinlock);
  2900. atomic_set(&chandev_new_msck,FALSE);
  2901. return(0);
  2902. }
  2903. #if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
  2904. __initcall(chandev_init);
  2905. #endif
  2906. int chandev_register_and_probe(chandev_probefunc probefunc,
  2907.        chandev_shutdownfunc shutdownfunc,
  2908.        chandev_msck_notification_func msck_notfunc,
  2909.        chandev_type chan_type)
  2910. {
  2911. chandev_probelist *new_probe,*curr_probe;
  2912. /* Avoid chicked & egg situations where we may be called before we */
  2913. /* are initialised. */
  2914. chandev_interrupt_check();
  2915. if(!atomic_compare_and_swap(FALSE,TRUE,&chandev_initialised))
  2916. chandev_init();
  2917. chandev_lock();
  2918. for_each(curr_probe,chandev_probelist_head)
  2919. {
  2920. if(curr_probe->probefunc==probefunc)
  2921. {
  2922. chandev_unlock();
  2923. printk("chandev_register_and_probe detected duplicate probefunc %p"
  2924.        " for chan_type  0x%02x n",probefunc,chan_type);
  2925. return (-EPERM);
  2926. }
  2927. }
  2928. chandev_unlock();
  2929. if((new_probe=chandev_alloc(sizeof(chandev_probelist))))
  2930. {
  2931. new_probe->probefunc=probefunc;
  2932. new_probe->shutdownfunc=shutdownfunc;
  2933. new_probe->msck_notfunc=msck_notfunc;
  2934. new_probe->chan_type=chan_type;
  2935. new_probe->devices_found=0;
  2936. chandev_add_to_list((list **)&chandev_probelist_head,new_probe);
  2937. chandev_probe();
  2938. }
  2939. return(new_probe ? new_probe->devices_found:-ENOMEM);
  2940. }
  2941. void chandev_unregister(chandev_probefunc probefunc,int call_shutdown)
  2942. {
  2943. chandev_probelist *curr_probe;
  2944. chandev_activelist *curr_device,*next_device;
  2945. chandev_interrupt_check();
  2946. chandev_lock();
  2947. for_each(curr_probe,chandev_probelist_head)
  2948. {
  2949. if(curr_probe->probefunc==probefunc)
  2950. {
  2951. for_each_allow_delete(curr_device,next_device,chandev_activelist_head)
  2952. if(curr_device->probefunc==probefunc&&call_shutdown)
  2953. chandev_shutdown(curr_device);
  2954. chandev_free_listmember((list **)&chandev_probelist_head,
  2955. (list *)curr_probe);
  2956. break;
  2957. }
  2958. }
  2959. chandev_unlock();
  2960. }
  2961. int chandev_persist(chandev_type chan_type)
  2962. {
  2963. return((chandev_persistent&chan_type) ? TRUE:FALSE);
  2964. }
  2965. EXPORT_SYMBOL(chandev_register_and_probe);
  2966. EXPORT_SYMBOL(chandev_request_irq);
  2967. EXPORT_SYMBOL(chandev_unregister);
  2968. EXPORT_SYMBOL(chandev_initdevice);
  2969. EXPORT_SYMBOL(chandev_build_device_name);
  2970. EXPORT_SYMBOL(chandev_initnetdevice);
  2971. EXPORT_SYMBOL(chandev_init_netdev);
  2972. EXPORT_SYMBOL(chandev_use_devno_names);
  2973. EXPORT_SYMBOL(chandev_free_irq);
  2974. EXPORT_SYMBOL(chandev_add_model);
  2975. EXPORT_SYMBOL(chandev_del_model);
  2976. EXPORT_SYMBOL(chandev_persist);