Subject: Re: [PATCH] rapidio/rio_mport_cdev: fix build failure if CONFIG_DMA_ENGINE is not enabled

From: Randy Dunlap <[email-masked]>
Date: Mon, 29 Feb 2016 13:39:02 -0800

On 02/29/16 08:52, Alexandre Bounine wrote:
> Fix the driver build failure if CONFIG_DMA_ENGINE option is not enabled
> This patch is applicable to linux-next tree.
> 
> Signed-off-by: Alexandre Bounine <[email-masked]>
> Reported-by: Stephen Rothwell <[email-masked]>
> Cc: Randy Dunlap <[email-masked]>
> Cc: Matt Porter <[email-masked]>
> Cc: [email-masked]
> Cc: [email-masked]
> ---
>  drivers/rapidio/devices/rio_mport_cdev.c |   18 ++++++++++++++----
>  1 files changed, 14 insertions(+), 4 deletions(-)

With this patch applied to linux-next of 20160229, I still get lots of
build errors (on i386).
.config is attached.

../drivers/rapidio/devices/rio_mport_cdev.c:548:2: error: unknown type name 'dma_cookie_t'
  dma_cookie_t cookie;
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:549:18: error: field 'status' has incomplete type
  enum dma_status status;
                  ^
In file included from ../include/linux/kernel.h:13:0,
                 from ../include/linux/list.h:8,
                 from ../include/linux/module.h:9,
                 from ../drivers/rapidio/devices/rio_mport_cdev.c:17:
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'mport_release_def_dma':
../drivers/rapidio/devices/rio_mport_cdev.c:563:41: error: dereferencing pointer to incomplete type
  rmcd_debug(EXIT, "DMA_%d", md->dma_chan->chan_id);
                                         ^
../include/linux/printk.h:114:17: note: in definition of macro 'no_printk'
   printk(fmt, ##__VA_ARGS__); \
                 ^
../drivers/rapidio/devices/rio_mport_cdev.c:563:2: note: in expansion of macro 'rmcd_debug'
  rmcd_debug(EXIT, "DMA_%d", md->dma_chan->chan_id);
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:564:2: error: implicit declaration of function 'rio_release_dma' [-Werror=implicit-function-declaration]
  rio_release_dma(md->dma_chan);
  ^
In file included from ../include/linux/kernel.h:13:0,
                 from ../include/linux/list.h:8,
                 from ../include/linux/module.h:9,
                 from ../drivers/rapidio/devices/rio_mport_cdev.c:17:
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'mport_release_dma':
../drivers/rapidio/devices/rio_mport_cdev.c:573:40: error: dereferencing pointer to incomplete type
  rmcd_debug(EXIT, "DMA_%d", priv->dmach->chan_id);
                                        ^
../include/linux/printk.h:114:17: note: in definition of macro 'no_printk'
   printk(fmt, ##__VA_ARGS__); \
                 ^
../drivers/rapidio/devices/rio_mport_cdev.c:573:2: note: in expansion of macro 'rmcd_debug'
  rmcd_debug(EXIT, "DMA_%d", priv->dmach->chan_id);
  ^
In file included from ../drivers/rapidio/devices/rio_mport_cdev.c:36:0:
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'dma_req_free':
../drivers/rapidio/devices/rio_mport_cdev.c:582:25: error: dereferencing pointer to incomplete type
  dma_unmap_sg(req->dmach->device->dev,
                         ^
../include/linux/dma-mapping.h:295:53: note: in definition of macro 'dma_unmap_sg'
 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
                                                     ^
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'dma_xfer_callback':
../drivers/rapidio/devices/rio_mport_cdev.c:607:2: error: implicit declaration of function 'dma_async_is_tx_complete' [-Werror=implicit-function-declaration]
  req->status = dma_async_is_tx_complete(priv->dmach, req->cookie,
  ^
../drivers/rapidio/devices/rio_mport_cdev.c: At top level:
../drivers/rapidio/devices/rio_mport_cdev.c:646:7: warning: 'enum dma_ctrl_flags' declared inside parameter list [enabled by default]
  enum dma_ctrl_flags flags)
       ^
../drivers/rapidio/devices/rio_mport_cdev.c:646:7: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
../drivers/rapidio/devices/rio_mport_cdev.c:646:7: warning: 'enum dma_transfer_direction' declared inside parameter list [enabled by default]
../drivers/rapidio/devices/rio_mport_cdev.c:645:63: error: parameter 5 ('dir') has incomplete type
  struct sg_table *sgt, int nents, enum dma_transfer_direction dir,
                                                               ^
../drivers/rapidio/devices/rio_mport_cdev.c:646:22: error: parameter 6 ('flags') has incomplete type
  enum dma_ctrl_flags flags)
                      ^
../drivers/rapidio/devices/rio_mport_cdev.c:644:2: error: function declaration isn't a prototype [-Werror=strict-prototypes]
 *prep_dma_xfer(struct dma_chan *chan, struct rio_transfer_io *transfer,
  ^
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'prep_dma_xfer':
../drivers/rapidio/devices/rio_mport_cdev.c:648:22: error: storage size of 'tx_data' isn't known
  struct rio_dma_data tx_data;
                      ^
../drivers/rapidio/devices/rio_mport_cdev.c:654:13: error: 'DMA_MEM_TO_DEV' undeclared (first use in this function)
  if (dir == DMA_MEM_TO_DEV) {
             ^
../drivers/rapidio/devices/rio_mport_cdev.c:654:13: note: each undeclared identifier is reported only once for each function it appears in
../drivers/rapidio/devices/rio_mport_cdev.c:657:22: error: 'RDW_ALL_NWRITE' undeclared (first use in this function)
    tx_data.wr_type = RDW_ALL_NWRITE;
                      ^
../drivers/rapidio/devices/rio_mport_cdev.c:660:22: error: 'RDW_ALL_NWRITE_R' undeclared (first use in this function)
    tx_data.wr_type = RDW_ALL_NWRITE_R;
                      ^
../drivers/rapidio/devices/rio_mport_cdev.c:663:22: error: 'RDW_LAST_NWRITE_R' undeclared (first use in this function)
    tx_data.wr_type = RDW_LAST_NWRITE_R;
                      ^
../drivers/rapidio/devices/rio_mport_cdev.c:666:22: error: 'RDW_DEFAULT' undeclared (first use in this function)
    tx_data.wr_type = RDW_DEFAULT;
                      ^
../drivers/rapidio/devices/rio_mport_cdev.c:673:2: error: implicit declaration of function 'rio_dma_prep_xfer' [-Werror=implicit-function-declaration]
  return rio_dma_prep_xfer(chan, transfer->rioid, &tx_data, dir, flags);
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:648:22: warning: unused variable 'tx_data' [-Wunused-variable]
  struct rio_dma_data tx_data;
                      ^
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'get_dma_channel':
../drivers/rapidio/devices/rio_mport_cdev.c:685:3: error: implicit declaration of function 'rio_request_mport_dma' [-Werror=implicit-function-declaration]
   priv->dmach = rio_request_mport_dma(priv->md->mport);
   ^
../drivers/rapidio/devices/rio_mport_cdev.c:685:15: warning: assignment makes pointer from integer without a cast [enabled by default]
   priv->dmach = rio_request_mport_dma(priv->md->mport);
               ^
In file included from ../include/linux/kernel.h:13:0,
                 from ../include/linux/list.h:8,
                 from ../include/linux/module.h:9,
                 from ../drivers/rapidio/devices/rio_mport_cdev.c:17:
../drivers/rapidio/devices/rio_mport_cdev.c:701:19: error: dereferencing pointer to incomplete type
        priv->dmach->chan_id);
                   ^
../include/linux/printk.h:114:17: note: in definition of macro 'no_printk'
   printk(fmt, ##__VA_ARGS__); \
                 ^
../drivers/rapidio/devices/rio_mport_cdev.c:700:4: note: in expansion of macro 'rmcd_debug'
    rmcd_debug(DMA, "Register DMA_chan %d as default",
    ^
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'do_dma_request':
../drivers/rapidio/devices/rio_mport_cdev.c:729:2: error: unknown type name 'dma_cookie_t'
  dma_cookie_t cookie;
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:731:30: error: storage size of 'dir' isn't known
  enum dma_transfer_direction dir;
                              ^
../drivers/rapidio/devices/rio_mport_cdev.c:739:40: error: 'DMA_DEV_TO_MEM' undeclared (first use in this function)
  dir = (req->dir == DMA_FROM_DEVICE) ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV;
                                        ^
../drivers/rapidio/devices/rio_mport_cdev.c:739:57: error: 'DMA_MEM_TO_DEV' undeclared (first use in this function)
  dir = (req->dir == DMA_FROM_DEVICE) ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV;
                                                         ^
In file included from ../include/linux/kernel.h:13:0,
                 from ../include/linux/list.h:8,
                 from ../include/linux/module.h:9,
                 from ../drivers/rapidio/devices/rio_mport_cdev.c:17:
../drivers/rapidio/devices/rio_mport_cdev.c:743:20: error: dereferencing pointer to incomplete type
      dev_name(&chan->dev->device),
                    ^
../include/linux/printk.h:114:17: note: in definition of macro 'no_printk'
   printk(fmt, ##__VA_ARGS__); \
                 ^
../drivers/rapidio/devices/rio_mport_cdev.c:741:2: note: in expansion of macro 'rmcd_debug'
  rmcd_debug(DMA, "%s(%d) uses %s for DMA_%s",
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:748:7: error: 'DMA_CTRL_ACK' undeclared (first use in this function)
       DMA_CTRL_ACK | DMA_PREP_INTERRUPT);
       ^
../drivers/rapidio/devices/rio_mport_cdev.c:748:22: error: 'DMA_PREP_INTERRUPT' undeclared (first use in this function)
       DMA_CTRL_ACK | DMA_PREP_INTERRUPT);
                      ^
../drivers/rapidio/devices/rio_mport_cdev.c:765:5: error: dereferencing pointer to incomplete type
   tx->callback = dma_faf_callback;
     ^
../drivers/rapidio/devices/rio_mport_cdev.c:767:5: error: dereferencing pointer to incomplete type
   tx->callback = dma_xfer_callback;
     ^
../drivers/rapidio/devices/rio_mport_cdev.c:768:4: error: dereferencing pointer to incomplete type
  tx->callback_param = req;
    ^
../drivers/rapidio/devices/rio_mport_cdev.c:772:16: error: 'DMA_IN_PROGRESS' undeclared (first use in this function)
  req->status = DMA_IN_PROGRESS;
                ^
../drivers/rapidio/devices/rio_mport_cdev.c:775:2: error: implicit declaration of function 'dmaengine_submit' [-Werror=implicit-function-declaration]
  cookie = dmaengine_submit(tx);
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:781:2: error: implicit declaration of function 'dma_submit_error' [-Werror=implicit-function-declaration]
  if (dma_submit_error(cookie)) {
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:788:2: error: implicit declaration of function 'dma_async_issue_pending' [-Werror=implicit-function-declaration]
  dma_async_issue_pending(chan);
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:816:21: error: 'DMA_COMPLETE' undeclared (first use in this function)
  if (req->status != DMA_COMPLETE) {
                     ^
../drivers/rapidio/devices/rio_mport_cdev.c:731:30: warning: unused variable 'dir' [-Wunused-variable]
  enum dma_transfer_direction dir;
                              ^
In file included from ../drivers/rapidio/devices/rio_mport_cdev.c:36:0:
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'rio_dma_transfer':
../drivers/rapidio/devices/rio_mport_cdev.c:958:25: error: dereferencing pointer to incomplete type
  nents = dma_map_sg(chan->device->dev,
                         ^
../include/linux/dma-mapping.h:294:49: note: in definition of macro 'dma_map_sg'
 #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
                                                 ^
../drivers/rapidio/devices/rio_mport_cdev.c:988:19: error: dereferencing pointer to incomplete type
  dma_unmap_sg(chan->device->dev, req->sgt.sgl, req->sgt.nents, dir);
                   ^
../include/linux/dma-mapping.h:295:53: note: in definition of macro 'dma_unmap_sg'
 #define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
                                                     ^
../drivers/rapidio/devices/rio_mport_cdev.c: In function 'rio_mport_wait_for_async_dma':
../drivers/rapidio/devices/rio_mport_cdev.c:1057:2: error: unknown type name 'dma_cookie_t'
  dma_cookie_t cookie;
  ^
../drivers/rapidio/devices/rio_mport_cdev.c:1108:21: error: 'DMA_COMPLETE' undeclared (first use in this function)
  if (req->status != DMA_COMPLETE) {
                     ^
../drivers/rapidio/devices/rio_mport_cdev.c:1118:21: error: 'DMA_IN_PROGRESS' undeclared (first use in this function)
  if (req->status != DMA_IN_PROGRESS && req->status != DMA_PAUSED)
                     ^
../drivers/rapidio/devices/rio_mport_cdev.c:1118:55: error: 'DMA_PAUSED' undeclared (first use in this function)
  if (req->status != DMA_IN_PROGRESS && req->status != DMA_PAUSED)
                                                       ^
../drivers/rapidio/devices/rio_mport_cdev.c: At top level:
../drivers/rapidio/devices/rio_mport_cdev.c:558:13: warning: 'mport_release_def_dma' defined but not used [-Wunused-function]
 static void mport_release_def_dma(struct kref *dma_ref)
             ^

-- 
~Randy