cxgb3_offload.c 32 KB

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