zfcp_fsf.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  19. {
  20. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  21. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  22. "fsrth_1", NULL);
  23. }
  24. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  25. unsigned long timeout)
  26. {
  27. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  28. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  29. fsf_req->timer.expires = jiffies + timeout;
  30. add_timer(&fsf_req->timer);
  31. }
  32. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  33. {
  34. BUG_ON(!fsf_req->erp_action);
  35. fsf_req->timer.function = zfcp_erp_timeout_handler;
  36. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  37. fsf_req->timer.expires = jiffies + 30 * HZ;
  38. add_timer(&fsf_req->timer);
  39. }
  40. /* association between FSF command and FSF QTCB type */
  41. static u32 fsf_qtcb_type[] = {
  42. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  43. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  52. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  53. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  54. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  55. };
  56. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  57. {
  58. u16 subtable = table >> 16;
  59. u16 rule = table & 0xffff;
  60. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  61. if (subtable && subtable < ARRAY_SIZE(act_type))
  62. dev_warn(&adapter->ccw_device->dev,
  63. "Access denied according to ACT rule type %s, "
  64. "rule %d\n", act_type[subtable], rule);
  65. }
  66. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  67. struct zfcp_port *port)
  68. {
  69. struct fsf_qtcb_header *header = &req->qtcb->header;
  70. dev_warn(&req->adapter->ccw_device->dev,
  71. "Access denied to port 0x%016Lx\n",
  72. (unsigned long long)port->wwpn);
  73. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  74. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  75. zfcp_erp_port_access_denied(port, "fspad_1", req);
  76. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  77. }
  78. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  79. struct zfcp_unit *unit)
  80. {
  81. struct fsf_qtcb_header *header = &req->qtcb->header;
  82. dev_warn(&req->adapter->ccw_device->dev,
  83. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  84. (unsigned long long)unit->fcp_lun,
  85. (unsigned long long)unit->port->wwpn);
  86. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  87. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  88. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  89. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  90. }
  91. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  92. {
  93. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  94. "operational because of an unsupported FC class\n");
  95. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  96. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  97. }
  98. /**
  99. * zfcp_fsf_req_free - free memory used by fsf request
  100. * @fsf_req: pointer to struct zfcp_fsf_req
  101. */
  102. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  103. {
  104. if (likely(req->pool)) {
  105. if (likely(req->qtcb))
  106. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  107. mempool_free(req, req->pool);
  108. return;
  109. }
  110. if (likely(req->qtcb))
  111. kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
  112. kfree(req);
  113. }
  114. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  115. {
  116. unsigned long flags;
  117. struct fsf_status_read_buffer *sr_buf = req->data;
  118. struct zfcp_adapter *adapter = req->adapter;
  119. struct zfcp_port *port;
  120. int d_id = ntoh24(sr_buf->d_id);
  121. read_lock_irqsave(&adapter->port_list_lock, flags);
  122. list_for_each_entry(port, &adapter->port_list, list)
  123. if (port->d_id == d_id) {
  124. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  125. break;
  126. }
  127. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  128. }
  129. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  130. struct fsf_link_down_info *link_down)
  131. {
  132. struct zfcp_adapter *adapter = req->adapter;
  133. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  134. return;
  135. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  136. zfcp_scsi_schedule_rports_block(adapter);
  137. if (!link_down)
  138. goto out;
  139. switch (link_down->error_code) {
  140. case FSF_PSQ_LINK_NO_LIGHT:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "There is no light signal from the local "
  143. "fibre channel cable\n");
  144. break;
  145. case FSF_PSQ_LINK_WRAP_PLUG:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "There is a wrap plug instead of a fibre "
  148. "channel cable\n");
  149. break;
  150. case FSF_PSQ_LINK_NO_FCP:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The adjacent fibre channel node does not "
  153. "support FCP\n");
  154. break;
  155. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The FCP device is suspended because of a "
  158. "firmware update\n");
  159. break;
  160. case FSF_PSQ_LINK_INVALID_WWPN:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "The FCP device detected a WWPN that is "
  163. "duplicate or not valid\n");
  164. break;
  165. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The fibre channel fabric does not support NPIV\n");
  168. break;
  169. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  170. dev_warn(&req->adapter->ccw_device->dev,
  171. "The FCP adapter cannot support more NPIV ports\n");
  172. break;
  173. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  174. dev_warn(&req->adapter->ccw_device->dev,
  175. "The adjacent switch cannot support "
  176. "more NPIV ports\n");
  177. break;
  178. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  179. dev_warn(&req->adapter->ccw_device->dev,
  180. "The FCP adapter could not log in to the "
  181. "fibre channel fabric\n");
  182. break;
  183. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  184. dev_warn(&req->adapter->ccw_device->dev,
  185. "The WWPN assignment file on the FCP adapter "
  186. "has been damaged\n");
  187. break;
  188. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  189. dev_warn(&req->adapter->ccw_device->dev,
  190. "The mode table on the FCP adapter "
  191. "has been damaged\n");
  192. break;
  193. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  194. dev_warn(&req->adapter->ccw_device->dev,
  195. "All NPIV ports on the FCP adapter have "
  196. "been assigned\n");
  197. break;
  198. default:
  199. dev_warn(&req->adapter->ccw_device->dev,
  200. "The link between the FCP adapter and "
  201. "the FC fabric is down\n");
  202. }
  203. out:
  204. zfcp_erp_adapter_failed(adapter, id, req);
  205. }
  206. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  207. {
  208. struct fsf_status_read_buffer *sr_buf = req->data;
  209. struct fsf_link_down_info *ldi =
  210. (struct fsf_link_down_info *) &sr_buf->payload;
  211. switch (sr_buf->status_subtype) {
  212. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  213. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  214. break;
  215. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  216. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  217. break;
  218. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  219. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  220. };
  221. }
  222. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  223. {
  224. struct zfcp_adapter *adapter = req->adapter;
  225. struct fsf_status_read_buffer *sr_buf = req->data;
  226. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  227. zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
  228. mempool_free(sr_buf, adapter->pool.status_read_data);
  229. zfcp_fsf_req_free(req);
  230. return;
  231. }
  232. zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
  233. switch (sr_buf->status_type) {
  234. case FSF_STATUS_READ_PORT_CLOSED:
  235. zfcp_fsf_status_read_port_closed(req);
  236. break;
  237. case FSF_STATUS_READ_INCOMING_ELS:
  238. zfcp_fc_incoming_els(req);
  239. break;
  240. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  241. break;
  242. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  243. dev_warn(&adapter->ccw_device->dev,
  244. "The error threshold for checksum statistics "
  245. "has been exceeded\n");
  246. zfcp_dbf_hba_berr(adapter->dbf, req);
  247. break;
  248. case FSF_STATUS_READ_LINK_DOWN:
  249. zfcp_fsf_status_read_link_down(req);
  250. break;
  251. case FSF_STATUS_READ_LINK_UP:
  252. dev_info(&adapter->ccw_device->dev,
  253. "The local link has been restored\n");
  254. /* All ports should be marked as ready to run again */
  255. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  256. ZFCP_STATUS_COMMON_RUNNING,
  257. ZFCP_SET);
  258. zfcp_erp_adapter_reopen(adapter,
  259. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  260. ZFCP_STATUS_COMMON_ERP_FAILED,
  261. "fssrh_2", req);
  262. break;
  263. case FSF_STATUS_READ_NOTIFICATION_LOST:
  264. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  265. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  266. req);
  267. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  268. queue_work(adapter->work_queue, &adapter->scan_work);
  269. break;
  270. case FSF_STATUS_READ_CFDC_UPDATED:
  271. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  272. break;
  273. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  274. adapter->adapter_features = sr_buf->payload.word[0];
  275. break;
  276. }
  277. mempool_free(sr_buf, adapter->pool.status_read_data);
  278. zfcp_fsf_req_free(req);
  279. atomic_inc(&adapter->stat_miss);
  280. queue_work(adapter->work_queue, &adapter->stat_work);
  281. }
  282. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  283. {
  284. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  285. case FSF_SQ_FCP_RSP_AVAILABLE:
  286. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  287. case FSF_SQ_NO_RETRY_POSSIBLE:
  288. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  289. return;
  290. case FSF_SQ_COMMAND_ABORTED:
  291. break;
  292. case FSF_SQ_NO_RECOM:
  293. dev_err(&req->adapter->ccw_device->dev,
  294. "The FCP adapter reported a problem "
  295. "that cannot be recovered\n");
  296. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  297. break;
  298. }
  299. /* all non-return stats set FSFREQ_ERROR*/
  300. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  301. }
  302. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  303. {
  304. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  305. return;
  306. switch (req->qtcb->header.fsf_status) {
  307. case FSF_UNKNOWN_COMMAND:
  308. dev_err(&req->adapter->ccw_device->dev,
  309. "The FCP adapter does not recognize the command 0x%x\n",
  310. req->qtcb->header.fsf_command);
  311. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  312. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  313. break;
  314. case FSF_ADAPTER_STATUS_AVAILABLE:
  315. zfcp_fsf_fsfstatus_qual_eval(req);
  316. break;
  317. }
  318. }
  319. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  320. {
  321. struct zfcp_adapter *adapter = req->adapter;
  322. struct fsf_qtcb *qtcb = req->qtcb;
  323. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  324. zfcp_dbf_hba_fsf_response(req);
  325. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  327. return;
  328. }
  329. switch (qtcb->prefix.prot_status) {
  330. case FSF_PROT_GOOD:
  331. case FSF_PROT_FSF_STATUS_PRESENTED:
  332. return;
  333. case FSF_PROT_QTCB_VERSION_ERROR:
  334. dev_err(&adapter->ccw_device->dev,
  335. "QTCB version 0x%x not supported by FCP adapter "
  336. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  337. psq->word[0], psq->word[1]);
  338. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  339. break;
  340. case FSF_PROT_ERROR_STATE:
  341. case FSF_PROT_SEQ_NUMB_ERROR:
  342. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  343. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  344. break;
  345. case FSF_PROT_UNSUPP_QTCB_TYPE:
  346. dev_err(&adapter->ccw_device->dev,
  347. "The QTCB type is not supported by the FCP adapter\n");
  348. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  349. break;
  350. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  351. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  352. &adapter->status);
  353. break;
  354. case FSF_PROT_DUPLICATE_REQUEST_ID:
  355. dev_err(&adapter->ccw_device->dev,
  356. "0x%Lx is an ambiguous request identifier\n",
  357. (unsigned long long)qtcb->bottom.support.req_handle);
  358. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  359. break;
  360. case FSF_PROT_LINK_DOWN:
  361. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  362. &psq->link_down_info);
  363. /* go through reopen to flush pending requests */
  364. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  365. break;
  366. case FSF_PROT_REEST_QUEUE:
  367. /* All ports should be marked as ready to run again */
  368. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  369. ZFCP_STATUS_COMMON_RUNNING,
  370. ZFCP_SET);
  371. zfcp_erp_adapter_reopen(adapter,
  372. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  373. ZFCP_STATUS_COMMON_ERP_FAILED,
  374. "fspse_8", req);
  375. break;
  376. default:
  377. dev_err(&adapter->ccw_device->dev,
  378. "0x%x is not a valid transfer protocol status\n",
  379. qtcb->prefix.prot_status);
  380. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  381. }
  382. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  383. }
  384. /**
  385. * zfcp_fsf_req_complete - process completion of a FSF request
  386. * @fsf_req: The FSF request that has been completed.
  387. *
  388. * When a request has been completed either from the FCP adapter,
  389. * or it has been dismissed due to a queue shutdown, this function
  390. * is called to process the completion status and trigger further
  391. * events related to the FSF request.
  392. */
  393. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  394. {
  395. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  396. zfcp_fsf_status_read_handler(req);
  397. return;
  398. }
  399. del_timer(&req->timer);
  400. zfcp_fsf_protstatus_eval(req);
  401. zfcp_fsf_fsfstatus_eval(req);
  402. req->handler(req);
  403. if (req->erp_action)
  404. zfcp_erp_notify(req->erp_action, 0);
  405. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  406. zfcp_fsf_req_free(req);
  407. else
  408. complete(&req->completion);
  409. }
  410. /**
  411. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  412. * @adapter: pointer to struct zfcp_adapter
  413. *
  414. * Never ever call this without shutting down the adapter first.
  415. * Otherwise the adapter would continue using and corrupting s390 storage.
  416. * Included BUG_ON() call to ensure this is done.
  417. * ERP is supposed to be the only user of this function.
  418. */
  419. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  420. {
  421. struct zfcp_fsf_req *req, *tmp;
  422. LIST_HEAD(remove_queue);
  423. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  424. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  425. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  426. list_del(&req->list);
  427. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  428. zfcp_fsf_req_complete(req);
  429. }
  430. }
  431. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  432. {
  433. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  434. struct zfcp_adapter *adapter = req->adapter;
  435. struct Scsi_Host *shost = adapter->scsi_host;
  436. struct fc_els_flogi *nsp, *plogi;
  437. /* adjust pointers for missing command code */
  438. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  439. - sizeof(u32));
  440. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  441. - sizeof(u32));
  442. if (req->data)
  443. memcpy(req->data, bottom, sizeof(*bottom));
  444. fc_host_port_name(shost) = nsp->fl_wwpn;
  445. fc_host_node_name(shost) = nsp->fl_wwnn;
  446. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  447. fc_host_speed(shost) = bottom->fc_link_speed;
  448. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  449. adapter->hydra_version = bottom->adapter_type;
  450. adapter->timer_ticks = bottom->timer_interval;
  451. if (fc_host_permanent_port_name(shost) == -1)
  452. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  453. switch (bottom->fc_topology) {
  454. case FSF_TOPO_P2P:
  455. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  456. adapter->peer_wwpn = plogi->fl_wwpn;
  457. adapter->peer_wwnn = plogi->fl_wwnn;
  458. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  459. break;
  460. case FSF_TOPO_FABRIC:
  461. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  462. break;
  463. case FSF_TOPO_AL:
  464. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  465. /* fall through */
  466. default:
  467. dev_err(&adapter->ccw_device->dev,
  468. "Unknown or unsupported arbitrated loop "
  469. "fibre channel topology detected\n");
  470. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  471. return -EIO;
  472. }
  473. return 0;
  474. }
  475. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  476. {
  477. struct zfcp_adapter *adapter = req->adapter;
  478. struct fsf_qtcb *qtcb = req->qtcb;
  479. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  480. struct Scsi_Host *shost = adapter->scsi_host;
  481. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  482. return;
  483. adapter->fsf_lic_version = bottom->lic_version;
  484. adapter->adapter_features = bottom->adapter_features;
  485. adapter->connection_features = bottom->connection_features;
  486. adapter->peer_wwpn = 0;
  487. adapter->peer_wwnn = 0;
  488. adapter->peer_d_id = 0;
  489. switch (qtcb->header.fsf_status) {
  490. case FSF_GOOD:
  491. if (zfcp_fsf_exchange_config_evaluate(req))
  492. return;
  493. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  494. dev_err(&adapter->ccw_device->dev,
  495. "FCP adapter maximum QTCB size (%d bytes) "
  496. "is too small\n",
  497. bottom->max_qtcb_size);
  498. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  499. return;
  500. }
  501. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  502. &adapter->status);
  503. break;
  504. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  505. fc_host_node_name(shost) = 0;
  506. fc_host_port_name(shost) = 0;
  507. fc_host_port_id(shost) = 0;
  508. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  509. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  510. adapter->hydra_version = 0;
  511. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  512. &adapter->status);
  513. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  514. &qtcb->header.fsf_status_qual.link_down_info);
  515. break;
  516. default:
  517. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  518. return;
  519. }
  520. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  521. adapter->hardware_version = bottom->hardware_version;
  522. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  523. min(FC_SERIAL_NUMBER_SIZE, 17));
  524. EBCASC(fc_host_serial_number(shost),
  525. min(FC_SERIAL_NUMBER_SIZE, 17));
  526. }
  527. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  528. dev_err(&adapter->ccw_device->dev,
  529. "The FCP adapter only supports newer "
  530. "control block versions\n");
  531. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  532. return;
  533. }
  534. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  535. dev_err(&adapter->ccw_device->dev,
  536. "The FCP adapter only supports older "
  537. "control block versions\n");
  538. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  539. }
  540. }
  541. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  542. {
  543. struct zfcp_adapter *adapter = req->adapter;
  544. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  545. struct Scsi_Host *shost = adapter->scsi_host;
  546. if (req->data)
  547. memcpy(req->data, bottom, sizeof(*bottom));
  548. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  549. fc_host_permanent_port_name(shost) = bottom->wwpn;
  550. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  551. } else
  552. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  553. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  554. fc_host_supported_speeds(shost) = bottom->supported_speed;
  555. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  556. FC_FC4_LIST_SIZE);
  557. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  558. FC_FC4_LIST_SIZE);
  559. }
  560. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  561. {
  562. struct fsf_qtcb *qtcb = req->qtcb;
  563. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  564. return;
  565. switch (qtcb->header.fsf_status) {
  566. case FSF_GOOD:
  567. zfcp_fsf_exchange_port_evaluate(req);
  568. break;
  569. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  570. zfcp_fsf_exchange_port_evaluate(req);
  571. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  572. &qtcb->header.fsf_status_qual.link_down_info);
  573. break;
  574. }
  575. }
  576. static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
  577. {
  578. struct zfcp_qdio_queue *req_q = &qdio->req_q;
  579. spin_lock_bh(&qdio->req_q_lock);
  580. if (atomic_read(&req_q->count))
  581. return 1;
  582. spin_unlock_bh(&qdio->req_q_lock);
  583. return 0;
  584. }
  585. static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
  586. {
  587. struct zfcp_adapter *adapter = qdio->adapter;
  588. long ret;
  589. spin_unlock_bh(&qdio->req_q_lock);
  590. ret = wait_event_interruptible_timeout(qdio->req_q_wq,
  591. zfcp_fsf_sbal_check(qdio), 5 * HZ);
  592. if (ret > 0)
  593. return 0;
  594. if (!ret) {
  595. atomic_inc(&qdio->req_q_full);
  596. /* assume hanging outbound queue, try queue recovery */
  597. zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
  598. }
  599. spin_lock_bh(&qdio->req_q_lock);
  600. return -EIO;
  601. }
  602. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  603. {
  604. struct zfcp_fsf_req *req;
  605. if (likely(pool))
  606. req = mempool_alloc(pool, GFP_ATOMIC);
  607. else
  608. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  609. if (unlikely(!req))
  610. return NULL;
  611. memset(req, 0, sizeof(*req));
  612. req->pool = pool;
  613. return req;
  614. }
  615. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  616. {
  617. struct fsf_qtcb *qtcb;
  618. if (likely(pool))
  619. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  620. else
  621. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  622. if (unlikely(!qtcb))
  623. return NULL;
  624. memset(qtcb, 0, sizeof(*qtcb));
  625. return qtcb;
  626. }
  627. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  628. u32 fsf_cmd, mempool_t *pool)
  629. {
  630. struct qdio_buffer_element *sbale;
  631. struct zfcp_qdio_queue *req_q = &qdio->req_q;
  632. struct zfcp_adapter *adapter = qdio->adapter;
  633. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  634. if (unlikely(!req))
  635. return ERR_PTR(-ENOMEM);
  636. if (adapter->req_no == 0)
  637. adapter->req_no++;
  638. INIT_LIST_HEAD(&req->list);
  639. init_timer(&req->timer);
  640. init_completion(&req->completion);
  641. req->adapter = adapter;
  642. req->fsf_command = fsf_cmd;
  643. req->req_id = adapter->req_no;
  644. req->qdio_req.sbal_number = 1;
  645. req->qdio_req.sbal_first = req_q->first;
  646. req->qdio_req.sbal_last = req_q->first;
  647. req->qdio_req.sbale_curr = 1;
  648. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  649. sbale[0].addr = (void *) req->req_id;
  650. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  651. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  652. if (likely(pool))
  653. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  654. else
  655. req->qtcb = zfcp_qtcb_alloc(NULL);
  656. if (unlikely(!req->qtcb)) {
  657. zfcp_fsf_req_free(req);
  658. return ERR_PTR(-ENOMEM);
  659. }
  660. req->seq_no = adapter->fsf_req_seq_no;
  661. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  662. req->qtcb->prefix.req_id = req->req_id;
  663. req->qtcb->prefix.ulp_info = 26;
  664. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  665. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  666. req->qtcb->header.req_handle = req->req_id;
  667. req->qtcb->header.fsf_command = req->fsf_command;
  668. sbale[1].addr = (void *) req->qtcb;
  669. sbale[1].length = sizeof(struct fsf_qtcb);
  670. }
  671. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  672. zfcp_fsf_req_free(req);
  673. return ERR_PTR(-EIO);
  674. }
  675. return req;
  676. }
  677. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  678. {
  679. struct zfcp_adapter *adapter = req->adapter;
  680. struct zfcp_qdio *qdio = adapter->qdio;
  681. int with_qtcb = (req->qtcb != NULL);
  682. int req_id = req->req_id;
  683. zfcp_reqlist_add(adapter->req_list, req);
  684. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
  685. req->issued = get_clock();
  686. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  687. del_timer(&req->timer);
  688. /* lookup request again, list might have changed */
  689. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  690. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  691. return -EIO;
  692. }
  693. /* Don't increase for unsolicited status */
  694. if (with_qtcb)
  695. adapter->fsf_req_seq_no++;
  696. adapter->req_no++;
  697. return 0;
  698. }
  699. /**
  700. * zfcp_fsf_status_read - send status read request
  701. * @adapter: pointer to struct zfcp_adapter
  702. * @req_flags: request flags
  703. * Returns: 0 on success, ERROR otherwise
  704. */
  705. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  706. {
  707. struct zfcp_adapter *adapter = qdio->adapter;
  708. struct zfcp_fsf_req *req;
  709. struct fsf_status_read_buffer *sr_buf;
  710. struct qdio_buffer_element *sbale;
  711. int retval = -EIO;
  712. spin_lock_bh(&qdio->req_q_lock);
  713. if (zfcp_fsf_req_sbal_get(qdio))
  714. goto out;
  715. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
  716. adapter->pool.status_read_req);
  717. if (IS_ERR(req)) {
  718. retval = PTR_ERR(req);
  719. goto out;
  720. }
  721. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  722. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  723. req->qdio_req.sbale_curr = 2;
  724. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  725. if (!sr_buf) {
  726. retval = -ENOMEM;
  727. goto failed_buf;
  728. }
  729. memset(sr_buf, 0, sizeof(*sr_buf));
  730. req->data = sr_buf;
  731. sbale = zfcp_qdio_sbale_curr(qdio, &req->qdio_req);
  732. sbale->addr = (void *) sr_buf;
  733. sbale->length = sizeof(*sr_buf);
  734. retval = zfcp_fsf_req_send(req);
  735. if (retval)
  736. goto failed_req_send;
  737. goto out;
  738. failed_req_send:
  739. mempool_free(sr_buf, adapter->pool.status_read_data);
  740. failed_buf:
  741. zfcp_fsf_req_free(req);
  742. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  743. out:
  744. spin_unlock_bh(&qdio->req_q_lock);
  745. return retval;
  746. }
  747. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  748. {
  749. struct zfcp_unit *unit = req->data;
  750. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  751. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  752. return;
  753. switch (req->qtcb->header.fsf_status) {
  754. case FSF_PORT_HANDLE_NOT_VALID:
  755. if (fsq->word[0] == fsq->word[1]) {
  756. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  757. "fsafch1", req);
  758. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  759. }
  760. break;
  761. case FSF_LUN_HANDLE_NOT_VALID:
  762. if (fsq->word[0] == fsq->word[1]) {
  763. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  764. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  765. }
  766. break;
  767. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  768. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  769. break;
  770. case FSF_PORT_BOXED:
  771. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  772. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  773. break;
  774. case FSF_LUN_BOXED:
  775. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  776. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  777. break;
  778. case FSF_ADAPTER_STATUS_AVAILABLE:
  779. switch (fsq->word[0]) {
  780. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  781. zfcp_fc_test_link(unit->port);
  782. /* fall through */
  783. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  784. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  785. break;
  786. }
  787. break;
  788. case FSF_GOOD:
  789. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  790. break;
  791. }
  792. }
  793. /**
  794. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  795. * @old_req_id: unsigned long
  796. * @unit: pointer to struct zfcp_unit
  797. * Returns: pointer to struct zfcp_fsf_req
  798. */
  799. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  800. struct zfcp_unit *unit)
  801. {
  802. struct qdio_buffer_element *sbale;
  803. struct zfcp_fsf_req *req = NULL;
  804. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  805. spin_lock_bh(&qdio->req_q_lock);
  806. if (zfcp_fsf_req_sbal_get(qdio))
  807. goto out;
  808. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  809. qdio->adapter->pool.scsi_abort);
  810. if (IS_ERR(req)) {
  811. req = NULL;
  812. goto out;
  813. }
  814. if (unlikely(!(atomic_read(&unit->status) &
  815. ZFCP_STATUS_COMMON_UNBLOCKED)))
  816. goto out_error_free;
  817. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  818. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  819. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  820. req->data = unit;
  821. req->handler = zfcp_fsf_abort_fcp_command_handler;
  822. req->qtcb->header.lun_handle = unit->handle;
  823. req->qtcb->header.port_handle = unit->port->handle;
  824. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  825. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  826. if (!zfcp_fsf_req_send(req))
  827. goto out;
  828. out_error_free:
  829. zfcp_fsf_req_free(req);
  830. req = NULL;
  831. out:
  832. spin_unlock_bh(&qdio->req_q_lock);
  833. return req;
  834. }
  835. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  836. {
  837. struct zfcp_adapter *adapter = req->adapter;
  838. struct zfcp_fsf_ct_els *ct = req->data;
  839. struct fsf_qtcb_header *header = &req->qtcb->header;
  840. ct->status = -EINVAL;
  841. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  842. goto skip_fsfstatus;
  843. switch (header->fsf_status) {
  844. case FSF_GOOD:
  845. zfcp_dbf_san_ct_response(req);
  846. ct->status = 0;
  847. break;
  848. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  849. zfcp_fsf_class_not_supp(req);
  850. break;
  851. case FSF_ADAPTER_STATUS_AVAILABLE:
  852. switch (header->fsf_status_qual.word[0]){
  853. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  854. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  855. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  856. break;
  857. }
  858. break;
  859. case FSF_ACCESS_DENIED:
  860. break;
  861. case FSF_PORT_BOXED:
  862. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  863. break;
  864. case FSF_PORT_HANDLE_NOT_VALID:
  865. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  866. /* fall through */
  867. case FSF_GENERIC_COMMAND_REJECTED:
  868. case FSF_PAYLOAD_SIZE_MISMATCH:
  869. case FSF_REQUEST_SIZE_TOO_LARGE:
  870. case FSF_RESPONSE_SIZE_TOO_LARGE:
  871. case FSF_SBAL_MISMATCH:
  872. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  873. break;
  874. }
  875. skip_fsfstatus:
  876. if (ct->handler)
  877. ct->handler(ct->handler_data);
  878. }
  879. static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
  880. struct scatterlist *sg_req,
  881. struct scatterlist *sg_resp)
  882. {
  883. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  884. sbale[2].addr = sg_virt(sg_req);
  885. sbale[2].length = sg_req->length;
  886. sbale[3].addr = sg_virt(sg_resp);
  887. sbale[3].length = sg_resp->length;
  888. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  889. }
  890. static int zfcp_fsf_one_sbal(struct scatterlist *sg)
  891. {
  892. return sg_is_last(sg) && sg->length <= PAGE_SIZE;
  893. }
  894. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  895. struct scatterlist *sg_req,
  896. struct scatterlist *sg_resp,
  897. int max_sbals)
  898. {
  899. struct zfcp_adapter *adapter = req->adapter;
  900. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
  901. &req->qdio_req);
  902. u32 feat = adapter->adapter_features;
  903. int bytes;
  904. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  905. if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
  906. return -EOPNOTSUPP;
  907. zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
  908. return 0;
  909. }
  910. /* use single, unchained SBAL if it can hold the request */
  911. if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
  912. zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
  913. return 0;
  914. }
  915. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  916. SBAL_FLAGS0_TYPE_WRITE_READ,
  917. sg_req, max_sbals);
  918. if (bytes <= 0)
  919. return -EIO;
  920. req->qtcb->bottom.support.req_buf_length = bytes;
  921. req->qdio_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  922. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  923. SBAL_FLAGS0_TYPE_WRITE_READ,
  924. sg_resp, max_sbals);
  925. req->qtcb->bottom.support.resp_buf_length = bytes;
  926. if (bytes <= 0)
  927. return -EIO;
  928. return 0;
  929. }
  930. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  931. struct scatterlist *sg_req,
  932. struct scatterlist *sg_resp,
  933. int max_sbals, unsigned int timeout)
  934. {
  935. int ret;
  936. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
  937. if (ret)
  938. return ret;
  939. /* common settings for ct/gs and els requests */
  940. if (timeout > 255)
  941. timeout = 255; /* max value accepted by hardware */
  942. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  943. req->qtcb->bottom.support.timeout = timeout;
  944. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  945. return 0;
  946. }
  947. /**
  948. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  949. * @ct: pointer to struct zfcp_send_ct with data for request
  950. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  951. */
  952. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  953. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  954. unsigned int timeout)
  955. {
  956. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  957. struct zfcp_fsf_req *req;
  958. int ret = -EIO;
  959. spin_lock_bh(&qdio->req_q_lock);
  960. if (zfcp_fsf_req_sbal_get(qdio))
  961. goto out;
  962. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
  963. if (IS_ERR(req)) {
  964. ret = PTR_ERR(req);
  965. goto out;
  966. }
  967. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  968. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
  969. FSF_MAX_SBALS_PER_REQ, timeout);
  970. if (ret)
  971. goto failed_send;
  972. req->handler = zfcp_fsf_send_ct_handler;
  973. req->qtcb->header.port_handle = wka_port->handle;
  974. req->data = ct;
  975. zfcp_dbf_san_ct_request(req, wka_port->d_id);
  976. ret = zfcp_fsf_req_send(req);
  977. if (ret)
  978. goto failed_send;
  979. goto out;
  980. failed_send:
  981. zfcp_fsf_req_free(req);
  982. out:
  983. spin_unlock_bh(&qdio->req_q_lock);
  984. return ret;
  985. }
  986. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  987. {
  988. struct zfcp_fsf_ct_els *send_els = req->data;
  989. struct zfcp_port *port = send_els->port;
  990. struct fsf_qtcb_header *header = &req->qtcb->header;
  991. send_els->status = -EINVAL;
  992. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  993. goto skip_fsfstatus;
  994. switch (header->fsf_status) {
  995. case FSF_GOOD:
  996. zfcp_dbf_san_els_response(req);
  997. send_els->status = 0;
  998. break;
  999. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1000. zfcp_fsf_class_not_supp(req);
  1001. break;
  1002. case FSF_ADAPTER_STATUS_AVAILABLE:
  1003. switch (header->fsf_status_qual.word[0]){
  1004. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1005. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1006. case FSF_SQ_RETRY_IF_POSSIBLE:
  1007. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1008. break;
  1009. }
  1010. break;
  1011. case FSF_ELS_COMMAND_REJECTED:
  1012. case FSF_PAYLOAD_SIZE_MISMATCH:
  1013. case FSF_REQUEST_SIZE_TOO_LARGE:
  1014. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1015. break;
  1016. case FSF_ACCESS_DENIED:
  1017. if (port)
  1018. zfcp_fsf_access_denied_port(req, port);
  1019. break;
  1020. case FSF_SBAL_MISMATCH:
  1021. /* should never occure, avoided in zfcp_fsf_send_els */
  1022. /* fall through */
  1023. default:
  1024. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1025. break;
  1026. }
  1027. skip_fsfstatus:
  1028. if (send_els->handler)
  1029. send_els->handler(send_els->handler_data);
  1030. }
  1031. /**
  1032. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1033. * @els: pointer to struct zfcp_send_els with data for the command
  1034. */
  1035. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  1036. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  1037. {
  1038. struct zfcp_fsf_req *req;
  1039. struct zfcp_qdio *qdio = adapter->qdio;
  1040. int ret = -EIO;
  1041. spin_lock_bh(&qdio->req_q_lock);
  1042. if (zfcp_fsf_req_sbal_get(qdio))
  1043. goto out;
  1044. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
  1045. if (IS_ERR(req)) {
  1046. ret = PTR_ERR(req);
  1047. goto out;
  1048. }
  1049. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1050. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
  1051. if (ret)
  1052. goto failed_send;
  1053. hton24(req->qtcb->bottom.support.d_id, d_id);
  1054. req->handler = zfcp_fsf_send_els_handler;
  1055. req->data = els;
  1056. zfcp_dbf_san_els_request(req);
  1057. ret = zfcp_fsf_req_send(req);
  1058. if (ret)
  1059. goto failed_send;
  1060. goto out;
  1061. failed_send:
  1062. zfcp_fsf_req_free(req);
  1063. out:
  1064. spin_unlock_bh(&qdio->req_q_lock);
  1065. return ret;
  1066. }
  1067. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1068. {
  1069. struct qdio_buffer_element *sbale;
  1070. struct zfcp_fsf_req *req;
  1071. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1072. int retval = -EIO;
  1073. spin_lock_bh(&qdio->req_q_lock);
  1074. if (zfcp_fsf_req_sbal_get(qdio))
  1075. goto out;
  1076. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1077. qdio->adapter->pool.erp_req);
  1078. if (IS_ERR(req)) {
  1079. retval = PTR_ERR(req);
  1080. goto out;
  1081. }
  1082. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1083. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1084. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1085. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1086. req->qtcb->bottom.config.feature_selection =
  1087. FSF_FEATURE_CFDC |
  1088. FSF_FEATURE_LUN_SHARING |
  1089. FSF_FEATURE_NOTIFICATION_LOST |
  1090. FSF_FEATURE_UPDATE_ALERT;
  1091. req->erp_action = erp_action;
  1092. req->handler = zfcp_fsf_exchange_config_data_handler;
  1093. erp_action->fsf_req_id = req->req_id;
  1094. zfcp_fsf_start_erp_timer(req);
  1095. retval = zfcp_fsf_req_send(req);
  1096. if (retval) {
  1097. zfcp_fsf_req_free(req);
  1098. erp_action->fsf_req_id = 0;
  1099. }
  1100. out:
  1101. spin_unlock_bh(&qdio->req_q_lock);
  1102. return retval;
  1103. }
  1104. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1105. struct fsf_qtcb_bottom_config *data)
  1106. {
  1107. struct qdio_buffer_element *sbale;
  1108. struct zfcp_fsf_req *req = NULL;
  1109. int retval = -EIO;
  1110. spin_lock_bh(&qdio->req_q_lock);
  1111. if (zfcp_fsf_req_sbal_get(qdio))
  1112. goto out_unlock;
  1113. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
  1114. if (IS_ERR(req)) {
  1115. retval = PTR_ERR(req);
  1116. goto out_unlock;
  1117. }
  1118. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1119. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1120. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1121. req->handler = zfcp_fsf_exchange_config_data_handler;
  1122. req->qtcb->bottom.config.feature_selection =
  1123. FSF_FEATURE_CFDC |
  1124. FSF_FEATURE_LUN_SHARING |
  1125. FSF_FEATURE_NOTIFICATION_LOST |
  1126. FSF_FEATURE_UPDATE_ALERT;
  1127. if (data)
  1128. req->data = data;
  1129. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1130. retval = zfcp_fsf_req_send(req);
  1131. spin_unlock_bh(&qdio->req_q_lock);
  1132. if (!retval)
  1133. wait_for_completion(&req->completion);
  1134. zfcp_fsf_req_free(req);
  1135. return retval;
  1136. out_unlock:
  1137. spin_unlock_bh(&qdio->req_q_lock);
  1138. return retval;
  1139. }
  1140. /**
  1141. * zfcp_fsf_exchange_port_data - request information about local port
  1142. * @erp_action: ERP action for the adapter for which port data is requested
  1143. * Returns: 0 on success, error otherwise
  1144. */
  1145. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1146. {
  1147. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1148. struct qdio_buffer_element *sbale;
  1149. struct zfcp_fsf_req *req;
  1150. int retval = -EIO;
  1151. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1152. return -EOPNOTSUPP;
  1153. spin_lock_bh(&qdio->req_q_lock);
  1154. if (zfcp_fsf_req_sbal_get(qdio))
  1155. goto out;
  1156. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1157. qdio->adapter->pool.erp_req);
  1158. if (IS_ERR(req)) {
  1159. retval = PTR_ERR(req);
  1160. goto out;
  1161. }
  1162. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1163. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1164. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1165. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1166. req->handler = zfcp_fsf_exchange_port_data_handler;
  1167. req->erp_action = erp_action;
  1168. erp_action->fsf_req_id = req->req_id;
  1169. zfcp_fsf_start_erp_timer(req);
  1170. retval = zfcp_fsf_req_send(req);
  1171. if (retval) {
  1172. zfcp_fsf_req_free(req);
  1173. erp_action->fsf_req_id = 0;
  1174. }
  1175. out:
  1176. spin_unlock_bh(&qdio->req_q_lock);
  1177. return retval;
  1178. }
  1179. /**
  1180. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1181. * @qdio: pointer to struct zfcp_qdio
  1182. * @data: pointer to struct fsf_qtcb_bottom_port
  1183. * Returns: 0 on success, error otherwise
  1184. */
  1185. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1186. struct fsf_qtcb_bottom_port *data)
  1187. {
  1188. struct qdio_buffer_element *sbale;
  1189. struct zfcp_fsf_req *req = NULL;
  1190. int retval = -EIO;
  1191. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1192. return -EOPNOTSUPP;
  1193. spin_lock_bh(&qdio->req_q_lock);
  1194. if (zfcp_fsf_req_sbal_get(qdio))
  1195. goto out_unlock;
  1196. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
  1197. if (IS_ERR(req)) {
  1198. retval = PTR_ERR(req);
  1199. goto out_unlock;
  1200. }
  1201. if (data)
  1202. req->data = data;
  1203. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1204. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1205. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1206. req->handler = zfcp_fsf_exchange_port_data_handler;
  1207. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1208. retval = zfcp_fsf_req_send(req);
  1209. spin_unlock_bh(&qdio->req_q_lock);
  1210. if (!retval)
  1211. wait_for_completion(&req->completion);
  1212. zfcp_fsf_req_free(req);
  1213. return retval;
  1214. out_unlock:
  1215. spin_unlock_bh(&qdio->req_q_lock);
  1216. return retval;
  1217. }
  1218. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1219. {
  1220. struct zfcp_port *port = req->data;
  1221. struct fsf_qtcb_header *header = &req->qtcb->header;
  1222. struct fc_els_flogi *plogi;
  1223. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1224. goto out;
  1225. switch (header->fsf_status) {
  1226. case FSF_PORT_ALREADY_OPEN:
  1227. break;
  1228. case FSF_ACCESS_DENIED:
  1229. zfcp_fsf_access_denied_port(req, port);
  1230. break;
  1231. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1232. dev_warn(&req->adapter->ccw_device->dev,
  1233. "Not enough FCP adapter resources to open "
  1234. "remote port 0x%016Lx\n",
  1235. (unsigned long long)port->wwpn);
  1236. zfcp_erp_port_failed(port, "fsoph_1", req);
  1237. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1238. break;
  1239. case FSF_ADAPTER_STATUS_AVAILABLE:
  1240. switch (header->fsf_status_qual.word[0]) {
  1241. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1242. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1243. case FSF_SQ_NO_RETRY_POSSIBLE:
  1244. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1245. break;
  1246. }
  1247. break;
  1248. case FSF_GOOD:
  1249. port->handle = header->port_handle;
  1250. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1251. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1252. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1253. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1254. &port->status);
  1255. /* check whether D_ID has changed during open */
  1256. /*
  1257. * FIXME: This check is not airtight, as the FCP channel does
  1258. * not monitor closures of target port connections caused on
  1259. * the remote side. Thus, they might miss out on invalidating
  1260. * locally cached WWPNs (and other N_Port parameters) of gone
  1261. * target ports. So, our heroic attempt to make things safe
  1262. * could be undermined by 'open port' response data tagged with
  1263. * obsolete WWPNs. Another reason to monitor potential
  1264. * connection closures ourself at least (by interpreting
  1265. * incoming ELS' and unsolicited status). It just crosses my
  1266. * mind that one should be able to cross-check by means of
  1267. * another GID_PN straight after a port has been opened.
  1268. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1269. */
  1270. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1271. if (req->qtcb->bottom.support.els1_length >=
  1272. FSF_PLOGI_MIN_LEN)
  1273. zfcp_fc_plogi_evaluate(port, plogi);
  1274. break;
  1275. case FSF_UNKNOWN_OP_SUBTYPE:
  1276. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1277. break;
  1278. }
  1279. out:
  1280. put_device(&port->dev);
  1281. }
  1282. /**
  1283. * zfcp_fsf_open_port - create and send open port request
  1284. * @erp_action: pointer to struct zfcp_erp_action
  1285. * Returns: 0 on success, error otherwise
  1286. */
  1287. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1288. {
  1289. struct qdio_buffer_element *sbale;
  1290. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1291. struct zfcp_port *port = erp_action->port;
  1292. struct zfcp_fsf_req *req;
  1293. int retval = -EIO;
  1294. spin_lock_bh(&qdio->req_q_lock);
  1295. if (zfcp_fsf_req_sbal_get(qdio))
  1296. goto out;
  1297. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1298. qdio->adapter->pool.erp_req);
  1299. if (IS_ERR(req)) {
  1300. retval = PTR_ERR(req);
  1301. goto out;
  1302. }
  1303. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1304. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1305. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1306. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1307. req->handler = zfcp_fsf_open_port_handler;
  1308. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1309. req->data = port;
  1310. req->erp_action = erp_action;
  1311. erp_action->fsf_req_id = req->req_id;
  1312. get_device(&port->dev);
  1313. zfcp_fsf_start_erp_timer(req);
  1314. retval = zfcp_fsf_req_send(req);
  1315. if (retval) {
  1316. zfcp_fsf_req_free(req);
  1317. erp_action->fsf_req_id = 0;
  1318. put_device(&port->dev);
  1319. }
  1320. out:
  1321. spin_unlock_bh(&qdio->req_q_lock);
  1322. return retval;
  1323. }
  1324. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1325. {
  1326. struct zfcp_port *port = req->data;
  1327. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1328. return;
  1329. switch (req->qtcb->header.fsf_status) {
  1330. case FSF_PORT_HANDLE_NOT_VALID:
  1331. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1332. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1333. break;
  1334. case FSF_ADAPTER_STATUS_AVAILABLE:
  1335. break;
  1336. case FSF_GOOD:
  1337. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1338. ZFCP_STATUS_COMMON_OPEN,
  1339. ZFCP_CLEAR);
  1340. break;
  1341. }
  1342. }
  1343. /**
  1344. * zfcp_fsf_close_port - create and send close port request
  1345. * @erp_action: pointer to struct zfcp_erp_action
  1346. * Returns: 0 on success, error otherwise
  1347. */
  1348. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1349. {
  1350. struct qdio_buffer_element *sbale;
  1351. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1352. struct zfcp_fsf_req *req;
  1353. int retval = -EIO;
  1354. spin_lock_bh(&qdio->req_q_lock);
  1355. if (zfcp_fsf_req_sbal_get(qdio))
  1356. goto out;
  1357. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1358. qdio->adapter->pool.erp_req);
  1359. if (IS_ERR(req)) {
  1360. retval = PTR_ERR(req);
  1361. goto out;
  1362. }
  1363. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1364. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1365. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1366. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1367. req->handler = zfcp_fsf_close_port_handler;
  1368. req->data = erp_action->port;
  1369. req->erp_action = erp_action;
  1370. req->qtcb->header.port_handle = erp_action->port->handle;
  1371. erp_action->fsf_req_id = req->req_id;
  1372. zfcp_fsf_start_erp_timer(req);
  1373. retval = zfcp_fsf_req_send(req);
  1374. if (retval) {
  1375. zfcp_fsf_req_free(req);
  1376. erp_action->fsf_req_id = 0;
  1377. }
  1378. out:
  1379. spin_unlock_bh(&qdio->req_q_lock);
  1380. return retval;
  1381. }
  1382. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1383. {
  1384. struct zfcp_fc_wka_port *wka_port = req->data;
  1385. struct fsf_qtcb_header *header = &req->qtcb->header;
  1386. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1387. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1388. goto out;
  1389. }
  1390. switch (header->fsf_status) {
  1391. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1392. dev_warn(&req->adapter->ccw_device->dev,
  1393. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1394. /* fall through */
  1395. case FSF_ADAPTER_STATUS_AVAILABLE:
  1396. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1397. /* fall through */
  1398. case FSF_ACCESS_DENIED:
  1399. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1400. break;
  1401. case FSF_GOOD:
  1402. wka_port->handle = header->port_handle;
  1403. /* fall through */
  1404. case FSF_PORT_ALREADY_OPEN:
  1405. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1406. }
  1407. out:
  1408. wake_up(&wka_port->completion_wq);
  1409. }
  1410. /**
  1411. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1412. * @wka_port: pointer to struct zfcp_fc_wka_port
  1413. * Returns: 0 on success, error otherwise
  1414. */
  1415. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1416. {
  1417. struct qdio_buffer_element *sbale;
  1418. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1419. struct zfcp_fsf_req *req;
  1420. int retval = -EIO;
  1421. spin_lock_bh(&qdio->req_q_lock);
  1422. if (zfcp_fsf_req_sbal_get(qdio))
  1423. goto out;
  1424. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1425. qdio->adapter->pool.erp_req);
  1426. if (unlikely(IS_ERR(req))) {
  1427. retval = PTR_ERR(req);
  1428. goto out;
  1429. }
  1430. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1431. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1432. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1433. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1434. req->handler = zfcp_fsf_open_wka_port_handler;
  1435. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1436. req->data = wka_port;
  1437. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1438. retval = zfcp_fsf_req_send(req);
  1439. if (retval)
  1440. zfcp_fsf_req_free(req);
  1441. out:
  1442. spin_unlock_bh(&qdio->req_q_lock);
  1443. return retval;
  1444. }
  1445. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1446. {
  1447. struct zfcp_fc_wka_port *wka_port = req->data;
  1448. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1449. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1450. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1451. }
  1452. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1453. wake_up(&wka_port->completion_wq);
  1454. }
  1455. /**
  1456. * zfcp_fsf_close_wka_port - create and send close wka port request
  1457. * @wka_port: WKA port to open
  1458. * Returns: 0 on success, error otherwise
  1459. */
  1460. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1461. {
  1462. struct qdio_buffer_element *sbale;
  1463. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1464. struct zfcp_fsf_req *req;
  1465. int retval = -EIO;
  1466. spin_lock_bh(&qdio->req_q_lock);
  1467. if (zfcp_fsf_req_sbal_get(qdio))
  1468. goto out;
  1469. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1470. qdio->adapter->pool.erp_req);
  1471. if (unlikely(IS_ERR(req))) {
  1472. retval = PTR_ERR(req);
  1473. goto out;
  1474. }
  1475. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1476. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1477. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1478. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1479. req->handler = zfcp_fsf_close_wka_port_handler;
  1480. req->data = wka_port;
  1481. req->qtcb->header.port_handle = wka_port->handle;
  1482. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1483. retval = zfcp_fsf_req_send(req);
  1484. if (retval)
  1485. zfcp_fsf_req_free(req);
  1486. out:
  1487. spin_unlock_bh(&qdio->req_q_lock);
  1488. return retval;
  1489. }
  1490. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1491. {
  1492. struct zfcp_port *port = req->data;
  1493. struct fsf_qtcb_header *header = &req->qtcb->header;
  1494. struct zfcp_unit *unit;
  1495. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1496. return;
  1497. switch (header->fsf_status) {
  1498. case FSF_PORT_HANDLE_NOT_VALID:
  1499. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1500. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1501. break;
  1502. case FSF_ACCESS_DENIED:
  1503. zfcp_fsf_access_denied_port(req, port);
  1504. break;
  1505. case FSF_PORT_BOXED:
  1506. /* can't use generic zfcp_erp_modify_port_status because
  1507. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1508. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1509. read_lock(&port->unit_list_lock);
  1510. list_for_each_entry(unit, &port->unit_list, list)
  1511. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1512. &unit->status);
  1513. read_unlock(&port->unit_list_lock);
  1514. zfcp_erp_port_boxed(port, "fscpph2", req);
  1515. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1516. break;
  1517. case FSF_ADAPTER_STATUS_AVAILABLE:
  1518. switch (header->fsf_status_qual.word[0]) {
  1519. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1520. /* fall through */
  1521. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1522. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1523. break;
  1524. }
  1525. break;
  1526. case FSF_GOOD:
  1527. /* can't use generic zfcp_erp_modify_port_status because
  1528. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1529. */
  1530. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1531. read_lock(&port->unit_list_lock);
  1532. list_for_each_entry(unit, &port->unit_list, list)
  1533. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1534. &unit->status);
  1535. read_unlock(&port->unit_list_lock);
  1536. break;
  1537. }
  1538. }
  1539. /**
  1540. * zfcp_fsf_close_physical_port - close physical port
  1541. * @erp_action: pointer to struct zfcp_erp_action
  1542. * Returns: 0 on success
  1543. */
  1544. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1545. {
  1546. struct qdio_buffer_element *sbale;
  1547. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1548. struct zfcp_fsf_req *req;
  1549. int retval = -EIO;
  1550. spin_lock_bh(&qdio->req_q_lock);
  1551. if (zfcp_fsf_req_sbal_get(qdio))
  1552. goto out;
  1553. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1554. qdio->adapter->pool.erp_req);
  1555. if (IS_ERR(req)) {
  1556. retval = PTR_ERR(req);
  1557. goto out;
  1558. }
  1559. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1560. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1561. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1562. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1563. req->data = erp_action->port;
  1564. req->qtcb->header.port_handle = erp_action->port->handle;
  1565. req->erp_action = erp_action;
  1566. req->handler = zfcp_fsf_close_physical_port_handler;
  1567. erp_action->fsf_req_id = req->req_id;
  1568. zfcp_fsf_start_erp_timer(req);
  1569. retval = zfcp_fsf_req_send(req);
  1570. if (retval) {
  1571. zfcp_fsf_req_free(req);
  1572. erp_action->fsf_req_id = 0;
  1573. }
  1574. out:
  1575. spin_unlock_bh(&qdio->req_q_lock);
  1576. return retval;
  1577. }
  1578. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1579. {
  1580. struct zfcp_adapter *adapter = req->adapter;
  1581. struct zfcp_unit *unit = req->data;
  1582. struct fsf_qtcb_header *header = &req->qtcb->header;
  1583. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1584. struct fsf_queue_designator *queue_designator =
  1585. &header->fsf_status_qual.fsf_queue_designator;
  1586. int exclusive, readwrite;
  1587. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1588. return;
  1589. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1590. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1591. ZFCP_STATUS_UNIT_SHARED |
  1592. ZFCP_STATUS_UNIT_READONLY,
  1593. &unit->status);
  1594. switch (header->fsf_status) {
  1595. case FSF_PORT_HANDLE_NOT_VALID:
  1596. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1597. /* fall through */
  1598. case FSF_LUN_ALREADY_OPEN:
  1599. break;
  1600. case FSF_ACCESS_DENIED:
  1601. zfcp_fsf_access_denied_unit(req, unit);
  1602. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1603. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1604. break;
  1605. case FSF_PORT_BOXED:
  1606. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1607. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1608. break;
  1609. case FSF_LUN_SHARING_VIOLATION:
  1610. if (header->fsf_status_qual.word[0])
  1611. dev_warn(&adapter->ccw_device->dev,
  1612. "LUN 0x%Lx on port 0x%Lx is already in "
  1613. "use by CSS%d, MIF Image ID %x\n",
  1614. (unsigned long long)unit->fcp_lun,
  1615. (unsigned long long)unit->port->wwpn,
  1616. queue_designator->cssid,
  1617. queue_designator->hla);
  1618. else
  1619. zfcp_act_eval_err(adapter,
  1620. header->fsf_status_qual.word[2]);
  1621. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1622. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1623. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1624. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1625. break;
  1626. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1627. dev_warn(&adapter->ccw_device->dev,
  1628. "No handle is available for LUN "
  1629. "0x%016Lx on port 0x%016Lx\n",
  1630. (unsigned long long)unit->fcp_lun,
  1631. (unsigned long long)unit->port->wwpn);
  1632. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1633. /* fall through */
  1634. case FSF_INVALID_COMMAND_OPTION:
  1635. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1636. break;
  1637. case FSF_ADAPTER_STATUS_AVAILABLE:
  1638. switch (header->fsf_status_qual.word[0]) {
  1639. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1640. zfcp_fc_test_link(unit->port);
  1641. /* fall through */
  1642. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1643. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1644. break;
  1645. }
  1646. break;
  1647. case FSF_GOOD:
  1648. unit->handle = header->lun_handle;
  1649. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1650. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1651. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1652. !zfcp_ccw_priv_sch(adapter)) {
  1653. exclusive = (bottom->lun_access_info &
  1654. FSF_UNIT_ACCESS_EXCLUSIVE);
  1655. readwrite = (bottom->lun_access_info &
  1656. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1657. if (!exclusive)
  1658. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1659. &unit->status);
  1660. if (!readwrite) {
  1661. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1662. &unit->status);
  1663. dev_info(&adapter->ccw_device->dev,
  1664. "SCSI device at LUN 0x%016Lx on port "
  1665. "0x%016Lx opened read-only\n",
  1666. (unsigned long long)unit->fcp_lun,
  1667. (unsigned long long)unit->port->wwpn);
  1668. }
  1669. if (exclusive && !readwrite) {
  1670. dev_err(&adapter->ccw_device->dev,
  1671. "Exclusive read-only access not "
  1672. "supported (unit 0x%016Lx, "
  1673. "port 0x%016Lx)\n",
  1674. (unsigned long long)unit->fcp_lun,
  1675. (unsigned long long)unit->port->wwpn);
  1676. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1677. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1678. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1679. } else if (!exclusive && readwrite) {
  1680. dev_err(&adapter->ccw_device->dev,
  1681. "Shared read-write access not "
  1682. "supported (unit 0x%016Lx, port "
  1683. "0x%016Lx)\n",
  1684. (unsigned long long)unit->fcp_lun,
  1685. (unsigned long long)unit->port->wwpn);
  1686. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1687. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1688. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1689. }
  1690. }
  1691. break;
  1692. }
  1693. }
  1694. /**
  1695. * zfcp_fsf_open_unit - open unit
  1696. * @erp_action: pointer to struct zfcp_erp_action
  1697. * Returns: 0 on success, error otherwise
  1698. */
  1699. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1700. {
  1701. struct qdio_buffer_element *sbale;
  1702. struct zfcp_adapter *adapter = erp_action->adapter;
  1703. struct zfcp_qdio *qdio = adapter->qdio;
  1704. struct zfcp_fsf_req *req;
  1705. int retval = -EIO;
  1706. spin_lock_bh(&qdio->req_q_lock);
  1707. if (zfcp_fsf_req_sbal_get(qdio))
  1708. goto out;
  1709. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1710. adapter->pool.erp_req);
  1711. if (IS_ERR(req)) {
  1712. retval = PTR_ERR(req);
  1713. goto out;
  1714. }
  1715. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1716. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1717. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1718. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1719. req->qtcb->header.port_handle = erp_action->port->handle;
  1720. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1721. req->handler = zfcp_fsf_open_unit_handler;
  1722. req->data = erp_action->unit;
  1723. req->erp_action = erp_action;
  1724. erp_action->fsf_req_id = req->req_id;
  1725. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1726. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1727. zfcp_fsf_start_erp_timer(req);
  1728. retval = zfcp_fsf_req_send(req);
  1729. if (retval) {
  1730. zfcp_fsf_req_free(req);
  1731. erp_action->fsf_req_id = 0;
  1732. }
  1733. out:
  1734. spin_unlock_bh(&qdio->req_q_lock);
  1735. return retval;
  1736. }
  1737. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1738. {
  1739. struct zfcp_unit *unit = req->data;
  1740. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1741. return;
  1742. switch (req->qtcb->header.fsf_status) {
  1743. case FSF_PORT_HANDLE_NOT_VALID:
  1744. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1745. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1746. break;
  1747. case FSF_LUN_HANDLE_NOT_VALID:
  1748. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1749. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1750. break;
  1751. case FSF_PORT_BOXED:
  1752. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1753. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1754. break;
  1755. case FSF_ADAPTER_STATUS_AVAILABLE:
  1756. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1757. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1758. zfcp_fc_test_link(unit->port);
  1759. /* fall through */
  1760. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1761. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1762. break;
  1763. }
  1764. break;
  1765. case FSF_GOOD:
  1766. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1767. break;
  1768. }
  1769. }
  1770. /**
  1771. * zfcp_fsf_close_unit - close zfcp unit
  1772. * @erp_action: pointer to struct zfcp_unit
  1773. * Returns: 0 on success, error otherwise
  1774. */
  1775. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1776. {
  1777. struct qdio_buffer_element *sbale;
  1778. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1779. struct zfcp_fsf_req *req;
  1780. int retval = -EIO;
  1781. spin_lock_bh(&qdio->req_q_lock);
  1782. if (zfcp_fsf_req_sbal_get(qdio))
  1783. goto out;
  1784. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1785. qdio->adapter->pool.erp_req);
  1786. if (IS_ERR(req)) {
  1787. retval = PTR_ERR(req);
  1788. goto out;
  1789. }
  1790. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1791. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  1792. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1793. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1794. req->qtcb->header.port_handle = erp_action->port->handle;
  1795. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1796. req->handler = zfcp_fsf_close_unit_handler;
  1797. req->data = erp_action->unit;
  1798. req->erp_action = erp_action;
  1799. erp_action->fsf_req_id = req->req_id;
  1800. zfcp_fsf_start_erp_timer(req);
  1801. retval = zfcp_fsf_req_send(req);
  1802. if (retval) {
  1803. zfcp_fsf_req_free(req);
  1804. erp_action->fsf_req_id = 0;
  1805. }
  1806. out:
  1807. spin_unlock_bh(&qdio->req_q_lock);
  1808. return retval;
  1809. }
  1810. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1811. {
  1812. lat_rec->sum += lat;
  1813. lat_rec->min = min(lat_rec->min, lat);
  1814. lat_rec->max = max(lat_rec->max, lat);
  1815. }
  1816. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1817. {
  1818. struct fsf_qual_latency_info *lat_in;
  1819. struct latency_cont *lat = NULL;
  1820. struct zfcp_unit *unit = req->unit;
  1821. struct zfcp_blk_drv_data blktrc;
  1822. int ticks = req->adapter->timer_ticks;
  1823. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1824. blktrc.flags = 0;
  1825. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1826. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1827. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1828. blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
  1829. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1830. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1831. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1832. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1833. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1834. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1835. switch (req->qtcb->bottom.io.data_direction) {
  1836. case FSF_DATADIR_READ:
  1837. lat = &unit->latencies.read;
  1838. break;
  1839. case FSF_DATADIR_WRITE:
  1840. lat = &unit->latencies.write;
  1841. break;
  1842. case FSF_DATADIR_CMND:
  1843. lat = &unit->latencies.cmd;
  1844. break;
  1845. }
  1846. if (lat) {
  1847. spin_lock(&unit->latencies.lock);
  1848. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1849. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1850. lat->counter++;
  1851. spin_unlock(&unit->latencies.lock);
  1852. }
  1853. }
  1854. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1855. sizeof(blktrc));
  1856. }
  1857. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1858. {
  1859. struct scsi_cmnd *scpnt;
  1860. struct fcp_resp_with_ext *fcp_rsp;
  1861. unsigned long flags;
  1862. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1863. scpnt = req->data;
  1864. if (unlikely(!scpnt)) {
  1865. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1866. return;
  1867. }
  1868. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1869. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1870. goto skip_fsfstatus;
  1871. }
  1872. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1873. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1874. skip_fsfstatus:
  1875. zfcp_fsf_req_trace(req, scpnt);
  1876. zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
  1877. scpnt->host_scribble = NULL;
  1878. (scpnt->scsi_done) (scpnt);
  1879. /*
  1880. * We must hold this lock until scsi_done has been called.
  1881. * Otherwise we may call scsi_done after abort regarding this
  1882. * command has completed.
  1883. * Note: scsi_done must not block!
  1884. */
  1885. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1886. }
  1887. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1888. {
  1889. struct fcp_resp_with_ext *fcp_rsp;
  1890. struct fcp_resp_rsp_info *rsp_info;
  1891. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1892. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1893. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1894. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1895. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1896. }
  1897. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1898. {
  1899. struct zfcp_unit *unit;
  1900. struct fsf_qtcb_header *header = &req->qtcb->header;
  1901. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1902. unit = req->data;
  1903. else
  1904. unit = req->unit;
  1905. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1906. goto skip_fsfstatus;
  1907. switch (header->fsf_status) {
  1908. case FSF_HANDLE_MISMATCH:
  1909. case FSF_PORT_HANDLE_NOT_VALID:
  1910. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1911. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1912. break;
  1913. case FSF_FCPLUN_NOT_VALID:
  1914. case FSF_LUN_HANDLE_NOT_VALID:
  1915. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1916. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1917. break;
  1918. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1919. zfcp_fsf_class_not_supp(req);
  1920. break;
  1921. case FSF_ACCESS_DENIED:
  1922. zfcp_fsf_access_denied_unit(req, unit);
  1923. break;
  1924. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1925. dev_err(&req->adapter->ccw_device->dev,
  1926. "Incorrect direction %d, unit 0x%016Lx on port "
  1927. "0x%016Lx closed\n",
  1928. req->qtcb->bottom.io.data_direction,
  1929. (unsigned long long)unit->fcp_lun,
  1930. (unsigned long long)unit->port->wwpn);
  1931. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1932. req);
  1933. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1934. break;
  1935. case FSF_CMND_LENGTH_NOT_VALID:
  1936. dev_err(&req->adapter->ccw_device->dev,
  1937. "Incorrect CDB length %d, unit 0x%016Lx on "
  1938. "port 0x%016Lx closed\n",
  1939. req->qtcb->bottom.io.fcp_cmnd_length,
  1940. (unsigned long long)unit->fcp_lun,
  1941. (unsigned long long)unit->port->wwpn);
  1942. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1943. req);
  1944. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1945. break;
  1946. case FSF_PORT_BOXED:
  1947. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1948. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1949. break;
  1950. case FSF_LUN_BOXED:
  1951. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1952. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1953. break;
  1954. case FSF_ADAPTER_STATUS_AVAILABLE:
  1955. if (header->fsf_status_qual.word[0] ==
  1956. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1957. zfcp_fc_test_link(unit->port);
  1958. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1959. break;
  1960. }
  1961. skip_fsfstatus:
  1962. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1963. zfcp_fsf_send_fcp_ctm_handler(req);
  1964. else {
  1965. zfcp_fsf_send_fcp_command_task_handler(req);
  1966. req->unit = NULL;
  1967. put_device(&unit->dev);
  1968. }
  1969. }
  1970. /**
  1971. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1972. * @unit: unit where command is sent to
  1973. * @scsi_cmnd: scsi command to be sent
  1974. */
  1975. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  1976. struct scsi_cmnd *scsi_cmnd)
  1977. {
  1978. struct zfcp_fsf_req *req;
  1979. struct fcp_cmnd *fcp_cmnd;
  1980. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  1981. int real_bytes, retval = -EIO;
  1982. struct zfcp_adapter *adapter = unit->port->adapter;
  1983. struct zfcp_qdio *qdio = adapter->qdio;
  1984. if (unlikely(!(atomic_read(&unit->status) &
  1985. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1986. return -EBUSY;
  1987. spin_lock(&qdio->req_q_lock);
  1988. if (atomic_read(&qdio->req_q.count) <= 0) {
  1989. atomic_inc(&qdio->req_q_full);
  1990. goto out;
  1991. }
  1992. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1993. adapter->pool.scsi_req);
  1994. if (IS_ERR(req)) {
  1995. retval = PTR_ERR(req);
  1996. goto out;
  1997. }
  1998. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1999. get_device(&unit->dev);
  2000. req->unit = unit;
  2001. req->data = scsi_cmnd;
  2002. req->handler = zfcp_fsf_send_fcp_command_handler;
  2003. req->qtcb->header.lun_handle = unit->handle;
  2004. req->qtcb->header.port_handle = unit->port->handle;
  2005. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2006. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2007. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2008. /*
  2009. * set depending on data direction:
  2010. * data direction bits in SBALE (SB Type)
  2011. * data direction bits in QTCB
  2012. */
  2013. switch (scsi_cmnd->sc_data_direction) {
  2014. case DMA_NONE:
  2015. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2016. break;
  2017. case DMA_FROM_DEVICE:
  2018. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2019. break;
  2020. case DMA_TO_DEVICE:
  2021. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2022. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2023. break;
  2024. case DMA_BIDIRECTIONAL:
  2025. goto failed_scsi_cmnd;
  2026. }
  2027. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2028. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
  2029. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sbtype,
  2030. scsi_sglist(scsi_cmnd),
  2031. FSF_MAX_SBALS_PER_REQ);
  2032. if (unlikely(real_bytes < 0)) {
  2033. if (req->qdio_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
  2034. dev_err(&adapter->ccw_device->dev,
  2035. "Oversize data package, unit 0x%016Lx "
  2036. "on port 0x%016Lx closed\n",
  2037. (unsigned long long)unit->fcp_lun,
  2038. (unsigned long long)unit->port->wwpn);
  2039. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  2040. retval = -EINVAL;
  2041. }
  2042. goto failed_scsi_cmnd;
  2043. }
  2044. retval = zfcp_fsf_req_send(req);
  2045. if (unlikely(retval))
  2046. goto failed_scsi_cmnd;
  2047. goto out;
  2048. failed_scsi_cmnd:
  2049. put_device(&unit->dev);
  2050. zfcp_fsf_req_free(req);
  2051. scsi_cmnd->host_scribble = NULL;
  2052. out:
  2053. spin_unlock(&qdio->req_q_lock);
  2054. return retval;
  2055. }
  2056. /**
  2057. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2058. * @unit: pointer to struct zfcp_unit
  2059. * @tm_flags: unsigned byte for task management flags
  2060. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2061. */
  2062. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  2063. {
  2064. struct qdio_buffer_element *sbale;
  2065. struct zfcp_fsf_req *req = NULL;
  2066. struct fcp_cmnd *fcp_cmnd;
  2067. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  2068. if (unlikely(!(atomic_read(&unit->status) &
  2069. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2070. return NULL;
  2071. spin_lock_bh(&qdio->req_q_lock);
  2072. if (zfcp_fsf_req_sbal_get(qdio))
  2073. goto out;
  2074. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2075. qdio->adapter->pool.scsi_req);
  2076. if (IS_ERR(req)) {
  2077. req = NULL;
  2078. goto out;
  2079. }
  2080. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2081. req->data = unit;
  2082. req->handler = zfcp_fsf_send_fcp_command_handler;
  2083. req->qtcb->header.lun_handle = unit->handle;
  2084. req->qtcb->header.port_handle = unit->port->handle;
  2085. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2086. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2087. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2088. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  2089. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2090. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2091. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2092. zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
  2093. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2094. if (!zfcp_fsf_req_send(req))
  2095. goto out;
  2096. zfcp_fsf_req_free(req);
  2097. req = NULL;
  2098. out:
  2099. spin_unlock_bh(&qdio->req_q_lock);
  2100. return req;
  2101. }
  2102. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2103. {
  2104. }
  2105. /**
  2106. * zfcp_fsf_control_file - control file upload/download
  2107. * @adapter: pointer to struct zfcp_adapter
  2108. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2109. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2110. */
  2111. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2112. struct zfcp_fsf_cfdc *fsf_cfdc)
  2113. {
  2114. struct qdio_buffer_element *sbale;
  2115. struct zfcp_qdio *qdio = adapter->qdio;
  2116. struct zfcp_fsf_req *req = NULL;
  2117. struct fsf_qtcb_bottom_support *bottom;
  2118. int direction, retval = -EIO, bytes;
  2119. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2120. return ERR_PTR(-EOPNOTSUPP);
  2121. switch (fsf_cfdc->command) {
  2122. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2123. direction = SBAL_FLAGS0_TYPE_WRITE;
  2124. break;
  2125. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2126. direction = SBAL_FLAGS0_TYPE_READ;
  2127. break;
  2128. default:
  2129. return ERR_PTR(-EINVAL);
  2130. }
  2131. spin_lock_bh(&qdio->req_q_lock);
  2132. if (zfcp_fsf_req_sbal_get(qdio))
  2133. goto out;
  2134. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
  2135. if (IS_ERR(req)) {
  2136. retval = -EPERM;
  2137. goto out;
  2138. }
  2139. req->handler = zfcp_fsf_control_file_handler;
  2140. sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
  2141. sbale[0].flags |= direction;
  2142. bottom = &req->qtcb->bottom.support;
  2143. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2144. bottom->option = fsf_cfdc->option;
  2145. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  2146. direction, fsf_cfdc->sg,
  2147. FSF_MAX_SBALS_PER_REQ);
  2148. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2149. zfcp_fsf_req_free(req);
  2150. goto out;
  2151. }
  2152. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2153. retval = zfcp_fsf_req_send(req);
  2154. out:
  2155. spin_unlock_bh(&qdio->req_q_lock);
  2156. if (!retval) {
  2157. wait_for_completion(&req->completion);
  2158. return req;
  2159. }
  2160. return ERR_PTR(retval);
  2161. }
  2162. /**
  2163. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2164. * @adapter: pointer to struct zfcp_adapter
  2165. * @sbal_idx: response queue index of SBAL to be processed
  2166. */
  2167. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2168. {
  2169. struct zfcp_adapter *adapter = qdio->adapter;
  2170. struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
  2171. struct qdio_buffer_element *sbale;
  2172. struct zfcp_fsf_req *fsf_req;
  2173. unsigned long req_id;
  2174. int idx;
  2175. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2176. sbale = &sbal->element[idx];
  2177. req_id = (unsigned long) sbale->addr;
  2178. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2179. if (!fsf_req)
  2180. /*
  2181. * Unknown request means that we have potentially memory
  2182. * corruption and must stop the machine immediately.
  2183. */
  2184. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2185. req_id, dev_name(&adapter->ccw_device->dev));
  2186. fsf_req->qdio_req.sbal_response = sbal_idx;
  2187. fsf_req->qdio_req.qdio_inb_usage =
  2188. atomic_read(&qdio->resp_q.count);
  2189. zfcp_fsf_req_complete(fsf_req);
  2190. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2191. break;
  2192. }
  2193. }