bfad_attr.c 29 KB

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