2222
2323#define KCS_ZERO_DATA 0
2424
25-
2625/* IPMI 2.0 - Table 9-1, KCS Interface Status Register Bits */
2726#define KCS_STATUS_STATE (state ) (state << 6)
2827#define KCS_STATUS_STATE_MASK GENMASK(7, 6)
@@ -179,12 +178,19 @@ static void kcs_bmc_ipmi_handle_cmd(struct kcs_bmc *kcs_bmc)
179178 }
180179}
181180
182- int kcs_bmc_ipmi_event (struct kcs_bmc * kcs_bmc );
183- int kcs_bmc_ipmi_event (struct kcs_bmc * kcs_bmc )
181+ static inline struct kcs_bmc * client_to_kcs_bmc (struct kcs_bmc_client * client )
182+ {
183+ return container_of (client , struct kcs_bmc , client );
184+ }
185+
186+ static irqreturn_t kcs_bmc_ipmi_event (struct kcs_bmc_client * client )
184187{
188+ struct kcs_bmc * kcs_bmc ;
185189 unsigned long flags ;
186- int ret = - ENODATA ;
187190 u8 status ;
191+ int ret ;
192+
193+ kcs_bmc = client_to_kcs_bmc (client );
188194
189195 spin_lock_irqsave (& kcs_bmc -> lock , flags );
190196
@@ -197,23 +203,28 @@ int kcs_bmc_ipmi_event(struct kcs_bmc *kcs_bmc)
197203 else
198204 kcs_bmc_ipmi_handle_data (kcs_bmc );
199205
200- ret = 0 ;
206+ ret = IRQ_HANDLED ;
207+ } else {
208+ ret = IRQ_NONE ;
201209 }
202210
203211 spin_unlock_irqrestore (& kcs_bmc -> lock , flags );
204212
205213 return ret ;
206214}
207- EXPORT_SYMBOL (kcs_bmc_ipmi_event );
208215
209- static inline struct kcs_bmc * to_kcs_bmc (struct file * filp )
216+ static const struct kcs_bmc_client_ops kcs_bmc_ipmi_client_ops = {
217+ .event = kcs_bmc_ipmi_event ,
218+ };
219+
220+ static inline struct kcs_bmc * file_to_kcs_bmc (struct file * filp )
210221{
211222 return container_of (filp -> private_data , struct kcs_bmc , miscdev );
212223}
213224
214225static int kcs_bmc_ipmi_open (struct inode * inode , struct file * filp )
215226{
216- struct kcs_bmc * kcs_bmc = to_kcs_bmc (filp );
227+ struct kcs_bmc * kcs_bmc = file_to_kcs_bmc (filp );
217228 int ret = 0 ;
218229
219230 spin_lock_irq (& kcs_bmc -> lock );
@@ -228,7 +239,7 @@ static int kcs_bmc_ipmi_open(struct inode *inode, struct file *filp)
228239
229240static __poll_t kcs_bmc_ipmi_poll (struct file * filp , poll_table * wait )
230241{
231- struct kcs_bmc * kcs_bmc = to_kcs_bmc (filp );
242+ struct kcs_bmc * kcs_bmc = file_to_kcs_bmc (filp );
232243 __poll_t mask = 0 ;
233244
234245 poll_wait (filp , & kcs_bmc -> queue , wait );
@@ -244,7 +255,7 @@ static __poll_t kcs_bmc_ipmi_poll(struct file *filp, poll_table *wait)
244255static ssize_t kcs_bmc_ipmi_read (struct file * filp , char __user * buf ,
245256 size_t count , loff_t * ppos )
246257{
247- struct kcs_bmc * kcs_bmc = to_kcs_bmc (filp );
258+ struct kcs_bmc * kcs_bmc = file_to_kcs_bmc (filp );
248259 bool data_avail ;
249260 size_t data_len ;
250261 ssize_t ret ;
@@ -306,7 +317,7 @@ static ssize_t kcs_bmc_ipmi_read(struct file *filp, char __user *buf,
306317static ssize_t kcs_bmc_ipmi_write (struct file * filp , const char __user * buf ,
307318 size_t count , loff_t * ppos )
308319{
309- struct kcs_bmc * kcs_bmc = to_kcs_bmc (filp );
320+ struct kcs_bmc * kcs_bmc = file_to_kcs_bmc (filp );
310321 ssize_t ret ;
311322
312323 /* a minimum response size '3' : netfn + cmd + ccode */
@@ -342,7 +353,7 @@ static ssize_t kcs_bmc_ipmi_write(struct file *filp, const char __user *buf,
342353static long kcs_bmc_ipmi_ioctl (struct file * filp , unsigned int cmd ,
343354 unsigned long arg )
344355{
345- struct kcs_bmc * kcs_bmc = to_kcs_bmc (filp );
356+ struct kcs_bmc * kcs_bmc = file_to_kcs_bmc (filp );
346357 long ret = 0 ;
347358
348359 spin_lock_irq (& kcs_bmc -> lock );
@@ -372,7 +383,7 @@ static long kcs_bmc_ipmi_ioctl(struct file *filp, unsigned int cmd,
372383
373384static int kcs_bmc_ipmi_release (struct inode * inode , struct file * filp )
374385{
375- struct kcs_bmc * kcs_bmc = to_kcs_bmc (filp );
386+ struct kcs_bmc * kcs_bmc = file_to_kcs_bmc (filp );
376387
377388 spin_lock_irq (& kcs_bmc -> lock );
378389 kcs_bmc -> running = 0 ;
@@ -401,6 +412,8 @@ int kcs_bmc_ipmi_add_device(struct kcs_bmc *kcs_bmc)
401412 mutex_init (& kcs_bmc -> mutex );
402413 init_waitqueue_head (& kcs_bmc -> queue );
403414
415+ kcs_bmc -> client .dev = kcs_bmc ;
416+ kcs_bmc -> client .ops = & kcs_bmc_ipmi_client_ops ;
404417 kcs_bmc -> data_in = devm_kmalloc (kcs_bmc -> dev , KCS_MSG_BUFSIZ , GFP_KERNEL );
405418 kcs_bmc -> data_out = devm_kmalloc (kcs_bmc -> dev , KCS_MSG_BUFSIZ , GFP_KERNEL );
406419 kcs_bmc -> kbuffer = devm_kmalloc (kcs_bmc -> dev , KCS_MSG_BUFSIZ , GFP_KERNEL );
0 commit comments