bfad_attr.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. /*
  2. * Copyright (c) 2005-2010 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. * bfa_attr.c Linux driver configuration interface module.
  19. */
  20. #include "bfad_drv.h"
  21. #include "bfad_im.h"
  22. /*
  23. * FC transport template entry, get SCSI target port ID.
  24. */
  25. static void
  26. bfad_im_get_starget_port_id(struct scsi_target *starget)
  27. {
  28. struct Scsi_Host *shost;
  29. struct bfad_im_port_s *im_port;
  30. struct bfad_s *bfad;
  31. struct bfad_itnim_s *itnim = NULL;
  32. u32 fc_id = -1;
  33. unsigned long flags;
  34. shost = dev_to_shost(starget->dev.parent);
  35. im_port = (struct bfad_im_port_s *) shost->hostdata[0];
  36. bfad = im_port->bfad;
  37. spin_lock_irqsave(&bfad->bfad_lock, flags);
  38. itnim = bfad_get_itnim(im_port, starget->id);
  39. if (itnim)
  40. fc_id = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
  41. fc_starget_port_id(starget) = fc_id;
  42. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  43. }
  44. /*
  45. * FC transport template entry, get SCSI target nwwn.
  46. */
  47. static void
  48. bfad_im_get_starget_node_name(struct scsi_target *starget)
  49. {
  50. struct Scsi_Host *shost;
  51. struct bfad_im_port_s *im_port;
  52. struct bfad_s *bfad;
  53. struct bfad_itnim_s *itnim = NULL;
  54. u64 node_name = 0;
  55. unsigned long flags;
  56. shost = dev_to_shost(starget->dev.parent);
  57. im_port = (struct bfad_im_port_s *) shost->hostdata[0];
  58. bfad = im_port->bfad;
  59. spin_lock_irqsave(&bfad->bfad_lock, flags);
  60. itnim = bfad_get_itnim(im_port, starget->id);
  61. if (itnim)
  62. node_name = bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim);
  63. fc_starget_node_name(starget) = cpu_to_be64(node_name);
  64. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  65. }
  66. /*
  67. * FC transport template entry, get SCSI target pwwn.
  68. */
  69. static void
  70. bfad_im_get_starget_port_name(struct scsi_target *starget)
  71. {
  72. struct Scsi_Host *shost;
  73. struct bfad_im_port_s *im_port;
  74. struct bfad_s *bfad;
  75. struct bfad_itnim_s *itnim = NULL;
  76. u64 port_name = 0;
  77. unsigned long flags;
  78. shost = dev_to_shost(starget->dev.parent);
  79. im_port = (struct bfad_im_port_s *) shost->hostdata[0];
  80. bfad = im_port->bfad;
  81. spin_lock_irqsave(&bfad->bfad_lock, flags);
  82. itnim = bfad_get_itnim(im_port, starget->id);
  83. if (itnim)
  84. port_name = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
  85. fc_starget_port_name(starget) = cpu_to_be64(port_name);
  86. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  87. }
  88. /*
  89. * FC transport template entry, get SCSI host port ID.
  90. */
  91. static void
  92. bfad_im_get_host_port_id(struct Scsi_Host *shost)
  93. {
  94. struct bfad_im_port_s *im_port =
  95. (struct bfad_im_port_s *) shost->hostdata[0];
  96. struct bfad_port_s *port = im_port->port;
  97. fc_host_port_id(shost) =
  98. bfa_hton3b(bfa_fcs_lport_get_fcid(port->fcs_port));
  99. }
  100. /*
  101. * FC transport template entry, get SCSI host port type.
  102. */
  103. static void
  104. bfad_im_get_host_port_type(struct Scsi_Host *shost)
  105. {
  106. struct bfad_im_port_s *im_port =
  107. (struct bfad_im_port_s *) shost->hostdata[0];
  108. struct bfad_s *bfad = im_port->bfad;
  109. struct bfa_lport_attr_s port_attr;
  110. bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
  111. switch (port_attr.port_type) {
  112. case BFA_PORT_TYPE_NPORT:
  113. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  114. break;
  115. case BFA_PORT_TYPE_NLPORT:
  116. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  117. break;
  118. case BFA_PORT_TYPE_P2P:
  119. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  120. break;
  121. case BFA_PORT_TYPE_LPORT:
  122. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  123. break;
  124. default:
  125. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  126. break;
  127. }
  128. }
  129. /*
  130. * FC transport template entry, get SCSI host port state.
  131. */
  132. static void
  133. bfad_im_get_host_port_state(struct Scsi_Host *shost)
  134. {
  135. struct bfad_im_port_s *im_port =
  136. (struct bfad_im_port_s *) shost->hostdata[0];
  137. struct bfad_s *bfad = im_port->bfad;
  138. struct bfa_port_attr_s attr;
  139. bfa_fcport_get_attr(&bfad->bfa, &attr);
  140. switch (attr.port_state) {
  141. case BFA_PORT_ST_LINKDOWN:
  142. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  143. break;
  144. case BFA_PORT_ST_LINKUP:
  145. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  146. break;
  147. case BFA_PORT_ST_DISABLED:
  148. case BFA_PORT_ST_STOPPED:
  149. case BFA_PORT_ST_IOCDOWN:
  150. case BFA_PORT_ST_IOCDIS:
  151. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  152. break;
  153. case BFA_PORT_ST_UNINIT:
  154. case BFA_PORT_ST_ENABLING_QWAIT:
  155. case BFA_PORT_ST_ENABLING:
  156. case BFA_PORT_ST_DISABLING_QWAIT:
  157. case BFA_PORT_ST_DISABLING:
  158. default:
  159. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  160. break;
  161. }
  162. }
  163. /*
  164. * FC transport template entry, get SCSI host active fc4s.
  165. */
  166. static void
  167. bfad_im_get_host_active_fc4s(struct Scsi_Host *shost)
  168. {
  169. struct bfad_im_port_s *im_port =
  170. (struct bfad_im_port_s *) shost->hostdata[0];
  171. struct bfad_port_s *port = im_port->port;
  172. memset(fc_host_active_fc4s(shost), 0,
  173. sizeof(fc_host_active_fc4s(shost)));
  174. if (port->supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
  175. fc_host_active_fc4s(shost)[2] = 1;
  176. fc_host_active_fc4s(shost)[7] = 1;
  177. }
  178. /*
  179. * FC transport template entry, get SCSI host link speed.
  180. */
  181. static void
  182. bfad_im_get_host_speed(struct Scsi_Host *shost)
  183. {
  184. struct bfad_im_port_s *im_port =
  185. (struct bfad_im_port_s *) shost->hostdata[0];
  186. struct bfad_s *bfad = im_port->bfad;
  187. struct bfa_port_attr_s attr;
  188. bfa_fcport_get_attr(&bfad->bfa, &attr);
  189. switch (attr.speed) {
  190. case BFA_PORT_SPEED_10GBPS:
  191. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  192. break;
  193. case BFA_PORT_SPEED_16GBPS:
  194. fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
  195. break;
  196. case BFA_PORT_SPEED_8GBPS:
  197. fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
  198. break;
  199. case BFA_PORT_SPEED_4GBPS:
  200. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  201. break;
  202. case BFA_PORT_SPEED_2GBPS:
  203. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  204. break;
  205. case BFA_PORT_SPEED_1GBPS:
  206. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  207. break;
  208. default:
  209. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  210. break;
  211. }
  212. }
  213. /*
  214. * FC transport template entry, get SCSI host port type.
  215. */
  216. static void
  217. bfad_im_get_host_fabric_name(struct Scsi_Host *shost)
  218. {
  219. struct bfad_im_port_s *im_port =
  220. (struct bfad_im_port_s *) shost->hostdata[0];
  221. struct bfad_port_s *port = im_port->port;
  222. wwn_t fabric_nwwn = 0;
  223. fabric_nwwn = bfa_fcs_lport_get_fabric_name(port->fcs_port);
  224. fc_host_fabric_name(shost) = cpu_to_be64(fabric_nwwn);
  225. }
  226. /*
  227. * FC transport template entry, get BFAD statistics.
  228. */
  229. static struct fc_host_statistics *
  230. bfad_im_get_stats(struct Scsi_Host *shost)
  231. {
  232. struct bfad_im_port_s *im_port =
  233. (struct bfad_im_port_s *) shost->hostdata[0];
  234. struct bfad_s *bfad = im_port->bfad;
  235. struct bfad_hal_comp fcomp;
  236. union bfa_port_stats_u *fcstats;
  237. struct fc_host_statistics *hstats;
  238. bfa_status_t rc;
  239. unsigned long flags;
  240. fcstats = kzalloc(sizeof(union bfa_port_stats_u), GFP_KERNEL);
  241. if (fcstats == NULL)
  242. return NULL;
  243. hstats = &bfad->link_stats;
  244. init_completion(&fcomp.comp);
  245. spin_lock_irqsave(&bfad->bfad_lock, flags);
  246. memset(hstats, 0, sizeof(struct fc_host_statistics));
  247. rc = bfa_port_get_stats(BFA_FCPORT(&bfad->bfa),
  248. fcstats, bfad_hcb_comp, &fcomp);
  249. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  250. if (rc != BFA_STATUS_OK)
  251. return NULL;
  252. wait_for_completion(&fcomp.comp);
  253. /* Fill the fc_host_statistics structure */
  254. hstats->seconds_since_last_reset = fcstats->fc.secs_reset;
  255. hstats->tx_frames = fcstats->fc.tx_frames;
  256. hstats->tx_words = fcstats->fc.tx_words;
  257. hstats->rx_frames = fcstats->fc.rx_frames;
  258. hstats->rx_words = fcstats->fc.rx_words;
  259. hstats->lip_count = fcstats->fc.lip_count;
  260. hstats->nos_count = fcstats->fc.nos_count;
  261. hstats->error_frames = fcstats->fc.error_frames;
  262. hstats->dumped_frames = fcstats->fc.dropped_frames;
  263. hstats->link_failure_count = fcstats->fc.link_failures;
  264. hstats->loss_of_sync_count = fcstats->fc.loss_of_syncs;
  265. hstats->loss_of_signal_count = fcstats->fc.loss_of_signals;
  266. hstats->prim_seq_protocol_err_count = fcstats->fc.primseq_errs;
  267. hstats->invalid_crc_count = fcstats->fc.invalid_crcs;
  268. kfree(fcstats);
  269. return hstats;
  270. }
  271. /*
  272. * FC transport template entry, reset BFAD statistics.
  273. */
  274. static void
  275. bfad_im_reset_stats(struct Scsi_Host *shost)
  276. {
  277. struct bfad_im_port_s *im_port =
  278. (struct bfad_im_port_s *) shost->hostdata[0];
  279. struct bfad_s *bfad = im_port->bfad;
  280. struct bfad_hal_comp fcomp;
  281. unsigned long flags;
  282. bfa_status_t rc;
  283. init_completion(&fcomp.comp);
  284. spin_lock_irqsave(&bfad->bfad_lock, flags);
  285. rc = bfa_port_clear_stats(BFA_FCPORT(&bfad->bfa), bfad_hcb_comp,
  286. &fcomp);
  287. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  288. if (rc != BFA_STATUS_OK)
  289. return;
  290. wait_for_completion(&fcomp.comp);
  291. return;
  292. }
  293. /*
  294. * FC transport template entry, set rport loss timeout.
  295. * Update dev_loss_tmo based on the value pushed down by the stack
  296. * In case it is lesser than path_tov of driver, set it to path_tov + 1
  297. * to ensure that the driver times out before the application
  298. */
  299. static void
  300. bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
  301. {
  302. struct bfad_itnim_data_s *itnim_data = rport->dd_data;
  303. struct bfad_itnim_s *itnim = itnim_data->itnim;
  304. struct bfad_s *bfad = itnim->im->bfad;
  305. uint16_t path_tov = bfa_fcpim_path_tov_get(&bfad->bfa);
  306. rport->dev_loss_tmo = timeout;
  307. if (timeout < path_tov)
  308. rport->dev_loss_tmo = path_tov + 1;
  309. }
  310. static int
  311. bfad_im_vport_create(struct fc_vport *fc_vport, bool disable)
  312. {
  313. char *vname = fc_vport->symbolic_name;
  314. struct Scsi_Host *shost = fc_vport->shost;
  315. struct bfad_im_port_s *im_port =
  316. (struct bfad_im_port_s *) shost->hostdata[0];
  317. struct bfad_s *bfad = im_port->bfad;
  318. struct bfa_lport_cfg_s port_cfg;
  319. struct bfad_vport_s *vp;
  320. int status = 0, rc;
  321. unsigned long flags;
  322. memset(&port_cfg, 0, sizeof(port_cfg));
  323. u64_to_wwn(fc_vport->node_name, (u8 *)&port_cfg.nwwn);
  324. u64_to_wwn(fc_vport->port_name, (u8 *)&port_cfg.pwwn);
  325. if (strlen(vname) > 0)
  326. strcpy((char *)&port_cfg.sym_name, vname);
  327. port_cfg.roles = BFA_LPORT_ROLE_FCP_IM;
  328. spin_lock_irqsave(&bfad->bfad_lock, flags);
  329. list_for_each_entry(vp, &bfad->pbc_vport_list, list_entry) {
  330. if (port_cfg.pwwn ==
  331. vp->fcs_vport.lport.port_cfg.pwwn) {
  332. port_cfg.preboot_vp =
  333. vp->fcs_vport.lport.port_cfg.preboot_vp;
  334. break;
  335. }
  336. }
  337. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  338. rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev);
  339. if (rc == BFA_STATUS_OK) {
  340. struct bfad_vport_s *vport;
  341. struct bfa_fcs_vport_s *fcs_vport;
  342. struct Scsi_Host *vshost;
  343. spin_lock_irqsave(&bfad->bfad_lock, flags);
  344. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0,
  345. port_cfg.pwwn);
  346. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  347. if (fcs_vport == NULL)
  348. return VPCERR_BAD_WWN;
  349. fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
  350. if (disable) {
  351. spin_lock_irqsave(&bfad->bfad_lock, flags);
  352. bfa_fcs_vport_stop(fcs_vport);
  353. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  354. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  355. }
  356. vport = fcs_vport->vport_drv;
  357. vshost = vport->drv_port.im_port->shost;
  358. fc_host_node_name(vshost) = wwn_to_u64((u8 *)&port_cfg.nwwn);
  359. fc_host_port_name(vshost) = wwn_to_u64((u8 *)&port_cfg.pwwn);
  360. fc_host_supported_classes(vshost) = FC_COS_CLASS3;
  361. memset(fc_host_supported_fc4s(vshost), 0,
  362. sizeof(fc_host_supported_fc4s(vshost)));
  363. /* For FCP type 0x08 */
  364. if (supported_fc4s & BFA_LPORT_ROLE_FCP_IM)
  365. fc_host_supported_fc4s(vshost)[2] = 1;
  366. /* For fibre channel services type 0x20 */
  367. fc_host_supported_fc4s(vshost)[7] = 1;
  368. fc_host_supported_speeds(vshost) =
  369. bfad_im_supported_speeds(&bfad->bfa);
  370. fc_host_maxframe_size(vshost) =
  371. bfa_fcport_get_maxfrsize(&bfad->bfa);
  372. fc_vport->dd_data = vport;
  373. vport->drv_port.im_port->fc_vport = fc_vport;
  374. } else if (rc == BFA_STATUS_INVALID_WWN)
  375. return VPCERR_BAD_WWN;
  376. else if (rc == BFA_STATUS_VPORT_EXISTS)
  377. return VPCERR_BAD_WWN;
  378. else if (rc == BFA_STATUS_VPORT_MAX)
  379. return VPCERR_NO_FABRIC_SUPP;
  380. else if (rc == BFA_STATUS_VPORT_WWN_BP)
  381. return VPCERR_BAD_WWN;
  382. else
  383. return FC_VPORT_FAILED;
  384. return status;
  385. }
  386. int
  387. bfad_im_issue_fc_host_lip(struct Scsi_Host *shost)
  388. {
  389. struct bfad_im_port_s *im_port =
  390. (struct bfad_im_port_s *) shost->hostdata[0];
  391. struct bfad_s *bfad = im_port->bfad;
  392. struct bfad_hal_comp fcomp;
  393. unsigned long flags;
  394. uint32_t status;
  395. init_completion(&fcomp.comp);
  396. spin_lock_irqsave(&bfad->bfad_lock, flags);
  397. status = bfa_port_disable(&bfad->bfa.modules.port,
  398. bfad_hcb_comp, &fcomp);
  399. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  400. if (status != BFA_STATUS_OK)
  401. return -EIO;
  402. wait_for_completion(&fcomp.comp);
  403. if (fcomp.status != BFA_STATUS_OK)
  404. return -EIO;
  405. spin_lock_irqsave(&bfad->bfad_lock, flags);
  406. status = bfa_port_enable(&bfad->bfa.modules.port,
  407. bfad_hcb_comp, &fcomp);
  408. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  409. if (status != BFA_STATUS_OK)
  410. return -EIO;
  411. wait_for_completion(&fcomp.comp);
  412. if (fcomp.status != BFA_STATUS_OK)
  413. return -EIO;
  414. return 0;
  415. }
  416. static int
  417. bfad_im_vport_delete(struct fc_vport *fc_vport)
  418. {
  419. struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
  420. struct bfad_im_port_s *im_port =
  421. (struct bfad_im_port_s *) vport->drv_port.im_port;
  422. struct bfad_s *bfad = im_port->bfad;
  423. struct bfad_port_s *port;
  424. struct bfa_fcs_vport_s *fcs_vport;
  425. struct Scsi_Host *vshost;
  426. wwn_t pwwn;
  427. int rc;
  428. unsigned long flags;
  429. struct completion fcomp;
  430. if (im_port->flags & BFAD_PORT_DELETE) {
  431. bfad_scsi_host_free(bfad, im_port);
  432. list_del(&vport->list_entry);
  433. kfree(vport);
  434. return 0;
  435. }
  436. port = im_port->port;
  437. vshost = vport->drv_port.im_port->shost;
  438. u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
  439. spin_lock_irqsave(&bfad->bfad_lock, flags);
  440. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
  441. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  442. if (fcs_vport == NULL)
  443. return VPCERR_BAD_WWN;
  444. vport->drv_port.flags |= BFAD_PORT_DELETE;
  445. vport->comp_del = &fcomp;
  446. init_completion(vport->comp_del);
  447. spin_lock_irqsave(&bfad->bfad_lock, flags);
  448. rc = bfa_fcs_vport_delete(&vport->fcs_vport);
  449. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  450. if (rc == BFA_STATUS_PBC) {
  451. vport->drv_port.flags &= ~BFAD_PORT_DELETE;
  452. vport->comp_del = NULL;
  453. return -1;
  454. }
  455. wait_for_completion(vport->comp_del);
  456. bfad_scsi_host_free(bfad, im_port);
  457. list_del(&vport->list_entry);
  458. kfree(vport);
  459. return 0;
  460. }
  461. static int
  462. bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable)
  463. {
  464. struct bfad_vport_s *vport;
  465. struct bfad_s *bfad;
  466. struct bfa_fcs_vport_s *fcs_vport;
  467. struct Scsi_Host *vshost;
  468. wwn_t pwwn;
  469. unsigned long flags;
  470. vport = (struct bfad_vport_s *)fc_vport->dd_data;
  471. bfad = vport->drv_port.bfad;
  472. vshost = vport->drv_port.im_port->shost;
  473. u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
  474. spin_lock_irqsave(&bfad->bfad_lock, flags);
  475. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
  476. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  477. if (fcs_vport == NULL)
  478. return VPCERR_BAD_WWN;
  479. if (disable) {
  480. bfa_fcs_vport_stop(fcs_vport);
  481. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  482. } else {
  483. bfa_fcs_vport_start(fcs_vport);
  484. fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
  485. }
  486. return 0;
  487. }
  488. void
  489. bfad_im_vport_set_symbolic_name(struct fc_vport *fc_vport)
  490. {
  491. struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
  492. struct bfad_im_port_s *im_port =
  493. (struct bfad_im_port_s *)vport->drv_port.im_port;
  494. struct bfad_s *bfad = im_port->bfad;
  495. struct Scsi_Host *vshost = vport->drv_port.im_port->shost;
  496. char *sym_name = fc_vport->symbolic_name;
  497. struct bfa_fcs_vport_s *fcs_vport;
  498. wwn_t pwwn;
  499. unsigned long flags;
  500. u64_to_wwn(fc_host_port_name(vshost), (u8 *)&pwwn);
  501. spin_lock_irqsave(&bfad->bfad_lock, flags);
  502. fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
  503. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  504. if (fcs_vport == NULL)
  505. return;
  506. spin_lock_irqsave(&bfad->bfad_lock, flags);
  507. if (strlen(sym_name) > 0)
  508. bfa_fcs_lport_set_symname(&fcs_vport->lport, sym_name);
  509. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  510. }
  511. struct fc_function_template bfad_im_fc_function_template = {
  512. /* Target dynamic attributes */
  513. .get_starget_port_id = bfad_im_get_starget_port_id,
  514. .show_starget_port_id = 1,
  515. .get_starget_node_name = bfad_im_get_starget_node_name,
  516. .show_starget_node_name = 1,
  517. .get_starget_port_name = bfad_im_get_starget_port_name,
  518. .show_starget_port_name = 1,
  519. /* Host dynamic attribute */
  520. .get_host_port_id = bfad_im_get_host_port_id,
  521. .show_host_port_id = 1,
  522. /* Host fixed attributes */
  523. .show_host_node_name = 1,
  524. .show_host_port_name = 1,
  525. .show_host_supported_classes = 1,
  526. .show_host_supported_fc4s = 1,
  527. .show_host_supported_speeds = 1,
  528. .show_host_maxframe_size = 1,
  529. /* More host dynamic attributes */
  530. .show_host_port_type = 1,
  531. .get_host_port_type = bfad_im_get_host_port_type,
  532. .show_host_port_state = 1,
  533. .get_host_port_state = bfad_im_get_host_port_state,
  534. .show_host_active_fc4s = 1,
  535. .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
  536. .show_host_speed = 1,
  537. .get_host_speed = bfad_im_get_host_speed,
  538. .show_host_fabric_name = 1,
  539. .get_host_fabric_name = bfad_im_get_host_fabric_name,
  540. .show_host_symbolic_name = 1,
  541. /* Statistics */
  542. .get_fc_host_stats = bfad_im_get_stats,
  543. .reset_fc_host_stats = bfad_im_reset_stats,
  544. /* Allocation length for host specific data */
  545. .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
  546. /* Remote port fixed attributes */
  547. .show_rport_maxframe_size = 1,
  548. .show_rport_supported_classes = 1,
  549. .show_rport_dev_loss_tmo = 1,
  550. .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
  551. .issue_fc_host_lip = bfad_im_issue_fc_host_lip,
  552. .vport_create = bfad_im_vport_create,
  553. .vport_delete = bfad_im_vport_delete,
  554. .vport_disable = bfad_im_vport_disable,
  555. .set_vport_symbolic_name = bfad_im_vport_set_symbolic_name,
  556. .bsg_request = bfad_im_bsg_request,
  557. .bsg_timeout = bfad_im_bsg_timeout,
  558. };
  559. struct fc_function_template bfad_im_vport_fc_function_template = {
  560. /* Target dynamic attributes */
  561. .get_starget_port_id = bfad_im_get_starget_port_id,
  562. .show_starget_port_id = 1,
  563. .get_starget_node_name = bfad_im_get_starget_node_name,
  564. .show_starget_node_name = 1,
  565. .get_starget_port_name = bfad_im_get_starget_port_name,
  566. .show_starget_port_name = 1,
  567. /* Host dynamic attribute */
  568. .get_host_port_id = bfad_im_get_host_port_id,
  569. .show_host_port_id = 1,
  570. /* Host fixed attributes */
  571. .show_host_node_name = 1,
  572. .show_host_port_name = 1,
  573. .show_host_supported_classes = 1,
  574. .show_host_supported_fc4s = 1,
  575. .show_host_supported_speeds = 1,
  576. .show_host_maxframe_size = 1,
  577. /* More host dynamic attributes */
  578. .show_host_port_type = 1,
  579. .get_host_port_type = bfad_im_get_host_port_type,
  580. .show_host_port_state = 1,
  581. .get_host_port_state = bfad_im_get_host_port_state,
  582. .show_host_active_fc4s = 1,
  583. .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
  584. .show_host_speed = 1,
  585. .get_host_speed = bfad_im_get_host_speed,
  586. .show_host_fabric_name = 1,
  587. .get_host_fabric_name = bfad_im_get_host_fabric_name,
  588. .show_host_symbolic_name = 1,
  589. /* Statistics */
  590. .get_fc_host_stats = bfad_im_get_stats,
  591. .reset_fc_host_stats = bfad_im_reset_stats,
  592. /* Allocation length for host specific data */
  593. .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
  594. /* Remote port fixed attributes */
  595. .show_rport_maxframe_size = 1,
  596. .show_rport_supported_classes = 1,
  597. .show_rport_dev_loss_tmo = 1,
  598. .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
  599. };
  600. /*
  601. * Scsi_Host_attrs SCSI host attributes
  602. */
  603. static ssize_t
  604. bfad_im_serial_num_show(struct device *dev, struct device_attribute *attr,
  605. char *buf)
  606. {
  607. struct Scsi_Host *shost = class_to_shost(dev);
  608. struct bfad_im_port_s *im_port =
  609. (struct bfad_im_port_s *) shost->hostdata[0];
  610. struct bfad_s *bfad = im_port->bfad;
  611. char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
  612. bfa_get_adapter_serial_num(&bfad->bfa, serial_num);
  613. return snprintf(buf, PAGE_SIZE, "%s\n", serial_num);
  614. }
  615. static ssize_t
  616. bfad_im_model_show(struct device *dev, struct device_attribute *attr,
  617. char *buf)
  618. {
  619. struct Scsi_Host *shost = class_to_shost(dev);
  620. struct bfad_im_port_s *im_port =
  621. (struct bfad_im_port_s *) shost->hostdata[0];
  622. struct bfad_s *bfad = im_port->bfad;
  623. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  624. bfa_get_adapter_model(&bfad->bfa, model);
  625. return snprintf(buf, PAGE_SIZE, "%s\n", model);
  626. }
  627. static ssize_t
  628. bfad_im_model_desc_show(struct device *dev, struct device_attribute *attr,
  629. char *buf)
  630. {
  631. struct Scsi_Host *shost = class_to_shost(dev);
  632. struct bfad_im_port_s *im_port =
  633. (struct bfad_im_port_s *) shost->hostdata[0];
  634. struct bfad_s *bfad = im_port->bfad;
  635. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  636. char model_descr[BFA_ADAPTER_MODEL_DESCR_LEN];
  637. int nports = 0;
  638. bfa_get_adapter_model(&bfad->bfa, model);
  639. nports = bfa_get_nports(&bfad->bfa);
  640. if (!strcmp(model, "Brocade-425"))
  641. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  642. "Brocade 4Gbps PCIe dual port FC HBA");
  643. else if (!strcmp(model, "Brocade-825"))
  644. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  645. "Brocade 8Gbps PCIe dual port FC HBA");
  646. else if (!strcmp(model, "Brocade-42B"))
  647. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  648. "Brocade 4Gbps PCIe dual port FC HBA for HP");
  649. else if (!strcmp(model, "Brocade-82B"))
  650. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  651. "Brocade 8Gbps PCIe dual port FC HBA for HP");
  652. else if (!strcmp(model, "Brocade-1010"))
  653. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  654. "Brocade 10Gbps single port CNA");
  655. else if (!strcmp(model, "Brocade-1020"))
  656. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  657. "Brocade 10Gbps dual port CNA");
  658. else if (!strcmp(model, "Brocade-1007"))
  659. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  660. "Brocade 10Gbps CNA for IBM Blade Center");
  661. else if (!strcmp(model, "Brocade-415"))
  662. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  663. "Brocade 4Gbps PCIe single port FC HBA");
  664. else if (!strcmp(model, "Brocade-815"))
  665. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  666. "Brocade 8Gbps PCIe single port FC HBA");
  667. else if (!strcmp(model, "Brocade-41B"))
  668. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  669. "Brocade 4Gbps PCIe single port FC HBA for HP");
  670. else if (!strcmp(model, "Brocade-81B"))
  671. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  672. "Brocade 8Gbps PCIe single port FC HBA for HP");
  673. else if (!strcmp(model, "Brocade-804"))
  674. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  675. "Brocade 8Gbps FC HBA for HP Bladesystem C-class");
  676. else if (!strcmp(model, "Brocade-1741"))
  677. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  678. "Brocade 10Gbps CNA for Dell M-Series Blade Servers");
  679. else if (strstr(model, "Brocade-1860")) {
  680. if (nports == 1 && bfa_ioc_is_cna(&bfad->bfa.ioc))
  681. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  682. "Brocade 10Gbps single port CNA");
  683. else if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
  684. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  685. "Brocade 16Gbps PCIe single port FC HBA");
  686. else if (nports == 2 && bfa_ioc_is_cna(&bfad->bfa.ioc))
  687. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  688. "Brocade 10Gbps dual port CNA");
  689. else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
  690. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  691. "Brocade 16Gbps PCIe dual port FC HBA");
  692. } else if (!strcmp(model, "Brocade-1867")) {
  693. if (nports == 1 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
  694. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  695. "Brocade 16Gbps PCIe single port FC HBA for IBM");
  696. else if (nports == 2 && !bfa_ioc_is_cna(&bfad->bfa.ioc))
  697. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  698. "Brocade 16Gbps PCIe dual port FC HBA for IBM");
  699. } else
  700. snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
  701. "Invalid Model");
  702. return snprintf(buf, PAGE_SIZE, "%s\n", model_descr);
  703. }
  704. static ssize_t
  705. bfad_im_node_name_show(struct device *dev, struct device_attribute *attr,
  706. char *buf)
  707. {
  708. struct Scsi_Host *shost = class_to_shost(dev);
  709. struct bfad_im_port_s *im_port =
  710. (struct bfad_im_port_s *) shost->hostdata[0];
  711. struct bfad_port_s *port = im_port->port;
  712. u64 nwwn;
  713. nwwn = bfa_fcs_lport_get_nwwn(port->fcs_port);
  714. return snprintf(buf, PAGE_SIZE, "0x%llx\n", cpu_to_be64(nwwn));
  715. }
  716. static ssize_t
  717. bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr,
  718. char *buf)
  719. {
  720. struct Scsi_Host *shost = class_to_shost(dev);
  721. struct bfad_im_port_s *im_port =
  722. (struct bfad_im_port_s *) shost->hostdata[0];
  723. struct bfad_s *bfad = im_port->bfad;
  724. struct bfa_lport_attr_s port_attr;
  725. char symname[BFA_SYMNAME_MAXLEN];
  726. bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
  727. strlcpy(symname, port_attr.port_cfg.sym_name.symname,
  728. BFA_SYMNAME_MAXLEN);
  729. return snprintf(buf, PAGE_SIZE, "%s\n", symname);
  730. }
  731. static ssize_t
  732. bfad_im_hw_version_show(struct device *dev, struct device_attribute *attr,
  733. char *buf)
  734. {
  735. struct Scsi_Host *shost = class_to_shost(dev);
  736. struct bfad_im_port_s *im_port =
  737. (struct bfad_im_port_s *) shost->hostdata[0];
  738. struct bfad_s *bfad = im_port->bfad;
  739. char hw_ver[BFA_VERSION_LEN];
  740. bfa_get_pci_chip_rev(&bfad->bfa, hw_ver);
  741. return snprintf(buf, PAGE_SIZE, "%s\n", hw_ver);
  742. }
  743. static ssize_t
  744. bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
  745. char *buf)
  746. {
  747. return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION);
  748. }
  749. static ssize_t
  750. bfad_im_optionrom_version_show(struct device *dev,
  751. struct device_attribute *attr, char *buf)
  752. {
  753. struct Scsi_Host *shost = class_to_shost(dev);
  754. struct bfad_im_port_s *im_port =
  755. (struct bfad_im_port_s *) shost->hostdata[0];
  756. struct bfad_s *bfad = im_port->bfad;
  757. char optrom_ver[BFA_VERSION_LEN];
  758. bfa_get_adapter_optrom_ver(&bfad->bfa, optrom_ver);
  759. return snprintf(buf, PAGE_SIZE, "%s\n", optrom_ver);
  760. }
  761. static ssize_t
  762. bfad_im_fw_version_show(struct device *dev, struct device_attribute *attr,
  763. char *buf)
  764. {
  765. struct Scsi_Host *shost = class_to_shost(dev);
  766. struct bfad_im_port_s *im_port =
  767. (struct bfad_im_port_s *) shost->hostdata[0];
  768. struct bfad_s *bfad = im_port->bfad;
  769. char fw_ver[BFA_VERSION_LEN];
  770. bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
  771. return snprintf(buf, PAGE_SIZE, "%s\n", fw_ver);
  772. }
  773. static ssize_t
  774. bfad_im_num_of_ports_show(struct device *dev, struct device_attribute *attr,
  775. char *buf)
  776. {
  777. struct Scsi_Host *shost = class_to_shost(dev);
  778. struct bfad_im_port_s *im_port =
  779. (struct bfad_im_port_s *) shost->hostdata[0];
  780. struct bfad_s *bfad = im_port->bfad;
  781. return snprintf(buf, PAGE_SIZE, "%d\n",
  782. bfa_get_nports(&bfad->bfa));
  783. }
  784. static ssize_t
  785. bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
  786. char *buf)
  787. {
  788. return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME);
  789. }
  790. static ssize_t
  791. bfad_im_num_of_discovered_ports_show(struct device *dev,
  792. struct device_attribute *attr, char *buf)
  793. {
  794. struct Scsi_Host *shost = class_to_shost(dev);
  795. struct bfad_im_port_s *im_port =
  796. (struct bfad_im_port_s *) shost->hostdata[0];
  797. struct bfad_port_s *port = im_port->port;
  798. struct bfad_s *bfad = im_port->bfad;
  799. int nrports = 2048;
  800. struct bfa_rport_qualifier_s *rports = NULL;
  801. unsigned long flags;
  802. rports = kzalloc(sizeof(struct bfa_rport_qualifier_s) * nrports,
  803. GFP_ATOMIC);
  804. if (rports == NULL)
  805. return snprintf(buf, PAGE_SIZE, "Failed\n");
  806. spin_lock_irqsave(&bfad->bfad_lock, flags);
  807. bfa_fcs_lport_get_rport_quals(port->fcs_port, rports, &nrports);
  808. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  809. kfree(rports);
  810. return snprintf(buf, PAGE_SIZE, "%d\n", nrports);
  811. }
  812. static DEVICE_ATTR(serial_number, S_IRUGO,
  813. bfad_im_serial_num_show, NULL);
  814. static DEVICE_ATTR(model, S_IRUGO, bfad_im_model_show, NULL);
  815. static DEVICE_ATTR(model_description, S_IRUGO,
  816. bfad_im_model_desc_show, NULL);
  817. static DEVICE_ATTR(node_name, S_IRUGO, bfad_im_node_name_show, NULL);
  818. static DEVICE_ATTR(symbolic_name, S_IRUGO,
  819. bfad_im_symbolic_name_show, NULL);
  820. static DEVICE_ATTR(hardware_version, S_IRUGO,
  821. bfad_im_hw_version_show, NULL);
  822. static DEVICE_ATTR(driver_version, S_IRUGO,
  823. bfad_im_drv_version_show, NULL);
  824. static DEVICE_ATTR(option_rom_version, S_IRUGO,
  825. bfad_im_optionrom_version_show, NULL);
  826. static DEVICE_ATTR(firmware_version, S_IRUGO,
  827. bfad_im_fw_version_show, NULL);
  828. static DEVICE_ATTR(number_of_ports, S_IRUGO,
  829. bfad_im_num_of_ports_show, NULL);
  830. static DEVICE_ATTR(driver_name, S_IRUGO, bfad_im_drv_name_show, NULL);
  831. static DEVICE_ATTR(number_of_discovered_ports, S_IRUGO,
  832. bfad_im_num_of_discovered_ports_show, NULL);
  833. struct device_attribute *bfad_im_host_attrs[] = {
  834. &dev_attr_serial_number,
  835. &dev_attr_model,
  836. &dev_attr_model_description,
  837. &dev_attr_node_name,
  838. &dev_attr_symbolic_name,
  839. &dev_attr_hardware_version,
  840. &dev_attr_driver_version,
  841. &dev_attr_option_rom_version,
  842. &dev_attr_firmware_version,
  843. &dev_attr_number_of_ports,
  844. &dev_attr_driver_name,
  845. &dev_attr_number_of_discovered_ports,
  846. NULL,
  847. };
  848. struct device_attribute *bfad_im_vport_attrs[] = {
  849. &dev_attr_serial_number,
  850. &dev_attr_model,
  851. &dev_attr_model_description,
  852. &dev_attr_node_name,
  853. &dev_attr_symbolic_name,
  854. &dev_attr_hardware_version,
  855. &dev_attr_driver_version,
  856. &dev_attr_option_rom_version,
  857. &dev_attr_firmware_version,
  858. &dev_attr_number_of_ports,
  859. &dev_attr_driver_name,
  860. &dev_attr_number_of_discovered_ports,
  861. NULL,
  862. };