zfcp_fsf.c 71 KB

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