bfad.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /**
  18. * bfad.c Linux driver PCI interface module.
  19. */
  20. #include <linux/slab.h>
  21. #include <linux/module.h>
  22. #include <linux/kthread.h>
  23. #include "bfad_drv.h"
  24. #include "bfad_im.h"
  25. #include "bfad_tm.h"
  26. #include "bfad_ipfc.h"
  27. #include "bfad_trcmod.h"
  28. #include <fcb/bfa_fcb_vf.h>
  29. #include <fcb/bfa_fcb_rport.h>
  30. #include <fcb/bfa_fcb_port.h>
  31. #include <fcb/bfa_fcb.h>
  32. BFA_TRC_FILE(LDRV, BFAD);
  33. static DEFINE_MUTEX(bfad_mutex);
  34. LIST_HEAD(bfad_list);
  35. static int bfad_inst;
  36. int bfad_supported_fc4s;
  37. static char *host_name;
  38. static char *os_name;
  39. static char *os_patch;
  40. static int num_rports;
  41. static int num_ios;
  42. static int num_tms;
  43. static int num_fcxps;
  44. static int num_ufbufs;
  45. static int reqq_size;
  46. static int rspq_size;
  47. static int num_sgpgs;
  48. static int rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT;
  49. static int bfa_io_max_sge = BFAD_IO_MAX_SGE;
  50. static int log_level = BFA_LOG_WARNING;
  51. static int ioc_auto_recover = BFA_TRUE;
  52. static int ipfc_enable = BFA_FALSE;
  53. static int ipfc_mtu = -1;
  54. static int fdmi_enable = BFA_TRUE;
  55. int bfa_lun_queue_depth = BFAD_LUN_QUEUE_DEPTH;
  56. int bfa_linkup_delay = -1;
  57. module_param(os_name, charp, S_IRUGO | S_IWUSR);
  58. module_param(os_patch, charp, S_IRUGO | S_IWUSR);
  59. module_param(host_name, charp, S_IRUGO | S_IWUSR);
  60. module_param(num_rports, int, S_IRUGO | S_IWUSR);
  61. module_param(num_ios, int, S_IRUGO | S_IWUSR);
  62. module_param(num_tms, int, S_IRUGO | S_IWUSR);
  63. module_param(num_fcxps, int, S_IRUGO | S_IWUSR);
  64. module_param(num_ufbufs, int, S_IRUGO | S_IWUSR);
  65. module_param(reqq_size, int, S_IRUGO | S_IWUSR);
  66. module_param(rspq_size, int, S_IRUGO | S_IWUSR);
  67. module_param(num_sgpgs, int, S_IRUGO | S_IWUSR);
  68. module_param(rport_del_timeout, int, S_IRUGO | S_IWUSR);
  69. module_param(bfa_lun_queue_depth, int, S_IRUGO | S_IWUSR);
  70. module_param(bfa_io_max_sge, int, S_IRUGO | S_IWUSR);
  71. module_param(log_level, int, S_IRUGO | S_IWUSR);
  72. module_param(ioc_auto_recover, int, S_IRUGO | S_IWUSR);
  73. module_param(ipfc_enable, int, S_IRUGO | S_IWUSR);
  74. module_param(ipfc_mtu, int, S_IRUGO | S_IWUSR);
  75. module_param(fdmi_enable, int, S_IRUGO | S_IWUSR);
  76. module_param(bfa_linkup_delay, int, S_IRUGO | S_IWUSR);
  77. /*
  78. * Stores the module parm num_sgpgs value;
  79. * used to reset for bfad next instance.
  80. */
  81. static int num_sgpgs_parm;
  82. static bfa_status_t
  83. bfad_fc4_probe(struct bfad_s *bfad)
  84. {
  85. int rc;
  86. rc = bfad_im_probe(bfad);
  87. if (rc != BFA_STATUS_OK)
  88. goto ext;
  89. bfad_tm_probe(bfad);
  90. if (ipfc_enable)
  91. bfad_ipfc_probe(bfad);
  92. bfad->bfad_flags |= BFAD_FC4_PROBE_DONE;
  93. ext:
  94. return rc;
  95. }
  96. static void
  97. bfad_fc4_probe_undo(struct bfad_s *bfad)
  98. {
  99. bfad_im_probe_undo(bfad);
  100. bfad_tm_probe_undo(bfad);
  101. if (ipfc_enable)
  102. bfad_ipfc_probe_undo(bfad);
  103. bfad->bfad_flags &= ~BFAD_FC4_PROBE_DONE;
  104. }
  105. static void
  106. bfad_fc4_probe_post(struct bfad_s *bfad)
  107. {
  108. if (bfad->im)
  109. bfad_im_probe_post(bfad->im);
  110. bfad_tm_probe_post(bfad);
  111. if (ipfc_enable)
  112. bfad_ipfc_probe_post(bfad);
  113. }
  114. static bfa_status_t
  115. bfad_fc4_port_new(struct bfad_s *bfad, struct bfad_port_s *port, int roles)
  116. {
  117. int rc = BFA_STATUS_FAILED;
  118. if (roles & BFA_PORT_ROLE_FCP_IM)
  119. rc = bfad_im_port_new(bfad, port);
  120. if (rc != BFA_STATUS_OK)
  121. goto ext;
  122. if (roles & BFA_PORT_ROLE_FCP_TM)
  123. rc = bfad_tm_port_new(bfad, port);
  124. if (rc != BFA_STATUS_OK)
  125. goto ext;
  126. if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
  127. rc = bfad_ipfc_port_new(bfad, port, port->pvb_type);
  128. ext:
  129. return rc;
  130. }
  131. static void
  132. bfad_fc4_port_delete(struct bfad_s *bfad, struct bfad_port_s *port, int roles)
  133. {
  134. if (roles & BFA_PORT_ROLE_FCP_IM)
  135. bfad_im_port_delete(bfad, port);
  136. if (roles & BFA_PORT_ROLE_FCP_TM)
  137. bfad_tm_port_delete(bfad, port);
  138. if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
  139. bfad_ipfc_port_delete(bfad, port);
  140. }
  141. /**
  142. * BFA callbacks
  143. */
  144. void
  145. bfad_hcb_comp(void *arg, bfa_status_t status)
  146. {
  147. struct bfad_hal_comp *fcomp = (struct bfad_hal_comp *)arg;
  148. fcomp->status = status;
  149. complete(&fcomp->comp);
  150. }
  151. /**
  152. * bfa_init callback
  153. */
  154. void
  155. bfa_cb_init(void *drv, bfa_status_t init_status)
  156. {
  157. struct bfad_s *bfad = drv;
  158. if (init_status == BFA_STATUS_OK) {
  159. bfad->bfad_flags |= BFAD_HAL_INIT_DONE;
  160. /* If BFAD_HAL_INIT_FAIL flag is set:
  161. * Wake up the kernel thread to start
  162. * the bfad operations after HAL init done
  163. */
  164. if ((bfad->bfad_flags & BFAD_HAL_INIT_FAIL)) {
  165. bfad->bfad_flags &= ~BFAD_HAL_INIT_FAIL;
  166. wake_up_process(bfad->bfad_tsk);
  167. }
  168. }
  169. complete(&bfad->comp);
  170. }
  171. /**
  172. * BFA_FCS callbacks
  173. */
  174. static struct bfad_port_s *
  175. bfad_get_drv_port(struct bfad_s *bfad, struct bfad_vf_s *vf_drv,
  176. struct bfad_vport_s *vp_drv)
  177. {
  178. return (vp_drv) ? (&(vp_drv)->drv_port)
  179. : ((vf_drv) ? (&(vf_drv)->base_port) : (&(bfad)->pport));
  180. }
  181. struct bfad_port_s *
  182. bfa_fcb_port_new(struct bfad_s *bfad, struct bfa_fcs_port_s *port,
  183. enum bfa_port_role roles, struct bfad_vf_s *vf_drv,
  184. struct bfad_vport_s *vp_drv)
  185. {
  186. bfa_status_t rc;
  187. struct bfad_port_s *port_drv;
  188. if (!vp_drv && !vf_drv) {
  189. port_drv = &bfad->pport;
  190. port_drv->pvb_type = BFAD_PORT_PHYS_BASE;
  191. } else if (!vp_drv && vf_drv) {
  192. port_drv = &vf_drv->base_port;
  193. port_drv->pvb_type = BFAD_PORT_VF_BASE;
  194. } else if (vp_drv && !vf_drv) {
  195. port_drv = &vp_drv->drv_port;
  196. port_drv->pvb_type = BFAD_PORT_PHYS_VPORT;
  197. } else {
  198. port_drv = &vp_drv->drv_port;
  199. port_drv->pvb_type = BFAD_PORT_VF_VPORT;
  200. }
  201. port_drv->fcs_port = port;
  202. port_drv->roles = roles;
  203. rc = bfad_fc4_port_new(bfad, port_drv, roles);
  204. if (rc != BFA_STATUS_OK) {
  205. bfad_fc4_port_delete(bfad, port_drv, roles);
  206. port_drv = NULL;
  207. }
  208. return port_drv;
  209. }
  210. void
  211. bfa_fcb_port_delete(struct bfad_s *bfad, enum bfa_port_role roles,
  212. struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
  213. {
  214. struct bfad_port_s *port_drv;
  215. /*
  216. * this will be only called from rmmod context
  217. */
  218. if (vp_drv && !vp_drv->comp_del) {
  219. port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
  220. bfa_trc(bfad, roles);
  221. bfad_fc4_port_delete(bfad, port_drv, roles);
  222. }
  223. }
  224. void
  225. bfa_fcb_port_online(struct bfad_s *bfad, enum bfa_port_role roles,
  226. struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
  227. {
  228. struct bfad_port_s *port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
  229. if (roles & BFA_PORT_ROLE_FCP_IM)
  230. bfad_im_port_online(bfad, port_drv);
  231. if (roles & BFA_PORT_ROLE_FCP_TM)
  232. bfad_tm_port_online(bfad, port_drv);
  233. if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
  234. bfad_ipfc_port_online(bfad, port_drv);
  235. bfad->bfad_flags |= BFAD_PORT_ONLINE;
  236. }
  237. void
  238. bfa_fcb_port_offline(struct bfad_s *bfad, enum bfa_port_role roles,
  239. struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
  240. {
  241. struct bfad_port_s *port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
  242. if (roles & BFA_PORT_ROLE_FCP_IM)
  243. bfad_im_port_offline(bfad, port_drv);
  244. if (roles & BFA_PORT_ROLE_FCP_TM)
  245. bfad_tm_port_offline(bfad, port_drv);
  246. if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
  247. bfad_ipfc_port_offline(bfad, port_drv);
  248. }
  249. void
  250. bfa_fcb_vport_delete(struct bfad_vport_s *vport_drv)
  251. {
  252. if (vport_drv->comp_del) {
  253. complete(vport_drv->comp_del);
  254. return;
  255. }
  256. }
  257. /**
  258. * FCS RPORT alloc callback, after successful PLOGI by FCS
  259. */
  260. bfa_status_t
  261. bfa_fcb_rport_alloc(struct bfad_s *bfad, struct bfa_fcs_rport_s **rport,
  262. struct bfad_rport_s **rport_drv)
  263. {
  264. bfa_status_t rc = BFA_STATUS_OK;
  265. *rport_drv = kzalloc(sizeof(struct bfad_rport_s), GFP_ATOMIC);
  266. if (*rport_drv == NULL) {
  267. rc = BFA_STATUS_ENOMEM;
  268. goto ext;
  269. }
  270. *rport = &(*rport_drv)->fcs_rport;
  271. ext:
  272. return rc;
  273. }
  274. void
  275. bfad_hal_mem_release(struct bfad_s *bfad)
  276. {
  277. int i;
  278. struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
  279. struct bfa_mem_elem_s *meminfo_elem;
  280. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  281. meminfo_elem = &hal_meminfo->meminfo[i];
  282. if (meminfo_elem->kva != NULL) {
  283. switch (meminfo_elem->mem_type) {
  284. case BFA_MEM_TYPE_KVA:
  285. vfree(meminfo_elem->kva);
  286. break;
  287. case BFA_MEM_TYPE_DMA:
  288. dma_free_coherent(&bfad->pcidev->dev,
  289. meminfo_elem->mem_len,
  290. meminfo_elem->kva,
  291. (dma_addr_t) meminfo_elem->dma);
  292. break;
  293. default:
  294. bfa_assert(0);
  295. break;
  296. }
  297. }
  298. }
  299. memset(hal_meminfo, 0, sizeof(struct bfa_meminfo_s));
  300. }
  301. void
  302. bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg)
  303. {
  304. if (num_rports > 0)
  305. bfa_cfg->fwcfg.num_rports = num_rports;
  306. if (num_ios > 0)
  307. bfa_cfg->fwcfg.num_ioim_reqs = num_ios;
  308. if (num_tms > 0)
  309. bfa_cfg->fwcfg.num_tskim_reqs = num_tms;
  310. if (num_fcxps > 0)
  311. bfa_cfg->fwcfg.num_fcxp_reqs = num_fcxps;
  312. if (num_ufbufs > 0)
  313. bfa_cfg->fwcfg.num_uf_bufs = num_ufbufs;
  314. if (reqq_size > 0)
  315. bfa_cfg->drvcfg.num_reqq_elems = reqq_size;
  316. if (rspq_size > 0)
  317. bfa_cfg->drvcfg.num_rspq_elems = rspq_size;
  318. if (num_sgpgs > 0)
  319. bfa_cfg->drvcfg.num_sgpgs = num_sgpgs;
  320. /*
  321. * populate the hal values back to the driver for sysfs use.
  322. * otherwise, the default values will be shown as 0 in sysfs
  323. */
  324. num_rports = bfa_cfg->fwcfg.num_rports;
  325. num_ios = bfa_cfg->fwcfg.num_ioim_reqs;
  326. num_tms = bfa_cfg->fwcfg.num_tskim_reqs;
  327. num_fcxps = bfa_cfg->fwcfg.num_fcxp_reqs;
  328. num_ufbufs = bfa_cfg->fwcfg.num_uf_bufs;
  329. reqq_size = bfa_cfg->drvcfg.num_reqq_elems;
  330. rspq_size = bfa_cfg->drvcfg.num_rspq_elems;
  331. num_sgpgs = bfa_cfg->drvcfg.num_sgpgs;
  332. }
  333. bfa_status_t
  334. bfad_hal_mem_alloc(struct bfad_s *bfad)
  335. {
  336. struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
  337. struct bfa_mem_elem_s *meminfo_elem;
  338. bfa_status_t rc = BFA_STATUS_OK;
  339. dma_addr_t phys_addr;
  340. int retry_count = 0;
  341. int reset_value = 1;
  342. int min_num_sgpgs = 512;
  343. void *kva;
  344. int i;
  345. bfa_cfg_get_default(&bfad->ioc_cfg);
  346. retry:
  347. bfad_update_hal_cfg(&bfad->ioc_cfg);
  348. bfad->cfg_data.ioc_queue_depth = bfad->ioc_cfg.fwcfg.num_ioim_reqs;
  349. bfa_cfg_get_meminfo(&bfad->ioc_cfg, hal_meminfo);
  350. for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
  351. meminfo_elem = &hal_meminfo->meminfo[i];
  352. switch (meminfo_elem->mem_type) {
  353. case BFA_MEM_TYPE_KVA:
  354. kva = vmalloc(meminfo_elem->mem_len);
  355. if (kva == NULL) {
  356. bfad_hal_mem_release(bfad);
  357. rc = BFA_STATUS_ENOMEM;
  358. goto ext;
  359. }
  360. memset(kva, 0, meminfo_elem->mem_len);
  361. meminfo_elem->kva = kva;
  362. break;
  363. case BFA_MEM_TYPE_DMA:
  364. kva = dma_alloc_coherent(&bfad->pcidev->dev,
  365. meminfo_elem->mem_len,
  366. &phys_addr, GFP_KERNEL);
  367. if (kva == NULL) {
  368. bfad_hal_mem_release(bfad);
  369. /*
  370. * If we cannot allocate with default
  371. * num_sgpages try with half the value.
  372. */
  373. if (num_sgpgs > min_num_sgpgs) {
  374. printk(KERN_INFO "bfad[%d]: memory"
  375. " allocation failed with"
  376. " num_sgpgs: %d\n",
  377. bfad->inst_no, num_sgpgs);
  378. nextLowerInt(&num_sgpgs);
  379. printk(KERN_INFO "bfad[%d]: trying to"
  380. " allocate memory with"
  381. " num_sgpgs: %d\n",
  382. bfad->inst_no, num_sgpgs);
  383. retry_count++;
  384. goto retry;
  385. } else {
  386. if (num_sgpgs_parm > 0)
  387. num_sgpgs = num_sgpgs_parm;
  388. else {
  389. reset_value =
  390. (1 << retry_count);
  391. num_sgpgs *= reset_value;
  392. }
  393. rc = BFA_STATUS_ENOMEM;
  394. goto ext;
  395. }
  396. }
  397. if (num_sgpgs_parm > 0)
  398. num_sgpgs = num_sgpgs_parm;
  399. else {
  400. reset_value = (1 << retry_count);
  401. num_sgpgs *= reset_value;
  402. }
  403. memset(kva, 0, meminfo_elem->mem_len);
  404. meminfo_elem->kva = kva;
  405. meminfo_elem->dma = phys_addr;
  406. break;
  407. default:
  408. break;
  409. }
  410. }
  411. ext:
  412. return rc;
  413. }
  414. /**
  415. * Create a vport under a vf.
  416. */
  417. bfa_status_t
  418. bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
  419. struct bfa_port_cfg_s *port_cfg, struct device *dev)
  420. {
  421. struct bfad_vport_s *vport;
  422. int rc = BFA_STATUS_OK;
  423. unsigned long flags;
  424. struct completion fcomp;
  425. vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
  426. if (!vport) {
  427. rc = BFA_STATUS_ENOMEM;
  428. goto ext;
  429. }
  430. vport->drv_port.bfad = bfad;
  431. spin_lock_irqsave(&bfad->bfad_lock, flags);
  432. rc = bfa_fcs_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, vf_id,
  433. port_cfg, vport);
  434. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  435. if (rc != BFA_STATUS_OK)
  436. goto ext_free_vport;
  437. if (port_cfg->roles & BFA_PORT_ROLE_FCP_IM) {
  438. rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port,
  439. dev);
  440. if (rc != BFA_STATUS_OK)
  441. goto ext_free_fcs_vport;
  442. }
  443. spin_lock_irqsave(&bfad->bfad_lock, flags);
  444. bfa_fcs_vport_start(&vport->fcs_vport);
  445. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  446. return BFA_STATUS_OK;
  447. ext_free_fcs_vport:
  448. spin_lock_irqsave(&bfad->bfad_lock, flags);
  449. vport->comp_del = &fcomp;
  450. init_completion(vport->comp_del);
  451. bfa_fcs_vport_delete(&vport->fcs_vport);
  452. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  453. wait_for_completion(vport->comp_del);
  454. ext_free_vport:
  455. kfree(vport);
  456. ext:
  457. return rc;
  458. }
  459. /**
  460. * Create a vf and its base vport implicitely.
  461. */
  462. bfa_status_t
  463. bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
  464. struct bfa_port_cfg_s *port_cfg)
  465. {
  466. struct bfad_vf_s *vf;
  467. int rc = BFA_STATUS_OK;
  468. vf = kzalloc(sizeof(struct bfad_vf_s), GFP_KERNEL);
  469. if (!vf) {
  470. rc = BFA_STATUS_FAILED;
  471. goto ext;
  472. }
  473. rc = bfa_fcs_vf_create(&vf->fcs_vf, &bfad->bfa_fcs, vf_id, port_cfg,
  474. vf);
  475. if (rc != BFA_STATUS_OK)
  476. kfree(vf);
  477. ext:
  478. return rc;
  479. }
  480. void
  481. bfad_bfa_tmo(unsigned long data)
  482. {
  483. struct bfad_s *bfad = (struct bfad_s *)data;
  484. unsigned long flags;
  485. struct list_head doneq;
  486. spin_lock_irqsave(&bfad->bfad_lock, flags);
  487. bfa_timer_tick(&bfad->bfa);
  488. bfa_comp_deq(&bfad->bfa, &doneq);
  489. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  490. if (!list_empty(&doneq)) {
  491. bfa_comp_process(&bfad->bfa, &doneq);
  492. spin_lock_irqsave(&bfad->bfad_lock, flags);
  493. bfa_comp_free(&bfad->bfa, &doneq);
  494. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  495. }
  496. mod_timer(&bfad->hal_tmo, jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
  497. }
  498. void
  499. bfad_init_timer(struct bfad_s *bfad)
  500. {
  501. init_timer(&bfad->hal_tmo);
  502. bfad->hal_tmo.function = bfad_bfa_tmo;
  503. bfad->hal_tmo.data = (unsigned long)bfad;
  504. mod_timer(&bfad->hal_tmo, jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
  505. }
  506. int
  507. bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
  508. {
  509. unsigned long bar0_len;
  510. int rc = -ENODEV;
  511. if (pci_enable_device(pdev)) {
  512. BFA_PRINTF(BFA_ERR, "pci_enable_device fail %p\n", pdev);
  513. goto out;
  514. }
  515. if (pci_request_regions(pdev, BFAD_DRIVER_NAME))
  516. goto out_disable_device;
  517. pci_set_master(pdev);
  518. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
  519. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
  520. BFA_PRINTF(BFA_ERR, "pci_set_dma_mask fail %p\n", pdev);
  521. goto out_release_region;
  522. }
  523. bfad->pci_bar0_map = pci_resource_start(pdev, 0);
  524. bar0_len = pci_resource_len(pdev, 0);
  525. bfad->pci_bar0_kva = ioremap(bfad->pci_bar0_map, bar0_len);
  526. if (bfad->pci_bar0_kva == NULL) {
  527. BFA_PRINTF(BFA_ERR, "Fail to map bar0\n");
  528. goto out_release_region;
  529. }
  530. bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn);
  531. bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn);
  532. bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva;
  533. bfad->hal_pcidev.device_id = pdev->device;
  534. bfad->pci_name = pci_name(pdev);
  535. bfad->pci_attr.vendor_id = pdev->vendor;
  536. bfad->pci_attr.device_id = pdev->device;
  537. bfad->pci_attr.ssid = pdev->subsystem_device;
  538. bfad->pci_attr.ssvid = pdev->subsystem_vendor;
  539. bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn);
  540. bfad->pcidev = pdev;
  541. return 0;
  542. out_release_region:
  543. pci_release_regions(pdev);
  544. out_disable_device:
  545. pci_disable_device(pdev);
  546. out:
  547. return rc;
  548. }
  549. void
  550. bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
  551. {
  552. #if defined(__ia64__)
  553. pci_iounmap(pdev, bfad->pci_bar0_kva);
  554. #else
  555. iounmap(bfad->pci_bar0_kva);
  556. #endif
  557. pci_release_regions(pdev);
  558. pci_disable_device(pdev);
  559. pci_set_drvdata(pdev, NULL);
  560. }
  561. void
  562. bfad_fcs_port_cfg(struct bfad_s *bfad)
  563. {
  564. struct bfa_port_cfg_s port_cfg;
  565. struct bfa_pport_attr_s attr;
  566. char symname[BFA_SYMNAME_MAXLEN];
  567. sprintf(symname, "%s-%d", BFAD_DRIVER_NAME, bfad->inst_no);
  568. memcpy(port_cfg.sym_name.symname, symname, strlen(symname));
  569. bfa_fcport_get_attr(&bfad->bfa, &attr);
  570. port_cfg.nwwn = attr.nwwn;
  571. port_cfg.pwwn = attr.pwwn;
  572. bfa_fcs_cfg_base_port(&bfad->bfa_fcs, &port_cfg);
  573. }
  574. bfa_status_t
  575. bfad_drv_init(struct bfad_s *bfad)
  576. {
  577. bfa_status_t rc;
  578. unsigned long flags;
  579. struct bfa_fcs_driver_info_s driver_info;
  580. bfad->cfg_data.rport_del_timeout = rport_del_timeout;
  581. bfad->cfg_data.lun_queue_depth = bfa_lun_queue_depth;
  582. bfad->cfg_data.io_max_sge = bfa_io_max_sge;
  583. bfad->cfg_data.binding_method = FCP_PWWN_BINDING;
  584. rc = bfad_hal_mem_alloc(bfad);
  585. if (rc != BFA_STATUS_OK) {
  586. printk(KERN_WARNING "bfad%d bfad_hal_mem_alloc failure\n",
  587. bfad->inst_no);
  588. printk(KERN_WARNING
  589. "Not enough memory to attach all Brocade HBA ports,"
  590. " System may need more memory.\n");
  591. goto out_hal_mem_alloc_failure;
  592. }
  593. bfa_init_log(&bfad->bfa, bfad->logmod);
  594. bfa_init_trc(&bfad->bfa, bfad->trcmod);
  595. bfa_init_aen(&bfad->bfa, bfad->aen);
  596. memset(bfad->file_map, 0, sizeof(bfad->file_map));
  597. bfa_init_plog(&bfad->bfa, &bfad->plog_buf);
  598. bfa_plog_init(&bfad->plog_buf);
  599. bfa_plog_str(&bfad->plog_buf, BFA_PL_MID_DRVR, BFA_PL_EID_DRIVER_START,
  600. 0, "Driver Attach");
  601. bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, &bfad->meminfo,
  602. &bfad->hal_pcidev);
  603. init_completion(&bfad->comp);
  604. /*
  605. * Enable Interrupt and wait bfa_init completion
  606. */
  607. if (bfad_setup_intr(bfad)) {
  608. printk(KERN_WARNING "bfad%d: bfad_setup_intr failed\n",
  609. bfad->inst_no);
  610. goto out_setup_intr_failure;
  611. }
  612. spin_lock_irqsave(&bfad->bfad_lock, flags);
  613. bfa_init(&bfad->bfa);
  614. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  615. /*
  616. * Set up interrupt handler for each vectors
  617. */
  618. if ((bfad->bfad_flags & BFAD_MSIX_ON)
  619. && bfad_install_msix_handler(bfad)) {
  620. printk(KERN_WARNING "%s: install_msix failed, bfad%d\n",
  621. __func__, bfad->inst_no);
  622. }
  623. bfad_init_timer(bfad);
  624. wait_for_completion(&bfad->comp);
  625. memset(&driver_info, 0, sizeof(driver_info));
  626. strncpy(driver_info.version, BFAD_DRIVER_VERSION,
  627. sizeof(driver_info.version) - 1);
  628. if (host_name)
  629. strncpy(driver_info.host_machine_name, host_name,
  630. sizeof(driver_info.host_machine_name) - 1);
  631. if (os_name)
  632. strncpy(driver_info.host_os_name, os_name,
  633. sizeof(driver_info.host_os_name) - 1);
  634. if (os_patch)
  635. strncpy(driver_info.host_os_patch, os_patch,
  636. sizeof(driver_info.host_os_patch) - 1);
  637. strncpy(driver_info.os_device_name, bfad->pci_name,
  638. sizeof(driver_info.os_device_name - 1));
  639. /*
  640. * FCS INIT
  641. */
  642. spin_lock_irqsave(&bfad->bfad_lock, flags);
  643. bfa_fcs_log_init(&bfad->bfa_fcs, bfad->logmod);
  644. bfa_fcs_trc_init(&bfad->bfa_fcs, bfad->trcmod);
  645. bfa_fcs_aen_init(&bfad->bfa_fcs, bfad->aen);
  646. bfa_fcs_attach(&bfad->bfa_fcs, &bfad->bfa, bfad, BFA_FALSE);
  647. /* Do FCS init only when HAL init is done */
  648. if ((bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  649. bfa_fcs_init(&bfad->bfa_fcs);
  650. bfad->bfad_flags |= BFAD_FCS_INIT_DONE;
  651. }
  652. bfa_fcs_driver_info_init(&bfad->bfa_fcs, &driver_info);
  653. bfa_fcs_set_fdmi_param(&bfad->bfa_fcs, fdmi_enable);
  654. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  655. bfad->bfad_flags |= BFAD_DRV_INIT_DONE;
  656. return BFA_STATUS_OK;
  657. out_setup_intr_failure:
  658. bfa_detach(&bfad->bfa);
  659. bfad_hal_mem_release(bfad);
  660. out_hal_mem_alloc_failure:
  661. return BFA_STATUS_FAILED;
  662. }
  663. void
  664. bfad_drv_uninit(struct bfad_s *bfad)
  665. {
  666. unsigned long flags;
  667. spin_lock_irqsave(&bfad->bfad_lock, flags);
  668. init_completion(&bfad->comp);
  669. bfa_stop(&bfad->bfa);
  670. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  671. wait_for_completion(&bfad->comp);
  672. del_timer_sync(&bfad->hal_tmo);
  673. bfa_isr_disable(&bfad->bfa);
  674. bfa_detach(&bfad->bfa);
  675. bfad_remove_intr(bfad);
  676. bfad_hal_mem_release(bfad);
  677. bfad->bfad_flags &= ~BFAD_DRV_INIT_DONE;
  678. }
  679. void
  680. bfad_drv_start(struct bfad_s *bfad)
  681. {
  682. unsigned long flags;
  683. spin_lock_irqsave(&bfad->bfad_lock, flags);
  684. bfa_start(&bfad->bfa);
  685. bfa_fcs_start(&bfad->bfa_fcs);
  686. bfad->bfad_flags |= BFAD_HAL_START_DONE;
  687. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  688. bfad_fc4_probe_post(bfad);
  689. }
  690. void
  691. bfad_drv_stop(struct bfad_s *bfad)
  692. {
  693. unsigned long flags;
  694. spin_lock_irqsave(&bfad->bfad_lock, flags);
  695. init_completion(&bfad->comp);
  696. bfad->pport.flags |= BFAD_PORT_DELETE;
  697. bfa_fcs_exit(&bfad->bfa_fcs);
  698. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  699. wait_for_completion(&bfad->comp);
  700. spin_lock_irqsave(&bfad->bfad_lock, flags);
  701. init_completion(&bfad->comp);
  702. bfa_stop(&bfad->bfa);
  703. bfad->bfad_flags &= ~BFAD_HAL_START_DONE;
  704. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  705. wait_for_completion(&bfad->comp);
  706. }
  707. bfa_status_t
  708. bfad_cfg_pport(struct bfad_s *bfad, enum bfa_port_role role)
  709. {
  710. int rc = BFA_STATUS_OK;
  711. /*
  712. * Allocate scsi_host for the physical port
  713. */
  714. if ((bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IM)
  715. && (role & BFA_PORT_ROLE_FCP_IM)) {
  716. if (bfad->pport.im_port == NULL) {
  717. rc = BFA_STATUS_FAILED;
  718. goto out;
  719. }
  720. rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port,
  721. &bfad->pcidev->dev);
  722. if (rc != BFA_STATUS_OK)
  723. goto out;
  724. bfad->pport.roles |= BFA_PORT_ROLE_FCP_IM;
  725. }
  726. bfad->bfad_flags |= BFAD_CFG_PPORT_DONE;
  727. out:
  728. return rc;
  729. }
  730. void
  731. bfad_uncfg_pport(struct bfad_s *bfad)
  732. {
  733. if ((bfad->pport.roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) {
  734. bfad_ipfc_port_delete(bfad, &bfad->pport);
  735. bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IPFC;
  736. }
  737. if ((bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IM)
  738. && (bfad->pport.roles & BFA_PORT_ROLE_FCP_IM)) {
  739. bfad_im_scsi_host_free(bfad, bfad->pport.im_port);
  740. bfad_im_port_clean(bfad->pport.im_port);
  741. kfree(bfad->pport.im_port);
  742. bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IM;
  743. }
  744. bfad->bfad_flags &= ~BFAD_CFG_PPORT_DONE;
  745. }
  746. void
  747. bfad_drv_log_level_set(struct bfad_s *bfad)
  748. {
  749. if (log_level > BFA_LOG_INVALID && log_level <= BFA_LOG_LEVEL_MAX)
  750. bfa_log_set_level_all(&bfad->log_data, log_level);
  751. }
  752. bfa_status_t
  753. bfad_start_ops(struct bfad_s *bfad)
  754. {
  755. int retval;
  756. /* PPORT FCS config */
  757. bfad_fcs_port_cfg(bfad);
  758. retval = bfad_cfg_pport(bfad, BFA_PORT_ROLE_FCP_IM);
  759. if (retval != BFA_STATUS_OK)
  760. goto out_cfg_pport_failure;
  761. /* BFAD level FC4 (IM/TM/IPFC) specific resource allocation */
  762. retval = bfad_fc4_probe(bfad);
  763. if (retval != BFA_STATUS_OK) {
  764. printk(KERN_WARNING "bfad_fc4_probe failed\n");
  765. goto out_fc4_probe_failure;
  766. }
  767. bfad_drv_start(bfad);
  768. /*
  769. * If bfa_linkup_delay is set to -1 default; try to retrive the
  770. * value using the bfad_os_get_linkup_delay(); else use the
  771. * passed in module param value as the bfa_linkup_delay.
  772. */
  773. if (bfa_linkup_delay < 0) {
  774. bfa_linkup_delay = bfad_os_get_linkup_delay(bfad);
  775. bfad_os_rport_online_wait(bfad);
  776. bfa_linkup_delay = -1;
  777. } else {
  778. bfad_os_rport_online_wait(bfad);
  779. }
  780. bfa_log(bfad->logmod, BFA_LOG_LINUX_DEVICE_CLAIMED, bfad->pci_name);
  781. return BFA_STATUS_OK;
  782. out_fc4_probe_failure:
  783. bfad_fc4_probe_undo(bfad);
  784. bfad_uncfg_pport(bfad);
  785. out_cfg_pport_failure:
  786. return BFA_STATUS_FAILED;
  787. }
  788. int
  789. bfad_worker (void *ptr)
  790. {
  791. struct bfad_s *bfad;
  792. unsigned long flags;
  793. bfad = (struct bfad_s *)ptr;
  794. while (!kthread_should_stop()) {
  795. /* Check if the FCS init is done from bfad_drv_init;
  796. * if not done do FCS init and set the flag.
  797. */
  798. if (!(bfad->bfad_flags & BFAD_FCS_INIT_DONE)) {
  799. spin_lock_irqsave(&bfad->bfad_lock, flags);
  800. bfa_fcs_init(&bfad->bfa_fcs);
  801. bfad->bfad_flags |= BFAD_FCS_INIT_DONE;
  802. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  803. }
  804. /* Start the bfad operations after HAL init done */
  805. bfad_start_ops(bfad);
  806. spin_lock_irqsave(&bfad->bfad_lock, flags);
  807. bfad->bfad_tsk = NULL;
  808. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  809. break;
  810. }
  811. return 0;
  812. }
  813. /*
  814. * PCI_entry PCI driver entries * {
  815. */
  816. /**
  817. * PCI probe entry.
  818. */
  819. int
  820. bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
  821. {
  822. struct bfad_s *bfad;
  823. int error = -ENODEV, retval;
  824. /*
  825. * For single port cards - only claim function 0
  826. */
  827. if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G1P)
  828. && (PCI_FUNC(pdev->devfn) != 0))
  829. return -ENODEV;
  830. BFA_TRACE(BFA_INFO, "bfad_pci_probe entry");
  831. bfad = kzalloc(sizeof(struct bfad_s), GFP_KERNEL);
  832. if (!bfad) {
  833. error = -ENOMEM;
  834. goto out;
  835. }
  836. bfad->trcmod = kzalloc(sizeof(struct bfa_trc_mod_s), GFP_KERNEL);
  837. if (!bfad->trcmod) {
  838. printk(KERN_WARNING "Error alloc trace buffer!\n");
  839. error = -ENOMEM;
  840. goto out_alloc_trace_failure;
  841. }
  842. /*
  843. * LOG/TRACE INIT
  844. */
  845. bfa_trc_init(bfad->trcmod);
  846. bfa_trc(bfad, bfad_inst);
  847. bfad->logmod = &bfad->log_data;
  848. bfa_log_init(bfad->logmod, (char *)pci_name(pdev), bfa_os_printf);
  849. bfad_drv_log_level_set(bfad);
  850. bfad->aen = &bfad->aen_buf;
  851. if (!(bfad_load_fwimg(pdev))) {
  852. printk(KERN_WARNING "bfad_load_fwimg failure!\n");
  853. kfree(bfad->trcmod);
  854. goto out_alloc_trace_failure;
  855. }
  856. retval = bfad_pci_init(pdev, bfad);
  857. if (retval) {
  858. printk(KERN_WARNING "bfad_pci_init failure!\n");
  859. error = retval;
  860. goto out_pci_init_failure;
  861. }
  862. mutex_lock(&bfad_mutex);
  863. bfad->inst_no = bfad_inst++;
  864. list_add_tail(&bfad->list_entry, &bfad_list);
  865. mutex_unlock(&bfad_mutex);
  866. spin_lock_init(&bfad->bfad_lock);
  867. pci_set_drvdata(pdev, bfad);
  868. bfad->ref_count = 0;
  869. bfad->pport.bfad = bfad;
  870. bfad->bfad_tsk = kthread_create(bfad_worker, (void *) bfad, "%s",
  871. "bfad_worker");
  872. if (IS_ERR(bfad->bfad_tsk)) {
  873. printk(KERN_INFO "bfad[%d]: Kernel thread"
  874. " creation failed!\n",
  875. bfad->inst_no);
  876. goto out_kthread_create_failure;
  877. }
  878. retval = bfad_drv_init(bfad);
  879. if (retval != BFA_STATUS_OK)
  880. goto out_drv_init_failure;
  881. if (!(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  882. bfad->bfad_flags |= BFAD_HAL_INIT_FAIL;
  883. printk(KERN_WARNING "bfad%d: hal init failed\n", bfad->inst_no);
  884. goto ok;
  885. }
  886. retval = bfad_start_ops(bfad);
  887. if (retval != BFA_STATUS_OK)
  888. goto out_start_ops_failure;
  889. kthread_stop(bfad->bfad_tsk);
  890. bfad->bfad_tsk = NULL;
  891. ok:
  892. return 0;
  893. out_start_ops_failure:
  894. bfad_drv_uninit(bfad);
  895. out_drv_init_failure:
  896. kthread_stop(bfad->bfad_tsk);
  897. out_kthread_create_failure:
  898. mutex_lock(&bfad_mutex);
  899. bfad_inst--;
  900. list_del(&bfad->list_entry);
  901. mutex_unlock(&bfad_mutex);
  902. bfad_pci_uninit(pdev, bfad);
  903. out_pci_init_failure:
  904. kfree(bfad->trcmod);
  905. out_alloc_trace_failure:
  906. kfree(bfad);
  907. out:
  908. return error;
  909. }
  910. /**
  911. * PCI remove entry.
  912. */
  913. void
  914. bfad_pci_remove(struct pci_dev *pdev)
  915. {
  916. struct bfad_s *bfad = pci_get_drvdata(pdev);
  917. unsigned long flags;
  918. bfa_trc(bfad, bfad->inst_no);
  919. spin_lock_irqsave(&bfad->bfad_lock, flags);
  920. if (bfad->bfad_tsk != NULL)
  921. kthread_stop(bfad->bfad_tsk);
  922. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  923. if ((bfad->bfad_flags & BFAD_DRV_INIT_DONE)
  924. && !(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
  925. spin_lock_irqsave(&bfad->bfad_lock, flags);
  926. init_completion(&bfad->comp);
  927. bfa_stop(&bfad->bfa);
  928. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  929. wait_for_completion(&bfad->comp);
  930. bfad_remove_intr(bfad);
  931. del_timer_sync(&bfad->hal_tmo);
  932. goto hal_detach;
  933. } else if (!(bfad->bfad_flags & BFAD_DRV_INIT_DONE)) {
  934. goto remove_sysfs;
  935. }
  936. if (bfad->bfad_flags & BFAD_HAL_START_DONE) {
  937. bfad_drv_stop(bfad);
  938. } else if (bfad->bfad_flags & BFAD_DRV_INIT_DONE) {
  939. /* Invoking bfa_stop() before bfa_detach
  940. * when HAL and DRV init are success
  941. * but HAL start did not occur.
  942. */
  943. spin_lock_irqsave(&bfad->bfad_lock, flags);
  944. init_completion(&bfad->comp);
  945. bfa_stop(&bfad->bfa);
  946. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  947. wait_for_completion(&bfad->comp);
  948. }
  949. bfad_remove_intr(bfad);
  950. del_timer_sync(&bfad->hal_tmo);
  951. if (bfad->bfad_flags & BFAD_FC4_PROBE_DONE)
  952. bfad_fc4_probe_undo(bfad);
  953. if (bfad->bfad_flags & BFAD_CFG_PPORT_DONE)
  954. bfad_uncfg_pport(bfad);
  955. hal_detach:
  956. spin_lock_irqsave(&bfad->bfad_lock, flags);
  957. bfa_detach(&bfad->bfa);
  958. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  959. bfad_hal_mem_release(bfad);
  960. remove_sysfs:
  961. mutex_lock(&bfad_mutex);
  962. bfad_inst--;
  963. list_del(&bfad->list_entry);
  964. mutex_unlock(&bfad_mutex);
  965. bfad_pci_uninit(pdev, bfad);
  966. kfree(bfad->trcmod);
  967. kfree(bfad);
  968. }
  969. static struct pci_device_id bfad_id_table[] = {
  970. {
  971. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  972. .device = BFA_PCI_DEVICE_ID_FC_8G2P,
  973. .subvendor = PCI_ANY_ID,
  974. .subdevice = PCI_ANY_ID,
  975. },
  976. {
  977. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  978. .device = BFA_PCI_DEVICE_ID_FC_8G1P,
  979. .subvendor = PCI_ANY_ID,
  980. .subdevice = PCI_ANY_ID,
  981. },
  982. {
  983. .vendor = BFA_PCI_VENDOR_ID_BROCADE,
  984. .device = BFA_PCI_DEVICE_ID_CT,
  985. .subvendor = PCI_ANY_ID,
  986. .subdevice = PCI_ANY_ID,
  987. .class = (PCI_CLASS_SERIAL_FIBER << 8),
  988. .class_mask = ~0,
  989. },
  990. {0, 0},
  991. };
  992. MODULE_DEVICE_TABLE(pci, bfad_id_table);
  993. static struct pci_driver bfad_pci_driver = {
  994. .name = BFAD_DRIVER_NAME,
  995. .id_table = bfad_id_table,
  996. .probe = bfad_pci_probe,
  997. .remove = __devexit_p(bfad_pci_remove),
  998. };
  999. /**
  1000. * Linux driver module functions
  1001. */
  1002. bfa_status_t
  1003. bfad_fc4_module_init(void)
  1004. {
  1005. int rc;
  1006. rc = bfad_im_module_init();
  1007. if (rc != BFA_STATUS_OK)
  1008. goto ext;
  1009. bfad_tm_module_init();
  1010. if (ipfc_enable)
  1011. bfad_ipfc_module_init();
  1012. ext:
  1013. return rc;
  1014. }
  1015. void
  1016. bfad_fc4_module_exit(void)
  1017. {
  1018. if (ipfc_enable)
  1019. bfad_ipfc_module_exit();
  1020. bfad_tm_module_exit();
  1021. bfad_im_module_exit();
  1022. }
  1023. /**
  1024. * Driver module init.
  1025. */
  1026. static int __init
  1027. bfad_init(void)
  1028. {
  1029. int error = 0;
  1030. printk(KERN_INFO "Brocade BFA FC/FCOE SCSI driver - version: %s\n",
  1031. BFAD_DRIVER_VERSION);
  1032. if (num_sgpgs > 0)
  1033. num_sgpgs_parm = num_sgpgs;
  1034. error = bfad_fc4_module_init();
  1035. if (error) {
  1036. error = -ENOMEM;
  1037. printk(KERN_WARNING "bfad_fc4_module_init failure\n");
  1038. goto ext;
  1039. }
  1040. if (!strcmp(FCPI_NAME, " fcpim"))
  1041. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_IM;
  1042. if (!strcmp(FCPT_NAME, " fcptm"))
  1043. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_TM;
  1044. if (!strcmp(IPFC_NAME, " ipfc"))
  1045. bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_IPFC;
  1046. bfa_ioc_auto_recover(ioc_auto_recover);
  1047. bfa_fcs_rport_set_del_timeout(rport_del_timeout);
  1048. error = pci_register_driver(&bfad_pci_driver);
  1049. if (error) {
  1050. printk(KERN_WARNING "bfad pci_register_driver failure\n");
  1051. goto ext;
  1052. }
  1053. return 0;
  1054. ext:
  1055. bfad_fc4_module_exit();
  1056. return error;
  1057. }
  1058. /**
  1059. * Driver module exit.
  1060. */
  1061. static void __exit
  1062. bfad_exit(void)
  1063. {
  1064. pci_unregister_driver(&bfad_pci_driver);
  1065. bfad_fc4_module_exit();
  1066. bfad_free_fwimg();
  1067. }
  1068. #define BFAD_PROTO_NAME FCPI_NAME FCPT_NAME IPFC_NAME
  1069. module_init(bfad_init);
  1070. module_exit(bfad_exit);
  1071. MODULE_LICENSE("GPL");
  1072. MODULE_DESCRIPTION("Brocade Fibre Channel HBA Driver" BFAD_PROTO_NAME);
  1073. MODULE_AUTHOR("Brocade Communications Systems, Inc.");
  1074. MODULE_VERSION(BFAD_DRIVER_VERSION);