32 #include <linux/module.h>
34 #include <linux/device.h>
35 #include <linux/netdevice.h>
38 #include <linux/errno.h>
39 #include <linux/list.h>
41 #include <linux/ethtool.h>
42 #include <linux/rtnetlink.h>
47 #include <asm/byteorder.h>
57 static int fastreg_support = 1;
67 static int c4iw_ah_destroy(
struct ib_ah *
ah)
82 static int c4iw_process_mad(
struct ib_device *ibdev,
int mad_flags,
96 PDBG(
"%s context %p\n", __func__, context);
108 struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
110 PDBG(
"%s ibdev %p\n", __func__, ibdev);
111 context = kzalloc(
sizeof(*context),
GFP_KERNEL);
115 INIT_LIST_HEAD(&context->
mmaps);
130 PDBG(
"%s pgoff 0x%lx key 0x%x len %d\n", __func__, vma->
vm_pgoff,
136 rdev = &(to_c4iw_dev(context->
device)->rdev);
137 ucontext = to_c4iw_ucontext(context);
139 mm = remove_mmap(ucontext, key, len);
183 static int c4iw_deallocate_pd(
struct ib_pd *pd)
188 php = to_c4iw_pd(pd);
190 PDBG(
"%s ibpd %p pdid 0x%x\n", __func__, pd, php->
pdid);
193 rhp->
rdev.stats.pd.cur--;
207 PDBG(
"%s ibdev %p\n", __func__, ibdev);
220 if (ib_copy_to_udata(udata, &php->
pdid,
sizeof(
u32))) {
221 c4iw_deallocate_pd(&php->
ibpd);
226 rhp->
rdev.stats.pd.cur++;
227 if (rhp->
rdev.stats.pd.cur > rhp->
rdev.stats.pd.max)
228 rhp->
rdev.stats.pd.max = rhp->
rdev.stats.pd.cur;
230 PDBG(
"%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php);
237 PDBG(
"%s ibdev %p\n", __func__, ibdev);
247 PDBG(
"%s ibdev %p, port %d, index %d, gid %p\n",
248 __func__, ibdev, port, index, gid);
249 dev = to_c4iw_dev(ibdev);
252 memcpy(&(gid->
raw[0]), dev->
rdev.lldi.ports[port-1]->dev_addr, 6);
256 static int c4iw_query_device(
struct ib_device *ibdev,
261 PDBG(
"%s ibdev %p\n", __func__, ibdev);
263 dev = to_c4iw_dev(ibdev);
264 memset(props, 0,
sizeof *props);
289 static int c4iw_query_port(
struct ib_device *ibdev,
u8 port,
294 struct in_device *inetdev;
296 PDBG(
"%s ibdev %p\n", __func__, ibdev);
298 dev = to_c4iw_dev(ibdev);
299 netdev = dev->
rdev.lldi.ports[port-1];
303 if (netdev->
mtu >= 4096)
305 else if (netdev->
mtu >= 2048)
307 else if (netdev->
mtu >= 1024)
309 else if (netdev->
mtu >= 512)
314 if (!netif_carrier_ok(netdev))
317 inetdev = in_dev_get(netdev);
319 if (inetdev->ifa_list)
348 PDBG(
"%s dev 0x%p\n", __func__, dev);
349 return sprintf(buf,
"%d\n", c4iw_dev->
rdev.lldi.adapter_type);
357 PDBG(
"%s dev 0x%p\n", __func__, dev);
359 return sprintf(buf,
"%u.%u.%u.%u\n",
369 struct c4iw_dev *c4iw_dev =
container_of(dev,
struct c4iw_dev,
374 PDBG(
"%s dev 0x%p\n", __func__, dev);
382 struct c4iw_dev *c4iw_dev =
container_of(dev,
struct c4iw_dev,
384 PDBG(
"%s dev 0x%p\n", __func__, dev);
385 return sprintf(buf,
"%x.%x\n", c4iw_dev->
rdev.lldi.pdev->vendor,
386 c4iw_dev->
rdev.lldi.pdev->device);
389 static int c4iw_get_mib(
struct ib_device *ibdev,
393 struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);
396 memset(stats, 0,
sizeof *stats);
397 stats->
iw.tcpInSegs =
v4.tcpInSegs + v6.tcpInSegs;
398 stats->
iw.tcpOutSegs =
v4.tcpOutSegs + v6.tcpOutSegs;
399 stats->
iw.tcpRetransSegs =
v4.tcpRetransSegs + v6.tcpRetransSegs;
400 stats->
iw.tcpOutRsts =
v4.tcpOutRsts + v6.tcpOutSegs;
422 PDBG(
"%s c4iw_dev %p\n", __func__, dev);
431 dev->
ibdev.local_dma_lkey = 0;
432 dev->
ibdev.uverbs_cmd_mask =
453 dev->
ibdev.phys_port_cnt = dev->
rdev.lldi.nports;
454 dev->
ibdev.num_comp_vectors = 1;
455 dev->
ibdev.dma_device = &(dev->
rdev.lldi.pdev->dev);
456 dev->
ibdev.query_device = c4iw_query_device;
457 dev->
ibdev.query_port = c4iw_query_port;
458 dev->
ibdev.query_pkey = c4iw_query_pkey;
459 dev->
ibdev.query_gid = c4iw_query_gid;
460 dev->
ibdev.alloc_ucontext = c4iw_alloc_ucontext;
461 dev->
ibdev.dealloc_ucontext = c4iw_dealloc_ucontext;
462 dev->
ibdev.mmap = c4iw_mmap;
463 dev->
ibdev.alloc_pd = c4iw_allocate_pd;
464 dev->
ibdev.dealloc_pd = c4iw_deallocate_pd;
465 dev->
ibdev.create_ah = c4iw_ah_create;
466 dev->
ibdev.destroy_ah = c4iw_ah_destroy;
486 dev->
ibdev.attach_mcast = c4iw_multicast_attach;
487 dev->
ibdev.detach_mcast = c4iw_multicast_detach;
488 dev->
ibdev.process_mad = c4iw_process_mad;
492 dev->
ibdev.get_protocol_stats = c4iw_get_mib;
496 if (!dev->
ibdev.iwcm)
512 for (i = 0; i <
ARRAY_SIZE(c4iw_class_attributes); ++
i) {
514 c4iw_class_attributes[i]);
530 PDBG(
"%s c4iw_dev %p\n", __func__, dev);
531 for (i = 0; i <
ARRAY_SIZE(c4iw_class_attributes); ++
i)
533 c4iw_class_attributes[i]);