cxgb3_offload.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. /*
  2. * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/list.h>
  33. #include <net/neighbour.h>
  34. #include <linux/notifier.h>
  35. #include <asm/atomic.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/if_vlan.h>
  38. #include <net/netevent.h>
  39. #include <linux/highmem.h>
  40. #include <linux/vmalloc.h>
  41. #include "common.h"
  42. #include "regs.h"
  43. #include "cxgb3_ioctl.h"
  44. #include "cxgb3_ctl_defs.h"
  45. #include "cxgb3_defs.h"
  46. #include "l2t.h"
  47. #include "firmware_exports.h"
  48. #include "cxgb3_offload.h"
  49. static LIST_HEAD(client_list);
  50. static LIST_HEAD(ofld_dev_list);
  51. static DEFINE_MUTEX(cxgb3_db_lock);
  52. static DEFINE_RWLOCK(adapter_list_lock);
  53. static LIST_HEAD(adapter_list);
  54. static const unsigned int MAX_ATIDS = 64 * 1024;
  55. static const unsigned int ATID_BASE = 0x100000;
  56. static inline int offload_activated(struct t3cdev *tdev)
  57. {
  58. const struct adapter *adapter = tdev2adap(tdev);
  59. return (test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map));
  60. }
  61. /**
  62. * cxgb3_register_client - register an offload client
  63. * @client: the client
  64. *
  65. * Add the client to the client list,
  66. * and call backs the client for each activated offload device
  67. */
  68. void cxgb3_register_client(struct cxgb3_client *client)
  69. {
  70. struct t3cdev *tdev;
  71. mutex_lock(&cxgb3_db_lock);
  72. list_add_tail(&client->client_list, &client_list);
  73. if (client->add) {
  74. list_for_each_entry(tdev, &ofld_dev_list, ofld_dev_list) {
  75. if (offload_activated(tdev))
  76. client->add(tdev);
  77. }
  78. }
  79. mutex_unlock(&cxgb3_db_lock);
  80. }
  81. EXPORT_SYMBOL(cxgb3_register_client);
  82. /**
  83. * cxgb3_unregister_client - unregister an offload client
  84. * @client: the client
  85. *
  86. * Remove the client to the client list,
  87. * and call backs the client for each activated offload device.
  88. */
  89. void cxgb3_unregister_client(struct cxgb3_client *client)
  90. {
  91. struct t3cdev *tdev;
  92. mutex_lock(&cxgb3_db_lock);
  93. list_del(&client->client_list);
  94. if (client->remove) {
  95. list_for_each_entry(tdev, &ofld_dev_list, ofld_dev_list) {
  96. if (offload_activated(tdev))
  97. client->remove(tdev);
  98. }
  99. }
  100. mutex_unlock(&cxgb3_db_lock);
  101. }
  102. EXPORT_SYMBOL(cxgb3_unregister_client);
  103. /**
  104. * cxgb3_add_clients - activate registered clients for an offload device
  105. * @tdev: the offload device
  106. *
  107. * Call backs all registered clients once a offload device is activated
  108. */
  109. void cxgb3_add_clients(struct t3cdev *tdev)
  110. {
  111. struct cxgb3_client *client;
  112. mutex_lock(&cxgb3_db_lock);
  113. list_for_each_entry(client, &client_list, client_list) {
  114. if (client->add)
  115. client->add(tdev);
  116. }
  117. mutex_unlock(&cxgb3_db_lock);
  118. }
  119. /**
  120. * cxgb3_remove_clients - deactivates registered clients
  121. * for an offload device
  122. * @tdev: the offload device
  123. *
  124. * Call backs all registered clients once a offload device is deactivated
  125. */
  126. void cxgb3_remove_clients(struct t3cdev *tdev)
  127. {
  128. struct cxgb3_client *client;
  129. mutex_lock(&cxgb3_db_lock);
  130. list_for_each_entry(client, &client_list, client_list) {
  131. if (client->remove)
  132. client->remove(tdev);
  133. }
  134. mutex_unlock(&cxgb3_db_lock);
  135. }
  136. static struct net_device *get_iff_from_mac(struct adapter *adapter,
  137. const unsigned char *mac,
  138. unsigned int vlan)
  139. {
  140. int i;
  141. for_each_port(adapter, i) {
  142. struct vlan_group *grp;
  143. struct net_device *dev = adapter->port[i];
  144. const struct port_info *p = netdev_priv(dev);
  145. if (!memcmp(dev->dev_addr, mac, ETH_ALEN)) {
  146. if (vlan && vlan != VLAN_VID_MASK) {
  147. grp = p->vlan_grp;
  148. dev = NULL;
  149. if (grp)
  150. dev = vlan_group_get_device(grp, vlan);
  151. } else
  152. while (dev->master)
  153. dev = dev->master;
  154. return dev;
  155. }
  156. }
  157. return NULL;
  158. }
  159. static int cxgb_ulp_iscsi_ctl(struct adapter *adapter, unsigned int req,
  160. void *data)
  161. {
  162. int ret = 0;
  163. struct ulp_iscsi_info *uiip = data;
  164. switch (req) {
  165. case ULP_ISCSI_GET_PARAMS:
  166. uiip->pdev = adapter->pdev;
  167. uiip->llimit = t3_read_reg(adapter, A_ULPRX_ISCSI_LLIMIT);
  168. uiip->ulimit = t3_read_reg(adapter, A_ULPRX_ISCSI_ULIMIT);
  169. uiip->tagmask = t3_read_reg(adapter, A_ULPRX_ISCSI_TAGMASK);
  170. /*
  171. * On tx, the iscsi pdu has to be <= tx page size and has to
  172. * fit into the Tx PM FIFO.
  173. */
  174. uiip->max_txsz = min(adapter->params.tp.tx_pg_size,
  175. t3_read_reg(adapter, A_PM1_TX_CFG) >> 17);
  176. /* on rx, the iscsi pdu has to be < rx page size and the
  177. whole pdu + cpl headers has to fit into one sge buffer */
  178. uiip->max_rxsz = min_t(unsigned int,
  179. adapter->params.tp.rx_pg_size,
  180. (adapter->sge.qs[0].fl[1].buf_size -
  181. sizeof(struct cpl_rx_data) * 2 -
  182. sizeof(struct cpl_rx_data_ddp)));
  183. break;
  184. case ULP_ISCSI_SET_PARAMS:
  185. t3_write_reg(adapter, A_ULPRX_ISCSI_TAGMASK, uiip->tagmask);
  186. break;
  187. default:
  188. ret = -EOPNOTSUPP;
  189. }
  190. return ret;
  191. }
  192. /* Response queue used for RDMA events. */
  193. #define ASYNC_NOTIF_RSPQ 0
  194. static int cxgb_rdma_ctl(struct adapter *adapter, unsigned int req, void *data)
  195. {
  196. int ret = 0;
  197. switch (req) {
  198. case RDMA_GET_PARAMS:{
  199. struct rdma_info *req = data;
  200. struct pci_dev *pdev = adapter->pdev;
  201. req->udbell_physbase = pci_resource_start(pdev, 2);
  202. req->udbell_len = pci_resource_len(pdev, 2);
  203. req->tpt_base =
  204. t3_read_reg(adapter, A_ULPTX_TPT_LLIMIT);
  205. req->tpt_top = t3_read_reg(adapter, A_ULPTX_TPT_ULIMIT);
  206. req->pbl_base =
  207. t3_read_reg(adapter, A_ULPTX_PBL_LLIMIT);
  208. req->pbl_top = t3_read_reg(adapter, A_ULPTX_PBL_ULIMIT);
  209. req->rqt_base = t3_read_reg(adapter, A_ULPRX_RQ_LLIMIT);
  210. req->rqt_top = t3_read_reg(adapter, A_ULPRX_RQ_ULIMIT);
  211. req->kdb_addr = adapter->regs + A_SG_KDOORBELL;
  212. req->pdev = pdev;
  213. break;
  214. }
  215. case RDMA_CQ_OP:{
  216. unsigned long flags;
  217. struct rdma_cq_op *req = data;
  218. /* may be called in any context */
  219. spin_lock_irqsave(&adapter->sge.reg_lock, flags);
  220. ret = t3_sge_cqcntxt_op(adapter, req->id, req->op,
  221. req->credits);
  222. spin_unlock_irqrestore(&adapter->sge.reg_lock, flags);
  223. break;
  224. }
  225. case RDMA_GET_MEM:{
  226. struct ch_mem_range *t = data;
  227. struct mc7 *mem;
  228. if ((t->addr & 7) || (t->len & 7))
  229. return -EINVAL;
  230. if (t->mem_id == MEM_CM)
  231. mem = &adapter->cm;
  232. else if (t->mem_id == MEM_PMRX)
  233. mem = &adapter->pmrx;
  234. else if (t->mem_id == MEM_PMTX)
  235. mem = &adapter->pmtx;
  236. else
  237. return -EINVAL;
  238. ret =
  239. t3_mc7_bd_read(mem, t->addr / 8, t->len / 8,
  240. (u64 *) t->buf);
  241. if (ret)
  242. return ret;
  243. break;
  244. }
  245. case RDMA_CQ_SETUP:{
  246. struct rdma_cq_setup *req = data;
  247. spin_lock_irq(&adapter->sge.reg_lock);
  248. ret =
  249. t3_sge_init_cqcntxt(adapter, req->id,
  250. req->base_addr, req->size,
  251. ASYNC_NOTIF_RSPQ,
  252. req->ovfl_mode, req->credits,
  253. req->credit_thres);
  254. spin_unlock_irq(&adapter->sge.reg_lock);
  255. break;
  256. }
  257. case RDMA_CQ_DISABLE:
  258. spin_lock_irq(&adapter->sge.reg_lock);
  259. ret = t3_sge_disable_cqcntxt(adapter, *(unsigned int *)data);
  260. spin_unlock_irq(&adapter->sge.reg_lock);
  261. break;
  262. case RDMA_CTRL_QP_SETUP:{
  263. struct rdma_ctrlqp_setup *req = data;
  264. spin_lock_irq(&adapter->sge.reg_lock);
  265. ret = t3_sge_init_ecntxt(adapter, FW_RI_SGEEC_START, 0,
  266. SGE_CNTXT_RDMA,
  267. ASYNC_NOTIF_RSPQ,
  268. req->base_addr, req->size,
  269. FW_RI_TID_START, 1, 0);
  270. spin_unlock_irq(&adapter->sge.reg_lock);
  271. break;
  272. }
  273. default:
  274. ret = -EOPNOTSUPP;
  275. }
  276. return ret;
  277. }
  278. static int cxgb_offload_ctl(struct t3cdev *tdev, unsigned int req, void *data)
  279. {
  280. struct adapter *adapter = tdev2adap(tdev);
  281. struct tid_range *tid;
  282. struct mtutab *mtup;
  283. struct iff_mac *iffmacp;
  284. struct ddp_params *ddpp;
  285. struct adap_ports *ports;
  286. int i;
  287. switch (req) {
  288. case GET_MAX_OUTSTANDING_WR:
  289. *(unsigned int *)data = FW_WR_NUM;
  290. break;
  291. case GET_WR_LEN:
  292. *(unsigned int *)data = WR_FLITS;
  293. break;
  294. case GET_TX_MAX_CHUNK:
  295. *(unsigned int *)data = 1 << 20; /* 1MB */
  296. break;
  297. case GET_TID_RANGE:
  298. tid = data;
  299. tid->num = t3_mc5_size(&adapter->mc5) -
  300. adapter->params.mc5.nroutes -
  301. adapter->params.mc5.nfilters - adapter->params.mc5.nservers;
  302. tid->base = 0;
  303. break;
  304. case GET_STID_RANGE:
  305. tid = data;
  306. tid->num = adapter->params.mc5.nservers;
  307. tid->base = t3_mc5_size(&adapter->mc5) - tid->num -
  308. adapter->params.mc5.nfilters - adapter->params.mc5.nroutes;
  309. break;
  310. case GET_L2T_CAPACITY:
  311. *(unsigned int *)data = 2048;
  312. break;
  313. case GET_MTUS:
  314. mtup = data;
  315. mtup->size = NMTUS;
  316. mtup->mtus = adapter->params.mtus;
  317. break;
  318. case GET_IFF_FROM_MAC:
  319. iffmacp = data;
  320. iffmacp->dev = get_iff_from_mac(adapter, iffmacp->mac_addr,
  321. iffmacp->vlan_tag &
  322. VLAN_VID_MASK);
  323. break;
  324. case GET_DDP_PARAMS:
  325. ddpp = data;
  326. ddpp->llimit = t3_read_reg(adapter, A_ULPRX_TDDP_LLIMIT);
  327. ddpp->ulimit = t3_read_reg(adapter, A_ULPRX_TDDP_ULIMIT);
  328. ddpp->tag_mask = t3_read_reg(adapter, A_ULPRX_TDDP_TAGMASK);
  329. break;
  330. case GET_PORTS:
  331. ports = data;
  332. ports->nports = adapter->params.nports;
  333. for_each_port(adapter, i)
  334. ports->lldevs[i] = adapter->port[i];
  335. break;
  336. case ULP_ISCSI_GET_PARAMS:
  337. case ULP_ISCSI_SET_PARAMS:
  338. if (!offload_running(adapter))
  339. return -EAGAIN;
  340. return cxgb_ulp_iscsi_ctl(adapter, req, data);
  341. case RDMA_GET_PARAMS:
  342. case RDMA_CQ_OP:
  343. case RDMA_CQ_SETUP:
  344. case RDMA_CQ_DISABLE:
  345. case RDMA_CTRL_QP_SETUP:
  346. case RDMA_GET_MEM:
  347. if (!offload_running(adapter))
  348. return -EAGAIN;
  349. return cxgb_rdma_ctl(adapter, req, data);
  350. default:
  351. return -EOPNOTSUPP;
  352. }
  353. return 0;
  354. }
  355. /*
  356. * Dummy handler for Rx offload packets in case we get an offload packet before
  357. * proper processing is setup. This complains and drops the packet as it isn't
  358. * normal to get offload packets at this stage.
  359. */
  360. static int rx_offload_blackhole(struct t3cdev *dev, struct sk_buff **skbs,
  361. int n)
  362. {
  363. CH_ERR(tdev2adap(dev), "%d unexpected offload packets, first data %u\n",
  364. n, ntohl(*(__be32 *)skbs[0]->data));
  365. while (n--)
  366. dev_kfree_skb_any(skbs[n]);
  367. return 0;
  368. }
  369. static void dummy_neigh_update(struct t3cdev *dev, struct neighbour *neigh)
  370. {
  371. }
  372. void cxgb3_set_dummy_ops(struct t3cdev *dev)
  373. {
  374. dev->recv = rx_offload_blackhole;
  375. dev->neigh_update = dummy_neigh_update;
  376. }
  377. /*
  378. * Free an active-open TID.
  379. */
  380. void *cxgb3_free_atid(struct t3cdev *tdev, int atid)
  381. {
  382. struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
  383. union active_open_entry *p = atid2entry(t, atid);
  384. void *ctx = p->t3c_tid.ctx;
  385. spin_lock_bh(&t->atid_lock);
  386. p->next = t->afree;
  387. t->afree = p;
  388. t->atids_in_use--;
  389. spin_unlock_bh(&t->atid_lock);
  390. return ctx;
  391. }
  392. EXPORT_SYMBOL(cxgb3_free_atid);
  393. /*
  394. * Free a server TID and return it to the free pool.
  395. */
  396. void cxgb3_free_stid(struct t3cdev *tdev, int stid)
  397. {
  398. struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
  399. union listen_entry *p = stid2entry(t, stid);
  400. spin_lock_bh(&t->stid_lock);
  401. p->next = t->sfree;
  402. t->sfree = p;
  403. t->stids_in_use--;
  404. spin_unlock_bh(&t->stid_lock);
  405. }
  406. EXPORT_SYMBOL(cxgb3_free_stid);
  407. void cxgb3_insert_tid(struct t3cdev *tdev, struct cxgb3_client *client,
  408. void *ctx, unsigned int tid)
  409. {
  410. struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
  411. t->tid_tab[tid].client = client;
  412. t->tid_tab[tid].ctx = ctx;
  413. atomic_inc(&t->tids_in_use);
  414. }
  415. EXPORT_SYMBOL(cxgb3_insert_tid);
  416. /*
  417. * Populate a TID_RELEASE WR. The skb must be already propely sized.
  418. */
  419. static inline void mk_tid_release(struct sk_buff *skb, unsigned int tid)
  420. {
  421. struct cpl_tid_release *req;
  422. skb->priority = CPL_PRIORITY_SETUP;
  423. req = (struct cpl_tid_release *)__skb_put(skb, sizeof(*req));
  424. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  425. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
  426. }
  427. static void t3_process_tid_release_list(struct work_struct *work)
  428. {
  429. struct t3c_data *td = container_of(work, struct t3c_data,
  430. tid_release_task);
  431. struct sk_buff *skb;
  432. struct t3cdev *tdev = td->dev;
  433. spin_lock_bh(&td->tid_release_lock);
  434. while (td->tid_release_list) {
  435. struct t3c_tid_entry *p = td->tid_release_list;
  436. td->tid_release_list = (struct t3c_tid_entry *)p->ctx;
  437. spin_unlock_bh(&td->tid_release_lock);
  438. skb = alloc_skb(sizeof(struct cpl_tid_release),
  439. GFP_KERNEL | __GFP_NOFAIL);
  440. mk_tid_release(skb, p - td->tid_maps.tid_tab);
  441. cxgb3_ofld_send(tdev, skb);
  442. p->ctx = NULL;
  443. spin_lock_bh(&td->tid_release_lock);
  444. }
  445. spin_unlock_bh(&td->tid_release_lock);
  446. }
  447. /* use ctx as a next pointer in the tid release list */
  448. void cxgb3_queue_tid_release(struct t3cdev *tdev, unsigned int tid)
  449. {
  450. struct t3c_data *td = T3C_DATA(tdev);
  451. struct t3c_tid_entry *p = &td->tid_maps.tid_tab[tid];
  452. spin_lock_bh(&td->tid_release_lock);
  453. p->ctx = (void *)td->tid_release_list;
  454. td->tid_release_list = p;
  455. if (!p->ctx)
  456. schedule_work(&td->tid_release_task);
  457. spin_unlock_bh(&td->tid_release_lock);
  458. }
  459. EXPORT_SYMBOL(cxgb3_queue_tid_release);
  460. /*
  461. * Remove a tid from the TID table. A client may defer processing its last
  462. * CPL message if it is locked at the time it arrives, and while the message
  463. * sits in the client's backlog the TID may be reused for another connection.
  464. * To handle this we atomically switch the TID association if it still points
  465. * to the original client context.
  466. */
  467. void cxgb3_remove_tid(struct t3cdev *tdev, void *ctx, unsigned int tid)
  468. {
  469. struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
  470. BUG_ON(tid >= t->ntids);
  471. if (tdev->type == T3A)
  472. (void)cmpxchg(&t->tid_tab[tid].ctx, ctx, NULL);
  473. else {
  474. struct sk_buff *skb;
  475. skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
  476. if (likely(skb)) {
  477. mk_tid_release(skb, tid);
  478. cxgb3_ofld_send(tdev, skb);
  479. t->tid_tab[tid].ctx = NULL;
  480. } else
  481. cxgb3_queue_tid_release(tdev, tid);
  482. }
  483. atomic_dec(&t->tids_in_use);
  484. }
  485. EXPORT_SYMBOL(cxgb3_remove_tid);
  486. int cxgb3_alloc_atid(struct t3cdev *tdev, struct cxgb3_client *client,
  487. void *ctx)
  488. {
  489. int atid = -1;
  490. struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
  491. spin_lock_bh(&t->atid_lock);
  492. if (t->afree &&
  493. t->atids_in_use + atomic_read(&t->tids_in_use) + MC5_MIN_TIDS <=
  494. t->ntids) {
  495. union active_open_entry *p = t->afree;
  496. atid = (p - t->atid_tab) + t->atid_base;
  497. t->afree = p->next;
  498. p->t3c_tid.ctx = ctx;
  499. p->t3c_tid.client = client;
  500. t->atids_in_use++;
  501. }
  502. spin_unlock_bh(&t->atid_lock);
  503. return atid;
  504. }
  505. EXPORT_SYMBOL(cxgb3_alloc_atid);
  506. int cxgb3_alloc_stid(struct t3cdev *tdev, struct cxgb3_client *client,
  507. void *ctx)
  508. {
  509. int stid = -1;
  510. struct tid_info *t = &(T3C_DATA(tdev))->tid_maps;
  511. spin_lock_bh(&t->stid_lock);
  512. if (t->sfree) {
  513. union listen_entry *p = t->sfree;
  514. stid = (p - t->stid_tab) + t->stid_base;
  515. t->sfree = p->next;
  516. p->t3c_tid.ctx = ctx;
  517. p->t3c_tid.client = client;
  518. t->stids_in_use++;
  519. }
  520. spin_unlock_bh(&t->stid_lock);
  521. return stid;
  522. }
  523. EXPORT_SYMBOL(cxgb3_alloc_stid);
  524. static int do_smt_write_rpl(struct t3cdev *dev, struct sk_buff *skb)
  525. {
  526. struct cpl_smt_write_rpl *rpl = cplhdr(skb);
  527. if (rpl->status != CPL_ERR_NONE)
  528. printk(KERN_ERR
  529. "Unexpected SMT_WRITE_RPL status %u for entry %u\n",
  530. rpl->status, GET_TID(rpl));
  531. return CPL_RET_BUF_DONE;
  532. }
  533. static int do_l2t_write_rpl(struct t3cdev *dev, struct sk_buff *skb)
  534. {
  535. struct cpl_l2t_write_rpl *rpl = cplhdr(skb);
  536. if (rpl->status != CPL_ERR_NONE)
  537. printk(KERN_ERR
  538. "Unexpected L2T_WRITE_RPL status %u for entry %u\n",
  539. rpl->status, GET_TID(rpl));
  540. return CPL_RET_BUF_DONE;
  541. }
  542. static int do_act_open_rpl(struct t3cdev *dev, struct sk_buff *skb)
  543. {
  544. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  545. unsigned int atid = G_TID(ntohl(rpl->atid));
  546. struct t3c_tid_entry *t3c_tid;
  547. t3c_tid = lookup_atid(&(T3C_DATA(dev))->tid_maps, atid);
  548. if (t3c_tid->ctx && t3c_tid->client && t3c_tid->client->handlers &&
  549. t3c_tid->client->handlers[CPL_ACT_OPEN_RPL]) {
  550. return t3c_tid->client->handlers[CPL_ACT_OPEN_RPL] (dev, skb,
  551. t3c_tid->
  552. ctx);
  553. } else {
  554. printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
  555. dev->name, CPL_ACT_OPEN_RPL);
  556. return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
  557. }
  558. }
  559. static int do_stid_rpl(struct t3cdev *dev, struct sk_buff *skb)
  560. {
  561. union opcode_tid *p = cplhdr(skb);
  562. unsigned int stid = G_TID(ntohl(p->opcode_tid));
  563. struct t3c_tid_entry *t3c_tid;
  564. t3c_tid = lookup_stid(&(T3C_DATA(dev))->tid_maps, stid);
  565. if (t3c_tid->ctx && t3c_tid->client->handlers &&
  566. t3c_tid->client->handlers[p->opcode]) {
  567. return t3c_tid->client->handlers[p->opcode] (dev, skb,
  568. t3c_tid->ctx);
  569. } else {
  570. printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
  571. dev->name, p->opcode);
  572. return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
  573. }
  574. }
  575. static int do_hwtid_rpl(struct t3cdev *dev, struct sk_buff *skb)
  576. {
  577. union opcode_tid *p = cplhdr(skb);
  578. unsigned int hwtid = G_TID(ntohl(p->opcode_tid));
  579. struct t3c_tid_entry *t3c_tid;
  580. t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid);
  581. if (t3c_tid->ctx && t3c_tid->client->handlers &&
  582. t3c_tid->client->handlers[p->opcode]) {
  583. return t3c_tid->client->handlers[p->opcode]
  584. (dev, skb, t3c_tid->ctx);
  585. } else {
  586. printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
  587. dev->name, p->opcode);
  588. return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
  589. }
  590. }
  591. static int do_cr(struct t3cdev *dev, struct sk_buff *skb)
  592. {
  593. struct cpl_pass_accept_req *req = cplhdr(skb);
  594. unsigned int stid = G_PASS_OPEN_TID(ntohl(req->tos_tid));
  595. struct t3c_tid_entry *t3c_tid;
  596. t3c_tid = lookup_stid(&(T3C_DATA(dev))->tid_maps, stid);
  597. if (t3c_tid->ctx && t3c_tid->client->handlers &&
  598. t3c_tid->client->handlers[CPL_PASS_ACCEPT_REQ]) {
  599. return t3c_tid->client->handlers[CPL_PASS_ACCEPT_REQ]
  600. (dev, skb, t3c_tid->ctx);
  601. } else {
  602. printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
  603. dev->name, CPL_PASS_ACCEPT_REQ);
  604. return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
  605. }
  606. }
  607. static int do_abort_req_rss(struct t3cdev *dev, struct sk_buff *skb)
  608. {
  609. union opcode_tid *p = cplhdr(skb);
  610. unsigned int hwtid = G_TID(ntohl(p->opcode_tid));
  611. struct t3c_tid_entry *t3c_tid;
  612. t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid);
  613. if (t3c_tid->ctx && t3c_tid->client->handlers &&
  614. t3c_tid->client->handlers[p->opcode]) {
  615. return t3c_tid->client->handlers[p->opcode]
  616. (dev, skb, t3c_tid->ctx);
  617. } else {
  618. struct cpl_abort_req_rss *req = cplhdr(skb);
  619. struct cpl_abort_rpl *rpl;
  620. struct sk_buff *skb =
  621. alloc_skb(sizeof(struct cpl_abort_rpl), GFP_ATOMIC);
  622. if (!skb) {
  623. printk("do_abort_req_rss: couldn't get skb!\n");
  624. goto out;
  625. }
  626. skb->priority = CPL_PRIORITY_DATA;
  627. __skb_put(skb, sizeof(struct cpl_abort_rpl));
  628. rpl = cplhdr(skb);
  629. rpl->wr.wr_hi =
  630. htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL));
  631. rpl->wr.wr_lo = htonl(V_WR_TID(GET_TID(req)));
  632. OPCODE_TID(rpl) =
  633. htonl(MK_OPCODE_TID(CPL_ABORT_RPL, GET_TID(req)));
  634. rpl->cmd = req->status;
  635. cxgb3_ofld_send(dev, skb);
  636. out:
  637. return CPL_RET_BUF_DONE;
  638. }
  639. }
  640. static int do_act_establish(struct t3cdev *dev, struct sk_buff *skb)
  641. {
  642. struct cpl_act_establish *req = cplhdr(skb);
  643. unsigned int atid = G_PASS_OPEN_TID(ntohl(req->tos_tid));
  644. struct t3c_tid_entry *t3c_tid;
  645. t3c_tid = lookup_atid(&(T3C_DATA(dev))->tid_maps, atid);
  646. if (t3c_tid->ctx && t3c_tid->client->handlers &&
  647. t3c_tid->client->handlers[CPL_ACT_ESTABLISH]) {
  648. return t3c_tid->client->handlers[CPL_ACT_ESTABLISH]
  649. (dev, skb, t3c_tid->ctx);
  650. } else {
  651. printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
  652. dev->name, CPL_PASS_ACCEPT_REQ);
  653. return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
  654. }
  655. }
  656. static int do_set_tcb_rpl(struct t3cdev *dev, struct sk_buff *skb)
  657. {
  658. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  659. if (rpl->status != CPL_ERR_NONE)
  660. printk(KERN_ERR
  661. "Unexpected SET_TCB_RPL status %u for tid %u\n",
  662. rpl->status, GET_TID(rpl));
  663. return CPL_RET_BUF_DONE;
  664. }
  665. static int do_trace(struct t3cdev *dev, struct sk_buff *skb)
  666. {
  667. struct cpl_trace_pkt *p = cplhdr(skb);
  668. skb->protocol = htons(0xffff);
  669. skb->dev = dev->lldev;
  670. skb_pull(skb, sizeof(*p));
  671. skb->mac.raw = skb->data;
  672. netif_receive_skb(skb);
  673. return 0;
  674. }
  675. static int do_term(struct t3cdev *dev, struct sk_buff *skb)
  676. {
  677. unsigned int hwtid = ntohl(skb->priority) >> 8 & 0xfffff;
  678. unsigned int opcode = G_OPCODE(ntohl(skb->csum));
  679. struct t3c_tid_entry *t3c_tid;
  680. t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid);
  681. if (t3c_tid->ctx && t3c_tid->client->handlers &&
  682. t3c_tid->client->handlers[opcode]) {
  683. return t3c_tid->client->handlers[opcode] (dev, skb,
  684. t3c_tid->ctx);
  685. } else {
  686. printk(KERN_ERR "%s: received clientless CPL command 0x%x\n",
  687. dev->name, opcode);
  688. return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
  689. }
  690. }
  691. static int nb_callback(struct notifier_block *self, unsigned long event,
  692. void *ctx)
  693. {
  694. switch (event) {
  695. case (NETEVENT_NEIGH_UPDATE):{
  696. cxgb_neigh_update((struct neighbour *)ctx);
  697. break;
  698. }
  699. case (NETEVENT_PMTU_UPDATE):
  700. break;
  701. case (NETEVENT_REDIRECT):{
  702. struct netevent_redirect *nr = ctx;
  703. cxgb_redirect(nr->old, nr->new);
  704. cxgb_neigh_update(nr->new->neighbour);
  705. break;
  706. }
  707. default:
  708. break;
  709. }
  710. return 0;
  711. }
  712. static struct notifier_block nb = {
  713. .notifier_call = nb_callback
  714. };
  715. /*
  716. * Process a received packet with an unknown/unexpected CPL opcode.
  717. */
  718. static int do_bad_cpl(struct t3cdev *dev, struct sk_buff *skb)
  719. {
  720. printk(KERN_ERR "%s: received bad CPL command 0x%x\n", dev->name,
  721. *skb->data);
  722. return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG;
  723. }
  724. /*
  725. * Handlers for each CPL opcode
  726. */
  727. static cpl_handler_func cpl_handlers[NUM_CPL_CMDS];
  728. /*
  729. * Add a new handler to the CPL dispatch table. A NULL handler may be supplied
  730. * to unregister an existing handler.
  731. */
  732. void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h)
  733. {
  734. if (opcode < NUM_CPL_CMDS)
  735. cpl_handlers[opcode] = h ? h : do_bad_cpl;
  736. else
  737. printk(KERN_ERR "T3C: handler registration for "
  738. "opcode %x failed\n", opcode);
  739. }
  740. EXPORT_SYMBOL(t3_register_cpl_handler);
  741. /*
  742. * T3CDEV's receive method.
  743. */
  744. int process_rx(struct t3cdev *dev, struct sk_buff **skbs, int n)
  745. {
  746. while (n--) {
  747. struct sk_buff *skb = *skbs++;
  748. unsigned int opcode = G_OPCODE(ntohl(skb->csum));
  749. int ret = cpl_handlers[opcode] (dev, skb);
  750. #if VALIDATE_TID
  751. if (ret & CPL_RET_UNKNOWN_TID) {
  752. union opcode_tid *p = cplhdr(skb);
  753. printk(KERN_ERR "%s: CPL message (opcode %u) had "
  754. "unknown TID %u\n", dev->name, opcode,
  755. G_TID(ntohl(p->opcode_tid)));
  756. }
  757. #endif
  758. if (ret & CPL_RET_BUF_DONE)
  759. kfree_skb(skb);
  760. }
  761. return 0;
  762. }
  763. /*
  764. * Sends an sk_buff to a T3C driver after dealing with any active network taps.
  765. */
  766. int cxgb3_ofld_send(struct t3cdev *dev, struct sk_buff *skb)
  767. {
  768. int r;
  769. local_bh_disable();
  770. r = dev->send(dev, skb);
  771. local_bh_enable();
  772. return r;
  773. }
  774. EXPORT_SYMBOL(cxgb3_ofld_send);
  775. static int is_offloading(struct net_device *dev)
  776. {
  777. struct adapter *adapter;
  778. int i;
  779. read_lock_bh(&adapter_list_lock);
  780. list_for_each_entry(adapter, &adapter_list, adapter_list) {
  781. for_each_port(adapter, i) {
  782. if (dev == adapter->port[i]) {
  783. read_unlock_bh(&adapter_list_lock);
  784. return 1;
  785. }
  786. }
  787. }
  788. read_unlock_bh(&adapter_list_lock);
  789. return 0;
  790. }
  791. void cxgb_neigh_update(struct neighbour *neigh)
  792. {
  793. struct net_device *dev = neigh->dev;
  794. if (dev && (is_offloading(dev))) {
  795. struct t3cdev *tdev = T3CDEV(dev);
  796. BUG_ON(!tdev);
  797. t3_l2t_update(tdev, neigh);
  798. }
  799. }
  800. static void set_l2t_ix(struct t3cdev *tdev, u32 tid, struct l2t_entry *e)
  801. {
  802. struct sk_buff *skb;
  803. struct cpl_set_tcb_field *req;
  804. skb = alloc_skb(sizeof(*req), GFP_ATOMIC);
  805. if (!skb) {
  806. printk(KERN_ERR "%s: cannot allocate skb!\n", __FUNCTION__);
  807. return;
  808. }
  809. skb->priority = CPL_PRIORITY_CONTROL;
  810. req = (struct cpl_set_tcb_field *)skb_put(skb, sizeof(*req));
  811. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  812. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
  813. req->reply = 0;
  814. req->cpu_idx = 0;
  815. req->word = htons(W_TCB_L2T_IX);
  816. req->mask = cpu_to_be64(V_TCB_L2T_IX(M_TCB_L2T_IX));
  817. req->val = cpu_to_be64(V_TCB_L2T_IX(e->idx));
  818. tdev->send(tdev, skb);
  819. }
  820. void cxgb_redirect(struct dst_entry *old, struct dst_entry *new)
  821. {
  822. struct net_device *olddev, *newdev;
  823. struct tid_info *ti;
  824. struct t3cdev *tdev;
  825. u32 tid;
  826. int update_tcb;
  827. struct l2t_entry *e;
  828. struct t3c_tid_entry *te;
  829. olddev = old->neighbour->dev;
  830. newdev = new->neighbour->dev;
  831. if (!is_offloading(olddev))
  832. return;
  833. if (!is_offloading(newdev)) {
  834. printk(KERN_WARNING "%s: Redirect to non-offload"
  835. "device ignored.\n", __FUNCTION__);
  836. return;
  837. }
  838. tdev = T3CDEV(olddev);
  839. BUG_ON(!tdev);
  840. if (tdev != T3CDEV(newdev)) {
  841. printk(KERN_WARNING "%s: Redirect to different "
  842. "offload device ignored.\n", __FUNCTION__);
  843. return;
  844. }
  845. /* Add new L2T entry */
  846. e = t3_l2t_get(tdev, new->neighbour, newdev);
  847. if (!e) {
  848. printk(KERN_ERR "%s: couldn't allocate new l2t entry!\n",
  849. __FUNCTION__);
  850. return;
  851. }
  852. /* Walk tid table and notify clients of dst change. */
  853. ti = &(T3C_DATA(tdev))->tid_maps;
  854. for (tid = 0; tid < ti->ntids; tid++) {
  855. te = lookup_tid(ti, tid);
  856. BUG_ON(!te);
  857. if (te->ctx && te->client && te->client->redirect) {
  858. update_tcb = te->client->redirect(te->ctx, old, new, e);
  859. if (update_tcb) {
  860. l2t_hold(L2DATA(tdev), e);
  861. set_l2t_ix(tdev, tid, e);
  862. }
  863. }
  864. }
  865. l2t_release(L2DATA(tdev), e);
  866. }
  867. /*
  868. * Allocate a chunk of memory using kmalloc or, if that fails, vmalloc.
  869. * The allocated memory is cleared.
  870. */
  871. void *cxgb_alloc_mem(unsigned long size)
  872. {
  873. void *p = kmalloc(size, GFP_KERNEL);
  874. if (!p)
  875. p = vmalloc(size);
  876. if (p)
  877. memset(p, 0, size);
  878. return p;
  879. }
  880. /*
  881. * Free memory allocated through t3_alloc_mem().
  882. */
  883. void cxgb_free_mem(void *addr)
  884. {
  885. unsigned long p = (unsigned long)addr;
  886. if (p >= VMALLOC_START && p < VMALLOC_END)
  887. vfree(addr);
  888. else
  889. kfree(addr);
  890. }
  891. /*
  892. * Allocate and initialize the TID tables. Returns 0 on success.
  893. */
  894. static int init_tid_tabs(struct tid_info *t, unsigned int ntids,
  895. unsigned int natids, unsigned int nstids,
  896. unsigned int atid_base, unsigned int stid_base)
  897. {
  898. unsigned long size = ntids * sizeof(*t->tid_tab) +
  899. natids * sizeof(*t->atid_tab) + nstids * sizeof(*t->stid_tab);
  900. t->tid_tab = cxgb_alloc_mem(size);
  901. if (!t->tid_tab)
  902. return -ENOMEM;
  903. t->stid_tab = (union listen_entry *)&t->tid_tab[ntids];
  904. t->atid_tab = (union active_open_entry *)&t->stid_tab[nstids];
  905. t->ntids = ntids;
  906. t->nstids = nstids;
  907. t->stid_base = stid_base;
  908. t->sfree = NULL;
  909. t->natids = natids;
  910. t->atid_base = atid_base;
  911. t->afree = NULL;
  912. t->stids_in_use = t->atids_in_use = 0;
  913. atomic_set(&t->tids_in_use, 0);
  914. spin_lock_init(&t->stid_lock);
  915. spin_lock_init(&t->atid_lock);
  916. /*
  917. * Setup the free lists for stid_tab and atid_tab.
  918. */
  919. if (nstids) {
  920. while (--nstids)
  921. t->stid_tab[nstids - 1].next = &t->stid_tab[nstids];
  922. t->sfree = t->stid_tab;
  923. }
  924. if (natids) {
  925. while (--natids)
  926. t->atid_tab[natids - 1].next = &t->atid_tab[natids];
  927. t->afree = t->atid_tab;
  928. }
  929. return 0;
  930. }
  931. static void free_tid_maps(struct tid_info *t)
  932. {
  933. cxgb_free_mem(t->tid_tab);
  934. }
  935. static inline void add_adapter(struct adapter *adap)
  936. {
  937. write_lock_bh(&adapter_list_lock);
  938. list_add_tail(&adap->adapter_list, &adapter_list);
  939. write_unlock_bh(&adapter_list_lock);
  940. }
  941. static inline void remove_adapter(struct adapter *adap)
  942. {
  943. write_lock_bh(&adapter_list_lock);
  944. list_del(&adap->adapter_list);
  945. write_unlock_bh(&adapter_list_lock);
  946. }
  947. int cxgb3_offload_activate(struct adapter *adapter)
  948. {
  949. struct t3cdev *dev = &adapter->tdev;
  950. int natids, err;
  951. struct t3c_data *t;
  952. struct tid_range stid_range, tid_range;
  953. struct mtutab mtutab;
  954. unsigned int l2t_capacity;
  955. t = kcalloc(1, sizeof(*t), GFP_KERNEL);
  956. if (!t)
  957. return -ENOMEM;
  958. err = -EOPNOTSUPP;
  959. if (dev->ctl(dev, GET_TX_MAX_CHUNK, &t->tx_max_chunk) < 0 ||
  960. dev->ctl(dev, GET_MAX_OUTSTANDING_WR, &t->max_wrs) < 0 ||
  961. dev->ctl(dev, GET_L2T_CAPACITY, &l2t_capacity) < 0 ||
  962. dev->ctl(dev, GET_MTUS, &mtutab) < 0 ||
  963. dev->ctl(dev, GET_TID_RANGE, &tid_range) < 0 ||
  964. dev->ctl(dev, GET_STID_RANGE, &stid_range) < 0)
  965. goto out_free;
  966. err = -ENOMEM;
  967. L2DATA(dev) = t3_init_l2t(l2t_capacity);
  968. if (!L2DATA(dev))
  969. goto out_free;
  970. natids = min(tid_range.num / 2, MAX_ATIDS);
  971. err = init_tid_tabs(&t->tid_maps, tid_range.num, natids,
  972. stid_range.num, ATID_BASE, stid_range.base);
  973. if (err)
  974. goto out_free_l2t;
  975. t->mtus = mtutab.mtus;
  976. t->nmtus = mtutab.size;
  977. INIT_WORK(&t->tid_release_task, t3_process_tid_release_list);
  978. spin_lock_init(&t->tid_release_lock);
  979. INIT_LIST_HEAD(&t->list_node);
  980. t->dev = dev;
  981. T3C_DATA(dev) = t;
  982. dev->recv = process_rx;
  983. dev->neigh_update = t3_l2t_update;
  984. /* Register netevent handler once */
  985. if (list_empty(&adapter_list))
  986. register_netevent_notifier(&nb);
  987. add_adapter(adapter);
  988. return 0;
  989. out_free_l2t:
  990. t3_free_l2t(L2DATA(dev));
  991. L2DATA(dev) = NULL;
  992. out_free:
  993. kfree(t);
  994. return err;
  995. }
  996. void cxgb3_offload_deactivate(struct adapter *adapter)
  997. {
  998. struct t3cdev *tdev = &adapter->tdev;
  999. struct t3c_data *t = T3C_DATA(tdev);
  1000. remove_adapter(adapter);
  1001. if (list_empty(&adapter_list))
  1002. unregister_netevent_notifier(&nb);
  1003. free_tid_maps(&t->tid_maps);
  1004. T3C_DATA(tdev) = NULL;
  1005. t3_free_l2t(L2DATA(tdev));
  1006. L2DATA(tdev) = NULL;
  1007. kfree(t);
  1008. }
  1009. static inline void register_tdev(struct t3cdev *tdev)
  1010. {
  1011. static int unit;
  1012. mutex_lock(&cxgb3_db_lock);
  1013. snprintf(tdev->name, sizeof(tdev->name), "ofld_dev%d", unit++);
  1014. list_add_tail(&tdev->ofld_dev_list, &ofld_dev_list);
  1015. mutex_unlock(&cxgb3_db_lock);
  1016. }
  1017. static inline void unregister_tdev(struct t3cdev *tdev)
  1018. {
  1019. mutex_lock(&cxgb3_db_lock);
  1020. list_del(&tdev->ofld_dev_list);
  1021. mutex_unlock(&cxgb3_db_lock);
  1022. }
  1023. void __devinit cxgb3_adapter_ofld(struct adapter *adapter)
  1024. {
  1025. struct t3cdev *tdev = &adapter->tdev;
  1026. INIT_LIST_HEAD(&tdev->ofld_dev_list);
  1027. cxgb3_set_dummy_ops(tdev);
  1028. tdev->send = t3_offload_tx;
  1029. tdev->ctl = cxgb_offload_ctl;
  1030. tdev->type = adapter->params.rev == 0 ? T3A : T3B;
  1031. register_tdev(tdev);
  1032. }
  1033. void __devexit cxgb3_adapter_unofld(struct adapter *adapter)
  1034. {
  1035. struct t3cdev *tdev = &adapter->tdev;
  1036. tdev->recv = NULL;
  1037. tdev->neigh_update = NULL;
  1038. unregister_tdev(tdev);
  1039. }
  1040. void __init cxgb3_offload_init(void)
  1041. {
  1042. int i;
  1043. for (i = 0; i < NUM_CPL_CMDS; ++i)
  1044. cpl_handlers[i] = do_bad_cpl;
  1045. t3_register_cpl_handler(CPL_SMT_WRITE_RPL, do_smt_write_rpl);
  1046. t3_register_cpl_handler(CPL_L2T_WRITE_RPL, do_l2t_write_rpl);
  1047. t3_register_cpl_handler(CPL_PASS_OPEN_RPL, do_stid_rpl);
  1048. t3_register_cpl_handler(CPL_CLOSE_LISTSRV_RPL, do_stid_rpl);
  1049. t3_register_cpl_handler(CPL_PASS_ACCEPT_REQ, do_cr);
  1050. t3_register_cpl_handler(CPL_PASS_ESTABLISH, do_hwtid_rpl);
  1051. t3_register_cpl_handler(CPL_ABORT_RPL_RSS, do_hwtid_rpl);
  1052. t3_register_cpl_handler(CPL_ABORT_RPL, do_hwtid_rpl);
  1053. t3_register_cpl_handler(CPL_RX_URG_NOTIFY, do_hwtid_rpl);
  1054. t3_register_cpl_handler(CPL_RX_DATA, do_hwtid_rpl);
  1055. t3_register_cpl_handler(CPL_TX_DATA_ACK, do_hwtid_rpl);
  1056. t3_register_cpl_handler(CPL_TX_DMA_ACK, do_hwtid_rpl);
  1057. t3_register_cpl_handler(CPL_ACT_OPEN_RPL, do_act_open_rpl);
  1058. t3_register_cpl_handler(CPL_PEER_CLOSE, do_hwtid_rpl);
  1059. t3_register_cpl_handler(CPL_CLOSE_CON_RPL, do_hwtid_rpl);
  1060. t3_register_cpl_handler(CPL_ABORT_REQ_RSS, do_abort_req_rss);
  1061. t3_register_cpl_handler(CPL_ACT_ESTABLISH, do_act_establish);
  1062. t3_register_cpl_handler(CPL_SET_TCB_RPL, do_set_tcb_rpl);
  1063. t3_register_cpl_handler(CPL_RDMA_TERMINATE, do_term);
  1064. t3_register_cpl_handler(CPL_RDMA_EC_STATUS, do_hwtid_rpl);
  1065. t3_register_cpl_handler(CPL_TRACE_PKT, do_trace);
  1066. t3_register_cpl_handler(CPL_RX_DATA_DDP, do_hwtid_rpl);
  1067. t3_register_cpl_handler(CPL_RX_DDP_COMPLETE, do_hwtid_rpl);
  1068. t3_register_cpl_handler(CPL_ISCSI_HDR, do_hwtid_rpl);
  1069. }